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

Side by Side Diff: Source/platform/fonts/GlyphBuffer.h

Issue 607483002: Separate advance from offset in GlypBuffer (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: w/TestExpectations Created 6 years, 2 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 "platform/fonts/Glyph.h" 33 #include "platform/fonts/Glyph.h"
34 #include "platform/geometry/FloatSize.h" 34 #include "platform/geometry/FloatSize.h"
35 #include "wtf/Vector.h" 35 #include "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 void reserveOffsetsCapacity(size_t size) { m_offsets.reserveCapacity(size); }
jbroman 2014/09/25 17:03:31 This seems like an odd method to have. Why not jus
eae 2014/09/26 05:26:51 Good point, I'll rename it and change it to operat
48 49
49 void clear() 50 void clear()
50 { 51 {
51 m_fontData.clear(); 52 m_fontData.clear();
52 m_glyphs.clear(); 53 m_glyphs.clear();
54 m_offsets.clear();
53 m_advances.clear(); 55 m_advances.clear();
54 m_hasVerticalAdvances = false;
55 } 56 }
56 57
57 const Glyph* glyphs(unsigned from) const { return m_glyphs.data() + from; } 58 const Glyph* glyphs(unsigned from) const { return m_glyphs.data() + from; }
58 const FloatSize* advances(unsigned from) const { return m_advances.data() + from; } 59 const FloatSize* offsets(unsigned from) const { return m_offsets.data() + fr om; }
60 const float* advances(unsigned from) const { return m_advances.data() + from ; }
59 61
60 const SimpleFontData* fontDataAt(unsigned index) const { return m_fontData[i ndex]; } 62 const SimpleFontData* fontDataAt(unsigned index) const { return m_fontData[i ndex]; }
61 63
62 Glyph glyphAt(unsigned index) const 64 Glyph glyphAt(unsigned index) const
63 { 65 {
64 return m_glyphs[index]; 66 return m_glyphs[index];
65 } 67 }
66 68
67 FloatSize advanceAt(unsigned index) const 69 FloatSize offsetAt(unsigned index) const
70 {
71 return m_offsets[index];
72 }
73
74 float advanceAt(unsigned index) const
68 { 75 {
69 return m_advances[index]; 76 return m_advances[index];
70 } 77 }
71 78
72 void add(Glyph glyph, const SimpleFontData* font, float width) 79 void add(Glyph glyph, const SimpleFontData* font, float width)
73 { 80 {
jbroman 2014/09/25 17:03:32 Could we do something to ensure callers don't wind
eae 2014/09/26 05:26:51 Yeah, I was thinking about that, I don't really wa
74 m_fontData.append(font); 81 m_fontData.append(font);
75 m_glyphs.append(glyph); 82 m_glyphs.append(glyph);
76 m_advances.append(FloatSize(width, 0)); 83 m_advances.append(width);
77 } 84 }
78 85
79 void add(Glyph glyph, const SimpleFontData* font, const FloatSize& advance) 86 void add(Glyph glyph, const SimpleFontData* font, const FloatSize& offset, f loat advance = 0)
80 { 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();
98 m_offsets.reverse();
jbroman 2014/09/25 17:11:35 Are these offsets from the text origin, or from th
92 m_advances.reverse(); 99 m_advances.reverse();
93 } 100 }
94 101
95 void setAdvanceWidth(unsigned index, float newWidth)
96 {
97 m_advances[index].setWidth(newWidth);
98 }
99
100 void expandLastAdvance(float width) 102 void expandLastAdvance(float width)
101 { 103 {
102 ASSERT(!isEmpty()); 104 ASSERT(!isEmpty());
103 FloatSize& lastAdvance = m_advances.last(); 105 float& lastAdvance = m_advances.last();
104 lastAdvance.setWidth(lastAdvance.width() + width); 106 lastAdvance += width;
105 } 107 }
106 108
107 private: 109 private:
108 Vector<const SimpleFontData*, 2048> m_fontData; 110 Vector<const SimpleFontData*, 2048> m_fontData;
109 Vector<Glyph, 2048> m_glyphs; 111 Vector<Glyph, 2048> m_glyphs;
110 Vector<FloatSize, 2048> m_advances; 112 Vector<float, 2048> m_advances;
111 bool m_hasVerticalAdvances; 113 Vector<FloatSize> m_offsets;
f(malita) 2014/09/25 16:42:05 Why no inline capacity for m_offsets? Using stack-
eae 2014/09/26 05:26:51 As explained in the CL description the m_offsets f
112 }; 114 };
113 115
114 } // namespace blink 116 } // namespace blink
115 117
116 #endif 118 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698