Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. | 2 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. |
| 3 * | 3 * |
| 4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
| 5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
| 6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
| 7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
| 8 * | 8 * |
| 9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 155 fillCharacterDataMap(m_textPositions[i]); | 155 fillCharacterDataMap(m_textPositions[i]); |
| 156 | 156 |
| 157 // Handle x/y default attributes. | 157 // Handle x/y default attributes. |
| 158 SVGCharacterData& data = m_characterDataMap.add(1, SVGCharacterData()).store dValue->value; | 158 SVGCharacterData& data = m_characterDataMap.add(1, SVGCharacterData()).store dValue->value; |
| 159 if (SVGTextLayoutAttributes::isEmptyValue(data.x)) | 159 if (SVGTextLayoutAttributes::isEmptyValue(data.x)) |
| 160 data.x = 0; | 160 data.x = 0; |
| 161 if (SVGTextLayoutAttributes::isEmptyValue(data.y)) | 161 if (SVGTextLayoutAttributes::isEmptyValue(data.y)) |
| 162 data.y = 0; | 162 data.y = 0; |
| 163 } | 163 } |
| 164 | 164 |
| 165 static inline void updateCharacterData(unsigned i, float& lastRotation, SVGChara cterData& data, const SVGLengthContext& lengthContext, const SVGLengthList* xLis t, const SVGLengthList* yList, const SVGLengthList* dxList, const SVGLengthList* dyList, const SVGNumberList* rotateList) | 165 namespace { |
| 166 | |
| 167 class AttributeListsIterator { | |
| 168 STACK_ALLOCATED(); | |
| 169 public: | |
| 170 AttributeListsIterator(SVGTextPositioningElement*); | |
| 171 | |
| 172 bool hasAttributes() const | |
| 173 { | |
| 174 return m_xListRemaining || m_yListRemaining | |
| 175 || m_dxListRemaining || m_dyListRemaining | |
| 176 || m_rotateListRemaining; | |
| 177 } | |
| 178 void updateCharacterData(unsigned index, SVGCharacterData&); | |
| 179 | |
| 180 bool hasRotation() const { return !SVGTextLayoutAttributes::isEmptyValue(m_l astRotation); } | |
| 181 float lastRotation() const { return m_lastRotation; } | |
| 182 unsigned rotateEnd() const { return m_rotateList->length(); } | |
| 183 | |
| 184 private: | |
| 185 SVGLengthContext m_lengthContext; | |
| 186 Member<SVGLengthList> m_xList; | |
| 187 unsigned m_xListRemaining; | |
| 188 Member<SVGLengthList> m_yList; | |
| 189 unsigned m_yListRemaining; | |
| 190 Member<SVGLengthList> m_dxList; | |
| 191 unsigned m_dxListRemaining; | |
| 192 Member<SVGLengthList> m_dyList; | |
| 193 unsigned m_dyListRemaining; | |
| 194 Member<SVGNumberList> m_rotateList; | |
| 195 unsigned m_rotateListRemaining; | |
| 196 float m_lastRotation; | |
| 197 }; | |
| 198 | |
| 199 AttributeListsIterator::AttributeListsIterator(SVGTextPositioningElement* elemen t) | |
| 200 : m_lengthContext(element) | |
| 201 , m_xList(element->x()->currentValue()) | |
| 202 , m_xListRemaining(m_xList->length()) | |
| 203 , m_yList(element->y()->currentValue()) | |
| 204 , m_yListRemaining(m_yList->length()) | |
| 205 , m_dxList(element->dx()->currentValue()) | |
| 206 , m_dxListRemaining(m_dxList->length()) | |
| 207 , m_dyList(element->dy()->currentValue()) | |
| 208 , m_dyListRemaining(m_dyList->length()) | |
| 209 , m_rotateList(element->rotate()->currentValue()) | |
| 210 , m_rotateListRemaining(m_rotateList->length()) | |
| 211 , m_lastRotation(SVGTextLayoutAttributes::emptyValue()) | |
| 166 { | 212 { |
| 167 if (xList) | 213 } |
| 168 data.x = xList->at(i)->value(lengthContext); | 214 |
| 169 if (yList) | 215 inline void AttributeListsIterator::updateCharacterData(unsigned index, SVGChara cterData& data) |
| 170 data.y = yList->at(i)->value(lengthContext); | 216 { |
| 171 if (dxList) | 217 if (m_xListRemaining) { |
| 172 data.dx = dxList->at(i)->value(lengthContext); | 218 data.x = m_xList->at(index)->value(m_lengthContext); |
| 173 if (dyList) | 219 --m_xListRemaining; |
| 174 data.dy = dyList->at(i)->value(lengthContext); | 220 } |
| 175 if (rotateList) { | 221 if (m_yListRemaining) { |
| 176 data.rotate = rotateList->at(i)->value(); | 222 data.y = m_yList->at(index)->value(m_lengthContext); |
| 177 lastRotation = data.rotate; | 223 --m_yListRemaining; |
| 224 } | |
| 225 if (m_dxListRemaining) { | |
| 226 data.dx = m_dxList->at(index)->value(m_lengthContext); | |
| 227 --m_dxListRemaining; | |
| 228 } | |
| 229 if (m_dyListRemaining) { | |
| 230 data.dy = m_dyList->at(index)->value(m_lengthContext); | |
| 231 --m_dyListRemaining; | |
| 232 } | |
| 233 if (m_rotateListRemaining) { | |
| 234 data.rotate = m_rotateList->at(index)->value(); | |
| 235 m_lastRotation = data.rotate; | |
|
pdr.
2016/04/04 22:12:17
Not a fan of this, but I see you've done it to hel
| |
| 236 --m_rotateListRemaining; | |
| 178 } | 237 } |
| 179 } | 238 } |
| 180 | 239 |
| 240 } // namespace | |
| 241 | |
| 181 void SVGTextLayoutAttributesBuilder::fillCharacterDataMap(const TextPosition& po sition) | 242 void SVGTextLayoutAttributesBuilder::fillCharacterDataMap(const TextPosition& po sition) |
| 182 { | 243 { |
| 183 RawPtr<SVGLengthList> xList = position.element->x()->currentValue(); | 244 AttributeListsIterator attrLists(position.element); |
| 184 RawPtr<SVGLengthList> yList = position.element->y()->currentValue(); | 245 for (unsigned i = 0; attrLists.hasAttributes() && i < position.length; ++i) { |
| 185 RawPtr<SVGLengthList> dxList = position.element->dx()->currentValue(); | 246 SVGCharacterData& data = m_characterDataMap.add(position.start + i + 1, SVGCharacterData()).storedValue->value; |
| 186 RawPtr<SVGLengthList> dyList = position.element->dy()->currentValue(); | 247 attrLists.updateCharacterData(i, data); |
| 187 RawPtr<SVGNumberList> rotateList = position.element->rotate()->currentValue( ); | 248 } |
| 188 | 249 |
| 189 unsigned xListSize = xList->length(); | 250 if (!attrLists.hasRotation()) |
| 190 unsigned yListSize = yList->length(); | |
| 191 unsigned dxListSize = dxList->length(); | |
| 192 unsigned dyListSize = dyList->length(); | |
| 193 unsigned rotateListSize = rotateList->length(); | |
| 194 if (!xListSize && !yListSize && !dxListSize && !dyListSize && !rotateListSiz e) | |
| 195 return; | 251 return; |
| 196 | 252 |
| 197 float lastRotation = SVGTextLayoutAttributes::emptyValue(); | 253 // The last rotation value always spans the whole scope. |
|
pdr.
2016/04/04 22:12:17
TIL
| |
| 198 SVGLengthContext lengthContext(position.element); | 254 for (unsigned i = attrLists.rotateEnd(); i < position.length; ++i) { |
| 199 for (unsigned i = 0; i < position.length; ++i) { | |
| 200 const SVGLengthList* xListPtr = i < xListSize ? xList.get() : 0; | |
| 201 const SVGLengthList* yListPtr = i < yListSize ? yList.get() : 0; | |
| 202 const SVGLengthList* dxListPtr = i < dxListSize ? dxList.get() : 0; | |
| 203 const SVGLengthList* dyListPtr = i < dyListSize ? dyList.get() : 0; | |
| 204 const SVGNumberList* rotateListPtr = i < rotateListSize ? rotateList.get () : 0; | |
| 205 if (!xListPtr && !yListPtr && !dxListPtr && !dyListPtr && !rotateListPtr ) | |
| 206 break; | |
| 207 | |
| 208 SVGCharacterData& data = m_characterDataMap.add(position.start + i + 1, SVGCharacterData()).storedValue->value; | 255 SVGCharacterData& data = m_characterDataMap.add(position.start + i + 1, SVGCharacterData()).storedValue->value; |
| 209 updateCharacterData(i, lastRotation, data, lengthContext, xListPtr, yLis tPtr, dxListPtr, dyListPtr, rotateListPtr); | 256 data.rotate = attrLists.lastRotation(); |
| 210 } | |
| 211 | |
| 212 // The last rotation value always spans the whole scope. | |
| 213 if (SVGTextLayoutAttributes::isEmptyValue(lastRotation)) | |
| 214 return; | |
| 215 | |
| 216 for (unsigned i = rotateList->length(); i < position.length; ++i) { | |
| 217 SVGCharacterData& data = m_characterDataMap.add(position.start + i + 1, SVGCharacterData()).storedValue->value; | |
| 218 data.rotate = lastRotation; | |
| 219 } | 257 } |
| 220 } | 258 } |
| 221 | 259 |
| 222 DEFINE_TRACE(SVGTextLayoutAttributesBuilder::TextPosition) | 260 DEFINE_TRACE(SVGTextLayoutAttributesBuilder::TextPosition) |
| 223 { | 261 { |
| 224 visitor->trace(element); | 262 visitor->trace(element); |
| 225 } | 263 } |
| 226 | 264 |
| 227 } // namespace blink | 265 } // namespace blink |
| OLD | NEW |