diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-10-27 17:13:16 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-10-30 08:33:39 +0100 |
commit | 1ecdddcc32ce2b003fca43ac2c5ef0668afef8dd (patch) | |
tree | 40d202cc79977e5f4f4aa9a010d55dc72a4a3d1f /vcl/source/fontsubset | |
parent | dd9c17ae211a8171a7dc84acd9c9dc17cc5b8c48 (diff) |
loplugin:constantparam in vcl
Change-Id: Ic32e4098dcdae5ca5d7fe2749badedabda86a90d
Reviewed-on: https://gerrit.libreoffice.org/44043
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Tested-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'vcl/source/fontsubset')
-rw-r--r-- | vcl/source/fontsubset/ttcr.cxx | 230 |
1 files changed, 99 insertions, 131 deletions
diff --git a/vcl/source/fontsubset/ttcr.cxx b/vcl/source/fontsubset/ttcr.cxx index b90166a1b76e..e8c1b744054e 100644 --- a/vcl/source/fontsubset/ttcr.cxx +++ b/vcl/source/fontsubset/ttcr.cxx @@ -60,76 +60,44 @@ typedef struct { } TableEntry; /*- Data access macros for data stored in big-endian or little-endian format */ -static sal_Int16 GetInt16( const sal_uInt8* ptr, sal_uInt32 offset, int bigendian) +static sal_Int16 GetInt16( const sal_uInt8* ptr, sal_uInt32 offset) { - sal_Int16 t; assert(ptr != nullptr); - - if (bigendian) { - t = (ptr+offset)[0] << 8 | (ptr+offset)[1]; - } else { - t = (ptr+offset)[1] << 8 | (ptr+offset)[0]; - } - + sal_Int16 t = (ptr+offset)[0] << 8 | (ptr+offset)[1]; return t; } -static sal_uInt16 GetUInt16( const sal_uInt8* ptr, sal_uInt32 offset, int bigendian) +static sal_uInt16 GetUInt16( const sal_uInt8* ptr, sal_uInt32 offset) { - sal_uInt16 t; assert(ptr != nullptr); - - if (bigendian) { - t = (ptr+offset)[0] << 8 | (ptr+offset)[1]; - } else { - t = (ptr+offset)[1] << 8 | (ptr+offset)[0]; - } - + sal_uInt16 t = (ptr+offset)[0] << 8 | (ptr+offset)[1]; return t; } -static void PutInt16(sal_Int16 val, sal_uInt8 *ptr, sal_uInt32 offset, int bigendian) +static void PutInt16(sal_Int16 val, sal_uInt8 *ptr, sal_uInt32 offset) { assert(ptr != nullptr); - if (bigendian) { - ptr[offset] = (sal_uInt8)((val >> 8) & 0xFF); - ptr[offset+1] = (sal_uInt8)(val & 0xFF); - } else { - ptr[offset+1] = (sal_uInt8)((val >> 8) & 0xFF); - ptr[offset] = (sal_uInt8)(val & 0xFF); - } + ptr[offset] = (sal_uInt8)((val >> 8) & 0xFF); + ptr[offset+1] = (sal_uInt8)(val & 0xFF); } -static void PutUInt16(sal_uInt16 val, sal_uInt8 *ptr, sal_uInt32 offset, int bigendian) +static void PutUInt16(sal_uInt16 val, sal_uInt8 *ptr, sal_uInt32 offset) { assert(ptr != nullptr); - if (bigendian) { - ptr[offset] = (sal_uInt8)((val >> 8) & 0xFF); - ptr[offset+1] = (sal_uInt8)(val & 0xFF); - } else { - ptr[offset+1] = (sal_uInt8)((val >> 8) & 0xFF); - ptr[offset] = (sal_uInt8)(val & 0xFF); - } + ptr[offset] = (sal_uInt8)((val >> 8) & 0xFF); + ptr[offset+1] = (sal_uInt8)(val & 0xFF); } -static void PutUInt32(sal_uInt32 val, sal_uInt8 *ptr, sal_uInt32 offset, int bigendian) +static void PutUInt32(sal_uInt32 val, sal_uInt8 *ptr, sal_uInt32 offset) { assert(ptr != nullptr); - if (bigendian) { - ptr[offset] = (sal_uInt8)((val >> 24) & 0xFF); - ptr[offset+1] = (sal_uInt8)((val >> 16) & 0xFF); - ptr[offset+2] = (sal_uInt8)((val >> 8) & 0xFF); - ptr[offset+3] = (sal_uInt8)(val & 0xFF); - } else { - ptr[offset+3] = (sal_uInt8)((val >> 24) & 0xFF); - ptr[offset+2] = (sal_uInt8)((val >> 16) & 0xFF); - ptr[offset+1] = (sal_uInt8)((val >> 8) & 0xFF); - ptr[offset] = (sal_uInt8)(val & 0xFF); - } - + ptr[offset] = (sal_uInt8)((val >> 24) & 0xFF); + ptr[offset+1] = (sal_uInt8)((val >> 16) & 0xFF); + ptr[offset+2] = (sal_uInt8)((val >> 8) & 0xFF); + ptr[offset+3] = (sal_uInt8)(val & 0xFF); } static int TableEntryCompareF(const void *l, const void *r) @@ -273,18 +241,18 @@ int StreamToMemory(TrueTypeCreator *_this, sal_uInt8 **ptr, sal_uInt32 *length) sal_uInt8* ttf = static_cast<sal_uInt8*>(smalloc(s)); /* Offset Table */ - PutUInt32(_this->tag, ttf, 0, 1); - PutUInt16(numTables, ttf, 4, 1); - PutUInt16(searchRange, ttf, 6, 1); - PutUInt16(entrySelector, ttf, 8, 1); - PutUInt16(rangeShift, ttf, 10, 1); + PutUInt32(_this->tag, ttf, 0); + PutUInt16(numTables, ttf, 4); + PutUInt16(searchRange, ttf, 6); + PutUInt16(entrySelector, ttf, 8); + PutUInt16(rangeShift, ttf, 10); /* Table Directory */ for (int i = 0; i < numTables; ++i) { - PutUInt32(te[i].tag, ttf + 12, 16 * i, 1); - PutUInt32(CheckSum(reinterpret_cast<sal_uInt32 *>(te[i].data), te[i].length), ttf + 12, 16 * i + 4, 1); - PutUInt32(offset, ttf + 12, 16 * i + 8, 1); - PutUInt32(te[i].length, ttf + 12, 16 * i + 12, 1); + PutUInt32(te[i].tag, ttf + 12, 16 * i); + PutUInt32(CheckSum(reinterpret_cast<sal_uInt32 *>(te[i].data), te[i].length), ttf + 12, 16 * i + 4); + PutUInt32(offset, ttf + 12, 16 * i + 8); + PutUInt32(te[i].length, ttf + 12, 16 * i + 12); if (te[i].tag == T_head) { head = ttf + offset; @@ -299,7 +267,7 @@ int StreamToMemory(TrueTypeCreator *_this, sal_uInt8 **ptr, sal_uInt32 *length) p = reinterpret_cast<sal_uInt32 *>(ttf); for (int i = 0; i < (int)s / 4; ++i) checkSumAdjustment += p[i]; - PutUInt32(0xB1B0AFBA - checkSumAdjustment, head, 8, 1); + PutUInt32(0xB1B0AFBA - checkSumAdjustment, head, 8); *ptr = ttf; *length = s; @@ -630,9 +598,9 @@ static sal_uInt8 *PackCmapType0(CmapSubTable *s, sal_uInt32 *length) sal_uInt32 i, j; sal_uInt16 g; - PutUInt16(0, ptr, 0, 1); - PutUInt16(262, ptr, 2, 1); - PutUInt16(0, ptr, 4, 1); + PutUInt16(0, ptr, 0); + PutUInt16(262, ptr, 2); + PutUInt16(0, ptr, 4); for (i = 0; i < 256; i++) { g = 0; @@ -654,11 +622,11 @@ static sal_uInt8 *PackCmapType6(CmapSubTable *s, sal_uInt32 *length) sal_uInt32 i, j; sal_uInt16 g; - PutUInt16(6, ptr, 0, 1); - PutUInt16((sal_uInt16)(s->n*2+10), ptr, 2, 1); - PutUInt16(0, ptr, 4, 1); - PutUInt16(0, ptr, 6, 1); - PutUInt16((sal_uInt16)(s->n), ptr, 8, 1 ); + PutUInt16(6, ptr, 0); + PutUInt16((sal_uInt16)(s->n*2+10), ptr, 2); + PutUInt16(0, ptr, 4); + PutUInt16(0, ptr, 6); + PutUInt16((sal_uInt16)(s->n), ptr, 8 ); for (i = 0; i < s->n; i++) { g = 0; @@ -667,7 +635,7 @@ static sal_uInt8 *PackCmapType6(CmapSubTable *s, sal_uInt32 *length) g = (sal_uInt16) s->xg[j]; } } - PutUInt16( g, p, 2*i, 1 ); + PutUInt16( g, p, 2*i ); } *length = s->n*2+10; return ptr; @@ -709,14 +677,14 @@ static int GetRawData_cmap(TrueTypeTable *_this, sal_uInt8 **ptr, sal_uInt32 *le cmapsize = tlen + 4 + 8 * t->n; _this->rawdata = cmap = ttmalloc(cmapsize); - PutUInt16(0, cmap, 0, 1); - PutUInt16((sal_uInt16)t->n, cmap, 2, 1); + PutUInt16(0, cmap, 0); + PutUInt16((sal_uInt16)t->n, cmap, 2); coffset = 4 + t->n * 8; for (i = 0; i < t->n; i++) { - PutUInt16((sal_uInt16)(t->s[i].id >> 16), cmap + 4, i * 8, 1); - PutUInt16((sal_uInt16)(t->s[i].id & 0xFF), cmap + 4, 2 + i * 8, 1); - PutUInt32(coffset, cmap + 4, 4 + i * 8, 1); + PutUInt16((sal_uInt16)(t->s[i].id >> 16), cmap + 4, i * 8); + PutUInt16((sal_uInt16)(t->s[i].id & 0xFF), cmap + 4, 2 + i * 8); + PutUInt32(coffset, cmap + 4, 4 + i * 8); memcpy(cmap + coffset, subtables[i], sizes[i]); free(subtables[i]); coffset += sizes[i]; @@ -769,20 +737,20 @@ static int GetRawData_name(TrueTypeTable *_this, sal_uInt8 **ptr, sal_uInt32 *le int nameLen = stringLen + 12 * n + 6; sal_uInt8* name = ttmalloc(nameLen); - PutUInt16(0, name, 0, 1); - PutUInt16(n, name, 2, 1); - PutUInt16((sal_uInt16)(6 + 12 * n), name, 4, 1); + PutUInt16(0, name, 0); + PutUInt16(n, name, 2); + PutUInt16((sal_uInt16)(6 + 12 * n), name, 4); p1 = name + 6; p2 = p1 + 12 * n; for (i = 0; i < n; i++) { - PutUInt16(nr[i].platformID, p1, 0, 1); - PutUInt16(nr[i].encodingID, p1, 2, 1); - PutUInt16((sal_uInt16)nr[i].languageID, p1, 4, 1); - PutUInt16(nr[i].nameID, p1, 6, 1); - PutUInt16(nr[i].slen, p1, 8, 1); - PutUInt16((sal_uInt16)(p2 - (name + 6 + 12 * n)), p1, 10, 1); + PutUInt16(nr[i].platformID, p1, 0); + PutUInt16(nr[i].encodingID, p1, 2); + PutUInt16((sal_uInt16)nr[i].languageID, p1, 4); + PutUInt16(nr[i].nameID, p1, 6); + PutUInt16(nr[i].slen, p1, 8); + PutUInt16((sal_uInt16)(p2 - (name + 6 + 12 * n)), p1, 10); if (nr[i].slen) { memcpy(p2, nr[i].sptr, nr[i].slen); } @@ -815,11 +783,11 @@ static int GetRawData_post(TrueTypeTable *_this, sal_uInt8 **ptr, sal_uInt32 *le if (p->format == 0x00030000) { postLen = 32; post = ttmalloc(postLen); - PutUInt32(0x00030000, post, 0, 1); - PutUInt32(p->italicAngle, post, 4, 1); - PutUInt16(p->underlinePosition, post, 8, 1); - PutUInt16(p->underlineThickness, post, 10, 1); - PutUInt16((sal_uInt16)p->isFixedPitch, post, 12, 1); + PutUInt32(0x00030000, post, 0); + PutUInt32(p->italicAngle, post, 4); + PutUInt16(p->underlinePosition, post, 8); + PutUInt16(p->underlineThickness, post, 10); + PutUInt16((sal_uInt16)p->isFixedPitch, post, 12); ret = TTCR_OK; } else { fprintf(stderr, "Unrecognized format of a post table: %08X.\n", (int)p->format); @@ -900,17 +868,17 @@ TrueTypeTable *TrueTypeTableNew_head(sal_uInt32 fontRevision, TrueTypeTable* table = static_cast<TrueTypeTable*>(smalloc(sizeof(TrueTypeTable))); sal_uInt8* ptr = ttmalloc(TABLESIZE_head); - PutUInt32(0x00010000, ptr, 0, 1); /* version */ - PutUInt32(fontRevision, ptr, 4, 1); - PutUInt32(0x5F0F3CF5, ptr, 12, 1); /* magic number */ - PutUInt16(flags, ptr, 16, 1); - PutUInt16(unitsPerEm, ptr, 18, 1); + PutUInt32(0x00010000, ptr, 0); /* version */ + PutUInt32(fontRevision, ptr, 4); + PutUInt32(0x5F0F3CF5, ptr, 12); /* magic number */ + PutUInt16(flags, ptr, 16); + PutUInt16(unitsPerEm, ptr, 18); memcpy(ptr+20, created, 8); /* Created Long Date */ memset(ptr+28, 0, 8); /* Modified Long Date */ - PutUInt16(macStyle, ptr, 44, 1); - PutUInt16(lowestRecPPEM, ptr, 46, 1); - PutUInt16(fontDirectionHint, ptr, 48, 1); - PutUInt16(0, ptr, 52, 1); /* glyph data format: 0 */ + PutUInt16(macStyle, ptr, 44); + PutUInt16(lowestRecPPEM, ptr, 46); + PutUInt16(fontDirectionHint, ptr, 48); + PutUInt16(0, ptr, 52); /* glyph data format: 0 */ table->data = static_cast<void *>(ptr); table->tag = T_head; @@ -928,18 +896,18 @@ TrueTypeTable *TrueTypeTableNew_hhea(sal_Int16 ascender, TrueTypeTable* table = static_cast<TrueTypeTable*>(smalloc(sizeof(TrueTypeTable))); sal_uInt8* ptr = ttmalloc(TABLESIZE_hhea); - PutUInt32(0x00010000, ptr, 0, 1); /* version */ - PutUInt16(ascender, ptr, 4, 1); - PutUInt16(descender, ptr, 6, 1); - PutUInt16(linegap, ptr, 8, 1); - PutUInt16(caretSlopeRise, ptr, 18, 1); - PutUInt16(caretSlopeRun, ptr, 20, 1); - PutUInt16(0, ptr, 22, 1); /* reserved 1 */ - PutUInt16(0, ptr, 24, 1); /* reserved 2 */ - PutUInt16(0, ptr, 26, 1); /* reserved 3 */ - PutUInt16(0, ptr, 28, 1); /* reserved 4 */ - PutUInt16(0, ptr, 30, 1); /* reserved 5 */ - PutUInt16(0, ptr, 32, 1); /* metricDataFormat */ + PutUInt32(0x00010000, ptr, 0); /* version */ + PutUInt16(ascender, ptr, 4); + PutUInt16(descender, ptr, 6); + PutUInt16(linegap, ptr, 8); + PutUInt16(caretSlopeRise, ptr, 18); + PutUInt16(caretSlopeRun, ptr, 20); + PutUInt16(0, ptr, 22); /* reserved 1 */ + PutUInt16(0, ptr, 24); /* reserved 2 */ + PutUInt16(0, ptr, 26); /* reserved 3 */ + PutUInt16(0, ptr, 28); /* reserved 4 */ + PutUInt16(0, ptr, 30); /* reserved 5 */ + PutUInt16(0, ptr, 32); /* metricDataFormat */ table->data = static_cast<void *>(ptr); table->tag = T_hhea; @@ -1304,16 +1272,16 @@ static void ProcessTables(TrueTypeCreator *tt) /* printf("IDs: %d %d.\n", gd->glyphID, gd->newID); */ if (gd->nbytes != 0) { - z = GetInt16(gd->ptr, 2, 1); + z = GetInt16(gd->ptr, 2); if (z < xMin) xMin = z; - z = GetInt16(gd->ptr, 4, 1); + z = GetInt16(gd->ptr, 4); if (z < yMin) yMin = z; - z = GetInt16(gd->ptr, 6, 1); + z = GetInt16(gd->ptr, 6); if (z > xMax) xMax = z; - z = GetInt16(gd->ptr, 8, 1); + z = GetInt16(gd->ptr, 8); if (z > yMax) yMax = z; } @@ -1346,8 +1314,8 @@ static void ProcessTables(TrueTypeCreator *tt) sal_uInt8 *ptr = gd->ptr + 10; do { sal_uInt32 j; - flags = GetUInt16(ptr, 0, 1); - index = GetUInt16(ptr, 2, 1); + flags = GetUInt16(ptr, 0); + index = GetUInt16(ptr, 2); /* XXX use the sorted array of old to new glyphID mapping and do a binary search */ for (j = 0; j < nGlyphs; j++) { if (gid[j] == index) { @@ -1356,7 +1324,7 @@ static void ProcessTables(TrueTypeCreator *tt) } /* printf("X: %d -> %d.\n", index, j); */ - PutUInt16((sal_uInt16) j, ptr, 2, 1); + PutUInt16((sal_uInt16) j, ptr, 2); ptr += 4; @@ -1380,10 +1348,10 @@ static void ProcessTables(TrueTypeCreator *tt) memcpy(p1, gd->ptr, gd->nbytes); } if (indexToLocFormat == 1) { - PutUInt32(p1 - glyfPtr, p2, 0, 1); + PutUInt32(p1 - glyfPtr, p2, 0); p2 += 4; } else { - PutUInt16((sal_uInt16)((p1 - glyfPtr) >> 1), p2, 0, 1); + PutUInt16((sal_uInt16)((p1 - glyfPtr) >> 1), p2, 0); p2 += 2; } p1 += gd->nbytes; @@ -1397,9 +1365,9 @@ static void ProcessTables(TrueTypeCreator *tt) free(gid); if (indexToLocFormat == 1) { - PutUInt32(p1 - glyfPtr, p2, 0, 1); + PutUInt32(p1 - glyfPtr, p2, 0); } else { - PutUInt16((sal_uInt16)((p1 - glyfPtr) >> 1), p2, 0, 1); + PutUInt16((sal_uInt16)((p1 - glyfPtr) >> 1), p2, 0); } glyf->rawdata = glyfPtr; @@ -1412,20 +1380,20 @@ static void ProcessTables(TrueTypeCreator *tt) head = FindTable(tt, T_head); sal_uInt8* const pHeadData = static_cast<sal_uInt8*>(head->data); - PutInt16(xMin, pHeadData, 36, 1); - PutInt16(yMin, pHeadData, 38, 1); - PutInt16(xMax, pHeadData, 40, 1); - PutInt16(yMax, pHeadData, 42, 1); - PutInt16(indexToLocFormat, pHeadData, 50, 1); + PutInt16(xMin, pHeadData, 36); + PutInt16(yMin, pHeadData, 38); + PutInt16(xMax, pHeadData, 40); + PutInt16(yMax, pHeadData, 42); + PutInt16(indexToLocFormat, pHeadData, 50); maxp = FindTable(tt, T_maxp); sal_uInt8* const pMaxpData = static_cast<sal_uInt8*>(maxp->data); - PutUInt16((sal_uInt16)nGlyphs, pMaxpData, 4, 1); - PutUInt16(maxPoints, pMaxpData, 6, 1); - PutUInt16(maxContours, pMaxpData, 8, 1); - PutUInt16(maxCompositePoints, pMaxpData, 10, 1); - PutUInt16(maxCompositeContours, pMaxpData, 12, 1); + PutUInt16((sal_uInt16)nGlyphs, pMaxpData, 4); + PutUInt16(maxPoints, pMaxpData, 6); + PutUInt16(maxContours, pMaxpData, 8); + PutUInt16(maxCompositePoints, pMaxpData, 10); + PutUInt16(maxCompositeContours, pMaxpData, 12); /* * Generate an htmx table and update hhea table @@ -1444,17 +1412,17 @@ static void ProcessTables(TrueTypeCreator *tt) for (i = 0; i < nGlyphs; i++) { if (i < nGlyphs - nlsb) { - PutUInt16(met[i].adv, p1, 0, 1); - PutUInt16(met[i].sb, p1, 2, 1); + PutUInt16(met[i].adv, p1, 0); + PutUInt16(met[i].sb, p1, 2); p1 += 4; } else { - PutUInt16(met[i].sb, p1, 0, 1); + PutUInt16(met[i].sb, p1, 0); p1 += 2; } } AddTable(tt, TrueTypeTableNew(T_hmtx, hmtxSize, hmtxPtr)); - PutUInt16((sal_uInt16)(nGlyphs - nlsb), hheaPtr, 34, 1); + PutUInt16((sal_uInt16)(nGlyphs - nlsb), hheaPtr, 34); free(hmtxPtr); free(met); } |