ReactOS  0.4.14-dev-317-g96040ec
style.c File Reference
#include "editor.h"
Include dependency graph for style.c:

Go to the source code of this file.

Macros

#define COPY_STYLE_ITEM(mask, member)
 
#define COPY_STYLE_ITEM_MEMCPY(mask, member)
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (richedit)
 
 WINE_DECLARE_DEBUG_CHANNEL (richedit_style)
 
BOOL cfany_to_cf2w (CHARFORMAT2W *to, const CHARFORMAT2W *from)
 
BOOL cf2w_to_cfany (CHARFORMAT2W *to, const CHARFORMAT2W *from)
 
ME_StyleME_MakeStyle (CHARFORMAT2W *style)
 
void ME_InitCharFormat2W (CHARFORMAT2W *pFmt)
 
ME_StyleME_ApplyStyle (ME_TextEditor *editor, ME_Style *sSrc, CHARFORMAT2W *mod)
 
void ME_CopyCharFormat (CHARFORMAT2W *pDest, const CHARFORMAT2W *pSrc)
 
static void ME_DumpStyleEffect (char **p, const char *name, const CHARFORMAT2W *fmt, int mask)
 
void ME_DumpStyle (ME_Style *s)
 
void ME_DumpStyleToBuf (CHARFORMAT2W *pFmt, char buf[2048])
 
static void ME_LogFontFromStyle (ME_Context *c, LOGFONTW *lf, const ME_Style *s)
 
void ME_CharFormatFromLogFont (HDC hDC, const LOGFONTW *lf, CHARFORMAT2W *fmt)
 
static BOOL ME_IsFontEqual (const LOGFONTW *p1, const LOGFONTW *p2)
 
HFONT ME_SelectStyleFont (ME_Context *c, ME_Style *s)
 
static void release_font_cache (ME_FontCacheItem *item)
 
void ME_UnselectStyleFont (ME_Context *c, ME_Style *s, HFONT hOldFont)
 
void ME_DestroyStyle (ME_Style *s)
 
void ME_AddRefStyle (ME_Style *s)
 
void ME_ReleaseStyle (ME_Style *s)
 
ME_StyleME_GetInsertStyle (ME_TextEditor *editor, int nCursor)
 
void ME_SaveTempStyle (ME_TextEditor *editor, ME_Style *style)
 
void ME_ClearTempStyle (ME_TextEditor *editor)
 
void ME_SetDefaultCharFormat (ME_TextEditor *editor, CHARFORMAT2W *mod)
 

Variables

static int all_refs = 0
 

Macro Definition Documentation

◆ COPY_STYLE_ITEM

#define COPY_STYLE_ITEM (   mask,
  member 
)
Value:
if (mod->dwMask & mask) { \
fmt.dwMask |= mask;\
fmt.member = mod->member;\
}
GLenum GLint GLuint mask
Definition: glext.h:6028
static int mod
Definition: i386-dis.c:1273

Definition at line 134 of file style.c.

◆ COPY_STYLE_ITEM_MEMCPY

#define COPY_STYLE_ITEM_MEMCPY (   mask,
  member 
)
Value:
if (mod->dwMask & mask) { \
fmt.dwMask |= mask;\
CopyMemory(fmt.member, mod->member, sizeof(mod->member));\
}
GLenum GLint GLuint mask
Definition: glext.h:6028
Definition: dsound.c:943
static int mod
Definition: i386-dis.c:1273

Definition at line 140 of file style.c.

Function Documentation

◆ cf2w_to_cfany()

BOOL cf2w_to_cfany ( CHARFORMAT2W to,
const CHARFORMAT2W from 
)

Definition at line 79 of file style.c.

80 {
81  assert(from->cbSize == sizeof(CHARFORMAT2W));
82  if (to->cbSize == sizeof(CHARFORMATA))
83  {
84  CHARFORMATA *t = (CHARFORMATA *)to;
85  CopyMemory(t, from, FIELD_OFFSET(CHARFORMATA, szFaceName));
86  WideCharToMultiByte(CP_ACP, 0, from->szFaceName, -1, t->szFaceName, sizeof(t->szFaceName), NULL, NULL);
87  t->cbSize = sizeof(*t); /* it was overwritten by CopyMemory */
88  return TRUE;
89  }
90  if (to->cbSize == sizeof(CHARFORMATW))
91  {
92  CHARFORMATW *t = (CHARFORMATW *)to;
93  CopyMemory(t, from, sizeof(*t));
94  t->cbSize = sizeof(*t); /* it was overwritten by CopyMemory */
95  return TRUE;
96  }
97  if (to->cbSize == sizeof(CHARFORMAT2A))
98  {
99  CHARFORMAT2A *t = (CHARFORMAT2A *)to;
100  /* copy the A structure without face name */
101  CopyMemory(t, from, FIELD_OFFSET(CHARFORMATA, szFaceName));
102  /* convert face name */
103  WideCharToMultiByte(CP_ACP, 0, from->szFaceName, -1, t->szFaceName, sizeof(t->szFaceName), NULL, NULL);
104  /* copy the rest of the 2A structure to 2W */
105  CopyMemory(&t->wWeight, &from->wWeight, sizeof(CHARFORMAT2W)-FIELD_OFFSET(CHARFORMAT2W,wWeight));
106  t->cbSize = sizeof(*t); /* it was overwritten by CopyMemory */
107  return TRUE;
108  }
109  if (to->cbSize == sizeof(CHARFORMAT2W))
110  {
111  CopyMemory(to, from, sizeof(CHARFORMAT2W));
112  return TRUE;
113  }
114  return FALSE;
115 }
#define TRUE
Definition: types.h:120
#define WideCharToMultiByte
Definition: compat.h:101
#define CP_ACP
Definition: compat.h:99
GLdouble GLdouble t
Definition: gl.h:2047
#define assert(x)
Definition: debug.h:53
smooth NULL
Definition: ftsmooth.c:416
#define CopyMemory
Definition: winbase.h:1640
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
CardRegion * from
Definition: spigame.cpp:19

