static void MCFontMeasureTextCallback(MCFontRef p_font, MCStringRef p_string, MCRange p_range, font_measure_text_context *ctxt) { if (MCStringIsEmpty(p_string) || p_range.length == 0) return; MCGFont t_font; t_font = MCFontStructToMCGFont(p_font->fontstruct); // MW-2013-12-04: [[ Bug 11535 ]] Pass through the fixed advance. t_font . fixed_advance = p_font -> fixed_advance; ctxt -> m_width += MCGContextMeasurePlatformText(NULL, MCStringGetCharPtr(p_string) + p_range.offset, p_range.length*2, t_font, ctxt -> m_transform); }
static void MCFontDrawTextCallback(MCFontRef p_font, MCStringRef p_text, MCRange p_range, font_draw_text_context *ctxt) { MCGFont t_font; t_font = MCFontStructToMCGFont(p_font->fontstruct); // MW-2013-12-04: [[ Bug 11535 ]] Pass through the fixed advance. t_font . fixed_advance = p_font -> fixed_advance; // The drawing is done on the UTF-16 form of the text MCGContextDrawPlatformText(ctxt->m_gcontext, MCStringGetCharPtr(p_text) + p_range.offset, p_range.length*2, MCGPointMake(ctxt->x, ctxt->y), t_font, ctxt->rtl); // The draw position needs to be advanced // MM-2014-04-16: [[ Bug 11964 ]] Pass through the scale of the context to make sure the measurment is correct. ctxt -> x += MCGContextMeasurePlatformText(NULL, MCStringGetCharPtr(p_text) + p_range.offset, p_range.length*2, t_font, MCGContextGetDeviceTransform(ctxt->m_gcontext)); }
static void MCFontDrawTextCallback(MCFontRef p_font, const char *p_text, uint32_t p_length, bool p_is_unicode, font_draw_text_context *ctxt) { MCGFont t_font; t_font = MCFontStructToMCGFont(p_font->fontstruct); // MW-2013-12-04: [[ Bug 11535 ]] Pass through the fixed advance. t_font . fixed_advance = p_font -> fixed_advance; // MW-2013-12-04: [[ Bug 11549 ]] Make sure unicode text is short-aligned. MCExecPoint ep; ep . setsvalue(MCString(p_text, p_length)); if (!p_is_unicode) ep . nativetoutf16(); else if ((((uintptr_t)ep . getsvalue() . getstring()) & 1) != 0) ep . grabsvalue(); MCGContextDrawPlatformText(ctxt->m_gcontext, (unichar_t *) ep . getsvalue() . getstring(), ep . getsvalue() . getlength(), MCGPointMake(ctxt->x, ctxt->y), t_font); // The draw position needs to be advanced. Can this be done more efficiently? ctxt -> x += MCGContextMeasurePlatformText(NULL, (unichar_t*)ep.getsvalue().getstring(), ep.getsvalue().getlength(), t_font); }
static void MCFontMeasureTextCallback(MCFontRef p_font, const char *p_text, uint32_t p_length, bool p_is_unicode, font_measure_text_context *ctxt) { if (p_length == 0 || p_text == NULL) return; MCGFont t_font; t_font = MCFontStructToMCGFont(p_font->fontstruct); // MW-2013-12-04: [[ Bug 11535 ]] Pass through the fixed advance. t_font . fixed_advance = p_font -> fixed_advance; // MW-2013-12-04: [[ Bug 11549 ]] Make sure unicode text is short-aligned. MCExecPoint ep; ep . setsvalue(MCString(p_text, p_length)); if (!p_is_unicode) ep . nativetoutf16(); else if ((((uintptr_t)ep . getsvalue() . getstring()) & 1) != 0) ep . grabsvalue(); ctxt -> m_width += MCGContextMeasurePlatformText(NULL, (unichar_t *) ep . getsvalue() . getstring(), ep . getsvalue() . getlength(), t_font); }
bool MCFontCreate(MCNameRef p_name, MCFontStyle p_style, int32_t p_size, MCFontRef& r_font) { for(MCFont *t_font = s_fonts; t_font != nil; t_font = t_font -> next) { if (p_name == t_font -> name && p_style == t_font -> style && p_size == t_font -> size) { t_font -> references += 1; r_font = t_font; return true; } } MCFontRef self; if (!MCMemoryNew(self)) return false; self -> references = 1; /* UNCHECKED */ MCNameClone(p_name, self -> name); self -> style = p_style; self -> size = p_size; uint2 t_temp_size; t_temp_size = self -> size; self -> fontstruct = MCdispatcher -> loadfont(self -> name, t_temp_size, MCFontStyleToTextStyle(self -> style), (self -> style & kMCFontStylePrinterMetrics) != 0); // MW-2013-12-04: [[ Bug 11535 ]] Test to see if the font is fixed-width, at least for // Roman script. MCGFont t_gfont; t_gfont = MCFontStructToMCGFont(self -> fontstruct); t_gfont . fixed_advance = 0; // We check the width of ' ', i, l, m and w. If they are all the same width // we assume the font is monospaced and subsequently set the fixed_advance // field to a suitable value. MCGFloat t_last_width; for(uindex_t i = 0; i < 5; i++) { unichar_t t_char; t_char = (unichar_t)((" ilmw")[i]); // MM-2014-04-16: [[ Bug 11964 ]] MCGContextMeasurePlatformText prototype updated to take scale. Pass identity. MCGFloat t_this_width; t_this_width = MCGContextMeasurePlatformText(nil, &t_char, 2, t_gfont, MCGAffineTransformMakeIdentity()); if (t_this_width == 0.0 || (i != 0 && t_this_width != t_last_width)) { t_last_width = 0; break; } t_last_width = t_this_width; } self -> fixed_advance = floorf(t_last_width + 0.5); self -> next = s_fonts; s_fonts = self; r_font = self; return true; }