1 /* libsswf_tag_csmtextsettings.c++ -- written by Alexis WILKE for Made to Order Software Corp. (c) 2002-2008 */
2 
3 /*
4 
5 Copyright (c) 2002-2008 Made to Order Software Corp.
6 
7 Permission is hereby granted, free of charge, to any
8 person obtaining a copy of this software and
9 associated documentation files (the "Software"), to
10 deal in the Software without restriction, including
11 without limitation the rights to use, copy, modify,
12 merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom
14 the Software is furnished to do so, subject to the
15 following conditions:
16 
17 The above copyright notice and this permission notice
18 shall be included in all copies or substantial
19 portions of the Software.
20 
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
22 ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
23 LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
24 FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
25 EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
28 ARISING FROM, OUT OF OR IN CONNECTION WITH THE
29 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 SOFTWARE.
31 
32 */
33 
34 /** \file
35  *
36  * \brief The implementation of the sswf::TagCSMTextSettings class
37  *
38  * This file declares the body of the functions which are not
39  * inline. It is part of the SSWF library.
40  */
41 
42 #include	"sswf/libsswf.h"
43 
44 using namespace sswf;
45 
46 
47 
48 
49 /////////////////////////////////////////// TagCSMTextSettings
50 
51 
52 
53 /** \class sswf::TagCSMTextSettings
54  *
55  * \brief Defines extraneous settings for text tags.
56  *
57  * This object defines extraneous settings to be used with text
58  * tags such as DefineText, DefineText2 and DefineEditText.
59  *
60  * \sa sswf::TagEditText
61  * \sa sswf::TagFont
62  * \sa sswf::TagText
63  * \sa <a href="../SWFalexref.html#tag_csmtextsettings">SWF Alexis' Reference&mdash;CSM Text Settings</a>
64  * \sa <a href="../SWFalexref.html#swf_tag">SWF Alexis' Reference&mdash;swf_tag</a>
65  */
66 
67 
68 /** \enum sswf::TagCSMTextSettings::csm_text_renderer_t
69  *
70  * \brief The list of renderer available in the Flash player
71  *
72  * This enumeration is used to list all the text renderers available
73  * in a Flash Player.
74  */
75 
76 /** \var sswf::TagCSMTextSettings::CSM_TEXT_RENDERER_NORMAL
77  *
78  * \brief Use the normal renderer.
79  *
80  * This value is used as the default. It will use the older Flash renderer
81  * instead of the FontType specialized renderer.
82  */
83 
84 /** \var sswf::TagCSMTextSettings::CSM_TEXT_RENDERER_FLASH
85  *
86  * \brief Use the special FontType renderer
87  *
88  * This value is used to ask the player to use the new Font Type renderer.
89  * This option appeared in SFW version 8.
90  *
91  * It is supposed to do a much better job at drawing small fonts.
92  */
93 
94 /** \enum sswf::TagCSMTextSettings::csm_text_gridfit_t
95  *
96  * \brief Defines how to draw points in regard to screen pixels.
97  *
98  * This enumeration is used to define how to render fonts in regard
99  * to pixels.
100  */
101 
102 /** \var sswf::TagCSMTextSettings::CSM_TEXT_GRIDFIT_NO_GRID
103  *
104  * \brief The default value meaning draw text anywhere.
105  *
106  * This value is the default and lets the renderer draw the font at
107  * any position. Very useful if you are scrolling your text horizontally
108  * or rotating it.
109  */
110 
111 /** \var sswf::TagCSMTextSettings::CSM_TEXT_GRIDFIT_PIXEL
112  *
113  * \brief The simple pixel grid snap feature.
114  *
115  * This value indicates that fonts should be drawn on a per pixel
116  * basis.
117  *
118  * There are two problems with this method:
119  *
120  * \li Some glyphs will be rendered a little further than they
121  *     should otherwise be. This can make some words look broken.
122  *
123  * \li Moving such fonts in any direction will make it jump if the
124  *     move is too slow.
125  */
126 
127 /** \var sswf::TagCSMTextSettings::CSM_TEXT_GRIDFIT_SUBPIXEL
128  *
129  * \brief Use 1/3rd of a pixel to snap the font.
130  *
131  * This feature allows for 1/3rd of a pixel snapping system that
132  * mostly solves the two problems of the PIXEL Grid Fit.
133  */
134 
135 
136 /** \brief Initializes the CSM Text Settings tag.
137  *
138  * This function initializes the CSM Text Settings tag to its
139  * defaults. This means it will not be used.
140  */
TagCSMTextSettings(void)141 TagCSMTextSettings::TagCSMTextSettings(void)
142 {
143 	f_csm_text_renderer = CSM_TEXT_RENDERER_NORMAL;
144 	f_csm_text_gridfit = CSM_TEXT_GRIDFIT_NO_GRID;
145 	f_thickness = 0.0f;
146 	f_sharpness = 0.0f;
147 }
148 
149 /** \brief Clean up the TagCSMTextSettings
150  *
151  * This function cleans up the CSM Text Settings tag.
152  *
153  * Also, the existance of a virtual function makes the
154  * TagCSMTextSettings class polymorphic.
155  */
~TagCSMTextSettings()156 TagCSMTextSettings::~TagCSMTextSettings()
157 {
158 }
159 
160 
161 
162 
163 
164 /** \brief Check whether an option is not the default.
165  *
166  * This function checks all the parameters of the TagCSMTextSettings
167  * and returns true if any one of them was modified and thus the
168  * tag needs to be saved.
169  *
170  * \return True if the tag needs to be saved.
171  */
IsCSMTextSettingsDefined(void) const172 bool TagCSMTextSettings::IsCSMTextSettingsDefined(void) const
173 {
174 	return f_csm_text_renderer != CSM_TEXT_RENDERER_NORMAL
175 		|| f_csm_text_gridfit != CSM_TEXT_GRIDFIT_NO_GRID
176 		|| f_thickness != 0.0f
177 		|| f_sharpness != 0.0f;
178 }
179 
180 
181 /** \brief Defines the renderer to use.
182  *
183  * This function is used to define the renderer to use
184  * with this TagCSMTextSetting.
185  *
186  * \param[in] csm_text_renderer The new renderer.
187  */
SetRenderer(csm_text_renderer_t csm_text_renderer)188 void TagCSMTextSettings::SetRenderer(csm_text_renderer_t csm_text_renderer)
189 {
190 	f_csm_text_renderer = csm_text_renderer;
191 }
192 
193 
194 /** \brief Defines the grid to use.
195  *
196  * This function is used to define the grid to use
197  * with this TagCSMTextSetting.
198  *
199  * \param[in] csm_text_gridfit The new grid mode.
200  */
SetGridFit(csm_text_gridfit_t csm_text_gridfit)201 void TagCSMTextSettings::SetGridFit(csm_text_gridfit_t csm_text_gridfit)
202 {
203 	f_csm_text_gridfit = csm_text_gridfit;
204 }
205 
206 
207 /** \brief Defines the thickness to use.
208  *
209  * This function is used to define the thickness to use
210  * with this TagCSMTextSetting.
211  *
212  * \param[in] thickness The new thickness.
213  */
SetThickness(float thickness)214 void TagCSMTextSettings::SetThickness(float thickness)
215 {
216 	f_thickness = thickness;
217 }
218 
219 
220 /** \brief Defines the sharpness to use.
221  *
222  * This function is used to define the sharpness to use
223  * with this TagCSMTextSetting.
224  *
225  * \param[in] sharpness The new sharpness.
226  */
SetSharpness(float sharpness)227 void TagCSMTextSettings::SetSharpness(float sharpness)
228 {
229 	f_sharpness = sharpness;
230 }
231 
232 
233 
234 /** \brief Ensure that the minimum version is 8.
235  *
236  * This function ensures that the minimum version is 8 if the
237  * tag needs to be saved. Otherwise it does nothing.
238  *
239  * \return An error code or ErrorManager::ERROR_CODE_NONE.
240  */
PreSaveCSMTextSettings(void)241 ErrorManager::error_code_t TagCSMTextSettings::PreSaveCSMTextSettings(void)
242 {
243 	TagBaseID *base_id = dynamic_cast<TagBaseID *>(this);
244 
245 	if(IsCSMTextSettingsDefined()) {
246 		base_id->MinimumVersion(8);
247 	}
248 
249 	return ErrorManager::ERROR_CODE_NONE;
250 }
251 
252 
253 /** \brief Save the TagCSMTextSettings in the specified Data buffer.
254  *
255  * This function checks whether the tag needs to be saved.
256  * If not, nothing happens and the function returns immediately.
257  * Otherwise, it saves the TagCSMTextSettings.
258  *
259  * \param[in] data The Data buffer where the tag is saved
260  *
261  * \return An error code or ErrorManager::ERROR_CODE_NONE.
262  */
SaveCSMTextSettings(Data & data)263 ErrorManager::error_code_t TagCSMTextSettings::SaveCSMTextSettings(Data& data)
264 {
265 	if(!IsCSMTextSettingsDefined()) {
266 		return ErrorManager::ERROR_CODE_NONE;
267 	}
268 
269 	TagBaseID *base_id = dynamic_cast<TagBaseID *>(this);
270 	base_id->SaveTag(data, TagBase::SWF_TAG_CSM_TEXT_SETTINGS, 12);
271 	base_id->SaveID(data);
272 	data.WriteBits(f_csm_text_renderer, 2);
273 	data.WriteBits(f_csm_text_gridfit, 3);
274 	data.WriteBits(0, 3);
275 	data.PutLongFloat(f_thickness);
276 	data.PutLongFloat(f_sharpness);
277 	data.PutByte(0);
278 
279 	return ErrorManager::ERROR_CODE_NONE;
280 }
281 
282 
283 
284 
285 /* The following options fold the documentation; use 'zi' to turn on and off
286  *
287  * vim: foldexpr=getline(v\:lnum)!~'^/\\*\\*'&&getline(v\:lnum)!~'^\ \\*'?0\:1 foldcolumn=2 foldmethod=expr
288  */
289