Referenced by ME_HandleMessage().

◆ cfany_to_cf2w()

BOOL cfany_to_cf2w ( CHARFORMAT2W to,
const CHARFORMAT2W from 
)

Definition at line 36 of file style.c.

37 {
38  if (from->cbSize == sizeof(CHARFORMATA))
39  {
41  CopyMemory(to, f, FIELD_OFFSET(CHARFORMATA, szFaceName));
42  to->cbSize = sizeof(CHARFORMAT2W);
43  if (f->dwMask & CFM_FACE) {
44  MultiByteToWideChar(CP_ACP, 0, f->szFaceName, -1, to->szFaceName, ARRAY_SIZE(to->szFaceName));
45  }
46  return TRUE;
47  }
48  if (from->cbSize == sizeof(CHARFORMATW))
49  {
51  CopyMemory(to, f, sizeof(*f));
52  /* theoretically, we don't need to zero the remaining memory */
53  ZeroMemory(&to->wWeight, sizeof(CHARFORMAT2W)-FIELD_OFFSET(CHARFORMAT2W, wWeight));
54  to->cbSize = sizeof(CHARFORMAT2W);
55  return TRUE;
56  }
57  if (from->cbSize == sizeof(CHARFORMAT2A))
58  {
60  /* copy the A structure without face name */
61  CopyMemory(to, f, FIELD_OFFSET(CHARFORMATA, szFaceName));
62  /* convert face name */
63  if (f->dwMask & CFM_FACE)
64  MultiByteToWideChar(CP_ACP, 0, f->szFaceName, -1, to->szFaceName, ARRAY_SIZE(to->szFaceName));
65  /* copy the rest of the 2A structure to 2W */
66  CopyMemory(&to->wWeight, &f->wWeight, sizeof(CHARFORMAT2A)-FIELD_OFFSET(CHARFORMAT2A, wWeight));
67  to->cbSize = sizeof(CHARFORMAT2W);
68  return TRUE;
69  }
70  if (from->cbSize == sizeof(CHARFORMAT2W))
71  {
72  CopyMemory(to, from, sizeof(CHARFORMAT2W));
73  return TRUE;
74  }
75 
76  return FALSE;
77 }
#define TRUE
Definition: types.h:120
WORD wWeight
Definition: richedit.h:314
#define CP_ACP
Definition: compat.h:99
#define CFM_FACE
Definition: richedit.h:360
#define ZeroMemory
Definition: winbase.h:1642
GLfloat f
Definition: glext.h:7540
#define CopyMemory
Definition: winbase.h:1640
WCHAR szFaceName[LF_FACESIZE]
Definition: richedit.h:313
#define ARRAY_SIZE(a)
Definition: main.h:24
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
#define MultiByteToWideChar
Definition: compat.h:100
struct _charformat2w CHARFORMAT2W
CardRegion * from
Definition: spigame.cpp:19

Referenced by ME_HandleMessage(), and ME_MakeFirstParagraph().

◆ ME_AddRefStyle()

void ME_AddRefStyle ( ME_Style s)

Definition at line 435 of file style.c.

436 {
437  assert(s->nRefs>0); /* style with 0 references isn't supposed to exist */
438  s->nRefs++;
439  all_refs++;
440  TRACE_(richedit_style)("ME_AddRefStyle %p, new refs=%d, total refs=%d\n", s, s->nRefs, all_refs);
441 }
#define assert(x)
Definition: debug.h:53
#define TRACE_(x)
Definition: compat.h:66
static int all_refs
Definition: style.c:26
GLdouble s
Definition: gl.h:2039

Referenced by add_undo_insert_run(), ME_ApplyStyle(), ME_GetInsertStyle(), ME_HandleMessage(), ME_MakeRun(), ME_RTFReadHook(), ME_SaveTempStyle(), ME_StreamIn(), para_num_init(), and RTFUngetToken().

◆ ME_ApplyStyle()

ME_Style* ME_ApplyStyle ( ME_TextEditor editor,
ME_Style sSrc,
CHARFORMAT2W mod 
)

Definition at line 152 of file style.c.

