ReactOS 0.4.16-dev-91-g764881a
glyph.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS win32 subsystem
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: GDI font driver for bitmap fonts
5 * PROGRAMMER: Timo Kreuzer (timo.kreuzer@reactos.org)
6 */
7
8#include "bmfd.h"
9
13 CHAR* pjBits,
14 ULONG x,
15 ULONG y,
16 ULONG ulHeight)
17{
18 CHAR j;
19 j = pjBits[(x/8) * ulHeight + y];
20 return (j >> (~x & 0x7)) & 1;
21}
22
23
25VOID
27 CHAR* pjBits,
28 ULONG x,
29 ULONG y,
30 ULONG cjRow,
32{
33 pjBits += y * cjRow;
34 pjBits += x / 8;
35 *pjBits |= color << (~x & 0x7);
36}
37
38
41 FONTOBJ *pfo,
42 PBMFD_FACE pface)
43{
44 PBMFD_FONT pfont = pfo->pvProducer;
47
48 if (!pfont)
49 {
50 /* Allocate realization info */
51 pfont = EngAllocMem(0, sizeof(BMFD_FONT), 0);
52 if (!pfont)
53 {
54 return NULL;
55 }
56
59
60 pfont->pfo = pfo;
61 pfont->pface = pface;
62 pfont->xScale = FLOATOBJ_GetLong(&xfo.eM11);
63 pfont->yScale = FLOATOBJ_GetLong(&xfo.eM22);
64 pfont->ulAngle = 0;
65
66 /* Set the pvProducer member of the fontobj */
67 pfo->pvProducer = pfont;
68 }
69
70 return pfont;
71}
72
73
76 PBMFD_FONT pfont,
77 HGLYPH hg,
79 GLYPHBITS *pgb,
81{
82 PBMFD_FACE pface = pfont->pface;
83 PGLYPHENTRY pge;
84 ULONG xSrc, ySrc, cxSrc, cySrc;
85 ULONG xDst, yDst, cxDst, cyDst;
86 LONG xScale, yScale;
87 ULONG ulGlyphOffset, cjDstRow, color;
88 PVOID pvSrc0, pvDst0;
89
90 /* The glyph handle is the byte offset to the glyph in the table */
91 pge = (PGLYPHENTRY)(pface->pCharTable + hg);
92
93 /* Get the bitmap offset depending on file version */
94 if (pface->ulVersion >= 0x300)
95 {
96 cxSrc = GETVAL(pge->ge20.geWidth);
97 ulGlyphOffset = GETVAL(pge->ge30.geOffset);
98 }
99 else
100 {
101 cxSrc = GETVAL(pge->ge30.geWidth);
102 ulGlyphOffset = GETVAL(pge->ge20.geOffset);
103 }
104 cySrc = pface->wPixHeight;
105
106 /* Pointer to the bitmap bits */
107 pvSrc0 = (PBYTE)pface->pFontInfo + ulGlyphOffset;
108 pvDst0 = pgb->aj;
109
110 xScale = pfont->xScale;
111 yScale = pfont->yScale;
112
113 /* Calculate extents of destination bitmap */
114 if (pfont->ulAngle == 90 || pfont->ulAngle == 270)
115 {
116 cxDst = cySrc * xScale;
117 cyDst = cxSrc * yScale;
118 }
119 else
120 {
121 cxDst = cxSrc * xScale;
122 cyDst = cySrc * yScale;
123 }
124 cjDstRow = (cxDst + 7) / 8;
125
126 if (pgd)
127 {
128 /* Fill GLYPHDATA structure */
129 pgd->gdf.pgb = pgb;
130 pgd->hg = hg;
131 pgd->fxD = xScale * (pface->wA + cxDst + pface->wC) << 4;
132 pgd->fxA = xScale * pface->wA << 4;
133 pgd->fxAB = xScale * (pface->wA + cxDst) << 4;
134 pgd->fxInkTop = yScale * pface->wAscent << 4;
135 pgd->fxInkBottom = - yScale * (pface->wDescent << 4);
136 pgd->rclInk.top = - yScale * pface->wAscent;
137 pgd->rclInk.bottom = yScale * pface->wDescent;
138 pgd->rclInk.left = xScale * pface->wA;
139 pgd->rclInk.right = pgd->rclInk.left + cxDst;
140 pgd->ptqD.x.LowPart = 0;
141 pgd->ptqD.x.HighPart = pgd->fxD;
142 pgd->ptqD.y.LowPart = 0;
143 pgd->ptqD.y.HighPart = 0;
144 }
145
146 if (pgb)
147 {
148 /* Verify that the buffer is big enough */
149 if (cjSize < FIELD_OFFSET(GLYPHBITS, aj) + cyDst * cjDstRow)
150 {
151 DbgPrint("Buffer too small (%ld), %ld,%ld\n",
152 cjSize, cxSrc, cySrc);
153 return FD_ERROR;
154 }
155
156 /* Fill GLYPHBITS structure */
157 pgb->ptlOrigin.x = xScale * pface->wA;
158 pgb->ptlOrigin.y = - yScale * pface->wAscent;
159 pgb->sizlBitmap.cx = cxDst;
160 pgb->sizlBitmap.cy = cyDst;
161
162 /* Erase destination surface */
163 memset(pvDst0, 0, cyDst * cjDstRow);
164
165 switch (pfont->ulAngle)
166 {
167 case 90:
168 /* Copy pixels */
169 for (yDst = 0; yDst < cyDst ; yDst++)
170 {
171 xSrc = yDst / yScale;
172 for (xDst = 0; xDst < cxDst; xDst++)
173 {
174 ySrc = (cxDst - xDst) / xScale;
175 color = _ReadPixel(pvSrc0, xSrc, ySrc, cySrc);
176 _WritePixel(pvDst0, xDst, yDst, cjDstRow, color);
177 }
178 }
179 break;
180
181 case 180:
182 for (yDst = 0; yDst < cyDst ; yDst++)
183 {
184 ySrc = (cyDst - yDst) / yScale;
185 for (xDst = 0; xDst < cxDst; xDst++)
186 {
187 xSrc = (cxDst - xDst) / xScale;
188 color = _ReadPixel(pvSrc0, xSrc, ySrc, cySrc);
189 _WritePixel(pvDst0, xDst, yDst, cjDstRow, color);
190 }
191 }
192 break;
193
194 case 270:
195 for (yDst = 0; yDst < cyDst ; yDst++)
196 {
197 xSrc = (cyDst - yDst) / yScale;
198 for (xDst = 0; xDst < cxDst; xDst++)
199 {
200 ySrc = xDst / xScale;
201 color = _ReadPixel(pvSrc0, xSrc, ySrc, cySrc);
202 _WritePixel(pvDst0, xDst, yDst, cjDstRow, color);
203 }
204 }
205 break;
206
207 case 0:
208 default:
209 for (yDst = 0; yDst < cyDst ; yDst++)
210 {
211 ySrc = yDst / yScale;
212 for (xDst = 0; xDst < cxDst; xDst++)
213 {
214 xSrc = xDst / xScale;
215 color = _ReadPixel(pvSrc0, xSrc, ySrc, cySrc);
216 _WritePixel(pvDst0, xDst, yDst, cjDstRow, color);
217 }
218 }
219 }
220 }
221
222 /* Return the size of the GLYPHBITS structure */
223 return FIELD_OFFSET(GLYPHBITS, aj) + cyDst * cjDstRow;
224}
225
226ULONG
228 PBMFD_FONT pfont,
229 PFD_DEVICEMETRICS pfddm,
231{
232 ULONG cjMaxWidth, cjMaxBitmapSize;
233 PFONTINFO16 pFontInfo;
234 ULONG xScale, yScale;
235
236 if (pfddm)
237 {
238 if (cjSize < sizeof(FD_DEVICEMETRICS))
239 {
240 /* Not enough space, fail */
241 return FD_ERROR;
242 }
243
244 pFontInfo = pfont->pface->pFontInfo;
245
246 xScale = pfont->xScale;
247 yScale = pfont->yScale;
248
249 /* Fill FD_DEVICEMETRICS */
250 pfddm->flRealizedType = FDM_MASK;
251 pfddm->pteBase.x = FLOATL_1;
252 pfddm->pteBase.y = 0;
253 pfddm->pteSide.x = 0;
254 pfddm->pteSide.y = FLOATL_1;
255 pfddm->ptlUnderline1.x = 0;
256 pfddm->ptlUnderline1.y = 1;
257 pfddm->ptlStrikeout.x = 0;
258 pfddm->ptlStrikeout.y = -4;
259 pfddm->ptlULThickness.x = 0;
260 pfddm->ptlULThickness.y = 1;
261 pfddm->ptlSOThickness.x = 0;
262 pfddm->ptlSOThickness.y = 1;
263 pfddm->lMinA = 0;
264 pfddm->lMinC = 0;
265 pfddm->lMinD = 0;
266
267 if (pfont->ulAngle == 90 || pfont->ulAngle == 270)
268 {
269 pfddm->cxMax = xScale * GETVAL(pFontInfo->dfPixHeight);
270 pfddm->cyMax = yScale * GETVAL(pFontInfo->dfMaxWidth);
271 pfddm->fxMaxAscender = yScale * GETVAL(pFontInfo->dfAscent) << 4;
272 pfddm->fxMaxDescender = (pfddm->cyMax << 4) - pfddm->fxMaxAscender;
273 }
274 else
275 {
276 pfddm->cxMax = xScale * GETVAL(pFontInfo->dfMaxWidth);
277 pfddm->cyMax = yScale * GETVAL(pFontInfo->dfPixHeight);
278 pfddm->fxMaxAscender = yScale * GETVAL(pFontInfo->dfAscent) << 4;
279 pfddm->fxMaxDescender = (pfddm->cyMax << 4) - pfddm->fxMaxAscender;
280 }
281
282 pfddm->lD = pfddm->cxMax;
283
284 /* Calculate Width in bytes */
285 cjMaxWidth = ((pfddm->cxMax + 7) >> 3);
286
287 /* Calculate size of the bitmap, rounded to DWORDs */
288 cjMaxBitmapSize = ((cjMaxWidth * pfddm->cyMax) + 3) & ~3;
289
290 /* cjGlyphMax is the full size of the GLYPHBITS structure */
291 pfddm->cjGlyphMax = FIELD_OFFSET(GLYPHBITS, aj) + cjMaxBitmapSize;
292
293 /* NOTE: fdxQuantized and NonLinear... stay unchanged */
294 }
295
296 /* Return the size of the structure */
297 return sizeof(FD_DEVICEMETRICS);
298}
299
300
306 FONTOBJ *pfo,
307 ULONG iMode)
308{
309 DbgPrint("BmfdQueryGlyphAttrs()\n");
310 /* We don't support FO_ATTR_MODE_ROTATE */
311 return NULL;
312}
313
314LONG
317 DHPDEV dhpdev,
318 FONTOBJ *pfo,
319 ULONG iMode,
320 HGLYPH hg,
322 PVOID pv,
324{
325 PBMFD_FILE pfile = (PBMFD_FILE)pfo->iFile;
326 PBMFD_FACE pface = &pfile->aface[pfo->iFace - 1];
327 PBMFD_FONT pfont= BmfdGetFontInstance(pfo, pface);
328
329 DbgPrint("BmfdQueryFontData(pfo=%p, iMode=%ld, hg=%p, pgd=%p, pv=%p, cjSize=%ld)\n",
330 pfo, iMode, hg, pgd, pv, cjSize);
331// __debugbreak();
332
333 switch (iMode)
334 {
335 case QFD_GLYPHANDBITMAP: /* 1 */
336 return BmfdQueryGlyphAndBitmap(pfont, hg, pgd, pv, cjSize);
337
338 case QFD_MAXEXTENTS: /* 3 */
339 return BmfdQueryMaxExtents(pfont, pv, cjSize);
340
341 /* we support nothing else */
342 default:
343 return FD_ERROR;
344
345 }
346
347 return FD_ERROR;
348}
#define _ReadPixel(bpp, pj, jShift)
Definition: DibLib_BitBlt.h:8
#define _WritePixel(pj, jShift, c)
Definition: DibLib_BitBlt.h:9
PBMFD_FONT BmfdGetFontInstance(FONTOBJ *pfo, PBMFD_FACE pface)
Definition: glyph.c:40
PFD_GLYPHATTR APIENTRY BmfdQueryGlyphAttrs(FONTOBJ *pfo, ULONG iMode)
Definition: glyph.c:305
ULONG BmfdQueryGlyphAndBitmap(PBMFD_FONT pfont, HGLYPH hg, GLYPHDATA *pgd, GLYPHBITS *pgb, ULONG cjSize)
Definition: glyph.c:75
ULONG BmfdQueryMaxExtents(PBMFD_FONT pfont, PFD_DEVICEMETRICS pfddm, ULONG cjSize)
Definition: glyph.c:227
LONG APIENTRY BmfdQueryFontData(DHPDEV dhpdev, FONTOBJ *pfo, ULONG iMode, HGLYPH hg, OUT GLYPHDATA *pgd, PVOID pv, ULONG cjSize)
Definition: glyph.c:316
#define GETVAL(x)
Definition: bmfd.h:21
#define FLOATL_1
Definition: bmfd.h:39
union GLYPHENTRY * PGLYPHENTRY
struct BMFD_FILE * PBMFD_FILE
#define FDM_MASK
Definition: bmfd.h:29
#define NULL
Definition: types.h:112
#define APIENTRY
Definition: api.h:79
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
GLuint color
Definition: glext.h:6243
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
#define DbgPrint
Definition: hal.h:12
if(dx< 0)
Definition: linetemp.h:194
BYTE * PBYTE
Definition: pedump.c:66
long LONG
Definition: pedump.c:60
void * EngAllocMem(int zero, unsigned long size, int tag=0)
Definition: polytest.cpp:70
#define memset(x, y, z)
Definition: compat.h:39
ULONG ulVersion
Definition: bmfd.h:212
WORD wPixHeight
Definition: bmfd.h:222
WORD wAscent
Definition: bmfd.h:228
PBYTE pCharTable
Definition: bmfd.h:210
WORD wDescent
Definition: bmfd.h:229
PFONTINFO16 pFontInfo
Definition: bmfd.h:209
WORD wA
Definition: bmfd.h:225
WORD wC
Definition: bmfd.h:227
ULONG_PTR iFile
Definition: bmfd.h:236
BMFD_FACE aface[1]
Definition: bmfd.h:240
FONTOBJ * pfo
Definition: bmfd.h:245
ULONG ulAngle
Definition: bmfd.h:249
LONG yScale
Definition: bmfd.h:248
LONG xScale
Definition: bmfd.h:247
PBMFD_FACE pface
Definition: bmfd.h:246
WORD dfPixHeight
Definition: bmfd.h:153
WORD dfMaxWidth
Definition: bmfd.h:156
WORD dfAscent
Definition: bmfd.h:144
WORD geWidth
Definition: bmfd.h:179
WORD geOffset
Definition: bmfd.h:180
DWORD geOffset
Definition: bmfd.h:186
WORD geWidth
Definition: bmfd.h:185
POINTL ptlULThickness
Definition: winddi.h:603
POINTL ptlSOThickness
Definition: winddi.h:604
FLONG flRealizedType
Definition: winddi.h:595
POINTE pteSide
Definition: winddi.h:597
ULONG cjGlyphMax
Definition: winddi.h:607
POINTL ptlUnderline1
Definition: winddi.h:601
FIX fxMaxDescender
Definition: winddi.h:600
POINTL ptlStrikeout
Definition: winddi.h:602
POINTE pteBase
Definition: winddi.h:596
POINTL ptlOrigin
Definition: winddi.h:960
BYTE aj[1]
Definition: winddi.h:962
SIZEL sizlBitmap
Definition: winddi.h:961
FLOATL y
Definition: winddi.h:197
FLOATL x
Definition: winddi.h:196
LONG y
Definition: windef.h:330
LONG x
Definition: windef.h:329
LONG cx
Definition: kdterminal.h:27
LONG cy
Definition: kdterminal.h:28
FLOATOBJ eM11
Definition: winddi.h:682
FLOATOBJ eM22
Definition: winddi.h:685
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
GLYPHENTRY30 ge30
Definition: bmfd.h:192
GLYPHENTRY20 ge20
Definition: bmfd.h:191
#define FORCEINLINE
Definition: wdftypes.h:67
#define FD_ERROR
Definition: winddi.h:153
_In_ FONTOBJ _In_ ULONG _In_ HGLYPH _In_opt_ GLYPHDATA * pgd
Definition: winddi.h:3872
typedef DHPDEV(APIENTRY FN_DrvEnablePDEV)(_In_ DEVMODEW *pdm
_In_ ULONG iMode
Definition: winddi.h:3520
#define FLOATOBJ_GetLong(pf)
Definition: winddi.h:2817
_In_opt_ FONTOBJ * pfo
Definition: winddi.h:3603
ENGAPI XFORMOBJ *APIENTRY FONTOBJ_pxoGetXform(_In_ FONTOBJ *pfo)
_In_ ULONG cjSize
Definition: winddi.h:3634
_In_ XLATEOBJ _In_ XFORMOBJ * pxo
Definition: winddi.h:3811
struct _FD_DEVICEMETRICS FD_DEVICEMETRICS
#define QFD_MAXEXTENTS
Definition: winddi.h:3857
_In_ FONTOBJ _In_ ULONG _In_ HGLYPH hg
Definition: winddi.h:3871
#define QFD_GLYPHANDBITMAP
Definition: winddi.h:3855
#define XFORMOBJ_iGetFloatObjXform
Definition: xformobj.h:10
char CHAR
Definition: xmlstorage.h:175