void MCGContextDrawPlatformText(MCGContextRef self, const unichar_t *p_text, uindex_t p_length, MCGPoint p_location, const MCGFont &p_font) { if (!MCGContextIsValid(self)) return; bool t_success; t_success = true; char *t_text; t_text = nil; if (t_success) t_success = MCCStringFromUnicodeSubstring(p_text, p_length / 2, t_text); if (t_success) { SkPaint t_paint; t_paint . setStyle(SkPaint::kFill_Style); t_paint . setAntiAlias(true); t_paint . setColor(MCGColorToSkColor(self -> state -> fill_color)); t_paint . setTextSize(p_font . size); SkXfermode *t_blend_mode; t_blend_mode = MCGBlendModeToSkXfermode(self -> state -> blend_mode); t_paint . setXfermode(t_blend_mode); if (t_blend_mode != NULL) t_blend_mode -> unref(); SkTypeface *t_typeface; t_typeface = (SkTypeface *) p_font . fid; t_paint . setTypeface(t_typeface); // MM-2013-12-05: [[ Bug 11527 ]] Make sure we calculate the UTF-8 string length correctly. uindex_t t_length; t_length = MCCStringLength(t_text); self -> layer -> canvas -> drawText(t_text, t_length, MCGCoordToSkCoord(p_location . x), MCGCoordToSkCoord(p_location . y), t_paint); } MCCStringFree(t_text); self -> is_valid = t_success; }
void MCGContextDrawPlatformText(MCGContextRef self, const unichar_t *p_text, uindex_t p_length, MCGPoint p_location, const MCGFont &p_font) { // MW-2013-12-19: [[ Bug 11559 ]] Do nothing if no text support. if (!s_has_text_support) return; if (!MCGContextIsValid(self)) return; bool t_success; t_success = true; if (t_success) t_success = s_layout != NULL; char *t_text; t_text = nil; if (t_success) t_success = MCCStringFromUnicodeSubstring(p_text, p_length / 2, t_text); MCGAffineTransform t_transform; MCGPoint t_device_location; PangoLayoutLine *t_line; t_line = nil; if (t_success) { t_transform = MCGContextGetDeviceTransform(self); t_device_location = MCGPointApplyAffineTransform(p_location, t_transform); t_transform . tx = modff(t_device_location . x, &t_device_location . x); t_transform . ty = modff(t_device_location . y, &t_device_location . y); PangoMatrix t_ptransform; t_ptransform . xx = t_transform . a; t_ptransform . xy = t_transform . b; t_ptransform . yx = t_transform . c; t_ptransform . yy = t_transform . d; t_ptransform . x0 = t_transform . tx; t_ptransform . y0 = t_transform . ty; pango_context_set_matrix(s_pango, &t_ptransform); pango_layout_set_font_description(s_layout, (PangoFontDescription *) p_font . fid); pango_layout_set_text(s_layout, t_text, -1); MCCStringFree(t_text); extern PangoLayoutLine *(*pango_layout_get_line_readonly_ptr)(PangoLayout *, int); if (pango_layout_get_line_readonly_ptr != nil) t_line = pango_layout_get_line_readonly_ptr(s_layout, 0); else t_line = pango_layout_get_line(s_layout, 0); t_success = t_line != nil; } MCGIntRectangle t_text_bounds, t_clipped_bounds; if (t_success) { PangoRectangle t_pbounds; pango_layout_line_get_extents(t_line, NULL, &t_pbounds); MCGRectangle t_float_text_bounds; t_float_text_bounds . origin . x = t_pbounds . x / PANGO_SCALE; t_float_text_bounds . origin . y = t_pbounds . y / PANGO_SCALE; t_float_text_bounds . size . width = t_pbounds . width / PANGO_SCALE; t_float_text_bounds . size . height = t_pbounds . height / PANGO_SCALE; MCGRectangle t_device_clip; t_device_clip = MCGContextGetDeviceClipBounds(self); t_device_clip . origin . x -= t_device_location . x; t_device_clip . origin . y -= t_device_location . y; MCGRectangle t_float_clipped_bounds; t_float_clipped_bounds = MCGRectangleIntersection(t_float_text_bounds, t_device_clip); t_text_bounds = MCGRectangleIntegerBounds(t_float_text_bounds); t_clipped_bounds = MCGRectangleIntegerBounds(t_float_clipped_bounds); if (t_clipped_bounds . width == 0 || t_clipped_bounds . height == 0) return; } void *t_data; t_data = nil; if (t_success) t_success = MCMemoryNew(t_clipped_bounds . width * t_clipped_bounds . height, t_data); if (t_success) { FT_Bitmap t_ftbitmap; t_ftbitmap . rows = t_clipped_bounds . height; t_ftbitmap . width = t_clipped_bounds . width; t_ftbitmap . pitch = t_clipped_bounds . width; t_ftbitmap . buffer = (unsigned char*) t_data; t_ftbitmap . num_grays = 256; t_ftbitmap . pixel_mode = FT_PIXEL_MODE_GRAY; t_ftbitmap . palette_mode = 0; t_ftbitmap . palette = nil; pango_ft2_render_layout_line(&t_ftbitmap, t_line, -(t_clipped_bounds . x - t_text_bounds . x), -(t_clipped_bounds . y - t_text_bounds . y) - t_text_bounds . y); SkPaint t_paint; t_paint . setStyle(SkPaint::kFill_Style); t_paint . setAntiAlias(self -> state -> should_antialias); t_paint . setColor(MCGColorToSkColor(self -> state -> fill_color)); SkXfermode *t_blend_mode; t_blend_mode = MCGBlendModeToSkXfermode(self -> state -> blend_mode); t_paint . setXfermode(t_blend_mode); if (t_blend_mode != NULL) t_blend_mode -> unref(); SkBitmap t_bitmap; t_bitmap . setConfig(SkBitmap::kA8_Config, t_clipped_bounds . width, t_clipped_bounds . height); t_bitmap . setIsOpaque(false); t_bitmap . setPixels(t_data); self -> layer -> canvas -> drawSprite(t_bitmap, t_clipped_bounds . x + t_device_location . x, t_clipped_bounds . y + t_device_location . y, &t_paint); } MCMemoryDelete(t_data); self -> is_valid = t_success; }