]>
code.delx.au - refind/blob - libeg/text.c
3 * Text drawing functions
5 * Copyright (c) 2006 Christoph Pfisterer
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * * Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the
20 * * Neither the name of Christoph Pfisterer nor the names of the
21 * contributors may be used to endorse or promote products derived
22 * from this software without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 #include "egemb_font.h"
40 #define FONT_CELL_WIDTH (7)
41 #define FONT_CELL_HEIGHT (12)
43 static EG_IMAGE
*FontImage
= NULL
;
49 VOID
egMeasureText(IN CHAR16
*Text
, OUT UINTN
*Width
, OUT UINTN
*Height
)
52 *Width
= StrLen(Text
) * FONT_CELL_WIDTH
;
54 *Height
= FONT_CELL_HEIGHT
;
57 VOID
egRenderText(IN CHAR16
*Text
, IN OUT EG_IMAGE
*CompImage
, IN UINTN PosX
, IN UINTN PosY
)
60 EG_PIXEL
*FontPixelData
;
61 UINTN BufferLineOffset
, FontLineOffset
;
66 TextLength
= StrLen(Text
);
67 if (TextLength
* FONT_CELL_WIDTH
+ PosX
> CompImage
->Width
)
68 TextLength
= (CompImage
->Width
- PosX
) / FONT_CELL_WIDTH
;
71 if (FontImage
== NULL
)
72 FontImage
= egPrepareEmbeddedImage(&egemb_font
, TRUE
);
75 BufferPtr
= CompImage
->PixelData
;
76 BufferLineOffset
= CompImage
->Width
;
77 BufferPtr
+= PosX
+ PosY
* BufferLineOffset
;
78 FontPixelData
= FontImage
->PixelData
;
79 FontLineOffset
= FontImage
->Width
;
80 for (i
= 0; i
< TextLength
; i
++) {
82 if (c
< 32 || c
>= 127)
86 egRawCompose(BufferPtr
, FontPixelData
+ c
* FONT_CELL_WIDTH
,
87 FONT_CELL_WIDTH
, FONT_CELL_HEIGHT
,
88 BufferLineOffset
, FontLineOffset
);
89 BufferPtr
+= FONT_CELL_WIDTH
;