diff options
author | Tor Lillqvist <tml@iki.fi> | 2013-01-15 22:23:07 +0200 |
---|---|---|
committer | Tor Lillqvist <tml@iki.fi> | 2013-01-19 10:52:40 +0200 |
commit | 0d816467302dae89fd2e326e97364d1d4db47e8e (patch) | |
tree | d30bd475450eea6fc536c554c0efe7be95f031c6 /vcl/ios | |
parent | 8a894b4af476641062bf340a2fb802558bf1cbe3 (diff) |
Fix iOS bit-rot and unify with OS X CoreText code
Adapt to the fairly pointless privatisations here, too. Unify with the
OS X CoreText code. Yeah, probably should unify physically, i.e. use
the same source files for both, with as little ifdefs as possible.
Change-Id: I63bc477f0c979769bb995db37a3c4194e8091b30
Diffstat (limited to 'vcl/ios')
-rw-r--r-- | vcl/ios/source/gdi/salcoretextfontutils.cxx | 228 | ||||
-rw-r--r-- | vcl/ios/source/gdi/salcoretextlayout.cxx | 81 | ||||
-rw-r--r-- | vcl/ios/source/gdi/salcoretextstyle.cxx | 31 | ||||
-rw-r--r-- | vcl/ios/source/gdi/salgdi.cxx | 25 |
4 files changed, 192 insertions, 173 deletions
diff --git a/vcl/ios/source/gdi/salcoretextfontutils.cxx b/vcl/ios/source/gdi/salcoretextfontutils.cxx index ade57115799c..06e2cfcfb5f2 100644 --- a/vcl/ios/source/gdi/salcoretextfontutils.cxx +++ b/vcl/ios/source/gdi/salcoretextfontutils.cxx @@ -28,24 +28,24 @@ static bool GetDevFontAttributes( CTFontDescriptorRef font_descriptor, ImplDevFontAttributes& rDFA ) { + int value = 0; // reset the attributes - rDFA.meFamily = FAMILY_DONTKNOW; - rDFA.mePitch = PITCH_VARIABLE; - rDFA.meWidthType = WIDTH_NORMAL; - rDFA.meWeight = WEIGHT_NORMAL; - rDFA.meItalic = ITALIC_NONE; - rDFA.mbSymbolFlag = false; + rDFA.SetFamilyType( FAMILY_DONTKNOW ); + rDFA.SetPitch( PITCH_VARIABLE ); + rDFA.SetWidthType( WIDTH_NORMAL ); + rDFA.SetWeight( WEIGHT_NORMAL ); + rDFA.SetItalic( ITALIC_NONE ); + rDFA.SetSymbolFlag( false ); rDFA.mbOrientation = true; rDFA.mbDevice = true; rDFA.mnQuality = 0; CFNumberRef format = (CFNumberRef)CTFontDescriptorCopyAttribute(font_descriptor, kCTFontFormatAttribute); - int value = 0; CFNumberGetValue(format, kCFNumberIntType, &value); CFRelease(format); - if (value == kCTFontFormatBitmap) + if(value == kCTFontFormatBitmap) { /* we don't want bitmap fonts */ return false; @@ -54,43 +54,41 @@ static bool GetDevFontAttributes( CTFontDescriptorRef font_descriptor, ImplDevFo rDFA.mbEmbeddable = false; CFStringRef family_name = (CFStringRef)CTFontDescriptorCopyAttribute(font_descriptor, kCTFontFamilyNameAttribute); - rDFA.maName = GetOUString(family_name); + rDFA.SetFamilyName( GetOUString(family_name) ); CFRelease(family_name); CFDictionaryRef traits = (CFDictionaryRef)CTFontDescriptorCopyAttribute(font_descriptor, kCTFontTraitsAttribute); CFNumberRef symbolics = (CFNumberRef)CFDictionaryGetValue(traits, kCTFontSymbolicTrait); - - value = 0; CFNumberGetValue(symbolics, kCFNumberIntType, &value); CFRelease(symbolics); - if (value & kCTFontMonoSpaceTrait) + if(value & kCTFontMonoSpaceTrait) { - rDFA.mePitch = PITCH_FIXED; + rDFA.SetPitch( PITCH_FIXED ); } - if (value & kCTFontItalicTrait) + if(value & kCTFontItalicTrait) { - rDFA.meItalic = ITALIC_NORMAL; + rDFA.SetItalic( ITALIC_NORMAL ); } - if (value & kCTFontBoldTrait) + if(value & kCTFontBoldTrait) { - rDFA.meWeight = WEIGHT_BOLD; + rDFA.SetWeight( WEIGHT_BOLD ); } - if (value & kCTFontCondensedTrait) + if(value & kCTFontCondensedTrait) { - rDFA.meWidthType = WIDTH_CONDENSED; + rDFA.SetWidthType( WIDTH_CONDENSED ); } - else if (value & kCTFontExpandedTrait) + else if(value & kCTFontExpandedTrait) { - rDFA.meWidthType = WIDTH_EXPANDED; + rDFA.SetWidthType( WIDTH_EXPANDED ); } switch(value & kCTFontClassMaskTrait) { case kCTFontOldStyleSerifsClass: - rDFA.meFamily = FAMILY_ROMAN; + rDFA.SetFamilyType( FAMILY_ROMAN ); break; case kCTFontTransitionalSerifsClass: case kCTFontModernSerifsClass: @@ -99,56 +97,56 @@ static bool GetDevFontAttributes( CTFontDescriptorRef font_descriptor, ImplDevFo case kCTFontFreeformSerifsClass: break; case kCTFontSansSerifClass: - rDFA.meFamily = FAMILY_SWISS; + rDFA.SetFamilyType( FAMILY_SWISS ); case kCTFontOrnamentalsClass: - rDFA.meFamily = FAMILY_DECORATIVE; + rDFA.SetFamilyType( FAMILY_DECORATIVE ); break; case kCTFontScriptsClass: - rDFA.meFamily = FAMILY_SCRIPT; + rDFA.SetFamilyType( FAMILY_SCRIPT ); break; case kCTFontSymbolicClass: - rDFA.mbSymbolFlag = true; + rDFA.SetSymbolFlag( true ); break; } CFNumberRef weight = (CFNumberRef)CFDictionaryGetValue(traits, kCTFontWeightTrait); float fdval = 0.0; CFNumberGetValue(weight, kCFNumberFloatType, &fdval); - if (fdval > 0.6) + if(fdval > 0.6) { - rDFA.meWeight = WEIGHT_BLACK; + rDFA.SetWeight( WEIGHT_BLACK ); } - else if (fdval > 0.4) + else if(fdval > 0.4) { - rDFA.meWeight = WEIGHT_ULTRABOLD; + rDFA.SetWeight( WEIGHT_ULTRABOLD ); } else if (fdval > 0.3) { - rDFA.meWeight = WEIGHT_BOLD; + rDFA.SetWeight( WEIGHT_BOLD ); } else if (fdval > 0.0) { - rDFA.meWeight = WEIGHT_SEMIBOLD; + rDFA.SetWeight( WEIGHT_SEMIBOLD ); } else if (fdval <= -0.8) { - rDFA.meWeight = WEIGHT_ULTRALIGHT; + rDFA.SetWeight( WEIGHT_ULTRALIGHT ); } else if (fdval <= -0.4) { - rDFA.meWeight = WEIGHT_LIGHT; + rDFA.SetWeight( WEIGHT_LIGHT ); } else if (fdval <= -0.3) { - rDFA.meWeight = WEIGHT_SEMILIGHT; + rDFA.SetWeight( WEIGHT_SEMILIGHT ); } else if (fdval <= -0.2) { - rDFA.meWeight = WEIGHT_THIN; + rDFA.SetWeight( WEIGHT_THIN ); } else { - rDFA.meWeight = WEIGHT_NORMAL; + rDFA.SetWeight( WEIGHT_NORMAL ); } CFStringRef string_ref = (CFStringRef)CTFontDescriptorCopyAttribute(font_descriptor, kCTFontStyleNameAttribute); @@ -157,41 +155,41 @@ static bool GetDevFontAttributes( CTFontDescriptorRef font_descriptor, ImplDevFo CFRelease(string_ref); // heuristics to adjust font slant - if ( (font_name_lc.indexOf("oblique") != -1) || + if( (font_name_lc.indexOf("oblique") != -1) || (font_name_lc.indexOf("inclined") != -1) || (font_name_lc.indexOf("slanted") != -1) ) { - rDFA.meItalic = ITALIC_OBLIQUE; + rDFA.SetItalic( ITALIC_OBLIQUE ); } // heuristics to adjust font width if (font_name_lc.indexOf("narrow") != -1) { - rDFA.meWidthType = WIDTH_SEMI_CONDENSED; + rDFA.SetWidthType( WIDTH_SEMI_CONDENSED ); } // heuristics for font family type - if ( (font_name_lc.indexOf("script") != -1) || + if( (font_name_lc.indexOf("script") != -1) || (font_name_lc.indexOf("chancery") != -1) || (font_name_lc.indexOf("zapfino") != -1)) { - rDFA.meFamily = FAMILY_SCRIPT; + rDFA.SetFamilyType( FAMILY_SCRIPT ); } - else if ( (font_name_lc.indexOf("comic") != -1) || + else if( (font_name_lc.indexOf("comic") != -1) || (font_name_lc.indexOf("outline") != -1) || (font_name_lc.indexOf("pinpoint") != -1) ) { - rDFA.meFamily = FAMILY_DECORATIVE; + rDFA.SetFamilyType( FAMILY_DECORATIVE ); } - else if ( (font_name_lc.indexOf("sans") != -1) || + else if( (font_name_lc.indexOf("sans") != -1) || (font_name_lc.indexOf("arial") != -1) ) { - rDFA.meFamily = FAMILY_SWISS; + rDFA.SetFamilyType( FAMILY_SWISS ); } - else if ( (font_name_lc.indexOf("roman") != -1) || + else if( (font_name_lc.indexOf("roman") != -1) || (font_name_lc.indexOf("times") != -1) ) { - rDFA.meFamily = FAMILY_ROMAN; + rDFA.SetFamilyType( FAMILY_ROMAN ); } return true; } @@ -199,28 +197,35 @@ static bool GetDevFontAttributes( CTFontDescriptorRef font_descriptor, ImplDevFo SystemFontList::SystemFontList() { CTFontCollectionRef font_collection = CTFontCollectionCreateFromAvailableFonts(NULL); - if (font_collection) + if(font_collection) { CFArrayRef font_descriptors = CTFontCollectionCreateMatchingFontDescriptors(font_collection); - for(int i = 0; i < CFArrayGetCount(font_descriptors); i++) + if(font_descriptors) { - CTFontDescriptorRef font_descriptor = (CTFontDescriptorRef)CFArrayGetValueAtIndex(font_descriptors, i); - CTFontRef font = CTFontCreateWithFontDescriptor(font_descriptor, 0, NULL); - ImplDevFontAttributes devfont_attr; - if (GetDevFontAttributes( font_descriptor, devfont_attr ) ) + for(int i = 0; i < CFArrayGetCount(font_descriptors); i++) { - ImplCoreTextFontData* font_data = new ImplCoreTextFontData(devfont_attr, font); - if (font_data && font_data->GetCTFont()) + CTFontDescriptorRef font_descriptor = (CTFontDescriptorRef)CFArrayGetValueAtIndex(font_descriptors, i); + CTFontRef font = CTFontCreateWithFontDescriptor(font_descriptor, 0, NULL); + if(font) { - m_aFontContainer [ font_data->GetCTFont() ] = font_data; + ImplDevFontAttributes devfont_attr; + if(GetDevFontAttributes( font_descriptor, devfont_attr ) ) + { + CoreTextPhysicalFontFace* font_face = new CoreTextPhysicalFontFace(devfont_attr, font); + if(font_face && font_face->GetCTFont()) + { + m_aFontContainer [ font_face->GetCTFont() ] = font_face; + } + } + CFRelease(font); } } - CFRelease(font); + CFRelease(font_descriptors); } - CFRelease(font_descriptors); + CFRelease(font_collection); } - CFRelease(font_collection); + } SystemFontList::~SystemFontList() @@ -231,7 +236,7 @@ SystemFontList::~SystemFontList() m_aFontContainer.clear(); } -ImplCoreTextFontData* SystemFontList::GetFontDataFromRef( CTFontRef font ) const +CoreTextPhysicalFontFace* SystemFontList::GetFontDataFromRef( CTFontRef font ) const { CoreTextFontContainer::const_iterator it = m_aFontContainer.find( font ); return it == m_aFontContainer.end() ? NULL : (*it).second; @@ -247,7 +252,7 @@ void SystemFontList::AnnounceFonts( ImplDevFontList& rFontList ) const } } -ImplCoreTextFontData::ImplCoreTextFontData( const ImplDevFontAttributes& rDFA, CTFontRef font ) +CoreTextPhysicalFontFace::CoreTextPhysicalFontFace( const ImplDevFontAttributes& rDFA, CTFontRef font ) : PhysicalFontFace( rDFA, 0 ) , m_CTFontRef((CTFontRef)CFRetain(font)) , m_pCharMap( NULL ) @@ -257,43 +262,43 @@ ImplCoreTextFontData::ImplCoreTextFontData( const ImplDevFontAttributes& rDFA, C , m_bHasCJKSupport( false ) , m_bFontCapabilitiesRead( false ) { + msgs_debug(font,"retain %p as %p",font, m_CTFontRef); } -ImplCoreTextFontData::~ImplCoreTextFontData() +CoreTextPhysicalFontFace::~CoreTextPhysicalFontFace() { - if ( m_pCharMap ) + if( m_pCharMap ) { m_pCharMap->DeReference(); } - if ( m_CTFontRef ) - { - CFRelease(m_CTFontRef); - } + msgs_debug(font,"release font %p", m_CTFontRef); + SafeCFRelease(m_CTFontRef); } -PhysicalFontFace* ImplCoreTextFontData::Clone() const +PhysicalFontFace* CoreTextPhysicalFontFace::Clone() const { - ImplCoreTextFontData* pClone = new ImplCoreTextFontData(*this); - if ( m_pCharMap ) + CoreTextPhysicalFontFace* pClone = new CoreTextPhysicalFontFace(*this); + if( m_pCharMap ) { m_pCharMap->AddReference(); } - if ( m_CTFontRef ) + if( m_CTFontRef ) { pClone->m_CTFontRef = (CTFontRef)CFRetain(m_CTFontRef); + msgs_debug(font,"clone ref %p into %p", m_CTFontRef, pClone->m_CTFontRef); } return pClone; } -ImplFontEntry* ImplCoreTextFontData::CreateFontInstance(FontSelectPattern& rFSD) const +ImplFontEntry* CoreTextPhysicalFontFace::CreateFontInstance(FontSelectPattern& rFSD) const { return new ImplFontEntry(rFSD); } -const ImplFontCharMap* ImplCoreTextFontData::GetImplFontCharMap() +const ImplFontCharMap* CoreTextPhysicalFontFace::GetImplFontCharMap() { // return the cached charmap - if ( m_pCharMap ) + if( m_pCharMap ) { return m_pCharMap; } @@ -303,18 +308,18 @@ const ImplFontCharMap* ImplCoreTextFontData::GetImplFontCharMap() // get the CMAP byte size CFDataRef rCmapTable = CTFontCopyTable( m_CTFontRef, kCTFontTableCmap, kCTFontTableOptionNoOptions); - if (!rCmapTable) + if(!rCmapTable) { return m_pCharMap; } - if (!m_bCmapTableRead) + if(!m_bCmapTableRead) { m_bCmapTableRead = true; DetermineCJKSupport_cmap(rCmapTable); } // parse the CMAP CmapResult aCmapResult; - if (ParseCMAP( CFDataGetBytePtr(rCmapTable), CFDataGetLength(rCmapTable), aCmapResult ) ) + if(ParseCMAP( CFDataGetBytePtr(rCmapTable), CFDataGetLength(rCmapTable), aCmapResult ) ) { m_pCharMap = new ImplFontCharMap( aCmapResult ); m_pCharMap->AddReference(); @@ -323,10 +328,10 @@ const ImplFontCharMap* ImplCoreTextFontData::GetImplFontCharMap() return m_pCharMap; } -bool ImplCoreTextFontData::GetImplFontCapabilities(vcl::FontCapabilities &rFontCapabilities) +bool CoreTextPhysicalFontFace::GetImplFontCapabilities(vcl::FontCapabilities &rFontCapabilities) { // read this only once per font - if ( m_bFontCapabilitiesRead ) + if( m_bFontCapabilitiesRead ) { rFontCapabilities = m_aFontCapabilities; return !rFontCapabilities.maUnicodeRange.empty() || !rFontCapabilities.maCodePageRange.empty(); @@ -335,7 +340,7 @@ bool ImplCoreTextFontData::GetImplFontCapabilities(vcl::FontCapabilities &rFontC // get the GSUB table raw data CFDataRef rGSUBTable = CTFontCopyTable( m_CTFontRef, kCTFontTableGSUB, kCTFontTableOptionNoOptions); - if (rGSUBTable) + if(rGSUBTable) { vcl::getTTScripts(m_aFontCapabilities.maGSUBScriptTags, @@ -343,14 +348,14 @@ bool ImplCoreTextFontData::GetImplFontCapabilities(vcl::FontCapabilities &rFontC CFRelease(rGSUBTable); } CFDataRef OS2_Table = CTFontCopyTable( m_CTFontRef, kCTFontTableOS2, kCTFontTableOptionNoOptions); - if (OS2_Table) + if(OS2_Table) { vcl::getTTCoverage( m_aFontCapabilities.maUnicodeRange, m_aFontCapabilities.maCodePageRange, CFDataGetBytePtr(OS2_Table), CFDataGetLength(OS2_Table)); /* while we are at it let's solve HasCJK for the same price */ - if (!m_bOs2TableRead ) + if(!m_bOs2TableRead ) { m_bOs2TableRead = true; m_bHasOs2Table = true; @@ -371,7 +376,7 @@ struct font_table void addTable(struct font_table* table, CTFontTableTag tag, CFDataRef data) { - if (data && CFDataGetLength(data) > 0) + if(data && CFDataGetLength(data) > 0) { *(uint32_t*)table->dir_entry = CFSwapInt32HostToBig(tag); table->dir_entry += 4; @@ -387,20 +392,17 @@ void addTable(struct font_table* table, CTFontTableTag tag, CFDataRef data) } } -bool ImplCoreTextFontData::GetRawFontData( std::vector<unsigned char>& rBuffer, bool* pJustCFF ) const +bool CoreTextPhysicalFontFace::GetRawFontData( std::vector<unsigned char>& rBuffer, bool* pJustCFF ) const { bool rc; int table_count = 0; CFDataRef CFF_table = CTFontCopyTable( m_CTFontRef, kCTFontTableCFF, kCTFontTableOptionNoOptions); - if (pJustCFF) + if(pJustCFF) { - if (CFF_table) + if(CFF_table) { *pJustCFF = CFDataGetLength(CFF_table) ? true : false; - } - if (CFF_table) - { CFRelease(CFF_table); return true; } @@ -417,9 +419,9 @@ bool ImplCoreTextFontData::GetRawFontData( std::vector<unsigned char>& rBuffer, CFDataRef hhea_table = CTFontCopyTable( m_CTFontRef, kCTFontTableHhea, kCTFontTableOptionNoOptions); CFDataRef hmtx_table = CTFontCopyTable( m_CTFontRef, kCTFontTableHmtx, kCTFontTableOptionNoOptions); rc = false; - if (head_table && maxp_table && cmap_table && name_table && hhea_table && hmtx_table) + if(head_table && maxp_table && cmap_table && name_table && hhea_table && hmtx_table) { - if (CFDataGetLength(head_table) && + if(CFDataGetLength(head_table) && CFDataGetLength(maxp_table) && CFDataGetLength(name_table) && CFDataGetLength(hhea_table) && @@ -440,13 +442,13 @@ bool ImplCoreTextFontData::GetRawFontData( std::vector<unsigned char>& rBuffer, CFDataRef prep_table = NULL; CFDataRef cvt_table = NULL; CFDataRef fpgm_table = NULL; - if (rc) + if(rc) { - if (!CFF_table || CFDataGetLength(CFF_table) == 0) + if(!CFF_table || CFDataGetLength(CFF_table) == 0) { loca_table = CTFontCopyTable( m_CTFontRef, kCTFontTableLoca, kCTFontTableOptionNoOptions); glyf_table = CTFontCopyTable( m_CTFontRef, kCTFontTableGlyf, kCTFontTableOptionNoOptions); - if (!loca_table || !glyf_table || !CFDataGetLength(loca_table) || !CFDataGetLength(glyf_table)) + if(!loca_table || !glyf_table || !CFDataGetLength(loca_table) || !CFDataGetLength(glyf_table)) { rc = false; } @@ -457,17 +459,17 @@ bool ImplCoreTextFontData::GetRawFontData( std::vector<unsigned char>& rBuffer, prep_table = CTFontCopyTable( m_CTFontRef, kCTFontTablePrep, kCTFontTableOptionNoOptions); cvt_table = CTFontCopyTable( m_CTFontRef, kCTFontTableCvt, kCTFontTableOptionNoOptions); fpgm_table = CTFontCopyTable( m_CTFontRef, kCTFontTableFpgm, kCTFontTableOptionNoOptions); - if (prep_table || CFDataGetLength(prep_table) > 0) + if(prep_table || CFDataGetLength(prep_table) > 0) { table_count += 1; total_len += CFDataGetLength(prep_table); } - if (cvt_table || CFDataGetLength(cvt_table) > 0) + if(cvt_table || CFDataGetLength(cvt_table) > 0) { table_count += 1; total_len += CFDataGetLength(cvt_table); } - if (fpgm_table || CFDataGetLength(fpgm_table) > 0) + if(fpgm_table || CFDataGetLength(fpgm_table) > 0) { table_count += 1; total_len += CFDataGetLength(fpgm_table); @@ -480,7 +482,7 @@ bool ImplCoreTextFontData::GetRawFontData( std::vector<unsigned char>& rBuffer, total_len += CFDataGetLength(CFF_table); } } - if (rc) + if(rc) { total_len += 12 + 16 * table_count; rBuffer.resize(total_len); @@ -535,16 +537,16 @@ bool ImplCoreTextFontData::GetRawFontData( std::vector<unsigned char>& rBuffer, return rc; } -void ImplCoreTextFontData::DetermineCJKSupport_OS2(CFDataRef rOS2Table) +void CoreTextPhysicalFontFace::DetermineCJKSupport_OS2(CFDataRef rOS2Table) { - if (CFDataGetLength(rOS2Table) >= 48) + if(CFDataGetLength(rOS2Table) >= 48) { const unsigned short* pOS2buffer = (const unsigned short*)CFDataGetBytePtr(rOS2Table); const unsigned short version = CFSwapInt16BigToHost(pOS2buffer[0]); - if ( version >= 1) + if( version >= 1) { const unsigned short unicode_range = CFSwapInt16BigToHost(pOS2buffer[23]); - if ( unicode_range & 0x2DF0) + if( unicode_range & 0x2DF0) { m_bHasCJKSupport = true; } @@ -552,22 +554,22 @@ void ImplCoreTextFontData::DetermineCJKSupport_OS2(CFDataRef rOS2Table) } } -void ImplCoreTextFontData::DetermineCJKSupport_cmap(CFDataRef rCmapTable) +void CoreTextPhysicalFontFace::DetermineCJKSupport_cmap(CFDataRef rCmapTable) { int table_len = CFDataGetLength(rCmapTable) / 2; - if (table_len >= 12) + if(table_len >= 12) { const unsigned short* pCmap = (const unsigned short*)CFDataGetBytePtr(rCmapTable); - if (pCmap[0] == 0) + if(pCmap[0] == 0) { short nb_sub_tables = CFSwapInt16BigToHost(pCmap[1]); for(int i = 2; --nb_sub_tables >= 0 && i < table_len; i += 4) { short platform = CFSwapInt16BigToHost(pCmap[i]); - if ( platform == kFontMacintoshPlatform ) + if( platform == kFontMacintoshPlatform ) { short encoding = CFSwapInt16BigToHost(pCmap[i+1]); - if ( encoding == kFontJapaneseScript || + if( encoding == kFontJapaneseScript || encoding == kFontTraditionalChineseScript || encoding == kFontKoreanScript || encoding == kFontSimpleChineseScript ) @@ -581,25 +583,25 @@ void ImplCoreTextFontData::DetermineCJKSupport_cmap(CFDataRef rCmapTable) } } -bool ImplCoreTextFontData::HasCJKSupport( void ) +bool CoreTextPhysicalFontFace::HasCJKSupport( void ) { // read this only once per font - if (!m_bOs2TableRead ) + if(!m_bOs2TableRead ) { m_bOs2TableRead = true; CFDataRef rOS2Table = CTFontCopyTable( m_CTFontRef, kCTFontTableOS2, kCTFontTableOptionNoOptions); - if (rOS2Table) + if(rOS2Table) { m_bHasOs2Table = true; DetermineCJKSupport_OS2(rOS2Table); CFRelease(rOS2Table); } } - if ( !m_bCmapTableRead && !m_bHasOs2Table && !m_bHasCJKSupport ) + if( !m_bCmapTableRead && !m_bHasOs2Table && !m_bHasCJKSupport ) { m_bCmapTableRead = true; CFDataRef rCmapTable = CTFontCopyTable( m_CTFontRef, kCTFontTableCmap, kCTFontTableOptionNoOptions); - if (rCmapTable) + if(rCmapTable) { DetermineCJKSupport_cmap(rCmapTable); CFRelease(rCmapTable); diff --git a/vcl/ios/source/gdi/salcoretextlayout.cxx b/vcl/ios/source/gdi/salcoretextlayout.cxx index c7db1945491f..8774d2e0a7cd 100644 --- a/vcl/ios/source/gdi/salcoretextlayout.cxx +++ b/vcl/ios/source/gdi/salcoretextlayout.cxx @@ -61,32 +61,32 @@ void CoreTextLayout::AdjustLayout( ImplLayoutArgs& /*rArgs*/ ) void CoreTextLayout::Clean() { msgs_debug(layout,"-->"); - if (m_glyphs) + if(m_glyphs) { delete[] m_glyphs; m_glyphs = NULL; } - if (m_chars2glyphs) + if(m_chars2glyphs) { delete[] m_chars2glyphs; m_chars2glyphs = NULL; } - if (m_glyphs2chars) + if(m_glyphs2chars) { delete[] m_glyphs2chars; m_glyphs2chars = NULL; } - if (m_char_widths) + if(m_char_widths) { delete[] m_char_widths; m_char_widths = NULL; } - if (m_glyph_advances) + if(m_glyph_advances) { delete[] m_glyph_advances; m_glyph_advances = NULL; } - if (m_glyph_positions) + if(m_glyph_positions) { delete[] m_glyph_positions; m_glyph_positions = NULL; @@ -101,7 +101,7 @@ void CoreTextLayout::DrawText( SalGraphics& rGraphics ) const { msgs_debug(layout,"-->"); IosSalGraphics& gr = static_cast<IosSalGraphics&>(rGraphics); - if (m_chars_count <= 0 || !gr.CheckContext()) + if(m_chars_count <= 0 || !gr.CheckContext()) { return; } @@ -115,13 +115,19 @@ void CoreTextLayout::DrawText( SalGraphics& rGraphics ) const CTLineDraw(m_line, gr.mrContext); #else InitGIA(); - msgs_debug(layout,"at- pos (%ld, %ld)", pos.X(), pos.Y()); + msgs_debug(layout,"at- pos (%ld, %ld) ctfont=%p", pos.X(), pos.Y(), + m_style->GetFont()); CGFontRef cg_font = CTFontCopyGraphicsFont(m_style->GetFont(), NULL); + if(!cg_font) + { + msgs_debug(layout, "Error cg_font is %s", "NULL"); + return; + } CGContextSetFont(gr.mrContext, cg_font); CGContextSetFontSize(gr.mrContext, CTFontGetSize(m_style->GetFont())); CGContextSetTextDrawingMode(gr.mrContext, kCGTextFill); CGContextSetShouldAntialias( gr.mrContext, true ); - if (m_style->GetColor()) + if(m_style->GetColor()) { CGContextSetFillColorWithColor(gr.mrContext, m_style->GetColor()); CGContextSetStrokeColorWithColor(gr.mrContext, m_style->GetColor()); @@ -131,20 +137,10 @@ void CoreTextLayout::DrawText( SalGraphics& rGraphics ) const CGContextSetRGBFillColor(gr.mrContext, 0.0, 0.0, 0.0, 1.0); } CFRelease(cg_font); -// CGContextSetTextPosition(gr.mrContext, pos.X(), pos.Y()); CGContextSetTextMatrix(gr.mrContext, CGAffineTransformMakeScale(1.0, -1.0)); CGContextSetShouldAntialias( gr.mrContext, !gr.mbNonAntialiasedText ); CGContextTranslateCTM(gr.mrContext, pos.X(), pos.Y()); -// for(int i = 0; i < m_glyphs_count ; ++i) -// { -// msgs_debug(layout,"m_glyph=%p m_glyph_positions=%p count=%d", m_glyphs, m_glyph_positions, m_glyphs_count); -// msgs_debug(layout,"glyph[%d]=0x%x position(%g,%g)", i, m_glyphs[i], m_glyph_positions[i].x, m_glyph_positions[i].y); - CGContextShowGlyphs(gr.mrContext, m_glyphs, m_glyphs_count); -// CGContextShowGlyphsAtPositions(gr.mrContext, m_glyphs, m_glyph_positions, m_glyphs_count); -// CGContextShowGlyphsWidthAdvances(gr.mrContext, m_glyphs, m_glyph_advances, m_glyphs_count); - -// CGContextShowGlyphsAtPoint(gr.mrContext, pos.X(), pos.Y(), m_glyphs, m_glyphs_count); -// } + CGContextShowGlyphs(gr.mrContext, m_glyphs, m_glyphs_count); #endif // restore the original graphic context transformations CGContextRestoreGState( gr.mrContext ); @@ -159,7 +155,7 @@ long CoreTextLayout::FillDXArray( long* pDXArray ) const { msgs_debug(layout,"-->"); // short circuit requests which don't need full details - if ( !pDXArray ) + if( !pDXArray ) { return GetTextWidth(); } @@ -186,10 +182,11 @@ long CoreTextLayout::FillDXArray( long* pDXArray ) const bool CoreTextLayout::GetBoundRect( SalGraphics &rGraphics, Rectangle& rVCLRect ) const { + msgs_debug(layout,"-->"); - IosSalGraphics& gr = static_cast<IosSalGraphics&>(rGraphics); if ( !m_has_bound_rec ) { + IosSalGraphics& gr = static_cast<IosSalGraphics&>(rGraphics); CGRect bound_rect = CTLineGetImageBounds( m_line, gr.mrContext ); if ( !CGRectIsNull( bound_rect ) ) { @@ -234,21 +231,21 @@ int CoreTextLayout::GetNextGlyphs( int nLen, sal_GlyphId* pGlyphIDs, Point& rPos // get glyph measurements InitGIA(); - if ( nStart < 0 ) // first glyph requested? + if( nStart < 0 ) // first glyph requested? { nStart = 0; m_current_run_index = 0; m_current_glyph_index = 0; m_current_glyphrun_index = 0; } - else if (nStart >= m_glyphs_count) + else if(nStart >= m_glyphs_count) { m_current_run_index = 0; m_current_glyph_index = 0; m_current_glyphrun_index = 0; return 0; } - if (!m_runs) + if(!m_runs) { m_runs = CTLineGetGlyphRuns(m_line); } @@ -260,10 +257,10 @@ int CoreTextLayout::GetNextGlyphs( int nLen, sal_GlyphId* pGlyphIDs, Point& rPos bool first = true; while(i < nLen) { - if (m_current_glyphrun_index >= nb_glyphs) + if(m_current_glyphrun_index >= nb_glyphs) { m_current_run_index += 1; - if (m_current_run_index >= nb_runs) + if(m_current_run_index >= nb_runs) { break; } @@ -271,7 +268,7 @@ int CoreTextLayout::GetNextGlyphs( int nLen, sal_GlyphId* pGlyphIDs, Point& rPos nb_glyphs = CTRunGetGlyphCount( run ); m_current_glyphrun_index = 0; } - if (first) + if(first) { CGPoint first_pos; CTRunGetPositions(run, CFRangeMake(m_current_glyphrun_index,1), &first_pos); @@ -281,11 +278,11 @@ int CoreTextLayout::GetNextGlyphs( int nLen, sal_GlyphId* pGlyphIDs, Point& rPos first = false; } pGlyphIDs[i] = m_glyphs[m_current_glyph_index]; - if (pGlyphAdvances) + if(pGlyphAdvances) { pGlyphAdvances[i] = m_glyph_advances[m_current_glyph_index]; } - if (pCharIndexes) + if(pCharIndexes) { pCharIndexes[i] = m_glyphs2chars[m_current_glyph_index]; } @@ -317,17 +314,18 @@ long CoreTextLayout::GetTextWidth() const // not needed. CoreText manage fallback directly void CoreTextLayout::InitFont() const { + msgs_debug(layout,"<-->"); } bool CoreTextLayout::InitGIA() const { msgs_debug(layout,"count=%d <--", m_chars_count); - if ( m_chars_count <= 0) + if( m_chars_count <= 0) { return false; } - if (m_glyphs) + if(m_glyphs) { return true; } @@ -351,13 +349,13 @@ bool CoreTextLayout::InitGIA() const for( CFIndex i = 0; i < nb_runs; ++i ) { CTRunRef run = (CTRunRef)CFArrayGetValueAtIndex( runs, i ); - if ( run ) + if( run ) { CFIndex nb_glyphs = CTRunGetGlyphCount( run ); - if (nb_glyphs) + if(nb_glyphs) { CFRange text_range = CTRunGetStringRange( run ); - if ( text_range.location != kCFNotFound && text_range.length > 0 ) + if( text_range.location != kCFNotFound && text_range.length > 0 ) { CFIndex indices[ nb_glyphs ]; CGGlyph glyphs[ nb_glyphs ]; @@ -375,6 +373,8 @@ bool CoreTextLayout::InitGIA() const for (CFIndex j = 0 ; j < nb_glyphs; ++p, ++j ) { m_glyphs[ p ] = glyphs[ j ]; + msgs_debug(layout,"m_glyphys[%d]=glyphs[%d] run %d : 0x%x\n", + p,(int)j, (int)i, glyphs[j]); CFIndex k = indices[ j ]; m_glyphs2chars[p] = k; m_chars2glyphs[k] = p; @@ -383,7 +383,7 @@ bool CoreTextLayout::InitGIA() const { m_char_widths[ k ] += m_glyph_positions[ p + 1 ].x - m_glyph_positions[ p ].x; } - if ( p > 0) + if( p > 0) { m_glyph_advances[p - 1] = m_glyph_positions[ p ].x - m_glyph_positions[p - 1].x; } @@ -398,7 +398,8 @@ bool CoreTextLayout::InitGIA() const bool CoreTextLayout::LayoutText(ImplLayoutArgs& args) { - msgs_debug(layout,"-->"); + msgs_debug(layout,"-->(m_style=%p font=%p", + m_style, m_style->GetFont()); Clean(); m_style->SetColor(); /* retreive MinCharPos EndCharPos Flags and Orientation */ @@ -406,7 +407,7 @@ bool CoreTextLayout::LayoutText(ImplLayoutArgs& args) m_chars_count = mnEndCharPos - mnMinCharPos; /* don't layout emptty (or worse negative size) strings */ - if (m_chars_count <= 0) + if(m_chars_count <= 0) { return false; } @@ -457,13 +458,13 @@ bool CoreTextLayout::LayoutText(ImplLayoutArgs& args) } m_typesetter = CTTypesetterCreateWithAttributedString(string); CFRelease(string); - if (!m_typesetter) + if(!m_typesetter) { Clean(); return false; } m_line = CTTypesetterCreateLine(m_typesetter, CFRangeMake(0, 0)); - if (!m_line) + if(!m_line) { Clean(); return false; diff --git a/vcl/ios/source/gdi/salcoretextstyle.cxx b/vcl/ios/source/gdi/salcoretextstyle.cxx index 46d11bc7604e..c0ef66b49e6c 100644 --- a/vcl/ios/source/gdi/salcoretextstyle.cxx +++ b/vcl/ios/source/gdi/salcoretextstyle.cxx @@ -30,7 +30,7 @@ CoreTextStyleInfo::CoreTextStyleInfo() : m_CTParagraphStyle(NULL), m_CTFont(NULL), m_color(NULL), - m_font_data(NULL) + m_font_face(NULL) { msgs_debug(style,"create <-->"); } @@ -52,27 +52,27 @@ long CoreTextStyleInfo::GetFontStretchedSize() const void CoreTextStyleInfo::SetFont(FontSelectPattern* requested_font) { msgs_debug(style,"req(%p) release font %p -->", requested_font, m_CTFont); - SafeCFRelease(m_CTFont); - if (!requested_font) + + if(!requested_font) { - m_font_data = NULL; + SafeCFRelease(m_CTFont); + m_font_face = NULL; return; } - const ImplCoreTextFontData* font_data = static_cast<const ImplCoreTextFontData*>(requested_font->mpFontData); + m_font_face = (CoreTextPhysicalFontFace*)(requested_font->mpFontData); - m_font_data = (ImplCoreTextFontData*)font_data; m_matrix = CGAffineTransformIdentity; CGFloat font_size = (CGFloat)requested_font->mfExactHeight; // enable bold-emulation if needed - if ( (requested_font->GetWeight() >= WEIGHT_BOLD) && - (font_data->GetWeight() < WEIGHT_SEMIBOLD) ) + if( (requested_font->GetWeight() >= WEIGHT_BOLD) && + (m_font_face->GetWeight() < WEIGHT_SEMIBOLD) ) { /* FIXME: add support for fake bold */ m_fake_bold = true; } - if ( ((requested_font->GetSlant() == ITALIC_NORMAL) || (requested_font->GetSlant() == ITALIC_OBLIQUE)) && - !((font_data->GetSlant() == ITALIC_NORMAL) || (font_data->GetSlant() == ITALIC_OBLIQUE)) ) + if( ((requested_font->GetSlant() == ITALIC_NORMAL) || (requested_font->GetSlant() == ITALIC_OBLIQUE)) && + !((m_font_face->GetSlant() == ITALIC_NORMAL) || (m_font_face->GetSlant() == ITALIC_OBLIQUE)) ) { #define kRotationForItalicText 10 m_fake_italic = true; @@ -81,15 +81,17 @@ void CoreTextStyleInfo::SetFont(FontSelectPattern* requested_font) } // prepare font stretching - if ( (requested_font->mnWidth != 0) && (requested_font->mnWidth != requested_font->mnHeight) ) + if( (requested_font->mnWidth != 0) && (requested_font->mnWidth != requested_font->mnHeight) ) { m_stretch_factor = (float)requested_font->mnWidth / requested_font->mnHeight; m_matrix = CGAffineTransformScale(m_matrix, m_stretch_factor, 1.0F ); } + SafeCFRelease(m_CTFont); + /* FIXME: pass attribute to take into accout 'VerticalStyle' */ /* FIXME: how to deal with 'rendering options' i.e anti-aliasing, does it even matter in CoreText ? */ - m_CTFont = CTFontCreateCopyWithAttributes(font_data->GetCTFont(), font_size, &m_matrix, NULL); + m_CTFont = CTFontCreateCopyWithAttributes(m_font_face->GetCTFont(), font_size, &m_matrix, NULL); msgs_debug(style,"font %p <--", m_CTFont); } @@ -97,10 +99,15 @@ void CoreTextStyleInfo::SetColor(SalColor color) { msgs_debug(style, "r:%d g:%d b:%d -->", SALCOLOR_RED(color), SALCOLOR_GREEN(color), SALCOLOR_BLUE(color)); SafeCFRelease(m_color); +#ifdef IOS + // No CGColorCreateGenericRGB on iOS CGColorSpaceRef rgb_space = CGColorSpaceCreateDeviceRGB(); CGFloat c[] = { SALCOLOR_RED(color) / 255.0f, SALCOLOR_GREEN(color) / 255.0f, SALCOLOR_BLUE(color) / 255.0f, 1.0 }; m_color = CGColorCreate(rgb_space, c); CGColorSpaceRelease(rgb_space); +#else + m_color = CGColorCreateGenericRGB(SALCOLOR_RED(color) / 255.0, SALCOLOR_GREEN(color) / 255.0, SALCOLOR_BLUE(color) / 255.0, 1.0); +#endif msgs_debug(style,"color=%p <--", m_color); } diff --git a/vcl/ios/source/gdi/salgdi.cxx b/vcl/ios/source/gdi/salgdi.cxx index faec9c40e931..fad782c483ae 100644 --- a/vcl/ios/source/gdi/salgdi.cxx +++ b/vcl/ios/source/gdi/salgdi.cxx @@ -40,7 +40,6 @@ IosSalGraphics::IosSalGraphics() , mxClipPath( NULL ) , maLineColor( COL_WHITE ) , maFillColor( COL_BLACK ) - , m_pCoreTextFontData( NULL ) , mbNonAntialiasedText( false ) , mbPrinter( false ) , mbVirDev( false ) @@ -169,28 +168,38 @@ sal_uLong IosSalGraphics::GetKernPairs( sal_uLong, ImplKernPairData* ) bool IosSalGraphics::GetImplFontCapabilities(vcl::FontCapabilities &rFontCapabilities) const { - if( !m_pCoreTextFontData ) + if( !m_style ) { return false; } - return m_pCoreTextFontData->GetImplFontCapabilities(rFontCapabilities); + CoreTextPhysicalFontFace* font_face = m_style->GetFontFace(); + if( !font_face) + { + return false; + } + return font_face->GetImplFontCapabilities(rFontCapabilities); } const ImplFontCharMap* IosSalGraphics::GetImplFontCharMap() const { - if( !m_pCoreTextFontData ) + if( !m_style ) + { + return NULL; + } + CoreTextPhysicalFontFace* font_face = m_style->GetFontFace(); + if( !font_face) { return ImplFontCharMap::GetDefaultMap(); } - return m_pCoreTextFontData->GetImplFontCharMap(); + return font_face->GetImplFontCharMap(); } -bool IosSalGraphics::GetRawFontData( const PhysicalFontFace* pFontData, +bool IosSalGraphics::GetRawFontData( const PhysicalFontFace* pFontFace, std::vector<unsigned char>& rBuffer, bool* pJustCFF ) { - const ImplCoreTextFontData* font_data = static_cast<const ImplCoreTextFontData*>(pFontData); + const CoreTextPhysicalFontFace* font_face = static_cast<const CoreTextPhysicalFontFace*>(pFontFace); - return font_data->GetRawFontData(rBuffer, pJustCFF); + return font_face->GetRawFontData(rBuffer, pJustCFF); } SystemFontData IosSalGraphics::GetSysFontData( int /* nFallbacklevel */ ) const |