ReactOS  0.4.14-dev-552-g2fad488
glyph.c File Reference
#include "bmfd.h"
Include dependency graph for glyph.c:

Go to the source code of this file.

Functions

FORCEINLINE ULONG _ReadPixel (CHAR *pjBits, ULONG x, ULONG y, ULONG ulHeight)
 
FORCEINLINE VOID _WritePixel (CHAR *pjBits, ULONG x, ULONG y, ULONG cjRow, ULONG color)
 
PBMFD_FONT BmfdGetFontInstance (FONTOBJ *pfo, PBMFD_FACE pface)
 
ULONG BmfdQueryGlyphAndBitmap (PBMFD_FONT pfont, HGLYPH hg, GLYPHDATA *pgd, GLYPHBITS *pgb, ULONG cjSize)
 
ULONG BmfdQueryMaxExtents (PBMFD_FONT pfont, PFD_DEVICEMETRICS pfddm, ULONG cjSize)
 
PFD_GLYPHATTR APIENTRY BmfdQueryGlyphAttrs (FONTOBJ *pfo, ULONG iMode)
 
LONG APIENTRY BmfdQueryFontData (DHPDEV dhpdev, FONTOBJ *pfo, ULONG iMode, HGLYPH hg, OUT GLYPHDATA *pgd, PVOID pv, ULONG cjSize)
 

Function Documentation

◆ _ReadPixel()

FORCEINLINE ULONG _ReadPixel ( CHAR pjBits,
ULONG  x,
ULONG  y,
ULONG  ulHeight 
)

Definition at line 12 of file glyph.c.

17 {
18  CHAR j;
19  j = pjBits[(x/8) * ulHeight + y];
20  return (j >> (~x & 0x7)) & 1;
21 }
char CHAR
Definition: xmlstorage.h:175
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
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
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548

Referenced by BmfdQueryGlyphAndBitmap().

◆ _WritePixel()

FORCEINLINE VOID _WritePixel ( CHAR pjBits,
ULONG  x,
ULONG  y,
ULONG  cjRow,
ULONG  color 
)

Definition at line 26 of file glyph.c.

32 {
33  pjBits += y * cjRow;
34  pjBits += x / 8;
35  *pjBits |= color << (~x & 0x7);
36 }
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLuint color
Definition: glext.h:6243
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548

Referenced by BmfdQueryGlyphAndBitmap().

◆ BmfdGetFontInstance()

PBMFD_FONT BmfdGetFontInstance ( FONTOBJ pfo,
PBMFD_FACE  pface 
)

Definition at line 40 of file glyph.c.

43 {
44  PBMFD_FONT pfont = pfo->pvProducer;
45  XFORMOBJ *pxo;
46  FLOATOBJ_XFORM xfo;
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 }
FONTOBJ * pfo
Definition: bmfd.h:245
#define FLOATOBJ_GetLong(pf)
Definition: winddi.h:2817
PBMFD_FACE pface
Definition: bmfd.h:246
LONG xScale
Definition: bmfd.h:247
#define XFORMOBJ_iGetFloatObjXform
Definition: xformobj.h:10
smooth NULL
Definition: ftsmooth.c:416
_In_opt_ FONTOBJ * pfo
Definition: winddi.h:3603
FLOATOBJ eM11
Definition: winddi.h:682
void * EngAllocMem(int zero, unsigned long size, int tag=0)
Definition: polytest.cpp:70
ENGAPI XFORMOBJ *APIENTRY FONTOBJ_pxoGetXform(_In_ FONTOBJ *pfo)
FLOATOBJ eM22
Definition: winddi.h:685
LONG yScale
Definition: bmfd.h:248
_In_ XLATEOBJ _In_ XFORMOBJ * pxo
Definition: winddi.h:3810
ULONG ulAngle
Definition: bmfd.h:249

Referenced by BmfdQueryFontData().

◆ BmfdQueryFontData()

LONG APIENTRY BmfdQueryFontData ( DHPDEV  dhpdev,
FONTOBJ pfo,
ULONG  iMode,
HGLYPH  hg,
OUT GLYPHDATA pgd,
PVOID  pv,
ULONG  cjSize 
)

Definition at line 316 of file glyph.c.

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 }
BMFD_FACE aface[1]
Definition: bmfd.h:240
_In_ ULONG iMode
Definition: winddi.h:3520
#define DbgPrint
Definition: loader.c:25
ULONG_PTR iFile
Definition: bmfd.h:236
ULONG BmfdQueryMaxExtents(PBMFD_FONT pfont, PFD_DEVICEMETRICS pfddm, ULONG cjSize)
Definition: glyph.c:227
#define FD_ERROR
Definition: winddi.h:153
struct BMFD_FILE * PBMFD_FILE
#define QFD_MAXEXTENTS
Definition: winddi.h:3857
_In_opt_ FONTOBJ * pfo
Definition: winddi.h:3603
_In_ FONTOBJ _In_ ULONG _In_ HGLYPH hg
Definition: winddi.h:3869
ULONG BmfdQueryGlyphAndBitmap(PBMFD_FONT pfont, HGLYPH hg, GLYPHDATA *pgd, GLYPHBITS *pgb, ULONG cjSize)
Definition: glyph.c:75
_In_ FONTOBJ _In_ ULONG _In_ HGLYPH _In_opt_ GLYPHDATA * pgd
Definition: winddi.h:3869
PBMFD_FONT BmfdGetFontInstance(FONTOBJ *pfo, PBMFD_FACE pface)
Definition: glyph.c:40
_In_ ULONG cjSize
Definition: winddi.h:3634
#define QFD_GLYPHANDBITMAP
Definition: winddi.h:3855

