From dcc91e539dc109c7c12762b11efe974f7828e5f1 Mon Sep 17 00:00:00 2001 From: Jonathan Kew Date: Fri, 27 Jan 2017 12:05:23 +0000 Subject: [PATCH] Bug 1331859 - For legacy Mac-platform font names that our standard decoders don't handle, try using CoreFoundation to convert to Unicode. r=jrmuizel --- gfx/thebes/gfxFontUtils.cpp | 22 ++++++++++++++++++++++ gfx/thebes/gfxHarfBuzzShaper.h | 10 +++++----- gfx/thebes/moz.build | 4 ++-- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/gfx/thebes/gfxFontUtils.cpp b/gfx/thebes/gfxFontUtils.cpp index db18ab6dfd37..a835da091a6e 100644 --- a/gfx/thebes/gfxFontUtils.cpp +++ b/gfx/thebes/gfxFontUtils.cpp @@ -25,6 +25,10 @@ #include "plbase64.h" #include "mozilla/Logging.h" +#ifdef XP_MACOSX +#include +#endif + #define LOG(log, args) MOZ_LOG(gfxPlatform::GetLog(log), \ LogLevel::Debug, args) @@ -1476,6 +1480,24 @@ gfxFontUtils::DecodeFontName(const char *aNameData, int32_t aByteLen, nsCOMPtr decoder = mozilla::dom::EncodingUtils::DecoderForEncoding(csName); if (!decoder) { +#ifdef XP_MACOSX + // Special case for macOS only: support legacy Mac encodings + // that DecoderForEncoding didn't handle. + if (aPlatformCode == PLATFORM_ID_MAC) { + CFStringRef str = + CFStringCreateWithBytes(kCFAllocatorDefault, + (const UInt8*)aNameData, aByteLen, + aScriptCode, false); + if (str) { + CFIndex length = CFStringGetLength(str); + aName.SetLength(length); + CFStringGetCharacters(str, CFRangeMake(0, length), + (UniChar*)aName.BeginWriting()); + CFRelease(str); + return true; + } + } +#endif NS_WARNING("failed to get the decoder for a font name string"); return false; } diff --git a/gfx/thebes/gfxHarfBuzzShaper.h b/gfx/thebes/gfxHarfBuzzShaper.h index 70d912cc0210..19ac40c63fe1 100644 --- a/gfx/thebes/gfxHarfBuzzShaper.h +++ b/gfx/thebes/gfxHarfBuzzShaper.h @@ -114,11 +114,11 @@ protected: struct Glyf { // we only need the bounding-box at the beginning // of the glyph record, not the actual outline data - AutoSwap_PRInt16 numberOfContours; - AutoSwap_PRInt16 xMin; - AutoSwap_PRInt16 yMin; - AutoSwap_PRInt16 xMax; - AutoSwap_PRInt16 yMax; + mozilla::AutoSwap_PRInt16 numberOfContours; + mozilla::AutoSwap_PRInt16 xMin; + mozilla::AutoSwap_PRInt16 yMin; + mozilla::AutoSwap_PRInt16 xMax; + mozilla::AutoSwap_PRInt16 yMax; }; const Glyf *FindGlyf(hb_codepoint_t aGlyph, bool *aEmptyGlyf) const; diff --git a/gfx/thebes/moz.build b/gfx/thebes/moz.build index b841a45de1f4..7eb894620741 100644 --- a/gfx/thebes/moz.build +++ b/gfx/thebes/moz.build @@ -179,7 +179,8 @@ SOURCES += [ # we could consider removing soon (affects Ubuntus older than 10.04 LTS) # which currently prevent it from joining UNIFIED_SOURCES. 'gfxDrawable.cpp', - # gfxPlatform.cpp includes mac system header conflicting with point/size + # gfxFontUtils.cpp and gfxPlatform.cpp include mac system header conflicting with point/size + 'gfxFontUtils.cpp', 'gfxPlatform.cpp', 'gfxPrefs.cpp', 'PrintTarget.cpp', @@ -198,7 +199,6 @@ UNIFIED_SOURCES += [ 'gfxFontInfoLoader.cpp', 'gfxFontMissingGlyphs.cpp', 'gfxFontTest.cpp', - 'gfxFontUtils.cpp', 'gfxGlyphExtents.cpp', 'gfxGradientCache.cpp', 'gfxGraphiteShaper.cpp',