Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: Source/platform/fonts/harfbuzz/HarfBuzzFaceCoreText.cpp

Issue 175253002: Switch to HarfBuzz on Mac and remove CoreText shaper (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: ChromiumAATTest font based test added, header inclusion order fixed Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 Google Inc. All rights reserved. 2 * Copyright (c) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 13 matching lines...) Expand all
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "platform/fonts/harfbuzz/HarfBuzzFace.h" 32 #include "platform/fonts/harfbuzz/HarfBuzzFace.h"
33 33
34 #include "hb-coretext.h"
35 #include "hb.h"
34 #include "platform/fonts/FontPlatformData.h" 36 #include "platform/fonts/FontPlatformData.h"
35 #include "platform/fonts/SimpleFontData.h" 37 #include "platform/fonts/SimpleFontData.h"
36 #include "platform/fonts/harfbuzz/HarfBuzzShaper.h" 38 #include "platform/fonts/harfbuzz/HarfBuzzShaper.h"
37
38 #include <ApplicationServices/ApplicationServices.h> 39 #include <ApplicationServices/ApplicationServices.h>
39 #include "hb.h"
40 40
41 namespace WebCore { 41 namespace WebCore {
42 42
43 static hb_position_t floatToHarfBuzzPosition(CGFloat value) 43 static hb_position_t floatToHarfBuzzPosition(CGFloat value)
44 { 44 {
45 return static_cast<hb_position_t>(value * (1 << 16)); 45 return static_cast<hb_position_t>(value * (1 << 16));
46 } 46 }
47 47
48 static hb_bool_t getGlyph(hb_font_t* hbFont, void* fontData, hb_codepoint_t unic ode, hb_codepoint_t variationSelector, hb_codepoint_t* glyph, void* userData) 48 static hb_bool_t getGlyph(hb_font_t* hbFont, void* fontData, hb_codepoint_t unic ode, hb_codepoint_t variationSelector, hb_codepoint_t* glyph, void* userData)
49 { 49 {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 harfBuzzCoreTextFontFuncs = hb_font_funcs_create(); 93 harfBuzzCoreTextFontFuncs = hb_font_funcs_create();
94 hb_font_funcs_set_glyph_func(harfBuzzCoreTextFontFuncs, getGlyph, 0, 0); 94 hb_font_funcs_set_glyph_func(harfBuzzCoreTextFontFuncs, getGlyph, 0, 0);
95 hb_font_funcs_set_glyph_h_advance_func(harfBuzzCoreTextFontFuncs, getGly phHorizontalAdvance, 0, 0); 95 hb_font_funcs_set_glyph_h_advance_func(harfBuzzCoreTextFontFuncs, getGly phHorizontalAdvance, 0, 0);
96 hb_font_funcs_set_glyph_h_origin_func(harfBuzzCoreTextFontFuncs, getGlyp hHorizontalOrigin, 0, 0); 96 hb_font_funcs_set_glyph_h_origin_func(harfBuzzCoreTextFontFuncs, getGlyp hHorizontalOrigin, 0, 0);
97 hb_font_funcs_set_glyph_extents_func(harfBuzzCoreTextFontFuncs, getGlyph Extents, 0, 0); 97 hb_font_funcs_set_glyph_extents_func(harfBuzzCoreTextFontFuncs, getGlyph Extents, 0, 0);
98 hb_font_funcs_make_immutable(harfBuzzCoreTextFontFuncs); 98 hb_font_funcs_make_immutable(harfBuzzCoreTextFontFuncs);
99 } 99 }
100 return harfBuzzCoreTextFontFuncs; 100 return harfBuzzCoreTextFontFuncs;
101 } 101 }
102 102
103 static void releaseTableData(void* userData)
104 {
105 CFDataRef cfData = reinterpret_cast<CFDataRef>(userData);
106 CFRelease(cfData);
107 }
108
109 static hb_blob_t* harfBuzzCoreTextGetTable(hb_face_t* face, hb_tag_t tag, void* userData)
110 {
111 CGFontRef cgFont = reinterpret_cast<CGFontRef>(userData);
112 CFDataRef cfData = CGFontCopyTableForTag(cgFont, tag);
113 if (!cfData)
114 return 0;
115
116 const char* data = reinterpret_cast<const char*>(CFDataGetBytePtr(cfData));
117 const size_t length = CFDataGetLength(cfData);
118 if (!data || !length)
119 return 0;
120 return hb_blob_create(data, length, HB_MEMORY_MODE_READONLY, reinterpret_cas t<void*>(const_cast<__CFData*>(cfData)), releaseTableData);
121 }
122
123 hb_face_t* HarfBuzzFace::createFace() 103 hb_face_t* HarfBuzzFace::createFace()
124 { 104 {
125 // It seems that CTFontCopyTable of MacOSX10.5 sdk doesn't work for 105 hb_face_t* face = hb_coretext_face_create(m_platformData->cgFont());
126 // OpenType layout tables(GDEF, GSUB, GPOS). Use CGFontCopyTableForTag inste ad.
127 hb_face_t* face = hb_face_create_for_tables(harfBuzzCoreTextGetTable, m_plat formData->cgFont(), 0);
128 ASSERT(face); 106 ASSERT(face);
129 return face; 107 return face;
130 } 108 }
131 109
132 hb_font_t* HarfBuzzFace::createFont() 110 hb_font_t* HarfBuzzFace::createFont()
133 { 111 {
134 hb_font_t* font = hb_font_create(m_face); 112 hb_font_t* font = hb_font_create(m_face);
135 hb_font_set_funcs(font, harfBuzzCoreTextGetFontFuncs(), m_platformData, 0); 113 hb_font_set_funcs(font, harfBuzzCoreTextGetFontFuncs(), m_platformData, 0);
136 const float size = m_platformData->m_size; 114 const float size = m_platformData->m_size;
137 hb_font_set_ppem(font, size, size); 115 hb_font_set_ppem(font, size, size);
138 const int scale = (1 << 16) * static_cast<int>(size); 116 const int scale = (1 << 16) * static_cast<int>(size);
139 hb_font_set_scale(font, scale, scale); 117 hb_font_set_scale(font, scale, scale);
140 hb_font_make_immutable(font); 118 hb_font_make_immutable(font);
141 return font; 119 return font;
142 } 120 }
143 121
144 GlyphBufferAdvance HarfBuzzShaper::createGlyphBufferAdvance(float width, float h eight) 122 GlyphBufferAdvance HarfBuzzShaper::createGlyphBufferAdvance(float width, float h eight)
145 { 123 {
146 return CGSizeMake(width, height); 124 return CGSizeMake(width, height);
147 } 125 }
148 126
149 } // namespace WebCore 127 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698