1 /* -*- Mode: C; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // -------------------------------------------------------------------------*/
11 * ScritchUI Pencil fonts.
16 #ifndef SQUIRRELJME_SCRITCHUIPENCILFONT_H
17 #define SQUIRRELJME_SCRITCHUIPENCILFONT_H
19 #include "lib/scritchui/scritchuiPencil.h"
23 #ifndef SJME_CXX_IS_EXTERNED
24 #define SJME_CXX_IS_EXTERNED
25 #define SJME_CXX_SQUIRRELJME_SCRITCHUIPENCILFONT_H
27 #endif /* #ifdef SJME_CXX_IS_EXTERNED */
28 #endif /* #ifdef __cplusplus */
30 /*--------------------------------------------------------------------------*/
33 * Font face for pencil fonts.
37 typedef enum sjme_scritchui_pencilFontFace
40 SJME_SCRITCHUI_PENCIL_FONT_FACE_MONOSPACE
= 1,
43 SJME_SCRITCHUI_PENCIL_FONT_FACE_SERIF
= 2,
46 SJME_SCRITCHUI_PENCIL_FONT_FACE_SYMBOL
= 4,
48 /** Normal, nothing different from anything. */
49 SJME_SCRITCHUI_PENCIL_FONT_FACE_NORMAL
= 8,
50 } sjme_scritchui_pencilFontFace
;
53 * Checks if two brackets refer to the same font.
55 * @param a The first font.
56 * @param b The second font.
57 * @return If the two fonts are the same.
60 typedef sjme_jboolean (*sjme_scritchui_pencilFontEqualsFunc
)(
61 sjme_attrInNullable sjme_scritchui_pencilFont a
,
62 sjme_attrInNullable sjme_scritchui_pencilFont b
);
65 * Returns the direction of the given character in the font.
67 * @param inFont The font to check.
68 * @param inCodepoint The character.
69 * @param outDirection The direction of the character, will be @c -1 or @c 1 .
70 * @return Any resultant error, if any.
73 typedef sjme_errorCode (*sjme_scritchui_pencilFontMetricCharDirectionFunc
)(
74 sjme_attrInNotNull sjme_scritchui_pencilFont inFont
,
75 sjme_attrInPositive sjme_jint inCodepoint
,
76 sjme_attrOutNotNull
sjme_attrInRange(-1, 1) sjme_jint
* outDirection
);
79 * Checks whether the character in the given font is valid, as in it has
80 * a render-able glyph.
82 * @param inFont The font to check within.
83 * @param inCodepoint The character to check.
84 * @param outValid If the character in the font has a glyph and is valid.
85 * @return Any resultant error, if any.
88 typedef sjme_errorCode (*sjme_scritchui_pencilFontMetricCharValidFunc
)(
89 sjme_attrInNotNull sjme_scritchui_pencilFont inFont
,
90 sjme_attrInPositive sjme_jint inCodepoint
,
91 sjme_attrOutNotNull sjme_jboolean
* outValid
);
94 * Returns the @c sjme_scritchui_pencilFontFace of a font.
96 * @param inFont The font to request from.
97 * @param outFace The font face, any flag
98 * from @c sjme_scritchui_pencilFontFace .
99 * @return Any resultant error, if any.
102 typedef sjme_errorCode (*sjme_scritchui_pencilFontMetricFontFaceFunc
)(
103 sjme_attrInNotNull sjme_scritchui_pencilFont inFont
,
104 sjme_attrOutNotNull sjme_scritchui_pencilFontFace
* outFace
);
107 * Returns the name of the font.
109 * @param inFont The font to get the name of.
110 * @param outName The font name.
111 * @return Any resultant error, if any.
114 typedef sjme_errorCode (*sjme_scritchui_pencilFontMetricFontNameFunc
)(
115 sjme_attrInNotNull sjme_scritchui_pencilFont inFont
,
116 sjme_attrOutNotNull sjme_lpcstr
* outName
);
119 * Returns the style of the font.
121 * @param inFont The style of the font to request.
122 * @param outStyle The font style, will be flags
123 * from @c sjme_scritchui_pencilFontStyle .
124 * @return Any resultant error, if any.
127 typedef sjme_errorCode (*sjme_scritchui_pencilFontMetricFontStyleFunc
)(
128 sjme_attrInNotNull sjme_scritchui_pencilFont inFont
,
129 sjme_attrOutNotNull sjme_scritchui_pencilFontStyle
* outStyle
);
132 * Returns the ascent of the font.
134 * @param inFont The font to check.
135 * @param isMax Should the max be obtained.
136 * @param outAscent The ascent of the font in pixels.
137 * @return Any resultant error, if any.
140 typedef sjme_errorCode (*sjme_scritchui_pencilFontMetricPixelAscentFunc
)(
141 sjme_attrInNotNull sjme_scritchui_pencilFont inFont
,
142 sjme_attrInValue sjme_jboolean isMax
,
143 sjme_attrOutNotNull sjme_jint
* outAscent
);
146 * Returns the baseline of the font.
148 * @param inFont The font to check.
149 * @param outBaseline The baseline of the font in pixels.
150 * @return Any resultant error, if any.
153 typedef sjme_errorCode (*sjme_scritchui_pencilFontMetricPixelBaselineFunc
)(
154 sjme_attrInNotNull sjme_scritchui_pencilFont inFont
,
155 sjme_attrOutNotNull sjme_jint
* outBaseline
);
158 * Returns the height of the font.
160 * @param inFont The font to check.
161 * @param outHeight The height of the font in pixels.
162 * @return Any resultant error, if any.
165 typedef sjme_errorCode (*sjme_scritchui_pencilFontMetricPixelHeightFunc
)(
166 sjme_attrInNotNull sjme_scritchui_pencilFont inFont
,
167 sjme_attrOutNotNull sjme_jint
* outHeight
);
170 * Returns the descent of the font.
172 * @param inFont The font to check.
173 * @param isMax Should the max be obtained.
174 * @param outDescent The descent of the font in pixels.
175 * @return Any resultant error, if any.
178 typedef sjme_errorCode (*sjme_scritchui_pencilFontMetricPixelDescentFunc
)(
179 sjme_attrInNotNull sjme_scritchui_pencilFont inFont
,
180 sjme_attrInValue sjme_jboolean isMax
,
181 sjme_attrOutNotNull sjme_jint
* outDescent
);
184 * Returns the leading of the font.
186 * @param inFont The font to obtain from.
187 * @param outLeading The leading amount in pixels.
188 * @return Any resultant error, if any.
191 typedef sjme_errorCode (*sjme_scritchui_pencilFontMetricPixelLeadingFunc
)(
192 sjme_attrInNotNull sjme_scritchui_pencilFont inFont
,
193 sjme_attrOutNotNull sjme_attrOutPositiveNonZero sjme_jint
* outLeading
);
196 * Returns the pixel size of the font.
198 * @param inFont The font to get the size of.
199 * @param outSize The pixel size of the font.
200 * @return Any resultant error, if any.
203 typedef sjme_errorCode (*sjme_scritchui_pencilFontMetricPixelSizeFunc
)(
204 sjme_attrInNotNull sjme_scritchui_pencilFont inFont
,
205 sjme_attrOutNotNull sjme_attrOutPositiveNonZero sjme_jint
* outSize
);
208 * Returns the width of the given character.
210 * @param inFont The font to obtain from.
211 * @param inCodepoint The character.
212 * @param outWidth The width of the font in pixels.
213 * @return Any resultant error, if any.
216 typedef sjme_errorCode (*sjme_scritchui_pencilFontPixelCharWidthFunc
)(
217 sjme_attrInNotNull sjme_scritchui_pencilFont inFont
,
218 sjme_attrInPositive sjme_jint inCodepoint
,
219 sjme_attrOutNotNull sjme_attrOutPositiveNonZero sjme_jint
* outWidth
);
222 * Renders the font glyph to a bitmap represented in a byte array. Each
223 * byte within the array represents 8 pixels.
225 * @param inFont The font to render to the bitmap.
226 * @param inCodepoint The character to render.
227 * @param buf The resultant buffer.
228 * @param bufOff The offset into the buffer.
229 * @param bufScanLen The scanline length of the buffer.
230 * @param bufHeight The buffer height.
231 * @param outOffX X offset of glyph, for proper rendering.
232 * @param outOffY Y offset of glyph, for proper rendering.
233 * @return Any resultant error, if any.
236 typedef sjme_errorCode (*sjme_scritchui_pencilFontRenderBitmapFunc
)(
237 sjme_attrInNotNull sjme_scritchui_pencilFont inFont
,
238 sjme_attrInPositive sjme_jint inCodepoint
,
239 sjme_attrInNotNull sjme_jubyte
* buf
,
240 sjme_attrInPositive sjme_jint bufOff
,
241 sjme_attrInPositive sjme_jint bufScanLen
,
242 sjme_attrInPositive sjme_jint bufHeight
,
243 sjme_attrOutNullable sjme_jint
* outOffX
,
244 sjme_attrOutNullable sjme_jint
* outOffY
);
247 * Renders the given character to the resultant pencil.
249 * @param inFont The font to render from.
250 * @param inCodepoint The character to render.
251 * @param inPencil The pencil to draw into.
252 * @param xPos The target X position.
253 * @param yPos The target Y position.
254 * @param nextXPos Optional output which contains the next X
255 * coordinate accordingly for continual drawing.
256 * @param nextYPos Optional output which contains the next Y
257 * coordinate accordingly for continual drawing.
258 * @return Any resultant error, if any.
261 typedef sjme_errorCode (*sjme_scritchui_pencilFontRenderCharFunc
)(
262 sjme_attrInNotNull sjme_scritchui_pencilFont inFont
,
263 sjme_attrInPositive sjme_jint inCodepoint
,
264 sjme_attrInNotNull sjme_scritchui_pencil inPencil
,
265 sjme_attrInValue sjme_jint xPos
,
266 sjme_attrInNotNull sjme_jint yPos
,
267 sjme_attrOutNullable sjme_jint
* nextXPos
,
268 sjme_attrOutNullable sjme_jint
* nextYPos
);
271 * Calculates the width of the given string.
273 * @param inFont The font to calculate for.
274 * @param s The input character sequence.
275 * @param o The offset into the sequence.
276 * @param l The length of the sequence.
277 * @param outWidth The resultant pixel width.
278 * @return Any resultant error, if any.
281 typedef sjme_errorCode (*sjme_scritchui_pencilFontStringWidthFunc
)(
282 sjme_attrInNotNull sjme_scritchui_pencilFont inFont
,
283 sjme_attrInNotNull
const sjme_charSeq
* s
,
284 sjme_attrInPositive sjme_jint o
,
285 sjme_attrInPositive sjme_jint l
,
286 sjme_attrOutNotNull sjme_jint
* outWidth
);
288 /** Quick definition for functions. */
289 #define SJME_SCRITCHUI_QUICK_PENCIL(what, lWhat) \
290 SJME_TOKEN_PASTE3(sjme_scritchui_pencilFont, what, Func) lWhat
293 * Functions to access pencil fonts.
297 typedef struct sjme_scritchui_pencilFontFunctions
299 /** Checks font equality. */
300 SJME_SCRITCHUI_QUICK_PENCIL(Equals
, equals
);
302 /** Returns the direction of the character. */
303 SJME_SCRITCHUI_QUICK_PENCIL(MetricCharDirection
, metricCharDirection
);
305 /** Checks the validity of a glyph. */
306 SJME_SCRITCHUI_QUICK_PENCIL(MetricCharValid
, metricCharValid
);
308 /** Returns the face of the font. */
309 SJME_SCRITCHUI_QUICK_PENCIL(MetricFontFace
, metricFontFace
);
311 /** Returns the name of the font. */
312 SJME_SCRITCHUI_QUICK_PENCIL(MetricFontName
, metricFontName
);
314 /** Returns the style of the font. */
315 SJME_SCRITCHUI_QUICK_PENCIL(MetricFontStyle
, metricFontStyle
);
317 /** Returns the ascent of the font. */
318 SJME_SCRITCHUI_QUICK_PENCIL(MetricPixelAscent
, metricPixelAscent
);
320 /** Returns the baseline of the font. */
321 SJME_SCRITCHUI_QUICK_PENCIL(MetricPixelBaseline
, metricPixelBaseline
);
323 /** Returns the descent of the font. */
324 SJME_SCRITCHUI_QUICK_PENCIL(MetricPixelDescent
, metricPixelDescent
);
326 /** Returns the height of the font. */
327 SJME_SCRITCHUI_QUICK_PENCIL(MetricPixelHeight
, metricPixelHeight
);
329 /** Returns the leading of the font. */
330 SJME_SCRITCHUI_QUICK_PENCIL(MetricPixelLeading
, metricPixelLeading
);
332 /** Returns the pixel size of the font. */
333 SJME_SCRITCHUI_QUICK_PENCIL(MetricPixelSize
, metricPixelSize
);
335 /** Returns the width of the font character. */
336 SJME_SCRITCHUI_QUICK_PENCIL(PixelCharWidth
, pixelCharWidth
);
338 /** Renders the font character to a bitmap. */
339 SJME_SCRITCHUI_QUICK_PENCIL(RenderBitmap
, renderBitmap
);
341 /** Renders the font character to the given pencil. */
342 SJME_SCRITCHUI_QUICK_PENCIL(RenderChar
, renderChar
);
344 /** Calculates the length of the given string. */
345 SJME_SCRITCHUI_QUICK_PENCIL(StringWidth
, stringWidth
);
346 } sjme_scritchui_pencilFontFunctions
;
349 * Functions to native implementation access pencil fonts.
353 typedef struct sjme_scritchui_pencilFontImplFunctions
355 /** Checks font equality. */
356 SJME_SCRITCHUI_QUICK_PENCIL(Equals
, equals
);
358 /** Checks the validity of a glyph. */
359 SJME_SCRITCHUI_QUICK_PENCIL(MetricCharValid
, metricCharValid
);
361 /** Returns the face of the font. */
362 SJME_SCRITCHUI_QUICK_PENCIL(MetricFontFace
, metricFontFace
);
364 /** Returns the name of the font. */
365 SJME_SCRITCHUI_QUICK_PENCIL(MetricFontName
, metricFontName
);
367 /** Returns the style of the font. */
368 SJME_SCRITCHUI_QUICK_PENCIL(MetricFontStyle
, metricFontStyle
);
370 /** Returns the ascent of the font. */
371 SJME_SCRITCHUI_QUICK_PENCIL(MetricPixelAscent
, metricPixelAscent
);
373 /** Returns the baseline of the font. */
374 SJME_SCRITCHUI_QUICK_PENCIL(MetricPixelBaseline
, metricPixelBaseline
);
376 /** Returns the descent of the font. */
377 SJME_SCRITCHUI_QUICK_PENCIL(MetricPixelDescent
, metricPixelDescent
);
379 /** Returns the leading of the font. */
380 SJME_SCRITCHUI_QUICK_PENCIL(MetricPixelLeading
, metricPixelLeading
);
382 /** Returns the pixel size of the font. */
383 SJME_SCRITCHUI_QUICK_PENCIL(MetricPixelSize
, metricPixelSize
);
385 /** Returns the width of the font character. */
386 SJME_SCRITCHUI_QUICK_PENCIL(PixelCharWidth
, pixelCharWidth
);
388 /** Renders the font character to a bitmap. */
389 SJME_SCRITCHUI_QUICK_PENCIL(RenderBitmap
, renderBitmap
);
390 } sjme_scritchui_pencilFontImplFunctions
;
392 #undef SJME_SCRITCHUI_QUICK_PENCIL
394 struct sjme_scritchui_pencilFontLink
396 /** The loaded font for this link. */
397 sjme_scritchui_pencilFont font
;
399 /** The previous link. */
400 sjme_scritchui_pencilFontLink
* prev
;
402 /** The next link. */
403 sjme_scritchui_pencilFontLink
* next
;
407 * Determines the scanline length of a bitmap.
409 * @param w The bitmap width.
410 * @return The result scanline length.
413 sjme_jint
sjme_scritchui_pencilFontScanLen(
414 sjme_attrInPositive sjme_jint w
);
417 * Initializes a static pencil font.
419 * @param inOutFont The resultant font.
420 * @return Any resultant error, if any.
423 sjme_errorCode
sjme_scritchui_newPencilFontStatic(
424 sjme_scritchui_pencilFont inOutFont
);
426 /*--------------------------------------------------------------------------*/
430 #ifdef SJME_CXX_SQUIRRELJME_SCRITCHUIPENCILFONT_H
432 #undef SJME_CXX_SQUIRRELJME_SCRITCHUIPENCILFONT_H
433 #undef SJME_CXX_IS_EXTERNED
434 #endif /* #ifdef SJME_CXX_SQUIRRELJME_SCRITCHUIPENCILFONT_H */
435 #endif /* #ifdef __cplusplus */
437 #endif /* SQUIRRELJME_SCRITCHUIPENCILFONT_H */