From 2a09b8d220b132e1b28c76f5e76357a8d2f896e8 Mon Sep 17 00:00:00 2001 From: Timo Kreuzer Date: Thu, 12 Mar 2009 03:00:51 +0000 Subject: [PATCH] WIP 1/x: Move freetype font driver. svn path=/trunk/; revision=39966 --- reactos/drivers/video/font/ftfd/enable.c | 105 +++ reactos/drivers/video/font/ftfd/font.c | 427 +++++++++++ reactos/drivers/video/font/ftfd/freetype.def | 26 + reactos/drivers/video/font/ftfd/freetype.rc | 8 + reactos/drivers/video/font/ftfd/ftfd.h | 156 ++++ reactos/drivers/video/font/ftfd/ftfd.rbuild | 13 + reactos/drivers/video/font/ftfd/glyph.c | 34 + reactos/drivers/video/font/ftfd/rosglue.c | 137 ++++ reactos/drivers/video/font/ftfd/sprintf.c | 742 +++++++++++++++++++ 9 files changed, 1648 insertions(+) create mode 100644 reactos/drivers/video/font/ftfd/enable.c create mode 100644 reactos/drivers/video/font/ftfd/font.c create mode 100644 reactos/drivers/video/font/ftfd/freetype.def create mode 100644 reactos/drivers/video/font/ftfd/freetype.rc create mode 100644 reactos/drivers/video/font/ftfd/ftfd.h create mode 100644 reactos/drivers/video/font/ftfd/ftfd.rbuild create mode 100644 reactos/drivers/video/font/ftfd/glyph.c create mode 100644 reactos/drivers/video/font/ftfd/rosglue.c create mode 100644 reactos/drivers/video/font/ftfd/sprintf.c diff --git a/reactos/drivers/video/font/ftfd/enable.c b/reactos/drivers/video/font/ftfd/enable.c new file mode 100644 index 00000000000..a6d1aeab088 --- /dev/null +++ b/reactos/drivers/video/font/ftfd/enable.c @@ -0,0 +1,105 @@ +/* + * PROJECT: ReactOS win32 subsystem + * LICENSE: GPL - See COPYING in the top level directory + * PURPOSE: GDI font driver for bitmap fonts + * PROGRAMMER: Timo Kreuzer (timo.kreuzer@reactos.org) + */ + +#include "ftfd.h" + +static DRVFN gadrvfn[] = +{ + {INDEX_DrvEnablePDEV, (PFN)FtfdEnablePDEV}, + {INDEX_DrvCompletePDEV, (PFN)FtfdCompletePDEV}, + {INDEX_DrvDisablePDEV, (PFN)FtfdDisablePDEV}, + {INDEX_DrvLoadFontFile, (PFN)FtfdLoadFontFile}, + {INDEX_DrvUnloadFontFile, (PFN)FtfdUnloadFontFile}, + {INDEX_DrvQueryFontFile, (PFN)FtfdQueryFontFile}, + {INDEX_DrvQueryFontCaps, (PFN)FtfdQueryFontCaps}, + {INDEX_DrvQueryFontTree, (PFN)FtfdQueryFontTree}, + {INDEX_DrvQueryFont, (PFN)FtfdQueryFont}, + {INDEX_DrvFree, (PFN)FtfdFree}, + {INDEX_DrvQueryGlyphAttrs, (PFN)FtfdQueryGlyphAttrs}, + {INDEX_DrvQueryFontData, (PFN)FtfdQueryFontData}, +}; + +FT_Library gftlibrary; + + +BOOL +APIENTRY +FtfdEnableDriver( + ULONG iEngineVersion, + ULONG cj, + PDRVENABLEDATA pded) +{ + FT_Error fterror; + + DbgPrint("FtfdEnableDriver()\n"); + + /* Check parameter */ + if (cj < sizeof(DRVENABLEDATA)) + { + return FALSE; + } + + /* Initialize freetype library */ + fterror = FT_Init_FreeType(&gftlibrary); + if (fterror) + { + DbgPrint("an error occurred during library initialization: %ld.\n", fterror); + return FALSE; + } + + /* Fill DRVENABLEDATA */ + pded->c = sizeof(gadrvfn) / sizeof(DRVFN); + pded->pdrvfn = gadrvfn; + pded->iDriverVersion = DDI_DRIVER_VERSION_NT5; + + /* Success */ + return TRUE; +} + + +DHPDEV +APIENTRY +FtfdEnablePDEV( + IN DEVMODEW *pdm, + IN LPWSTR pwszLogAddress, + IN ULONG cPat, + OUT HSURF *phsurfPatterns, + IN ULONG cjCaps, + OUT ULONG *pdevcaps, + IN ULONG cjDevInfo, + OUT DEVINFO *pdi, + IN HDEV hdev, + IN LPWSTR pwszDeviceName, + IN HANDLE hDriver) +{ + DbgPrint("FtfdEnablePDEV(hdev=%p)\n", hdev); + + + /* Return a dummy DHPDEV */ + return (PVOID)1; +} + + +VOID +APIENTRY +FtfdCompletePDEV( + IN DHPDEV dhpdev, + IN HDEV hdev) +{ + DbgPrint("FtfdCompletePDEV()\n"); + /* Nothing to do */ +} + + +VOID +APIENTRY +FtfdDisablePDEV( + IN DHPDEV dhpdev) +{ + DbgPrint("FtfdDisablePDEV()\n"); + /* Nothing to do */ +} diff --git a/reactos/drivers/video/font/ftfd/font.c b/reactos/drivers/video/font/ftfd/font.c new file mode 100644 index 00000000000..5b48df8bd5a --- /dev/null +++ b/reactos/drivers/video/font/ftfd/font.c @@ -0,0 +1,427 @@ +/* + * PROJECT: ReactOS win32 subsystem + * LICENSE: GPL - See COPYING in the top level directory + * PURPOSE: GDI font driver for bitmap fonts + * PROGRAMMER: Timo Kreuzer (timo.kreuzer@reactos.org) + */ + +#include "ftfd.h" + +PVOID +HackFixup( + PVOID pvView, + ULONG cjView) +{ + CHAR *pc; + CHAR c; + + pc = EngAllocMem(0, cjView, 'tmp '); + memcpy(pc, pvView, cjView); + + c = *pc; + *pc = 0; + + return pc; +} + +/** Public Interface **********************************************************/ + +ULONG_PTR +APIENTRY +FtfdLoadFontFile( + ULONG cFiles, + ULONG_PTR *piFile, + PVOID *ppvView, + ULONG *pcjView, + DESIGNVECTOR *pdv, + ULONG ulLangID, + ULONG ulFastCheckSum) +{ + PVOID pvView; + ULONG cjView, i; + FT_Error fterror; + FT_Face ftface; + PFTFD_FILE pfile; + ULONG cjSize, cNumFaces; + + DbgPrint("FtfdLoadFontFile()\n"); + + /* Check parameters */ + if (cFiles != 1) + { + DbgPrint("Only 1 File is allowed, got %ld!\n", cFiles); + return HFF_INVALID; + } + + /* Map the font file */ + if (!EngMapFontFileFD(*piFile, (PULONG*)&pvView, &cjView)) + { + DbgPrint("Could not map font file!\n"); + return HFF_INVALID; + } + + // HACK!!! + pvView = HackFixup(pvView, cjView); + + fterror = FT_New_Memory_Face(gftlibrary, pvView, cjView, 0, &ftface); + if (fterror) + { + DbgPrint("No faces found in file\n"); + + /* Unmap the file */ + EngUnmapFontFileFD(*piFile); + + /* Failure! */ + return HFF_INVALID; + } + + /* Get number of faces from the first face */ + cNumFaces = ftface->num_faces; + + cjSize = sizeof(FTFD_FILE) + cNumFaces * sizeof(FT_Face); + pfile = EngAllocMem(0, cjSize, 'dftF'); + if (!pfile) + { + DbgPrint("EngAllocMem() failed.\n"); + + /* Unmap the file */ + EngUnmapFontFileFD(*piFile); + + /* Failure! */ + return HFF_INVALID; + } + + pfile->cNumFaces = cNumFaces; + pfile->iFile = *piFile; + pfile->pvView = pvView; + pfile->cjView = cjView; + + for (i = 0; i < pfile->cNumFaces; i++) + { + pfile->aftface[i] = ftface; + FT_Select_Charmap(ftface, FT_ENCODING_UNICODE); + } + + DbgPrint("Success! Returning %ld faces\n", cNumFaces); + + return (ULONG_PTR)pfile; +} + +BOOL +APIENTRY +FtfdUnloadFontFile( + IN ULONG_PTR iFile) +{ + PFTFD_FILE pfile = (PFTFD_FILE)iFile; + ULONG i; + + DbgPrint("FtfdUnloadFontFile()\n"); + + // HACK!!! + EngFreeMem(pfile->pvView); + + /* Cleanup faces */ + for (i = 0; i < pfile->cNumFaces; i++) + { + FT_Done_Face(pfile->aftface[i]); + } + + /* Free the memory that was allocated for the font */ + EngFreeMem(pfile); + + /* Unmap the font file */ + EngUnmapFontFileFD(pfile->iFile); + + return TRUE; +} + + +LONG +APIENTRY +FtfdQueryFontFile( + ULONG_PTR iFile, + ULONG ulMode, + ULONG cjBuf, + ULONG *pulBuf) +{ + PFTFD_FILE pfile = (PFTFD_FILE)iFile; + + DbgPrint("FtfdQueryFontFile(ulMode=%ld)\n", ulMode); +// DbgBreakPoint(); + + switch (ulMode) + { + case QFF_DESCRIPTION: + { + return 0; + } + + case QFF_NUMFACES: + /* return the number of faces in the file */ + return pfile->cNumFaces; + + } + + return FD_ERROR; +} + + +PIFIMETRICS +APIENTRY +FtfdQueryFont( + IN DHPDEV dhpdev, + IN ULONG_PTR iFile, + IN ULONG iFace, + IN ULONG_PTR *pid) +{ + PFTFD_FILE pfile = (PFTFD_FILE)iFile; + PFTFD_IFIMETRICS pifiX; + PIFIMETRICS pifi; + FT_Face ftface; + FT_Error fterror; + + DbgPrint("FtfdQueryFont()\n"); + + /* Validate parameters */ + if (iFace > pfile->cNumFaces || !pid) + { + return NULL; + } + + fterror = FT_New_Memory_Face(gftlibrary, + pfile->pvView, + pfile->cjView, + iFace - 1, + &ftface); + if (fterror) + { + return NULL; + } + + /* Allocate the ifi metrics structure */ + pifiX = EngAllocMem(FL_ZERO_MEMORY, sizeof(FTFD_IFIMETRICS), TAG_IFIMETRICS); + if (!pifiX) + { + DbgPrint("EngAllocMem() failed.\n"); + FT_Done_Face(ftface); + return NULL; + } + + /* Fill IFIMETRICS */ + pifi = &pifiX->ifim; + pifi->cjThis = sizeof(FTFD_IFIMETRICS); + pifi->cjIfiExtra = 0; + pifi->dpwszFamilyName = FIELD_OFFSET(FTFD_IFIMETRICS, wszFamilyName); + pifi->dpwszStyleName = FIELD_OFFSET(FTFD_IFIMETRICS, wszFamilyName); + pifi->dpwszFaceName = FIELD_OFFSET(FTFD_IFIMETRICS, wszFaceName); + pifi->dpwszUniqueName = FIELD_OFFSET(FTFD_IFIMETRICS, wszFaceName); + pifi->dpFontSim = 0; + pifi->lEmbedId = 0; + pifi->lItalicAngle = 0; + pifi->lCharBias = 0; + pifi->dpCharSets = 0; +// pifi->jWinCharSet = pFontInfo->dfCharSet; +// pifi->jWinPitchAndFamily = pFontInfo->dfPitchAndFamily; +// pifi->usWinWeight = GETVAL(pFontInfo->dfWeight); +// pifi->flInfo = pface->flInfo; + pifi->fsSelection = 0; + pifi->fsType = 0; +// pifi->fwdUnitsPerEm = GETVAL(pFontInfo->dfPixHeight); + pifi->fwdLowestPPEm = 0; +// pifi->fwdWinAscender = GETVAL(pFontInfo->dfAscent); + pifi->fwdWinDescender = pifi->fwdUnitsPerEm - pifi->fwdWinAscender; + pifi->fwdMacAscender = pifi->fwdWinAscender; + pifi->fwdMacDescender = - pifi->fwdWinDescender; + pifi->fwdMacLineGap = 0; + pifi->fwdTypoAscender = pifi->fwdWinAscender; + pifi->fwdTypoDescender = - pifi->fwdWinDescender; + pifi->fwdTypoLineGap = 0; +// pifi->fwdAveCharWidth = GETVAL(pFontInfo->dfAvgWidth); +// pifi->fwdMaxCharInc = GETVAL(pFontInfo->dfMaxWidth); +// pifi->fwdCapHeight = pifi->fwdUnitsPerEm / 2; + pifi->fwdXHeight = pifi->fwdUnitsPerEm / 4; + pifi->fwdSubscriptXSize = 0; + pifi->fwdSubscriptYSize = 0; + pifi->fwdSubscriptXOffset = 0; + pifi->fwdSubscriptYOffset = 0; + pifi->fwdSuperscriptXSize = 0; + pifi->fwdSuperscriptYSize = 0; + pifi->fwdSuperscriptXOffset = 0; + pifi->fwdSuperscriptYOffset = 0; + pifi->fwdUnderscoreSize = 01; + pifi->fwdUnderscorePosition = -1; + pifi->fwdStrikeoutSize = 1; + pifi->fwdStrikeoutPosition = pifi->fwdXHeight + 1; +// pifi->chFirstChar = pFontInfo->dfFirstChar; +// pifi->chLastChar = pFontInfo->dfLastChar; +// pifi->chDefaultChar = pFontInfo->dfFirstChar + pFontInfo->dfDefaultChar; +// pifi->chBreakChar = pFontInfo->dfFirstChar + pFontInfo->dfBreakChar; +// pifi->wcFirstChar = pface->wcFirstChar; +// pifi->wcLastChar = pface->wcLastChar; +// pifi->wcDefaultChar = pface->wcDefaultChar; +// pifi->wcBreakChar = pface->wcBreakChar; + pifi->ptlBaseline.x = 1; + pifi->ptlBaseline.y = 0; +// pifi->ptlAspect.x = pFontInfo->dfVertRes; // CHECKME +// pifi->ptlAspect.y = pFontInfo->dfHorizRes; + pifi->ptlCaret.x = 0; + pifi->ptlCaret.y = 1; + pifi->rclFontBox.left = 0; + pifi->rclFontBox.right = pifi->fwdAveCharWidth; + pifi->rclFontBox.top = pifi->fwdWinAscender; + pifi->rclFontBox.bottom = - pifi->fwdWinDescender; + *(DWORD*)&pifi->achVendId = 0x30303030; // FIXME + pifi->cKerningPairs = 0; + pifi->ulPanoseCulture = FM_PANOSE_CULTURE_LATIN; +// pifi->panose = panose; + + /* Set char sets */ + pifiX->ajCharSet[0] = pifi->jWinCharSet; + pifiX->ajCharSet[1] = DEFAULT_CHARSET; + + FT_Done_Face(ftface); + + + return 0; +} + + +LONG +APIENTRY +FtfdQueryFontCaps( + ULONG culCaps, + ULONG *pulCaps) +{ + DbgPrint("FtfdQueryFontCaps()\n"); + + /* We need room for 2 ULONGs */ + if (culCaps < 2) + { + return FD_ERROR; + } + + /* We only support 1 bpp */ + pulCaps[0] = 2; + pulCaps[1] = QC_1BIT; + + return 2; +} + + +PVOID +APIENTRY +FtfdQueryFontTree( + DHPDEV dhpdev, + ULONG_PTR iFile, + ULONG iFace, + ULONG iMode, + ULONG_PTR *pid) +{ + PFTFD_FILE pfile = (PFTFD_FILE)iFile; + FT_Face ftface; + FT_Error fterror; + FTFD_CHARPAIR *pcp; + FD_GLYPHSET *pGlyphSet; + FT_ULong charcode; + ULONG i, j, cGlyphs, cRuns, cjSize; + WCRUN *pwcrun; + HGLYPH * phglyphs; + + DbgPrint("FtfdQueryFontTree()\n"); + + fterror = FT_New_Memory_Face(gftlibrary, + pfile->pvView, + pfile->cjView, + iFace - 1, + &ftface); + if (fterror) + { + return NULL; + } + + cGlyphs = ftface->num_glyphs; + cRuns = 1; + + pcp = EngAllocMem(0, cGlyphs * sizeof(FTFD_CHARPAIR), 'pcp '); + if (!pcp) + { + return NULL; + } + + charcode = FT_Get_First_Char(ftface, &pcp[0].index); + for (i = 0; i < cGlyphs && charcode != 0; i++) + { + pcp[i].charcode = charcode; + charcode = FT_Get_Next_Char(ftface, charcode, &pcp[i].index); + if (charcode != pcp[i - 1].charcode + 1) + { + cRuns++; + } + } + + /* Calculate FD_GLYPHSET size */ + cjSize = sizeof(FD_GLYPHSET) + + (cRuns - 1) * sizeof(WCRUN) + + cGlyphs * sizeof(HGLYPH); + + /* Allocate the FD_GLYPHSET structure */ + pGlyphSet = EngAllocMem(0, cjSize, TAG_GLYPHSET); + if (!pGlyphSet) + { + return NULL; + } + + /* Initialize FD_GLYPHSET */ + pGlyphSet->cjThis = cjSize; + pGlyphSet->flAccel = 0; + pGlyphSet->cGlyphsSupported = cGlyphs; + pGlyphSet->cRuns = cRuns; + + /* Initialize 1st WCRUN */ + pwcrun = pGlyphSet->awcrun; + phglyphs = (PHGLYPH)&pGlyphSet->awcrun[cRuns]; + pwcrun[0].wcLow = pcp[0].charcode; + pwcrun[0].cGlyphs = 1; + pwcrun[0].phg = phglyphs; + phglyphs[0] = pcp[0].index; + + /* Walk through all supported chars */ + for (i = 1, j = 0; i < cGlyphs; i++) + { + /* Use glyph index as HGLYPH */ + phglyphs[i] = pcp[i].index; + + /* Check whether we can append the wchar to a run */ + if (pcp[i].charcode == pcp[i - 1].charcode + 1) + { + /* Append to current WCRUN */ + pwcrun[j].cGlyphs++; + } + else + { + /* Add a new WCRUN */ + j++; + pwcrun[j].wcLow = pcp[i].charcode; + pwcrun[j].cGlyphs = 1; + pwcrun[j].phg = &phglyphs[i]; + } + } + + return NULL; +} + +VOID +APIENTRY +FtfdFree( + PVOID pv, + ULONG_PTR id) +{ + DbgPrint("FtfdFree()\n"); + if (id) + { + EngFreeMem((PVOID)id); + } +} + + + diff --git a/reactos/drivers/video/font/ftfd/freetype.def b/reactos/drivers/video/font/ftfd/freetype.def new file mode 100644 index 00000000000..1d278a8345a --- /dev/null +++ b/reactos/drivers/video/font/ftfd/freetype.def @@ -0,0 +1,26 @@ +LIBRARY freetype +EXPORTS + FT_Done_Face + FT_Done_Glyph + FT_Get_Char_Index + FT_Get_First_Char + FT_Get_Glyph + FT_Get_Kerning + FT_Get_Next_Char + FT_Get_PS_Font_Info + FT_Get_Sfnt_Table + FT_Get_WinFNT_Header + FT_Glyph_To_Bitmap + FT_Init_FreeType + FT_Load_Glyph + FT_Load_Sfnt_Table + FT_Matrix_Multiply + FT_MulFix + FT_New_Memory_Face + FT_Outline_Get_Bitmap + FT_Outline_Transform + FT_Outline_Translate + FT_Set_Charmap + FT_Set_Pixel_Sizes + FT_Vector_Transform + FT_Vector_Unit diff --git a/reactos/drivers/video/font/ftfd/freetype.rc b/reactos/drivers/video/font/ftfd/freetype.rc new file mode 100644 index 00000000000..00ec67fd60d --- /dev/null +++ b/reactos/drivers/video/font/ftfd/freetype.rc @@ -0,0 +1,8 @@ +#define REACTOS_VERSION_DLL +#define REACTOS_STR_FILE_DESCRIPTION "FreeType font handling library\0" +#define REACTOS_STR_INTERNAL_NAME "freetype\0" +#define REACTOS_STR_ORIGINAL_FILENAME "freetype.dll\0" +#define REACTOS_STR_COMPANY_NAME "ReactOS Development Team/FreeType Team\0" +#define REACTOS_STR_LEGAL_COPYRIGHT "Copyright 1998-2007 ReactOS Team\0" +#define REACTOS_STR_ORIGINAL_COPYRIGHT "Copyright 1996-2007 FreeType Team\0" +#include diff --git a/reactos/drivers/video/font/ftfd/ftfd.h b/reactos/drivers/video/font/ftfd/ftfd.h new file mode 100644 index 00000000000..09a8d563bee --- /dev/null +++ b/reactos/drivers/video/font/ftfd/ftfd.h @@ -0,0 +1,156 @@ +/* + * PROJECT: ReactOS win32 subsystem + * LICENSE: GPL - See COPYING in the top level directory + * PURPOSE: GDI font driver for bitmap fonts + * PROGRAMMER: Timo Kreuzer (timo.kreuzer@reactos.org) + */ + +#include +#include +#include +#include + +#include +#include FT_FREETYPE_H + +extern FT_Library gftlibrary; + +#define TAG_GLYPHSET 'GlSt' +#define TAG_IFIMETRICS 'Ifim' + +/** Driver specific types *****************************************************/ + +typedef struct +{ + FT_UInt index; + FT_ULong charcode; +} FTFD_CHARPAIR; + +typedef struct +{ + PVOID pvView; + ULONG cjView; + ULONG_PTR iFile; + ULONG cNumFaces; + FT_Face aftface[1]; +} FTFD_FILE, *PFTFD_FILE; + +//"Bold Italic Underline Strikeout" +#define MAX_STYLESIZE 35 +typedef struct +{ + IFIMETRICS ifim; + BYTE ajCharSet[16]; + WCHAR wszFamilyName[LF_FACESIZE]; + WCHAR wszFaceName[LF_FACESIZE]; + WCHAR wszStyleName[MAX_STYLESIZE]; +} FTFD_IFIMETRICS, *PFTFD_IFIMETRICS; + +/** Function prototypes *******************************************************/ + +ULONG +DbgPrint(IN PCHAR Format, IN ...); + +static __inline__ +void +DbgBreakPoint(void) +{ + asm volatile ("int $3"); +} + +DHPDEV +APIENTRY +FtfdEnablePDEV( + IN DEVMODEW *pdm, + IN LPWSTR pwszLogAddress, + IN ULONG cPat, + OUT HSURF *phsurfPatterns, + IN ULONG cjCaps, + OUT ULONG *pdevcaps, + IN ULONG cjDevInfo, + OUT DEVINFO *pdi, + IN HDEV hdev, + IN LPWSTR pwszDeviceName, + IN HANDLE hDriver); + +VOID +APIENTRY +FtfdCompletePDEV( + IN DHPDEV dhpdev, + IN HDEV hdev); + +VOID +APIENTRY +FtfdDisablePDEV( + IN DHPDEV dhpdev); + +ULONG_PTR +APIENTRY +FtfdLoadFontFile( + ULONG cFiles, + ULONG_PTR *piFile, + PVOID *ppvView, + ULONG *pcjView, + DESIGNVECTOR *pdv, + ULONG ulLangID, + ULONG ulFastCheckSum); + +BOOL +APIENTRY +FtfdUnloadFontFile( + IN ULONG_PTR iFile); + +LONG +APIENTRY +FtfdQueryFontFile( + ULONG_PTR iFile, + ULONG ulMode, + ULONG cjBuf, + ULONG *pulBuf); + +LONG +APIENTRY +FtfdQueryFontCaps( + ULONG culCaps, + ULONG *pulCaps); + +PVOID +APIENTRY +FtfdQueryFontTree( + DHPDEV dhpdev, + ULONG_PTR iFile, + ULONG iFace, + ULONG iMode, + ULONG_PTR *pid); + +PIFIMETRICS +APIENTRY +FtfdQueryFont( + IN DHPDEV dhpdev, + IN ULONG_PTR iFile, + IN ULONG iFace, + IN ULONG_PTR *pid); + +VOID +APIENTRY +FtfdFree( + PVOID pv, + ULONG_PTR id); + +PFD_GLYPHATTR +APIENTRY +FtfdQueryGlyphAttrs( + FONTOBJ *pfo, + ULONG iMode); + +LONG +APIENTRY +FtfdQueryFontData( + DHPDEV dhpdev, + FONTOBJ *pfo, + ULONG iMode, + HGLYPH hg, + OUT GLYPHDATA *pgd, + PVOID pv, + ULONG cjSize); + diff --git a/reactos/drivers/video/font/ftfd/ftfd.rbuild b/reactos/drivers/video/font/ftfd/ftfd.rbuild new file mode 100644 index 00000000000..a87a14d62d5 --- /dev/null +++ b/reactos/drivers/video/font/ftfd/ftfd.rbuild @@ -0,0 +1,13 @@ + + + + + include + win32k + freetype2 + enable.c + font.c + glyph.c + rosglue.c + sprintf.c + diff --git a/reactos/drivers/video/font/ftfd/glyph.c b/reactos/drivers/video/font/ftfd/glyph.c new file mode 100644 index 00000000000..a242fbe6acd --- /dev/null +++ b/reactos/drivers/video/font/ftfd/glyph.c @@ -0,0 +1,34 @@ +/* + * PROJECT: ReactOS win32 subsystem + * LICENSE: GPL - See COPYING in the top level directory + * PURPOSE: GDI font driver for bitmap fonts + * PROGRAMMER: Timo Kreuzer (timo.kreuzer@reactos.org) + */ + +#include "ftfd.h" + + +/** Public Interface **********************************************************/ + +PFD_GLYPHATTR +APIENTRY +FtfdQueryGlyphAttrs( + FONTOBJ *pfo, + ULONG iMode) +{ + return NULL; +} + +LONG +APIENTRY +FtfdQueryFontData( + DHPDEV dhpdev, + FONTOBJ *pfo, + ULONG iMode, + HGLYPH hg, + OUT GLYPHDATA *pgd, + PVOID pv, + ULONG cjSize) +{ + return FD_ERROR; +} diff --git a/reactos/drivers/video/font/ftfd/rosglue.c b/reactos/drivers/video/font/ftfd/rosglue.c new file mode 100644 index 00000000000..203ede43095 --- /dev/null +++ b/reactos/drivers/video/font/ftfd/rosglue.c @@ -0,0 +1,137 @@ +/* $Id: rosglue.c 39928 2009-03-10 02:49:45Z tkreuzer $ + * + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: FreeType implementation for ReactOS + * PURPOSE: Glue functions between FreeType + * FILE: thirdparty/freetype/rosglue.c + * PROGRAMMER: Ge van Geldorp (ge@gse.nl) + * NOTES: + */ + +#include +#include +#include +#include +#include + +#define NDEBUG +#include + +#define TAG(A, B, C, D) (ULONG)(((A)<<0) + ((B)<<8) + ((C)<<16) + ((D)<<24)) +#define TAG_FREETYPE TAG('F', 'T', 'Y', 'P') + +/* + * First some generic routines + */ + +ULONG +DbgPrint(IN PCCH Format, IN ...) +{ + va_list args; + + va_start(args, Format); + EngDebugPrint("ft2: ", (PCHAR)Format, args); + va_end(args); + return 0; +} + +/* + * Memory allocation + * + * Because of realloc, we need to keep track of the size of the allocated + * buffer (need to copy the old contents to the new buffer). So, allocate + * extra space for a size_t, store the allocated size in there and return + * the address just past it as the allocated buffer. + */ + +void * +malloc(size_t Size) +{ + void *Object; + + Object = EngAllocMem(0, sizeof(size_t) + Size, TAG_FREETYPE); + if (NULL != Object) + { + *((size_t *) Object) = Size; + Object = (void *)((size_t *) Object + 1); + } + + return Object; +} + +void * +realloc(void *Object, size_t Size) +{ + void *NewObject; + size_t CopySize; + + NewObject = EngAllocMem(0, sizeof(size_t) + Size, TAG_FREETYPE); + if (NULL != NewObject) + { + *((size_t *) NewObject) = Size; + NewObject = (void *)((size_t *) NewObject + 1); + CopySize = *((size_t *) Object - 1); + if (Size < CopySize) + { + CopySize = Size; + } + memcpy(NewObject, Object, CopySize); + EngFreeMem((size_t *) Object - 1); + } + + return NewObject; +} + +void +free(void *Object) +{ + EngFreeMem((size_t *) Object - 1); +} + +/* + * File I/O + * + * This is easy, we don't want FreeType to do any I/O. So return an + * error on each I/O attempt. Note that errno is not being set, it is + * not used by FreeType. + */ + +FILE * +fopen(const char *FileName, const char *Mode) +{ + DPRINT1("Freetype tries to open file %s\n", FileName); + + return NULL; +} + +int +fseek(FILE *Stream, long Offset, int Origin) +{ + DPRINT1("Doubleplus ungood: freetype shouldn't fseek!\n"); + + return -1; +} + +long +ftell(FILE *Stream) +{ + DPRINT1("Doubleplus ungood: freetype shouldn't ftell!\n"); + + return -1; +} + +size_t +fread(void *Buffer, size_t Size, size_t Count, FILE *Stream) +{ + DPRINT1("Doubleplus ungood: freetype shouldn't fread!\n"); + + return 0; +} + +int +fclose(FILE *Stream) +{ + DPRINT1("Doubleplus ungood: freetype shouldn't fclose!\n"); + + return EOF; +} diff --git a/reactos/drivers/video/font/ftfd/sprintf.c b/reactos/drivers/video/font/ftfd/sprintf.c new file mode 100644 index 00000000000..60bac91e684 --- /dev/null +++ b/reactos/drivers/video/font/ftfd/sprintf.c @@ -0,0 +1,742 @@ +/* + * PROGRAMMERS: David Welch + * Eric Kohl + * + * TODO: + * - Verify the implementation of '%Z'. + */ + +/* + * linux/lib/vsprintf.c + * + * Copyright (C) 1991, 1992 Linus Torvalds + */ + +/* vsprintf.c -- Lars Wirzenius & Linus Torvalds. */ +/* + * Wirzenius wrote this portably, Torvalds fucked it up :-) + */ + +#define WIN32_NO_STATUS +#include +#include +#include +#include + +#define ZEROPAD 1 /* pad with zero */ +#define SIGN 2 /* unsigned/signed long */ +#define PLUS 4 /* show plus */ +#define SPACE 8 /* space if plus */ +#define LEFT 16 /* left justified */ +#define SPECIAL 32 /* 0x */ +#define LARGE 64 /* use 'ABCDEF' instead of 'abcdef' */ +#define REMOVEHEX 256 /* use 256 as remve 0x frim BASE 16 */ +typedef struct { + unsigned int mantissal:32; + unsigned int mantissah:20; + unsigned int exponent:11; + unsigned int sign:1; +} double_t; + +static +__inline +int +_isinf(double __x) +{ + union + { + double* __x; + double_t* x; + } x; + + x.__x = &__x; + return ( x.x->exponent == 0x7ff && ( x.x->mantissah == 0 && x.x->mantissal == 0 )); +} + +static +__inline +int +_isnan(double __x) +{ + union + { + double* __x; + double_t* x; + } x; + x.__x = &__x; + return ( x.x->exponent == 0x7ff && ( x.x->mantissah != 0 || x.x->mantissal != 0 )); +} + + +static +__inline +int +do_div(long long *n, int base) +{ + int a; + a = ((unsigned long long) *n) % (unsigned) base; + *n = ((unsigned long long) *n) / (unsigned) base; + return a; +} + + +static int skip_atoi(const char **s) +{ + int i=0; + + while (isdigit(**s)) + i = i*10 + *((*s)++) - '0'; + return i; +} + + +static char * +number(char * buf, char * end, long long num, int base, int size, int precision, int type) +{ + char c,sign,tmp[66]; + const char *digits; + const char *small_digits = "0123456789abcdefghijklmnopqrstuvwxyz"; + const char *large_digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + int i; + + digits = (type & LARGE) ? large_digits : small_digits; + if (type & LEFT) + type &= ~ZEROPAD; + if (base < 2 || base > 36) + return 0; + c = (type & ZEROPAD) ? '0' : ' '; + sign = 0; + if (type & SIGN) { + if (num < 0) { + sign = '-'; + num = -num; + size--; + } else if (type & PLUS) { + sign = '+'; + size--; + } else if (type & SPACE) { + sign = ' '; + size--; + } + } + + if ((type & SPECIAL) && ((type & REMOVEHEX) == 0)) { + if (base == 16) + size -= 2; + + } + i = 0; + if ((num == 0) && (precision !=0)) + tmp[i++] = '0'; + else while (num != 0) + tmp[i++] = digits[do_div(&num,base)]; + if (i > precision) + precision = i; + size -= precision; + if (!(type&(ZEROPAD+LEFT))) { + while(size-->0) { + if (buf <= end) + *buf = ' '; + ++buf; + } + } + if (sign) { + if (buf <= end) + *buf = sign; + ++buf; + } + + if ((type & SPECIAL) && ((type & REMOVEHEX) == 0)) { + if (base==16) { + if (buf <= end) + *buf = '0'; + ++buf; + if (buf <= end) + *buf = digits[33]; + ++buf; + } + } + + if (!(type & LEFT)) { + while (size-- > 0) { + if (buf <= end) + *buf = c; + ++buf; + } + } + while (i < precision--) { + if (buf <= end) + *buf = '0'; + ++buf; + } + while (i-- > 0) { + if (buf <= end) + *buf = tmp[i]; + ++buf; + } + while (size-- > 0) { + if (buf <= end) + *buf = ' '; + ++buf; + } + + return buf; +} + +static char * +numberf(char * buf, char * end, double num, int base, int size, int precision, int type) +{ + char c,sign,tmp[66]; + const char *digits; + const char *small_digits = "0123456789abcdefghijklmnopqrstuvwxyz"; + const char *large_digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + int i; + long long x; + + /* FIXME + the float version of number is direcly copy of number + */ + + digits = (type & LARGE) ? large_digits : small_digits; + if (type & LEFT) + type &= ~ZEROPAD; + if (base < 2 || base > 36) + return 0; + c = (type & ZEROPAD) ? '0' : ' '; + sign = 0; + if (type & SIGN) { + if (num < 0) { + sign = '-'; + num = -num; + size--; + } else if (type & PLUS) { + sign = '+'; + size--; + } else if (type & SPACE) { + sign = ' '; + size--; + } + } + if (type & SPECIAL) { + if (base == 16) + size -= 2; + else if (base == 8) + size--; + } + i = 0; + if (num == 0) + tmp[i++] = '0'; + else while (num != 0) + { + x = num; + tmp[i++] = digits[do_div(&x,base)]; + num=x; + } + if (i > precision) + precision = i; + size -= precision; + if (!(type&(ZEROPAD+LEFT))) { + while(size-->0) { + if (buf <= end) + *buf = ' '; + ++buf; + } + } + if (sign) { + if (buf <= end) + *buf = sign; + ++buf; + } + if (type & SPECIAL) { + if (base==8) { + if (buf <= end) + *buf = '0'; + ++buf; + } else if (base==16) { + if (buf <= end) + *buf = '0'; + ++buf; + if (buf <= end) + *buf = digits[33]; + ++buf; + } + } + if (!(type & LEFT)) { + while (size-- > 0) { + if (buf <= end) + *buf = c; + ++buf; + } + } + while (i < precision--) { + if (buf <= end) + *buf = '0'; + ++buf; + } + while (i-- > 0) { + if (buf <= end) + *buf = tmp[i]; + ++buf; + } + while (size-- > 0) { + if (buf <= end) + *buf = ' '; + ++buf; + } + return buf; +} + +static char* +string(char* buf, char* end, const char* s, int len, int field_width, int precision, int flags) +{ + int i; + char c; + + c = (flags & ZEROPAD) ? '0' : ' '; + + if (s == NULL) + { + s = ""; + len = 6; + } + else + { + if (len == -1) + { + len = 0; + while ((unsigned int)len < (unsigned int)precision && s[len]) + len++; + } + else + { + if ((unsigned int)len > (unsigned int)precision) + len = precision; + } + } + if (!(flags & LEFT)) + while (len < field_width--) + { + if (buf <= end) + *buf = c; + ++buf; + } + for (i = 0; i < len; ++i) + { + if (buf <= end) + *buf = *s++; + ++buf; + } + while (len < field_width--) + { + if (buf <= end) + *buf = ' '; + ++buf; + } + return buf; +} + +static char* +stringw(char* buf, char* end, const wchar_t* sw, int len, int field_width, int precision, int flags) +{ + int i; + char c; + + c = (flags & ZEROPAD) ? '0' : ' '; + + if (sw == NULL) + { + sw = L""; + len = 6; + } + else + { + if (len == -1) + { + len = 0; + while ((unsigned int)len < (unsigned int)precision && sw[len]) + len++; + } + else + { + if ((unsigned int)len > (unsigned int)precision) + len = precision; + } + } + if (!(flags & LEFT)) + while (len < field_width--) + { + if (buf <= end) + *buf = c; + buf++; + } + for (i = 0; i < len; ++i) + { + if (buf <= end) + *buf = (unsigned char)(*sw++); + buf++; + } + while (len < field_width--) + { + if (buf <= end) + *buf = ' '; + buf++; + } + return buf; +} + +/* + * @implemented + */ +int __cdecl _vsnprintf(char *buf, size_t cnt, const char *fmt, va_list args) +{ + int len; + unsigned long long num; + double _double; + + int base; + char *str, *end; + const char *s; + const wchar_t *sw; + + int flags; /* flags to number() */ + + int field_width; /* width of output field */ + int precision; /* min. # of digits for integers; max + number of chars for from string */ + int qualifier; /* 'h', 'l', 'L', 'I' or 'w' for integer fields */ + + /* clear the string buffer with zero so we do not need NULL terment it at end */ + + str = buf; + end = buf + cnt - 1; + if (end < buf - 1) { + end = ((char *) -1); + cnt = end - buf + 1; + } + + for ( ; *fmt ; ++fmt) { + if (*fmt != '%') { + if (str <= end) + *str = *fmt; + ++str; + continue; + } + + /* process flags */ + flags = 0; + repeat: + ++fmt; /* this also skips first '%' */ + switch (*fmt) { + case '-': flags |= LEFT; goto repeat; + case '+': flags |= PLUS; goto repeat; + case ' ': flags |= SPACE; goto repeat; + case '#': flags |= SPECIAL; goto repeat; + case '0': flags |= ZEROPAD; goto repeat; + } + + /* get field width */ + field_width = -1; + if (isdigit(*fmt)) + field_width = skip_atoi(&fmt); + else if (*fmt == '*') { + ++fmt; + /* it's the next argument */ + field_width = va_arg(args, int); + if (field_width < 0) { + field_width = -field_width; + flags |= LEFT; + } + } + + /* get the precision */ + precision = -1; + if (*fmt == '.') { + ++fmt; + if (isdigit(*fmt)) + precision = skip_atoi(&fmt); + else if (*fmt == '*') { + ++fmt; + /* it's the next argument */ + precision = va_arg(args, int); + } + if (precision < 0) + precision = 0; + } + + /* get the conversion qualifier */ + qualifier = -1; + if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L' || *fmt == 'w') { + qualifier = *fmt; + ++fmt; + } else if (*fmt == 'I' && *(fmt+1) == '6' && *(fmt+2) == '4') { + qualifier = *fmt; + fmt += 3; + } else if (*fmt == 'I' && *(fmt+1) == '3' && *(fmt+2) == '2') { + qualifier = 'l'; + fmt += 3; + } else if (*fmt == 'F' && *(fmt+1) == 'p') { + fmt += 1; + flags |= REMOVEHEX; + } + + /* default base */ + base = 10; + + switch (*fmt) { + case 'c': /* finished */ + if (qualifier == 'l' || qualifier == 'w') { + wchar_t sw1[2]; + /* print unicode string */ + sw1[0] = (wchar_t) va_arg(args, int); + sw1[1] = 0; + str = stringw(str, end, (wchar_t *)&sw1, -1, field_width, precision, flags); + } else { + char s1[2]; + /* print ascii string */ + s1[0] = ( unsigned char) va_arg(args, int); + s1[1] = 0; + str = string(str, end, (char *)&s1, -1, field_width, precision, flags); + } + continue; + + case 'C': /* finished */ + if (!(flags & LEFT)) + while (--field_width > 0) { + if (str <= end) + *str = ' '; + ++str; + } + if (qualifier == 'h') { + if (str <= end) + *str = (unsigned char) va_arg(args, int); + ++str; + } else { + if (str <= end) + *str = (unsigned char)(wchar_t) va_arg(args, int); + ++str; + } + while (--field_width > 0) { + if (str <= end) + *str = ' '; + ++str; + } + continue; + + case 's': /* finished */ + if (qualifier == 'l' || qualifier == 'w') { + /* print unicode string */ + sw = va_arg(args, wchar_t *); + str = stringw(str, end, sw, -1, field_width, precision, flags); + } else { + /* print ascii string */ + s = va_arg(args, char *); + str = string(str, end, s, -1, field_width, precision, flags); + } + continue; + + case 'S': + if (qualifier == 'h') { + /* print ascii string */ + s = va_arg(args, char *); + str = string(str, end, s, -1, field_width, precision, flags); + } else { + /* print unicode string */ + sw = va_arg(args, wchar_t *); + str = stringw(str, end, sw, -1, field_width, precision, flags); + } + continue; + + case 'Z': + if (qualifier == 'w') { + /* print counted unicode string */ + PUNICODE_STRING pus = va_arg(args, PUNICODE_STRING); + if ((pus == NULL) || (pus->Buffer == NULL)) { + sw = NULL; + len = -1; + } else { + sw = pus->Buffer; + len = pus->Length / sizeof(WCHAR); + } + str = stringw(str, end, sw, len, field_width, precision, flags); + } else { + /* print counted ascii string */ + PANSI_STRING pus = va_arg(args, PANSI_STRING); + if ((pus == NULL) || (pus->Buffer == NULL)) { + s = NULL; + len = -1; + } else { + s = pus->Buffer; + len = pus->Length; + } + str = string(str, end, s, len, field_width, precision, flags); + } + continue; + + case 'p': + if ((flags & LARGE) == 0) + flags |= LARGE; + + if (field_width == -1) { + field_width = 2 * sizeof(void *); + flags |= ZEROPAD; + } + str = number(str, end, + (ULONG_PTR) va_arg(args, void *), 16, + field_width, precision, flags); + continue; + + case 'n': + /* FIXME: What does C99 say about the overflow case here? */ + if (qualifier == 'l') { + long * ip = va_arg(args, long *); + *ip = (str - buf); + } else { + int * ip = va_arg(args, int *); + *ip = (str - buf); + } + continue; + + /* float number formats - set up the flags and "break" */ + case 'e': + case 'E': + case 'f': + case 'g': + case 'G': + _double = (double)va_arg(args, double); + if ( _isnan(_double) ) { + s = "Nan"; + len = 3; + while ( len > 0 ) { + if (str <= end) + *str = *s++; + ++str; + len --; + } + } else if ( _isinf(_double) < 0 ) { + s = "-Inf"; + len = 4; + while ( len > 0 ) { + if (str <= end) + *str = *s++; + ++str; + len --; + } + } else if ( _isinf(_double) > 0 ) { + s = "+Inf"; + len = 4; + while ( len > 0 ) { + if (str <= end) + *str = *s++; + ++str; + len --; + } + } else { + if ( precision == -1 ) + precision = 6; + str = numberf(str, end, (int)_double, base, field_width, precision, flags); + } + + continue; + + + /* integer number formats - set up the flags and "break" */ + case 'o': + base = 8; + break; + + case 'b': + base = 2; + break; + + case 'X': + flags |= LARGE; + case 'x': + base = 16; + break; + + case 'd': + case 'i': + flags |= SIGN; + case 'u': + break; + + default: + if (*fmt) { + if (str <= end) + *str = *fmt; + ++str; + } else + --fmt; + continue; + } + + if (qualifier == 'I') + num = va_arg(args, unsigned long long); + else if (qualifier == 'l') { + if (flags & SIGN) + num = va_arg(args, long); + else + num = va_arg(args, unsigned long); + } + else if (qualifier == 'h') { + if (flags & SIGN) + num = va_arg(args, int); + else + num = va_arg(args, unsigned int); + } + else { + if (flags & SIGN) + num = va_arg(args, int); + else + num = va_arg(args, unsigned int); + } + str = number(str, end, num, base, field_width, precision, flags); + } + if (str <= end) + *str = '\0'; + else if (cnt > 0) + /* don't write out a null byte if the buf size is zero */ + *end = '\0'; + return str-buf; +} + + +/* + * @implemented + */ +int sprintf(char * buf, const char *fmt, ...) +{ + va_list args; + int i; + + va_start(args, fmt); + i=_vsnprintf(buf,MAXLONG,fmt,args); + va_end(args); + return i; +} + + +/* + * @implemented + */ +int _snprintf(char * buf, size_t cnt, const char *fmt, ...) +{ + va_list args; + int i; + + va_start(args, fmt); + i=_vsnprintf(buf,cnt,fmt,args); + va_end(args); + return i; +} + + +/* + * @implemented + */ +int __cdecl vsprintf(char *buf, const char *fmt, va_list args) +{ + return _vsnprintf(buf,MAXLONG,fmt,args); +} + +/* EOF */