[Libreoffice-commits] core.git: vcl/inc vcl/source

Julien Nabet (via logerrit) logerrit at kemper.freedesktop.org
Sun Oct 13 17:47:14 UTC 2019


 vcl/inc/sft.hxx                |   23 ++++++++++++++++++
 vcl/source/fontsubset/sft.cxx  |   52 +++++++++++------------------------------
 vcl/source/fontsubset/ttcr.cxx |   32 +++++++------------------
 vcl/source/fontsubset/ttcr.hxx |    4 +--
 4 files changed, 49 insertions(+), 62 deletions(-)

New commits:
commit a17fb721bd0b6ddde88c4aaf3ceba9650f4e7879
Author:     Julien Nabet <serval2412 at yahoo.fr>
AuthorDate: Sun Oct 13 13:51:39 2019 +0200
Commit:     Julien Nabet <serval2412 at yahoo.fr>
CommitDate: Sun Oct 13 19:46:37 2019 +0200

    Refactor + fix TrueTypeTableNew_post + some reading types for sft/ttcr (vcl)
    
    Move const in sft.hxx and replace define by static const
    Also, fix some errors with data formats
    + TrueTypeTableNew_post definition
    Following https://docs.microsoft.com/en-us/typography/opentype/spec/otff:
    Fixed = 32-bit signed fixed-point number (16.16)
    FWORD = int16
    UFWORD = uint16
    
    Change-Id: I8c460e517b9f25077f5ad81a6da656695c8e6fa1
    Reviewed-on: https://gerrit.libreoffice.org/80733
    Tested-by: Jenkins
    Reviewed-by: Julien Nabet <serval2412 at yahoo.fr>

diff --git a/vcl/inc/sft.hxx b/vcl/inc/sft.hxx
index 27a5093e61e7..e52657fe4933 100644
--- a/vcl/inc/sft.hxx
+++ b/vcl/inc/sft.hxx
@@ -425,6 +425,29 @@ static const int GLYF_yMin_offset = 4;
 static const int GLYF_xMax_offset = 6;
 static const int GLYF_yMax_offset = 8;
 
+static const sal_uInt32 T_true = 0x74727565;        /* 'true' */
+static const sal_uInt32 T_ttcf = 0x74746366;        /* 'ttcf' */
+static const sal_uInt32 T_otto = 0x4f54544f;        /* 'OTTO' */
+
+// standard TrueType table tags
+static const sal_uInt32 T_maxp = 0x6D617870;
+static const sal_uInt32 T_glyf = 0x676C7966;
+static const sal_uInt32 T_head = 0x68656164;
+static const sal_uInt32 T_loca = 0x6C6F6361;
+static const sal_uInt32 T_name = 0x6E616D65;
+static const sal_uInt32 T_hhea = 0x68686561;
+static const sal_uInt32 T_hmtx = 0x686D7478;
+static const sal_uInt32 T_cmap = 0x636D6170;
+static const sal_uInt32 T_vhea = 0x76686561;
+static const sal_uInt32 T_vmtx = 0x766D7478;
+static const sal_uInt32 T_OS2  = 0x4F532F32;
+static const sal_uInt32 T_post = 0x706F7374;
+static const sal_uInt32 T_cvt  = 0x63767420;
+static const sal_uInt32 T_prep = 0x70726570;
+static const sal_uInt32 T_fpgm = 0x6670676D;
+static const sal_uInt32 T_gsub = 0x47535542;
+static const sal_uInt32 T_CFF  = 0x43464620;
+
 
 /**
  * @defgroup sft Sun Font Tools Exported Functions
diff --git a/vcl/source/fontsubset/sft.cxx b/vcl/source/fontsubset/sft.cxx
index 7c527887dc65..2f29ca97cbd3 100644
--- a/vcl/source/fontsubset/sft.cxx
+++ b/vcl/source/fontsubset/sft.cxx
@@ -103,29 +103,6 @@ struct GlyphOffsets {
     sal_uInt32 *offs;             /* array of nGlyphs offsets */
 };
 
