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 || (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)==0 || !BidiAvail)
465 /* Treat the case where no special handling was requested in a fastpath way */
466 /* copy will do if the GCP_REORDER flag is not set */
467 if(lpResults
->lpOutString
)
468 lstrcpynW( lpResults
->lpOutString
, lpString
, nSet
);
470 if(lpResults
->lpOrder
)
472 for(i
= 0; i
< nSet
; i
++)
473 lpResults
->lpOrder
[i
] = i
;
477 BIDI_Reorder( lpString, uCount, dwFlags, WINE_GCPW_FORCE_LTR, lpResults->lpOutString,
478 nSet, lpResults->lpOrder );
481 /* FIXME: Will use the placement chars */
485 for (i
= 0; i
< nSet
; i
++)
487 if (GetCharWidth32W(hdc
, lpString
[i
], lpString
[i
], &c
))
488 lpResults
->lpDx
[i
]= c
;
492 if (lpResults
->lpCaretPos
&& !(dwFlags
& GCP_REORDER
))
496 lpResults
->lpCaretPos
[0] = 0;
497 for (i
= 1; i
< nSet
; i
++)
498 if (GetTextExtentPoint32W(hdc
, &(lpString
[i
- 1]), 1, &size
))
499 lpResults
->lpCaretPos
[i
] = (pos
+= size
.cx
);
502 if (lpResults
->lpGlyphs
)
503 NtGdiGetGlyphIndicesW(hdc
, lpString
, nSet
, lpResults
->lpGlyphs
, 0);
505 if (GetTextExtentPoint32W(hdc
, lpString
, uCount
, &size
))
506 ret
= MAKELONG(size
.cx
, size
.cy
);
513 NewGetCharacterPlacementW(
518 GCP_RESULTSW
*lpResults
,
525 if ( !lpString
|| uCount
<= 0 || (nMaxExtent
< 0 && nMaxExtent
!= -1 ) )
527 SetLastError(ERROR_INVALID_PARAMETER
);
533 if ( GetTextExtentPointW(hdc
, lpString
, uCount
, &Size
) )
535 return MAKELONG(Size
.cx
, Size
.cy
);
541 if ( nSet
> lpResults
->nGlyphs
)
542 nSet
= lpResults
->nGlyphs
;
544 return NtGdiGetCharacterPlacementW( hdc
,
558 GetCharABCWidthsFloatW(HDC hdc
,
563 DPRINT("GetCharABCWidthsFloatW\n");
564 if ((!abcF
) || (FirstChar
> LastChar
))
566 SetLastError(ERROR_INVALID_PARAMETER
);
569 return NtGdiGetCharABCWidthsW( hdc
,
571 (ULONG
)(LastChar
- FirstChar
+ 1),
583 GetCharWidthFloatW(HDC hdc
,
588 DPRINT("GetCharWidthsFloatW\n");
589 if ((!pxBuffer
) || (iFirstChar
> iLastChar
))
591 SetLastError(ERROR_INVALID_PARAMETER
);
594 return NtGdiGetCharWidthW( hdc
,
596 (ULONG
)(iLastChar
- iFirstChar
+ 1),
608 GetCharWidthW(HDC hdc
,
613 DPRINT("GetCharWidthsW\n");
614 if ((!lpBuffer
) || (iFirstChar
> iLastChar
))
616 SetLastError(ERROR_INVALID_PARAMETER
);
619 return NtGdiGetCharWidthW( hdc
,
621 (ULONG
)(iLastChar
- iFirstChar
+ 1),
633 GetCharWidth32W(HDC hdc
,
638 DPRINT("GetCharWidths32W\n");
639 if ((!lpBuffer
) || (iFirstChar
> iLastChar
))
641 SetLastError(ERROR_INVALID_PARAMETER
);
644 return NtGdiGetCharWidthW( hdc
,
646 (ULONG
)(iLastChar
- iFirstChar
+ 1),
648 GCW_NOFLOAT
|GCW_WIN32
,
659 GetCharABCWidthsW(HDC hdc
,
664 DPRINT("GetCharABCWidthsW\n");
665 if ((!lpabc
) || (FirstChar
> LastChar
))
667 SetLastError(ERROR_INVALID_PARAMETER
);
670 return NtGdiGetCharABCWidthsW( hdc
,
672 (ULONG
)(LastChar
- FirstChar
+ 1),
695 DPRINT("GetCharWidthsA\n");
697 str
= FONT_GetCharsByRangeA(hdc
, iFirstChar
, iLastChar
, &count
);
701 wstr
= FONT_mbtowc(hdc
, str
, count
+1, &wlen
, NULL
);
704 HeapFree(GetProcessHeap(), 0, str
);
708 ret
= NtGdiGetCharWidthW( hdc
,
715 HeapFree(GetProcessHeap(), 0, str
);
716 HeapFree(GetProcessHeap(), 0, wstr
);
738 DPRINT("GetCharWidths32A\n");
740 str
= FONT_GetCharsByRangeA(hdc
, iFirstChar
, iLastChar
, &count
);
744 wstr
= FONT_mbtowc(hdc
, str
, count
+1, &wlen
, NULL
);
747 HeapFree(GetProcessHeap(), 0, str
);
751 ret
= NtGdiGetCharWidthW( hdc
,
755 GCW_NOFLOAT
|GCW_WIN32
,
758 HeapFree(GetProcessHeap(), 0, str
);
759 HeapFree(GetProcessHeap(), 0, wstr
);
781 DPRINT("GetCharWidthsFloatA\n");
783 str
= FONT_GetCharsByRangeA(hdc
, iFirstChar
, iLastChar
, &count
);
787 wstr
= FONT_mbtowc(hdc
, str
, count
+1, &wlen
, NULL
);
790 HeapFree(GetProcessHeap(), 0, str
);
793 ret
= NtGdiGetCharWidthW( hdc
, wstr
[0], (ULONG
) count
, (PWCHAR
) wstr
, 0, (PVOID
) pxBuffer
);
795 HeapFree(GetProcessHeap(), 0, str
);
796 HeapFree(GetProcessHeap(), 0, wstr
);
818 DPRINT("GetCharABCWidthsA\n");
820 str
= FONT_GetCharsByRangeA(hdc
, iFirstChar
, iLastChar
, &count
);
824 wstr
= FONT_mbtowc(hdc
, str
, count
+1, &wlen
, NULL
);
827 HeapFree(GetProcessHeap(), 0, str
);
831 ret
= NtGdiGetCharABCWidthsW( hdc
,
838 HeapFree(GetProcessHeap(), 0, str
);
839 HeapFree(GetProcessHeap(), 0, wstr
);
849 GetCharABCWidthsFloatA(
861 DPRINT("GetCharABCWidthsFloatA\n");
863 str
= FONT_GetCharsByRangeA(hdc
, iFirstChar
, iLastChar
, &count
);
867 wstr
= FONT_mbtowc( hdc
, str
, count
+1, &wlen
, NULL
);
870 HeapFree( GetProcessHeap(), 0, str
);
873 ret
= NtGdiGetCharABCWidthsW( hdc
,wstr
[0],(ULONG
)count
, (PWCHAR
)wstr
, 0, (PVOID
)lpABCF
);
875 HeapFree( GetProcessHeap(), 0, str
);
876 HeapFree( GetProcessHeap(), 0, wstr
);
886 GetCharABCWidthsI(HDC hdc
,
892 DPRINT("GetCharABCWidthsI\n");
893 return NtGdiGetCharABCWidthsW( hdc
,
897 GCABCW_NOFLOAT
|GCABCW_INDICES
,
906 GetCharWidthI(HDC hdc
,
913 DPRINT("GetCharWidthsI\n");
914 if (!lpBuffer
|| (!pgi
&& (giFirst
== MAXUSHORT
))) // Cannot be at max.
916 SetLastError(ERROR_INVALID_PARAMETER
);
919 if (!cgi
) return TRUE
;
920 return NtGdiGetCharWidthW( hdc
,
924 GCW_INDICES
|GCW_NOFLOAT
|GCW_WIN32
,
937 DWORD Gcp
= 0, Ret
= 0;
940 Ret
= NtGdiGetTextCharsetInfo(hDc
, NULL
, 0);
941 if ((Ret
== ARABIC_CHARSET
) || (Ret
== HEBREW_CHARSET
))
942 Ret
= (GCP_KASHIDA
|GCP_DIACRITIC
|GCP_LIGATE
|GCP_GLYPHSHAPE
|GCP_REORDER
);
944 Gcp
= GetDCDWord(hDc
, GdiGetFontLanguageInfo
, GCP_ERROR
);
945 if ( Gcp
== GCP_ERROR
)
969 lpstrW
= FONT_mbtowc(hdc
, lpstr
, count
, &countW
, NULL
);
974 Ret
= NtGdiGetGlyphIndicesW(hdc
, lpstrW
, countW
, pgi
, flags
);
975 HeapFree(GetProcessHeap(), 0, lpstrW
);
998 DPRINT("GetGlyphOutlineA uChar %x\n", uChar
);
999 if (!lpgm
|| !lpmat2
) return GDI_ERROR
;
1000 if(!(uFormat
& GGO_GLYPH_INDEX
))
1004 if(uChar
> 0xff) /* but, 2 bytes character only */
1007 mbchs
[0] = (uChar
& 0xff00) >> 8;
1008 mbchs
[1] = (uChar
& 0xff);
1013 mbchs
[0] = (uChar
& 0xff);
1015 p
= FONT_mbtowc(hdc
, mbchs
, len
, NULL
, NULL
);
1022 ret
= NtGdiGetGlyphOutline(hdc
, c
, uFormat
, lpgm
, cbBuffer
, lpvBuffer
, (CONST LPMAT2
)lpmat2
, TRUE
);
1023 HeapFree(GetProcessHeap(), 0, p
);
1037 LPGLYPHMETRICS lpgm
,
1043 DPRINT("GetGlyphOutlineW uChar %x\n", uChar
);
1044 if (!lpgm
|| !lpmat2
) return GDI_ERROR
;
1045 if (!lpvBuffer
) cbBuffer
= 0;
1046 return NtGdiGetGlyphOutline ( hdc
, uChar
, uFormat
, lpgm
, cbBuffer
, lpvBuffer
, (CONST LPMAT2
)lpmat2
, TRUE
);
1065 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1074 GetOutlineTextMetricsA(
1077 LPOUTLINETEXTMETRICA lpOTM
1080 char buf
[512], *ptr
;
1082 OUTLINETEXTMETRICW
*lpOTMW
= (OUTLINETEXTMETRICW
*)buf
;
1083 OUTLINETEXTMETRICA
*output
= lpOTM
;
1086 if((ret
= GetOutlineTextMetricsW(hdc
, 0, NULL
)) == 0)
1088 if(ret
> sizeof(buf
))
1090 lpOTMW
= HeapAlloc(GetProcessHeap(), 0, ret
);
1096 GetOutlineTextMetricsW(hdc
, ret
, lpOTMW
);
1098 needed
= sizeof(OUTLINETEXTMETRICA
);
1099 if(lpOTMW
->otmpFamilyName
)
1100 needed
+= WideCharToMultiByte(CP_ACP
, 0,
1101 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpFamilyName
), -1,
1102 NULL
, 0, NULL
, NULL
);
1103 if(lpOTMW
->otmpFaceName
)
1104 needed
+= WideCharToMultiByte(CP_ACP
, 0,
1105 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpFaceName
), -1,
1106 NULL
, 0, NULL
, NULL
);
1107 if(lpOTMW
->otmpStyleName
)
1108 needed
+= WideCharToMultiByte(CP_ACP
, 0,
1109 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpStyleName
), -1,
1110 NULL
, 0, NULL
, NULL
);
1111 if(lpOTMW
->otmpFullName
)
1112 needed
+= WideCharToMultiByte(CP_ACP
, 0,
1113 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpFullName
), -1,
1114 NULL
, 0, NULL
, NULL
);
1122 DPRINT("needed = %u\n", needed
);
1125 /* Since the supplied buffer isn't big enough, we'll alloc one
1126 that is and memcpy the first cbData bytes into the lpOTM at
1128 output
= HeapAlloc(GetProcessHeap(), 0, needed
);
1135 ret
= output
->otmSize
= min(needed
, cbData
);
1136 FONT_TextMetricWToA( &lpOTMW
->otmTextMetrics
, &output
->otmTextMetrics
);
1137 output
->otmFiller
= 0;
1138 output
->otmPanoseNumber
= lpOTMW
->otmPanoseNumber
;
1139 output
->otmfsSelection
= lpOTMW
->otmfsSelection
;
1140 output
->otmfsType
= lpOTMW
->otmfsType
;
1141 output
->otmsCharSlopeRise
= lpOTMW
->otmsCharSlopeRise
;
1142 output
->otmsCharSlopeRun
= lpOTMW
->otmsCharSlopeRun
;
1143 output
->otmItalicAngle
= lpOTMW
->otmItalicAngle
;
1144 output
->otmEMSquare
= lpOTMW
->otmEMSquare
;
1145 output
->otmAscent
= lpOTMW
->otmAscent
;
1146 output
->otmDescent
= lpOTMW
->otmDescent
;
1147 output
->otmLineGap
= lpOTMW
->otmLineGap
;
1148 output
->otmsCapEmHeight
= lpOTMW
->otmsCapEmHeight
;
1149 output
->otmsXHeight
= lpOTMW
->otmsXHeight
;
1150 output
->otmrcFontBox
= lpOTMW
->otmrcFontBox
;
1151 output
->otmMacAscent
= lpOTMW
->otmMacAscent
;
1152 output
->otmMacDescent
= lpOTMW
->otmMacDescent
;
1153 output
->otmMacLineGap
= lpOTMW
->otmMacLineGap
;
1154 output
->otmusMinimumPPEM
= lpOTMW
->otmusMinimumPPEM
;
1155 output
->otmptSubscriptSize
= lpOTMW
->otmptSubscriptSize
;
1156 output
->otmptSubscriptOffset
= lpOTMW
->otmptSubscriptOffset
;
1157 output
->otmptSuperscriptSize
= lpOTMW
->otmptSuperscriptSize
;
1158 output
->otmptSuperscriptOffset
= lpOTMW
->otmptSuperscriptOffset
;
1159 output
->otmsStrikeoutSize
= lpOTMW
->otmsStrikeoutSize
;
1160 output
->otmsStrikeoutPosition
= lpOTMW
->otmsStrikeoutPosition
;
1161 output
->otmsUnderscoreSize
= lpOTMW
->otmsUnderscoreSize
;
1162 output
->otmsUnderscorePosition
= lpOTMW
->otmsUnderscorePosition
;
1165 ptr
= (char*)(output
+ 1);
1166 left
= needed
- sizeof(*output
);
1168 if(lpOTMW
->otmpFamilyName
)
1170 output
->otmpFamilyName
= (LPSTR
)(ptr
- (char*)output
);
1171 len
= WideCharToMultiByte(CP_ACP
, 0,
1172 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpFamilyName
), -1,
1173 ptr
, left
, NULL
, NULL
);
1178 output
->otmpFamilyName
= 0;
1180 if(lpOTMW
->otmpFaceName
)
1182 output
->otmpFaceName
= (LPSTR
)(ptr
- (char*)output
);
1183 len
= WideCharToMultiByte(CP_ACP
, 0,
1184 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpFaceName
), -1,
1185 ptr
, left
, NULL
, NULL
);
1190 output
->otmpFaceName
= 0;
1192 if(lpOTMW
->otmpStyleName
)
1194 output
->otmpStyleName
= (LPSTR
)(ptr
- (char*)output
);
1195 len
= WideCharToMultiByte(CP_ACP
, 0,
1196 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpStyleName
), -1,
1197 ptr
, left
, NULL
, NULL
);
1202 output
->otmpStyleName
= 0;
1204 if(lpOTMW
->otmpFullName
)
1206 output
->otmpFullName
= (LPSTR
)(ptr
- (char*)output
);
1207 len
= WideCharToMultiByte(CP_ACP
, 0,
1208 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpFullName
), -1,
1209 ptr
, left
, NULL
, NULL
);
1213 output
->otmpFullName
= 0;
1219 memcpy(lpOTM
, output
, cbData
);
1220 HeapFree(GetProcessHeap(), 0, output
);
1222 /* check if the string offsets really fit into the provided size */
1223 /* FIXME: should we check string length as well? */
1224 if ((UINT_PTR
)lpOTM
->otmpFamilyName
>= lpOTM
->otmSize
)
1225 lpOTM
->otmpFamilyName
= 0; /* doesn't fit */
1227 if ((UINT_PTR
)lpOTM
->otmpFaceName
>= lpOTM
->otmSize
)
1228 lpOTM
->otmpFaceName
= 0; /* doesn't fit */
1230 if ((UINT_PTR
)lpOTM
->otmpStyleName
>= lpOTM
->otmSize
)
1231 lpOTM
->otmpStyleName
= 0; /* doesn't fit */
1233 if ((UINT_PTR
)lpOTM
->otmpFullName
>= lpOTM
->otmSize
)
1234 lpOTM
->otmpFullName
= 0; /* doesn't fit */
1238 if(lpOTMW
!= (OUTLINETEXTMETRICW
*)buf
)
1239 HeapFree(GetProcessHeap(), 0, lpOTMW
);
1244 /* Performs a device to world transformation on the specified size (which
1245 * is in integer format).
1247 static inline INT
INTERNAL_YDSTOWS(XFORM
*xForm
, INT height
)
1251 /* Perform operation with floating point */
1252 floatHeight
= (double)height
* xForm
->eM22
;
1253 /* Round to integers */
1254 return GDI_ROUND(floatHeight
);
1257 /* scale width and height but don't mirror them */
1258 static inline INT
width_to_LP( XFORM
*xForm
, INT width
)
1260 return GDI_ROUND( (double)width
* fabs( xForm
->eM11
));
1263 static inline INT
height_to_LP( XFORM
*xForm
, INT height
)
1265 return GDI_ROUND( (double)height
* fabs( xForm
->eM22
));
1273 GetOutlineTextMetricsW(
1276 LPOUTLINETEXTMETRICW lpOTM
1279 TMDIFF Tmd
; // Should not be zero.
1280 UINT Size
, AvailableSize
= 0, StringSize
;
1282 OUTLINETEXTMETRICW
* LocalOTM
;
1286 /* Get the structure */
1287 Size
= NtGdiGetOutlineTextMetricsInternalW(hdc
, 0, NULL
, &Tmd
);
1290 if (!lpOTM
|| (cbData
< sizeof(*lpOTM
)))
1293 LocalOTM
= HeapAlloc(GetProcessHeap(), 0, Size
);
1294 LocalOTM
->otmSize
= Size
;
1295 Size
= NtGdiGetOutlineTextMetricsInternalW(hdc
, Size
, LocalOTM
, &Tmd
);
1298 HeapFree(GetProcessHeap(), 0, LocalOTM
);
1302 if (!NtGdiGetTransform(hdc
, GdiDeviceSpaceToWorldSpace
, &DevToWorld
))
1304 DPRINT1("NtGdiGetTransform failed!\n");
1305 HeapFree(GetProcessHeap(), 0, LocalOTM
);
1306 SetLastError(ERROR_INVALID_HANDLE
);
1310 /* Fill in DC specific data */
1311 LocalOTM
->otmTextMetrics
.tmDigitizedAspectX
= GetDeviceCaps(hdc
, LOGPIXELSX
);
1312 LocalOTM
->otmTextMetrics
.tmDigitizedAspectY
= GetDeviceCaps(hdc
, LOGPIXELSY
);
1313 LocalOTM
->otmTextMetrics
.tmHeight
= height_to_LP( &DevToWorld
, LocalOTM
->otmTextMetrics
.tmHeight
);
1314 LocalOTM
->otmTextMetrics
.tmAscent
= height_to_LP( &DevToWorld
, LocalOTM
->otmTextMetrics
.tmAscent
);
1315 LocalOTM
->otmTextMetrics
.tmDescent
= height_to_LP( &DevToWorld
, LocalOTM
->otmTextMetrics
.tmDescent
);
1316 LocalOTM
->otmTextMetrics
.tmInternalLeading
= height_to_LP( &DevToWorld
, LocalOTM
->otmTextMetrics
.tmInternalLeading
);
1317 LocalOTM
->otmTextMetrics
.tmExternalLeading
= height_to_LP( &DevToWorld
, LocalOTM
->otmTextMetrics
.tmExternalLeading
);
1318 LocalOTM
->otmTextMetrics
.tmAveCharWidth
= width_to_LP( &DevToWorld
, LocalOTM
->otmTextMetrics
.tmAveCharWidth
);
1319 LocalOTM
->otmTextMetrics
.tmMaxCharWidth
= width_to_LP( &DevToWorld
, LocalOTM
->otmTextMetrics
.tmMaxCharWidth
);
1320 LocalOTM
->otmTextMetrics
.tmOverhang
= width_to_LP( &DevToWorld
, LocalOTM
->otmTextMetrics
.tmOverhang
);
1321 LocalOTM
->otmAscent
= height_to_LP( &DevToWorld
, LocalOTM
->otmAscent
);
1322 LocalOTM
->otmDescent
= height_to_LP( &DevToWorld
, LocalOTM
->otmDescent
);
1323 LocalOTM
->otmLineGap
= abs(INTERNAL_YDSTOWS(&DevToWorld
,LocalOTM
->otmLineGap
));
1324 LocalOTM
->otmsCapEmHeight
= abs(INTERNAL_YDSTOWS(&DevToWorld
,LocalOTM
->otmsCapEmHeight
));
1325 LocalOTM
->otmsXHeight
= abs(INTERNAL_YDSTOWS(&DevToWorld
,LocalOTM
->otmsXHeight
));
1326 LocalOTM
->otmrcFontBox
.top
= height_to_LP( &DevToWorld
, LocalOTM
->otmrcFontBox
.top
);
1327 LocalOTM
->otmrcFontBox
.bottom
= height_to_LP( &DevToWorld
, LocalOTM
->otmrcFontBox
.bottom
);
1328 LocalOTM
->otmrcFontBox
.left
= width_to_LP( &DevToWorld
, LocalOTM
->otmrcFontBox
.left
);
1329 LocalOTM
->otmrcFontBox
.right
= width_to_LP( &DevToWorld
, LocalOTM
->otmrcFontBox
.right
);
1330 LocalOTM
->otmMacAscent
= height_to_LP( &DevToWorld
, LocalOTM
->otmMacAscent
);
1331 LocalOTM
->otmMacDescent
= height_to_LP( &DevToWorld
, LocalOTM
->otmMacDescent
);
1332 LocalOTM
->otmMacLineGap
= abs(INTERNAL_YDSTOWS(&DevToWorld
,LocalOTM
->otmMacLineGap
));
1333 LocalOTM
->otmptSubscriptSize
.x
= width_to_LP( &DevToWorld
, LocalOTM
->otmptSubscriptSize
.x
);
1334 LocalOTM
->otmptSubscriptSize
.y
= height_to_LP( &DevToWorld
, LocalOTM
->otmptSubscriptSize
.y
);
1335 LocalOTM
->otmptSubscriptOffset
.x
= width_to_LP( &DevToWorld
, LocalOTM
->otmptSubscriptOffset
.x
);
1336 LocalOTM
->otmptSubscriptOffset
.y
= height_to_LP( &DevToWorld
, LocalOTM
->otmptSubscriptOffset
.y
);
1337 LocalOTM
->otmptSuperscriptSize
.x
= width_to_LP( &DevToWorld
, LocalOTM
->otmptSuperscriptSize
.x
);
1338 LocalOTM
->otmptSuperscriptSize
.y
= height_to_LP( &DevToWorld
, LocalOTM
->otmptSuperscriptSize
.y
);
1339 LocalOTM
->otmptSuperscriptOffset
.x
= width_to_LP( &DevToWorld
, LocalOTM
->otmptSuperscriptOffset
.x
);
1340 LocalOTM
->otmptSuperscriptOffset
.y
= height_to_LP( &DevToWorld
, LocalOTM
->otmptSuperscriptOffset
.y
);
1341 LocalOTM
->otmsStrikeoutSize
= abs(INTERNAL_YDSTOWS(&DevToWorld
,LocalOTM
->otmsStrikeoutSize
));
1342 LocalOTM
->otmsStrikeoutPosition
= height_to_LP( &DevToWorld
, LocalOTM
->otmsStrikeoutPosition
);
1343 LocalOTM
->otmsUnderscoreSize
= height_to_LP( &DevToWorld
, LocalOTM
->otmsUnderscoreSize
);
1344 LocalOTM
->otmsUnderscorePosition
= height_to_LP( &DevToWorld
, LocalOTM
->otmsUnderscorePosition
);
1346 /* Copy what we can */
1347 CopyMemory(lpOTM
, LocalOTM
, min(Size
, cbData
));
1349 lpOTM
->otmpFamilyName
= NULL
;
1350 lpOTM
->otmpFaceName
= NULL
;
1351 lpOTM
->otmpStyleName
= NULL
;
1352 lpOTM
->otmpFullName
= NULL
;
1354 Size
= sizeof(*lpOTM
);
1355 AvailableSize
= cbData
- Size
;
1356 Ptr
= (BYTE
*)lpOTM
+ sizeof(*lpOTM
);
1358 /* Fix string values up */
1359 if (LocalOTM
->otmpFamilyName
)
1361 Str
= (WCHAR
*)((char*)LocalOTM
+ (ptrdiff_t)LocalOTM
->otmpFamilyName
);
1362 StringSize
= (wcslen(Str
) + 1) * sizeof(WCHAR
);
1363 if (AvailableSize
>= StringSize
)
1365 CopyMemory(Ptr
, Str
, StringSize
);
1366 lpOTM
->otmpFamilyName
= (PSTR
)(Ptr
- (BYTE
*)lpOTM
);
1368 AvailableSize
-= StringSize
;
1373 if (LocalOTM
->otmpFaceName
)
1375 Str
= (WCHAR
*)((char*)LocalOTM
+ (ptrdiff_t)LocalOTM
->otmpFaceName
);
1376 StringSize
= (wcslen(Str
) + 1) * sizeof(WCHAR
);
1377 if (AvailableSize
>= StringSize
)
1379 CopyMemory(Ptr
, Str
, StringSize
);
1380 lpOTM
->otmpFaceName
= (PSTR
)(Ptr
- (BYTE
*)lpOTM
);
1382 AvailableSize
-= StringSize
;
1387 if (LocalOTM
->otmpStyleName
)
1389 Str
= (WCHAR
*)((char*)LocalOTM
+ (ptrdiff_t)LocalOTM
->otmpStyleName
);
1390 StringSize
= (wcslen(Str
) + 1) * sizeof(WCHAR
);
1391 if (AvailableSize
>= StringSize
)
1393 CopyMemory(Ptr
, Str
, StringSize
);
1394 lpOTM
->otmpStyleName
= (PSTR
)(Ptr
- (BYTE
*)lpOTM
);
1396 AvailableSize
-= StringSize
;
1401 if (LocalOTM
->otmpFullName
)
1403 Str
= (WCHAR
*)((char*)LocalOTM
+ (ptrdiff_t)LocalOTM
->otmpFullName
);
1404 StringSize
= (wcslen(Str
) + 1) * sizeof(WCHAR
);
1405 if (AvailableSize
>= StringSize
)
1407 CopyMemory(Ptr
, Str
, StringSize
);
1408 lpOTM
->otmpFullName
= (PSTR
)(Ptr
- (BYTE
*)lpOTM
);
1410 AvailableSize
-= StringSize
;
1415 lpOTM
->otmSize
= Size
;
1417 HeapFree(GetProcessHeap(), 0, LocalOTM
);
1427 GetKerningPairsW(HDC hdc
,
1429 LPKERNINGPAIR pkpDst
)
1431 if ((cPairs
!= 0) || (pkpDst
== 0))
1433 return NtGdiGetKerningPairs(hdc
,cPairs
,pkpDst
);
1437 SetLastError(ERROR_INVALID_PARAMETER
);
1447 GetKerningPairsA( HDC hDC
,
1449 LPKERNINGPAIR kern_pairA
)
1454 DWORD i
, total_kern_pairs
, kern_pairs_copied
= 0;
1455 KERNINGPAIR
*kern_pairW
;
1457 if (!cPairs
&& kern_pairA
)
1459 SetLastError(ERROR_INVALID_PARAMETER
);
1463 charset
= GetTextCharset(hDC
);
1464 if (!TranslateCharsetInfo(ULongToPtr(charset
), &csi
, TCI_SRCCHARSET
))
1466 DPRINT1("Can't find codepage for charset %d\n", charset
);
1469 /* GetCPInfo() will fail on CP_SYMBOL, and WideCharToMultiByte is supposed
1470 * to fail on an invalid character for CP_SYMBOL.
1472 cpi
.DefaultChar
[0] = 0;
1473 if (csi
.ciACP
!= CP_SYMBOL
&& !GetCPInfo(csi
.ciACP
, &cpi
))
1475 DPRINT1("Can't find codepage %u info\n", csi
.ciACP
);
1478 DPRINT("charset %d => codepage %u\n", charset
, csi
.ciACP
);
1480 total_kern_pairs
= NtGdiGetKerningPairs(hDC
, 0, NULL
);
1481 if (!total_kern_pairs
) return 0;
1483 if (!cPairs
&& !kern_pairA
) return total_kern_pairs
;
1485 kern_pairW
= HeapAlloc(GetProcessHeap(), 0, total_kern_pairs
* sizeof(*kern_pairW
));
1486 if (kern_pairW
== NULL
)
1490 GetKerningPairsW(hDC
, total_kern_pairs
, kern_pairW
);
1492 for (i
= 0; i
< total_kern_pairs
; i
++)
1496 if (!WideCharToMultiByte(csi
.ciACP
, 0, &kern_pairW
[i
].wFirst
, 1, &first
, 1, NULL
, NULL
))
1499 if (!WideCharToMultiByte(csi
.ciACP
, 0, &kern_pairW
[i
].wSecond
, 1, &second
, 1, NULL
, NULL
))
1502 if (first
== cpi
.DefaultChar
[0] || second
== cpi
.DefaultChar
[0])
1507 if (kern_pairs_copied
>= cPairs
) break;
1509 kern_pairA
->wFirst
= (BYTE
)first
;
1510 kern_pairA
->wSecond
= (BYTE
)second
;
1511 kern_pairA
->iKernAmount
= kern_pairW
[i
].iKernAmount
;
1514 kern_pairs_copied
++;
1517 HeapFree(GetProcessHeap(), 0, kern_pairW
);
1519 return kern_pairs_copied
;
1529 CreateFontIndirectExA(const ENUMLOGFONTEXDVA
*elfexd
)
1533 ENUMLOGFONTEXDVW Logfont
;
1535 EnumLogFontExW2A( (LPENUMLOGFONTEXA
) elfexd
,
1536 &Logfont
.elfEnumLogfontEx
);
1538 RtlCopyMemory( &Logfont
.elfDesignVector
,
1539 (PVOID
) &elfexd
->elfDesignVector
,
1540 sizeof(DESIGNVECTOR
));
1542 return NtGdiHfontCreate( &Logfont
, 0, 0, 0, NULL
);
1553 CreateFontIndirectExW(const ENUMLOGFONTEXDVW
*elfexd
)
1555 /* Msdn: Note, this function ignores the elfDesignVector member in
1560 return NtGdiHfontCreate((PENUMLOGFONTEXDVW
) elfexd
, 0, 0, 0, NULL
);
1571 CreateFontIndirectA(
1572 CONST LOGFONTA
*lplf
1579 LogFontA2W(&tlf
, lplf
);
1580 return CreateFontIndirectW(&tlf
);
1591 CreateFontIndirectW(
1592 CONST LOGFONTW
*lplf
1597 ENUMLOGFONTEXDVW Logfont
;
1599 RtlCopyMemory( &Logfont
.elfEnumLogfontEx
.elfLogFont
, lplf
, sizeof(LOGFONTW
));
1600 // Need something other than just cleaning memory here.
1601 // Guess? Use caller data to determine the rest.
1602 RtlZeroMemory( &Logfont
.elfEnumLogfontEx
.elfFullName
,
1603 sizeof(Logfont
.elfEnumLogfontEx
.elfFullName
));
1604 RtlZeroMemory( &Logfont
.elfEnumLogfontEx
.elfStyle
,
1605 sizeof(Logfont
.elfEnumLogfontEx
.elfStyle
));
1606 RtlZeroMemory( &Logfont
.elfEnumLogfontEx
.elfScript
,
1607 sizeof(Logfont
.elfEnumLogfontEx
.elfScript
));
1609 Logfont
.elfDesignVector
.dvNumAxes
= 0; // No more than MM_MAX_NUMAXES
1611 RtlZeroMemory( &Logfont
.elfDesignVector
, sizeof(DESIGNVECTOR
));
1613 return CreateFontIndirectExW(&Logfont
);
1634 DWORD fdwOutputPrecision
,
1635 DWORD fdwClipPrecision
,
1637 DWORD fdwPitchAndFamily
,
1641 ANSI_STRING StringA
;
1642 UNICODE_STRING StringU
;
1645 RtlInitAnsiString(&StringA
, (LPSTR
)lpszFace
);
1646 RtlAnsiStringToUnicodeString(&StringU
, &StringA
, TRUE
);
1648 ret
= CreateFontW(nHeight
,
1663 RtlFreeUnicodeString(&StringU
);
1684 DWORD fdwOutputPrecision
,
1685 DWORD fdwClipPrecision
,
1687 DWORD fdwPitchAndFamily
,
1693 logfont
.lfHeight
= nHeight
;
1694 logfont
.lfWidth
= nWidth
;
1695 logfont
.lfEscapement
= nEscapement
;
1696 logfont
.lfOrientation
= nOrientation
;
1697 logfont
.lfWeight
= nWeight
;
1698 logfont
.lfItalic
= (BYTE
)fnItalic
;
1699 logfont
.lfUnderline
= (BYTE
)fdwUnderline
;
1700 logfont
.lfStrikeOut
= (BYTE
)fdwStrikeOut
;
1701 logfont
.lfCharSet
= (BYTE
)fdwCharSet
;
1702 logfont
.lfOutPrecision
= (BYTE
)fdwOutputPrecision
;
1703 logfont
.lfClipPrecision
= (BYTE
)fdwClipPrecision
;
1704 logfont
.lfQuality
= (BYTE
)fdwQuality
;
1705 logfont
.lfPitchAndFamily
= (BYTE
)fdwPitchAndFamily
;
1707 if (NULL
!= lpszFace
)
1709 int Size
= sizeof(logfont
.lfFaceName
) / sizeof(WCHAR
);
1710 wcsncpy((wchar_t *)logfont
.lfFaceName
, lpszFace
, Size
- 1);
1711 /* Be 101% sure to have '\0' at end of string */
1712 logfont
.lfFaceName
[Size
- 1] = '\0';
1716 logfont
.lfFaceName
[0] = L
'\0';
1719 return CreateFontIndirectW(&logfont
);
1728 CreateScalableFontResourceA(
1731 LPCSTR lpszFontFile
,
1732 LPCSTR lpszCurrentPath
1744 AddFontResourceExW ( LPCWSTR lpszFilename
, DWORD fl
, PVOID pvReserved
)
1746 if (fl
& ~(FR_PRIVATE
| FR_NOT_ENUM
))
1748 SetLastError( ERROR_INVALID_PARAMETER
);
1752 return GdiAddFontResourceW(lpszFilename
, fl
,0);
1761 AddFontResourceExA ( LPCSTR lpszFilename
, DWORD fl
, PVOID pvReserved
)
1767 if (fl
& ~(FR_PRIVATE
| FR_NOT_ENUM
))
1769 SetLastError( ERROR_INVALID_PARAMETER
);
1773 Status
= HEAP_strdupA2W ( &FilenameW
, lpszFilename
);
1774 if ( !NT_SUCCESS (Status
) )
1776 SetLastError (RtlNtStatusToDosError(Status
));
1780 rc
= GdiAddFontResourceW ( FilenameW
, fl
, 0 );
1781 HEAP_free ( FilenameW
);
1791 AddFontResourceA ( LPCSTR lpszFilename
)
1797 Status
= HEAP_strdupA2W ( &FilenameW
, lpszFilename
);
1798 if ( !NT_SUCCESS (Status
) )
1800 SetLastError (RtlNtStatusToDosError(Status
));
1804 rc
= GdiAddFontResourceW ( FilenameW
, 0, 0);
1806 HEAP_free ( FilenameW
);
1817 AddFontResourceW ( LPCWSTR lpszFilename
)
1819 return GdiAddFontResourceW ( lpszFilename
, 0, 0 );
1828 RemoveFontResourceW(LPCWSTR lpFileName
)
1830 return RemoveFontResourceExW(lpFileName
,0,0);
1839 RemoveFontResourceA(LPCSTR lpFileName
)
1841 return RemoveFontResourceExA(lpFileName
,0,0);
1849 RemoveFontResourceExA(LPCSTR lpFileName
,
1857 /* FIXME the flags */
1859 /* FIXME NtGdiRemoveFontResource handle flags and pdv */
1861 Status
= HEAP_strdupA2W ( &lpFileNameW
, lpFileName
);
1862 if (!NT_SUCCESS (Status
))
1863 SetLastError (RtlNtStatusToDosError(Status
));
1867 HEAP_free ( lpFileNameW
);
1878 RemoveFontResourceExW(LPCWSTR lpFileName
,
1882 /* FIXME the flags */
1884 /* FIXME NtGdiRemoveFontResource handle flags and pdv */
1885 DPRINT("RemoveFontResourceExW\n");
1890 /***********************************************************************
1891 * GdiGetCharDimensions
1893 * Gets the average width of the characters in the English alphabet.
1896 * hdc [I] Handle to the device context to measure on.
1897 * lptm [O] Pointer to memory to store the text metrics into.
1898 * height [O] On exit, the maximum height of characters in the English alphabet.
1901 * The average width of characters in the English alphabet.
1904 * This function is used by the dialog manager to get the size of a dialog
1905 * unit. It should also be used by other pieces of code that need to know
1906 * the size of a dialog unit in logical units without having access to the
1907 * window handle of the dialog.
1908 * Windows caches the font metrics from this function, but we don't and
1909 * there doesn't appear to be an immediate advantage to do so.
1912 * GetTextExtentPointW, GetTextMetricsW, MapDialogRect.
1914 * Despite most of MSDN insisting that the horizontal base unit is
1915 * tmAveCharWidth it isn't. Knowledge base article Q145994
1916 * "HOWTO: Calculate Dialog Units When Not Using the System Font",
1917 * says that we should take the average of the 52 English upper and lower
1925 GdiGetCharDimensions(HDC hdc
, LPTEXTMETRICW lptm
, LONG
*height
)
1929 static const WCHAR alphabet
[] =
1931 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q',
1932 'r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H',
1933 'I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',0
1936 if(!GetTextMetricsW(hdc
, &tm
)) return 0;
1938 if(!GetTextExtentPointW(hdc
, alphabet
, 52, &sz
)) return 0;
1940 if (lptm
) *lptm
= tm
;
1941 if (height
) *height
= tm
.tmHeight
;
1943 return (sz
.cx
/ 26 + 1) / 2;
1946 /*************************************************************************
1947 * TranslateCharsetInfo [GDI32.@]
1949 * Fills a CHARSETINFO structure for a character set, code page, or
1950 * font. This allows making the correspondance between different labelings
1951 * (character set, Windows, ANSI, and OEM codepages, and Unicode ranges)
1952 * of the same encoding.
1954 * Only one codepage will be set in lpCs->fs. If TCI_SRCFONTSIG is used,
1955 * only one codepage should be set in *lpSrc.
1958 * TRUE on success, FALSE on failure.
1966 TranslateCharsetInfo(
1967 LPDWORD lpSrc
, /* [in]
1968 if flags == TCI_SRCFONTSIG: pointer to fsCsb of a FONTSIGNATURE
1969 if flags == TCI_SRCCHARSET: a character set value
1970 if flags == TCI_SRCCODEPAGE: a code page value
1972 LPCHARSETINFO lpCs
, /* [out] structure to receive charset information */
1973 DWORD flags
/* [in] determines interpretation of lpSrc */)
1978 case TCI_SRCFONTSIG
:
1979 while (index
< MAXTCIINDEX
&& !(*lpSrc
>>index
& 0x0001)) index
++;
1981 case TCI_SRCCODEPAGE
:
1982 while (index
< MAXTCIINDEX
&& PtrToUlong(lpSrc
) != FONT_tci
[index
].ciACP
) index
++;
1984 case TCI_SRCCHARSET
:
1985 while (index
< MAXTCIINDEX
&& PtrToUlong(lpSrc
) != FONT_tci
[index
].ciCharset
) index
++;
1989 LCID lCid
= (LCID
)PtrToUlong(lpSrc
);
1990 LOCALESIGNATURE LocSig
;
1991 INT Ret
= GetLocaleInfoW(lCid
, LOCALE_FONTSIGNATURE
, (LPWSTR
)&LocSig
, 0);
1992 if ( GetLocaleInfoW(lCid
, LOCALE_FONTSIGNATURE
, (LPWSTR
)&LocSig
, Ret
))
1994 while (index
< MAXTCIINDEX
&& !(LocSig
.lsCsbDefault
[0]>>index
& 0x0001)) index
++;
1999 GdiSetLastError(ERROR_INVALID_PARAMETER
);
2002 if (index
>= MAXTCIINDEX
|| FONT_tci
[index
].ciCharset
== DEFAULT_CHARSET
) return FALSE
;
2003 DPRINT("Index %d Charset %u CodePage %u FontSig %lu\n",
2004 index
,FONT_tci
[index
].ciCharset
,FONT_tci
[index
].ciACP
,FONT_tci
[index
].fs
.fsCsb
[0]);
2005 memcpy(lpCs
, &FONT_tci
[index
], sizeof(CHARSETINFO
));
2020 DWORD Ret
= GDI_ERROR
;
2023 if (GDI_HANDLE_GET_TYPE(hDC
) != GDI_OBJECT_TYPE_DC
)
2025 if (GDI_HANDLE_GET_TYPE(hDC
) == GDI_OBJECT_TYPE_METADC
)
2026 return MFDRV_SetMapperFlags( hDC
, flags
);
2029 PLDC pLDC
= Dc_Attr
->pvLDC
;
2032 SetLastError(ERROR_INVALID_HANDLE
);
2035 if (pLDC
->iType
== LDC_EMFLDC
)
2037 return EMFDRV_SetMapperFlags( hDC
, flags
);
2042 if (!GdiGetHandleUserData((HGDIOBJ
) hDC
, GDI_OBJECT_TYPE_DC
, (PVOID
) &Dc_Attr
)) return GDI_ERROR
;
2044 if (NtCurrentTeb()->GdiTebBatch
.HDC
== hDC
)
2046 if (Dc_Attr
->ulDirty_
& DC_FONTTEXT_DIRTY
)
2049 Dc_Attr
->ulDirty_
&= ~(DC_MODE_DIRTY
|DC_FONTTEXT_DIRTY
);
2054 SetLastError(ERROR_INVALID_PARAMETER
);
2057 Ret
= Dc_Attr
->flFontMapper
;
2058 Dc_Attr
->flFontMapper
= flags
;
2072 FONTENUMPROCW FontFunc
,
2077 return NtGdiEnumFonts ( hDC
, lpFaceName
, FontFunc
, lParam
);
2079 return EnumFontFamiliesW( hDC
, lpFaceName
, FontFunc
, lParam
);
2091 FONTENUMPROCA FontFunc
,
2100 Status
= HEAP_strdupA2W ( &lpFaceNameW
, lpFaceName
);
2101 if (!NT_SUCCESS (Status
))
2102 SetLastError (RtlNtStatusToDosError(Status
));
2105 rc
= NtGdiEnumFonts ( hDC
, lpFaceNameW
, FontFunc
, lParam
);
2107 HEAP_free ( lpFaceNameW
);
2111 return EnumFontFamiliesA( hDC
, lpFaceName
, FontFunc
, lParam
);
2115 #define EfdFontFamilies 3
2119 NewEnumFontFamiliesExW(
2121 LPLOGFONTW lpLogfont
,
2122 FONTENUMPROCW lpEnumFontFamExProcW
,
2126 ULONG_PTR idEnum
, cbDataSize
, cbRetSize
;
2127 PENUMFONTDATAW pEfdw
;
2132 /* Open enumeration handle and find out how much memory we need */
2133 idEnum
= NtGdiEnumFontOpen(hDC
,
2137 (lpLogfont
&& lpLogfont
->lfFaceName
[0])? lpLogfont
->lfFaceName
: NULL
,
2138 lpLogfont
? lpLogfont
->lfCharSet
: DEFAULT_CHARSET
,
2144 if (cbDataSize
== 0)
2146 NtGdiEnumFontClose(idEnum
);
2150 /* Allocate memory */
2151 pBuffer
= HeapAlloc(GetProcessHeap(), 0, cbDataSize
);
2152 if (pBuffer
== NULL
)
2154 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2155 NtGdiEnumFontClose(idEnum
);
2159 /* Do the enumeration */
2160 if (!NtGdiEnumFontChunk(hDC
, idEnum
, cbDataSize
, &cbRetSize
, (PVOID
)pBuffer
))
2162 HeapFree(GetProcessHeap(), 0, pBuffer
);
2163 NtGdiEnumFontClose(idEnum
);
2167 /* Get start and end address */
2168 pEfdw
= (PENUMFONTDATAW
)pBuffer
;
2169 pMax
= pBuffer
+ cbDataSize
;
2171 /* Iterate through the structures */
2172 while ((PBYTE
)pEfdw
< pMax
&& ret
)
2174 PNTMW_INTERNAL pNtmwi
= (PNTMW_INTERNAL
)((ULONG_PTR
)pEfdw
+ pEfdw
->ulNtmwiOffset
);
2176 ret
= lpEnumFontFamExProcW((VOID
*)&pEfdw
->elfexdv
.elfEnumLogfontEx
,
2177 (VOID
*)&pNtmwi
->ntmw
,
2181 pEfdw
= (PENUMFONTDATAW
)((ULONG_PTR
)pEfdw
+ pEfdw
->cbSize
);
2184 /* Release the memory and close handle */
2185 HeapFree(GetProcessHeap(), 0, pBuffer
);
2186 NtGdiEnumFontClose(idEnum
);
2196 GdiAddFontResourceW(
2197 LPCWSTR lpszFilename
,
2202 WCHAR lpszBuffer
[MAX_PATH
];
2203 WCHAR lpszAbsPath
[MAX_PATH
];
2204 UNICODE_STRING NtAbsPath
;
2206 /* FIXME: We don't support multiple files passed in lpszFilename
2207 * as L"abcxxxxx.pfm|abcxxxxx.pfb"
2210 /* Does the file exist in CurrentDirectory or in the Absolute Path passed? */
2211 GetCurrentDirectoryW(MAX_PATH
, lpszBuffer
);
2213 if (!SearchPathW(lpszBuffer
, lpszFilename
, NULL
, MAX_PATH
, lpszAbsPath
, NULL
))
2215 /* Nope. Then let's check Fonts folder */
2216 GetWindowsDirectoryW(lpszBuffer
, MAX_PATH
);
2217 StringCbCatW(lpszBuffer
, sizeof(lpszBuffer
), L
"\\Fonts");
2219 if (!SearchPathW(lpszBuffer
, lpszFilename
, NULL
, MAX_PATH
, lpszAbsPath
, NULL
))
2221 DPRINT1("Font not found. The Buffer is: %ls, the FileName is: %S\n", lpszBuffer
, lpszFilename
);
2226 /* We found the font file so: */
2227 if (!RtlDosPathNameToNtPathName_U(lpszAbsPath
, &NtAbsPath
, NULL
, NULL
))
2229 DPRINT1("Can't convert Path! Path: %ls\n", lpszAbsPath
);
2233 /* The Nt call expects a null-terminator included in cwc param. */
2234 ASSERT(NtAbsPath
.Buffer
[NtAbsPath
.Length
/ sizeof(WCHAR
)] == UNICODE_NULL
);
2235 Ret
= NtGdiAddFontResourceW(NtAbsPath
.Buffer
, NtAbsPath
.Length
/ sizeof(WCHAR
) + 1, 1, fl
, 0, pdv
);
2237 RtlFreeUnicodeString(&NtAbsPath
);
2247 AddFontMemResourceEx(
2254 if ( pbFont
&& cbFont
&& pcFonts
)
2256 return NtGdiAddFontMemResourceEx(pbFont
, cbFont
, NULL
, 0, pcFonts
);
2258 SetLastError(ERROR_INVALID_PARAMETER
);
2267 RemoveFontMemResourceEx(HANDLE fh
)
2271 return NtGdiRemoveFontMemResourceEx(fh
);
2273 SetLastError(ERROR_INVALID_PARAMETER
);
2283 AddFontResourceTracking(
2289 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2298 RemoveFontResourceTracking(LPCSTR lpString
,int unknown
)
2301 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2307 CreateScalableFontResourceW(
2309 LPCWSTR lpszFontRes
,
2310 LPCWSTR lpszFontFile
,
2311 LPCWSTR lpszCurrentPath
2318 /* fHidden=1 - only visible for the calling app, read-only, not
2319 * enumerated with EnumFonts/EnumFontFamilies
2320 * lpszCurrentPath can be NULL
2323 /* If the output file already exists, return the ERROR_FILE_EXISTS error as specified in MSDN */
2324 if ((f
= CreateFileW(lpszFontRes
, 0, 0, NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, 0)) != INVALID_HANDLE_VALUE
)
2327 SetLastError(ERROR_FILE_EXISTS
);
2330 return FALSE
; /* create failed */
2338 bInitSystemAndFontsDirectoriesW(LPWSTR
*SystemDir
,LPWSTR
*FontsDir
)
2341 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2350 EudcLoadLinkW(LPCWSTR pBaseFaceName
,LPCWSTR pEudcFontPath
,INT iPriority
,INT iFontLinkType
)
2353 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2362 EudcUnloadLinkW(LPCWSTR pBaseFaceName
,LPCWSTR pEudcFontPath
)
2365 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2374 GetEUDCTimeStamp(VOID
)
2376 return NtGdiGetEudcTimeStampEx(NULL
,0,TRUE
);
2384 GetEUDCTimeStampExW(LPWSTR lpBaseFaceName
)
2388 if (!lpBaseFaceName
)
2390 retValue
= NtGdiGetEudcTimeStampEx(NULL
,0,FALSE
);
2394 retValue
= NtGdiGetEudcTimeStampEx(lpBaseFaceName
, wcslen(lpBaseFaceName
), FALSE
);
2405 GetFontAssocStatus(HDC hdc
)
2411 retValue
= NtGdiQueryFontAssocInfo(hdc
);
2422 QueryFontAssocStatus(VOID
)
2425 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2434 UnloadNetworkFonts(DWORD unknown
)
2437 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2446 GetFontData(HDC hdc
,
2456 return NtGdiGetFontData(hdc
, dwTable
, dwOffset
, lpvBuffer
, cbData
);
2461 cGetTTFFromFOT(DWORD x1
,DWORD x2
,DWORD x3
, DWORD x4
, DWORD x5
, DWORD x6
, DWORD x7
)
2464 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);