Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit a40b154

Browse files
Remove the old "ascent" and "descent" metrics from MCFontStruct
Any places that they were referenced are updated to use the new metrics (which separates leading from the other two).
1 parent 959e99b commit a40b154

File tree

10 files changed

+25
-71
lines changed

10 files changed

+25
-71
lines changed

engine/src/em-fontlist.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,6 @@ MCFontnode::MCFontnode(MCNameRef p_name,
7070
// Load the font as requested
7171
m_font_info.fid = emscripten_get_font_by_name(p_name);
7272

73-
/* FIXME Dummy values */
74-
m_font_info.size = p_size;
75-
m_font_info.ascent = p_size - 1;
76-
m_font_info.descent = p_size * 2 / 14 + 1;
77-
7873
//MCLog("Created dummy font: %@ %hi %hi", p_name, p_size, p_style);
7974
}
8075

engine/src/graphics_util.h

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,9 @@ static inline MCGFont MCFontStructToMCGFont(MCFontStruct *p_font)
343343

344344
MCGFont t_font;
345345
t_font . size = t_android_font -> size;
346-
t_font . ascent = p_font -> ascent;
347-
t_font . descent = p_font -> descent;
346+
t_font . m_ascent = p_font -> m_ascent;
347+
t_font . m_descent = p_font -> m_descent;
348+
t_font . m_leading = p_font -> m_leading;
348349
t_font . fid = t_android_font -> typeface;
349350
t_font . ideal = false;
350351
return t_font;
@@ -364,8 +365,9 @@ static inline MCGFont MCFontStructToMCGFont(MCFontStruct *p_font)
364365
}
365366

366367
t_font . size = p_font -> size;
367-
t_font . ascent = p_font -> ascent;
368-
t_font . descent = p_font -> descent;
368+
t_font . m_ascent = p_font -> m_ascent;
369+
t_font . m_descent = p_font -> m_descent;
370+
t_font . m_leading = p_font -> m_leading;
369371
t_font . fid = static_cast<MCNewFontStruct *>(p_font) -> description;
370372
t_font . ideal = false;
371373
return t_font;
@@ -383,8 +385,9 @@ static inline MCGFont MCFontStructToMCGFont(MCFontStruct *p_font)
383385
}
384386

