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 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_sw.hxx" 26 27 #include "../inc/wwstyles.hxx" 28 29 #include <functional> //std::unary_function 30 #include <algorithm> //std::find_if 31 #include <tools/string.hxx> //do we have to... 32 33 #include <tools/debug.hxx> 34 # include "staticassert.hxx" //StaticAssert 35 36 namespace 37 { 38 class SameName: public std::unary_function<const sal_Char*, bool> 39 { 40 private: 41 const String &mrName; 42 public: SameName(const String & rName)43 explicit SameName(const String &rName) : mrName(rName) {} operator ()(const sal_Char * pEntry) const44 bool operator() (const sal_Char *pEntry) const 45 { return mrName.EqualsAscii(pEntry); } 46 }; 47 GetStiNames()48 const sal_Char **GetStiNames() throw() 49 { 50 static const sal_Char *stiName[] = 51 { 52 "Normal", 53 "Heading 1", 54 "Heading 2", 55 "Heading 3", 56 "Heading 4", 57 "Heading 5", 58 "Heading 6", 59 "Heading 7", 60 "Heading 8", 61 "Heading 9", 62 "Index 1", 63 "Index 2", 64 "Index 3", 65 "Index 4", 66 "Index 5", 67 "Index 6", 68 "Index 7", 69 "Index 8", 70 "Index 9", 71 "TOC 1", 72 "TOC 2", 73 "TOC 3", 74 "TOC 4", 75 "TOC 5", 76 "TOC 6", 77 "TOC 7", 78 "TOC 8", 79 "TOC 9", 80 "Normal Indent", 81 "Footnote Text", 82 "Annotation Text", 83 "Header", 84 "Footer", 85 "Index Heading", 86 "Caption", 87 "Table of Figures", 88 "Envelope Address", 89 "Envelope Return", 90 "Footnote Reference", 91 "Annotation Reference", 92 "Line Number", 93 "Page Number", 94 "Endnote Reference", 95 "Endnote Text", 96 "Table of Authorities", 97 "Macro Text", 98 "TOA Heading", 99 "List", 100 "List 2", 101 "List 3", 102 "List 4", 103 "List 5", 104 "List Bullet", 105 "List Bullet 2", 106 "List Bullet 3", 107 "List Bullet 4", 108 "List Bullet 5", 109 "List Number", 110 "List Number 2", 111 "List Number 3", 112 "List Number 4", 113 "List Number 5", 114 "Title", 115 "Closing", 116 "Signature", 117 "Default Paragraph Font", 118 "Body Text", 119 "Body Text Indent", 120 "List Continue", 121 "List Continue 2", 122 "List Continue 3", 123 "List Continue 4", 124 "List Continue 5", 125 "Message Header", 126 "Subtitle", 127 "Salutation", 128 "Date", 129 "Body Text First Indent", 130 "Body Text First Indent 2", 131 "Note Heading", 132 "Body Text 2", 133 "Body Text 3", 134 "Body Text Indent 2", 135 "Body Text Indent 3", 136 "Block Text", 137 "Hyperlink", 138 "Followed Hyperlink", 139 "Strong", 140 "Emphasis", 141 "Document Map", 142 "Plain Text" 143 }; 144 145 DBG_ASSERT( (sizeof(stiName) / sizeof(stiName[0])) == ww::stiMax, "WrongSizeOfArray" ); 146 147 return stiName; 148 } 149 } 150 151 namespace ww 152 { 153 //Original code/idea by Takashi Ono for CJK GetCanonicalStiFromEnglishName(const String & rName)154 sti GetCanonicalStiFromEnglishName(const String &rName) throw() 155 { 156 typedef const sal_Char** myIter; 157 sti eRet = stiUser; 158 myIter aBegin = GetStiNames(); 159 myIter aEnd(aBegin); 160 std::advance(aEnd, stiMax); 161 myIter aIter = std::find_if(aBegin, aEnd, SameName(rName)); 162 if (aIter != aEnd) 163 eRet = static_cast<sti>(std::distance(aBegin, aIter)); 164 return eRet; 165 } 166 GetEnglishNameFromSti(sti eSti)167 const sal_Char* GetEnglishNameFromSti(sti eSti) throw() 168 { 169 if (eSti >= stiMax) 170 return 0; 171 else 172 return GetStiNames()[eSti]; 173 } 174 StandardStiIsCharStyle(sti eSti)175 bool StandardStiIsCharStyle(sti eSti) throw() 176 { 177 switch (eSti) 178 { 179 case stiFtnRef: 180 case stiAtnRef: 181 case stiLnn: 182 case stiPgn: 183 case stiEdnRef: 184 case stiNormalChar: 185 return true; 186 default: 187 return false; 188 } 189 } 190 GetCanonicalStiFromStc(sal_uInt8 stc)191 sti GetCanonicalStiFromStc(sal_uInt8 stc) throw() 192 { 193 if (stc == 0) 194 return stiNormal; 195 else if (stc < 222) 196 return stiUser; 197 else 198 { 199 static sti aMapping[] = 200 { 201 stiNil, stiAtnRef, stiAtnText, stiToc8, stiToc7, stiToc6, 202 stiToc5, stiToc4, stiToc3, stiToc2, stiToc1, stiIndex7, 203 stiIndex6, stiIndex5, stiIndex4, stiIndex3, stiIndex2, 204 stiIndex1, stiLnn, stiIndexHeading, stiFooter, stiHeader, 205 stiFtnRef, stiFtnText, stiLev9, stiLev8, stiLev7, stiLev6, 206 stiLev5, stiLev4, stiLev3, stiLev2, stiLev1, stiNormIndent 207 }; 208 return aMapping[stc-222]; 209 } 210 } 211 } 212 213 /* vi:set tabstop=4 shiftwidth=4 expandtab: */ 214