Coverage Report

Created: 2025-07-07 10:01

/work/workdir/UnpackedTarball/libeot/src/libeot.c
Line
Count
Source (jump to first uncovered line)
1
/* Copyright (c) 2013 Brennan T. Vincent <brennanv@email.arizona.edu>
2
 * This file is a part of libeot, which is licensed under the MPL license, version 2.0.
3
 * For full details, see the file LICENSE
4
 */
5
6
#include <stdlib.h>
7
#include <stdio.h>
8
#include <stdint.h>
9
10
#include <sys/stat.h>
11
12
#include <libeot/libeot.h>
13
14
#include "flags.h"
15
#include "writeFontFile.h"
16
17
void EOTprintError(enum EOTError error, FILE *out)
18
0
{
19
0
  switch (error)
20
0
  {
21
0
  case EOT_SUCCESS:
22
0
    break;
23
0
  case EOT_INSUFFICIENT_BYTES:
24
0
    fputs("The font file appears truncated.\n", out);
25
0
    break;
26
0
  case EOT_BOGUS_STRING_SIZE:
27
0
  case EOT_CORRUPT_FILE:
28
0
    fputs("The font file appears corrupt.\n", out);
29
0
    break;
30
0
  case EOT_CANT_ALLOCATE_MEMORY:
31
0
    fputs("Couldn't allocate sufficient memory.\n", out);
32
0
    break;
33
0
  case EOT_OTHER_STDLIB_ERROR:
34
0
    fputs("There was an unknown system error.\n", out);
35
0
    break;
36
0
  case EOT_COMPRESSION_NOT_YET_IMPLEMENTED:
37
0
    fputs("MTX Compression has not yet been implemented in this version of libeot. The font could therefore not be converted.\n", out);
38
0
    break;
39
0
  default:
40
0
    fputs("Unknown error: this is a bug in libeot; it does not *necessarily* indicate a corrupted font file.\n", out);
41
0
    break;
42
0
  }
43
44
0
}
45
46
enum EOTError EOT2ttf_file(const uint8_t *font, unsigned fontSize, struct EOTMetadata *metadataOut, FILE *out)
47
0
{
48
0
  enum EOTError result = EOTfillMetadata(font, fontSize, metadataOut);
49
0
  if (result >= EOT_WARN)
50
0
  {
51
0
    EOTprintError(result, stderr);
52
0
  }
53
0
  else if (result != EOT_SUCCESS)
54
0
  {
55
0
    return result;
56
0
  }
57
58
0
  enum EOTError writeResult = writeFontFile(font + metadataOut->fontDataOffset, metadataOut->fontDataSize, metadataOut->flags & TTEMBED_TTCOMPRESSED, metadataOut->flags & TTEMBED_XORENCRYPTDATA, out);
59
0
  if (writeResult != EOT_SUCCESS)
60
0
  {
61
0
    return writeResult;
62
0
  }
63
0
  return EOT_SUCCESS;
64
0
}
65
66
enum EOTError EOT2ttf_buffer(const uint8_t *font, unsigned fontSize, struct EOTMetadata *metadataOut, uint8_t **fontOut,
67
    unsigned *fontSizeOut)
68
0
{
69
0
  enum EOTError result = EOTfillMetadata(font, fontSize, metadataOut);
70
0
  if (result >= EOT_WARN)
71
0
  {
72
0
    EOTprintError(result, stderr);
73
0
  }
74
0
  else if (result != EOT_SUCCESS)
75
0
  {
76
0
    return result;
77
0
  }
78
79
0
  enum EOTError writeResult = writeFontBuffer(font + metadataOut->fontDataOffset, metadataOut->fontDataSize, metadataOut->flags & TTEMBED_TTCOMPRESSED, metadataOut->flags & TTEMBED_XORENCRYPTDATA, fontOut, fontSizeOut);
80
0
  if (result >= EOT_WARN)
81
0
  {
82
0
    EOTprintError(result, stderr);
83
0
  }
84
0
  else if (writeResult != EOT_SUCCESS)
85
0
  {
86
0
    return writeResult;
87
0
  }
88
0
  return EOT_SUCCESS;
89
0
}
90
91
void EOTfreeBuffer(const uint8_t *buffer)
92
0
{
93
0
  free((void *)buffer);
94
0
}
95
96
/* vim:set shiftwidth=2 softtabstop=2 expandtab: */