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

Side by Side Diff: sky/engine/platform/fonts/GlyphBuffer.h

Issue 859203002: Merge Blink code to cache SkTextBlob (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 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) 2006, 2009, 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2009, 2011 Apple Inc. All rights reserved.
3 * Copyright (C) 2007-2008 Torch Mobile Inc. 3 * Copyright (C) 2007-2008 Torch Mobile Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 22 matching lines...) Expand all
33 #include "sky/engine/platform/fonts/Glyph.h" 33 #include "sky/engine/platform/fonts/Glyph.h"
34 #include "sky/engine/platform/geometry/FloatSize.h" 34 #include "sky/engine/platform/geometry/FloatSize.h"
35 #include "sky/engine/wtf/Vector.h" 35 #include "sky/engine/wtf/Vector.h"
36 36
37 namespace blink { 37 namespace blink {
38 38
39 class SimpleFontData; 39 class SimpleFontData;
40 40
41 class GlyphBuffer { 41 class GlyphBuffer {
42 public: 42 public:
43 GlyphBuffer() : m_hasVerticalAdvances(false) { } 43 GlyphBuffer() { }
44 44
45 bool isEmpty() const { return m_fontData.isEmpty(); } 45 bool isEmpty() const { return m_fontData.isEmpty(); }
46 bool hasOffsets() const { return !m_offsets.isEmpty(); }
46 unsigned size() const { return m_fontData.size(); } 47 unsigned size() const { return m_fontData.size(); }
47 bool hasVerticalAdvances() const { return m_hasVerticalAdvances; }
48 48
49 void clear() 49 void clear()
50 { 50 {
51 m_fontData.clear(); 51 m_fontData.clear();
52 m_glyphs.clear(); 52 m_glyphs.clear();
53 m_advances.clear(); 53 m_advances.clear();
54 m_hasVerticalAdvances = false; 54 m_offsets.clear();
55 } 55 }
56 56
57 const Glyph* glyphs(unsigned from) const { return m_glyphs.data() + from; } 57 const Glyph* glyphs(unsigned from) const { return m_glyphs.data() + from; }
58 const FloatSize* advances(unsigned from) const { return m_advances.data() + from; } 58 const float* advances(unsigned from) const { return m_advances.data() + from ; }
59 const FloatSize* offsets(unsigned from) const { return m_offsets.data() + fr om; }
59 60
60 const SimpleFontData* fontDataAt(unsigned index) const { return m_fontData[i ndex]; } 61 const SimpleFontData* fontDataAt(unsigned index) const { return m_fontData[i ndex]; }
61 62
62 Glyph glyphAt(unsigned index) const 63 Glyph glyphAt(unsigned index) const
63 { 64 {
64 return m_glyphs[index]; 65 return m_glyphs[index];
65 } 66 }
66 67
67 FloatSize advanceAt(unsigned index) const 68 float advanceAt(unsigned index) const
68 { 69 {
69 return m_advances[index]; 70 return m_advances[index];
70 } 71 }
71 72
72 void add(Glyph glyph, const SimpleFontData* font, float width) 73 void add(Glyph glyph, const SimpleFontData* font, float width)
73 { 74 {
75 // should not mix offset/advance-only glyphs
76 ASSERT(!hasOffsets());
77
74 m_fontData.append(font); 78 m_fontData.append(font);
75 m_glyphs.append(glyph); 79 m_glyphs.append(glyph);
76 m_advances.append(FloatSize(width, 0)); 80 m_advances.append(width);
77 } 81 }
78 82
79 void add(Glyph glyph, const SimpleFontData* font, const FloatSize& advance) 83 void add(Glyph glyph, const SimpleFontData* font, const FloatSize& offset, f loat advance)
80 { 84 {
85 // should not mix offset/advance-only glyphs
86 ASSERT(size() == m_offsets.size());
87
81 m_fontData.append(font); 88 m_fontData.append(font);
82 m_glyphs.append(glyph); 89 m_glyphs.append(glyph);
90 m_offsets.append(offset);
83 m_advances.append(advance); 91 m_advances.append(advance);
84 if (advance.height())
85 m_hasVerticalAdvances = true;
86 } 92 }
87 93
88 void reverse() 94 void reverse()
89 { 95 {
90 m_fontData.reverse(); 96 m_fontData.reverse();
91 m_glyphs.reverse(); 97 m_glyphs.reverse();
92 m_advances.reverse(); 98 m_advances.reverse();
93 } 99 }
94 100
95 void setAdvanceWidth(unsigned index, float newWidth)
96 {
97 m_advances[index].setWidth(newWidth);
98 }
99
100 void expandLastAdvance(float width) 101 void expandLastAdvance(float width)
101 { 102 {
102 ASSERT(!isEmpty()); 103 ASSERT(!isEmpty());
103 FloatSize& lastAdvance = m_advances.last(); 104 float& lastAdvance = m_advances.last();
104 lastAdvance.setWidth(lastAdvance.width() + width); 105 lastAdvance += width;
105 } 106 }
106 107
107 private: 108 private:
108 Vector<const SimpleFontData*, 2048> m_fontData; 109 Vector<const SimpleFontData*, 2048> m_fontData;
109 Vector<Glyph, 2048> m_glyphs; 110 Vector<Glyph, 2048> m_glyphs;
110 Vector<FloatSize, 2048> m_advances; 111 Vector<float, 2048> m_advances;
111 bool m_hasVerticalAdvances; 112 Vector<FloatSize, 1024> m_offsets;
112 }; 113 };
113 114
114 } // namespace blink 115 } // namespace blink
115 116
116 #endif // SKY_ENGINE_PLATFORM_FONTS_GLYPHBUFFER_H_ 117 #endif // SKY_ENGINE_PLATFORM_FONTS_GLYPHBUFFER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698