History

ComponentGlyf reader: fix F2DOT14 parsing

Sigrid Solveig Haflínudóttir committed 2 years ago

Commit 1d352251 parent 96da9f02 files · +18 −14Browse files

Unified · Split

2 files
  1. otf.c.in +9 −7
  2. plan9/otf.c +9 −7
otf.c.in+9−7
@@ -264,6 +264,7 @@ read_ComponentGlyph(Otf *o, ComponentGlyph **out, int instr) · 263 unmodified lines
264264 {
265265 ComponentGlyph *v;
266266 u8int *b;
267+ s16int f;
267268
268269 if((v = calloc(1, sizeof(*v))) == nil){
269270 nomem:
@@ -296,16 +297,17 @@ nomem: · 26 unmodified lines
296297 }
297298 if(b == nil)
298299 goto err;
300+ #define f2dot14(o) (f = b[2*o]<<8 | b[2*o+1], (f>>14)+(f&((1<<14)-1))/16384.0)
299301 if((v->flags & CGLYPH_FL_SCALE) != 0 && (b = otfreadn(o, 2)) != nil){
300− v->scale = (b[0]<<8 | b[1]>>14)+(b[0]<<8 | b[1]&((1<<14)-1))/16384.0;
302+ v->scale = f2dot14(0);
301303 }else if((v->flags & CGLYPH_FL_SCALE_XY) != 0 && (b = otfreadn(o, 2*2)) != nil){
302− v->scaleX = (b[0]<<8 | b[1]>>14)+(b[0]<<8 | b[1]&((1<<14)-1))/16384.0;
303− v->scaleY = (b[2]<<8 | b[3]>>14)+(b[2]<<8 | b[3]&((1<<14)-1))/16384.0;
304+ v->scaleX = f2dot14(0);
305+ v->scaleY = f2dot14(1);
304306 }else if((v->flags & CGLYPH_FL_2X2_TRANSFORM) != 0 && (b = otfreadn(o, 2*2*2)) != nil){
305− v->scaleX = (b[0]<<8 | b[1]>>14)+(b[0]<<8 | b[1]&((1<<14)-1))/16384.0;
306− v->scale01 = (b[2]<<8 | b[3]>>14)+(b[2]<<8 | b[3]&((1<<14)-1))/16384.0;
307− v->scale10 = (b[4]<<8 | b[5]>>14)+(b[4]<<8 | b[5]&((1<<14)-1))/16384.0;
308− v->scaleY = (b[6]<<8 | b[7]>>14)+(b[6]<<8 | b[7]&((1<<14)-1))/16384.0;
307+ v->scaleX = f2dot14(0);
308+ v->scale01 = f2dot14(1);
309+ v->scale10 = f2dot14(2);
310+ v->scaleY = f2dot14(3);
309311 }
310312 if(b == nil)
311313 goto err;
plan9/otf.c+9−7
@@ -278,6 +278,7 @@ read_ComponentGlyph(Otf *o, ComponentGlyph **out, int instr) · 277 unmodified lines
278278 {
279279 ComponentGlyph *v;
280280 u8int *b;
281+ s16int f;
281282
282283 if((v = calloc(1, sizeof(*v))) == nil){
283284 nomem:
@@ -310,16 +311,17 @@ nomem: · 26 unmodified lines
310311 }
311312 if(b == nil)
312313 goto err;
314+ #define f2dot14(o) (f = b[2*o]<<8 | b[2*o+1], (f>>14)+(f&((1<<14)-1))/16384.0)
313315 if((v->flags & CGLYPH_FL_SCALE) != 0 && (b = otfreadn(o, 2)) != nil){
314− v->scale = (b[0]<<8 | b[1]>>14)+(b[0]<<8 | b[1]&((1<<14)-1))/16384.0;
316+ v->scale = f2dot14(0);
315317 }else if((v->flags & CGLYPH_FL_SCALE_XY) != 0 && (b = otfreadn(o, 2*2)) != nil){
316− v->scaleX = (b[0]<<8 | b[1]>>14)+(b[0]<<8 | b[1]&((1<<14)-1))/16384.0;
317− v->scaleY = (b[2]<<8 | b[3]>>14)+(b[2]<<8 | b[3]&((1<<14)-1))/16384.0;
318+ v->scaleX = f2dot14(0);
319+ v->scaleY = f2dot14(1);
318320 }else if((v->flags & CGLYPH_FL_2X2_TRANSFORM) != 0 && (b = otfreadn(o, 2*2*2)) != nil){
319− v->scaleX = (b[0]<<8 | b[1]>>14)+(b[0]<<8 | b[1]&((1<<14)-1))/16384.0;
320− v->scale01 = (b[2]<<8 | b[3]>>14)+(b[2]<<8 | b[3]&((1<<14)-1))/16384.0;
321− v->scale10 = (b[4]<<8 | b[5]>>14)+(b[4]<<8 | b[5]&((1<<14)-1))/16384.0;
322− v->scaleY = (b[6]<<8 | b[7]>>14)+(b[6]<<8 | b[7]&((1<<14)-1))/16384.0;
321+ v->scaleX = f2dot14(0);
322+ v->scale01 = f2dot14(1);
323+ v->scale10 = f2dot14(2);
324+ v->scaleY = f2dot14(3);
323325 }
324326 if(b == nil)
325327 goto err;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t