◆ BmfdQueryGlyphAndBitmap()

ULONG BmfdQueryGlyphAndBitmap ( PBMFD_FONT  pfont,
HGLYPH  hg,
GLYPHDATA pgd,
GLYPHBITS pgb,
ULONG  cjSize 
)

Definition at line 75 of file glyph.c.

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 }
BYTE aj[1]
Definition: winddi.h:962
union GLYPHENTRY * PGLYPHENTRY
#define DbgPrint
Definition: loader.c:25
ULONG ulVersion
Definition: bmfd.h:212
DWORD geOffset
Definition: bmfd.h:186
GLYPHENTRY20 ge20
Definition: bmfd.h:191
#define FD_ERROR
Definition: winddi.h:153
FORCEINLINE ULONG _ReadPixel(CHAR *pjBits, ULONG x, ULONG y, ULONG ulHeight)
Definition: glyph.c:12
PBMFD_FACE pface
Definition: bmfd.h:246
WORD geWidth
Definition: bmfd.h:179
LONG y
Definition: windef.h:330
SIZEL sizlBitmap
Definition: winddi.h:961
long LONG
Definition: pedump.c:60
GLuint color
Definition: glext.h:6243
LONG xScale
Definition: bmfd.h:247
LONG cx
Definition: windef.h:334
PBYTE pCharTable
Definition: bmfd.h:210
_In_ FONTOBJ _In_ ULONG _In_ HGLYPH hg
Definition: winddi.h:3869
if(!(yy_init))
Definition: macro.lex.yy.c:714
GLYPHENTRY30 ge30
Definition: bmfd.h:192
LONG x
Definition: windef.h:329
PFONTINFO16 pFontInfo
Definition: bmfd.h:209
WORD wC
Definition: bmfd.h:227
WORD wAscent
Definition: bmfd.h:228
_In_ FONTOBJ _In_ ULONG _In_ HGLYPH _In_opt_ GLYPHDATA * pgd
Definition: winddi.h:3869
#define GETVAL(x)
Definition: bmfd.h:21
WORD wA
Definition: bmfd.h:225
WORD geOffset
Definition: bmfd.h:180
WORD geWidth
Definition: bmfd.h:185
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
LONG yScale
Definition: bmfd.h:248
FORCEINLINE VOID _WritePixel(CHAR *pjBits, ULONG x, ULONG y, ULONG cjRow, ULONG color)
Definition: glyph.c:26
WORD wDescent
Definition: bmfd.h:229
unsigned int ULONG
Definition: retypes.h:1
_In_ ULONG cjSize
Definition: winddi.h:3634
POINTL ptlOrigin
Definition: winddi.h:960
#define memset(x, y, z)
Definition: compat.h:39
LONG cy
Definition: windef.h:335
BYTE * PBYTE
Definition: pedump.c:66
WORD wPixHeight
Definition: bmfd.h:222
ULONG ulAngle
Definition: bmfd.h:249

Referenced by BmfdQueryFontData().

◆ BmfdQueryGlyphAttrs()

PFD_GLYPHATTR APIENTRY BmfdQueryGlyphAttrs ( FONTOBJ pfo,
ULONG  iMode 
)

Public Interface

Definition at line 305 of file glyph.c.

308 {
309  DbgPrint("BmfdQueryGlyphAttrs()\n");
310  /* We don't support FO_ATTR_MODE_ROTATE */
311  return NULL;
312 }
#define DbgPrint
Definition: loader.c:25
smooth NULL
Definition: ftsmooth.c:416

◆ BmfdQueryMaxExtents()

ULONG BmfdQueryMaxExtents ( PBMFD_FONT  pfont,
PFD_DEVICEMETRICS  pfddm,
ULONG  cjSize 
)

Definition at line 227 of file glyph.c.

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 }
POINTE pteSide
Definition: winddi.h:597
POINTL ptlSOThickness
Definition: winddi.h:604
FLOATL y
Definition: winddi.h:197
FLOATL x
Definition: winddi.h:196
POINTL ptlULThickness
Definition: winddi.h:603
#define FD_ERROR
Definition: winddi.h:153
PBMFD_FACE pface
Definition: bmfd.h:246
LONG y
Definition: windef.h:330
LONG xScale
Definition: bmfd.h:247
#define FDM_MASK
Definition: bmfd.h:29
WORD dfAscent
Definition: bmfd.h:144
POINTE pteBase
Definition: winddi.h:596
POINTL ptlUnderline1
Definition: winddi.h:601
#define FLOATL_1
Definition: bmfd.h:39
struct _FD_DEVICEMETRICS FD_DEVICEMETRICS
POINTL ptlStrikeout
Definition: winddi.h:602
ULONG cjGlyphMax
Definition: winddi.h:607
LONG x
Definition: windef.h:329
PFONTINFO16 pFontInfo
Definition: bmfd.h:209
WORD dfMaxWidth
Definition: bmfd.h:156
WORD dfPixHeight
Definition: bmfd.h:153
FIX fxMaxDescender
Definition: winddi.h:600
#define GETVAL(x)
Definition: bmfd.h:21
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
LONG yScale
Definition: bmfd.h:248
unsigned int ULONG
Definition: retypes.h:1
_In_ ULONG cjSize
Definition: winddi.h:3634
FLONG flRealizedType
Definition: winddi.h:595
ULONG ulAngle
Definition: bmfd.h:249

Referenced by BmfdQueryFontData().