From f1b17dfb8d088d823b9a6b242b68bf0738bac544 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Mon, 10 Aug 2015 09:59:07 -0700 Subject: [PATCH] Improve Cairo font hinting --- lime/graphics/cairo/CairoFont.hx | 5 +- lime/graphics/cairo/CairoFontOptions.hx | 136 +++++++++++++++--------- project/lib/freetype | 2 +- 3 files changed, 89 insertions(+), 54 deletions(-) diff --git a/lime/graphics/cairo/CairoFont.hx b/lime/graphics/cairo/CairoFont.hx index 30ddd5622..9fb4f2261 100644 --- a/lime/graphics/cairo/CairoFont.hx +++ b/lime/graphics/cairo/CairoFont.hx @@ -8,7 +8,10 @@ import lime.system.System; class CairoFont { + private static inline var FT_LOAD_FORCE_AUTOHINT = (1 << 5); + public var font (default, null):Font; + @:noCompletion public var handle:Dynamic; @@ -20,7 +23,7 @@ class CairoFont { if (font != null && font.src != null) { - handle = lime_cairo_ft_font_face_create_for_ft_face (font.src, 0); + handle = lime_cairo_ft_font_face_create_for_ft_face (font.src, FT_LOAD_FORCE_AUTOHINT); } diff --git a/lime/graphics/cairo/CairoFontOptions.hx b/lime/graphics/cairo/CairoFontOptions.hx index fa4a6402b..945c7b5ca 100644 --- a/lime/graphics/cairo/CairoFontOptions.hx +++ b/lime/graphics/cairo/CairoFontOptions.hx @@ -1,29 +1,43 @@ package lime.graphics.cairo; -import lime.graphics.cairo.CairoSubpixelOrder; -import lime.graphics.cairo.CairoSubpixelOrder; -import lime.graphics.cairo.CairoSubpixelOrder; + + import lime.text.Font; import lime.system.System; -class CairoFontOptions -{ + +class CairoFontOptions { + + public var antialias (get, set):CairoAntialias; - public var subpixelOrder (get, set):CairoSubpixelOrder; - public var hintStyle (get, set):CairoHintStyle; public var hintMetrics (get, set):CairoHintMetrics; + public var hintStyle (get, set):CairoHintStyle; + public var subpixelOrder (get, set):CairoSubpixelOrder; @:noCompletion public var handle:Dynamic; - - public function new( handle : Dynamic = null ) { + + + public function new (handle:Dynamic = null) { #if lime_cairo - if ( handle == null ) - handle = lime_cairo_font_options_create(); - #end + if (handle == null) { - this.handle = handle; - } + handle = lime_cairo_font_options_create (); + + } + #end + this.handle = handle; + + } + + + + + // Get & Set Methods + + + + @:noCompletion private function get_antialias ():CairoAntialias { #if lime_cairo @@ -45,6 +59,52 @@ class CairoFontOptions } + + @:noCompletion private function get_hintMetrics ():CairoHintMetrics { + + #if lime_cairo + return lime_cairo_font_options_get_hint_metrics (handle); + #end + + return cast 0; + + } + + + @:noCompletion private function set_hintMetrics (value:CairoHintMetrics):CairoHintMetrics { + + #if lime_cairo + lime_cairo_font_options_set_hint_metrics (handle, value); + #end + + return value; + + } + + + + @:noCompletion private function get_hintStyle ():CairoHintStyle { + + #if lime_cairo + return lime_cairo_font_options_get_hint_style (handle); + #end + + return cast 0; + + } + + + @:noCompletion private function set_hintStyle (value:CairoHintStyle):CairoHintStyle { + + #if lime_cairo + lime_cairo_font_options_set_hint_style (handle, value); + #end + + return value; + + } + + @:noCompletion private function get_subpixelOrder ():CairoSubpixelOrder { #if lime_cairo @@ -66,53 +126,25 @@ class CairoFontOptions } - @:noCompletion private function get_hintStyle ():CairoHintStyle { - - #if lime_cairo - return lime_cairo_font_options_get_hint_style (handle); - #end - - return cast 0; - } - @:noCompletion private function set_hintStyle (value:CairoHintStyle):CairoHintStyle { - - #if lime_cairo - lime_cairo_font_options_set_hint_style (handle, value); - #end - - return value; - } - - @:noCompletion private function get_hintMetrics ():CairoHintMetrics { - - #if lime_cairo - return lime_cairo_font_options_get_hint_metrics (handle); - #end - - return cast 0; - } - - @:noCompletion private function set_hintMetrics (value:CairoHintMetrics):CairoHintMetrics { - - #if lime_cairo - lime_cairo_font_options_set_hint_metrics (handle, value); - #end - - return value; - } + + // Native Methods + + + #if (cpp || neko || nodejs) private static var lime_cairo_font_options_create = System.load ("lime", "lime_cairo_font_options_create", 0); private static var lime_cairo_font_options_get_antialias = System.load ("lime", "lime_cairo_font_options_get_antialias", 1); - private static var lime_cairo_font_options_get_subpixel_order = System.load ("lime", "lime_cairo_font_options_get_subpixel_order", 1); - private static var lime_cairo_font_options_get_hint_style = System.load ("lime", "lime_cairo_font_options_get_hint_style", 1); private static var lime_cairo_font_options_get_hint_metrics = System.load ("lime", "lime_cairo_font_options_get_hint_metrics", 1); + private static var lime_cairo_font_options_get_hint_style = System.load ("lime", "lime_cairo_font_options_get_hint_style", 1); + private static var lime_cairo_font_options_get_subpixel_order = System.load ("lime", "lime_cairo_font_options_get_subpixel_order", 1); private static var lime_cairo_font_options_set_antialias = System.load ("lime", "lime_cairo_font_options_set_antialias", 2); - private static var lime_cairo_font_options_set_subpixel_order = System.load ("lime", "lime_cairo_font_options_set_subpixel_order", 2); - private static var lime_cairo_font_options_set_hint_style = System.load ("lime", "lime_cairo_font_options_set_hint_style", 2); private static var lime_cairo_font_options_set_hint_metrics = System.load ("lime", "lime_cairo_font_options_set_hint_metrics", 2); + private static var lime_cairo_font_options_set_hint_style = System.load ("lime", "lime_cairo_font_options_set_hint_style", 2); + private static var lime_cairo_font_options_set_subpixel_order = System.load ("lime", "lime_cairo_font_options_set_subpixel_order", 2); #end + } \ No newline at end of file diff --git a/project/lib/freetype b/project/lib/freetype index 3ce727ee6..91868e616 160000 --- a/project/lib/freetype +++ b/project/lib/freetype @@ -1 +1 @@ -Subproject commit 3ce727ee611fd2af6be6af37585fd08c914e1af5 +Subproject commit 91868e61652843284c76c7df95a7f08e896f8aee