forked from reactos/reactos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lpk.c
212 lines (177 loc) · 5.63 KB
/
lpk.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/*
* PROJECT: ReactOS LPK
* LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
* PURPOSE: Language Pack DLL.
* PROGRAMMERS: Magnus Olsen (greatlrd)
* Baruch Rutman (peterooch at gmail dot com)
*/
#include "ros_lpk.h"
#include <debug.h>
LPK_LPEDITCONTROL_LIST LpkEditControl = {EditCreate, EditIchToXY, EditMouseToIch, EditCchInWidth,
EditGetLineWidth, EditDrawText, EditHScroll, EditMoveSelection,
EditVerifyText, EditNextWord, EditSetMenu, EditProcessMenu,
EditCreateCaret, EditAdjustCaret};
BOOL
WINAPI
DllMain(
HANDLE hDll,
DWORD dwReason,
LPVOID lpReserved)
{
return LpkDllInitialize(hDll,dwReason,lpReserved);
}
BOOL
WINAPI
LpkDllInitialize(
HANDLE hDll,
DWORD dwReason,
LPVOID lpReserved)
{
switch(dwReason)
{
case DLL_PROCESS_ATTACH:
DisableThreadLibraryCalls(hDll);
/* Tell usp10 it is activated usp10 */
//LpkPresent();
break;
default:
break;
}
return TRUE;
}
/*
* @implemented
*/
BOOL
WINAPI
LpkExtTextOut(
HDC hdc,
int x,
int y,
UINT fuOptions,
const RECT *lprc,
LPCWSTR lpString,
UINT uCount,
const INT *lpDx,
INT unknown)
{
LPWORD glyphs = NULL;
LPWSTR reordered_str = NULL;
INT cGlyphs;
DWORD dwSICFlags = SIC_COMPLEX;
BOOL bResult, bReorder;
UNREFERENCED_PARAMETER(unknown);
fuOptions |= ETO_IGNORELANGUAGE;
/* Check text direction */
if ((GetLayout(hdc) & LAYOUT_RTL) || (GetTextAlign(hdc) & TA_RTLREADING))
fuOptions |= ETO_RTLREADING;
/* If text direction is RTL change flag to account neutral characters */
if (fuOptions & ETO_RTLREADING)
dwSICFlags |= SIC_NEUTRAL;
/* Check if the string requires complex script processing and not a "glyph indices" array */
if (ScriptIsComplex(lpString, uCount, dwSICFlags) == S_OK && !(fuOptions & ETO_GLYPH_INDEX))
{
/* reordered_str is used as fallback in case the glyphs array fails to generate,
BIDI_Reorder doesn't attempt to write into reordered_str if memory allocation fails */
reordered_str = HeapAlloc(GetProcessHeap(), 0, uCount * sizeof(WCHAR));
bReorder = BIDI_Reorder(hdc, lpString, uCount, GCP_REORDER,
(fuOptions & ETO_RTLREADING) ? WINE_GCPW_FORCE_RTL : WINE_GCPW_FORCE_LTR,
reordered_str, uCount, NULL, &glyphs, &cGlyphs);
if (glyphs)
{
fuOptions |= ETO_GLYPH_INDEX;
uCount = cGlyphs;
}
/* Now display the reordered text if any of the arrays is valid and if BIDI_Reorder succeeded */
if ((glyphs || reordered_str) && bReorder)
{
bResult = ExtTextOutW(hdc, x, y, fuOptions, lprc,
glyphs ? (LPWSTR)glyphs : reordered_str, uCount, lpDx);
}
else
{
DPRINT1("BIDI_Reorder failed, falling back to original string.\n");
bResult = ExtTextOutW(hdc, x, y, fuOptions, lprc, lpString, uCount, lpDx);
}
HeapFree(GetProcessHeap(), 0, glyphs);
HeapFree(GetProcessHeap(), 0, reordered_str);
return bResult;
}
return ExtTextOutW(hdc, x, y, fuOptions, lprc, lpString, uCount, lpDx);
}
/*
* @implemented
*/
DWORD
WINAPI
LpkGetCharacterPlacement(
HDC hdc,
LPCWSTR lpString,
INT uCount,
INT nMaxExtent,
LPGCP_RESULTSW lpResults,
DWORD dwFlags,
DWORD dwUnused)
{
LPWORD lpGlyphs = NULL;
SIZE size;
DWORD ret = 0;
UINT nSet, i;
INT cGlyphs;
UNREFERENCED_PARAMETER(dwUnused);
/* Sanity check (most likely a direct call) */
if (!(dwFlags & GCP_REORDER))
return GetCharacterPlacementW(hdc, lpString, uCount, nMaxExtent, lpResults, dwFlags);
nSet = (UINT)uCount;
if (nSet > lpResults->nGlyphs)
nSet = lpResults->nGlyphs;
BIDI_Reorder(hdc, lpString, uCount, dwFlags, WINE_GCPW_FORCE_LTR, lpResults->lpOutString,
nSet, lpResults->lpOrder, &lpGlyphs, &cGlyphs);
lpResults->nGlyphs = (UINT)cGlyphs;
if (lpResults->lpGlyphs)
{
if (lpGlyphs)
StringCchCopyW(lpResults->lpGlyphs, cGlyphs, lpGlyphs);
else if (lpResults->lpOutString)
GetGlyphIndicesW(hdc, lpResults->lpOutString, nSet, lpResults->lpGlyphs, 0);
}
if (lpResults->lpDx)
{
int c;
/* If glyph shaping was requested */
if (dwFlags & GCP_GLYPHSHAPE)
{
if (lpResults->lpGlyphs)
{
for (i = 0; i < lpResults->nGlyphs; i++)
{
if (GetCharWidthI(hdc, 0, 1, (WORD *)&lpResults->lpGlyphs[i], &c))
lpResults->lpDx[i] = c;
}
}
}
else
{
for (i = 0; i < nSet; i++)
{
if (GetCharWidth32W(hdc, lpResults->lpOutString[i], lpResults->lpOutString[i], &c))
lpResults->lpDx[i] = c;
}
}
}
/* FIXME: Currently not bidi compliant! */
if (lpResults->lpCaretPos)
{
int pos = 0;
lpResults->lpCaretPos[0] = 0;
for (i = 1; i < nSet; i++)
{
if (GetTextExtentPoint32W(hdc, &(lpString[i - 1]), 1, &size))
lpResults->lpCaretPos[i] = (pos += size.cx);
}
}
if (GetTextExtentPoint32W(hdc, lpString, uCount, &size))
ret = MAKELONG(size.cx, size.cy);
HeapFree(GetProcessHeap(), 0, lpGlyphs);
return ret;
}