svgnode.cxx (4374d266) | svgnode.cxx (9d56236f) |
---|---|
1/************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance --- 41 unchanged lines hidden (view full) --- 50 const SvgStyleAttributes* SvgNode::checkForCssStyle(const rtl::OUString& rClassStr, const SvgStyleAttributes& rOriginal) const 51 { 52 if(maCssStyleVector.empty()) // #120435# Evaluate for CSS styles only once, this cannot change 53 { 54 const SvgDocument& rDocument = getDocument(); 55 56 if(rDocument.hasSvgStyleAttributesById()) 57 { | 1/************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance --- 41 unchanged lines hidden (view full) --- 50 const SvgStyleAttributes* SvgNode::checkForCssStyle(const rtl::OUString& rClassStr, const SvgStyleAttributes& rOriginal) const 51 { 52 if(maCssStyleVector.empty()) // #120435# Evaluate for CSS styles only once, this cannot change 53 { 54 const SvgDocument& rDocument = getDocument(); 55 56 if(rDocument.hasSvgStyleAttributesById()) 57 { |
58 // #125293# If we have CssStyles we need to buuild a linked list of SvgStyleAttributes 59 // which represent this for the current object. There are various methods to 60 // specify CssStyles which need to be taken into account in a given order: 61 // - 'id' element 62 // - 'class' element(s) 63 // - type-dependent elements (e..g. 'rect' for all rect elements) 64 // - local firect attributes (rOriginal) 65 // - inherited attributes (up the hierarchy) 66 // The first three will be collected in maCssStyleVector for the current element 67 // (once, this will not change) and be linked in the needed order using the 68 // get/setCssStyleParent at the SvgStyleAttributes which will be used preferred in 69 // member evaluation over the existing parent hierarchy 70 71 // check for 'id' references 72 if(getId()) 73 { 74 // search for CSS style equal to Id 75 const SvgStyleAttributes* pNew = rDocument.findSvgStyleAttributesById(*getId()); 76 77 if(pNew) 78 { 79 const_cast< SvgNode* >(this)->maCssStyleVector.push_back(pNew); 80 } 81 } 82 83 // check for 'class' references |
|
58 if(getClass()) 59 { 60 // find all referenced CSS styles, a list of entries is allowed 61 const rtl::OUString* pClassList = getClass(); 62 const sal_Int32 nLen(pClassList->getLength()); 63 sal_Int32 nPos(0); 64 const SvgStyleAttributes* pNew = 0; 65 66 skip_char(*pClassList, sal_Unicode(' '), nPos, nLen); | 84 if(getClass()) 85 { 86 // find all referenced CSS styles, a list of entries is allowed 87 const rtl::OUString* pClassList = getClass(); 88 const sal_Int32 nLen(pClassList->getLength()); 89 sal_Int32 nPos(0); 90 const SvgStyleAttributes* pNew = 0; 91 92 skip_char(*pClassList, sal_Unicode(' '), nPos, nLen); |
67 | 93 |
68 while(nPos < nLen) 69 { 70 rtl::OUStringBuffer aTokenValue; | 94 while(nPos < nLen) 95 { 96 rtl::OUStringBuffer aTokenValue; |
71 | 97 |
72 copyToLimiter(*pClassList, sal_Unicode(' '), nPos, aTokenValue, nLen); 73 skip_char(*pClassList, sal_Unicode(' '), nPos, nLen); 74 75 rtl::OUString aId(rtl::OUString::createFromAscii(".")); 76 const rtl::OUString aOUTokenValue(aTokenValue.makeStringAndClear()); | 98 copyToLimiter(*pClassList, sal_Unicode(' '), nPos, aTokenValue, nLen); 99 skip_char(*pClassList, sal_Unicode(' '), nPos, nLen); 100 101 rtl::OUString aId(rtl::OUString::createFromAscii(".")); 102 const rtl::OUString aOUTokenValue(aTokenValue.makeStringAndClear()); |
77 | 103 |
78 // look for CSS style common to token 79 aId = aId + aOUTokenValue; 80 pNew = rDocument.findSvgStyleAttributesById(aId); | 104 // look for CSS style common to token 105 aId = aId + aOUTokenValue; 106 pNew = rDocument.findSvgStyleAttributesById(aId); |
81 | 107 |
82 if(!pNew && rClassStr.getLength()) 83 { 84 // look for CSS style common to class.token 85 aId = rClassStr + aId; | 108 if(!pNew && rClassStr.getLength()) 109 { 110 // look for CSS style common to class.token 111 aId = rClassStr + aId; |
86 | 112 |
87 pNew = rDocument.findSvgStyleAttributesById(aId); 88 } | 113 pNew = rDocument.findSvgStyleAttributesById(aId); 114 } |
89 | 115 |
90 if(pNew) 91 { 92 const_cast< SvgNode* >(this)->maCssStyleVector.push_back(pNew); 93 } 94 } 95 } | 116 if(pNew) 117 { 118 const_cast< SvgNode* >(this)->maCssStyleVector.push_back(pNew); 119 } 120 } 121 } |
96 97 if(maCssStyleVector.empty() && getId()) 98 { 99 // if none found, search for CSS style equal to Id 100 const SvgStyleAttributes* pNew = rDocument.findSvgStyleAttributesById(*getId()); | |
101 | 122 |
102 if(pNew) 103 { 104 const_cast< SvgNode* >(this)->maCssStyleVector.push_back(pNew); 105 } 106 } 107 108 if(maCssStyleVector.empty() && rClassStr.getLength()) | 123 // check for class-dependent references to CssStyles 124 if(rClassStr.getLength()) |
109 { | 125 { |
110 // if none found, search for CSS style equal to class type | 126 // search for CSS style equal to class type |
111 const SvgStyleAttributes* pNew = rDocument.findSvgStyleAttributesById(rClassStr); | 127 const SvgStyleAttributes* pNew = rDocument.findSvgStyleAttributesById(rClassStr); |
112 | 128 |
113 if(pNew) 114 { 115 const_cast< SvgNode* >(this)->maCssStyleVector.push_back(pNew); 116 } 117 } 118 } 119 } 120 | 129 if(pNew) 130 { 131 const_cast< SvgNode* >(this)->maCssStyleVector.push_back(pNew); 132 } 133 } 134 } 135 } 136 |
121 if(!maCssStyleVector.empty()) | 137 if(maCssStyleVector.empty()) |
122 { | 138 { |
123 // #123510# if CSS styles were found, create a linked list with rOriginal as parent 124 // and all CSS styles as linked children, so that the style attribute has 125 // priority over the CSS style. If there is no style attribute this means that 126 // no values are set at rOriginal, thus it is still correct to have that order. 127 // Repeated style requests should only be issued from sub-Text nodes and I'm not 128 // sure if in-between text nodes may build other chains (should not happen). But 129 // it's only a re-chaining with pointers (cheap), so allow to do it every time. 130 SvgStyleAttributes* pCurrent = const_cast< SvgStyleAttributes* >(&rOriginal); 131 pCurrent->setCssStyleParent(0); | 139 // return original if no CssStlyes found 140 return &rOriginal; 141 } 142 else 143 { 144 // #125293# rOriginal will be the last element in the linked list; use no CssStyleParent 145 // there (reset it) to ensure that the parent hierarchy will be used when it's base 146 // is referenced. This new chaning inserts the CssStyles before the original style, 147 // this makes the whole process much safer since the original style when used will 148 // be not different to the situation without CssStyles; thus loops which may be caused 149 // by trying to use the parent hierarchy of the owner of the style will be avoided 150 // already in this mechanism. It's still good to keep the supportsParentStyle 151 // from #125258# in place, though. 152 // This chain building using pointers will be done every time when checkForCssStyle 153 // is used (not the search, only the chaining). This is needed since the CssStyles 154 // themselves will be potentially used multiple times. It is not expensive since it's 155 // only changing some pointers. 156 // The alternative would be to create the style hierarchy for every element (or even 157 // for the element containing the hierarchy) in a vector of pointers and to use that. 158 // Resetting the CssStyleParent on rOriginal is probably not needeed 159 // but simply safer to do. 160 const_cast< SvgStyleAttributes& >(rOriginal).setCssStyleParent(0); |
132 | 161 |
133 for(sal_uInt32 a(0); a < maCssStyleVector.size(); a++) | 162 // loop over the existing CssStyles and link them. There is a first one, take 163 // as current 164 SvgStyleAttributes* pCurrent = const_cast< SvgStyleAttributes* >(maCssStyleVector[0]); 165 166 for(sal_uInt32 a(1); a < maCssStyleVector.size(); a++) |
134 { 135 SvgStyleAttributes* pNext = const_cast< SvgStyleAttributes* >(maCssStyleVector[a]); 136 137 pCurrent->setCssStyleParent(pNext); 138 pCurrent = pNext; | 167 { 168 SvgStyleAttributes* pNext = const_cast< SvgStyleAttributes* >(maCssStyleVector[a]); 169 170 pCurrent->setCssStyleParent(pNext); 171 pCurrent = pNext; |
139 pCurrent->setCssStyleParent(0); | |
140 } | 172 } |
141 } | |
142 | 173 |
143 return &rOriginal; | 174 // pCurrent is the last used CssStyle, let it point to the original style 175 pCurrent->setCssStyleParent(&rOriginal); 176 177 // return 1st CssStyle as style chain start element (only for the 178 // local element, still no hierarchy used here) 179 return maCssStyleVector[0]; 180 } |
144 } 145 146 SvgNode::SvgNode( 147 SVGToken aType, 148 SvgDocument& rDocument, 149 SvgNode* pParent) 150 : maType(aType), 151 mrDocument(rDocument), --- 439 unchanged lines hidden --- | 181 } 182 183 SvgNode::SvgNode( 184 SVGToken aType, 185 SvgDocument& rDocument, 186 SvgNode* pParent) 187 : maType(aType), 188 mrDocument(rDocument), --- 439 unchanged lines hidden --- |