xref: /aoo42x/main/sw/source/filter/ww8/styles.cxx (revision efeef26f)
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 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil -*- */
28 #include "../inc/wwstyles.hxx"
29 
30 #include <functional>               //std::unary_function
31 #include <algorithm>                //std::find_if
32 #include <tools/string.hxx>         //do we have to...
33 
34 #include <tools/debug.hxx>
35 #   include "staticassert.hxx"      //StaticAssert
36 
37 namespace
38 {
39     class SameName: public std::unary_function<const sal_Char*, bool>
40     {
41     private:
42         const String &mrName;
43     public:
SameName(const String & rName)44         explicit SameName(const String &rName) : mrName(rName) {}
operator ()(const sal_Char * pEntry) const45         bool operator() (const sal_Char *pEntry) const
46             { return mrName.EqualsAscii(pEntry); }
47     };
48 
GetStiNames()49     const sal_Char **GetStiNames() throw()
50     {
51         static const sal_Char *stiName[] =
52         {
53             "Normal",
54             "Heading 1",
55             "Heading 2",
56             "Heading 3",
57             "Heading 4",
58             "Heading 5",
59             "Heading 6",
60             "Heading 7",
61             "Heading 8",
62             "Heading 9",
63             "Index 1",
64             "Index 2",
65             "Index 3",
66             "Index 4",
67             "Index 5",
68             "Index 6",
69             "Index 7",
70             "Index 8",
71             "Index 9",
72             "TOC 1",
73             "TOC 2",
74             "TOC 3",
75             "TOC 4",
76             "TOC 5",
77             "TOC 6",
78             "TOC 7",
79             "TOC 8",
80             "TOC 9",
81             "Normal Indent",
82             "Footnote Text",
83             "Annotation Text",
84             "Header",
85             "Footer",
86             "Index Heading",
87             "Caption",
88             "Table of Figures",
89             "Envelope Address",
90             "Envelope Return",
91             "Footnote Reference",
92             "Annotation Reference",
93             "Line Number",
94             "Page Number",
95             "Endnote Reference",
96             "Endnote Text",
97             "Table of Authorities",
98             "Macro Text",
99             "TOA Heading",
100             "List",
101             "List 2",
102             "List 3",
103             "List 4",
104             "List 5",
105             "List Bullet",
106             "List Bullet 2",
107             "List Bullet 3",
108             "List Bullet 4",
109             "List Bullet 5",
110             "List Number",
111             "List Number 2",
112             "List Number 3",
113             "List Number 4",
114             "List Number 5",
115             "Title",
116             "Closing",
117             "Signature",
118             "Default Paragraph Font",
119             "Body Text",
120             "Body Text Indent",
121             "List Continue",
122             "List Continue 2",
123             "List Continue 3",
124             "List Continue 4",
125             "List Continue 5",
126             "Message Header",
127             "Subtitle",
128             "Salutation",
129             "Date",
130             "Body Text First Indent",
131             "Body Text First Indent 2",
132             "Note Heading",
133             "Body Text 2",
134             "Body Text 3",
135             "Body Text Indent 2",
136             "Body Text Indent 3",
137             "Block Text",
138             "Hyperlink",
139             "Followed Hyperlink",
140             "Strong",
141             "Emphasis",
142             "Document Map",
143             "Plain Text"
144         };
145 
146         DBG_ASSERT( (sizeof(stiName) / sizeof(stiName[0])) == ww::stiMax, "WrongSizeOfArray" );
147 
148         return stiName;
149     }
150 }
151 
152 namespace ww
153 {
154     //Original code/idea by Takashi Ono for CJK
GetCanonicalStiFromEnglishName(const String & rName)155     sti GetCanonicalStiFromEnglishName(const String &rName) throw()
156     {
157         typedef const sal_Char** myIter;
158         sti eRet = stiUser;
159         myIter aBegin = GetStiNames();
160         myIter aEnd(aBegin);
161         std::advance(aEnd, stiMax);
162         myIter aIter = std::find_if(aBegin, aEnd, SameName(rName));
163         if (aIter != aEnd)
164             eRet = static_cast<sti>(std::distance(aBegin, aIter));
165         return eRet;
166     }
167 
GetEnglishNameFromSti(sti eSti)168     const sal_Char* GetEnglishNameFromSti(sti eSti) throw()
169     {
170         if (eSti >= stiMax)
171             return 0;
172         else
173             return GetStiNames()[eSti];
174     }
175 
StandardStiIsCharStyle(sti eSti)176     bool StandardStiIsCharStyle(sti eSti) throw()
177     {
178         switch (eSti)
179         {
180             case stiFtnRef:
181             case stiAtnRef:
182             case stiLnn:
183             case stiPgn:
184             case stiEdnRef:
185             case stiNormalChar:
186                 return true;
187             default:
188                 return false;
189         }
190     }
191 
GetCanonicalStiFromStc(sal_uInt8 stc)192     sti GetCanonicalStiFromStc(sal_uInt8 stc) throw()
193     {
194         if (stc == 0)
195             return stiNormal;
196         else if (stc < 222)
197             return stiUser;
198         else
199         {
200             static sti aMapping[] =
201             {
202                 stiNil, stiAtnRef, stiAtnText, stiToc8, stiToc7, stiToc6,
203                 stiToc5, stiToc4, stiToc3, stiToc2, stiToc1, stiIndex7,
204                 stiIndex6, stiIndex5, stiIndex4, stiIndex3, stiIndex2,
205                 stiIndex1, stiLnn, stiIndexHeading, stiFooter, stiHeader,
206                 stiFtnRef, stiFtnText, stiLev9, stiLev8, stiLev7, stiLev6,
207                 stiLev5, stiLev4, stiLev3, stiLev2, stiLev1, stiNormIndent
208             };
209             return aMapping[stc-222];
210         }
211     }
212 }
213 
214 /* vi:set tabstop=4 shiftwidth=4 expandtab: */
215