Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5b2f6fb

Browse files
committed
Support scale in ttf composite glyphs
Fixes #17197
1 parent 3e439a4 commit 5b2f6fb

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

extern/ttconv/pprdrv_tt.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,31 @@ Fixed getFixed(BYTE *s)
107107
return val;
108108
} /* end of getFixed() */
109109

110+
/*
111+
** Get a 16 bit fixed point (2.14) number.
112+
*/
113+
F2DOT14 getF2DOT14(BYTE *s)
114+
{
115+
F2DOT14 val={0, 0};
116+
117+
int sign = s[0] & 0x80;
118+
int bit = (s[0] & 0x40) >> 6;
119+
if (sign) {
120+
val.whole = bit-2;
121+
} else {
122+
val.whole = bit;
123+
}
124+
val.fraction = ((s[0] & 0x3f) << 8) + s[1];
125+
126+
return val;
127+
}
128+
129+
float F2DOT14value(F2DOT14 f)
130+
{
131+
return f.whole + (float)f.fraction/16384;
132+
}
133+
134+
110135
/*-----------------------------------------------------------------------
111136
** Load a TrueType font table into memory and return a pointer to it.
112137
** The font's "file" and "offset_table" fields must be set before this

extern/ttconv/pprdrv_tt2.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ void GlyphToType3::do_composite(TTStreamWriter& stream, struct TTFONT *font, BYT
417417
USHORT glyphIndex;
418418
int arg1;
419419
int arg2;
420+
F2DOT14 mat00 = {1, 0}, mat01 = {0, 0}, mat10 = {0, 0}, mat11 = {1, 0};
420421

421422
/* Once around this loop for each component. */
422423
do
@@ -444,14 +445,21 @@ void GlyphToType3::do_composite(TTStreamWriter& stream, struct TTFONT *font, BYT
444445

445446
if (flags & WE_HAVE_A_SCALE)
446447
{
448+
mat00 = mat11 = getF2DOT14(glyph);
447449
glyph += 2;
448450
}
449451
else if (flags & WE_HAVE_AN_X_AND_Y_SCALE)
450452
{
453+
mat00 = getF2DOT14(glyph);
454+
mat11 = getF2DOT14(glyph+2);
451455
glyph += 4;
452456
}
453457
else if (flags & WE_HAVE_A_TWO_BY_TWO)
454458
{
459+
mat00 = getF2DOT14(glyph);
460+
mat01 = getF2DOT14(glyph+2);
461+
mat10 = getF2DOT14(glyph+4);
462+
mat11 = getF2DOT14(glyph+6);
455463
glyph += 8;
456464
}
457465
else
@@ -472,7 +480,10 @@ void GlyphToType3::do_composite(TTStreamWriter& stream, struct TTFONT *font, BYT
472480
subglyph here. However, that doesn't seem to work with
473481
xpdf or gs (only acrobat), so instead, this just includes
474482
the subglyph here inline. */
475-
stream.printf("q 1 0 0 1 %d %d cm\n", topost(arg1), topost(arg2));
483+
stream.printf("q %.6f %.6f %.6f %.6f %d %d cm\n",
484+
F2DOT14value(mat00), F2DOT14value(mat01),
485+
F2DOT14value(mat10), F2DOT14value(mat11),
486+
topost(arg1), topost(arg2));
476487
}
477488
else
478489
{

extern/ttconv/truetype.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ typedef struct
4141
unsigned short int fraction;
4242
} Fixed;
4343

44+
/* A 2.14 fixed point number */
45+
typedef struct
46+
{
47+
SHORT whole;
48+
USHORT fraction;
49+
} F2DOT14;
50+
4451
/* This structure tells what we have found out about */
4552
/* the current font. */
4653
struct TTFONT
@@ -86,6 +93,8 @@ struct TTFONT
8693
ULONG getULONG(BYTE *p);
8794
USHORT getUSHORT(BYTE *p);
8895
Fixed getFixed(BYTE *p);
96+
F2DOT14 getF2DOT14(BYTE *p);
97+
float F2DOT14value(F2DOT14 f);
8998

9099
/*
91100
** Get an funits word.

0 commit comments

Comments
 (0)