1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     font_PairFont.cpp
4 
5   Copyright (C)2009-2010 Nintendo Co., Ltd./HAL Laboratory, Inc.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law.  They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13   $Revision: 24480 $
14  *---------------------------------------------------------------------------*/
15 
16 #include "precompiled.h"
17 
18 #include <nn/assert.h>
19 #include <nw/font/font_PairFont.h>
20 #include <nw/ut/ut_inlines.h>
21 
22 namespace nw {
23 namespace font {
24 
25 
26 
27 /* ------------------------------------------------------------------------
28         コンストラクタ/デストラクタ
29    ------------------------------------------------------------------------ */
30 
PairFont(Font * primary,Font * secondary)31 PairFont::PairFont(Font* primary, Font* secondary)
32 :   m_Primary(primary),
33     m_Secondary(secondary),
34     m_AlternateWithPrimary(true)
35 {
36     NN_POINTER_ASSERT(primary);
37     NN_POINTER_ASSERT(secondary);
38     NN_ASSERT(primary->GetTextureFormat() == secondary->GetTextureFormat());
39     NN_ASSERT(primary->GetCharacterCode() == secondary->GetCharacterCode());
40 }
41 
42 
~PairFont()43 PairFont::~PairFont()
44 {
45 }
46 
47 
48 /* ------------------------------------------------------------------------
49         フォント全体情報アクセサ
50    ------------------------------------------------------------------------ */
51 
52 int
GetWidth() const53 PairFont::GetWidth() const
54 {
55     return math::Max(m_Primary->GetWidth(), m_Secondary->GetWidth());
56 }
57 
58 int
GetHeight() const59 PairFont::GetHeight() const
60 {
61     return math::Max(m_Primary->GetHeight(), m_Secondary->GetHeight());
62 }
63 
64 int
GetAscent() const65 PairFont::GetAscent() const
66 {
67     return m_Primary->GetHeight() >= m_Secondary->GetHeight() ?
68         m_Primary->GetAscent():
69         m_Secondary->GetAscent();
70 }
71 
72 int
GetDescent() const73 PairFont::GetDescent() const
74 {
75     return m_Primary->GetHeight() >= m_Secondary->GetHeight() ?
76         m_Primary->GetDescent():
77         m_Secondary->GetDescent();
78 }
79 
80 int
GetBaselinePos() const81 PairFont::GetBaselinePos() const
82 {
83     return m_Primary->GetHeight() >= m_Secondary->GetHeight() ?
84         m_Primary->GetBaselinePos():
85         m_Secondary->GetBaselinePos();
86 }
87 
88 int
GetCellHeight() const89 PairFont::GetCellHeight() const
90 {
91     return m_Primary->GetHeight() >= m_Secondary->GetHeight() ?
92         m_Primary->GetCellHeight():
93         m_Secondary->GetCellHeight();
94 }
95 
96 int
GetCellWidth() const97 PairFont::GetCellWidth() const
98 {
99     return m_Primary->GetWidth() >= m_Secondary->GetWidth() ?
100         m_Primary->GetCellWidth():
101         m_Secondary->GetCellWidth();
102 }
103 
104 int
GetMaxCharWidth() const105 PairFont::GetMaxCharWidth() const
106 {
107     return math::Max(m_Primary->GetMaxCharWidth(), m_Secondary->GetMaxCharWidth());
108 }
109 
110 Font::Type
GetType() const111 PairFont::GetType() const
112 {
113     return TYPE_PAIR;
114 }
115 
116 TexFmt
GetTextureFormat() const117 PairFont::GetTextureFormat() const
118 {
119     // テクスチャフォーマットは一致していなければならない
120     return m_Primary->GetTextureFormat();
121 }
122 
123 int
GetLineFeed() const124 PairFont::GetLineFeed() const
125 {
126     return math::Max(m_Primary->GetLineFeed(), m_Secondary->GetLineFeed());
127 }
128 
129 const CharWidths
GetDefaultCharWidths() const130 PairFont::GetDefaultCharWidths() const
131 {
132     return m_Primary->GetWidth() >= m_Secondary->GetWidth() ?
133         m_Primary->GetDefaultCharWidths():
134         m_Secondary->GetDefaultCharWidths();
135 }
136 
137 void
SetDefaultCharWidths(const CharWidths & widths)138 PairFont::SetDefaultCharWidths(const CharWidths& widths)
139 {
140     m_Primary->SetDefaultCharWidths(widths);
141     m_Secondary->SetDefaultCharWidths(widths);
142 }
143 
144 bool
SetAlternateChar(CharCode c)145 PairFont::SetAlternateChar(CharCode c)
146 {
147     bool bPrimary = m_Primary->SetAlternateChar(c);
148     bool bSecondary = m_Secondary->SetAlternateChar(c);
149     if (bPrimary)
150     {
151         m_AlternateWithPrimary = true;
152         return true;
153     }
154     else if (bSecondary)
155     {
156         m_AlternateWithPrimary = false;
157         return true;
158     }
159     else
160     {
161         return false;
162     }
163 }
164 
165 void
SetLineFeed(int linefeed)166 PairFont::SetLineFeed(int linefeed)
167 {
168     NW_FONT_MINMAX_ASSERT(linefeed, 0, USHRT_MAX);
169 
170     return m_Primary->GetHeight() >= m_Secondary->GetHeight() ?
171         m_Primary->SetLineFeed(linefeed):
172         m_Secondary->SetLineFeed(linefeed);
173 }
174 
175 
176 
177 /* ------------------------------------------------------------------------
178         文字単体情報アクセサ
179    ------------------------------------------------------------------------ */
180 
181 int
GetCharWidth(CharCode c) const182 PairFont::GetCharWidth(CharCode c) const
183 {
184     if (m_Primary->HasGlyph(c))
185     {
186         return m_Primary->GetCharWidth(c);
187     }
188     else if (m_Secondary->HasGlyph(c))
189     {
190         return m_Secondary->GetCharWidth(c);
191     }
192     else if (m_AlternateWithPrimary)
193     {
194         return m_Primary->GetCharWidth(c);
195     }
196     else
197     {
198         return m_Secondary->GetCharWidth(c);
199     }
200 }
201 
202 const CharWidths
GetCharWidths(CharCode c) const203 PairFont::GetCharWidths(CharCode c) const
204 {
205     if (m_Primary->HasGlyph(c))
206     {
207         return m_Primary->GetCharWidths(c);
208     }
209     else if (m_Secondary->HasGlyph(c))
210     {
211         return m_Secondary->GetCharWidths(c);
212     }
213     else if (m_AlternateWithPrimary)
214     {
215         return m_Primary->GetCharWidths(c);
216     }
217     else
218     {
219         return m_Secondary->GetCharWidths(c);
220     }
221 }
222 
223 void
GetGlyph(Glyph * glyph,CharCode c) const224 PairFont::GetGlyph(
225      Glyph*     glyph,
226      CharCode   c
227 ) const
228 {
229     if (m_Primary->HasGlyph(c))
230     {
231         return m_Primary->GetGlyph(glyph, c);
232     }
233     else if (m_Secondary->HasGlyph(c))
234     {
235         return m_Secondary->GetGlyph(glyph, c);
236     }
237     else if (m_AlternateWithPrimary)
238     {
239         return m_Primary->GetGlyph(glyph, c);
240     }
241     else
242     {
243         return m_Secondary->GetGlyph(glyph, c);
244     }
245 }
246 
247 bool
HasGlyph(CharCode c) const248 PairFont::HasGlyph(CharCode c) const
249 {
250     return m_Primary->HasGlyph(c) || m_Secondary->HasGlyph(c);
251 }
252 
253 
254 /* ------------------------------------------------------------------------
255         文字ストリーム
256    ------------------------------------------------------------------------ */
257 
258 CharacterCode
GetCharacterCode() const259 PairFont::GetCharacterCode() const
260 {
261     // 文字列エンコーディング形式は一致していなければならない
262     return m_Primary->GetCharacterCode();
263 }
264 
265 /* ------------------------------------------------------------------------
266         テクスチャフィルタ
267    ------------------------------------------------------------------------ */
268 
269 void
EnableLinearFilter(bool atSmall,bool atLarge)270 PairFont::EnableLinearFilter(
271     bool    atSmall,
272     bool    atLarge
273 )
274 {
275     m_Primary->EnableLinearFilter(atSmall, atLarge);
276     m_Secondary->EnableLinearFilter(atSmall, atLarge);
277 }
278 
279 bool
IsLinearFilterEnableAtSmall() const280 PairFont::IsLinearFilterEnableAtSmall() const
281 {
282     // プライマリの値を返します(値は一致していなければならない)。
283     return m_Primary->IsLinearFilterEnableAtSmall();
284 }
285 
286 bool
IsLinearFilterEnableAtLarge() const287 PairFont::IsLinearFilterEnableAtLarge() const
288 {
289     // プライマリの値を返します(値は一致していなければならない)。
290     return m_Primary->IsLinearFilterEnableAtLarge();
291 }
292 
293 u32
GetTextureWrapFilterValue() const294 PairFont::GetTextureWrapFilterValue() const
295 {
296     // プライマリの値を返します(値は一致していなければならない)。
297     return m_Primary->GetTextureWrapFilterValue();
298 }
299 
300 
301 
302 }   // namespace font
303 }   // namespace nw
304