2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * FILE: win32ss/gdi/gdi32/objects/font.c
18 /* Rounds a floating point number to integer. The world-to-viewport
19 * transformation process is done in floating point internally. This function
20 * is then used to round these coordinates to integer values.
22 static __inline INT
GDI_ROUND(FLOAT val
)
24 return (int)floor(val
+ 0.5);
28 * For TranslateCharsetInfo
30 #define MAXTCIINDEX 32
31 static const CHARSETINFO FONT_tci
[MAXTCIINDEX
] =
34 { ANSI_CHARSET
, 1252, {{0,0,0,0},{FS_LATIN1
,0}} },
35 { EASTEUROPE_CHARSET
, 1250, {{0,0,0,0},{FS_LATIN2
,0}} },
36 { RUSSIAN_CHARSET
, 1251, {{0,0,0,0},{FS_CYRILLIC
,0}} },
37 { GREEK_CHARSET
, 1253, {{0,0,0,0},{FS_GREEK
,0}} },
38 { TURKISH_CHARSET
, 1254, {{0,0,0,0},{FS_TURKISH
,0}} },
39 { HEBREW_CHARSET
, 1255, {{0,0,0,0},{FS_HEBREW
,0}} },
40 { ARABIC_CHARSET
, 1256, {{0,0,0,0},{FS_ARABIC
,0}} },
41 { BALTIC_CHARSET
, 1257, {{0,0,0,0},{FS_BALTIC
,0}} },
42 { VIETNAMESE_CHARSET
, 1258, {{0,0,0,0},{FS_VIETNAMESE
,0}} },
43 /* reserved by ANSI */
44 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
45 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
46 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
47 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
48 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
49 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
50 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
52 { THAI_CHARSET
, 874, {{0,0,0,0},{FS_THAI
,0}} },
53 { SHIFTJIS_CHARSET
, 932, {{0,0,0,0},{FS_JISJAPAN
,0}} },
54 { GB2312_CHARSET
, 936, {{0,0,0,0},{FS_CHINESESIMP
,0}} },
55 { HANGEUL_CHARSET
, 949, {{0,0,0,0},{FS_WANSUNG
,0}} },
56 { CHINESEBIG5_CHARSET
, 950, {{0,0,0,0},{FS_CHINESETRAD
,0}} },
57 { JOHAB_CHARSET
, 1361, {{0,0,0,0},{FS_JOHAB
,0}} },
58 /* reserved for alternate ANSI and OEM */
59 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
60 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
61 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
62 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
63 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
64 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
65 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
66 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
67 /* reserved for system */
68 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
69 { SYMBOL_CHARSET
, CP_SYMBOL
, {{0,0,0,0},{FS_SYMBOL
,0}} }
72 #define INITIAL_FAMILY_COUNT 64
74 /***********************************************************************
75 * TEXTMETRIC conversion functions.
79 FONT_TextMetricWToA(const TEXTMETRICW
*ptmW
, LPTEXTMETRICA ptmA
)
81 ptmA
->tmHeight
= ptmW
->tmHeight
;
82 ptmA
->tmAscent
= ptmW
->tmAscent
;
83 ptmA
->tmDescent
= ptmW
->tmDescent
;
84 ptmA
->tmInternalLeading
= ptmW
->tmInternalLeading
;
85 ptmA
->tmExternalLeading
= ptmW
->tmExternalLeading
;
86 ptmA
->tmAveCharWidth
= ptmW
->tmAveCharWidth
;
87 ptmA
->tmMaxCharWidth
= ptmW
->tmMaxCharWidth
;
88 ptmA
->tmWeight
= ptmW
->tmWeight
;
89 ptmA
->tmOverhang
= ptmW
->tmOverhang
;
90 ptmA
->tmDigitizedAspectX
= ptmW
->tmDigitizedAspectX
;
91 ptmA
->tmDigitizedAspectY
= ptmW
->tmDigitizedAspectY
;
92 ptmA
->tmFirstChar
= min(ptmW
->tmFirstChar
, 255);
93 if (ptmW
->tmCharSet
== SYMBOL_CHARSET
)
95 ptmA
->tmFirstChar
= 0x1e;
96 ptmA
->tmLastChar
= 0xff; /* win9x behaviour - we need the OS2 table data to calculate correctly */
100 ptmA
->tmFirstChar
= ptmW
->tmDefaultChar
- 1;
101 ptmA
->tmLastChar
= min(ptmW
->tmLastChar
, 0xff);
103 ptmA
->tmDefaultChar
= (CHAR
)ptmW
->tmDefaultChar
;
104 ptmA
->tmBreakChar
= (CHAR
)ptmW
->tmBreakChar
;
105 ptmA
->tmItalic
= ptmW
->tmItalic
;
106 ptmA
->tmUnderlined
= ptmW
->tmUnderlined
;
107 ptmA
->tmStruckOut
= ptmW
->tmStruckOut
;
108 ptmA
->tmPitchAndFamily
= ptmW
->tmPitchAndFamily
;
109 ptmA
->tmCharSet
= ptmW
->tmCharSet
;
112 /***********************************************************************
115 * Returns a Unicode translation of str using the charset of the
116 * currently selected font in hdc. If count is -1 then str is assumed
117 * to be '\0' terminated, otherwise it contains the number of bytes to
118 * convert. If plenW is non-NULL, on return it will point to the
119 * number of WCHARs that have been written. If pCP is non-NULL, on
120 * return it will point to the codepage used in the conversion. The
121 * caller should free the returned LPWSTR from the process heap
124 static LPWSTR
FONT_mbtowc(HDC hdc
, LPCSTR str
, INT count
, INT
*plenW
, UINT
*pCP
)
126 UINT cp
= GdiGetCodePage( hdc
);
130 if(count
== -1) count
= strlen(str
);
131 lenW
= MultiByteToWideChar(cp
, 0, str
, count
, NULL
, 0);
132 strW
= HeapAlloc(GetProcessHeap(), 0, lenW
*sizeof(WCHAR
));
135 if(!MultiByteToWideChar(cp
, 0, str
, count
, strW
, lenW
))
137 HeapFree(GetProcessHeap(), 0, strW
);
140 DPRINT("mapped %s -> %S\n", str
, strW
);
141 if(plenW
) *plenW
= lenW
;
146 static LPSTR
FONT_GetCharsByRangeA(HDC hdc
, UINT firstChar
, UINT lastChar
, PINT pByteLen
)
148 INT i
, count
= lastChar
- firstChar
+ 1;
155 switch (GdiGetCodePage(hdc
))
162 if (lastChar
> 0xffff)
164 if ((firstChar
^ lastChar
) > 0xff)
173 str
= HeapAlloc(GetProcessHeap(), 0, count
* 2 + 1);
177 for(i
= 0, c
= firstChar
; c
<= lastChar
; i
++, c
++)
180 str
[i
++] = (BYTE
)(c
>> 8);
191 NewTextMetricW2A(NEWTEXTMETRICA
*tma
, NEWTEXTMETRICW
*tmw
)
193 FONT_TextMetricWToA((TEXTMETRICW
*) tmw
, (TEXTMETRICA
*) tma
);
194 tma
->ntmFlags
= tmw
->ntmFlags
;
195 tma
->ntmSizeEM
= tmw
->ntmSizeEM
;
196 tma
->ntmCellHeight
= tmw
->ntmCellHeight
;
197 tma
->ntmAvgWidth
= tmw
->ntmAvgWidth
;
201 NewTextMetricExW2A(NEWTEXTMETRICEXA
*tma
, NEWTEXTMETRICEXW
*tmw
)
203 NewTextMetricW2A(&tma
->ntmTm
, &tmw
->ntmTm
);
204 tma
->ntmFontSig
= tmw
->ntmFontSig
;
208 IntEnumFontFamilies(HDC Dc
, LPLOGFONTW LogFont
, PVOID EnumProc
, LPARAM lParam
,
213 PFONTFAMILYINFO Info
;
216 ENUMLOGFONTEXA EnumLogFontExA
;
217 NEWTEXTMETRICEXA NewTextMetricExA
;
220 Info
= RtlAllocateHeap(GetProcessHeap(), 0,
221 INITIAL_FAMILY_COUNT
* sizeof(FONTFAMILYINFO
));
229 lfW
.lfCharSet
= DEFAULT_CHARSET
;
230 lfW
.lfPitchAndFamily
= 0;
231 lfW
.lfFaceName
[0] = 0;
235 FontFamilyCount
= NtGdiGetFontFamilyInfo(Dc
, LogFont
, Info
, INITIAL_FAMILY_COUNT
);
236 if (FontFamilyCount
< 0)
238 RtlFreeHeap(GetProcessHeap(), 0, Info
);
241 if (INITIAL_FAMILY_COUNT
< FontFamilyCount
)
243 FontFamilySize
= FontFamilyCount
;
244 RtlFreeHeap(GetProcessHeap(), 0, Info
);
245 Info
= RtlAllocateHeap(GetProcessHeap(), 0,
246 FontFamilyCount
* sizeof(FONTFAMILYINFO
));
251 FontFamilyCount
= NtGdiGetFontFamilyInfo(Dc
, LogFont
, Info
, FontFamilySize
);
252 if (FontFamilyCount
< 0 || FontFamilySize
< FontFamilyCount
)
254 RtlFreeHeap(GetProcessHeap(), 0, Info
);
259 for (i
= 0; i
< FontFamilyCount
; i
++)
263 Ret
= ((FONTENUMPROCW
) EnumProc
)(
264 (VOID
*)&Info
[i
].EnumLogFontEx
,
265 (VOID
*)&Info
[i
].NewTextMetricEx
,
266 Info
[i
].FontType
, lParam
);
270 // Could use EnumLogFontExW2A here?
271 LogFontW2A(&EnumLogFontExA
.elfLogFont
, &Info
[i
].EnumLogFontEx
.elfLogFont
);
272 WideCharToMultiByte(CP_THREAD_ACP
, 0, Info
[i
].EnumLogFontEx
.elfFullName
, -1,
273 (LPSTR
)EnumLogFontExA
.elfFullName
, LF_FULLFACESIZE
, NULL
, NULL
);
274 WideCharToMultiByte(CP_THREAD_ACP
, 0, Info
[i
].EnumLogFontEx
.elfStyle
, -1,
275 (LPSTR
)EnumLogFontExA
.elfStyle
, LF_FACESIZE
, NULL
, NULL
);
276 WideCharToMultiByte(CP_THREAD_ACP
, 0, Info
[i
].EnumLogFontEx
.elfScript
, -1,
277 (LPSTR
)EnumLogFontExA
.elfScript
, LF_FACESIZE
, NULL
, NULL
);
278 NewTextMetricExW2A(&NewTextMetricExA
,
279 &Info
[i
].NewTextMetricEx
);
280 Ret
= ((FONTENUMPROCA
) EnumProc
)(
281 (VOID
*)&EnumLogFontExA
,
282 (VOID
*)&NewTextMetricExA
,
283 Info
[i
].FontType
, lParam
);
290 RtlFreeHeap(GetProcessHeap(), 0, Info
);
299 EnumFontFamiliesExW(HDC hdc
, LPLOGFONTW lpLogfont
, FONTENUMPROCW lpEnumFontFamExProc
,
300 LPARAM lParam
, DWORD dwFlags
)
302 return IntEnumFontFamilies(hdc
, lpLogfont
, lpEnumFontFamExProc
, lParam
, TRUE
);
310 EnumFontFamiliesW(HDC hdc
, LPCWSTR lpszFamily
, FONTENUMPROCW lpEnumFontFamProc
,
315 ZeroMemory(&LogFont
, sizeof(LOGFONTW
));
316 LogFont
.lfCharSet
= DEFAULT_CHARSET
;
317 if (NULL
!= lpszFamily
)
319 if (!*lpszFamily
) return 1;
320 lstrcpynW(LogFont
.lfFaceName
, lpszFamily
, LF_FACESIZE
);
323 return IntEnumFontFamilies(hdc
, &LogFont
, lpEnumFontFamProc
, lParam
, TRUE
);
331 EnumFontFamiliesExA (HDC hdc
, LPLOGFONTA lpLogfont
, FONTENUMPROCA lpEnumFontFamExProc
,
332 LPARAM lParam
, DWORD dwFlags
)
334 LOGFONTW LogFontW
, *pLogFontW
;
338 LogFontA2W(&LogFontW
,lpLogfont
);
339 pLogFontW
= &LogFontW
;
341 else pLogFontW
= NULL
;
343 /* no need to convert LogFontW back to lpLogFont b/c it's an [in] parameter only */
344 return IntEnumFontFamilies(hdc
, pLogFontW
, lpEnumFontFamExProc
, lParam
, FALSE
);
352 EnumFontFamiliesA(HDC hdc
, LPCSTR lpszFamily
, FONTENUMPROCA lpEnumFontFamProc
,
357 ZeroMemory(&LogFont
, sizeof(LOGFONTW
));
358 LogFont
.lfCharSet
= DEFAULT_CHARSET
;
359 if (NULL
!= lpszFamily
)
361 if (!*lpszFamily
) return 1;
362 MultiByteToWideChar(CP_THREAD_ACP
, 0, lpszFamily
, -1, LogFont
.lfFaceName
, LF_FACESIZE
);
365 return IntEnumFontFamilies(hdc
, &LogFont
, lpEnumFontFamProc
, lParam
, FALSE
);
374 GetCharacterPlacementA(
379 GCP_RESULTSA
*lpResults
,
384 GCP_RESULTSW resultsW
;
388 if ( !lpString
|| uCount
<= 0 || !lpResults
|| (nMaxExtent
< 0 && nMaxExtent
!= -1 ) )
390 SetLastError(ERROR_INVALID_PARAMETER
);
393 /* TRACE("%s, %d, %d, 0x%08x\n",
394 debugstr_an(lpString, uCount), uCount, nMaxExtent, dwFlags);
396 /* both structs are equal in size */
397 memcpy(&resultsW
, lpResults
, sizeof(resultsW
));
399 lpStringW
= FONT_mbtowc(hdc
, lpString
, uCount
, &uCountW
, &font_cp
);
400 if (lpStringW
== NULL
)
404 if(lpResults
->lpOutString
)
406 resultsW
.lpOutString
= HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR
)*uCountW
);
407 if (resultsW
.lpOutString
== NULL
)
409 HeapFree(GetProcessHeap(), 0, lpStringW
);
414 ret
= GetCharacterPlacementW(hdc
, lpStringW
, uCountW
, nMaxExtent
, &resultsW
, dwFlags
);
416 lpResults
->nGlyphs
= resultsW
.nGlyphs
;
417 lpResults
->nMaxFit
= resultsW
.nMaxFit
;
419 if(lpResults
->lpOutString
)
421 WideCharToMultiByte(font_cp
, 0, resultsW
.lpOutString
, uCountW
,
422 lpResults
->lpOutString
, uCount
, NULL
, NULL
);
425 HeapFree(GetProcessHeap(), 0, lpStringW
);
426 HeapFree(GetProcessHeap(), 0, resultsW
.lpOutString
);
437 GetCharacterPlacementW(
442 GCP_RESULTSW
*lpResults
,
449 DPRINT("GetCharacterPlacementW\n");
451 if (dwFlags
&(~GCP_REORDER
)) DPRINT("flags 0x%08lx ignored\n", dwFlags
);
452 if (lpResults
->lpClass
) DPRINT("classes not implemented\n");
453 if (lpResults
->lpCaretPos
&& (dwFlags
& GCP_REORDER
))
454 DPRINT("Caret positions for complex scripts not implemented\n");
457 if (nSet
> lpResults
->nGlyphs
)
458 nSet
= lpResults
->nGlyphs
;
460 /* return number of initialized fields */
461 lpResults
->nGlyphs
= nSet
;
463 if (dwFlags
& GCP_REORDER
)
465 if (LoadLPK(LPK_GCP
))
466 return LpkGetCharacterPlacement(hdc
, lpString
, uCount
, nMaxExtent
, lpResults
, dwFlags
, 0);
469 /* Treat the case where no special handling was requested in a fastpath way */
470 /* copy will do if the GCP_REORDER flag is not set */
471 if (lpResults
->lpOutString
)
472 lstrcpynW( lpResults
->lpOutString
, lpString
, nSet
);
474 if (lpResults
->lpOrder
)
476 for (i
= 0; i
< nSet
; i
++)
477 lpResults
->lpOrder
[i
] = i
;
480 /* FIXME: Will use the placement chars */
484 for (i
= 0; i
< nSet
; i
++)
486 if (GetCharWidth32W(hdc
, lpString
[i
], lpString
[i
], &c
))
487 lpResults
->lpDx
[i
]= c
;
491 if (lpResults
->lpCaretPos
&& !(dwFlags
& GCP_REORDER
))
495 lpResults
->lpCaretPos
[0] = 0;
496 for (i
= 1; i
< nSet
; i
++)
497 if (GetTextExtentPoint32W(hdc
, &(lpString
[i
- 1]), 1, &size
))
498 lpResults
->lpCaretPos
[i
] = (pos
+= size
.cx
);
501 if (lpResults
->lpGlyphs
)
502 NtGdiGetGlyphIndicesW(hdc
, lpString
, nSet
, lpResults
->lpGlyphs
, 0);
504 if (GetTextExtentPoint32W(hdc
, lpString
, uCount
, &size
))
505 ret
= MAKELONG(size
.cx
, size
.cy
);
512 NewGetCharacterPlacementW(
517 GCP_RESULTSW
*lpResults
,
524 if ( !lpString
|| uCount
<= 0 || (nMaxExtent
< 0 && nMaxExtent
!= -1 ) )
526 SetLastError(ERROR_INVALID_PARAMETER
);
532 if ( GetTextExtentPointW(hdc
, lpString
, uCount
, &Size
) )
534 return MAKELONG(Size
.cx
, Size
.cy
);
540 if ( nSet
> lpResults
->nGlyphs
)
541 nSet
= lpResults
->nGlyphs
;
543 return NtGdiGetCharacterPlacementW( hdc
,
557 GetCharABCWidthsFloatW(HDC hdc
,
562 DPRINT("GetCharABCWidthsFloatW\n");
563 if ((!abcF
) || (FirstChar
> LastChar
))
565 SetLastError(ERROR_INVALID_PARAMETER
);
568 return NtGdiGetCharABCWidthsW( hdc
,
570 (ULONG
)(LastChar
- FirstChar
+ 1),
582 GetCharWidthFloatW(HDC hdc
,
587 DPRINT("GetCharWidthsFloatW\n");
588 if ((!pxBuffer
) || (iFirstChar
> iLastChar
))
590 SetLastError(ERROR_INVALID_PARAMETER
);
593 return NtGdiGetCharWidthW( hdc
,
595 (ULONG
)(iLastChar
- iFirstChar
+ 1),
607 GetCharWidthW(HDC hdc
,
612 DPRINT("GetCharWidthsW\n");
613 if ((!lpBuffer
) || (iFirstChar
> iLastChar
))
615 SetLastError(ERROR_INVALID_PARAMETER
);
618 return NtGdiGetCharWidthW( hdc
,
620 (ULONG
)(iLastChar
- iFirstChar
+ 1),
632 GetCharWidth32W(HDC hdc
,
637 DPRINT("GetCharWidths32W\n");
638 if ((!lpBuffer
) || (iFirstChar
> iLastChar
))
640 SetLastError(ERROR_INVALID_PARAMETER
);
643 return NtGdiGetCharWidthW( hdc
,
645 (ULONG
)(iLastChar
- iFirstChar
+ 1),
647 GCW_NOFLOAT
|GCW_WIN32
,
658 GetCharABCWidthsW(HDC hdc
,
663 DPRINT("GetCharABCWidthsW\n");
664 if ((!lpabc
) || (FirstChar
> LastChar
))
666 SetLastError(ERROR_INVALID_PARAMETER
);
669 return NtGdiGetCharABCWidthsW( hdc
,
671 (ULONG
)(LastChar
- FirstChar
+ 1),
694 DPRINT("GetCharWidthsA\n");
696 str
= FONT_GetCharsByRangeA(hdc
, iFirstChar
, iLastChar
, &count
);
700 wstr
= FONT_mbtowc(hdc
, str
, count
+1, &wlen
, NULL
);
703 HeapFree(GetProcessHeap(), 0, str
);
707 ret
= NtGdiGetCharWidthW( hdc
,
714 HeapFree(GetProcessHeap(), 0, str
);
715 HeapFree(GetProcessHeap(), 0, wstr
);
737 DPRINT("GetCharWidths32A\n");
739 str
= FONT_GetCharsByRangeA(hdc
, iFirstChar
, iLastChar
, &count
);
743 wstr
= FONT_mbtowc(hdc
, str
, count
+1, &wlen
, NULL
);
746 HeapFree(GetProcessHeap(), 0, str
);
750 ret
= NtGdiGetCharWidthW( hdc
,
754 GCW_NOFLOAT
|GCW_WIN32
,
757 HeapFree(GetProcessHeap(), 0, str
);
758 HeapFree(GetProcessHeap(), 0, wstr
);
780 DPRINT("GetCharWidthsFloatA\n");
782 str
= FONT_GetCharsByRangeA(hdc
, iFirstChar
, iLastChar
, &count
);
786 wstr
= FONT_mbtowc(hdc
, str
, count
+1, &wlen
, NULL
);
789 HeapFree(GetProcessHeap(), 0, str
);
792 ret
= NtGdiGetCharWidthW( hdc
, wstr
[0], (ULONG
) count
, (PWCHAR
) wstr
, 0, (PVOID
) pxBuffer
);
794 HeapFree(GetProcessHeap(), 0, str
);
795 HeapFree(GetProcessHeap(), 0, wstr
);
817 DPRINT("GetCharABCWidthsA\n");
819 str
= FONT_GetCharsByRangeA(hdc
, iFirstChar
, iLastChar
, &count
);
823 wstr
= FONT_mbtowc(hdc
, str
, count
+1, &wlen
, NULL
);
826 HeapFree(GetProcessHeap(), 0, str
);
830 ret
= NtGdiGetCharABCWidthsW( hdc
,
837 HeapFree(GetProcessHeap(), 0, str
);
838 HeapFree(GetProcessHeap(), 0, wstr
);
848 GetCharABCWidthsFloatA(
860 DPRINT("GetCharABCWidthsFloatA\n");
862 str
= FONT_GetCharsByRangeA(hdc
, iFirstChar
, iLastChar
, &count
);
866 wstr
= FONT_mbtowc( hdc
, str
, count
+1, &wlen
, NULL
);
869 HeapFree( GetProcessHeap(), 0, str
);
872 ret
= NtGdiGetCharABCWidthsW( hdc
,wstr
[0],(ULONG
)count
, (PWCHAR
)wstr
, 0, (PVOID
)lpABCF
);
874 HeapFree( GetProcessHeap(), 0, str
);
875 HeapFree( GetProcessHeap(), 0, wstr
);
885 GetCharABCWidthsI(HDC hdc
,
891 DPRINT("GetCharABCWidthsI\n");
892 return NtGdiGetCharABCWidthsW( hdc
,
896 GCABCW_NOFLOAT
|GCABCW_INDICES
,
905 GetCharWidthI(HDC hdc
,
912 DPRINT("GetCharWidthsI\n");
913 if (!lpBuffer
|| (!pgi
&& (giFirst
== MAXUSHORT
))) // Cannot be at max.
915 SetLastError(ERROR_INVALID_PARAMETER
);
918 if (!cgi
) return TRUE
;
919 return NtGdiGetCharWidthW( hdc
,
923 GCW_INDICES
|GCW_NOFLOAT
|GCW_WIN32
,
936 DWORD Gcp
= 0, Ret
= 0;
939 Ret
= NtGdiGetTextCharsetInfo(hDc
, NULL
, 0);
940 if ((Ret
== ARABIC_CHARSET
) || (Ret
== HEBREW_CHARSET
))
941 Ret
= (GCP_KASHIDA
|GCP_DIACRITIC
|GCP_LIGATE
|GCP_GLYPHSHAPE
|GCP_REORDER
);
943 Gcp
= GetDCDWord(hDc
, GdiGetFontLanguageInfo
, GCP_ERROR
);
944 if ( Gcp
== GCP_ERROR
)
968 lpstrW
= FONT_mbtowc(hdc
, lpstr
, count
, &countW
, NULL
);
973 Ret
= NtGdiGetGlyphIndicesW(hdc
, lpstrW
, countW
, pgi
, flags
);
974 HeapFree(GetProcessHeap(), 0, lpstrW
);
997 DPRINT("GetGlyphOutlineA uChar %x\n", uChar
);
998 if (!lpgm
|| !lpmat2
) return GDI_ERROR
;
999 if(!(uFormat
& GGO_GLYPH_INDEX
))
1003 if(uChar
> 0xff) /* but, 2 bytes character only */
1006 mbchs
[0] = (uChar
& 0xff00) >> 8;
1007 mbchs
[1] = (uChar
& 0xff);
1012 mbchs
[0] = (uChar
& 0xff);
1014 p
= FONT_mbtowc(hdc
, mbchs
, len
, NULL
, NULL
);
1021 ret
= NtGdiGetGlyphOutline(hdc
, c
, uFormat
, lpgm
, cbBuffer
, lpvBuffer
, (CONST LPMAT2
)lpmat2
, TRUE
);
1022 HeapFree(GetProcessHeap(), 0, p
);
1036 LPGLYPHMETRICS lpgm
,
1042 DPRINT("GetGlyphOutlineW uChar %x\n", uChar
);
1043 if (!lpgm
|| !lpmat2
) return GDI_ERROR
;
1044 if (!lpvBuffer
) cbBuffer
= 0;
1045 return NtGdiGetGlyphOutline ( hdc
, uChar
, uFormat
, lpgm
, cbBuffer
, lpvBuffer
, (CONST LPMAT2
)lpmat2
, TRUE
);
1064 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1073 GetOutlineTextMetricsA(
1076 LPOUTLINETEXTMETRICA lpOTM
1079 char buf
[512], *ptr
;
1081 OUTLINETEXTMETRICW
*lpOTMW
= (OUTLINETEXTMETRICW
*)buf
;
1082 OUTLINETEXTMETRICA
*output
= lpOTM
;
1085 if((ret
= GetOutlineTextMetricsW(hdc
, 0, NULL
)) == 0)
1087 if(ret
> sizeof(buf
))
1089 lpOTMW
= HeapAlloc(GetProcessHeap(), 0, ret
);
1095 GetOutlineTextMetricsW(hdc
, ret
, lpOTMW
);
1097 needed
= sizeof(OUTLINETEXTMETRICA
);
1098 if(lpOTMW
->otmpFamilyName
)
1099 needed
+= WideCharToMultiByte(CP_ACP
, 0,
1100 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpFamilyName
), -1,
1101 NULL
, 0, NULL
, NULL
);
1102 if(lpOTMW
->otmpFaceName
)
1103 needed
+= WideCharToMultiByte(CP_ACP
, 0,
1104 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpFaceName
), -1,
1105 NULL
, 0, NULL
, NULL
);
1106 if(lpOTMW
->otmpStyleName
)
1107 needed
+= WideCharToMultiByte(CP_ACP
, 0,
1108 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpStyleName
), -1,
1109 NULL
, 0, NULL
, NULL
);
1110 if(lpOTMW
->otmpFullName
)
1111 needed
+= WideCharToMultiByte(CP_ACP
, 0,
1112 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpFullName
), -1,
1113 NULL
, 0, NULL
, NULL
);
1121 DPRINT("needed = %u\n", needed
);
1124 /* Since the supplied buffer isn't big enough, we'll alloc one
1125 that is and memcpy the first cbData bytes into the lpOTM at
1127 output
= HeapAlloc(GetProcessHeap(), 0, needed
);
1134 ret
= output
->otmSize
= min(needed
, cbData
);
1135 FONT_TextMetricWToA( &lpOTMW
->otmTextMetrics
, &output
->otmTextMetrics
);
1136 output
->otmFiller
= 0;
1137 output
->otmPanoseNumber
= lpOTMW
->otmPanoseNumber
;
1138 output
->otmfsSelection
= lpOTMW
->otmfsSelection
;
1139 output
->otmfsType
= lpOTMW
->otmfsType
;
1140 output
->otmsCharSlopeRise
= lpOTMW
->otmsCharSlopeRise
;
1141 output
->otmsCharSlopeRun
= lpOTMW
->otmsCharSlopeRun
;
1142 output
->otmItalicAngle
= lpOTMW
->otmItalicAngle
;
1143 output
->otmEMSquare
= lpOTMW
->otmEMSquare
;
1144 output
->otmAscent
= lpOTMW
->otmAscent
;
1145 output
->otmDescent
= lpOTMW
->otmDescent
;
1146 output
->otmLineGap
= lpOTMW
->otmLineGap
;
1147 output
->otmsCapEmHeight
= lpOTMW
->otmsCapEmHeight
;
1148 output
->otmsXHeight
= lpOTMW
->otmsXHeight
;
1149 output
->otmrcFontBox
= lpOTMW
->otmrcFontBox
;
1150 output
->otmMacAscent
= lpOTMW
->otmMacAscent
;
1151 output
->otmMacDescent
= lpOTMW
->otmMacDescent
;
1152 output
->otmMacLineGap
= lpOTMW
->otmMacLineGap
;
1153 output
->otmusMinimumPPEM
= lpOTMW
->otmusMinimumPPEM
;
1154 output
->otmptSubscriptSize
= lpOTMW
->otmptSubscriptSize
;
1155 output
->otmptSubscriptOffset
= lpOTMW
->otmptSubscriptOffset
;
1156 output
->otmptSuperscriptSize
= lpOTMW
->otmptSuperscriptSize
;
1157 output
->otmptSuperscriptOffset
= lpOTMW
->otmptSuperscriptOffset
;
1158 output
->otmsStrikeoutSize
= lpOTMW
->otmsStrikeoutSize
;
1159 output
->otmsStrikeoutPosition
= lpOTMW
->otmsStrikeoutPosition
;
1160 output
->otmsUnderscoreSize
= lpOTMW
->otmsUnderscoreSize
;
1161 output
->otmsUnderscorePosition
= lpOTMW
->otmsUnderscorePosition
;
1164 ptr
= (char*)(output
+ 1);
1165 left
= needed
- sizeof(*output
);
1167 if(lpOTMW
->otmpFamilyName
)
1169 output
->otmpFamilyName
= (LPSTR
)(ptr
- (char*)output
);
1170 len
= WideCharToMultiByte(CP_ACP
, 0,
1171 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpFamilyName
), -1,
1172 ptr
, left
, NULL
, NULL
);
1177 output
->otmpFamilyName
= 0;
1179 if(lpOTMW
->otmpFaceName
)
1181 output
->otmpFaceName
= (LPSTR
)(ptr
- (char*)output
);
1182 len
= WideCharToMultiByte(CP_ACP
, 0,
1183 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpFaceName
), -1,
1184 ptr
, left
, NULL
, NULL
);
1189 output
->otmpFaceName
= 0;
1191 if(lpOTMW
->otmpStyleName
)
1193 output
->otmpStyleName
= (LPSTR
)(ptr
- (char*)output
);
1194 len
= WideCharToMultiByte(CP_ACP
, 0,
1195 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpStyleName
), -1,
1196 ptr
, left
, NULL
, NULL
);
1201 output
->otmpStyleName
= 0;
1203 if(lpOTMW
->otmpFullName
)
1205 output
->otmpFullName
= (LPSTR
)(ptr
- (char*)output
);
1206 len
= WideCharToMultiByte(CP_ACP
, 0,
1207 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpFullName
), -1,
1208 ptr
, left
, NULL
, NULL
);
1212 output
->otmpFullName
= 0;
1218 memcpy(lpOTM
, output
, cbData
);
1219 HeapFree(GetProcessHeap(), 0, output
);
1221 /* check if the string offsets really fit into the provided size */
1222 /* FIXME: should we check string length as well? */
1223 if ((UINT_PTR
)lpOTM
->otmpFamilyName
>= lpOTM
->otmSize
)
1224 lpOTM
->otmpFamilyName
= 0; /* doesn't fit */
1226 if ((UINT_PTR
)lpOTM
->otmpFaceName
>= lpOTM
->otmSize
)
1227 lpOTM
->otmpFaceName
= 0; /* doesn't fit */
1229 if ((UINT_PTR
)lpOTM
->otmpStyleName
>= lpOTM
->otmSize
)
1230 lpOTM
->otmpStyleName
= 0; /* doesn't fit */
1232 if ((UINT_PTR
)lpOTM
->otmpFullName
>= lpOTM
->otmSize
)
1233 lpOTM
->otmpFullName
= 0; /* doesn't fit */
1237 if(lpOTMW
!= (OUTLINETEXTMETRICW
*)buf
)
1238 HeapFree(GetProcessHeap(), 0, lpOTMW
);
1243 /* Performs a device to world transformation on the specified size (which
1244 * is in integer format).
1246 static inline INT
INTERNAL_YDSTOWS(XFORM
*xForm
, INT height
)
1250 /* Perform operation with floating point */
1251 floatHeight
= (double)height
* xForm
->eM22
;
1252 /* Round to integers */
1253 return GDI_ROUND(floatHeight
);
1256 /* scale width and height but don't mirror them */
1257 static inline INT
width_to_LP( XFORM
*xForm
, INT width
)
1259 return GDI_ROUND( (double)width
* fabs( xForm
->eM11
));
1262 static inline INT
height_to_LP( XFORM
*xForm
, INT height
)
1264 return GDI_ROUND( (double)height
* fabs( xForm
->eM22
));
1272 GetOutlineTextMetricsW(
1275 LPOUTLINETEXTMETRICW lpOTM
1278 TMDIFF Tmd
; // Should not be zero.
1279 UINT Size
, AvailableSize
= 0, StringSize
;
1281 OUTLINETEXTMETRICW
* LocalOTM
;
1285 /* Get the structure */
1286 Size
= NtGdiGetOutlineTextMetricsInternalW(hdc
, 0, NULL
, &Tmd
);
1289 if (!lpOTM
|| (cbData
< sizeof(*lpOTM
)))
1292 LocalOTM
= HeapAlloc(GetProcessHeap(), 0, Size
);
1293 LocalOTM
->otmSize
= Size
;
1294 Size
= NtGdiGetOutlineTextMetricsInternalW(hdc
, Size
, LocalOTM
, &Tmd
);
1297 HeapFree(GetProcessHeap(), 0, LocalOTM
);
1301 if (!NtGdiGetTransform(hdc
, GdiDeviceSpaceToWorldSpace
, &DevToWorld
))
1303 DPRINT1("NtGdiGetTransform failed!\n");
1304 HeapFree(GetProcessHeap(), 0, LocalOTM
);
1305 SetLastError(ERROR_INVALID_HANDLE
);
1309 /* Fill in DC specific data */
1310 LocalOTM
->otmTextMetrics
.tmDigitizedAspectX
= GetDeviceCaps(hdc
, LOGPIXELSX
);
1311 LocalOTM
->otmTextMetrics
.tmDigitizedAspectY
= GetDeviceCaps(hdc
, LOGPIXELSY
);
1312 LocalOTM
->otmTextMetrics
.tmHeight
= height_to_LP( &DevToWorld
, LocalOTM
->otmTextMetrics
.tmHeight
);
1313 LocalOTM
->otmTextMetrics
.tmAscent
= height_to_LP( &DevToWorld
, LocalOTM
->otmTextMetrics
.tmAscent
);
1314 LocalOTM
->otmTextMetrics
.tmDescent
= height_to_LP( &DevToWorld
, LocalOTM
->otmTextMetrics
.tmDescent
);
1315 LocalOTM
->otmTextMetrics
.tmInternalLeading
= height_to_LP( &DevToWorld
, LocalOTM
->otmTextMetrics
.tmInternalLeading
);
1316 LocalOTM
->otmTextMetrics
.tmExternalLeading
= height_to_LP( &DevToWorld
, LocalOTM
->otmTextMetrics
.tmExternalLeading
);
1317 LocalOTM
->otmTextMetrics
.tmAveCharWidth
= width_to_LP( &DevToWorld
, LocalOTM
->otmTextMetrics
.tmAveCharWidth
);
1318 LocalOTM
->otmTextMetrics
.tmMaxCharWidth
= width_to_LP( &DevToWorld
, LocalOTM
->otmTextMetrics
.tmMaxCharWidth
);
1319 LocalOTM
->otmTextMetrics
.tmOverhang
= width_to_LP( &DevToWorld
, LocalOTM
->otmTextMetrics
.tmOverhang
);
1320 LocalOTM
->otmAscent
= height_to_LP( &DevToWorld
, LocalOTM
->otmAscent
);
1321 LocalOTM
->otmDescent
= height_to_LP( &DevToWorld
, LocalOTM
->otmDescent
);
1322 LocalOTM
->otmLineGap
= abs(INTERNAL_YDSTOWS(&DevToWorld
,LocalOTM
->otmLineGap
));
1323 LocalOTM
->otmsCapEmHeight
= abs(INTERNAL_YDSTOWS(&DevToWorld
,LocalOTM
->otmsCapEmHeight
));
1324 LocalOTM
->otmsXHeight
= abs(INTERNAL_YDSTOWS(&DevToWorld
,LocalOTM
->otmsXHeight
));
1325 LocalOTM
->otmrcFontBox
.top
= height_to_LP( &DevToWorld
, LocalOTM
->otmrcFontBox
.top
);
1326 LocalOTM
->otmrcFontBox
.bottom
= height_to_LP( &DevToWorld
, LocalOTM
->otmrcFontBox
.bottom
);
1327 LocalOTM
->otmrcFontBox
.left
= width_to_LP( &DevToWorld
, LocalOTM
->otmrcFontBox
.left
);
1328 LocalOTM
->otmrcFontBox
.right
= width_to_LP( &DevToWorld
, LocalOTM
->otmrcFontBox
.right
);
1329 LocalOTM
->otmMacAscent
= height_to_LP( &DevToWorld
, LocalOTM
->otmMacAscent
);
1330 LocalOTM
->otmMacDescent
= height_to_LP( &DevToWorld
, LocalOTM
->otmMacDescent
);
1331 LocalOTM
->otmMacLineGap
= abs(INTERNAL_YDSTOWS(&DevToWorld
,LocalOTM
->otmMacLineGap
));
1332 LocalOTM
->otmptSubscriptSize
.x
= width_to_LP( &DevToWorld
, LocalOTM
->otmptSubscriptSize
.x
);
1333 LocalOTM
->otmptSubscriptSize
.y
= height_to_LP( &DevToWorld
, LocalOTM
->otmptSubscriptSize
.y
);
1334 LocalOTM
->otmptSubscriptOffset
.x
= width_to_LP( &DevToWorld
, LocalOTM
->otmptSubscriptOffset
.x
);
1335 LocalOTM
->otmptSubscriptOffset
.y
= height_to_LP( &DevToWorld
, LocalOTM
->otmptSubscriptOffset
.y
);
1336 LocalOTM
->otmptSuperscriptSize
.x
= width_to_LP( &DevToWorld
, LocalOTM
->otmptSuperscriptSize
.x
);
1337 LocalOTM
->otmptSuperscriptSize
.y
= height_to_LP( &DevToWorld
, LocalOTM
->otmptSuperscriptSize
.y
);
1338 LocalOTM
->otmptSuperscriptOffset
.x
= width_to_LP( &DevToWorld
, LocalOTM
->otmptSuperscriptOffset
.x
);
1339 LocalOTM
->otmptSuperscriptOffset
.y
= height_to_LP( &DevToWorld
, LocalOTM
->otmptSuperscriptOffset
.y
);
1340 LocalOTM
->otmsStrikeoutSize
= abs(INTERNAL_YDSTOWS(&DevToWorld
,LocalOTM
->otmsStrikeoutSize
));
1341 LocalOTM
->otmsStrikeoutPosition
= height_to_LP( &DevToWorld
, LocalOTM
->otmsStrikeoutPosition
);
1342 LocalOTM
->otmsUnderscoreSize
= height_to_LP( &DevToWorld
, LocalOTM
->otmsUnderscoreSize
);
1343 LocalOTM
->otmsUnderscorePosition
= height_to_LP( &DevToWorld
, LocalOTM
->otmsUnderscorePosition
);
1345 /* Copy what we can */
1346 CopyMemory(lpOTM
, LocalOTM
, min(Size
, cbData
));
1348 lpOTM
->otmpFamilyName
= NULL
;
1349 lpOTM
->otmpFaceName
= NULL
;
1350 lpOTM
->otmpStyleName
= NULL
;
1351 lpOTM
->otmpFullName
= NULL
;
1353 Size
= sizeof(*lpOTM
);
1354 AvailableSize
= cbData
- Size
;
1355 Ptr
= (BYTE
*)lpOTM
+ sizeof(*lpOTM
);
1357 /* Fix string values up */
1358 if (LocalOTM
->otmpFamilyName
)
1360 Str
= (WCHAR
*)((char*)LocalOTM
+ (ptrdiff_t)LocalOTM
->otmpFamilyName
);
1361 StringSize
= (wcslen(Str
) + 1) * sizeof(WCHAR
);
1362 if (AvailableSize
>= StringSize
)
1364 CopyMemory(Ptr
, Str
, StringSize
);
1365 lpOTM
->otmpFamilyName
= (PSTR
)(Ptr
- (BYTE
*)lpOTM
);
1367 AvailableSize
-= StringSize
;
1372 if (LocalOTM
->otmpFaceName
)
1374 Str
= (WCHAR
*)((char*)LocalOTM
+ (ptrdiff_t)LocalOTM
->otmpFaceName
);
1375 StringSize
= (wcslen(Str
) + 1) * sizeof(WCHAR
);
1376 if (AvailableSize
>= StringSize
)
1378 CopyMemory(Ptr
, Str
, StringSize
);
1379 lpOTM
->otmpFaceName
= (PSTR
)(Ptr
- (BYTE
*)lpOTM
);
1381 AvailableSize
-= StringSize
;
1386 if (LocalOTM
->otmpStyleName
)
1388 Str
= (WCHAR
*)((char*)LocalOTM
+ (ptrdiff_t)LocalOTM
->otmpStyleName
);
1389 StringSize
= (wcslen(Str
) + 1) * sizeof(WCHAR
);
1390 if (AvailableSize
>= StringSize
)
1392 CopyMemory(Ptr
, Str
, StringSize
);
1393 lpOTM
->otmpStyleName
= (PSTR
)(Ptr
- (BYTE
*)lpOTM
);
1395 AvailableSize
-= StringSize
;
1400 if (LocalOTM
->otmpFullName
)
1402 Str
= (WCHAR
*)((char*)LocalOTM
+ (ptrdiff_t)LocalOTM
->otmpFullName
);
1403 StringSize
= (wcslen(Str
) + 1) * sizeof(WCHAR
);
1404 if (AvailableSize
>= StringSize
)
1406 CopyMemory(Ptr
, Str
, StringSize
);
1407 lpOTM
->otmpFullName
= (PSTR
)(Ptr
- (BYTE
*)lpOTM
);
1409 AvailableSize
-= StringSize
;
1414 lpOTM
->otmSize
= Size
;
1416 HeapFree(GetProcessHeap(), 0, LocalOTM
);
1426 GetKerningPairsW(HDC hdc
,
1428 LPKERNINGPAIR pkpDst
)
1430 if ((cPairs
!= 0) || (pkpDst
== 0))
1432 return NtGdiGetKerningPairs(hdc
,cPairs
,pkpDst
);
1436 SetLastError(ERROR_INVALID_PARAMETER
);
1446 GetKerningPairsA( HDC hDC
,
1448 LPKERNINGPAIR kern_pairA
)
1453 DWORD i
, total_kern_pairs
, kern_pairs_copied
= 0;
1454 KERNINGPAIR
*kern_pairW
;
1456 if (!cPairs
&& kern_pairA
)
1458 SetLastError(ERROR_INVALID_PARAMETER
);
1462 charset
= GetTextCharset(hDC
);
1463 if (!TranslateCharsetInfo(ULongToPtr(charset
), &csi
, TCI_SRCCHARSET
))
1465 DPRINT1("Can't find codepage for charset %d\n", charset
);
1468 /* GetCPInfo() will fail on CP_SYMBOL, and WideCharToMultiByte is supposed
1469 * to fail on an invalid character for CP_SYMBOL.
1471 cpi
.DefaultChar
[0] = 0;
1472 if (csi
.ciACP
!= CP_SYMBOL
&& !GetCPInfo(csi
.ciACP
, &cpi
))
1474 DPRINT1("Can't find codepage %u info\n", csi
.ciACP
);
1477 DPRINT("charset %d => codepage %u\n", charset
, csi
.ciACP
);
1479 total_kern_pairs
= NtGdiGetKerningPairs(hDC
, 0, NULL
);
1480 if (!total_kern_pairs
) return 0;
1482 if (!cPairs
&& !kern_pairA
) return total_kern_pairs
;
1484 kern_pairW
= HeapAlloc(GetProcessHeap(), 0, total_kern_pairs
* sizeof(*kern_pairW
));
1485 if (kern_pairW
== NULL
)
1489 GetKerningPairsW(hDC
, total_kern_pairs
, kern_pairW
);
1491 for (i
= 0; i
< total_kern_pairs
; i
++)
1495 if (!WideCharToMultiByte(csi
.ciACP
, 0, &kern_pairW
[i
].wFirst
, 1, &first
, 1, NULL
, NULL
))
1498 if (!WideCharToMultiByte(csi
.ciACP
, 0, &kern_pairW
[i
].wSecond
, 1, &second
, 1, NULL
, NULL
))
1501 if (first
== cpi
.DefaultChar
[0] || second
== cpi
.DefaultChar
[0])
1506 if (kern_pairs_copied
>= cPairs
) break;
1508 kern_pairA
->wFirst
= (BYTE
)first
;
1509 kern_pairA
->wSecond
= (BYTE
)second
;
1510 kern_pairA
->iKernAmount
= kern_pairW
[i
].iKernAmount
;
1513 kern_pairs_copied
++;
1516 HeapFree(GetProcessHeap(), 0, kern_pairW
);
1518 return kern_pairs_copied
;
1528 CreateFontIndirectExA(const ENUMLOGFONTEXDVA
*elfexd
)
1532 ENUMLOGFONTEXDVW Logfont
;
1534 EnumLogFontExW2A( (LPENUMLOGFONTEXA
) elfexd
,
1535 &Logfont
.elfEnumLogfontEx
);
1537 RtlCopyMemory( &Logfont
.elfDesignVector
,
1538 (PVOID
) &elfexd
->elfDesignVector
,
1539 sizeof(DESIGNVECTOR
));
1541 return NtGdiHfontCreate( &Logfont
, 0, 0, 0, NULL
);
1552 CreateFontIndirectExW(const ENUMLOGFONTEXDVW
*elfexd
)
1554 /* Msdn: Note, this function ignores the elfDesignVector member in
1559 return NtGdiHfontCreate((PENUMLOGFONTEXDVW
) elfexd
, 0, 0, 0, NULL
);
1570 CreateFontIndirectA(
1571 CONST LOGFONTA
*lplf
1578 LogFontA2W(&tlf
, lplf
);
1579 return CreateFontIndirectW(&tlf
);
1590 CreateFontIndirectW(
1591 CONST LOGFONTW
*lplf
1596 ENUMLOGFONTEXDVW Logfont
;
1598 RtlCopyMemory( &Logfont
.elfEnumLogfontEx
.elfLogFont
, lplf
, sizeof(LOGFONTW
));
1599 // Need something other than just cleaning memory here.
1600 // Guess? Use caller data to determine the rest.
1601 RtlZeroMemory( &Logfont
.elfEnumLogfontEx
.elfFullName
,
1602 sizeof(Logfont
.elfEnumLogfontEx
.elfFullName
));
1603 RtlZeroMemory( &Logfont
.elfEnumLogfontEx
.elfStyle
,
1604 sizeof(Logfont
.elfEnumLogfontEx
.elfStyle
));
1605 RtlZeroMemory( &Logfont
.elfEnumLogfontEx
.elfScript
,
1606 sizeof(Logfont
.elfEnumLogfontEx
.elfScript
));
1608 Logfont
.elfDesignVector
.dvNumAxes
= 0; // No more than MM_MAX_NUMAXES
1610 RtlZeroMemory( &Logfont
.elfDesignVector
, sizeof(DESIGNVECTOR
));
1612 return CreateFontIndirectExW(&Logfont
);
1633 DWORD fdwOutputPrecision
,
1634 DWORD fdwClipPrecision
,
1636 DWORD fdwPitchAndFamily
,
1640 ANSI_STRING StringA
;
1641 UNICODE_STRING StringU
;
1644 RtlInitAnsiString(&StringA
, (LPSTR
)lpszFace
);
1645 RtlAnsiStringToUnicodeString(&StringU
, &StringA
, TRUE
);
1647 ret
= CreateFontW(nHeight
,
1662 RtlFreeUnicodeString(&StringU
);
1683 DWORD fdwOutputPrecision
,
1684 DWORD fdwClipPrecision
,
1686 DWORD fdwPitchAndFamily
,
1692 logfont
.lfHeight
= nHeight
;
1693 logfont
.lfWidth
= nWidth
;
1694 logfont
.lfEscapement
= nEscapement
;
1695 logfont
.lfOrientation
= nOrientation
;
1696 logfont
.lfWeight
= nWeight
;
1697 logfont
.lfItalic
= (BYTE
)fnItalic
;
1698 logfont
.lfUnderline
= (BYTE
)fdwUnderline
;
1699 logfont
.lfStrikeOut
= (BYTE
)fdwStrikeOut
;
1700 logfont
.lfCharSet
= (BYTE
)fdwCharSet
;
1701 logfont
.lfOutPrecision
= (BYTE
)fdwOutputPrecision
;
1702 logfont
.lfClipPrecision
= (BYTE
)fdwClipPrecision
;
1703 logfont
.lfQuality
= (BYTE
)fdwQuality
;
1704 logfont
.lfPitchAndFamily
= (BYTE
)fdwPitchAndFamily
;
1706 if (NULL
!= lpszFace
)
1708 int Size
= sizeof(logfont
.lfFaceName
) / sizeof(WCHAR
);
1709 wcsncpy((wchar_t *)logfont
.lfFaceName
, lpszFace
, Size
- 1);
1710 /* Be 101% sure to have '\0' at end of string */
1711 logfont
.lfFaceName
[Size
- 1] = '\0';
1715 logfont
.lfFaceName
[0] = L
'\0';
1718 return CreateFontIndirectW(&logfont
);
1727 CreateScalableFontResourceA(
1730 LPCSTR lpszFontFile
,
1731 LPCSTR lpszCurrentPath
1743 AddFontResourceExW ( LPCWSTR lpszFilename
, DWORD fl
, PVOID pvReserved
)
1745 if (fl
& ~(FR_PRIVATE
| FR_NOT_ENUM
))
1747 SetLastError( ERROR_INVALID_PARAMETER
);
1751 return GdiAddFontResourceW(lpszFilename
, fl
,0);
1760 AddFontResourceExA ( LPCSTR lpszFilename
, DWORD fl
, PVOID pvReserved
)
1766 if (fl
& ~(FR_PRIVATE
| FR_NOT_ENUM
))
1768 SetLastError( ERROR_INVALID_PARAMETER
);
1772 Status
= HEAP_strdupA2W ( &FilenameW
, lpszFilename
);
1773 if ( !NT_SUCCESS (Status
) )
1775 SetLastError (RtlNtStatusToDosError(Status
));
1779 rc
= GdiAddFontResourceW ( FilenameW
, fl
, 0 );
1780 HEAP_free ( FilenameW
);
1790 AddFontResourceA ( LPCSTR lpszFilename
)
1796 Status
= HEAP_strdupA2W ( &FilenameW
, lpszFilename
);
1797 if ( !NT_SUCCESS (Status
) )
1799 SetLastError (RtlNtStatusToDosError(Status
));
1803 rc
= GdiAddFontResourceW ( FilenameW
, 0, 0);
1805 HEAP_free ( FilenameW
);
1816 AddFontResourceW ( LPCWSTR lpszFilename
)
1818 return GdiAddFontResourceW ( lpszFilename
, 0, 0 );
1827 RemoveFontResourceW(LPCWSTR lpFileName
)
1829 return RemoveFontResourceExW(lpFileName
,0,0);
1838 RemoveFontResourceA(LPCSTR lpFileName
)
1840 return RemoveFontResourceExA(lpFileName
,0,0);
1848 RemoveFontResourceExA(LPCSTR lpFileName
,
1856 /* FIXME the flags */
1858 /* FIXME NtGdiRemoveFontResource handle flags and pdv */
1860 Status
= HEAP_strdupA2W ( &lpFileNameW
, lpFileName
);
1861 if (!NT_SUCCESS (Status
))
1862 SetLastError (RtlNtStatusToDosError(Status
));
1866 HEAP_free ( lpFileNameW
);
1877 RemoveFontResourceExW(LPCWSTR lpFileName
,
1881 /* FIXME the flags */
1883 /* FIXME NtGdiRemoveFontResource handle flags and pdv */
1884 DPRINT("RemoveFontResourceExW\n");
1889 /***********************************************************************
1890 * GdiGetCharDimensions
1892 * Gets the average width of the characters in the English alphabet.
1895 * hdc [I] Handle to the device context to measure on.
1896 * lptm [O] Pointer to memory to store the text metrics into.
1897 * height [O] On exit, the maximum height of characters in the English alphabet.
1900 * The average width of characters in the English alphabet.
1903 * This function is used by the dialog manager to get the size of a dialog
1904 * unit. It should also be used by other pieces of code that need to know
1905 * the size of a dialog unit in logical units without having access to the
1906 * window handle of the dialog.
1907 * Windows caches the font metrics from this function, but we don't and
1908 * there doesn't appear to be an immediate advantage to do so.
1911 * GetTextExtentPointW, GetTextMetricsW, MapDialogRect.
1913 * Despite most of MSDN insisting that the horizontal base unit is
1914 * tmAveCharWidth it isn't. Knowledge base article Q145994
1915 * "HOWTO: Calculate Dialog Units When Not Using the System Font",
1916 * says that we should take the average of the 52 English upper and lower
1924 GdiGetCharDimensions(HDC hdc
, LPTEXTMETRICW lptm
, LONG
*height
)
1928 static const WCHAR alphabet
[] =
1930 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q',
1931 'r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H',
1932 'I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',0
1935 if(!GetTextMetricsW(hdc
, &tm
)) return 0;
1937 if(!GetTextExtentPointW(hdc
, alphabet
, 52, &sz
)) return 0;
1939 if (lptm
) *lptm
= tm
;
1940 if (height
) *height
= tm
.tmHeight
;
1942 return (sz
.cx
/ 26 + 1) / 2;
1945 /*************************************************************************
1946 * TranslateCharsetInfo [GDI32.@]
1948 * Fills a CHARSETINFO structure for a character set, code page, or
1949 * font. This allows making the correspondance between different labelings
1950 * (character set, Windows, ANSI, and OEM codepages, and Unicode ranges)
1951 * of the same encoding.
1953 * Only one codepage will be set in lpCs->fs. If TCI_SRCFONTSIG is used,
1954 * only one codepage should be set in *lpSrc.
1957 * TRUE on success, FALSE on failure.
1965 TranslateCharsetInfo(
1966 LPDWORD lpSrc
, /* [in]
1967 if flags == TCI_SRCFONTSIG: pointer to fsCsb of a FONTSIGNATURE
1968 if flags == TCI_SRCCHARSET: a character set value
1969 if flags == TCI_SRCCODEPAGE: a code page value
1971 LPCHARSETINFO lpCs
, /* [out] structure to receive charset information */
1972 DWORD flags
/* [in] determines interpretation of lpSrc */)
1977 case TCI_SRCFONTSIG
:
1978 while (index
< MAXTCIINDEX
&& !(*lpSrc
>>index
& 0x0001)) index
++;
1980 case TCI_SRCCODEPAGE
:
1981 while (index
< MAXTCIINDEX
&& PtrToUlong(lpSrc
) != FONT_tci
[index
].ciACP
) index
++;
1983 case TCI_SRCCHARSET
:
1984 while (index
< MAXTCIINDEX
&& PtrToUlong(lpSrc
) != FONT_tci
[index
].ciCharset
) index
++;
1988 LCID lCid
= (LCID
)PtrToUlong(lpSrc
);
1989 LOCALESIGNATURE LocSig
;
1990 INT Ret
= GetLocaleInfoW(lCid
, LOCALE_FONTSIGNATURE
, (LPWSTR
)&LocSig
, 0);
1991 if ( GetLocaleInfoW(lCid
, LOCALE_FONTSIGNATURE
, (LPWSTR
)&LocSig
, Ret
))
1993 while (index
< MAXTCIINDEX
&& !(LocSig
.lsCsbDefault
[0]>>index
& 0x0001)) index
++;
1998 GdiSetLastError(ERROR_INVALID_PARAMETER
);
2001 if (index
>= MAXTCIINDEX
|| FONT_tci
[index
].ciCharset
== DEFAULT_CHARSET
) return FALSE
;
2002 DPRINT("Index %d Charset %u CodePage %u FontSig %lu\n",
2003 index
,FONT_tci
[index
].ciCharset
,FONT_tci
[index
].ciACP
,FONT_tci
[index
].fs
.fsCsb
[0]);
2004 memcpy(lpCs
, &FONT_tci
[index
], sizeof(CHARSETINFO
));
2019 DWORD Ret
= GDI_ERROR
;
2022 if (GDI_HANDLE_GET_TYPE(hDC
) != GDI_OBJECT_TYPE_DC
)
2024 if (GDI_HANDLE_GET_TYPE(hDC
) == GDI_OBJECT_TYPE_METADC
)
2025 return MFDRV_SetMapperFlags( hDC
, flags
);
2028 PLDC pLDC
= Dc_Attr
->pvLDC
;
2031 SetLastError(ERROR_INVALID_HANDLE
);
2034 if (pLDC
->iType
== LDC_EMFLDC
)
2036 return EMFDRV_SetMapperFlags( hDC
, flags
);
2041 if (!GdiGetHandleUserData((HGDIOBJ
) hDC
, GDI_OBJECT_TYPE_DC
, (PVOID
) &Dc_Attr
)) return GDI_ERROR
;
2043 if (NtCurrentTeb()->GdiTebBatch
.HDC
== hDC
)
2045 if (Dc_Attr
->ulDirty_
& DC_FONTTEXT_DIRTY
)
2048 Dc_Attr
->ulDirty_
&= ~(DC_MODE_DIRTY
|DC_FONTTEXT_DIRTY
);
2053 SetLastError(ERROR_INVALID_PARAMETER
);
2056 Ret
= Dc_Attr
->flFontMapper
;
2057 Dc_Attr
->flFontMapper
= flags
;
2071 FONTENUMPROCW FontFunc
,
2076 return NtGdiEnumFonts ( hDC
, lpFaceName
, FontFunc
, lParam
);
2078 return EnumFontFamiliesW( hDC
, lpFaceName
, FontFunc
, lParam
);
2090 FONTENUMPROCA FontFunc
,
2099 Status
= HEAP_strdupA2W ( &lpFaceNameW
, lpFaceName
);
2100 if (!NT_SUCCESS (Status
))
2101 SetLastError (RtlNtStatusToDosError(Status
));
2104 rc
= NtGdiEnumFonts ( hDC
, lpFaceNameW
, FontFunc
, lParam
);
2106 HEAP_free ( lpFaceNameW
);
2110 return EnumFontFamiliesA( hDC
, lpFaceName
, FontFunc
, lParam
);
2114 #define EfdFontFamilies 3
2118 NewEnumFontFamiliesExW(
2120 LPLOGFONTW lpLogfont
,
2121 FONTENUMPROCW lpEnumFontFamExProcW
,
2125 ULONG_PTR idEnum
, cbDataSize
, cbRetSize
;
2126 PENUMFONTDATAW pEfdw
;
2131 /* Open enumeration handle and find out how much memory we need */
2132 idEnum
= NtGdiEnumFontOpen(hDC
,
2136 (lpLogfont
&& lpLogfont
->lfFaceName
[0])? lpLogfont
->lfFaceName
: NULL
,
2137 lpLogfont
? lpLogfont
->lfCharSet
: DEFAULT_CHARSET
,
2143 if (cbDataSize
== 0)
2145 NtGdiEnumFontClose(idEnum
);
2149 /* Allocate memory */
2150 pBuffer
= HeapAlloc(GetProcessHeap(), 0, cbDataSize
);
2151 if (pBuffer
== NULL
)
2153 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2154 NtGdiEnumFontClose(idEnum
);
2158 /* Do the enumeration */
2159 if (!NtGdiEnumFontChunk(hDC
, idEnum
, cbDataSize
, &cbRetSize
, (PVOID
)pBuffer
))
2161 HeapFree(GetProcessHeap(), 0, pBuffer
);
2162 NtGdiEnumFontClose(idEnum
);
2166 /* Get start and end address */
2167 pEfdw
= (PENUMFONTDATAW
)pBuffer
;
2168 pMax
= pBuffer
+ cbDataSize
;
2170 /* Iterate through the structures */
2171 while ((PBYTE
)pEfdw
< pMax
&& ret
)
2173 PNTMW_INTERNAL pNtmwi
= (PNTMW_INTERNAL
)((ULONG_PTR
)pEfdw
+ pEfdw
->ulNtmwiOffset
);
2175 ret
= lpEnumFontFamExProcW((VOID
*)&pEfdw
->elfexdv
.elfEnumLogfontEx
,
2176 (VOID
*)&pNtmwi
->ntmw
,
2180 pEfdw
= (PENUMFONTDATAW
)((ULONG_PTR
)pEfdw
+ pEfdw
->cbSize
);
2183 /* Release the memory and close handle */
2184 HeapFree(GetProcessHeap(), 0, pBuffer
);
2185 NtGdiEnumFontClose(idEnum
);
2195 GdiAddFontResourceW(
2196 LPCWSTR lpszFilename
,
2201 WCHAR lpszBuffer
[MAX_PATH
];
2202 WCHAR lpszAbsPath
[MAX_PATH
];
2203 UNICODE_STRING NtAbsPath
;
2205 /* FIXME: We don't support multiple files passed in lpszFilename
2206 * as L"abcxxxxx.pfm|abcxxxxx.pfb"
2209 /* Does the file exist in CurrentDirectory or in the Absolute Path passed? */
2210 GetCurrentDirectoryW(MAX_PATH
, lpszBuffer
);
2212 if (!SearchPathW(lpszBuffer
, lpszFilename
, NULL
, MAX_PATH
, lpszAbsPath
, NULL
))
2214 /* Nope. Then let's check Fonts folder */
2215 GetWindowsDirectoryW(lpszBuffer
, MAX_PATH
);
2216 StringCbCatW(lpszBuffer
, sizeof(lpszBuffer
), L
"\\Fonts");
2218 if (!SearchPathW(lpszBuffer
, lpszFilename
, NULL
, MAX_PATH
, lpszAbsPath
, NULL
))
2220 DPRINT1("Font not found. The Buffer is: %ls, the FileName is: %S\n", lpszBuffer
, lpszFilename
);
2225 /* We found the font file so: */
2226 if (!RtlDosPathNameToNtPathName_U(lpszAbsPath
, &NtAbsPath
, NULL
, NULL
))
2228 DPRINT1("Can't convert Path! Path: %ls\n", lpszAbsPath
);
2232 /* The Nt call expects a null-terminator included in cwc param. */
2233 ASSERT(NtAbsPath
.Buffer
[NtAbsPath
.Length
/ sizeof(WCHAR
)] == UNICODE_NULL
);
2234 Ret
= NtGdiAddFontResourceW(NtAbsPath
.Buffer
, NtAbsPath
.Length
/ sizeof(WCHAR
) + 1, 1, fl
, 0, pdv
);
2236 RtlFreeUnicodeString(&NtAbsPath
);
2246 AddFontMemResourceEx(
2253 if ( pbFont
&& cbFont
&& pcFonts
)
2255 return NtGdiAddFontMemResourceEx(pbFont
, cbFont
, NULL
, 0, pcFonts
);
2257 SetLastError(ERROR_INVALID_PARAMETER
);
2266 RemoveFontMemResourceEx(HANDLE fh
)
2270 return NtGdiRemoveFontMemResourceEx(fh
);
2272 SetLastError(ERROR_INVALID_PARAMETER
);
2282 AddFontResourceTracking(
2288 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2297 RemoveFontResourceTracking(LPCSTR lpString
,int unknown
)
2300 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2306 CreateScalableFontResourceW(
2308 LPCWSTR lpszFontRes
,
2309 LPCWSTR lpszFontFile
,
2310 LPCWSTR lpszCurrentPath
2317 /* fHidden=1 - only visible for the calling app, read-only, not
2318 * enumerated with EnumFonts/EnumFontFamilies
2319 * lpszCurrentPath can be NULL
2322 /* If the output file already exists, return the ERROR_FILE_EXISTS error as specified in MSDN */
2323 if ((f
= CreateFileW(lpszFontRes
, 0, 0, NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, 0)) != INVALID_HANDLE_VALUE
)
2326 SetLastError(ERROR_FILE_EXISTS
);
2329 return FALSE
; /* create failed */
2337 bInitSystemAndFontsDirectoriesW(LPWSTR
*SystemDir
,LPWSTR
*FontsDir
)
2340 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2349 EudcLoadLinkW(LPCWSTR pBaseFaceName
,LPCWSTR pEudcFontPath
,INT iPriority
,INT iFontLinkType
)
2352 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2361 EudcUnloadLinkW(LPCWSTR pBaseFaceName
,LPCWSTR pEudcFontPath
)
2364 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2373 GetEUDCTimeStamp(VOID
)
2375 return NtGdiGetEudcTimeStampEx(NULL
,0,TRUE
);
2383 GetEUDCTimeStampExW(LPWSTR lpBaseFaceName
)
2387 if (!lpBaseFaceName
)
2389 retValue
= NtGdiGetEudcTimeStampEx(NULL
,0,FALSE
);
2393 retValue
= NtGdiGetEudcTimeStampEx(lpBaseFaceName
, wcslen(lpBaseFaceName
), FALSE
);
2404 GetFontAssocStatus(HDC hdc
)
2410 retValue
= NtGdiQueryFontAssocInfo(hdc
);
2421 QueryFontAssocStatus(VOID
)
2424 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2433 UnloadNetworkFonts(DWORD unknown
)
2436 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2445 GetFontData(HDC hdc
,
2455 return NtGdiGetFontData(hdc
, dwTable
, dwOffset
, lpvBuffer
, cbData
);
2460 cGetTTFFromFOT(DWORD x1
,DWORD x2
,DWORD x3
, DWORD x4
, DWORD x5
, DWORD x6
, DWORD x7
)
2463 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);