153 {
154  CHARFORMAT2W fmt = sSrc->fmt;
155  ME_Style *s;
156 
157  assert(mod->cbSize == sizeof(CHARFORMAT2W));
158  COPY_STYLE_ITEM(CFM_ANIMATION, bAnimation);
159  COPY_STYLE_ITEM(CFM_BACKCOLOR, crBackColor);
160  COPY_STYLE_ITEM(CFM_CHARSET, bCharSet);
161  COPY_STYLE_ITEM(CFM_COLOR, crTextColor);
162  COPY_STYLE_ITEM_MEMCPY(CFM_FACE, szFaceName);
163  COPY_STYLE_ITEM(CFM_KERNING, wKerning);
164  COPY_STYLE_ITEM(CFM_LCID, lcid);
166  COPY_STYLE_ITEM(CFM_REVAUTHOR, bRevAuthor);
167  if (mod->dwMask & CFM_SIZE) {
168  fmt.dwMask |= CFM_SIZE;
169  fmt.yHeight = min(mod->yHeight, yHeightCharPtsMost * 20);
170  }
171  COPY_STYLE_ITEM(CFM_SPACING, sSpacing);
172  COPY_STYLE_ITEM(CFM_STYLE, sStyle);
173  COPY_STYLE_ITEM(CFM_WEIGHT, wWeight);
174  /* FIXME: this is not documented this way, but that's the more logical */
175  COPY_STYLE_ITEM(CFM_FACE, bPitchAndFamily);
176 
177  fmt.dwEffects &= ~(mod->dwMask);
178  fmt.dwEffects |= mod->dwEffects & mod->dwMask;
179  fmt.dwMask |= mod->dwMask;
180  if (mod->dwMask & CFM_COLOR)
181  {
182  if (mod->dwEffects & CFE_AUTOCOLOR)
183  fmt.dwEffects |= CFE_AUTOCOLOR;
184  else
185  fmt.dwEffects &= ~CFE_AUTOCOLOR;
186  }
187 
188  COPY_STYLE_ITEM(CFM_UNDERLINETYPE, bUnderlineType);
189  /* If the CFM_UNDERLINE effect is not specified, set it appropriately */
190  if ((mod->dwMask & CFM_UNDERLINETYPE) && !(mod->dwMask & CFM_UNDERLINE))
191  {
192  fmt.dwMask |= CFM_UNDERLINE;
193  if (mod->bUnderlineType == CFU_UNDERLINENONE)
194  fmt.dwEffects &= ~CFE_UNDERLINE;
195  else
196  fmt.dwEffects |= CFE_UNDERLINE;
197  }
198 
199  if (mod->dwMask & CFM_BOLD && !(mod->dwMask & CFM_WEIGHT))
200  {
201  fmt.wWeight = (mod->dwEffects & CFE_BOLD) ? FW_BOLD : FW_NORMAL;
202  } else if (mod->dwMask & CFM_WEIGHT && !(mod->dwMask & CFM_BOLD)) {
203  if (mod->wWeight > FW_NORMAL)
204  fmt.dwEffects |= CFE_BOLD;
205  else
206  fmt.dwEffects &= ~CFE_BOLD;
207  }
208 
210  {
211  if (!memcmp( &s->fmt, &fmt, sizeof(fmt) ))
212  {
213  TRACE_(richedit_style)("found existing style %p\n", s);
214  ME_AddRefStyle( s );
215  return s;
216  }
217  }
218 
219  s = ME_MakeStyle( &fmt );
220  if (s)
221  list_add_head( &editor->style_list, &s->entry );
222  TRACE_(richedit_style)("created new style %p\n", s);
223  return s;
224 }
struct list style_list
Definition: editstr.h:447
#define CFM_KERNING
Definition: richedit.h:352
#define CFE_AUTOCOLOR
Definition: richedit.h:414
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
#define CFE_UNDERLINE
Definition: richedit.h:408
#define CFM_REVAUTHOR
Definition: richedit.h:347
#define CFM_FACE
Definition: richedit.h:360
__WINE_SERVER_LIST_INLINE void list_add_head(struct list *list, struct list *elem)
Definition: list.h:96
#define assert(x)
Definition: debug.h:53
#define CFM_ANIMATION
Definition: richedit.h:350
#define CFM_STYLE
Definition: richedit.h:351
#define yHeightCharPtsMost
Definition: richedit.h:214
#define COPY_STYLE_ITEM(mask, member)
Definition: style.c:134
#define CFE_BOLD
Definition: richedit.h:406
#define CFU_UNDERLINENONE
Definition: richedit.h:427
#define LIST_FOR_EACH_ENTRY(elem, list, type, field)
Definition: list.h:198
#define CFM_COLOR
Definition: richedit.h:361
#define CFM_UNDERLINE
Definition: richedit.h:334
#define CFM_LCID
Definition: richedit.h:356
#define TRACE_(x)
Definition: compat.h:66
#define CFM_SIZE
Definition: richedit.h:362
#define CFM_OFFSET
Definition: richedit.h:359
#define CFM_SPACING
Definition: richedit.h:353
void ME_AddRefStyle(ME_Style *s)
Definition: style.c:435
uint32_t entry
Definition: isohybrid.c:63
GLdouble s
Definition: gl.h:2039
#define FW_BOLD
Definition: wingdi.h:377
#define CFM_BOLD
Definition: richedit.h:332
#define min(a, b)
Definition: monoChain.cc:55
#define CFM_WEIGHT
Definition: richedit.h:354
#define FW_NORMAL
Definition: wingdi.h:372
#define CFM_BACKCOLOR
Definition: richedit.h:357
int yOffset
Definition: appswitch.c:59
#define COPY_STYLE_ITEM_MEMCPY(mask, member)
Definition: style.c:140
#define CFM_UNDERLINETYPE
Definition: richedit.h:355
ME_Style * ME_MakeStyle(CHARFORMAT2W *style)
Definition: style.c:117
CHARFORMAT2W fmt
Definition: editstr.h:77
Definition: dsound.c:943
#define CFM_CHARSET
Definition: richedit.h:358
static int mod
Definition: i386-dis.c:1273

Referenced by ME_RTFCharAttrHook(), ME_SetCharFormat(), ME_SetDefaultCharFormat(), ME_SetSelectionCharFormat(), and para_num_init().

◆ ME_CharFormatFromLogFont()

void ME_CharFormatFromLogFont ( HDC  hDC,
const LOGFONTW lf,
CHARFORMAT2W fmt 
)

Definition at line 327 of file style.c.

