summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorNoel Grandin <noelgrandin@gmail.com>2022-09-20 21:15:10 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2022-09-21 10:18:31 +0200
commit2de582e29dd6bc678b5b9d7d0ae1b8f8c6c0c862 (patch)
treeb96fe04ec4a19f05b4f2e8b8ec3f923ce63e5874 /vcl
parent59286d0b99679aeeffd989380754a3687effbb22 (diff)
convert HexFmt to a C++ class
Change-Id: Iebe385b1a6d51ab2c179a27eef4fb1199bc3aa41 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140264 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/source/fontsubset/sft.cxx95
1 files changed, 46 insertions, 49 deletions
diff --git a/vcl/source/fontsubset/sft.cxx b/vcl/source/fontsubset/sft.cxx
index 8f8dd7b60892..9794cc23f118 100644
--- a/vcl/source/fontsubset/sft.cxx
+++ b/vcl/source/fontsubset/sft.cxx
@@ -102,13 +102,25 @@ struct TTGlyphMetrics {
sal_uInt16 ah; /*- advance height (vertical writing mode) */
};
-#define HFORMAT_LINELEN 64
+constexpr int HFORMAT_LINELEN = 64;
-struct HexFmt {
+class HexFmt {
+public:
+ HexFmt(FILE *outf) : o(outf) {}
+ ~HexFmt()
+ {
+ Flush();
+ }
+ bool Flush();
+ void OpenString();
+ void CloseString();
+ void BlockWrite(const void *ptr, sal_uInt32 size);
+
+private:
FILE *o;
char buffer[HFORMAT_LINELEN];
- size_t bufpos;
- int total;
+ size_t bufpos = 0;
+ int total = 0;
};
struct GlyphOffsets {
@@ -207,62 +219,48 @@ static char toHex(sal_uInt8 nIndex)
return HexChars[nIndex];
}
-static HexFmt *HexFmtNew(FILE *outf)
-{
- HexFmt* res = static_cast<HexFmt*>(smalloc(sizeof(HexFmt)));
- res->bufpos = res->total = 0;
- res->o = outf;
- return res;
-}
-
-static bool HexFmtFlush(HexFmt *_this)
+bool HexFmt::Flush()
{
bool bRet = true;
- if (_this->bufpos) {
- size_t nWritten = fwrite(_this->buffer, 1, _this->bufpos, _this->o);
- bRet = nWritten == _this->bufpos;
- _this->bufpos = 0;
+ if (bufpos) {
+ size_t nWritten = fwrite(buffer, 1, bufpos, o);
+ bRet = nWritten == bufpos;
+ bufpos = 0;
}
return bRet;
}
-static void HexFmtOpenString(HexFmt *_this)
-{
- fputs("<\n", _this->o);
-}
-
-static void HexFmtCloseString(HexFmt *_this)
+void HexFmt::OpenString()
{
- HexFmtFlush(_this);
- fputs("00\n>\n", _this->o);
+ fputs("<\n", o);
}
-static void HexFmtDispose(HexFmt *_this)
+void HexFmt::CloseString()
{
- HexFmtFlush(_this);
- free(_this);
+ Flush();
+ fputs("00\n>\n", o);
}
-static void HexFmtBlockWrite(HexFmt *_this, const void *ptr, sal_uInt32 size)
+void HexFmt::BlockWrite(const void *ptr, sal_uInt32 size)
{
- if (_this->total + size > 65534) {
- HexFmtFlush(_this);
- HexFmtCloseString(_this);
- _this->total = 0;
- HexFmtOpenString(_this);
+ if (total + size > 65534) {
+ Flush();
+ CloseString();
+ total = 0;
+ OpenString();
}
for (sal_uInt32 i = 0; i < size; ++i) {
sal_uInt8 Ch = static_cast<sal_uInt8 const *>(ptr)[i];
- _this->buffer[_this->bufpos++] = toHex(Ch >> 4);
- _this->buffer[_this->bufpos++] = toHex(Ch & 0xF);
- if (_this->bufpos == HFORMAT_LINELEN) {
- HexFmtFlush(_this);
- fputc('\n', _this->o);
+ buffer[bufpos++] = toHex(Ch >> 4);
+ buffer[bufpos++] = toHex(Ch & 0xF);
+ if (bufpos == HFORMAT_LINELEN) {
+ Flush();
+ fputc('\n', o);
}
}
- _this->total += size;
+ total += size;
}
/* Outline Extraction functions */
@@ -2004,7 +2002,7 @@ static void DumpSfnts(FILE *outf, sal_uInt8 *sfntP, sal_uInt32 sfntLen)
const sal_uInt32 nTableSize = 16;
const sal_uInt32 nMaxPossibleTables = nSpaceForTables/nTableSize;
- HexFmt *h = HexFmtNew(outf);
+ HexFmt h(outf);
sal_uInt16 i, numTables = GetUInt16(sfntP, 4);
GlyphOffsets *go = GlyphOffsetsNew(sfntP, sfntLen);
sal_uInt8 const pad[] = {0,0,0,0}; /* zeroes */
@@ -2021,9 +2019,9 @@ static void DumpSfnts(FILE *outf, sal_uInt8 *sfntP, sal_uInt32 sfntLen)
sal_uInt32* offs = static_cast<sal_uInt32*>(scalloc(numTables, sizeof(sal_uInt32)));
fputs("/sfnts [", outf);
- HexFmtOpenString(h);
- HexFmtBlockWrite(h, sfntP, 12); /* stream out the Offset Table */
- HexFmtBlockWrite(h, sfntP+12, 16 * numTables); /* stream out the Table Directory */
+ h.OpenString();
+ h.BlockWrite(sfntP, 12); /* stream out the Offset Table */
+ h.BlockWrite(sfntP+12, 16 * numTables); /* stream out the Table Directory */
for (i=0; i<numTables; i++)
{
@@ -2056,7 +2054,7 @@ static void DumpSfnts(FILE *outf, sal_uInt8 *sfntP, sal_uInt32 sfntLen)
if (tag != T_glyf)
{
- HexFmtBlockWrite(h, pRecordStart, len);
+ h.BlockWrite(pRecordStart, len);
}
else
{
@@ -2083,15 +2081,14 @@ static void DumpSfnts(FILE *outf, sal_uInt8 *sfntP, sal_uInt32 sfntLen)
}
sal_uInt32 l = pSubRecordEnd - pSubRecordStart;
- HexFmtBlockWrite(h, pSubRecordStart, l);
+ h.BlockWrite(pSubRecordStart, l);
}
}
- HexFmtBlockWrite(h, pad, (4 - (len & 3)) & 3);
+ h.BlockWrite(pad, (4 - (len & 3)) & 3);
}
- HexFmtCloseString(h);
+ h.CloseString();
fputs("] def\n", outf);
GlyphOffsetsDispose(go);
- HexFmtDispose(h);
free(offs);
}