2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * FILE: lib/gdi32/object/font.c
17 /* Rounds a floating point number to integer. The world-to-viewport
18 * transformation process is done in floating point internally. This function
19 * is then used to round these coordinates to integer values.
21 static __inline INT
GDI_ROUND(FLOAT val
)
23 return (int)floor(val
+ 0.5);
27 * For TranslateCharsetInfo
29 #define MAXTCIINDEX 32
30 static const CHARSETINFO FONT_tci
[MAXTCIINDEX
] =
33 { ANSI_CHARSET
, 1252, {{0,0,0,0},{FS_LATIN1
,0}} },
34 { EASTEUROPE_CHARSET
, 1250, {{0,0,0,0},{FS_LATIN2
,0}} },
35 { RUSSIAN_CHARSET
, 1251, {{0,0,0,0},{FS_CYRILLIC
,0}} },
36 { GREEK_CHARSET
, 1253, {{0,0,0,0},{FS_GREEK
,0}} },
37 { TURKISH_CHARSET
, 1254, {{0,0,0,0},{FS_TURKISH
,0}} },
38 { HEBREW_CHARSET
, 1255, {{0,0,0,0},{FS_HEBREW
,0}} },
39 { ARABIC_CHARSET
, 1256, {{0,0,0,0},{FS_ARABIC
,0}} },
40 { BALTIC_CHARSET
, 1257, {{0,0,0,0},{FS_BALTIC
,0}} },
41 { VIETNAMESE_CHARSET
, 1258, {{0,0,0,0},{FS_VIETNAMESE
,0}} },
42 /* reserved by ANSI */
43 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
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}} },
51 { THAI_CHARSET
, 874, {{0,0,0,0},{FS_THAI
,0}} },
52 { SHIFTJIS_CHARSET
, 932, {{0,0,0,0},{FS_JISJAPAN
,0}} },
53 { GB2312_CHARSET
, 936, {{0,0,0,0},{FS_CHINESESIMP
,0}} },
54 { HANGEUL_CHARSET
, 949, {{0,0,0,0},{FS_WANSUNG
,0}} },
55 { CHINESEBIG5_CHARSET
, 950, {{0,0,0,0},{FS_CHINESETRAD
,0}} },
56 { JOHAB_CHARSET
, 1361, {{0,0,0,0},{FS_JOHAB
,0}} },
57 /* reserved for alternate ANSI and OEM */
58 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
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 /* reserved for system */
67 { DEFAULT_CHARSET
, 0, {{0,0,0,0},{FS_LATIN1
,0}} },
68 { SYMBOL_CHARSET
, CP_SYMBOL
, {{0,0,0,0},{FS_SYMBOL
,0}} }
71 #define INITIAL_FAMILY_COUNT 64
73 /***********************************************************************
74 * TEXTMETRIC conversion functions.
78 FONT_TextMetricWToA(const TEXTMETRICW
*ptmW
, LPTEXTMETRICA ptmA
)
80 ptmA
->tmHeight
= ptmW
->tmHeight
;
81 ptmA
->tmAscent
= ptmW
->tmAscent
;
82 ptmA
->tmDescent
= ptmW
->tmDescent
;
83 ptmA
->tmInternalLeading
= ptmW
->tmInternalLeading
;
84 ptmA
->tmExternalLeading
= ptmW
->tmExternalLeading
;
85 ptmA
->tmAveCharWidth
= ptmW
->tmAveCharWidth
;
86 ptmA
->tmMaxCharWidth
= ptmW
->tmMaxCharWidth
;
87 ptmA
->tmWeight
= ptmW
->tmWeight
;
88 ptmA
->tmOverhang
= ptmW
->tmOverhang
;
89 ptmA
->tmDigitizedAspectX
= ptmW
->tmDigitizedAspectX
;
90 ptmA
->tmDigitizedAspectY
= ptmW
->tmDigitizedAspectY
;
91 ptmA
->tmFirstChar
= min(ptmW
->tmFirstChar
, 255);
92 if (ptmW
->tmCharSet
== SYMBOL_CHARSET
)
94 ptmA
->tmFirstChar
= 0x1e;
95 ptmA
->tmLastChar
= 0xff; /* win9x behaviour - we need the OS2 table data to calculate correctly */
99 ptmA
->tmFirstChar
= ptmW
->tmDefaultChar
- 1;
100 ptmA
->tmLastChar
= min(ptmW
->tmLastChar
, 0xff);
102 ptmA
->tmDefaultChar
= (CHAR
)ptmW
->tmDefaultChar
;
103 ptmA
->tmBreakChar
= (CHAR
)ptmW
->tmBreakChar
;
104 ptmA
->tmItalic
= ptmW
->tmItalic
;
105 ptmA
->tmUnderlined
= ptmW
->tmUnderlined
;
106 ptmA
->tmStruckOut
= ptmW
->tmStruckOut
;
107 ptmA
->tmPitchAndFamily
= ptmW
->tmPitchAndFamily
;
108 ptmA
->tmCharSet
= ptmW
->tmCharSet
;
111 /***********************************************************************
114 * Returns a Unicode translation of str using the charset of the
115 * currently selected font in hdc. If count is -1 then str is assumed
116 * to be '\0' terminated, otherwise it contains the number of bytes to
117 * convert. If plenW is non-NULL, on return it will point to the
118 * number of WCHARs that have been written. If pCP is non-NULL, on
119 * return it will point to the codepage used in the conversion. The
120 * caller should free the returned LPWSTR from the process heap
123 static LPWSTR
FONT_mbtowc(HDC hdc
, LPCSTR str
, INT count
, INT
*plenW
, UINT
*pCP
)
125 UINT cp
= GdiGetCodePage( hdc
);
129 if(count
== -1) count
= strlen(str
);
130 lenW
= MultiByteToWideChar(cp
, 0, str
, count
, NULL
, 0);
131 strW
= HeapAlloc(GetProcessHeap(), 0, lenW
*sizeof(WCHAR
));
134 MultiByteToWideChar(cp
, 0, str
, count
, strW
, lenW
);
135 DPRINT("mapped %s -> %S\n", str
, strW
);
136 if(plenW
) *plenW
= lenW
;
141 static LPSTR
FONT_GetCharsByRangeA(HDC hdc
, UINT firstChar
, UINT lastChar
, PINT pByteLen
)
143 INT i
, count
= lastChar
- firstChar
+ 1;
150 switch (GdiGetCodePage(hdc
))
157 if (lastChar
> 0xffff)
159 if ((firstChar
^ lastChar
) > 0xff)
168 str
= HeapAlloc(GetProcessHeap(), 0, count
* 2 + 1);
172 for(i
= 0, c
= firstChar
; c
<= lastChar
; i
++, c
++)
175 str
[i
++] = (BYTE
)(c
>> 8);
186 NewTextMetricW2A(NEWTEXTMETRICA
*tma
, NEWTEXTMETRICW
*tmw
)
188 FONT_TextMetricWToA((TEXTMETRICW
*) tmw
, (TEXTMETRICA
*) tma
);
189 tma
->ntmFlags
= tmw
->ntmFlags
;
190 tma
->ntmSizeEM
= tmw
->ntmSizeEM
;
191 tma
->ntmCellHeight
= tmw
->ntmCellHeight
;
192 tma
->ntmAvgWidth
= tmw
->ntmAvgWidth
;
196 NewTextMetricExW2A(NEWTEXTMETRICEXA
*tma
, NEWTEXTMETRICEXW
*tmw
)
198 NewTextMetricW2A(&tma
->ntmTm
, &tmw
->ntmTm
);
199 tma
->ntmFontSig
= tmw
->ntmFontSig
;
203 IntEnumFontFamilies(HDC Dc
, LPLOGFONTW LogFont
, PVOID EnumProc
, LPARAM lParam
,
208 PFONTFAMILYINFO Info
;
211 ENUMLOGFONTEXA EnumLogFontExA
;
212 NEWTEXTMETRICEXA NewTextMetricExA
;
215 Info
= RtlAllocateHeap(GetProcessHeap(), 0,
216 INITIAL_FAMILY_COUNT
* sizeof(FONTFAMILYINFO
));
224 lfW
.lfCharSet
= DEFAULT_CHARSET
;
225 lfW
.lfPitchAndFamily
= 0;
226 lfW
.lfFaceName
[0] = 0;
230 FontFamilyCount
= NtGdiGetFontFamilyInfo(Dc
, LogFont
, Info
, INITIAL_FAMILY_COUNT
);
231 if (FontFamilyCount
< 0)
233 RtlFreeHeap(GetProcessHeap(), 0, Info
);
236 if (INITIAL_FAMILY_COUNT
< FontFamilyCount
)
238 FontFamilySize
= FontFamilyCount
;
239 RtlFreeHeap(GetProcessHeap(), 0, Info
);
240 Info
= RtlAllocateHeap(GetProcessHeap(), 0,
241 FontFamilyCount
* sizeof(FONTFAMILYINFO
));
246 FontFamilyCount
= NtGdiGetFontFamilyInfo(Dc
, LogFont
, Info
, FontFamilySize
);
247 if (FontFamilyCount
< 0 || FontFamilySize
< FontFamilyCount
)
249 RtlFreeHeap(GetProcessHeap(), 0, Info
);
254 for (i
= 0; i
< FontFamilyCount
; i
++)
258 Ret
= ((FONTENUMPROCW
) EnumProc
)(
259 (VOID
*)&Info
[i
].EnumLogFontEx
,
260 (VOID
*)&Info
[i
].NewTextMetricEx
,
261 Info
[i
].FontType
, lParam
);
265 // Could use EnumLogFontExW2A here?
266 LogFontW2A(&EnumLogFontExA
.elfLogFont
, &Info
[i
].EnumLogFontEx
.elfLogFont
);
267 WideCharToMultiByte(CP_THREAD_ACP
, 0, Info
[i
].EnumLogFontEx
.elfFullName
, -1,
268 (LPSTR
)EnumLogFontExA
.elfFullName
, LF_FULLFACESIZE
, NULL
, NULL
);
269 WideCharToMultiByte(CP_THREAD_ACP
, 0, Info
[i
].EnumLogFontEx
.elfStyle
, -1,
270 (LPSTR
)EnumLogFontExA
.elfStyle
, LF_FACESIZE
, NULL
, NULL
);
271 WideCharToMultiByte(CP_THREAD_ACP
, 0, Info
[i
].EnumLogFontEx
.elfScript
, -1,
272 (LPSTR
)EnumLogFontExA
.elfScript
, LF_FACESIZE
, NULL
, NULL
);
273 NewTextMetricExW2A(&NewTextMetricExA
,
274 &Info
[i
].NewTextMetricEx
);
275 Ret
= ((FONTENUMPROCA
) EnumProc
)(
276 (VOID
*)&EnumLogFontExA
,
277 (VOID
*)&NewTextMetricExA
,
278 Info
[i
].FontType
, lParam
);
282 RtlFreeHeap(GetProcessHeap(), 0, Info
);
291 EnumFontFamiliesExW(HDC hdc
, LPLOGFONTW lpLogfont
, FONTENUMPROCW lpEnumFontFamExProc
,
292 LPARAM lParam
, DWORD dwFlags
)
294 return IntEnumFontFamilies(hdc
, lpLogfont
, lpEnumFontFamExProc
, lParam
, TRUE
);
302 EnumFontFamiliesW(HDC hdc
, LPCWSTR lpszFamily
, FONTENUMPROCW lpEnumFontFamProc
,
307 ZeroMemory(&LogFont
, sizeof(LOGFONTW
));
308 LogFont
.lfCharSet
= DEFAULT_CHARSET
;
309 if (NULL
!= lpszFamily
)
311 if (!*lpszFamily
) return 1;
312 lstrcpynW(LogFont
.lfFaceName
, lpszFamily
, LF_FACESIZE
);
315 return IntEnumFontFamilies(hdc
, &LogFont
, lpEnumFontFamProc
, lParam
, TRUE
);
323 EnumFontFamiliesExA (HDC hdc
, LPLOGFONTA lpLogfont
, FONTENUMPROCA lpEnumFontFamExProc
,
324 LPARAM lParam
, DWORD dwFlags
)
326 LOGFONTW LogFontW
, *pLogFontW
;
330 LogFontA2W(&LogFontW
,lpLogfont
);
331 pLogFontW
= &LogFontW
;
333 else pLogFontW
= NULL
;
335 /* no need to convert LogFontW back to lpLogFont b/c it's an [in] parameter only */
336 return IntEnumFontFamilies(hdc
, pLogFontW
, lpEnumFontFamExProc
, lParam
, FALSE
);
344 EnumFontFamiliesA(HDC hdc
, LPCSTR lpszFamily
, FONTENUMPROCA lpEnumFontFamProc
,
349 ZeroMemory(&LogFont
, sizeof(LOGFONTW
));
350 LogFont
.lfCharSet
= DEFAULT_CHARSET
;
351 if (NULL
!= lpszFamily
)
353 if (!*lpszFamily
) return 1;
354 MultiByteToWideChar(CP_THREAD_ACP
, 0, lpszFamily
, -1, LogFont
.lfFaceName
, LF_FACESIZE
);
357 return IntEnumFontFamilies(hdc
, &LogFont
, lpEnumFontFamProc
, lParam
, FALSE
);
366 GetCharacterPlacementA(
371 GCP_RESULTSA
*lpResults
,
376 GCP_RESULTSW resultsW
;
380 if ( !lpString
|| uCount
<= 0 || (nMaxExtent
< 0 && nMaxExtent
!= -1 ) )
382 SetLastError(ERROR_INVALID_PARAMETER
);
385 /* TRACE("%s, %d, %d, 0x%08x\n",
386 debugstr_an(lpString, uCount), uCount, nMaxExtent, dwFlags);
388 /* both structs are equal in size */
389 memcpy(&resultsW
, lpResults
, sizeof(resultsW
));
391 lpStringW
= FONT_mbtowc(hdc
, lpString
, uCount
, &uCountW
, &font_cp
);
392 if (lpStringW
== NULL
)
396 if(lpResults
->lpOutString
)
398 resultsW
.lpOutString
= HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR
)*uCountW
);
399 if (resultsW
.lpOutString
== NULL
)
401 HeapFree(GetProcessHeap(), 0, lpStringW
);
406 ret
= GetCharacterPlacementW(hdc
, lpStringW
, uCountW
, nMaxExtent
, &resultsW
, dwFlags
);
408 lpResults
->nGlyphs
= resultsW
.nGlyphs
;
409 lpResults
->nMaxFit
= resultsW
.nMaxFit
;
411 if(lpResults
->lpOutString
)
413 WideCharToMultiByte(font_cp
, 0, resultsW
.lpOutString
, uCountW
,
414 lpResults
->lpOutString
, uCount
, NULL
, NULL
);
417 HeapFree(GetProcessHeap(), 0, lpStringW
);
418 HeapFree(GetProcessHeap(), 0, resultsW
.lpOutString
);
429 GetCharacterPlacementW(
434 GCP_RESULTSW
*lpResults
,
441 DPRINT("GetCharacterPlacementW\n");
443 if(dwFlags
&(~GCP_REORDER
)) DPRINT("flags 0x%08lx ignored\n", dwFlags
);
444 if(lpResults
->lpClass
) DPRINT("classes not implemented\n");
445 if (lpResults
->lpCaretPos
&& (dwFlags
& GCP_REORDER
))
446 DPRINT("Caret positions for complex scripts not implemented\n");
449 if(nSet
> lpResults
->nGlyphs
)
450 nSet
= lpResults
->nGlyphs
;
452 /* return number of initialized fields */
453 lpResults
->nGlyphs
= nSet
;
455 /*if((dwFlags&GCP_REORDER)==0 || !BidiAvail)
457 /* Treat the case where no special handling was requested in a fastpath way */
458 /* copy will do if the GCP_REORDER flag is not set */
459 if(lpResults
->lpOutString
)
460 lstrcpynW( lpResults
->lpOutString
, lpString
, nSet
);
462 if(lpResults
->lpGlyphs
)
463 lstrcpynW( lpResults
->lpGlyphs
, lpString
, nSet
);
465 if(lpResults
->lpOrder
)
467 for(i
= 0; i
< nSet
; i
++)
468 lpResults
->lpOrder
[i
] = i
;
472 BIDI_Reorder( lpString, uCount, dwFlags, WINE_GCPW_FORCE_LTR, lpResults->lpOutString,
473 nSet, lpResults->lpOrder );
476 /* FIXME: Will use the placement chars */
480 for (i
= 0; i
< nSet
; i
++)
482 if (GetCharWidth32W(hdc
, lpString
[i
], lpString
[i
], &c
))
483 lpResults
->lpDx
[i
]= c
;
487 if (lpResults
->lpCaretPos
&& !(dwFlags
& GCP_REORDER
))
491 lpResults
->lpCaretPos
[0] = 0;
492 for (i
= 1; i
< nSet
; i
++)
493 if (GetTextExtentPoint32W(hdc
, &(lpString
[i
- 1]), 1, &size
))
494 lpResults
->lpCaretPos
[i
] = (pos
+= size
.cx
);
497 /*if(lpResults->lpGlyphs)
498 NtGdiGetGlyphIndicesW(hdc, lpString, nSet, lpResults->lpGlyphs, 0);*/
500 if (GetTextExtentPoint32W(hdc
, lpString
, uCount
, &size
))
501 ret
= MAKELONG(size
.cx
, size
.cy
);
508 NewGetCharacterPlacementW(
513 GCP_RESULTSW
*lpResults
,
520 if ( !lpString
|| uCount
<= 0 || (nMaxExtent
< 0 && nMaxExtent
!= -1 ) )
522 SetLastError(ERROR_INVALID_PARAMETER
);
528 if ( GetTextExtentPointW(hdc
, lpString
, uCount
, &Size
) )
530 return MAKELONG(Size
.cx
, Size
.cy
);
536 if ( nSet
> lpResults
->nGlyphs
)
537 nSet
= lpResults
->nGlyphs
;
539 return NtGdiGetCharacterPlacementW( hdc
,
553 GetCharABCWidthsFloatW(HDC hdc
,
558 DPRINT("GetCharABCWidthsFloatW\n");
559 if ((!abcF
) || (FirstChar
> LastChar
))
561 SetLastError(ERROR_INVALID_PARAMETER
);
564 return NtGdiGetCharABCWidthsW( hdc
,
566 (ULONG
)(LastChar
- FirstChar
+ 1),
578 GetCharWidthFloatW(HDC hdc
,
583 DPRINT("GetCharWidthsFloatW\n");
584 if ((!pxBuffer
) || (iFirstChar
> iLastChar
))
586 SetLastError(ERROR_INVALID_PARAMETER
);
589 return NtGdiGetCharWidthW( hdc
,
591 (ULONG
)(iLastChar
- iFirstChar
+ 1),
603 GetCharWidthW(HDC hdc
,
608 DPRINT("GetCharWidthsW\n");
609 if ((!lpBuffer
) || (iFirstChar
> iLastChar
))
611 SetLastError(ERROR_INVALID_PARAMETER
);
614 return NtGdiGetCharWidthW( hdc
,
616 (ULONG
)(iLastChar
- iFirstChar
+ 1),
628 GetCharWidth32W(HDC hdc
,
633 DPRINT("GetCharWidths32W\n");
634 if ((!lpBuffer
) || (iFirstChar
> iLastChar
))
636 SetLastError(ERROR_INVALID_PARAMETER
);
639 return NtGdiGetCharWidthW( hdc
,
641 (ULONG
)(iLastChar
- iFirstChar
+ 1),
643 GCW_NOFLOAT
|GCW_WIN32
,
654 GetCharABCWidthsW(HDC hdc
,
659 DPRINT("GetCharABCWidthsW\n");
660 if ((!lpabc
) || (FirstChar
> LastChar
))
662 SetLastError(ERROR_INVALID_PARAMETER
);
665 return NtGdiGetCharABCWidthsW( hdc
,
667 (ULONG
)(LastChar
- FirstChar
+ 1),
690 DPRINT("GetCharWidthsA\n");
692 str
= FONT_GetCharsByRangeA(hdc
, iFirstChar
, iLastChar
, &count
);
696 wstr
= FONT_mbtowc(hdc
, str
, count
+1, &wlen
, NULL
);
699 HeapFree(GetProcessHeap(), 0, str
);
703 ret
= NtGdiGetCharWidthW( hdc
,
710 HeapFree(GetProcessHeap(), 0, str
);
711 HeapFree(GetProcessHeap(), 0, wstr
);
733 DPRINT("GetCharWidths32A\n");
735 str
= FONT_GetCharsByRangeA(hdc
, iFirstChar
, iLastChar
, &count
);
739 wstr
= FONT_mbtowc(hdc
, str
, count
+1, &wlen
, NULL
);
742 HeapFree(GetProcessHeap(), 0, str
);
746 ret
= NtGdiGetCharWidthW( hdc
,
750 GCW_NOFLOAT
|GCW_WIN32
,
753 HeapFree(GetProcessHeap(), 0, str
);
754 HeapFree(GetProcessHeap(), 0, wstr
);
776 DPRINT("GetCharWidthsFloatA\n");
778 str
= FONT_GetCharsByRangeA(hdc
, iFirstChar
, iLastChar
, &count
);
782 wstr
= FONT_mbtowc(hdc
, str
, count
+1, &wlen
, NULL
);
785 HeapFree(GetProcessHeap(), 0, str
);
788 ret
= NtGdiGetCharWidthW( hdc
, wstr
[0], (ULONG
) count
, (PWCHAR
) wstr
, 0, (PVOID
) pxBuffer
);
790 HeapFree(GetProcessHeap(), 0, str
);
791 HeapFree(GetProcessHeap(), 0, wstr
);
813 DPRINT("GetCharABCWidthsA\n");
815 str
= FONT_GetCharsByRangeA(hdc
, iFirstChar
, iLastChar
, &count
);
819 wstr
= FONT_mbtowc(hdc
, str
, count
+1, &wlen
, NULL
);
822 HeapFree(GetProcessHeap(), 0, str
);
826 ret
= NtGdiGetCharABCWidthsW( hdc
,
833 HeapFree(GetProcessHeap(), 0, str
);
834 HeapFree(GetProcessHeap(), 0, wstr
);
844 GetCharABCWidthsFloatA(
856 DPRINT("GetCharABCWidthsFloatA\n");
858 str
= FONT_GetCharsByRangeA(hdc
, iFirstChar
, iLastChar
, &count
);
862 wstr
= FONT_mbtowc( hdc
, str
, count
+1, &wlen
, NULL
);
865 HeapFree( GetProcessHeap(), 0, str
);
868 ret
= NtGdiGetCharABCWidthsW( hdc
,wstr
[0],(ULONG
)count
, (PWCHAR
)wstr
, 0, (PVOID
)lpABCF
);
870 HeapFree( GetProcessHeap(), 0, str
);
871 HeapFree( GetProcessHeap(), 0, wstr
);
881 GetCharABCWidthsI(HDC hdc
,
887 DPRINT("GetCharABCWidthsI\n");
888 return NtGdiGetCharABCWidthsW( hdc
,
892 GCABCW_NOFLOAT
|GCABCW_INDICES
,
901 GetCharWidthI(HDC hdc
,
908 DPRINT("GetCharWidthsI\n");
909 if (!lpBuffer
|| (!pgi
&& (giFirst
== MAXUSHORT
))) // Cannot be at max.
911 SetLastError(ERROR_INVALID_PARAMETER
);
914 if (!cgi
) return TRUE
;
915 return NtGdiGetCharWidthW( hdc
,
919 GCW_INDICES
|GCW_NOFLOAT
|GCW_WIN32
,
932 DWORD Gcp
= 0, Ret
= 0;
935 Ret
= NtGdiGetTextCharsetInfo(hDc
, NULL
, 0);
936 if ((Ret
== ARABIC_CHARSET
) || (Ret
== HEBREW_CHARSET
))
937 Ret
= (GCP_KASHIDA
|GCP_DIACRITIC
|GCP_LIGATE
|GCP_GLYPHSHAPE
|GCP_REORDER
);
939 Gcp
= GetDCDWord(hDc
, GdiGetFontLanguageInfo
, GCP_ERROR
);
940 if ( Gcp
== GCP_ERROR
)
964 lpstrW
= FONT_mbtowc(hdc
, lpstr
, count
, &countW
, NULL
);
969 Ret
= NtGdiGetGlyphIndicesW(hdc
, lpstrW
, countW
, pgi
, flags
);
970 HeapFree(GetProcessHeap(), 0, lpstrW
);
993 DPRINT("GetGlyphOutlineA uChar %x\n", uChar
);
994 if (!lpgm
|| !lpmat2
) return GDI_ERROR
;
995 if(!(uFormat
& GGO_GLYPH_INDEX
))
999 if(uChar
> 0xff) /* but, 2 bytes character only */
1002 mbchs
[0] = (uChar
& 0xff00) >> 8;
1003 mbchs
[1] = (uChar
& 0xff);
1008 mbchs
[0] = (uChar
& 0xff);
1010 p
= FONT_mbtowc(hdc
, mbchs
, len
, NULL
, NULL
);
1015 ret
= NtGdiGetGlyphOutline(hdc
, c
, uFormat
, lpgm
, cbBuffer
, lpvBuffer
, (CONST LPMAT2
)lpmat2
, TRUE
);
1016 HeapFree(GetProcessHeap(), 0, p
);
1030 LPGLYPHMETRICS lpgm
,
1036 DPRINT("GetGlyphOutlineW uChar %x\n", uChar
);
1037 if (!lpgm
|| !lpmat2
) return GDI_ERROR
;
1038 if (!lpvBuffer
) cbBuffer
= 0;
1039 return NtGdiGetGlyphOutline ( hdc
, uChar
, uFormat
, lpgm
, cbBuffer
, lpvBuffer
, (CONST LPMAT2
)lpmat2
, TRUE
);
1048 GetOutlineTextMetricsA(
1051 LPOUTLINETEXTMETRICA lpOTM
1054 char buf
[512], *ptr
;
1056 OUTLINETEXTMETRICW
*lpOTMW
= (OUTLINETEXTMETRICW
*)buf
;
1057 OUTLINETEXTMETRICA
*output
= lpOTM
;
1060 if((ret
= GetOutlineTextMetricsW(hdc
, 0, NULL
)) == 0)
1062 if(ret
> sizeof(buf
))
1064 lpOTMW
= HeapAlloc(GetProcessHeap(), 0, ret
);
1070 GetOutlineTextMetricsW(hdc
, ret
, lpOTMW
);
1072 needed
= sizeof(OUTLINETEXTMETRICA
);
1073 if(lpOTMW
->otmpFamilyName
)
1074 needed
+= WideCharToMultiByte(CP_ACP
, 0,
1075 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpFamilyName
), -1,
1076 NULL
, 0, NULL
, NULL
);
1077 if(lpOTMW
->otmpFaceName
)
1078 needed
+= WideCharToMultiByte(CP_ACP
, 0,
1079 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpFaceName
), -1,
1080 NULL
, 0, NULL
, NULL
);
1081 if(lpOTMW
->otmpStyleName
)
1082 needed
+= WideCharToMultiByte(CP_ACP
, 0,
1083 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpStyleName
), -1,
1084 NULL
, 0, NULL
, NULL
);
1085 if(lpOTMW
->otmpFullName
)
1086 needed
+= WideCharToMultiByte(CP_ACP
, 0,
1087 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpFullName
), -1,
1088 NULL
, 0, NULL
, NULL
);
1096 DPRINT("needed = %u\n", needed
);
1099 /* Since the supplied buffer isn't big enough, we'll alloc one
1100 that is and memcpy the first cbData bytes into the lpOTM at
1102 output
= HeapAlloc(GetProcessHeap(), 0, needed
);
1109 ret
= output
->otmSize
= min(needed
, cbData
);
1110 FONT_TextMetricWToA( &lpOTMW
->otmTextMetrics
, &output
->otmTextMetrics
);
1111 output
->otmFiller
= 0;
1112 output
->otmPanoseNumber
= lpOTMW
->otmPanoseNumber
;
1113 output
->otmfsSelection
= lpOTMW
->otmfsSelection
;
1114 output
->otmfsType
= lpOTMW
->otmfsType
;
1115 output
->otmsCharSlopeRise
= lpOTMW
->otmsCharSlopeRise
;
1116 output
->otmsCharSlopeRun
= lpOTMW
->otmsCharSlopeRun
;
1117 output
->otmItalicAngle
= lpOTMW
->otmItalicAngle
;
1118 output
->otmEMSquare
= lpOTMW
->otmEMSquare
;
1119 output
->otmAscent
= lpOTMW
->otmAscent
;
1120 output
->otmDescent
= lpOTMW
->otmDescent
;
1121 output
->otmLineGap
= lpOTMW
->otmLineGap
;
1122 output
->otmsCapEmHeight
= lpOTMW
->otmsCapEmHeight
;
1123 output
->otmsXHeight
= lpOTMW
->otmsXHeight
;
1124 output
->otmrcFontBox
= lpOTMW
->otmrcFontBox
;
1125 output
->otmMacAscent
= lpOTMW
->otmMacAscent
;
1126 output
->otmMacDescent
= lpOTMW
->otmMacDescent
;
1127 output
->otmMacLineGap
= lpOTMW
->otmMacLineGap
;
1128 output
->otmusMinimumPPEM
= lpOTMW
->otmusMinimumPPEM
;
1129 output
->otmptSubscriptSize
= lpOTMW
->otmptSubscriptSize
;
1130 output
->otmptSubscriptOffset
= lpOTMW
->otmptSubscriptOffset
;
1131 output
->otmptSuperscriptSize
= lpOTMW
->otmptSuperscriptSize
;
1132 output
->otmptSuperscriptOffset
= lpOTMW
->otmptSuperscriptOffset
;
1133 output
->otmsStrikeoutSize
= lpOTMW
->otmsStrikeoutSize
;
1134 output
->otmsStrikeoutPosition
= lpOTMW
->otmsStrikeoutPosition
;
1135 output
->otmsUnderscoreSize
= lpOTMW
->otmsUnderscoreSize
;
1136 output
->otmsUnderscorePosition
= lpOTMW
->otmsUnderscorePosition
;
1139 ptr
= (char*)(output
+ 1);
1140 left
= needed
- sizeof(*output
);
1142 if(lpOTMW
->otmpFamilyName
)
1144 output
->otmpFamilyName
= (LPSTR
)(ptr
- (char*)output
);
1145 len
= WideCharToMultiByte(CP_ACP
, 0,
1146 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpFamilyName
), -1,
1147 ptr
, left
, NULL
, NULL
);
1152 output
->otmpFamilyName
= 0;
1154 if(lpOTMW
->otmpFaceName
)
1156 output
->otmpFaceName
= (LPSTR
)(ptr
- (char*)output
);
1157 len
= WideCharToMultiByte(CP_ACP
, 0,
1158 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpFaceName
), -1,
1159 ptr
, left
, NULL
, NULL
);
1164 output
->otmpFaceName
= 0;
1166 if(lpOTMW
->otmpStyleName
)
1168 output
->otmpStyleName
= (LPSTR
)(ptr
- (char*)output
);
1169 len
= WideCharToMultiByte(CP_ACP
, 0,
1170 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpStyleName
), -1,
1171 ptr
, left
, NULL
, NULL
);
1176 output
->otmpStyleName
= 0;
1178 if(lpOTMW
->otmpFullName
)
1180 output
->otmpFullName
= (LPSTR
)(ptr
- (char*)output
);
1181 len
= WideCharToMultiByte(CP_ACP
, 0,
1182 (WCHAR
*)((char*)lpOTMW
+ (int)lpOTMW
->otmpFullName
), -1,
1183 ptr
, left
, NULL
, NULL
);
1187 output
->otmpFullName
= 0;
1193 memcpy(lpOTM
, output
, cbData
);
1194 HeapFree(GetProcessHeap(), 0, output
);
1196 /* check if the string offsets really fit into the provided size */
1197 /* FIXME: should we check string length as well? */
1198 if ((UINT_PTR
)lpOTM
->otmpFamilyName
>= lpOTM
->otmSize
)
1199 lpOTM
->otmpFamilyName
= 0; /* doesn't fit */
1201 if ((UINT_PTR
)lpOTM
->otmpFaceName
>= lpOTM
->otmSize
)
1202 lpOTM
->otmpFaceName
= 0; /* doesn't fit */
1204 if ((UINT_PTR
)lpOTM
->otmpStyleName
>= lpOTM
->otmSize
)
1205 lpOTM
->otmpStyleName
= 0; /* doesn't fit */
1207 if ((UINT_PTR
)lpOTM
->otmpFullName
>= lpOTM
->otmSize
)
1208 lpOTM
->otmpFullName
= 0; /* doesn't fit */
1212 if(lpOTMW
!= (OUTLINETEXTMETRICW
*)buf
)
1213 HeapFree(GetProcessHeap(), 0, lpOTMW
);
1218 /* Performs a device to world transformation on the specified size (which
1219 * is in integer format).
1221 static inline INT
INTERNAL_YDSTOWS(XFORM
*xForm
, INT height
)
1225 /* Perform operation with floating point */
1226 floatHeight
= (double)height
* xForm
->eM22
;
1227 /* Round to integers */
1228 return GDI_ROUND(floatHeight
);
1231 /* scale width and height but don't mirror them */
1232 static inline INT
width_to_LP( XFORM
*xForm
, INT width
)
1234 return GDI_ROUND( (double)width
* fabs( xForm
->eM11
));
1237 static inline INT
height_to_LP( XFORM
*xForm
, INT height
)
1239 return GDI_ROUND( (double)height
* fabs( xForm
->eM22
));
1247 GetOutlineTextMetricsW(
1250 LPOUTLINETEXTMETRICW lpOTM
1253 TMDIFF Tmd
; // Should not be zero.
1254 UINT Size
, AvailableSize
= 0, StringSize
;
1256 OUTLINETEXTMETRICW
* LocalOTM
;
1260 /* Get the structure */
1261 Size
= NtGdiGetOutlineTextMetricsInternalW(hdc
, 0, NULL
, &Tmd
);
1264 if (!lpOTM
|| (cbData
< sizeof(*lpOTM
)))
1267 LocalOTM
= HeapAlloc(GetProcessHeap(), 0, Size
);
1268 LocalOTM
->otmSize
= Size
;
1269 Size
= NtGdiGetOutlineTextMetricsInternalW(hdc
, Size
, LocalOTM
, &Tmd
);
1272 HeapFree(GetProcessHeap(), 0, LocalOTM
);
1276 if (!NtGdiGetTransform(hdc
, GdiDeviceSpaceToWorldSpace
, &DevToWorld
))
1278 DPRINT1("NtGdiGetTransform failed!\n");
1279 HeapFree(GetProcessHeap(), 0, LocalOTM
);
1280 SetLastError(ERROR_INVALID_HANDLE
);
1284 /* Fill in DC specific data */
1285 LocalOTM
->otmTextMetrics
.tmDigitizedAspectX
= GetDeviceCaps(hdc
, LOGPIXELSX
);
1286 LocalOTM
->otmTextMetrics
.tmDigitizedAspectY
= GetDeviceCaps(hdc
, LOGPIXELSY
);
1287 LocalOTM
->otmTextMetrics
.tmHeight
= height_to_LP( &DevToWorld
, LocalOTM
->otmTextMetrics
.tmHeight
);
1288 LocalOTM
->otmTextMetrics
.tmAscent
= height_to_LP( &DevToWorld
, LocalOTM
->otmTextMetrics
.tmAscent
);
1289 LocalOTM
->otmTextMetrics
.tmDescent
= height_to_LP( &DevToWorld
, LocalOTM
->otmTextMetrics
.tmDescent
);
1290 LocalOTM
->otmTextMetrics
.tmInternalLeading
= height_to_LP( &DevToWorld
, LocalOTM
->otmTextMetrics
.tmInternalLeading
);
1291 LocalOTM
->otmTextMetrics
.tmExternalLeading
= height_to_LP( &DevToWorld
, LocalOTM
->otmTextMetrics
.tmExternalLeading
);
1292 LocalOTM
->otmTextMetrics
.tmAveCharWidth
= width_to_LP( &DevToWorld
, LocalOTM
->otmTextMetrics
.tmAveCharWidth
);
1293 LocalOTM
->otmTextMetrics
.tmMaxCharWidth
= width_to_LP( &DevToWorld
, LocalOTM
->otmTextMetrics
.tmMaxCharWidth
);
1294 LocalOTM
->otmTextMetrics
.tmOverhang
= width_to_LP( &DevToWorld
, LocalOTM
->otmTextMetrics
.tmOverhang
);
1295 LocalOTM
->otmAscent
= height_to_LP( &DevToWorld
, LocalOTM
->otmAscent
);
1296 LocalOTM
->otmDescent
= height_to_LP( &DevToWorld
, LocalOTM
->otmDescent
);
1297 LocalOTM
->otmLineGap
= abs(INTERNAL_YDSTOWS(&DevToWorld
,LocalOTM
->otmLineGap
));
1298 LocalOTM
->otmsCapEmHeight
= abs(INTERNAL_YDSTOWS(&DevToWorld
,LocalOTM
->otmsCapEmHeight
));
1299 LocalOTM
->otmsXHeight
= abs(INTERNAL_YDSTOWS(&DevToWorld
,LocalOTM
->otmsXHeight
));
1300 LocalOTM
->otmrcFontBox
.top
= height_to_LP( &DevToWorld
, LocalOTM
->otmrcFontBox
.top
);
1301 LocalOTM
->otmrcFontBox
.bottom
= height_to_LP( &DevToWorld
, LocalOTM
->otmrcFontBox
.bottom
);
1302 LocalOTM
->otmrcFontBox
.left
= width_to_LP( &DevToWorld
, LocalOTM
->otmrcFontBox
.left
);
1303 LocalOTM
->otmrcFontBox
.right
= width_to_LP( &DevToWorld
, LocalOTM
->otmrcFontBox
.right
);
1304 LocalOTM
->otmMacAscent
= height_to_LP( &DevToWorld
, LocalOTM
->otmMacAscent
);
1305 LocalOTM
->otmMacDescent
= height_to_LP( &DevToWorld
, LocalOTM
->otmMacDescent
);
1306 LocalOTM
->otmMacLineGap
= abs(INTERNAL_YDSTOWS(&DevToWorld
,LocalOTM
->otmMacLineGap
));
1307 LocalOTM
->otmptSubscriptSize
.x
= width_to_LP( &DevToWorld
, LocalOTM
->otmptSubscriptSize
.x
);
1308 LocalOTM
->otmptSubscriptSize
.y
= height_to_LP( &DevToWorld
, LocalOTM
->otmptSubscriptSize
.y
);
1309 LocalOTM
->otmptSubscriptOffset
.x
= width_to_LP( &DevToWorld
, LocalOTM
->otmptSubscriptOffset
.x
);
1310 LocalOTM
->otmptSubscriptOffset
.y
= height_to_LP( &DevToWorld
, LocalOTM
->otmptSubscriptOffset
.y
);
1311 LocalOTM
->otmptSuperscriptSize
.x
= width_to_LP( &DevToWorld
, LocalOTM
->otmptSuperscriptSize
.x
);
1312 LocalOTM
->otmptSuperscriptSize
.y
= height_to_LP( &DevToWorld
, LocalOTM
->otmptSuperscriptSize
.y
);
1313 LocalOTM
->otmptSuperscriptOffset
.x
= width_to_LP( &DevToWorld
, LocalOTM
->otmptSuperscriptOffset
.x
);
1314 LocalOTM
->otmptSuperscriptOffset
.y
= height_to_LP( &DevToWorld
, LocalOTM
->otmptSuperscriptOffset
.y
);
1315 LocalOTM
->otmsStrikeoutSize
= abs(INTERNAL_YDSTOWS(&DevToWorld
,LocalOTM
->otmsStrikeoutSize
));
1316 LocalOTM
->otmsStrikeoutPosition
= height_to_LP( &DevToWorld
, LocalOTM
->otmsStrikeoutPosition
);
1317 LocalOTM
->otmsUnderscoreSize
= height_to_LP( &DevToWorld
, LocalOTM
->otmsUnderscoreSize
);
1318 LocalOTM
->otmsUnderscorePosition
= height_to_LP( &DevToWorld
, LocalOTM
->otmsUnderscorePosition
);
1320 /* Copy what we can */
1321 CopyMemory(lpOTM
, LocalOTM
, min(Size
, cbData
));
1323 lpOTM
->otmpFamilyName
= NULL
;
1324 lpOTM
->otmpFaceName
= NULL
;
1325 lpOTM
->otmpStyleName
= NULL
;
1326 lpOTM
->otmpFullName
= NULL
;
1328 Size
= sizeof(*lpOTM
);
1329 AvailableSize
= cbData
- Size
;
1330 Ptr
= (BYTE
*)lpOTM
+ sizeof(*lpOTM
);
1332 /* Fix string values up */
1333 if (LocalOTM
->otmpFamilyName
)
1335 Str
= (WCHAR
*)((char*)LocalOTM
+ (ptrdiff_t)LocalOTM
->otmpFamilyName
);
1336 StringSize
= (wcslen(Str
) + 1) * sizeof(WCHAR
);
1337 if (AvailableSize
>= StringSize
)
1339 CopyMemory(Ptr
, Str
, StringSize
);
1340 lpOTM
->otmpFamilyName
= (PSTR
)(Ptr
- (BYTE
*)lpOTM
);
1342 AvailableSize
-= StringSize
;
1347 if (LocalOTM
->otmpFaceName
)
1349 Str
= (WCHAR
*)((char*)LocalOTM
+ (ptrdiff_t)LocalOTM
->otmpFaceName
);
1350 StringSize
= (wcslen(Str
) + 1) * sizeof(WCHAR
);
1351 if (AvailableSize
>= StringSize
)
1353 CopyMemory(Ptr
, Str
, StringSize
);
1354 lpOTM
->otmpFaceName
= (PSTR
)(Ptr
- (BYTE
*)lpOTM
);
1356 AvailableSize
-= StringSize
;
1361 if (LocalOTM
->otmpStyleName
)
1363 Str
= (WCHAR
*)((char*)LocalOTM
+ (ptrdiff_t)LocalOTM
->otmpStyleName
);
1364 StringSize
= (wcslen(Str
) + 1) * sizeof(WCHAR
);
1365 if (AvailableSize
>= StringSize
)
1367 CopyMemory(Ptr
, Str
, StringSize
);
1368 lpOTM
->otmpStyleName
= (PSTR
)(Ptr
- (BYTE
*)lpOTM
);
1370 AvailableSize
-= StringSize
;
1375 if (LocalOTM
->otmpFullName
)
1377 Str
= (WCHAR
*)((char*)LocalOTM
+ (ptrdiff_t)LocalOTM
->otmpFullName
);
1378 StringSize
= (wcslen(Str
) + 1) * sizeof(WCHAR
);
1379 if (AvailableSize
>= StringSize
)
1381 CopyMemory(Ptr
, Str
, StringSize
);
1382 lpOTM
->otmpFullName
= (PSTR
)(Ptr
- (BYTE
*)lpOTM
);
1384 AvailableSize
-= StringSize
;
1389 lpOTM
->otmSize
= Size
;
1391 HeapFree(GetProcessHeap(), 0, LocalOTM
);
1401 GetKerningPairsW(HDC hdc
,
1403 LPKERNINGPAIR pkpDst
)
1405 if ((cPairs
!= 0) || (pkpDst
== 0))
1407 return NtGdiGetKerningPairs(hdc
,cPairs
,pkpDst
);
1411 SetLastError(ERROR_INVALID_PARAMETER
);
1421 GetKerningPairsA( HDC hDC
,
1423 LPKERNINGPAIR kern_pairA
)
1428 DWORD i
, total_kern_pairs
, kern_pairs_copied
= 0;
1429 KERNINGPAIR
*kern_pairW
;
1431 if (!cPairs
&& kern_pairA
)
1433 SetLastError(ERROR_INVALID_PARAMETER
);
1437 charset
= GetTextCharset(hDC
);
1438 if (!TranslateCharsetInfo(ULongToPtr(charset
), &csi
, TCI_SRCCHARSET
))
1440 DPRINT1("Can't find codepage for charset %d\n", charset
);
1443 /* GetCPInfo() will fail on CP_SYMBOL, and WideCharToMultiByte is supposed
1444 * to fail on an invalid character for CP_SYMBOL.
1446 cpi
.DefaultChar
[0] = 0;
1447 if (csi
.ciACP
!= CP_SYMBOL
&& !GetCPInfo(csi
.ciACP
, &cpi
))
1449 DPRINT1("Can't find codepage %u info\n", csi
.ciACP
);
1452 DPRINT("charset %d => codepage %u\n", charset
, csi
.ciACP
);
1454 total_kern_pairs
= NtGdiGetKerningPairs(hDC
, 0, NULL
);
1455 if (!total_kern_pairs
) return 0;
1457 if (!cPairs
&& !kern_pairA
) return total_kern_pairs
;
1459 kern_pairW
= HeapAlloc(GetProcessHeap(), 0, total_kern_pairs
* sizeof(*kern_pairW
));
1460 if (kern_pairW
== NULL
)
1464 GetKerningPairsW(hDC
, total_kern_pairs
, kern_pairW
);
1466 for (i
= 0; i
< total_kern_pairs
; i
++)
1470 if (!WideCharToMultiByte(csi
.ciACP
, 0, &kern_pairW
[i
].wFirst
, 1, &first
, 1, NULL
, NULL
))
1473 if (!WideCharToMultiByte(csi
.ciACP
, 0, &kern_pairW
[i
].wSecond
, 1, &second
, 1, NULL
, NULL
))
1476 if (first
== cpi
.DefaultChar
[0] || second
== cpi
.DefaultChar
[0])
1481 if (kern_pairs_copied
>= cPairs
) break;
1483 kern_pairA
->wFirst
= (BYTE
)first
;
1484 kern_pairA
->wSecond
= (BYTE
)second
;
1485 kern_pairA
->iKernAmount
= kern_pairW
[i
].iKernAmount
;
1488 kern_pairs_copied
++;
1491 HeapFree(GetProcessHeap(), 0, kern_pairW
);
1493 return kern_pairs_copied
;
1503 CreateFontIndirectExA(const ENUMLOGFONTEXDVA
*elfexd
)
1507 ENUMLOGFONTEXDVW Logfont
;
1509 EnumLogFontExW2A( (LPENUMLOGFONTEXA
) elfexd
,
1510 &Logfont
.elfEnumLogfontEx
);
1512 RtlCopyMemory( &Logfont
.elfDesignVector
,
1513 (PVOID
) &elfexd
->elfDesignVector
,
1514 sizeof(DESIGNVECTOR
));
1516 return NtGdiHfontCreate( &Logfont
, 0, 0, 0, NULL
);
1527 CreateFontIndirectExW(const ENUMLOGFONTEXDVW
*elfexd
)
1529 /* Msdn: Note, this function ignores the elfDesignVector member in
1534 return NtGdiHfontCreate((PENUMLOGFONTEXDVW
) elfexd
, 0, 0, 0, NULL
);
1545 CreateFontIndirectA(
1546 CONST LOGFONTA
*lplf
1553 LogFontA2W(&tlf
, lplf
);
1554 return CreateFontIndirectW(&tlf
);
1565 CreateFontIndirectW(
1566 CONST LOGFONTW
*lplf
1571 ENUMLOGFONTEXDVW Logfont
;
1573 RtlCopyMemory( &Logfont
.elfEnumLogfontEx
.elfLogFont
, lplf
, sizeof(LOGFONTW
));
1574 // Need something other than just cleaning memory here.
1575 // Guess? Use caller data to determine the rest.
1576 RtlZeroMemory( &Logfont
.elfEnumLogfontEx
.elfFullName
,
1577 sizeof(Logfont
.elfEnumLogfontEx
.elfFullName
));
1578 RtlZeroMemory( &Logfont
.elfEnumLogfontEx
.elfStyle
,
1579 sizeof(Logfont
.elfEnumLogfontEx
.elfStyle
));
1580 RtlZeroMemory( &Logfont
.elfEnumLogfontEx
.elfScript
,
1581 sizeof(Logfont
.elfEnumLogfontEx
.elfScript
));
1583 Logfont
.elfDesignVector
.dvNumAxes
= 0; // No more than MM_MAX_NUMAXES
1585 RtlZeroMemory( &Logfont
.elfDesignVector
, sizeof(DESIGNVECTOR
));
1587 return CreateFontIndirectExW(&Logfont
);
1608 DWORD fdwOutputPrecision
,
1609 DWORD fdwClipPrecision
,
1611 DWORD fdwPitchAndFamily
,
1615 ANSI_STRING StringA
;
1616 UNICODE_STRING StringU
;
1619 RtlInitAnsiString(&StringA
, (LPSTR
)lpszFace
);
1620 RtlAnsiStringToUnicodeString(&StringU
, &StringA
, TRUE
);
1622 ret
= CreateFontW(nHeight
,
1637 RtlFreeUnicodeString(&StringU
);
1658 DWORD fdwOutputPrecision
,
1659 DWORD fdwClipPrecision
,
1661 DWORD fdwPitchAndFamily
,
1667 logfont
.lfHeight
= nHeight
;
1668 logfont
.lfWidth
= nWidth
;
1669 logfont
.lfEscapement
= nEscapement
;
1670 logfont
.lfOrientation
= nOrientation
;
1671 logfont
.lfWeight
= nWeight
;
1672 logfont
.lfItalic
= (BYTE
)fnItalic
;
1673 logfont
.lfUnderline
= (BYTE
)fdwUnderline
;
1674 logfont
.lfStrikeOut
= (BYTE
)fdwStrikeOut
;
1675 logfont
.lfCharSet
= (BYTE
)fdwCharSet
;
1676 logfont
.lfOutPrecision
= (BYTE
)fdwOutputPrecision
;
1677 logfont
.lfClipPrecision
= (BYTE
)fdwClipPrecision
;
1678 logfont
.lfQuality
= (BYTE
)fdwQuality
;
1679 logfont
.lfPitchAndFamily
= (BYTE
)fdwPitchAndFamily
;
1681 if (NULL
!= lpszFace
)
1683 int Size
= sizeof(logfont
.lfFaceName
) / sizeof(WCHAR
);
1684 wcsncpy((wchar_t *)logfont
.lfFaceName
, lpszFace
, Size
- 1);
1685 /* Be 101% sure to have '\0' at end of string */
1686 logfont
.lfFaceName
[Size
- 1] = '\0';
1690 logfont
.lfFaceName
[0] = L
'\0';
1693 return CreateFontIndirectW(&logfont
);
1702 CreateScalableFontResourceA(
1705 LPCSTR lpszFontFile
,
1706 LPCSTR lpszCurrentPath
1718 AddFontResourceExW ( LPCWSTR lpszFilename
, DWORD fl
, PVOID pvReserved
)
1720 if (fl
& ~(FR_PRIVATE
| FR_NOT_ENUM
))
1722 SetLastError( ERROR_INVALID_PARAMETER
);
1726 return GdiAddFontResourceW(lpszFilename
, fl
,0);
1735 AddFontResourceExA ( LPCSTR lpszFilename
, DWORD fl
, PVOID pvReserved
)
1741 if (fl
& ~(FR_PRIVATE
| FR_NOT_ENUM
))
1743 SetLastError( ERROR_INVALID_PARAMETER
);
1747 Status
= HEAP_strdupA2W ( &FilenameW
, lpszFilename
);
1748 if ( !NT_SUCCESS (Status
) )
1750 SetLastError (RtlNtStatusToDosError(Status
));
1754 rc
= GdiAddFontResourceW ( FilenameW
, fl
, 0 );
1755 HEAP_free ( FilenameW
);
1765 AddFontResourceA ( LPCSTR lpszFilename
)
1771 Status
= HEAP_strdupA2W ( &FilenameW
, lpszFilename
);
1772 if ( !NT_SUCCESS (Status
) )
1774 SetLastError (RtlNtStatusToDosError(Status
));
1778 rc
= GdiAddFontResourceW ( FilenameW
, 0, 0);
1780 HEAP_free ( FilenameW
);
1791 AddFontResourceW ( LPCWSTR lpszFilename
)
1793 return GdiAddFontResourceW ( lpszFilename
, 0, 0 );
1802 RemoveFontResourceW(LPCWSTR lpFileName
)
1804 return RemoveFontResourceExW(lpFileName
,0,0);
1813 RemoveFontResourceA(LPCSTR lpFileName
)
1815 return RemoveFontResourceExA(lpFileName
,0,0);
1823 RemoveFontResourceExA(LPCSTR lpFileName
,
1831 /* FIXME the flags */
1833 /* FIXME NtGdiRemoveFontResource handle flags and pdv */
1835 Status
= HEAP_strdupA2W ( &lpFileNameW
, lpFileName
);
1836 if (!NT_SUCCESS (Status
))
1837 SetLastError (RtlNtStatusToDosError(Status
));
1841 HEAP_free ( lpFileNameW
);
1852 RemoveFontResourceExW(LPCWSTR lpFileName
,
1856 /* FIXME the flags */
1858 /* FIXME NtGdiRemoveFontResource handle flags and pdv */
1863 /***********************************************************************
1864 * GdiGetCharDimensions
1866 * Gets the average width of the characters in the English alphabet.
1869 * hdc [I] Handle to the device context to measure on.
1870 * lptm [O] Pointer to memory to store the text metrics into.
1871 * height [O] On exit, the maximum height of characters in the English alphabet.
1874 * The average width of characters in the English alphabet.
1877 * This function is used by the dialog manager to get the size of a dialog
1878 * unit. It should also be used by other pieces of code that need to know
1879 * the size of a dialog unit in logical units without having access to the
1880 * window handle of the dialog.
1881 * Windows caches the font metrics from this function, but we don't and
1882 * there doesn't appear to be an immediate advantage to do so.
1885 * GetTextExtentPointW, GetTextMetricsW, MapDialogRect.
1887 * Despite most of MSDN insisting that the horizontal base unit is
1888 * tmAveCharWidth it isn't. Knowledge base article Q145994
1889 * "HOWTO: Calculate Dialog Units When Not Using the System Font",
1890 * says that we should take the average of the 52 English upper and lower
1898 GdiGetCharDimensions(HDC hdc
, LPTEXTMETRICW lptm
, LONG
*height
)
1902 static const WCHAR alphabet
[] =
1904 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q',
1905 'r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H',
1906 'I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',0
1909 if(!GetTextMetricsW(hdc
, &tm
)) return 0;
1911 if(!GetTextExtentPointW(hdc
, alphabet
, 52, &sz
)) return 0;
1913 if (lptm
) *lptm
= tm
;
1914 if (height
) *height
= tm
.tmHeight
;
1916 return (sz
.cx
/ 26 + 1) / 2;
1919 /*************************************************************************
1920 * TranslateCharsetInfo [GDI32.@]
1922 * Fills a CHARSETINFO structure for a character set, code page, or
1923 * font. This allows making the correspondance between different labelings
1924 * (character set, Windows, ANSI, and OEM codepages, and Unicode ranges)
1925 * of the same encoding.
1927 * Only one codepage will be set in lpCs->fs. If TCI_SRCFONTSIG is used,
1928 * only one codepage should be set in *lpSrc.
1931 * TRUE on success, FALSE on failure.
1939 TranslateCharsetInfo(
1940 LPDWORD lpSrc
, /* [in]
1941 if flags == TCI_SRCFONTSIG: pointer to fsCsb of a FONTSIGNATURE
1942 if flags == TCI_SRCCHARSET: a character set value
1943 if flags == TCI_SRCCODEPAGE: a code page value
1945 LPCHARSETINFO lpCs
, /* [out] structure to receive charset information */
1946 DWORD flags
/* [in] determines interpretation of lpSrc */)
1951 case TCI_SRCFONTSIG
:
1952 while (index
< MAXTCIINDEX
&& !(*lpSrc
>>index
& 0x0001)) index
++;
1954 case TCI_SRCCODEPAGE
:
1955 while (index
< MAXTCIINDEX
&& PtrToUlong(lpSrc
) != FONT_tci
[index
].ciACP
) index
++;
1957 case TCI_SRCCHARSET
:
1958 while (index
< MAXTCIINDEX
&& PtrToUlong(lpSrc
) != FONT_tci
[index
].ciCharset
) index
++;
1962 LCID lCid
= (LCID
)PtrToUlong(lpSrc
);
1963 LOCALESIGNATURE LocSig
;
1964 INT Ret
= GetLocaleInfoW(lCid
, LOCALE_FONTSIGNATURE
, (LPWSTR
)&LocSig
, 0);
1965 if ( GetLocaleInfoW(lCid
, LOCALE_FONTSIGNATURE
, (LPWSTR
)&LocSig
, Ret
))
1967 while (index
< MAXTCIINDEX
&& !(LocSig
.lsCsbDefault
[0]>>index
& 0x0001)) index
++;
1972 GdiSetLastError(ERROR_INVALID_PARAMETER
);
1975 if (index
>= MAXTCIINDEX
|| FONT_tci
[index
].ciCharset
== DEFAULT_CHARSET
) return FALSE
;
1976 DPRINT("Index %d Charset %u CodePage %u FontSig %lu\n",
1977 index
,FONT_tci
[index
].ciCharset
,FONT_tci
[index
].ciACP
,FONT_tci
[index
].fs
.fsCsb
[0]);
1978 memcpy(lpCs
, &FONT_tci
[index
], sizeof(CHARSETINFO
));
1993 DWORD Ret
= GDI_ERROR
;
1996 if (GDI_HANDLE_GET_TYPE(hDC
) != GDI_OBJECT_TYPE_DC
)
1998 if (GDI_HANDLE_GET_TYPE(hDC
) == GDI_OBJECT_TYPE_METADC
)
1999 return MFDRV_SetMapperFlags( hDC
, flags
);
2002 PLDC pLDC
= Dc_Attr
->pvLDC
;
2005 SetLastError(ERROR_INVALID_HANDLE
);
2008 if (pLDC
->iType
== LDC_EMFLDC
)
2010 return EMFDRV_SetMapperFlags( hDC
, flags
);
2015 if (!GdiGetHandleUserData((HGDIOBJ
) hDC
, GDI_OBJECT_TYPE_DC
, (PVOID
) &Dc_Attr
)) return GDI_ERROR
;
2017 if (NtCurrentTeb()->GdiTebBatch
.HDC
== hDC
)
2019 if (Dc_Attr
->ulDirty_
& DC_FONTTEXT_DIRTY
)
2022 Dc_Attr
->ulDirty_
&= ~(DC_MODE_DIRTY
|DC_FONTTEXT_DIRTY
);
2027 SetLastError(ERROR_INVALID_PARAMETER
);
2030 Ret
= Dc_Attr
->flFontMapper
;
2031 Dc_Attr
->flFontMapper
= flags
;
2045 FONTENUMPROCW FontFunc
,
2050 return NtGdiEnumFonts ( hDC
, lpFaceName
, FontFunc
, lParam
);
2052 return EnumFontFamiliesW( hDC
, lpFaceName
, FontFunc
, lParam
);
2064 FONTENUMPROCA FontFunc
,
2073 Status
= HEAP_strdupA2W ( &lpFaceNameW
, lpFaceName
);
2074 if (!NT_SUCCESS (Status
))
2075 SetLastError (RtlNtStatusToDosError(Status
));
2078 rc
= NtGdiEnumFonts ( hDC
, lpFaceNameW
, FontFunc
, lParam
);
2080 HEAP_free ( lpFaceNameW
);
2084 return EnumFontFamiliesA( hDC
, lpFaceName
, FontFunc
, lParam
);
2088 #define EfdFontFamilies 3
2092 NewEnumFontFamiliesExW(
2094 LPLOGFONTW lpLogfont
,
2095 FONTENUMPROCW lpEnumFontFamExProcW
,
2099 ULONG_PTR idEnum
, cbDataSize
, cbRetSize
;
2100 PENUMFONTDATAW pEfdw
;
2105 /* Open enumeration handle and find out how much memory we need */
2106 idEnum
= NtGdiEnumFontOpen(hDC
,
2110 (lpLogfont
&& lpLogfont
->lfFaceName
[0])? lpLogfont
->lfFaceName
: NULL
,
2111 lpLogfont
? lpLogfont
->lfCharSet
: DEFAULT_CHARSET
,
2117 if (cbDataSize
== 0)
2119 NtGdiEnumFontClose(idEnum
);
2123 /* Allocate memory */
2124 pBuffer
= HeapAlloc(GetProcessHeap(), 0, cbDataSize
);
2125 if (pBuffer
== NULL
)
2127 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2128 NtGdiEnumFontClose(idEnum
);
2132 /* Do the enumeration */
2133 if (!NtGdiEnumFontChunk(hDC
, idEnum
, cbDataSize
, &cbRetSize
, (PVOID
)pBuffer
))
2135 HeapFree(GetProcessHeap(), 0, pBuffer
);
2136 NtGdiEnumFontClose(idEnum
);
2140 /* Get start and end address */
2141 pEfdw
= (PENUMFONTDATAW
)pBuffer
;
2142 pMax
= pBuffer
+ cbDataSize
;
2144 /* Iterate through the structures */
2145 while ((PBYTE
)pEfdw
< pMax
&& ret
)
2147 PNTMW_INTERNAL pNtmwi
= (PNTMW_INTERNAL
)((ULONG_PTR
)pEfdw
+ pEfdw
->ulNtmwiOffset
);
2149 ret
= lpEnumFontFamExProcW((VOID
*)&pEfdw
->elfexdv
.elfEnumLogfontEx
,
2150 (VOID
*)&pNtmwi
->ntmw
,
2154 pEfdw
= (PENUMFONTDATAW
)((ULONG_PTR
)pEfdw
+ pEfdw
->cbSize
);
2157 /* Release the memory and close handle */
2158 HeapFree(GetProcessHeap(), 0, pBuffer
);
2159 NtGdiEnumFontClose(idEnum
);