328 {
329  int ry;
330 
333  lstrcpyW(fmt->szFaceName, lf->lfFaceName);
334  fmt->dwEffects = 0;
336  fmt->wWeight = lf->lfWeight;
337  fmt->yHeight = -lf->lfHeight*1440/ry;
338  if (lf->lfWeight > FW_NORMAL) fmt->dwEffects |= CFM_BOLD;
339  if (lf->lfItalic) fmt->dwEffects |= CFM_ITALIC;
340  if (lf->lfUnderline) fmt->dwEffects |= CFM_UNDERLINE;
341  fmt->bUnderlineType = CFU_UNDERLINE;
342  if (lf->lfStrikeOut) fmt->dwEffects |= CFM_STRIKEOUT;
343  fmt->bPitchAndFamily = lf->lfPitchAndFamily;
344  fmt->bCharSet = lf->lfCharSet;
345 }
BYTE lfPitchAndFamily
Definition: dimm.idl:71
#define CFU_UNDERLINE
Definition: richedit.h:428
LONG lfHeight
Definition: dimm.idl:59
BYTE lfCharSet
Definition: dimm.idl:67
#define CFM_FACE
Definition: richedit.h:360
#define CFM_ITALIC
Definition: richedit.h:333
void ME_InitCharFormat2W(CHARFORMAT2W *pFmt)
Definition: style.c:146
#define CFM_UNDERLINE
Definition: richedit.h:334
#define CFM_SIZE
Definition: richedit.h:362
int WINAPI GetDeviceCaps(_In_opt_ HDC, _In_ int)
#define CFM_STRIKEOUT
Definition: richedit.h:335
static HDC hDC
Definition: 3dtext.c:33
#define lstrcpyW
Definition: compat.h:406
#define CFM_BOLD
Definition: richedit.h:332
BYTE lfStrikeOut
Definition: dimm.idl:66
BYTE lfItalic
Definition: dimm.idl:64
#define CFM_WEIGHT
Definition: richedit.h:354
#define FW_NORMAL
Definition: wingdi.h:372
WCHAR lfFaceName[LF_FACESIZE]
Definition: dimm.idl:72
#define LOGPIXELSY
Definition: wingdi.h:718
LONG lfWeight
Definition: dimm.idl:63
BYTE lfUnderline
Definition: dimm.idl:65
#define CFM_UNDERLINETYPE
Definition: richedit.h:355
Definition: dsound.c:943
#define CFM_CHARSET
Definition: richedit.h:358

Referenced by ME_HandleMessage().

◆ ME_ClearTempStyle()

void ME_ClearTempStyle ( ME_TextEditor editor)

Definition at line 504 of file style.c.

505 {
506  if (!editor->pBuffer->pCharStyle) return;
508  editor->pBuffer->pCharStyle = NULL;
509 }
ME_Style * pCharStyle
Definition: editstr.h:273
ME_TextBuffer * pBuffer
Definition: editstr.h:390
smooth NULL
Definition: ftsmooth.c:416
void ME_ReleaseStyle(ME_Style *s)
Definition: style.c:443

Referenced by ME_DestroyEditor(), ME_HandleMessage(), ME_ReplaceSel(), ME_SendSelChange(), and ME_StreamIn().

◆ ME_CopyCharFormat()

void ME_CopyCharFormat ( CHARFORMAT2W pDest,
const CHARFORMAT2W pSrc 
)

Definition at line 226 of file style.c.

227 {
228  /* using this with non-2W structs is forbidden */
229  assert(pSrc->cbSize == sizeof(CHARFORMAT2W));
230  assert(pDest->cbSize == sizeof(CHARFORMAT2W));
231  *pDest = *pSrc;
232 }
#define assert(x)
Definition: debug.h:53

Referenced by ME_GetDefaultCharFormat(), ME_GetRunCharFormat(), and ME_GetSelectionCharFormat().

◆ ME_DestroyStyle()

void ME_DestroyStyle ( ME_Style s)

Definition at line 423 of file style.c.

424 {
425  list_remove( &s->entry );
426  if (s->font_cache)
427  {
428  release_font_cache( s->font_cache );
429  s->font_cache = NULL;
430  }
431  ScriptFreeCache( &s->script_cache );
432  heap_free(s);
433 }
static void release_font_cache(ME_FontCacheItem *item)
Definition: style.c:407
smooth NULL
Definition: ftsmooth.c:416
__WINE_SERVER_LIST_INLINE void list_remove(struct list *elem)
Definition: list.h:108
GLdouble s
Definition: gl.h:2039
HRESULT WINAPI ScriptFreeCache(SCRIPT_CACHE *psc)
Definition: usp10.c:1078
static BOOL heap_free(void *mem)
Definition: appwiz.h:75

Referenced by ME_DestroyEditor(), and ME_ReleaseStyle().

◆ ME_DumpStyle()

void ME_DumpStyle ( ME_Style s)

Definition at line 239 of file style.c.

240 {
241  char buf[2048];
242  ME_DumpStyleToBuf(&s->fmt, buf);
243  TRACE_(richedit_style)("%s\n", buf);
244 }
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define TRACE_(x)
Definition: compat.h:66
void ME_DumpStyleToBuf(CHARFORMAT2W *pFmt, char buf[2048])
Definition: style.c:246
GLdouble s
Definition: gl.h:2039

◆ ME_DumpStyleEffect()

static void ME_DumpStyleEffect ( char **  p,
const char name,
const CHARFORMAT2W fmt,
int  mask 
)
static

Definition at line 234 of file style.c.

235 {
236  *p += sprintf(*p, "%-22s%s\n", name, (fmt->dwMask & mask) ? ((fmt->dwEffects & mask) ? "YES" : "no") : "N/A");
237 }
#define sprintf(buf, format,...)
Definition: sprintf.c:55
GLenum GLint GLuint mask
Definition: glext.h:6028
Definition: name.c:36
GLfloat GLfloat p
Definition: glext.h:8902
Definition: dsound.c:943

