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

Side by Side Diff: webkit/port/platform/graphics/chromium/GlyphPageTreeNodeLinux.cpp

Issue 10414: Use Skia to render fonts (Closed)
Patch Set: Created 12 years, 1 month 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 // Copyright (c) 2008, Google Inc. 1 // Copyright (c) 2008, Google Inc.
2 // All rights reserved. 2 // 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 12 matching lines...) Expand all
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
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 #include "config.h" 30 #include "config.h"
31 #include "GlyphPageTreeNode.h" 31 #include "GlyphPageTreeNode.h"
32 32
33 // This PANGO_ENABLE_BACKEND define lets us get at some of the internal Pango
34 // call which we need. This include must be here otherwise we include pango.h
35 // via another route (without the define) and that sets the include guard.
36 // Then, when we try to include it in the future the guard stops us getting the
37 // functions that we need.
38 #define PANGO_ENABLE_BACKEND
39 #include <pango/pango.h>
40 #include <pango/pangofc-font.h>
41
42 #include "Font.h" 33 #include "Font.h"
43 #include "NotImplemented.h" 34 #include "NotImplemented.h"
44 #include "SimpleFontData.h" 35 #include "SimpleFontData.h"
45 36
37 #include "SkTemplates.h"
38 #include "SkPaint.h"
39 #include "SkUtils.h"
40
46 namespace WebCore 41 namespace WebCore
47 { 42 {
48 43
49 bool GlyphPage::fill(unsigned offset, unsigned length, UChar* buffer, unsigned b ufferLength, const SimpleFontData* fontData) 44 bool GlyphPage::fill(unsigned offset, unsigned length, UChar* buffer, unsigned b ufferLength, const SimpleFontData* fontData)
50 { 45 {
51 // The bufferLength will be greater than the glyph page size if the buffer h as Unicode supplementary characters. 46 if (SkUTF16_IsHighSurrogate(buffer[bufferLength-1])) {
52 // We won't support this for now. 47 SkDebugf("%s last char is high-surrogate", __FUNCTION__);
53 if (bufferLength > GlyphPage::size)
54 return false; 48 return false;
55 49 }
56 if (!fontData->m_font.m_font || fontData->m_font.m_font == reinterpret_cast< PangoFont*>(-1)) 50
51 SkPaint paint;
52 fontData->platformData().setupPaint(&paint);
53 paint.setTextEncoding(SkPaint::kUTF16_TextEncoding);
54
55 SkAutoSTMalloc <GlyphPage::size, uint16_t> glyphStorage(length);
56 uint16_t* glyphs = glyphStorage.get();
57 // textToGlyphs takes a byte count, not a glyph count so we multiply by two.
58 unsigned count = paint.textToGlyphs(buffer, bufferLength * 2, glyphs);
59 if (count != length) {
60 SkDebugf("%s count != length\n", __FUNCTION__);
57 return false; 61 return false;
58
59 bool haveGlyphs = false;
60 for (unsigned i = 0; i < length; i++) {
61 Glyph glyph = pango_fc_font_get_glyph(PANGO_FC_FONT(fontData->m_font.m_f ont), buffer[i]);
62 if (!glyph)
63 setGlyphDataForIndex(offset + i, 0, 0);
64 else {
65 setGlyphDataForIndex(offset + i, glyph, fontData);
66 haveGlyphs = true;
67 }
68 } 62 }
69 63
70 return haveGlyphs; 64 unsigned allGlyphs = 0; // track if any of the glyphIDs are non-zero
65 for (unsigned i = 0; i < length; i++) {
66 setGlyphDataForIndex(offset + i, glyphs[i], fontData);
67 allGlyphs |= glyphs[i];
68 }
69 return allGlyphs != 0;
71 } 70 }
72 71
73 } // namespace WebCore 72 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698