385387
t_font . size = p_font -> size;
386-
t_font . ascent = p_font -> ascent;
387-
t_font . descent = p_font -> descent;
388+
t_font . m_ascent = p_font -> m_ascent;
389+
t_font . m_descent = p_font -> m_descent;
390+
t_font . m_leading = p_font -> m_leading;
388391
t_font . fid = p_font -> fid;
389392
t_font . ideal = p_font -> printer == True;
390393
return t_font;
@@ -396,8 +399,9 @@ static inline MCGFont MCFontStructToMCGFont(MCFontStruct *p_font)
396399
{
397400
MCGFont t_font;
398401
t_font . size = p_font -> size;
399-
t_font . ascent = p_font -> ascent;
400-
t_font . descent = p_font -> descent;
402+
t_font . m_ascent = p_font -> m_ascent;
403+
t_font . m_descent = p_font -> m_descent;
404+
t_font . m_leading = p_font -> m_leading;
401405
t_font . fid = p_font -> fid;
402406
t_font . ideal = false;
403407
return t_font;
@@ -412,8 +416,9 @@ MCFontStructToMCGFont(MCFontStruct *p_font)
412416
MCMemoryClear(&t_font, sizeof(t_font));
413417

414418
t_font . size = p_font -> size;
415-
t_font . ascent = p_font -> ascent;
416-
t_font . descent = p_font -> descent;
419+
t_font . m_ascent = p_font -> m_ascent;
420+
t_font . m_descent = p_font -> m_descent;
421+
t_font . m_leading = p_font -> m_leading;
417422
t_font . fid = p_font -> fid;
418423
t_font . ideal = false;
419424

engine/src/lnxflst.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -201,17 +201,6 @@ MCFontStruct *MCNewFontlist::getfont(MCNameRef p_family, uint2& p_size, uint2 p_
201201
t_descent = t_face -> size -> metrics . descender / 64;
202202
t_height = t_face -> size -> metrics . height / 64.0;
203203

204-
if (t_ascent <= p_size)
205-
{
206-
t_font -> ascent = t_ascent;
207-
t_font -> descent = t_height - t_ascent;
208-
}
209-
else
210-
{
211-
t_font -> ascent = p_size * 7 / 8;
212-
t_font -> descent = t_height - t_ascent;
213-
}
214-
215204
t_font -> m_ascent = t_face -> size -> metrics.ascender / 64.0f;
216205
t_font -> m_descent = t_face -> size -> metrics.descender / -64.0f; // Note: descender is negative in FT!
217206
t_font -> m_leading = (t_face -> size -> metrics.height / 64.0f) - t_font -> m_ascent - t_font -> m_descent;

engine/src/mblflst.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,8 @@ MCFontnode::MCFontnode(MCNameRef fname, uint2 &size, uint2 style)
5858
/* UNCHECKED */ MCStringCopySubstring(*reqname_str, MCRangeMake(0, t_comma - 1), &t_before_comma);
5959

6060
font -> fid = (MCSysFontHandle)iphone_font_create(*t_before_comma, reqsize, (reqstyle & FA_WEIGHT) > 0x05, (reqstyle & FA_ITALIC) != 0);
61-
62-
font -> ascent = size - 1;
63-
font -> descent = size * 2 / 14 + 1;
6461

6562
iphone_font_get_metrics(font -> fid, font->m_ascent, font->m_descent, font->m_leading, font->m_xheight);
66-
if (ceilf(font->m_ascent) + ceilf(font->m_descent) > size)
67-
font -> ascent++;
6863

6964
#elif defined(TARGET_SUBPLATFORM_ANDROID)
7065
font = new MCFontStruct;
@@ -80,12 +75,7 @@ MCFontnode::MCFontnode(MCNameRef fname, uint2 &size, uint2 style)
8075
/* UNCHECKED */ MCStringCopySubstring(*reqname_str, MCRangeMake(0, t_comma - 1), &t_before_comma);
8176
font -> fid = (MCSysFontHandle)android_font_create(*t_before_comma, reqsize, (reqstyle & FA_WEIGHT) > 0x05, (reqstyle & FA_ITALIC) != 0);
8277

83-
font -> ascent = size - 1;
84-
font -> descent = size * 2 / 14 + 1;
85-
8678
android_font_get_metrics(font -> fid, font->m_ascent, font->m_descent, font->m_leading, font->m_xheight);
87-
if (ceilf(font->m_ascent) + ceilf(font->m_descent) > size)
88-
font -> ascent++;
8979

9080
#endif
9181
}

engine/src/osxflst.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,8 @@ MCFontnode::MCFontnode(MCSysFontHandle p_handle)
116116

117117
void MCFontnode::calculatemetrics()
118118
{
119-
font -> ascent = reqsize - 1;
120-
font -> descent = reqsize * 2 / 14 + 1;
121-
122119
// MM-2014-06-02: [[ CoreText ]] Updated to use core text fonts.
123120
coretext_font_get_metrics(font -> fid, font -> m_ascent, font -> m_descent, font -> m_leading, font -> m_xheight);
124-
if (ceilf(font -> m_ascent) + ceilf(font -> m_descent) > reqsize)
125-
font -> ascent++;
126121
}
127122

128123
MCFontnode::~MCFontnode()

engine/src/osxprinter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,8 +1684,8 @@ void MCQuartzMetaContext::domark(MCMark *p_mark)
16841684

16851685
// MM-2014-04-16: [[ Bug 11964 ]] Prototype for MCFontMeasureText now takes transform param. Pass through identity.
16861686
CGContextFillRect(m_context,
1687-
CGRectMake(x, y - f -> ascent,
1688-
MCFontMeasureText(p_mark -> text . font, *t_text, MCGAffineTransformMakeIdentity()), f -> ascent + f -> descent));
1687+
CGRectMake(x, y - f -> m_ascent - f -> m_leading,
1688+
MCFontMeasureText(p_mark -> text . font, *t_text, MCGAffineTransformMakeIdentity()), f -> m_ascent + f -> m_descent + f -> m_leading));
16891689
CGContextRestoreGState(m_context);
16901690
}
16911691