Referenced by ME_DumpStyleToBuf().

◆ ME_DumpStyleToBuf()

void ME_DumpStyleToBuf ( CHARFORMAT2W pFmt,
char  buf[2048] 
)

Definition at line 246 of file style.c.

247 {
248  /* FIXME only CHARFORMAT styles implemented */
249  /* this function sucks, doesn't check for buffer overruns but it's "good enough" as for debug code */
250  char *p;
251  p = buf;
252  p += sprintf(p, "Font face: ");
253  if (pFmt->dwMask & CFM_FACE) {
254  WCHAR *q = pFmt->szFaceName;
255  while(*q) {
256  *p++ = (*q > 255) ? '?' : *q;
257  q++;
258  }
259  } else
260  p += sprintf(p, "N/A");
261 
262  if (pFmt->dwMask & CFM_SIZE)
263  p += sprintf(p, "\nFont size: %d\n", pFmt->yHeight);
264  else
265  p += sprintf(p, "\nFont size: N/A\n");
266 
267  if (pFmt->dwMask & CFM_OFFSET)
268  p += sprintf(p, "Char offset: %d\n", pFmt->yOffset);
269  else
270  p += sprintf(p, "Char offset: N/A\n");
271 
272  if (pFmt->dwMask & CFM_CHARSET)
273  p += sprintf(p, "Font charset: %d\n", (int)pFmt->bCharSet);
274  else
275  p += sprintf(p, "Font charset: N/A\n");
276 
277  /* I'm assuming CFM_xxx and CFE_xxx are the same values, fortunately it IS true wrt used flags*/
278  ME_DumpStyleEffect(&p, "Font bold:", pFmt, CFM_BOLD);
279  ME_DumpStyleEffect(&p, "Font italic:", pFmt, CFM_ITALIC);
280  ME_DumpStyleEffect(&p, "Font underline:", pFmt, CFM_UNDERLINE);
281  ME_DumpStyleEffect(&p, "Font strikeout:", pFmt, CFM_STRIKEOUT);
282  ME_DumpStyleEffect(&p, "Hidden text:", pFmt, CFM_HIDDEN);
283  p += sprintf(p, "Text color: ");
284  if (pFmt->dwMask & CFM_COLOR)
285  {
286  if (pFmt->dwEffects & CFE_AUTOCOLOR)
287  p += sprintf(p, "auto\n");
288  else
289  p += sprintf(p, "%06x\n", (int)pFmt->crTextColor);
290  }
291  else
292  p += sprintf(p, "N/A\n");
293  ME_DumpStyleEffect(&p, "Text protected:", pFmt, CFM_PROTECTED);
294 }
#define CFE_AUTOCOLOR
Definition: richedit.h:414
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define CFM_FACE
Definition: richedit.h:360
#define CFM_PROTECTED
Definition: richedit.h:336
#define CFM_ITALIC
Definition: richedit.h:333
#define sprintf(buf, format,...)
Definition: sprintf.c:55
#define CFM_COLOR
Definition: richedit.h:361
DWORD dwEffects
Definition: richedit.h:307
#define CFM_UNDERLINE
Definition: richedit.h:334
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define CFM_SIZE
Definition: richedit.h:362
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
static void ME_DumpStyleEffect(char **p, const char *name, const CHARFORMAT2W *fmt, int mask)
Definition: style.c:234
#define CFM_OFFSET
Definition: richedit.h:359
WCHAR szFaceName[LF_FACESIZE]
Definition: richedit.h:313
#define CFM_STRIKEOUT
Definition: richedit.h:335
COLORREF crTextColor
Definition: richedit.h:310
#define CFM_HIDDEN
Definition: richedit.h:340
#define CFM_BOLD
Definition: richedit.h:332
BYTE bCharSet
Definition: richedit.h:311
DWORD dwMask
Definition: richedit.h:306
GLfloat GLfloat p
Definition: glext.h:8902
LONG yHeight
Definition: richedit.h:308
#define CFM_CHARSET
Definition: richedit.h:358
LONG yOffset
Definition: richedit.h:309

Referenced by ME_DumpStyle(), and ME_KeyDown().

◆ ME_GetInsertStyle()

ME_Style* ME_GetInsertStyle ( ME_TextEditor editor,
int  nCursor 
)

Definition at line 457 of file style.c.

