Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tx] i586 Precision Fix #1321

Merged
merged 2 commits into from
Mar 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 35 additions & 47 deletions c/public/lib/source/t1cstr/t1cstr.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ struct t1cCtx {
int cnt;
float array[T1_MAX_OP_STACK];
} stack;
float x; /* Path x-coord */
float y; /* Path y-coord */
double x; /* Path x-coord */
double y; /* Path y-coord */
long maxOpStack;
int subrDepth;
float transformMatrix[6];
Expand Down Expand Up @@ -117,19 +117,7 @@ struct t1cCtx {
#define PUSH(v) (h->stack.array[h->stack.cnt++] = (float)(v))

#define ARRAY_LEN(a) (sizeof(a) / sizeof(a[0]))
#define RND(v) ((float)floor((v) + 0.50001))
/* The 0.000005 is added to allow for differences in OS's and other mathlibs
when blending LE's or MM's. The problem is that the differences can lead to
a final value being just a hair above .5 on one platform and a hair below on
another,leading, to off by one differences depending on which system is being
used to build the output font.
The logic 'floor(x + 0.5)' implements std Java rounding, where x.5 rounds
to (x+1), -x.5) rounds to (-x), and everything else rounds to the nearest
whole integer. The addition of 0.00001 captures everything 'close enough'
to +/- x.5 to be treated as it if were on the boundary. This number is derived
empirically, as being the smallest number that is still larger than precision
differences between Flex/Flash in TWB2, and the 64 bit C math lib.
*/
#define RND(v) ((double)floor((v) + 0.5))

/* Transform coordinates by matrix. */
#define TX(x, y) \
Expand Down Expand Up @@ -214,17 +202,17 @@ static int callbackWidth(t1cCtx h, float width) {

/* Callback path move. */
static void callbackMove(t1cCtx h, float dx, float dy) {
float x;
float y;
double x;
double y;

h->flags &= ~PEND_MOVETO;
h->flags |= SEEN_MOVETO;

x = h->x + dx;
y = h->y + dy;

x = (float)RND_ON_READ(x);
y = (float)RND_ON_READ(y);
x = (double)RND_ON_READ(x);
y = (double)RND_ON_READ(y);

if (h->seac.phase == seacAccentPreMove) {
x += h->seac.xshift;
Expand Down Expand Up @@ -261,17 +249,17 @@ static void callbackMove(t1cCtx h, float dx, float dy) {

/* Callback path line. */
static void callbackLine(t1cCtx h, float dx, float dy) {
float x;
float y;
double x;
double y;

if (h->flags & PEND_MOVETO)
callbackMove(h, 0, 0); /* Insert missing move */

x = h->x + dx;
y = h->y + dy;

x = (float)RND_ON_READ(x);
y = (float)RND_ON_READ(y);
x = (double)RND_ON_READ(x);
y = (double)RND_ON_READ(y);

h->x = x;
h->y = y;
Expand All @@ -289,12 +277,12 @@ static void callbackCurve(t1cCtx h,
float dx1, float dy1,
float dx2, float dy2,
float dx3, float dy3) {
float x1;
float y1;
float x2;
float y2;
float x3;
float y3;
double x1;
double y1;
double x2;
double y2;
double x3;
double y3;

if (h->flags & PEND_MOVETO)
callbackMove(h, 0, 0); /* Insert missing move */
Expand All @@ -305,8 +293,8 @@ static void callbackCurve(t1cCtx h,
y2 = y1 + dy2;
x3 = x2 + dx3;
y3 = y2 + dy3;
x3 = (float)RND_ON_READ(x3);
y3 = (float)RND_ON_READ(y3);
x3 = (double)RND_ON_READ(x3);
y3 = (double)RND_ON_READ(y3);
h->x = x3;
h->y = y3;

Expand Down Expand Up @@ -408,20 +396,20 @@ static void callbackFlex(t1cCtx h) {
dx6, dy6);
} else {
/* Callback as flex hint; convert to absolute coordinates */
float x1 = h->x + dx1;
float y1 = h->y + dy1;
float x2 = x1 + dx2;
float y2 = y1 + dy2;
float x3 = x2 + dx3;
float y3 = y2 + dy3;
float x4 = x3 + dx4;
float y4 = y3 + dy4;
float x5 = x4 + dx5;
float y5 = y4 + dy5;
float x6 = x5 + dx6;
float y6 = y5 + dy6;
x6 = (float)RND_ON_READ(x6);
y6 = (float)RND_ON_READ(y6);
double x1 = h->x + dx1;
double y1 = h->y + dy1;
double x2 = x1 + dx2;
double y2 = y1 + dy2;
double x3 = x2 + dx3;
double y3 = y2 + dy3;
double x4 = x3 + dx4;
double y4 = y3 + dy4;
double x5 = x4 + dx5;
double y5 = y4 + dy5;
double x6 = x5 + dx6;
double y6 = y5 + dy6;
x6 = (double)RND_ON_READ(x6);
y6 = (double)RND_ON_READ(y6);
h->x = x6;
h->y = y6;

Expand Down Expand Up @@ -476,8 +464,8 @@ static void callbackFlex(t1cCtx h) {
a closepoint-terminated subpath to a new subpath in MM fonts. */

if (h->seac.phase <= seacBase) {
h->x = (float)RND_ON_READ(args[15]);
h->y = (float)RND_ON_READ(args[16]);
h->x = (double)RND_ON_READ(args[15]);
h->y = (double)RND_ON_READ(args[16]);
}
}

Expand Down
12 changes: 6 additions & 6 deletions c/public/lib/source/t1read/t1read.c
Original file line number Diff line number Diff line change
Expand Up @@ -1653,8 +1653,8 @@ static STI parseName(t1rCtx h, int kKey) {
}

/* Parse blend array and blend elements. */
static float parseBlend(t1rCtx h, int kKey, char **str) {
float value;
static double parseBlend(t1rCtx h, int kKey, char **str) {
double value;
int i;
char *p = *str;
char delim = (*p++ == '[') ? ']' : '}';
Expand All @@ -1672,7 +1672,7 @@ static float parseBlend(t1rCtx h, int kKey, char **str) {
char *q;

/* Parse and blend number */
value += h->fd->aux.WV[i] * (float)ctuStrtod(p, &q);
value += h->fd->aux.WV[i] * (double)ctuStrtod(p, &q);
if (p == q)
badKeyValue(h, kKey); /* Invalid number */
p = q;
Expand Down Expand Up @@ -1725,7 +1725,7 @@ static float parseNum(t1rCtx h, int kKey, int round) {
case pstArray:
case pstProcedure: {
char *p = copyArrayToken(h, token);
float value = parseBlend(h, kKey, &p);
double value = parseBlend(h, kKey, &p);
return round ? RND(value) : value;
}
default:
Expand Down Expand Up @@ -1764,10 +1764,10 @@ static int parseNumArray(t1rCtx h, int kKey,
case '{':
if (blend) {
if (i < max) {
float value = parseBlend(h, kKey, &p);
double value = parseBlend(h, kKey, &p);
if (kKey == kFontBBox) {
array[i] =
(float)((i < 2) ? floor(value) : ceil(value));
(double)((i < 2) ? floor(value) : ceil(value));
i++;
} else
array[i++] = value;
Expand Down
12 changes: 6 additions & 6 deletions tests/tx_data/expected_output/zx.dump2.U_500,500.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ glyph[4] {dollar,0x24,
glyph[5] {percent,0x25,
669 width 26 95 vstem 372 441 vstem 574 643 vstem -12 36 hstem 352 401 hstem
666 714 hstem newhints 26 95 vstem 229 297 vstem 372 441 vstem 574 643 vstem
-12 36 hstem 352 401 hstem 666 714 hstem 297 533 move 297 649 246 715 162 715
curve 77 715 26 649 26 533 curve 26 419 78 352 162 352 curve 245 352 297 418
-12 36 hstem 352 401 hstem 666 714 hstem 297 533 move 297 649 246 714 162 714
curve 77 714 26 649 26 533 curve 26 419 78 352 162 352 curve 245 352 297 418
297 532 curve newhints 26 95 vstem 372 441 vstem 574 643 vstem -12 36 hstem
352 401 hstem 666 714 hstem 548 711 move 477 711 line 119 -8 line 191 -8 line
newhints 26 95 vstem 229 297 vstem 372 441 vstem 574 643 vstem -12 36 hstem
Expand Down Expand Up @@ -483,11 +483,11 @@ glyph[72] {h,0x68,
326 430 328 393 328 350 curve 328 0 line endchar}
glyph[73] {i,0x69,
195 width 54 141 vstem 0 bottomedge 532 topedge 643 731 hstem 141 643 move
141 731 line 54 731 line 54 643 line 141 532 move 54 532 line 54 0 line 141 0
141 731 line 54 731 line 54 642 line 141 532 move 54 532 line 54 0 line 141 0
line endchar}
glyph[74] {j,0x6A,
195 width 53 141 vstem -241 -181 hstem 532 topedge 643 731 hstem 141 643 move
141 731 line 53 731 line 53 643 line -123 -212 move -105 -221 -87 -228 -69
141 731 line 53 731 line 53 642 line -123 -212 move -105 -221 -87 -228 -69
-233 curve -51 -238 -32 -241 -10 -241 curve 41 -241 80 -225 105 -191 curve
130 -156 141 -104 141 -21 curve 141 532 line 54 532 line 54 -36 line 54 -93
49 -129 36 -153 curve 22 -172 -1 -181 -22 -181 curve -42 -181 -54 -177 -63
Expand Down Expand Up @@ -829,7 +829,7 @@ glyph[120] {ellipsis,0xBC,
glyph[121] {perthousand,0xBD,
981 width 26 95 vstem 372 441 vstem 684 753 vstem 886 955 vstem -12 36 hstem
301 350 hstem 666 714 hstem newhints 26 95 vstem 229 297 vstem 352 401 hstem
666 714 hstem 297 533 move 297 649 246 715 162 715 curve 77 715 26 649 26 533
666 714 hstem 297 533 move 297 649 246 714 162 714 curve 77 714 26 649 26 533
curve 26 419 78 352 162 352 curve 245 352 297 418 297 532 curve newhints 26
95 vstem -12 36 hstem 666 714 hstem 548 711 move 477 711 line 119 -8 line 191
-8 line newhints 26 95 vstem 229 297 vstem 352 401 hstem 666 714 hstem 162
Expand Down Expand Up @@ -1493,4 +1493,4 @@ glyph[227] {yacute,-,
glyph[228] {ydieresis,-,
413 width 62 0 121 200 seac endchar}
glyph[229] {zcaron,-,
345 width 22 0 122 207 seac endchar}
345 width 22 0 122 207 seac endchar}
4 changes: 2 additions & 2 deletions tests/tx_data/expected_output/zx.dump2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ glyph[3] {numbersign,0x23,
glyph[4] {dollar,0x24,
625 width 81 165 vstem 287 337 vstem 469 554 vstem 12 67 hstem 620 675 hstem
337 620 move 405 616 434 579 447 541 curve 529 546 line 507 620 450 669 337
675 curve 337 750 line 287 750 line 287 675 line 126 670 81 594 81 519 curve
675 curve 337 749 line 287 749 line 287 675 line 126 670 81 594 81 519 curve
81 395 201 366 287 329 curve 287 67 line 222 71 177 100 151 155 curve 69 148
line 98 61 174 16 287 12 curve 287 -70 line 337 -70 line 337 13 line 476 20
554 100 554 198 curve 554 322 422 356 337 394 curve 287 412 move 236 437 165
Expand Down Expand Up @@ -1500,4 +1500,4 @@ glyph[227] {yacute,-,
glyph[228] {ydieresis,-,
534 width 77 0 121 200 seac endchar}
glyph[229] {zcaron,-,
452 width 23 0 122 207 seac endchar}
452 width 23 0 122 207 seac endchar}
8 changes: 4 additions & 4 deletions tests/tx_data/expected_output/zy.dump2.U_500,500.txt
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ glyph[23] {seven,0x37,
endchar}
glyph[24] {eight,0x38,
723 width 46 202 vstem 511 680 vstem -14 38 hstem 653 705 hstem 354 -14 move
471 -14 553 10 604 48 curve 657 86 680 140 680 196 curve 680 250 650 294 610
471 -14 553 10 604 48 curve 656 86 680 140 680 196 curve 680 250 650 294 610
327 curve 580 353 539 376 492 394 curve 492 397 line newhints 76 231 vstem
496 650 vstem -14 38 hstem 653 705 hstem 544 413 578 431 602 451 curve 634
478 650 508 650 546 curve 650 597 616 637 570 662 curve 513 692 438 705 364
Expand Down Expand Up @@ -1054,8 +1054,8 @@ glyph[114] {paragraph,0xB6,
155 332 202 320 260 320 curve 260 -33 line 260 -93 255 -97 179 -97 curve 179
-143 line 319 -143 line 319 662 line endchar}
glyph[115] {bullet,0xB7,
524 width 104 421 vstem 182 500 hstem 262 500 move 175 500 104 429 104 341
curve 104 254 175 182 262 182 curve 350 182 421 253 421 341 curve 421 428 350
524 width 104 421 vstem 182 500 hstem 262 500 move 175 500 104 428 104 341
curve 104 253 175 182 262 182 curve 350 182 421 253 421 341 curve 421 428 350
500 263 500 curve endchar}
glyph[116] {quotesinglbase,0xB8,
262 width 146 206 vstem -10 bottomedge 92 -137 move newhints 146 206 vstem
Expand Down Expand Up @@ -1999,4 +1999,4 @@ glyph[227] {yacute,-,
glyph[228] {ydieresis,-,
628 width 118 0 121 200 seac endchar}
glyph[229] {zcaron,-,
540 width 38 0 122 207 seac endchar}
540 width 38 0 122 207 seac endchar}
20 changes: 10 additions & 10 deletions tests/tx_data/expected_output/zy.dump2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
version "001.003"
Notice "Copyright (c) 1992, 1993, 1994, 1999 Adobe Systems Incorporated. All Rights Reserved."
Weight "SnapShotMM"
FontBBox {-157,-257,1195,911}
FontBBox {-157,-258,1195,911}
XUID {1,44277,17709,6867,29516,11444,300,600}
sup.srcFontType Type 1 (name-keyed)
sup.nGlyphs 230
Expand Down Expand Up @@ -1214,7 +1214,7 @@ glyph[137] {AE,0xE1,
580 vstem 774 818 vstem 0 35 hstem 233 277 hstem 347 391 hstem 665 709 hstem
197 35 line 138 35 126 48 156 103 curve 226 233 line 478 233 line 478 114
line 478 43 471 35 402 35 curve newhints 478 580 vstem 774 818 vstem 0 44
hstem 233 277 hstem 347 391 hstem 665 709 hstem 402 0 line 916 0 line 950 160
hstem 233 277 hstem 347 391 hstem 665 709 hstem 402 0 line 915 0 line 950 160
line 906 160 line 879 50 868 44 811 44 curve 608 44 line 588 44 580 48 580 86
curve 580 347 line 723 347 line 767 347 774 340 774 247 curve 818 247 line
newhints 478 580 vstem 774 818 vstem 0 44 hstem 233 277 hstem 347 488 hstem
Expand Down Expand Up @@ -1412,7 +1412,7 @@ glyph[154] {eth,-,
curve 525 709 line newhints 45 145 vstem 484 585 vstem -12 24 hstem 456 492
hstem 713 737 hstem 510 737 line newhints 45 145 vstem 484 585 vstem -12 24
hstem 456 492 hstem 713 739 hstem 382 675 line 322 708 250 731 168 739 curve
132 713 line 201 700 264 681 317 649 curve 172 579 line 187 551 line 348 626
132 713 line 201 700 264 681 317 649 curve 172 579 line 187 550 line 348 626
line 381 601 411 571 433 534 curve 454 499 470 459 483 409 curve 479 408 line
newhints 45 145 vstem 484 585 vstem -12 24 hstem 456 492 hstem 713 739 hstem
451 455 401 492 311 492 curve 315 456 move 367 456 408 439 436 407 curve 469
Expand Down Expand Up @@ -1489,8 +1489,8 @@ glyph[162] {Acircumflex,-,
line 660 35 646 46 624 102 curve 370 723 line 314 723 line 84 89 line 68 45
53 35 19 35 curve 19 0 line 189 0 line 189 35 line 129 35 125 47 145 107
curve 183 222 line 453 266 move 199 266 line 317 602 line 321 602 line 343
819 move 506 764 line 523 796 line 343 891 line 340 891 line 160 796 line 177
764 line 341 819 line endchar}
819 move 506 763 line 523 796 line 343 891 line 340 891 line 160 796 line 177
763 line 341 819 line endchar}
glyph[163] {Zcaron,-,
648 width 28 616 vstem 0 44 hstem 665 709 hstem 470 665 move 28 26 line 44 0
line 585 0 line 616 163 line 571 163 line 544 53 531 44 458 44 curve 163 44
Expand Down Expand Up @@ -1718,8 +1718,8 @@ glyph[184] {Ucircumflex,-,
247 line 110 150 129 82 186 38 curve 233 1 303 -14 390 -14 curve 473 -14 536
7 579 48 curve 623 90 646 150 646 239 curve 646 597 line 646 667 652 674 719
674 curve 719 709 line 521 709 line 521 674 line 589 674 596 668 596 597
curve 394 819 move 557 764 line 574 796 line 394 891 line 391 891 line 211
796 line 228 764 line 392 819 line endchar}
curve 394 819 move 557 763 line 574 796 line 394 891 line 391 891 line 211
796 line 228 763 line 392 819 line endchar}
glyph[185] {Ydieresis,-,
703 width 18 202 vstem 210 311 vstem 307 409 vstem 436 537 vstem 567 688
vstem 0 35 hstem 674 709 hstem 773 874 hstem 307 310 move 307 112 line 307 42
Expand Down Expand Up @@ -1935,8 +1935,8 @@ glyph[200] {Icircumflex,-,
350 width 124 226 vstem 0 35 hstem 674 709 hstem 124 112 move 124 42 119 35
33 35 curve 33 0 line 317 0 line 317 35 line 231 35 226 42 226 112 curve 226
597 line 226 667 231 674 316 674 curve 316 709 line 33 709 line 33 674 line
119 674 124 667 124 597 curve 176 819 move 339 764 line 357 796 line 176 891
line 174 891 line -7 796 line 10 764 line 174 819 line endchar}
119 674 124 667 124 597 curve 176 819 move 339 763 line 357 796 line 176 891
line 174 891 line -7 796 line 10 763 line 174 819 line endchar}
glyph[201] {Iacute,-,
350 width 124 226 vstem 0 35 hstem 674 709 hstem 124 112 move 124 42 119 35
33 35 curve 33 0 line 317 0 line 317 35 line 231 35 226 42 226 112 curve 226
Expand Down Expand Up @@ -1998,4 +1998,4 @@ glyph[227] {yacute,-,
glyph[228] {ydieresis,-,
588 width 97 0 121 200 seac endchar}
glyph[229] {zcaron,-,
506 width 32 0 122 207 seac endchar}
506 width 32 0 122 207 seac endchar}