engine/src/sysdefs.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,6 @@ struct MCFontStruct
309309
{
310310
MCSysFontHandle fid;
311311
uint16_t size;
312-
int ascent;
313-
int descent;
314312
Boolean printer;
315313

316314
coord_t m_ascent;
@@ -372,8 +370,6 @@ struct MCFontStruct
372370
MCSysFontHandle fid;
373371
uint2 size;
374372
uint2 style;
375-
int ascent;
376-
int descent;
377373

378374
coord_t m_ascent;
379375
coord_t m_descent;
@@ -438,8 +434,6 @@ struct MCFontStruct
438434
{
439435
MCSysFontHandle fid;
440436
uint16_t size;
441-
uint2 ascent;
442-
uint2 descent;
443437

444438
coord_t m_ascent;
445439
coord_t m_descent;
@@ -491,8 +485,6 @@ struct MCFontStruct
491485
MCSysFontHandle fid;
492486
uint2 size;
493487
uint2 style;
494-
int ascent;
495-
int descent;
496488

497489
coord_t m_ascent;
498490
coord_t m_descent;
@@ -536,8 +528,6 @@ inline uint1 MCS_toupper(uint1 p_char)
536528
struct MCFontStruct
537529
{
538530
uint16_t size;
539-
int ascent;
540-
int descent;
541531
MCSysFontHandle fid;
542532

543533
coord_t m_ascent;

engine/src/w32flst.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -227,18 +227,6 @@ MCFontnode::MCFontnode(MCNameRef fname, uint2 &size, uint2 style, Boolean printe
227227
GetTextMetricsW(hdc, &tm);
228228
font->fid = (MCSysFontHandle)newfont;
229229
font->size = size;
230-
// MW-2013-12-19: [[ Bug 11606 ]] Use Mac-style metric adjustment in printer (ideal
231-
// layout mode).
232-
if (!printer)
233-
{
234-
font->ascent = MulDiv(tm.tmAscent, 15, 16);
235-
font->descent = tm.tmDescent;
236-
}
237-
else
238-
{
239-
font -> ascent = size - 1;
240-
font -> descent = size * 2 / 14 + 1;
241-
}
242230
font->printer = printer;
243231

244232
font->m_ascent = tm.tmAscent;

libgraphics/include/graphics.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -500,19 +500,21 @@ struct MCGFont
500500
void *fid;
501501
uint16_t size;
502502
uint16_t fixed_advance;
503-
int32_t ascent;
504-
int32_t descent;
503+
MCGFloat m_ascent;
504+
MCGFloat m_descent;
505+
MCGFloat m_leading;
505506
bool ideal : 1;
506507
};
507508

508-
inline MCGFont MCGFontMake(void *fid, uint16_t size, uint16_t fixed_advance, int32_t ascent, int32_t descent, bool ideal)
509+
inline MCGFont MCGFontMake(void *fid, uint16_t size, uint16_t fixed_advance, MCGFloat ascent, MCGFloat descent, MCGFloat leading, bool ideal)
509510
{
510511
MCGFont t_font;
511512
t_font . fid = fid;
512513
t_font . size = size;
513514
t_font . fixed_advance = fixed_advance;
514-
t_font . ascent = ascent;
515-
t_font . descent = descent;
515+
t_font . m_ascent = ascent;
516+
t_font . m_descent = descent;
517+
t_font . m_leading = leading;
516518
t_font . ideal = ideal;
517519

518520
return t_font;

libgraphics/src/harfbuzztext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ void shape(const unichar_t* p_text, uindex_t p_char_count, MCGPoint p_location,
315315
// TODO: This currently seems to return nil all the time.
316316
if (t_fallback != nil)
317317
{
318-
MCGFont t_font = MCGFontMake(t_fallback, p_font . size, p_font . fixed_advance, p_font . ascent, p_font . descent, p_font . ideal);
318+
MCGFont t_font = MCGFontMake(t_fallback, p_font . size, p_font . fixed_advance, p_font . m_ascent, p_font . m_descent, p_font . m_leading, p_font . ideal);
319319

320320
MCGlyphRun *t_fallback_runs;
321321
uindex_t t_fallback_run_count;

0 commit comments

Comments
 (0)