458 {
459  if (ME_IsSelection(editor))
460  {
461  ME_Cursor *from, *to;
462 
463  ME_GetSelection(editor, &from, &to);
464  ME_AddRefStyle(from->pRun->member.run.style);
465  return from->pRun->member.run.style;
466  }
467  if (editor->pBuffer->pCharStyle) {
469  return editor->pBuffer->pCharStyle;
470  }
471  else
472  {
473  ME_Cursor *pCursor = &editor->pCursors[nCursor];
474  ME_DisplayItem *pRunItem = pCursor->pRun;
475  ME_DisplayItem *pPrevItem = NULL;
476  if (pCursor->nOffset) {
477  ME_Run *pRun = &pRunItem->member.run;
478  ME_AddRefStyle(pRun->style);
479  return pRun->style;
480  }
481  pPrevItem = ME_FindItemBack(pRunItem, diRunOrParagraph);
482  if (pPrevItem->type == diRun)
483  {
484  ME_AddRefStyle(pPrevItem->member.run.style);
485  return pPrevItem->member.run.style;
486  }
487  else
488  {
489  ME_AddRefStyle(pRunItem->member.run.style);
490  return pRunItem->member.run.style;
491  }
492  }
493 }
ME_DIType type
Definition: editstr.h:260
ME_Style * pCharStyle
Definition: editstr.h:273
ME_Style * style
Definition: editstr.h:164
union tagME_DisplayItem::@523 member
ME_TextBuffer * pBuffer
Definition: editstr.h:390
smooth NULL
Definition: ftsmooth.c:416
int ME_GetSelection(ME_TextEditor *editor, ME_Cursor **from, ME_Cursor **to)
Definition: caret.c:57
Definition: editstr.h:91
void ME_AddRefStyle(ME_Style *s)
Definition: style.c:435
int nOffset
Definition: editstr.h:281
ME_Cursor * pCursors
Definition: editstr.h:391
ME_DisplayItem * pRun
Definition: editstr.h:280
BOOL ME_IsSelection(ME_TextEditor *editor)
Definition: caret.c:1521
CardRegion * from
Definition: spigame.cpp:19
ME_DisplayItem * ME_FindItemBack(ME_DisplayItem *di, ME_DIType nTypeOrClass) DECLSPEC_HIDDEN
Definition: list.c:111

Referenced by handle_enter(), ITextRange_fnSetText(), ME_Char(), ME_GetSelectionInsertStyle(), ME_HandleMessage(), ME_InsertEndParaFromCursor(), ME_InsertEndRowFromCursor(), ME_InsertOLEFromCursor(), and ME_SetSelectionCharFormat().

◆ ME_InitCharFormat2W()

void ME_InitCharFormat2W ( CHARFORMAT2W pFmt)

Definition at line 146 of file style.c.

147 {
148  ZeroMemory(pFmt, sizeof(CHARFORMAT2W));
149  pFmt->cbSize = sizeof(CHARFORMAT2W);
150 }
#define ZeroMemory
Definition: winbase.h:1642
struct _charformat2w CHARFORMAT2W

Referenced by ME_CharFormatFromLogFont(), and ME_JoinParagraphs().

◆ ME_IsFontEqual()

static BOOL ME_IsFontEqual ( const LOGFONTW p1,
const LOGFONTW p2 
)
static

Definition at line 347 of file style.c.

