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