I noticed a regression where several Cairo text functions fail on UTF-8 input,
this patch restores the previous functionality. I've copied the withUTFString
function from glib to avoid any extra dependencies.
One minor issue is that glib is LGPL and Cairo is BSD3, meaning we need the
copyright holder's permission to make this modification. Axel Simon is listed
as the copyright holder of System.Glib.UTFString.
Cheers,
Spencer Janssen
1 patch for repository http://code.haskell.org/gtk2hs:
Tue Mar 29 15:24:56 CDT 2011 Spencer Janssen <spen...@well-typed.com>
* Fix regression where Cairo crashes on UTF-8 text
New patches:
[ Fix regression where Cairo crashes on UTF-8 text
Spencer Janssen <spen...@well-typed.com>**20110329202456
Ignore-this: 1aa7a8b1acf24daf3ce9bc4aa1560c2b
] hunk ./cairo/Graphics/Rendering/Cairo/Internal/Drawing/Paths.chs 21
import Foreign
import Foreign.C
+import Graphics.Rendering.Cairo.Internal.Utilities (withUTFString)
+
{#context lib="cairo" prefix="cairo"#}
{#fun get_current_point as getCurrentPoint { unCairo `Cairo', alloca- `Double' peekFloatConv*, alloca- `Double' peekFloatConv* } -> `()'#}
hunk ./cairo/Graphics/Rendering/Cairo/Internal/Drawing/Paths.chs 34
{#fun line_to as lineTo { unCairo `Cairo', `Double', `Double' } -> `()'#}
{#fun move_to as moveTo { unCairo `Cairo', `Double', `Double' } -> `()'#}
{#fun rectangle as rectangle { unCairo `Cairo', `Double', `Double', `Double', `Double' } -> `()'#}
-{#fun text_path as textPath { unCairo `Cairo', withCString* `String' } -> `()'#}
+{#fun text_path as textPath { unCairo `Cairo', withUTFString* `String' } -> `()'#}
{#fun rel_curve_to as relCurveTo { unCairo `Cairo', `Double', `Double', `Double', `Double', `Double', `Double' } -> `()'#}
{#fun rel_line_to as relLineTo { unCairo `Cairo', `Double', `Double' } -> `()'#}
{#fun rel_move_to as relMoveTo { unCairo `Cairo', `Double', `Double' } -> `()'#}
hunk ./cairo/Graphics/Rendering/Cairo/Internal/Drawing/Text.chs 18
{#import Graphics.Rendering.Cairo.Types#}
+import Graphics.Rendering.Cairo.Internal.Utilities (withUTFString)
import Foreign
import Foreign.C
hunk ./cairo/Graphics/Rendering/Cairo/Internal/Drawing/Text.chs 30
{#fun set_font_matrix as setFontMatrix { unCairo `Cairo', `Matrix' } -> `()'#}
{#fun get_font_matrix as getFontMatrix { unCairo `Cairo', alloca- `Matrix' peek*} -> `()'#}
{#fun set_font_options as setFontOptions { unCairo `Cairo', withFontOptions* `FontOptions' } -> `()'#}
-{#fun show_text as showText { unCairo `Cairo', withCString* `String' } -> `()'#}
+{#fun show_text as showText { unCairo `Cairo', withUTFString* `String' } -> `()'#}
{#fun font_extents as fontExtents { unCairo `Cairo', alloca- `FontExtents' peek* } -> `()'#}
hunk ./cairo/Graphics/Rendering/Cairo/Internal/Drawing/Text.chs 32
-{#fun text_extents as textExtents { unCairo `Cairo', withCString* `String', alloca- `TextExtents' peek* } -> `()'#}
+{#fun text_extents as textExtents { unCairo `Cairo', withUTFString* `String', alloca- `TextExtents' peek* } -> `()'#}
hunk ./cairo/Graphics/Rendering/Cairo/Internal/Utilities.chs 21
import Foreign
import Foreign.C
+import Data.Char (ord, chr)
+
{#context lib="cairo" prefix="cairo"#}
{#fun status_to_string as statusToString { cFromEnum `Status' } -> `String'#}
hunk ./cairo/Graphics/Rendering/Cairo/Internal/Utilities.chs 28
{#fun pure version as version {} -> `Int'#}
{#fun pure version_string as versionString {} -> `String'#}
+
+-- These functions taken from System/Glib/UTFString.hs
+-- Copyright (c) 1999..2002 Axel Simon
+
+-- Define withUTFString to emit UTF-8.
+--
+withUTFString :: String -> (CString -> IO a) -> IO a
+withUTFString hsStr = withCString (toUTF hsStr)
+ where
+ -- Convert Unicode characters to UTF-8.
+ --
+ toUTF :: String -> String
+ toUTF [] = []
+ toUTF (x:xs) | ord x<=0x007F = x:toUTF xs
+ | ord x<=0x07FF = chr (0xC0 .|. ((ord x `shift` (-6)) .&. 0x1F)):
+ chr (0x80 .|. (ord x .&. 0x3F)):
+ toUTF xs
+ | otherwise = chr (0xE0 .|. ((ord x `shift` (-12)) .&. 0x0F)):
+ chr (0x80 .|. ((ord x `shift` (-6)) .&. 0x3F)):
+ chr (0x80 .|. (ord x .&. 0x3F)):
+ toUTF xs
Context:
[Fix typo and add docs in INSTALL
Andy Stewart <lazycat.mana...@gmail.com>**20101222122119
Ignore-this: bc363a0efc4f6c975f35a3c8ffdbca1
]
[Add have-quartz-gtk flag to disable linking against gdk_x11_drawable_get_xid
Max Bolingbroke <batterseapo...@hotmail.com>**20101222113914
Ignore-this: 3cf2009a8db78814ad5de1ed0b2173ba
]
[Fix docs about 'imContextRetrieveSurrounding' signal.
Andy Stewart <lazycat.mana...@gmail.com>**20101217115003
Ignore-this: 26e7b7d10a3e97f7a185a0afbe72a9b9
]
[Don't emit an update signal with the incorrect stamp.
axel.si...@in.tum.de**20101216124643
Ignore-this: 64b053e5495b4879923b802194b91111
]
[Wrap version flag make gio can compile under gio-2.18.x
Andy Stewart <lazycat.mana...@gmail.com>**20101130130716
Ignore-this: 84989139d42c5790828cadaaec6a73bf
]
[Wrap 2.16.0 with EntryIconPosition to make gtk can compile in gtk+-2.14.x
Andy Stewart <lazycat.mana...@gmail.com>**20101130125652
Ignore-this: 2853a6fc9749f123b67ddc0b10b53174
]
[Add functions to query and show tooltips in TreeViews.
axel.si...@in.tum.de**20101123090253
Ignore-this: fa122105338c3b22d0ebccb8e213ebd0
]
[Add a note on broken binary Gtk+ installers on Windows.
axel.si...@in.tum.de**20101116154707
Ignore-this: 30ab8f947870103cca14271237e5b423
]
[Added basic GString support.
Andreas Baldeau <andr...@baldeau.net>**20101115103157
Ignore-this: 4fc62813b652cc6e420c7b69006dfdae
]
[TAG 0.12.0
axel.si...@in.tum.de**20101107135304
Ignore-this: 14b3023f48c36eed2cb136a2b69d6dae
]
Patch bundle hash:
523de6c37bab7f388deb7b9a54a5f2e65bd87fa5
------------------------------------------------------------------------------
Enable your software for Intel(R) Active Management Technology to meet the
growing manageability and security demands of your customers. Businesses
are taking advantage of Intel(R) vPro (TM) technology - will your software
be a part of the solution? Download the Intel(R) Manageability Checker
today! http://p.sf.net/sfu/intel-dev2devmar
_______________________________________________
Gtk2hs-devel mailing list
Gtk2hs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gtk2hs-devel