348 {
349  if (memcmp(p1, p2, sizeof(LOGFONTW)-sizeof(p1->lfFaceName)))
350  return FALSE;
351  if (lstrcmpW(p1->lfFaceName, p2->lfFaceName))
352  return FALSE;
353  return TRUE;
354 }
#define TRUE
Definition: types.h:120
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
int WINAPI lstrcmpW(LPCWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:170
WCHAR lfFaceName[LF_FACESIZE]
Definition: dimm.idl:72

Referenced by ME_SelectStyleFont().

◆ ME_LogFontFromStyle()

static void ME_LogFontFromStyle ( ME_Context c,
LOGFONTW lf,
const ME_Style s 
)
static

Definition at line 298 of file style.c.

299 {
300  ZeroMemory(lf, sizeof(LOGFONTW));
301  lstrcpyW(lf->lfFaceName, s->fmt.szFaceName);
302 
303  lf->lfHeight = ME_twips2pointsY(c, -s->fmt.yHeight);
304 
305  lf->lfWeight = FW_NORMAL;
306  if (s->fmt.dwEffects & s->fmt.dwMask & CFM_BOLD)
307  lf->lfWeight = FW_BOLD;
308  if (s->fmt.dwMask & CFM_WEIGHT)
309  lf->lfWeight = s->fmt.wWeight;
310  if (s->fmt.dwEffects & s->fmt.dwMask & CFM_ITALIC)
311  lf->lfItalic = 1;
312  if ((s->fmt.dwEffects & s->fmt.dwMask & CFM_UNDERLINE) &&
313  !(s->fmt.dwEffects & CFE_LINK) &&
314  s->fmt.bUnderlineType == CFU_CF1UNDERLINE)
315  lf->lfUnderline = 1;
316  if (s->fmt.dwEffects & s->fmt.dwMask & CFM_STRIKEOUT)
317  lf->lfStrikeOut = 1;
318  if (s->fmt.dwEffects & s->fmt.dwMask & (CFM_SUBSCRIPT|CFM_SUPERSCRIPT))
319  lf->lfHeight = (lf->lfHeight*2)/3;
320 /*lf.lfQuality = PROOF_QUALITY; */
321  if (s->fmt.dwMask & CFM_FACE)
322  lf->lfPitchAndFamily = s->fmt.bPitchAndFamily;
323  if (s->fmt.dwMask & CFM_CHARSET)
324  lf->lfCharSet = s->fmt.bCharSet;
325 }
BYTE lfPitchAndFamily
Definition: dimm.idl:71
#define CFM_SUBSCRIPT
Definition: richedit.h:348
LONG lfHeight
Definition: dimm.idl:59
BYTE lfCharSet
Definition: dimm.idl:67
#define CFM_FACE
Definition: richedit.h:360
#define CFM_SUPERSCRIPT
Definition: richedit.h:349
#define ZeroMemory
Definition: winbase.h:1642
#define CFM_ITALIC
Definition: richedit.h:333
#define CFE_LINK
Definition: richedit.h:411
#define CFM_UNDERLINE
Definition: richedit.h:334
#define CFU_CF1UNDERLINE
Definition: richedit.h:447
const GLubyte * c
Definition: glext.h:8905
GLdouble s
Definition: gl.h:2039
#define CFM_STRIKEOUT
Definition: richedit.h:335
#define FW_BOLD
Definition: wingdi.h:377
#define lstrcpyW
Definition: compat.h:406
#define CFM_BOLD
Definition: richedit.h:332
BYTE lfStrikeOut
Definition: dimm.idl:66
BYTE lfItalic
Definition: dimm.idl:64
int ME_twips2pointsY(const ME_Context *c, int y) DECLSPEC_HIDDEN
Definition: paint.c:161
#define CFM_WEIGHT
Definition: richedit.h:354
#define FW_NORMAL
Definition: wingdi.h:372
WCHAR lfFaceName[LF_FACESIZE]
Definition: dimm.idl:72
LONG lfWeight
Definition: dimm.idl:63
BYTE lfUnderline
Definition: dimm.idl:65
#define CFM_CHARSET
Definition: richedit.h:358

Referenced by ME_SelectStyleFont().

◆ ME_MakeStyle()

ME_Style* ME_MakeStyle ( CHARFORMAT2W style)

Definition at line 117 of file style.c.

118 {
119  ME_Style *s = heap_alloc(sizeof(*s));
120 
121  assert(style->cbSize == sizeof(CHARFORMAT2W));
122  s->fmt = *style;
123  s->nRefs = 1;
124  s->font_cache = NULL;
125  memset(&s->tm, 0, sizeof(s->tm));
126  s->tm.tmAscent = -1;
127  s->script_cache = NULL;
128  list_init(&s->entry);
129  all_refs++;
130  TRACE_(richedit_style)("ME_MakeStyle %p, total refs=%d\n", s, all_refs);
131  return s;
132 }
#define assert(x)
Definition: debug.h:53
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
smooth NULL
Definition: ftsmooth.c:416
#define TRACE_(x)
Definition: compat.h:66
static int all_refs
Definition: style.c:26
GLdouble s
Definition: gl.h:2039
__WINE_SERVER_LIST_INLINE void list_init(struct list *list)
Definition: list.h:149
Arabic default style
Definition: afstyles.h:93
#define memset(x, y, z)
Definition: compat.h:39

Referenced by ME_ApplyStyle(), and ME_MakeFirstParagraph().

◆ ME_ReleaseStyle()

void ME_ReleaseStyle ( ME_Style s)

Definition at line 443 of file style.c.

444 {
445  s->nRefs--;
446  all_refs--;
447  if (s->nRefs==0)
448  TRACE_(richedit_style)("destroy style %p, total refs=%d\n", s, all_refs);
449  else
450  TRACE_(richedit_style)("release style %p, new refs=%d, total refs=%d\n", s, s->nRefs, all_refs);
451  if (!all_refs) TRACE("all style references freed (good!)\n");
452  assert(s->nRefs>=0);
453  if (!s->nRefs)
455 }
void ME_DestroyStyle(ME_Style *s)
Definition: style.c:423
#define assert(x)
Definition: debug.h:53
#define TRACE_(x)
Definition: compat.h:66
#define TRACE(s)
Definition: solgame.cpp:4
static int all_refs
Definition: style.c:26
GLdouble s
Definition: gl.h:2039

Referenced by destroy_undo_item(), handle_enter(), ITextRange_fnSetText(), ME_Char(), ME_ClearTempStyle(), ME_DestroyDisplayItem(), ME_DestroyEditor(), ME_HandleMessage(), ME_InsertEndParaFromCursor(), ME_InsertEndRowFromCursor(), ME_InsertOLEFromCursor(), ME_ReplaceSel(), ME_RTFCharAttrHook(), ME_RTFReadHook(), ME_SaveTempStyle(), ME_SetCharFormat(), ME_SetDefaultCharFormat(), ME_SetSelectionCharFormat(), ME_StreamIn(), and para_num_clear().

◆ ME_SaveTempStyle()

void ME_SaveTempStyle ( ME_TextEditor editor,
ME_Style style 
)

Definition at line 495 of file style.c.

496 {
497  ME_Style *old_style = editor->pBuffer->pCharStyle;
498 
499  if (style) ME_AddRefStyle( style );
500  editor->pBuffer->pCharStyle = style;
501  if (old_style) ME_ReleaseStyle( old_style );
502 }
ME_Style * pCharStyle
Definition: editstr.h:273
ME_TextBuffer * pBuffer
Definition: editstr.h:390
void ME_AddRefStyle(ME_Style *s)
Definition: style.c:435
void ME_ReleaseStyle(ME_Style *s)
Definition: style.c:443
Arabic default style
Definition: afstyles.h:93

Referenced by handle_enter(), and ME_HandleMessage().

◆ ME_SelectStyleFont()

HFONT ME_SelectStyleFont ( ME_Context c,
ME_Style s 
)

Definition at line 356 of file style.c.

357 {
358  HFONT hOldFont;
359  LOGFONTW lf;
360  int i, nEmpty, nAge = 0x7FFFFFFF;
362  assert(s);
363 
364  ME_LogFontFromStyle(c, &lf, s);
365 
366  for (i=0; i<HFONT_CACHE_SIZE; i++)
367  c->editor->pFontCache[i].nAge++;
368  for (i=0, nEmpty=-1, nAge=0; i<HFONT_CACHE_SIZE; i++)
369  {
370  item = &c->editor->pFontCache[i];
371  if (!item->nRefs)
372  {
373  if (item->nAge > nAge)
374  nEmpty = i, nAge = item->nAge;
375  }
376  if (item->hFont && ME_IsFontEqual(&item->lfSpecs, &lf))
377  break;
378  }
379  if (i < HFONT_CACHE_SIZE) /* found */
380  {
381  item = &c->editor->pFontCache[i];
382  TRACE_(richedit_style)("font reused %d\n", i);
383  item->nRefs++;
384  }
385  else
386  {
387  item = &c->editor->pFontCache[nEmpty]; /* this legal even when nEmpty == -1, as we don't dereference it */
388 
389  assert(nEmpty != -1); /* otherwise we leak cache entries or get too many fonts at once*/
390  if (item->hFont) {
391  TRACE_(richedit_style)("font deleted %d\n", nEmpty);
392  DeleteObject(item->hFont);
393  item->hFont = NULL;
394  }
395  item->hFont = CreateFontIndirectW(&lf);
396  TRACE_(richedit_style)("font created %d\n", nEmpty);
397  item->nRefs = 1;
398  item->lfSpecs = lf;
399  }
400  s->font_cache = item;
401  hOldFont = SelectObject(c->hDC, item->hFont);
402  /* should be cached too, maybe ? */
403  GetTextMetricsW(c->hDC, &s->tm);
404  return hOldFont;
405 }
BOOL WINAPI GetTextMetricsW(_In_ HDC, _Out_ LPTEXTMETRICW)
Definition: text.c:221
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1497
#define assert(x)
Definition: debug.h:53
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
static BOOL ME_IsFontEqual(const LOGFONTW *p1, const LOGFONTW *p2)
Definition: style.c:347
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
smooth NULL
Definition: ftsmooth.c:416
HFONT WINAPI CreateFontIndirectW(_In_ const LOGFONTW *)
#define TRACE_(x)
Definition: compat.h:66
const GLubyte * c
Definition: glext.h:8905
#define for
Definition: utility.h:88
static void ME_LogFontFromStyle(ME_Context *c, LOGFONTW *lf, const ME_Style *s)
Definition: style.c:298
GLdouble s
Definition: gl.h:2039
static ATOM item
Definition: dde.c:856
#define HFONT_CACHE_SIZE
Definition: editstr.h:73
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)

