Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include "pppoptimizertoken.hxx"
22 : #include <osl/mutex.hxx>
23 : #include <sal/macros.h>
24 : #include <boost/unordered_map.hpp>
25 : #include <string.h>
26 :
27 : struct THash
28 : {
29 0 : size_t operator()( const char* s ) const
30 : {
31 0 : return rtl_str_hashCode(s);
32 : }
33 : };
34 : struct TCheck
35 : {
36 0 : bool operator()( const char* s1, const char* s2 ) const
37 : {
38 0 : return strcmp( s1, s2 ) == 0;
39 : }
40 : };
41 : typedef boost::unordered_map< const char*, PPPOptimizerTokenEnum, THash, TCheck> TypeNameHashMap;
42 : static TypeNameHashMap* pHashMap = NULL;
43 0 : static ::osl::Mutex& getHashMapMutex()
44 : {
45 0 : static osl::Mutex s_aHashMapProtection;
46 0 : return s_aHashMapProtection;
47 : }
48 :
49 : struct TokenTable
50 : {
51 : const char* pS;
52 : PPPOptimizerTokenEnum pE;
53 : };
54 :
55 : static const TokenTable pTokenTableArray[] =
56 : {
57 : { "rdmNavi", TK_rdmNavi },
58 : { "lnNavSep1", TK_lnNavSep1 },
59 : { "lnNavSep2", TK_lnNavSep2 },
60 : { "btnNavBack", TK_btnNavBack },
61 : { "btnNavNext", TK_btnNavNext },
62 : { "btnNavFinish", TK_btnNavFinish },
63 : { "btnNavCancel", TK_btnNavCancel },
64 :
65 : { "FixedText0Pg0", TK_FixedText0Pg0 },
66 : { "FixedText1Pg0", TK_FixedText1Pg0 },
67 : { "Separator1Pg0", TK_Separator1Pg0 },
68 : { "FixedText2Pg0", TK_FixedText2Pg0 },
69 : { "ListBox0Pg0", TK_ListBox0Pg0 },
70 : { "Button0Pg0", TK_Button0Pg0 },
71 : { "RadioButton0Pg1", TK_RadioButton0Pg1 },
72 : { "RadioButton1Pg1", TK_RadioButton1Pg1 },
73 : { "FixedText0Pg1", TK_FixedText0Pg1 },
74 : { "CheckBox1Pg1", TK_CheckBox1Pg1 },
75 : { "FixedText1Pg1", TK_FixedText1Pg1 },
76 : { "FixedText2Pg1", TK_FixedText2Pg1 },
77 : { "FormattedField0Pg1", TK_FormattedField0Pg1 },
78 : { "ComboBox0Pg1", TK_ComboBox0Pg1 },
79 : { "CheckBox2Pg1", TK_CheckBox2Pg1 },
80 : { "FixedText0Pg2", TK_FixedText0Pg2 },
81 : { "FixedText1Pg2", TK_FixedText1Pg2 },
82 : { "CheckBox0Pg2", TK_CheckBox0Pg2 },
83 : { "RadioButton0Pg2", TK_RadioButton0Pg2 },
84 : { "RadioButton1Pg2", TK_RadioButton1Pg2 },
85 : { "FixedText0Pg3", TK_FixedText0Pg3 },
86 : { "CheckBox0Pg3", TK_CheckBox0Pg3 },
87 : { "FixedText1Pg3", TK_FixedText1Pg3 },
88 : { "CheckBox1Pg3", TK_CheckBox1Pg3 },
89 : { "FixedText2Pg3", TK_FixedText2Pg3 },
90 : { "CheckBox2Pg3", TK_CheckBox2Pg3 },
91 : { "CheckBox3Pg3", TK_CheckBox3Pg3 },
92 : { "ListBox0Pg3", TK_ListBox0Pg3 },
93 : { "Separator0Pg4", TK_Separator0Pg4 },
94 : { "RadioButton0Pg4", TK_RadioButton0Pg4 },
95 : { "RadioButton1Pg4", TK_RadioButton1Pg4 },
96 : { "Separator1Pg4", TK_Separator1Pg4 },
97 : { "FixedText0Pg4", TK_FixedText0Pg4 },
98 : { "FixedText1Pg4", TK_FixedText1Pg4 },
99 : { "FixedText2Pg4", TK_FixedText2Pg4 },
100 : { "FixedText3Pg4", TK_FixedText3Pg4 },
101 : { "FixedText4Pg4", TK_FixedText4Pg4 },
102 : { "FixedText5Pg4", TK_FixedText5Pg4 },
103 : { "FixedText6Pg4", TK_FixedText6Pg4 },
104 : { "FixedText7Pg4", TK_FixedText7Pg4 },
105 : { "FixedText8Pg4", TK_FixedText8Pg4 },
106 : { "CheckBox1Pg4", TK_CheckBox1Pg4 },
107 : { "ComboBox0Pg4", TK_ComboBox0Pg4 },
108 :
109 : { "_blank", TK__blank },
110 : { "_self", TK__self },
111 : { "Activated", TK_Activated },
112 : { "Align", TK_Align },
113 : { "Alpha", TK_Alpha },
114 : { "Animated", TK_Animated },
115 : { "Background", TK_Background },
116 : { "BitmapPath", TK_BitmapPath },
117 : { "Border", TK_Border },
118 : { "Closeable", TK_Closeable },
119 : { "ColorMode", TK_ColorMode },
120 : { "Complete", TK_Complete },
121 : { "Compression", TK_Compression },
122 : { "CurrentItemID", TK_CurrentItemID },
123 : { "DefaultButton", TK_DefaultButton },
124 : { "DocumentService", TK_DocumentService },
125 : { "Dropdown", TK_Dropdown },
126 : { "EffectiveValue", TK_EffectiveValue },
127 : { "EffectiveMin", TK_EffectiveMin },
128 : { "EffectiveMax", TK_EffectiveMax },
129 : { "Enabled", TK_Enabled },
130 : { "Extensions", TK_Extensions },
131 : { "FileSizeDestination",TK_FileSizeDestination },
132 : { "FileSizeSource", TK_FileSizeSource },
133 : { "FillBitmap", TK_FillBitmap },
134 : { "FillBitmapLogicalSize",TK_FillBitmapLogicalSize },
135 : { "FillBitmapMode", TK_FillBitmapMode },
136 : { "FillBitmapSizeX", TK_FillBitmapSizeX },
137 : { "FillBitmapSizeY", TK_FillBitmapSizeY },
138 : { "FillBitmapURL", TK_FillBitmapURL },
139 : { "FillStyle", TK_FillStyle },
140 : { "FilterData", TK_FilterData },
141 : { "FilterName", TK_FilterName },
142 : { "Flags", TK_Flags },
143 : { "FontDescriptor", TK_FontDescriptor },
144 : { "Graphic", TK_Graphic },
145 : { "GraphicCrop", TK_GraphicCrop },
146 : { "GraphicCropLogic", TK_GraphicCropLogic },
147 : { "GraphicURL", TK_GraphicURL },
148 : { "GraphicStreamURL", TK_GraphicStreamURL },
149 : { "Height", TK_Height },
150 : { "Hidden", TK_Hidden },
151 : { "ID", TK_ID },
152 : { "ImageURL", TK_ImageURL },
153 : { "InformationDialog", TK_InformationDialog },
154 : { "InputStream", TK_InputStream },
155 : { "Interlaced", TK_Interlaced },
156 : { "IsInternal", TK_IsInternal },
157 : { "Label", TK_Label },
158 : { "LineCount", TK_LineCount },
159 : { "LogicalHeight", TK_LogicalHeight },
160 : { "LogicalWidth", TK_LogicalWidth },
161 : { "LogicalSize", TK_LogicalSize },
162 : { "MimeType", TK_MimeType },
163 : { "Moveable", TK_Moveable },
164 : { "MultiLine", TK_MultiLine },
165 : { "MultiSelection", TK_MultiSelection },
166 : { "Name", TK_Name },
167 : { "Orientation", TK_Orientation },
168 : { "OutputStream", TK_OutputStream },
169 : { "PixelHeight", TK_PixelHeight },
170 : { "PixelWidth", TK_PixelWidth },
171 : { "PositionX", TK_PositionX },
172 : { "PositionY", TK_PositionY },
173 : { "Progress", TK_Progress },
174 : { "ProgressValue", TK_ProgressValue },
175 : { "ProgressValueMax", TK_ProgressValueMax },
176 : { "ProgressValueMin", TK_ProgressValueMin },
177 : { "PushButtonType", TK_PushButtonType },
178 : { "Quality", TK_Quality },
179 : { "ReadOnly", TK_ReadOnly },
180 : { "Repeat", TK_Repeat },
181 : { "ScaleImage", TK_ScaleImage },
182 : { "SelectedItems", TK_SelectedItems },
183 : { "Settings", TK_Settings },
184 : { "Size100thMM", TK_Size100thMM },
185 : { "SizePixel", TK_SizePixel },
186 : { "Spin", TK_Spin },
187 : { "Step", TK_Step },
188 : { "State", TK_State },
189 : { "StatusDispatcher", TK_StatusDispatcher },
190 : { "StringItemList", TK_StringItemList },
191 : { "Strings", TK_Strings },
192 : { "TabIndex", TK_TabIndex },
193 : { "Template", TK_Template },
194 : { "Text", TK_Text },
195 : { "Title", TK_Title },
196 : { "Transparent", TK_Transparent },
197 : { "Type", TK_Type },
198 : { "UIName", TK_UIName },
199 : { "Value", TK_Value },
200 : { "Width", TK_Width },
201 : { "ZOrder", TK_ZOrder },
202 :
203 : { "LastUsedSettings", TK_LastUsedSettings },
204 : { "Settings/Templates", TK_Settings_Templates },
205 : { "Settings/Templates/",TK_Settings_Templates_ },
206 : { "JPEGCompression", TK_JPEGCompression },
207 : { "JPEGQuality", TK_JPEGQuality },
208 : { "RemoveCropArea", TK_RemoveCropArea },
209 : { "ImageResolution", TK_ImageResolution },
210 : { "EmbedLinkedGraphics",TK_EmbedLinkedGraphics },
211 : { "OLEOptimization", TK_OLEOptimization },
212 : { "OLEOptimizationType",TK_OLEOptimizationType },
213 : { "DeleteUnusedMasterPages", TK_DeleteUnusedMasterPages },
214 : { "DeleteHiddenSlides", TK_DeleteHiddenSlides },
215 : { "DeleteNotesPages", TK_DeleteNotesPages },
216 : { "CustomShowName", TK_CustomShowName },
217 : { "SaveAs", TK_SaveAs },
218 : { "SaveAsURL", TK_SaveAsURL },
219 : { "OpenNewDocument", TK_OpenNewDocument },
220 : { "EstimatedFileSize", TK_EstimatedFileSize },
221 :
222 : { "Status", TK_Status },
223 : { "Pages", TK_Pages },
224 : { "CurrentPage", TK_CurrentPage },
225 : { "GraphicObjects", TK_GraphicObjects },
226 : { "CurrentGraphicObject",TK_CurrentGraphicObject },
227 : { "OLEObjects", TK_OLEObjects },
228 : { "CurrentOLEObject", TK_CurrentOLEObject },
229 :
230 : { "STR_SUN_OPTIMIZATION_WIZARD2",STR_SUN_OPTIMIZATION_WIZARD2 },
231 : { "STR_STEPS", STR_STEPS },
232 : { "STR_BACK", STR_BACK },
233 : { "STR_NEXT", STR_NEXT },
234 : { "STR_FINISH", STR_FINISH },
235 : { "STR_CANCEL", STR_CANCEL },
236 : { "STR_INTRODUCTION", STR_INTRODUCTION },
237 : { "STR_INTRODUCTION_T", STR_INTRODUCTION_T },
238 : { "STR_CHOSE_SETTINGS", STR_CHOSE_SETTINGS },
239 : { "STR_REMOVE", STR_REMOVE },
240 : { "STR_GRAPHIC_OPTIMIZATION", STR_GRAPHIC_OPTIMIZATION },
241 : { "STR_IMAGE_OPTIMIZATION", STR_IMAGE_OPTIMIZATION },
242 : { "STR_LOSSLESS_COMPRESSION", STR_LOSSLESS_COMPRESSION },
243 : { "STR_JPEG_COMPRESSION", STR_JPEG_COMPRESSION },
244 : { "STR_QUALITY", STR_QUALITY },
245 : { "STR_REMOVE_CROP_AREA", STR_REMOVE_CROP_AREA },
246 : { "STR_IMAGE_RESOLUTION", STR_IMAGE_RESOLUTION },
247 : { "STR_IMAGE_RESOLUTION_0", STR_IMAGE_RESOLUTION_0 },
248 : { "STR_IMAGE_RESOLUTION_1", STR_IMAGE_RESOLUTION_1 },
249 : { "STR_IMAGE_RESOLUTION_2", STR_IMAGE_RESOLUTION_2 },
250 : { "STR_IMAGE_RESOLUTION_3", STR_IMAGE_RESOLUTION_3 },
251 : { "STR_EMBED_LINKED_GRAPHICS", STR_EMBED_LINKED_GRAPHICS },
252 : { "STR_OLE_OBJECTS", STR_OLE_OBJECTS },
253 : { "STR_OLE_OPTIMIZATION", STR_OLE_OPTIMIZATION },
254 : { "STR_OLE_REPLACE", STR_OLE_REPLACE },
255 : { "STR_ALL_OLE_OBJECTS", STR_ALL_OLE_OBJECTS },
256 : { "STR_ALIEN_OLE_OBJECTS_ONLY", STR_ALIEN_OLE_OBJECTS_ONLY },
257 : { "STR__OLE_OBJECTS_DESC", STR_OLE_OBJECTS_DESC },
258 : { "STR_NO_OLE_OBJECTS_DESC", STR_NO_OLE_OBJECTS_DESC },
259 : { "STR_SLIDES", STR_SLIDES },
260 : { "STR_CHOOSE_SLIDES", STR_CHOOSE_SLIDES },
261 : { "STR_MASTER_PAGES", STR_MASTER_PAGES },
262 : { "STR_DELETE_MASTER_PAGES", STR_DELETE_MASTER_PAGES },
263 : { "STR_DELETE_NOTES_PAGES", STR_DELETE_NOTES_PAGES },
264 : { "STR_DELETE_HIDDEN_SLIDES", STR_DELETE_HIDDEN_SLIDES },
265 : { "STR_CUSTOM_SHOW", STR_CUSTOM_SHOW },
266 : { "STR_SUMMARY", STR_SUMMARY },
267 : { "STR_SUMMARY_TITLE", STR_SUMMARY_TITLE },
268 : { "STR_PROGRESS", STR_PROGRESS },
269 : { "STR_OBJECTS_OPTIMIZED", STR_OBJECTS_OPTIMIZED },
270 : { "STR_APPLY_TO_CURRENT", STR_APPLY_TO_CURRENT },
271 : { "STR_AUTOMATICALLY_OPEN", STR_AUTOMATICALLY_OPEN },
272 : { "STR_SAVE_SETTINGS", STR_SAVE_SETTINGS },
273 : { "STR_SAVE_AS", STR_SAVE_AS },
274 : { "STR_DELETE_SLIDES", STR_DELETE_SLIDES },
275 : { "STR_OPTIMIZE_IMAGES", STR_OPTIMIZE_IMAGES },
276 : { "STR_CREATE_REPLACEMENT", STR_CREATE_REPLACEMENT },
277 : { "STR_CURRENT_FILESIZE", STR_CURRENT_FILESIZE },
278 : { "STR_ESTIMATED_FILESIZE", STR_ESTIMATED_FILESIZE },
279 : { "STR_MB", STR_MB },
280 : { "MY_SETTINGS", STR_MY_SETTINGS },
281 : { "STR_DEFAULT_SESSION", STR_DEFAULT_SESSION },
282 : { "STR_MODIFY_WARNING", STR_MODIFY_WARNING },
283 : { "STR_YES", STR_YES },
284 : { "STR_OK", STR_OK },
285 : { "STR_INFO_1", STR_INFO_1 },
286 : { "STR_INFO_2", STR_INFO_2 },
287 : { "STR_INFO_3", STR_INFO_3 },
288 : { "STR_INFO_4", STR_INFO_4 },
289 : { "STR_DUPLICATING_PRESENTATION",STR_DUPLICATING_PRESENTATION },
290 : { "STR_DELETING_SLIDES", STR_DELETING_SLIDES },
291 : { "STR_OPTIMIZING_GRAPHICS", STR_OPTIMIZING_GRAPHICS },
292 : { "STR_CREATING_OLE_REPLACEMENTS",STR_CREATING_OLE_REPLACEMENTS },
293 : { "STR_FileSizeSeparator", STR_FILESIZESEPARATOR },
294 :
295 : { "Last", TK_Last },
296 : { "NotFound", TK_NotFound }
297 : };
298 :
299 0 : PPPOptimizerTokenEnum TKGet( const rtl::OUString& rToken )
300 : {
301 0 : if ( !pHashMap )
302 : { // init hash map
303 0 : ::osl::MutexGuard aGuard( getHashMapMutex() );
304 0 : if ( !pHashMap )
305 : {
306 0 : TypeNameHashMap* pH = new TypeNameHashMap;
307 0 : const TokenTable* pPtr = pTokenTableArray;
308 0 : const TokenTable* pEnd = pPtr + SAL_N_ELEMENTS( pTokenTableArray );
309 0 : for ( ; pPtr < pEnd; pPtr++ )
310 0 : (*pH)[ pPtr->pS ] = pPtr->pE;
311 0 : pHashMap = pH;
312 0 : }
313 : }
314 0 : PPPOptimizerTokenEnum eRetValue = TK_NotFound;
315 0 : int i, nLen = rToken.getLength();
316 0 : char* pBuf = new char[ nLen + 1 ];
317 0 : for ( i = 0; i < nLen; i++ )
318 0 : pBuf[ i ] = (char)rToken[ i ];
319 0 : pBuf[ i ] = 0;
320 0 : TypeNameHashMap::iterator aHashIter( pHashMap->find( pBuf ) );
321 0 : delete[] pBuf;
322 0 : if ( aHashIter != pHashMap->end() )
323 0 : eRetValue = (*aHashIter).second;
324 0 : return eRetValue;
325 : }
326 :
327 0 : rtl::OUString TKGet( const PPPOptimizerTokenEnum eToken )
328 : {
329 : sal_uInt32 i = eToken >= TK_Last
330 : ? (sal_uInt32)TK_NotFound
331 0 : : (sal_uInt32)eToken;
332 0 : return rtl::OUString::createFromAscii( pTokenTableArray[ i ].pS );
333 : }
334 :
335 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|