| OLD | NEW |
| 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 25 matching lines...) Expand all Loading... |
| 36 #include "wtf/Vector.h" | 36 #include "wtf/Vector.h" |
| 37 | 37 |
| 38 namespace blink { | 38 namespace blink { |
| 39 | 39 |
| 40 class SimpleFontData; | 40 class SimpleFontData; |
| 41 | 41 |
| 42 class GlyphBuffer { | 42 class GlyphBuffer { |
| 43 STACK_ALLOCATED(); | 43 STACK_ALLOCATED(); |
| 44 public: | 44 public: |
| 45 bool isEmpty() const { return m_fontData.isEmpty(); } | 45 bool isEmpty() const { return m_fontData.isEmpty(); } |
| 46 virtual bool hasOffsets() const { return false; } | 46 bool hasOffsets() const { return !m_offsets.isEmpty(); } |
| 47 unsigned size() const { return m_fontData.size(); } | 47 unsigned size() const { return m_fontData.size(); } |
| 48 | 48 |
| 49 const Glyph* glyphs(unsigned from) const { return m_glyphs.data() + from; } | 49 const Glyph* glyphs(unsigned from) const { return m_glyphs.data() + from; } |
| 50 const float* advances(unsigned from) const { return m_advances.data() + from
; } | 50 const float* advances(unsigned from) const { return m_advances.data() + from
; } |
| 51 const SimpleFontData* fontDataAt(unsigned index) const { return m_fontData[i
ndex]; } | 51 const FloatSize* offsets(unsigned from) const { return m_offsets.data() + fr
om; } |
| 52 |
| 53 const SimpleFontData* fontDataAt(unsigned index) const |
| 54 { |
| 55 return m_fontData[index]; |
| 56 } |
| 52 | 57 |
| 53 Glyph glyphAt(unsigned index) const | 58 Glyph glyphAt(unsigned index) const |
| 54 { | 59 { |
| 55 return m_glyphs[index]; | 60 return m_glyphs[index]; |
| 56 } | 61 } |
| 57 | 62 |
| 58 float advanceAt(unsigned index) const | 63 float advanceAt(unsigned index) const |
| 59 { | 64 { |
| 60 return m_advances[index]; | 65 return m_advances[index]; |
| 61 } | 66 } |
| 62 | 67 |
| 63 void add(Glyph glyph, const SimpleFontData* font, float width) | 68 void add(Glyph glyph, const SimpleFontData* font, float width) |
| 64 { | 69 { |
| 70 // should not mix offset/advance-only glyphs |
| 71 ASSERT(!hasOffsets()); |
| 72 |
| 65 m_fontData.append(font); | 73 m_fontData.append(font); |
| 66 m_glyphs.append(glyph); | 74 m_glyphs.append(glyph); |
| 67 m_advances.append(width); | 75 m_advances.append(width); |
| 68 } | 76 } |
| 69 | 77 |
| 78 void add(Glyph glyph, const SimpleFontData* font, const FloatSize& offset, f
loat advance) |
| 79 { |
| 80 // should not mix offset/advance-only glyphs |
| 81 ASSERT(size() == m_offsets.size()); |
| 82 |
| 83 m_fontData.append(font); |
| 84 m_glyphs.append(glyph); |
| 85 m_offsets.append(offset); |
| 86 m_advances.append(advance); |
| 87 } |
| 88 |
| 70 void reverse() | 89 void reverse() |
| 71 { | 90 { |
| 72 m_fontData.reverse(); | 91 m_fontData.reverse(); |
| 73 m_glyphs.reverse(); | 92 m_glyphs.reverse(); |
| 74 m_advances.reverse(); | 93 m_advances.reverse(); |
| 75 } | 94 } |
| 76 | 95 |
| 77 void expandLastAdvance(float width) | 96 void expandLastAdvance(float width) |
| 78 { | 97 { |
| 79 ASSERT(!isEmpty()); | 98 ASSERT(!isEmpty()); |
| 80 float& lastAdvance = m_advances.last(); | 99 float& lastAdvance = m_advances.last(); |
| 81 lastAdvance += width; | 100 lastAdvance += width; |
| 82 } | 101 } |
| 83 | 102 |
| 84 protected: | 103 protected: |
| 85 Vector<const SimpleFontData*, 2048> m_fontData; | 104 Vector<const SimpleFontData*, 2048> m_fontData; |
| 86 Vector<Glyph, 2048> m_glyphs; | 105 Vector<Glyph, 2048> m_glyphs; |
| 87 Vector<float, 2048> m_advances; | 106 Vector<float, 2048> m_advances; |
| 88 }; | |
| 89 | |
| 90 | |
| 91 class GlyphBufferWithOffsets : public GlyphBuffer { | |
| 92 public: | |
| 93 virtual bool hasOffsets() const override { return true; } | |
| 94 | |
| 95 const FloatSize* offsets(unsigned from) const { return m_offsets.data() + fr
om; } | |
| 96 | |
| 97 FloatSize offsetAt(unsigned index) const | |
| 98 { | |
| 99 return m_offsets[index]; | |
| 100 } | |
| 101 | |
| 102 void add(Glyph glyph, const SimpleFontData* font, const FloatSize& offset, f
loat advance) | |
| 103 { | |
| 104 m_fontData.append(font); | |
| 105 m_glyphs.append(glyph); | |
| 106 m_offsets.append(offset); | |
| 107 m_advances.append(advance); | |
| 108 } | |
| 109 | |
| 110 private: | |
| 111 void add(Glyph glyph, const SimpleFontData* font, float width) | |
| 112 { | |
| 113 ASSERT_NOT_REACHED(); | |
| 114 } | |
| 115 | |
| 116 void reverse() | |
| 117 { | |
| 118 ASSERT_NOT_REACHED(); | |
| 119 } | |
| 120 | |
| 121 Vector<FloatSize, 1024> m_offsets; | 107 Vector<FloatSize, 1024> m_offsets; |
| 122 }; | 108 }; |
| 123 | 109 |
| 124 } // namespace blink | 110 } // namespace blink |
| 125 | 111 |
| 126 #endif | 112 #endif |
| OLD | NEW |