Referenced by draw_para_number(), draw_space(), ME_CharFromPointContext(), ME_DrawTextWithStyle(), ME_GetTextExtent(), para_num_init(), and shape_run().

◆ ME_SetDefaultCharFormat()

void ME_SetDefaultCharFormat ( ME_TextEditor editor,
CHARFORMAT2W mod 
)

Definition at line 521 of file style.c.

522 {
523  ME_Style *style, *def = editor->pBuffer->pDefaultStyle;
524 
525  assert(mod->cbSize == sizeof(CHARFORMAT2W));
526  style = ME_ApplyStyle(editor, def, mod);
527  def->fmt = style->fmt;
528  def->tm = style->tm;
529  if (def->font_cache)
530  {
532  def->font_cache = NULL;
533  }
534  ScriptFreeCache( &def->script_cache );
536  ME_MarkAllForWrapping( editor );
537 }
#define assert(x)
Definition: debug.h:53
TEXTMETRICW tm
Definition: editstr.h:80
static void release_font_cache(ME_FontCacheItem *item)
Definition: style.c:407
ME_TextBuffer * pBuffer
Definition: editstr.h:390
smooth NULL
Definition: ftsmooth.c:416
ME_Style * pDefaultStyle
Definition: editstr.h:274
ME_FontCacheItem * font_cache
Definition: editstr.h:79
void ME_ReleaseStyle(ME_Style *s)
Definition: style.c:443
void ME_MarkAllForWrapping(ME_TextEditor *editor) DECLSPEC_HIDDEN
Definition: para.c:236
SCRIPT_CACHE script_cache
Definition: editstr.h:82
HRESULT WINAPI ScriptFreeCache(SCRIPT_CACHE *psc)
Definition: usp10.c:1078
ME_Style * ME_ApplyStyle(ME_TextEditor *editor, ME_Style *sSrc, CHARFORMAT2W *mod)
Definition: style.c:152
Arabic default style
Definition: afstyles.h:93
CHARFORMAT2W fmt
Definition: editstr.h:77
static int mod
Definition: i386-dis.c:1273

Referenced by ME_HandleMessage(), and ME_MakeFirstParagraph().

◆ ME_UnselectStyleFont()

void ME_UnselectStyleFont ( ME_Context c,
ME_Style s,
HFONT  hOldFont 
)

Definition at line 416 of file style.c.

417 {
418  SelectObject(c->hDC, hOldFont);
419  release_font_cache(s->font_cache);
420  s->font_cache = NULL;
421 }
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1497
static void release_font_cache(ME_FontCacheItem *item)
Definition: style.c:407
smooth NULL
Definition: ftsmooth.c:416
const GLubyte * c
Definition: glext.h:8905
GLdouble s
Definition: gl.h:2039

Referenced by draw_para_number(), draw_space(), ME_CharFromPointContext(), ME_DrawTextWithStyle(), ME_GetTextExtent(), para_num_init(), and shape_run().

◆ release_font_cache()

static void release_font_cache ( ME_FontCacheItem item)
static

Definition at line 407 of file style.c.

408 {
409  if (item->nRefs > 0)
410  {
411  item->nRefs--;
412  item->nAge = 0;
413  }
414 }
static ATOM item
Definition: dde.c:856

Referenced by ME_DestroyStyle(), ME_SetDefaultCharFormat(), and ME_UnselectStyleFont().

◆ WINE_DECLARE_DEBUG_CHANNEL()

WINE_DECLARE_DEBUG_CHANNEL ( richedit_style  )

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( richedit  )

Variable Documentation

◆ all_refs

int all_refs = 0
static

Definition at line 26 of file style.c.

Referenced by ME_AddRefStyle(), ME_MakeStyle(), and ME_ReleaseStyle().