-static const sal_uInt32 T_true = 0x74727565;        /* 'true' */
-static const sal_uInt32 T_ttcf = 0x74746366;        /* 'ttcf' */
-static const sal_uInt32 T_otto = 0x4f54544f;        /* 'OTTO' */
-
-/* standard TrueType table tags */
-#define T_maxp 0x6D617870
-#define T_glyf 0x676C7966
-#define T_head 0x68656164
-#define T_loca 0x6C6F6361
-#define T_name 0x6E616D65
-#define T_hhea 0x68686561
-#define T_hmtx 0x686D7478
-#define T_cmap 0x636D6170
-#define T_vhea 0x76686561
-#define T_vmtx 0x766D7478
-#define T_OS2  0x4F532F32
-#define T_post 0x706F7374
-#define T_cvt  0x63767420
-#define T_prep 0x70726570
-#define T_fpgm 0x6670676D
-#define T_gsub 0x47535542
-#define T_CFF  0x43464620
-
 static void *smalloc(size_t size)
 {
     void *res = malloc(size);
@@ -1937,7 +1914,7 @@ SFErrCodes CreateTTFromTTGlyphs(TrueTypeFont  *ttf,
     /**                       hhea                         **/
     const sal_uInt8* p = getTable(ttf, O_hhea);
     if (p) {
-        hhea = TrueTypeTableNew_hhea(GetUInt16(p, HHEA_ascender_offset), GetUInt16(p, HHEA_descender_offset), GetUInt16(p, HHEA_lineGap_offset), GetUInt16(p, HHEA_caretSlopeRise_offset), GetUInt16(p, HHEA_caretSlopeRun_offset));
+        hhea = TrueTypeTableNew_hhea(GetInt16(p, HHEA_ascender_offset), GetInt16(p, HHEA_descender_offset), GetInt16(p, HHEA_lineGap_offset), GetInt16(p, HHEA_caretSlopeRise_offset), GetInt16(p, HHEA_caretSlopeRun_offset));
     } else {
         hhea = TrueTypeTableNew_hhea(0, 0, 0, 0, 0);
     }
@@ -1946,7 +1923,7 @@ SFErrCodes CreateTTFromTTGlyphs(TrueTypeFont  *ttf,
 
     p = getTable(ttf, O_head);
     assert(p != nullptr);
-    head = TrueTypeTableNew_head(GetUInt32(p, HEAD_fontRevision_offset),
+    head = TrueTypeTableNew_head(GetInt32(p, HEAD_fontRevision_offset),
                                  GetUInt16(p, HEAD_flags_offset),
                                  GetUInt16(p, HEAD_unitsPerEm_offset),
                                  p+HEAD_created_offset,
@@ -1988,10 +1965,10 @@ SFErrCodes CreateTTFromTTGlyphs(TrueTypeFont  *ttf,
     /**                       post                          **/
     if ((p = getTable(ttf, O_post)) != nullptr) {
         post = TrueTypeTableNew_post(0x00030000,
-                                     GetUInt32(p, POST_italicAngle_offset),
-                                     GetUInt16(p, POST_underlinePosition_offset),
-                                     GetUInt16(p, POST_underlineThickness_offset),
-                                     GetUInt16(p, POST_isFixedPitch_offset));
+                                     GetInt32(p, POST_italicAngle_offset),
+                                     GetInt16(p, POST_underlinePosition_offset),
+                                     GetInt16(p, POST_underlineThickness_offset),
+                                     GetUInt32(p, POST_isFixedPitch_offset));
     } else {
         post = TrueTypeTableNew_post(0x00030000, 0, 0, 0, 0);
     }
@@ -2171,7 +2148,8 @@ SFErrCodes CreateT42FromTTGlyphs(TrueTypeFont  *ttf,
     int i;
     SFErrCodes res;
 
-    sal_uInt32 ver, rev;
+    sal_uInt16 ver;
+    sal_Int32 rev;
 
     sal_uInt8 *sfntP;
     sal_uInt32 sfntLen;
@@ -2187,14 +2165,14 @@ SFErrCodes CreateT42FromTTGlyphs(TrueTypeFont  *ttf,
     const sal_uInt8* p = getTable(ttf, O_head);
     const sal_uInt8* headP = p;
     assert(p != nullptr);
-    head = TrueTypeTableNew_head(GetUInt32(p, 4), GetUInt16(p, 16), GetUInt16(p, 18), p+20, GetUInt16(p, 44), GetUInt16(p, 46), GetInt16(p, 48));
-    ver = GetUInt32(p, 0);
-    rev = GetUInt32(p, 4);
+    head = TrueTypeTableNew_head(GetInt32(p, HEAD_fontRevision_offset), GetUInt16(p, HEAD_flags_offset), GetUInt16(p, HEAD_unitsPerEm_offset), p+HEAD_created_offset, GetUInt16(p, HEAD_macStyle_offset), GetUInt16(p, HEAD_lowestRecPPEM_offset), GetInt16(p, HEAD_fontDirectionHint_offset));
+    ver = GetUInt16(p, HEAD_majorVersion_offset);
+    rev = GetInt32(p, HEAD_fontRevision_offset);
 
     /**                       hhea                         **/
     p = getTable(ttf, O_hhea);
     if (p) {
-        hhea = TrueTypeTableNew_hhea(GetUInt16(p, 4), GetUInt16(p, 6), GetUInt16(p, 8), GetUInt16(p, 18), GetUInt16(p, 20));
+        hhea = TrueTypeTableNew_hhea(GetInt16(p, HHEA_ascender_offset), GetInt16(p, HHEA_descender_offset), GetInt16(p, HHEA_lineGap_offset), GetInt16(p, HHEA_caretSlopeRise_offset), GetInt16(p, HHEA_caretSlopeRun_offset));
     } else {
         hhea = TrueTypeTableNew_hhea(0, 0, 0, 0, 0);
     }
@@ -2234,7 +2212,7 @@ SFErrCodes CreateT42FromTTGlyphs(TrueTypeFont  *ttf,
         return res;
     }
 
-    fprintf(outf, "%%!PS-TrueTypeFont-%d.%d-%d.%d\n", static_cast<int>(ver>>16), static_cast<int>(ver & 0xFFFF), static_cast<int>(rev>>16), static_cast<int>(rev & 0xFFFF));
+    fprintf(outf, "%%!PS-TrueTypeFont-%d.%d-%d.%d\n", static_cast<int>(ver), static_cast<int>(ver & 0xFF), static_cast<int>(rev>>16), static_cast<int>(rev & 0xFFFF));
     fprintf(outf, "%%%%Creator: %s %s %s\n", modname, modver, modextra);
     fprintf(outf, "%%- Font subset generated from a source font file: '%s'\n", ttf->fname);
     fprintf(outf, "%%- Original font name: %s\n", ttf->psname);
@@ -2244,7 +2222,7 @@ SFErrCodes CreateT42FromTTGlyphs(TrueTypeFont  *ttf,
     fprintf(outf, "/FontName (%s) cvn def\n", psname);
     fprintf(outf, "/PaintType 0 def\n");
     fprintf(outf, "/FontMatrix [1 0 0 1 0 0] def\n");
-    fprintf(outf, "/FontBBox [%d %d %d %d] def\n", XUnits(UPEm, GetInt16(headP, 36)), XUnits(UPEm, GetInt16(headP, 38)), XUnits(UPEm, GetInt16(headP, 40)), XUnits(UPEm, GetInt16(headP, 42)));
+    fprintf(outf, "/FontBBox [%d %d %d %d] def\n", XUnits(UPEm, GetInt16(headP, HEAD_xMin_offset)), XUnits(UPEm, GetInt16(headP, HEAD_yMin_offset)), XUnits(UPEm, GetInt16(headP, HEAD_xMax_offset)), XUnits(UPEm, GetInt16(headP, HEAD_yMax_offset)));
     fprintf(outf, "/FontType 42 def\n");
     fprintf(outf, "/Encoding 256 array def\n");
     fprintf(outf, "    0 1 255 {Encoding exch /.notdef put} for\n");
@@ -2429,7 +2407,7 @@ void GetTTGlobalFontInfo(TrueTypeFont *ttf, TTGlobalFontInfo *info)
         info->yMin = XUnits(UPEm, GetInt16(table, HEAD_yMin_offset));
         info->xMax = XUnits(UPEm, GetInt16(table, HEAD_xMax_offset));
         info->yMax = XUnits(UPEm, GetInt16(table, HEAD_yMax_offset));
-        info->macStyle = GetInt16(table, HEAD_macStyle_offset);
+        info->macStyle = GetUInt16(table, HEAD_macStyle_offset);
     }
 
     table = getTable(ttf, O_hhea);
diff --git a/vcl/source/fontsubset/ttcr.cxx b/vcl/source/fontsubset/ttcr.cxx
index f6d78ef5520c..e78f6d01853b 100644
--- a/vcl/source/fontsubset/ttcr.cxx
+++ b/vcl/source/fontsubset/ttcr.cxx
@@ -39,17 +39,6 @@ namespace vcl
         list   tables;                      /**< List of table tags and pointers */
     };
 
-/* These must be #defined so that they can be used in initializers */
-#define T_maxp  0x6D617870
-#define T_glyf  0x676C7966
-#define T_head  0x68656164
-#define T_loca  0x6C6F6361
-#define T_name  0x6E616D65
-#define T_hhea  0x68686561
-#define T_hmtx  0x686D7478
-#define T_cmap  0x636D6170
-#define T_post  0x706F7374
-
 struct TableEntry {
     sal_uInt32 tag;
     sal_uInt32 length;
@@ -1016,8 +1005,8 @@ TrueTypeTable *TrueTypeTableNew_name(int n, NameRecord const *nr)
     return table;
 }
 
-TrueTypeTable *TrueTypeTableNew_post(sal_uInt32 format,
-                                     sal_uInt32 italicAngle,
+TrueTypeTable *TrueTypeTableNew_post(sal_Int32 format,
+                                     sal_Int32 italicAngle,
                                      sal_Int16 underlinePosition,
                                      sal_Int16 underlineThickness,
                                      sal_uInt32 isFixedPitch)
@@ -1459,7 +1448,7 @@ static sal_uInt32 mkTag(sal_uInt8 a, sal_uInt8 b, sal_uInt8 c, sal_uInt8 d) {
 int main()
 {
     TrueTypeCreator *ttcr;
-    sal_uInt8 *t1, *t2, *t3, *t4, *t5, *t6, *t7;
+    sal_uInt8 *t1, *t2, *t3, *t4, *t5, *t6;
 
     TrueTypeCreatorNewEmpty(mkTag('t','r','u','e'), &ttcr);
 
@@ -1469,15 +1458,13 @@ int main()
     t4 = malloc(4000); memset(t4, 'd', 4000);
     t5 = malloc(5000); memset(t5, 'e', 5000);
     t6 = malloc(6000); memset(t6, 'f', 6000);
-    t7 = malloc(7000); memset(t7, 'g', 7000);
 
-    AddTable(ttcr, TrueTypeTableNew(0x6D617870, 1000, t1));
-    AddTable(ttcr, TrueTypeTableNew(0x4F532F32, 2000, t2));
-    AddTable(ttcr, TrueTypeTableNew(0x636D6170, 3000, t3));
-    AddTable(ttcr, TrueTypeTableNew(0x6C6F6361, 4000, t4));
-    AddTable(ttcr, TrueTypeTableNew(0x68686561, 5000, t5));
-    AddTable(ttcr, TrueTypeTableNew(0x676C7966, 6000, t6));
-    AddTable(ttcr, TrueTypeTableNew(0x6B65726E, 7000, t7));
+    AddTable(ttcr, TrueTypeTableNew(T_maxp, 1000, t1));
+    AddTable(ttcr, TrueTypeTableNew(T_OS2, 2000, t2));
+    AddTable(ttcr, TrueTypeTableNew(T_cmap, 3000, t3));
+    AddTable(ttcr, TrueTypeTableNew(T_loca, 4000, t4));
+    AddTable(ttcr, TrueTypeTableNew(T_hhea, 5000, t5));
+    AddTable(ttcr, TrueTypeTableNew(T_glyf, 6000, t6));
 
     free(t1);
     free(t2);
@@ -1485,7 +1472,6 @@ int main()
     free(t4);
     free(t5);
     free(t6);
-    free(t7);
 
     StreamToFile(ttcr, "ttcrout.ttf");
 
diff --git a/vcl/source/fontsubset/ttcr.hxx b/vcl/source/fontsubset/ttcr.hxx
index f30111af4b57..26298f78cafd 100644
--- a/vcl/source/fontsubset/ttcr.hxx
+++ b/vcl/source/fontsubset/ttcr.hxx
@@ -171,8 +171,8 @@ namespace vcl
 /**
  * Creates a new 'post' table of one of the supported formats
  */
-    TrueTypeTable *TrueTypeTableNew_post(sal_uInt32 format,
-                                         sal_uInt32 italicAngle,
+    TrueTypeTable *TrueTypeTableNew_post(sal_Int32 format,
+                                         sal_Int32 italicAngle,
                                          sal_Int16 underlinePosition,
                                          sal_Int16 underlineThickness,
                                          sal_uInt32 isFixedPitch);


More information about the Libreoffice-commits mailing list