2005-03-05 12:19:14 +01:00
|
|
|
/*
|
|
|
|
* RichEdit style management functions
|
|
|
|
*
|
|
|
|
* Copyright 2004 by Krzysztof Foltman
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-03-05 12:19:14 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "editor.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(richedit);
|
2005-10-12 23:05:52 +02:00
|
|
|
WINE_DECLARE_DEBUG_CHANNEL(richedit_style);
|
2005-03-05 12:19:14 +01:00
|
|
|
|
|
|
|
static int all_refs = 0;
|
|
|
|
|
2008-01-01 22:03:28 +01:00
|
|
|
/* the following routines assume that:
|
|
|
|
* - char2[AW] extends char[AW] by adding fields at the end of the charA form)
|
|
|
|
* - szFaceName is the last field of char[AW] form, and wWeight the first of 2[AW]
|
|
|
|
* - the difference between A and W form is the szFaceName as Ansi vs Unicode string
|
|
|
|
* - because of alignment, offset of wWeight field in 2[AW] structure *IS NOT*
|
|
|
|
* sizeof(char[AW])
|
|
|
|
*/
|
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
CHARFORMAT2W *ME_ToCF2W(CHARFORMAT2W *to, CHARFORMAT2W *from)
|
|
|
|
{
|
|
|
|
if (from->cbSize == sizeof(CHARFORMATA))
|
|
|
|
{
|
|
|
|
CHARFORMATA *f = (CHARFORMATA *)from;
|
2008-01-01 22:03:28 +01:00
|
|
|
CopyMemory(to, f, FIELD_OFFSET(CHARFORMATA, szFaceName));
|
2005-03-05 12:19:14 +01:00
|
|
|
to->cbSize = sizeof(CHARFORMAT2W);
|
|
|
|
if (f->dwMask & CFM_FACE) {
|
2012-09-24 13:04:26 +02:00
|
|
|
MultiByteToWideChar(CP_ACP, 0, f->szFaceName, -1, to->szFaceName, sizeof(to->szFaceName)/sizeof(WCHAR));
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
return to;
|
|
|
|
}
|
|
|
|
if (from->cbSize == sizeof(CHARFORMATW))
|
|
|
|
{
|
|
|
|
CHARFORMATW *f = (CHARFORMATW *)from;
|
|
|
|
CopyMemory(to, f, sizeof(*f));
|
|
|
|
/* theoretically, we don't need to zero the remaining memory */
|
2008-01-01 22:03:28 +01:00
|
|
|
ZeroMemory(&to->wWeight, sizeof(CHARFORMAT2W)-FIELD_OFFSET(CHARFORMAT2W, wWeight));
|
2005-03-05 12:19:14 +01:00
|
|
|
to->cbSize = sizeof(CHARFORMAT2W);
|
|
|
|
return to;
|
|
|
|
}
|
|
|
|
if (from->cbSize == sizeof(CHARFORMAT2A))
|
|
|
|
{
|
2008-01-01 22:03:28 +01:00
|
|
|
CHARFORMAT2A *f = (CHARFORMAT2A *)from;
|
2005-03-05 12:19:14 +01:00
|
|
|
/* copy the A structure without face name */
|
2008-01-01 22:03:28 +01:00
|
|
|
CopyMemory(to, f, FIELD_OFFSET(CHARFORMATA, szFaceName));
|
2005-03-05 12:19:14 +01:00
|
|
|
/* convert face name */
|
|
|
|
if (f->dwMask & CFM_FACE)
|
2012-09-24 13:04:26 +02:00
|
|
|
MultiByteToWideChar(CP_ACP, 0, f->szFaceName, -1, to->szFaceName, sizeof(to->szFaceName)/sizeof(WCHAR));
|
2005-03-05 12:19:14 +01:00
|
|
|
/* copy the rest of the 2A structure to 2W */
|
2008-01-01 22:03:28 +01:00
|
|
|
CopyMemory(&to->wWeight, &f->wWeight, sizeof(CHARFORMAT2A)-FIELD_OFFSET(CHARFORMAT2A, wWeight));
|
2005-03-05 12:19:14 +01:00
|
|
|
to->cbSize = sizeof(CHARFORMAT2W);
|
|
|
|
return to;
|
|
|
|
}
|
|
|
|
|
2007-09-26 19:58:24 +02:00
|
|
|
return (from->cbSize >= sizeof(CHARFORMAT2W)) ? from : NULL;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
2009-01-17 17:27:08 +01:00
|
|
|
static CHARFORMAT2W *ME_ToCFAny(CHARFORMAT2W *to, CHARFORMAT2W *from)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
|
|
|
assert(from->cbSize == sizeof(CHARFORMAT2W));
|
|
|
|
if (to->cbSize == sizeof(CHARFORMATA))
|
|
|
|
{
|
|
|
|
CHARFORMATA *t = (CHARFORMATA *)to;
|
2008-01-01 22:03:28 +01:00
|
|
|
CopyMemory(t, from, FIELD_OFFSET(CHARFORMATA, szFaceName));
|
2012-09-24 13:04:26 +02:00
|
|
|
WideCharToMultiByte(CP_ACP, 0, from->szFaceName, -1, t->szFaceName, sizeof(t->szFaceName), NULL, NULL);
|
2005-03-05 12:19:14 +01:00
|
|
|
t->cbSize = sizeof(*t); /* it was overwritten by CopyMemory */
|
|
|
|
return to;
|
|
|
|
}
|
|
|
|
if (to->cbSize == sizeof(CHARFORMATW))
|
|
|
|
{
|
|
|
|
CHARFORMATW *t = (CHARFORMATW *)to;
|
|
|
|
CopyMemory(t, from, sizeof(*t));
|
|
|
|
t->cbSize = sizeof(*t); /* it was overwritten by CopyMemory */
|
|
|
|
return to;
|
|
|
|
}
|
|
|
|
if (to->cbSize == sizeof(CHARFORMAT2A))
|
|
|
|
{
|
|
|
|
CHARFORMAT2A *t = (CHARFORMAT2A *)to;
|
|
|
|
/* copy the A structure without face name */
|
2008-01-01 22:03:28 +01:00
|
|
|
CopyMemory(t, from, FIELD_OFFSET(CHARFORMATA, szFaceName));
|
2005-03-05 12:19:14 +01:00
|
|
|
/* convert face name */
|
2012-09-24 13:04:26 +02:00
|
|
|
WideCharToMultiByte(CP_ACP, 0, from->szFaceName, -1, t->szFaceName, sizeof(t->szFaceName), NULL, NULL);
|
2005-03-05 12:19:14 +01:00
|
|
|
/* copy the rest of the 2A structure to 2W */
|
2008-01-01 22:03:28 +01:00
|
|
|
CopyMemory(&t->wWeight, &from->wWeight, sizeof(CHARFORMAT2W)-FIELD_OFFSET(CHARFORMAT2W,wWeight));
|
2005-03-05 12:19:14 +01:00
|
|
|
t->cbSize = sizeof(*t); /* it was overwritten by CopyMemory */
|
|
|
|
return to;
|
|
|
|
}
|
2008-01-01 22:03:28 +01:00
|
|
|
assert(to->cbSize >= sizeof(CHARFORMAT2W));
|
2005-03-05 12:19:14 +01:00
|
|
|
return from;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ME_CopyToCFAny(CHARFORMAT2W *to, CHARFORMAT2W *from)
|
|
|
|
{
|
|
|
|
if (ME_ToCFAny(to, from) == from)
|
|
|
|
CopyMemory(to, from, to->cbSize);
|
|
|
|
}
|
|
|
|
|
2010-07-29 20:06:08 +02:00
|
|
|
ME_Style *ME_MakeStyle(CHARFORMAT2W *style)
|
|
|
|
{
|
2018-02-03 23:59:47 +01:00
|
|
|
ME_Style *s = heap_alloc(sizeof(*s));
|
2005-03-05 12:19:14 +01:00
|
|
|
|
2010-07-29 20:06:08 +02:00
|
|
|
assert(style->cbSize == sizeof(CHARFORMAT2W));
|
|
|
|
s->fmt = *style;
|
2005-03-05 12:19:14 +01:00
|
|
|
s->nRefs = 1;
|
2015-11-09 17:11:41 +01:00
|
|
|
s->font_cache = NULL;
|
2010-07-29 20:06:08 +02:00
|
|
|
memset(&s->tm, 0, sizeof(s->tm));
|
2005-04-16 12:48:35 +02:00
|
|
|
s->tm.tmAscent = -1;
|
2014-01-15 14:06:43 +01:00
|
|
|
s->script_cache = NULL;
|
2015-11-09 17:11:43 +01:00
|
|
|
list_init(&s->entry);
|
2005-03-05 12:19:14 +01:00
|
|
|
all_refs++;
|
2009-08-10 16:53:53 +02:00
|
|
|
TRACE_(richedit_style)("ME_MakeStyle %p, total refs=%d\n", s, all_refs);
|
2005-03-05 12:19:14 +01:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define COPY_STYLE_ITEM(mask, member) \
|
2015-11-09 17:11:43 +01:00
|
|
|
if (mod->dwMask & mask) { \
|
|
|
|
fmt.dwMask |= mask;\
|
|
|
|
fmt.member = mod->member;\
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#define COPY_STYLE_ITEM_MEMCPY(mask, member) \
|
2015-11-09 17:11:43 +01:00
|
|
|
if (mod->dwMask & mask) { \
|
|
|
|
fmt.dwMask |= mask;\
|
|
|
|
CopyMemory(fmt.member, mod->member, sizeof(mod->member));\
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2010-07-29 20:06:08 +02:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
void ME_InitCharFormat2W(CHARFORMAT2W *pFmt)
|
|
|
|
{
|
|
|
|
ZeroMemory(pFmt, sizeof(CHARFORMAT2W));
|
|
|
|
pFmt->cbSize = sizeof(CHARFORMAT2W);
|
|
|
|
}
|
|
|
|
|
2015-11-09 17:11:43 +01:00
|
|
|
ME_Style *ME_ApplyStyle(ME_TextEditor *editor, ME_Style *sSrc, CHARFORMAT2W *mod)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2015-11-09 17:11:43 +01:00
|
|
|
CHARFORMAT2W fmt = sSrc->fmt;
|
|
|
|
ME_Style *s;
|
|
|
|
|
|
|
|
assert(mod->cbSize == sizeof(CHARFORMAT2W));
|
2005-03-05 12:19:14 +01:00
|
|
|
COPY_STYLE_ITEM(CFM_ANIMATION, bAnimation);
|
|
|
|
COPY_STYLE_ITEM(CFM_BACKCOLOR, crBackColor);
|
|
|
|
COPY_STYLE_ITEM(CFM_CHARSET, bCharSet);
|
|
|
|
COPY_STYLE_ITEM(CFM_COLOR, crTextColor);
|
|
|
|
COPY_STYLE_ITEM_MEMCPY(CFM_FACE, szFaceName);
|
|
|
|
COPY_STYLE_ITEM(CFM_KERNING, wKerning);
|
|
|
|
COPY_STYLE_ITEM(CFM_LCID, lcid);
|
|
|
|
COPY_STYLE_ITEM(CFM_OFFSET, yOffset);
|
|
|
|
COPY_STYLE_ITEM(CFM_REVAUTHOR, bRevAuthor);
|
2015-11-09 17:11:43 +01:00
|
|
|
if (mod->dwMask & CFM_SIZE) {
|
|
|
|
fmt.dwMask |= CFM_SIZE;
|
|
|
|
fmt.yHeight = min(mod->yHeight, yHeightCharPtsMost * 20);
|
2008-07-12 02:05:57 +02:00
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
COPY_STYLE_ITEM(CFM_SPACING, sSpacing);
|
|
|
|
COPY_STYLE_ITEM(CFM_STYLE, sStyle);
|
|
|
|
COPY_STYLE_ITEM(CFM_WEIGHT, wWeight);
|
2008-01-01 22:03:46 +01:00
|
|
|
/* FIXME: this is not documented this way, but that's the more logical */
|
|
|
|
COPY_STYLE_ITEM(CFM_FACE, bPitchAndFamily);
|
|
|
|
|
2015-11-09 17:11:43 +01:00
|
|
|
fmt.dwEffects &= ~(mod->dwMask);
|
|
|
|
fmt.dwEffects |= mod->dwEffects & mod->dwMask;
|
|
|
|
fmt.dwMask |= mod->dwMask;
|
|
|
|
if (mod->dwMask & CFM_COLOR)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2015-11-09 17:11:43 +01:00
|
|
|
if (mod->dwEffects & CFE_AUTOCOLOR)
|
|
|
|
fmt.dwEffects |= CFE_AUTOCOLOR;
|
2005-03-05 12:19:14 +01:00
|
|
|
else
|
2015-11-09 17:11:43 +01:00
|
|
|
fmt.dwEffects &= ~CFE_AUTOCOLOR;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2016-10-14 11:05:03 +02:00
|
|
|
|
|
|
|
COPY_STYLE_ITEM(CFM_UNDERLINETYPE, bUnderlineType);
|
2017-01-07 14:37:55 +01:00
|
|
|
/* If the CFM_UNDERLINE effect is not specified, set it appropriately */
|
2016-10-14 11:05:03 +02:00
|
|
|
if ((mod->dwMask & CFM_UNDERLINETYPE) && !(mod->dwMask & CFM_UNDERLINE))
|
2008-01-01 22:03:58 +01:00
|
|
|
{
|
2016-10-14 11:05:03 +02:00
|
|
|
fmt.dwMask |= CFM_UNDERLINE;
|
|
|
|
if (mod->bUnderlineType == CFU_UNDERLINENONE)
|
|
|
|
fmt.dwEffects &= ~CFE_UNDERLINE;
|
|
|
|
else
|
|
|
|
fmt.dwEffects |= CFE_UNDERLINE;
|
2008-01-01 22:03:58 +01:00
|
|
|
}
|
2016-10-14 11:05:03 +02:00
|
|
|
|
2015-11-09 17:11:43 +01:00
|
|
|
if (mod->dwMask & CFM_BOLD && !(mod->dwMask & CFM_WEIGHT))
|
2008-06-25 17:47:37 +02:00
|
|
|
{
|
2015-11-09 17:11:43 +01:00
|
|
|
fmt.wWeight = (mod->dwEffects & CFE_BOLD) ? FW_BOLD : FW_NORMAL;
|
|
|
|
} else if (mod->dwMask & CFM_WEIGHT && !(mod->dwMask & CFM_BOLD)) {
|
|
|
|
if (mod->wWeight > FW_NORMAL)
|
|
|
|
fmt.dwEffects |= CFE_BOLD;
|
2008-06-25 17:47:37 +02:00
|
|
|
else
|
2015-11-09 17:11:43 +01:00
|
|
|
fmt.dwEffects &= ~CFE_BOLD;
|
|
|
|
}
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(s, &editor->style_list, ME_Style, entry)
|
|
|
|
{
|
|
|
|
if (!memcmp( &s->fmt, &fmt, sizeof(fmt) ))
|
|
|
|
{
|
|
|
|
TRACE_(richedit_style)("found existing style %p\n", s);
|
|
|
|
ME_AddRefStyle( s );
|
|
|
|
return s;
|
|
|
|
}
|
2008-06-25 17:47:37 +02:00
|
|
|
}
|
2015-11-09 17:11:43 +01:00
|
|
|
|
|
|
|
s = ME_MakeStyle( &fmt );
|
|
|
|
if (s)
|
|
|
|
list_add_head( &editor->style_list, &s->entry );
|
|
|
|
TRACE_(richedit_style)("created new style %p\n", s);
|
2005-03-05 12:19:14 +01:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2007-08-16 22:57:12 +02:00
|
|
|
void ME_CopyCharFormat(CHARFORMAT2W *pDest, const CHARFORMAT2W *pSrc)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
|
|
|
/* using this with non-2W structs is forbidden */
|
|
|
|
assert(pSrc->cbSize == sizeof(CHARFORMAT2W));
|
|
|
|
assert(pDest->cbSize == sizeof(CHARFORMAT2W));
|
2008-03-16 21:47:01 +01:00
|
|
|
*pDest = *pSrc;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
2007-08-16 22:57:12 +02:00
|
|
|
static void ME_DumpStyleEffect(char **p, const char *name, const CHARFORMAT2W *fmt, int mask)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
|
|
|
*p += sprintf(*p, "%-22s%s\n", name, (fmt->dwMask & mask) ? ((fmt->dwEffects & mask) ? "YES" : "no") : "N/A");
|
|
|
|
}
|
|
|
|
|
|
|
|
void ME_DumpStyle(ME_Style *s)
|
|
|
|
{
|
|
|
|
char buf[2048];
|
|
|
|
ME_DumpStyleToBuf(&s->fmt, buf);
|
2005-10-12 23:05:52 +02:00
|
|
|
TRACE_(richedit_style)("%s\n", buf);
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ME_DumpStyleToBuf(CHARFORMAT2W *pFmt, char buf[2048])
|
|
|
|
{
|
|
|
|
/* FIXME only CHARFORMAT styles implemented */
|
|
|
|
/* this function sucks, doesn't check for buffer overruns but it's "good enough" as for debug code */
|
|
|
|
char *p;
|
|
|
|
p = buf;
|
|
|
|
p += sprintf(p, "Font face: ");
|
|
|
|
if (pFmt->dwMask & CFM_FACE) {
|
|
|
|
WCHAR *q = pFmt->szFaceName;
|
|
|
|
while(*q) {
|
|
|
|
*p++ = (*q > 255) ? '?' : *q;
|
|
|
|
q++;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
p += sprintf(p, "N/A");
|
|
|
|
|
|
|
|
if (pFmt->dwMask & CFM_SIZE)
|
2008-01-16 22:57:25 +01:00
|
|
|
p += sprintf(p, "\nFont size: %d\n", pFmt->yHeight);
|
2005-03-05 12:19:14 +01:00
|
|
|
else
|
|
|
|
p += sprintf(p, "\nFont size: N/A\n");
|
2008-01-16 22:57:25 +01:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
if (pFmt->dwMask & CFM_OFFSET)
|
2008-01-16 22:57:25 +01:00
|
|
|
p += sprintf(p, "Char offset: %d\n", pFmt->yOffset);
|
2005-03-05 12:19:14 +01:00
|
|
|
else
|
|
|
|
p += sprintf(p, "Char offset: N/A\n");
|
|
|
|
|
|
|
|
if (pFmt->dwMask & CFM_CHARSET)
|
|
|
|
p += sprintf(p, "Font charset: %d\n", (int)pFmt->bCharSet);
|
|
|
|
else
|
|
|
|
p += sprintf(p, "Font charset: N/A\n");
|
|
|
|
|
|
|
|
/* I'm assuming CFM_xxx and CFE_xxx are the same values, fortunately it IS true wrt used flags*/
|
|
|
|
ME_DumpStyleEffect(&p, "Font bold:", pFmt, CFM_BOLD);
|
|
|
|
ME_DumpStyleEffect(&p, "Font italic:", pFmt, CFM_ITALIC);
|
|
|
|
ME_DumpStyleEffect(&p, "Font underline:", pFmt, CFM_UNDERLINE);
|
|
|
|
ME_DumpStyleEffect(&p, "Font strikeout:", pFmt, CFM_STRIKEOUT);
|
2006-01-31 13:01:26 +01:00
|
|
|
ME_DumpStyleEffect(&p, "Hidden text:", pFmt, CFM_HIDDEN);
|
2005-03-05 12:19:14 +01:00
|
|
|
p += sprintf(p, "Text color: ");
|
|
|
|
if (pFmt->dwMask & CFM_COLOR)
|
|
|
|
{
|
|
|
|
if (pFmt->dwEffects & CFE_AUTOCOLOR)
|
|
|
|
p += sprintf(p, "auto\n");
|
|
|
|
else
|
|
|
|
p += sprintf(p, "%06x\n", (int)pFmt->crTextColor);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
p += sprintf(p, "N/A\n");
|
|
|
|
ME_DumpStyleEffect(&p, "Text protected:", pFmt, CFM_PROTECTED);
|
|
|
|
}
|
|
|
|
|
2005-07-24 18:17:43 +02:00
|
|
|
|
|
|
|
static void
|
2008-01-01 22:05:33 +01:00
|
|
|
ME_LogFontFromStyle(ME_Context* c, LOGFONTW *lf, const ME_Style *s)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2005-03-08 17:26:23 +01:00
|
|
|
ZeroMemory(lf, sizeof(LOGFONTW));
|
|
|
|
lstrcpyW(lf->lfFaceName, s->fmt.szFaceName);
|
2005-07-24 18:17:43 +02:00
|
|
|
|
2008-01-01 22:05:33 +01:00
|
|
|
lf->lfHeight = ME_twips2pointsY(c, -s->fmt.yHeight);
|
2005-07-24 18:17:43 +02:00
|
|
|
|
2008-03-16 21:47:39 +01:00
|
|
|
lf->lfWeight = FW_NORMAL;
|
2005-03-05 12:19:14 +01:00
|
|
|
if (s->fmt.dwEffects & s->fmt.dwMask & CFM_BOLD)
|
2008-03-16 21:47:39 +01:00
|
|
|
lf->lfWeight = FW_BOLD;
|
2008-01-01 22:03:34 +01:00
|
|
|
if (s->fmt.dwMask & CFM_WEIGHT)
|
2005-03-08 17:26:23 +01:00
|
|
|
lf->lfWeight = s->fmt.wWeight;
|
2005-03-05 12:19:14 +01:00
|
|
|
if (s->fmt.dwEffects & s->fmt.dwMask & CFM_ITALIC)
|
2005-03-08 17:26:23 +01:00
|
|
|
lf->lfItalic = 1;
|
2018-02-19 10:36:00 +01:00
|
|
|
if ((s->fmt.dwEffects & s->fmt.dwMask & CFM_UNDERLINE) &&
|
|
|
|
!(s->fmt.dwEffects & CFE_LINK) &&
|
2016-10-14 11:05:03 +02:00
|
|
|
s->fmt.bUnderlineType == CFU_CF1UNDERLINE)
|
2008-01-01 22:03:58 +01:00
|
|
|
lf->lfUnderline = 1;
|
2005-03-05 12:19:14 +01:00
|
|
|
if (s->fmt.dwEffects & s->fmt.dwMask & CFM_STRIKEOUT)
|
2005-03-08 17:26:23 +01:00
|
|
|
lf->lfStrikeOut = 1;
|
2005-06-12 12:43:24 +02:00
|
|
|
if (s->fmt.dwEffects & s->fmt.dwMask & (CFM_SUBSCRIPT|CFM_SUPERSCRIPT))
|
|
|
|
lf->lfHeight = (lf->lfHeight*2)/3;
|
2005-03-05 12:19:14 +01:00
|
|
|
/*lf.lfQuality = PROOF_QUALITY; */
|
2008-01-04 21:12:20 +01:00
|
|
|
if (s->fmt.dwMask & CFM_FACE)
|
|
|
|
lf->lfPitchAndFamily = s->fmt.bPitchAndFamily;
|
2008-01-04 21:12:03 +01:00
|
|
|
if (s->fmt.dwMask & CFM_CHARSET)
|
|
|
|
lf->lfCharSet = s->fmt.bCharSet;
|
2005-03-08 17:26:23 +01:00
|
|
|
}
|
|
|
|
|
2007-08-16 22:57:12 +02:00
|
|
|
void ME_CharFormatFromLogFont(HDC hDC, const LOGFONTW *lf, CHARFORMAT2W *fmt)
|
2006-07-14 19:43:00 +02:00
|
|
|
{
|
2008-04-23 23:13:07 +02:00
|
|
|
int ry;
|
2007-08-16 22:57:12 +02:00
|
|
|
|
2006-07-14 19:43:00 +02:00
|
|
|
ME_InitCharFormat2W(fmt);
|
|
|
|
ry = GetDeviceCaps(hDC, LOGPIXELSY);
|
|
|
|
lstrcpyW(fmt->szFaceName, lf->lfFaceName);
|
|
|
|
fmt->dwEffects = 0;
|
2016-10-14 11:05:03 +02:00
|
|
|
fmt->dwMask = CFM_WEIGHT|CFM_BOLD|CFM_ITALIC|CFM_UNDERLINE|CFM_UNDERLINETYPE|CFM_STRIKEOUT|CFM_SIZE|CFM_FACE|CFM_CHARSET;
|
2006-07-14 19:43:00 +02:00
|
|
|
fmt->wWeight = lf->lfWeight;
|
|
|
|
fmt->yHeight = -lf->lfHeight*1440/ry;
|
2008-03-16 21:47:39 +01:00
|
|
|
if (lf->lfWeight > FW_NORMAL) fmt->dwEffects |= CFM_BOLD;
|
2006-07-14 19:43:00 +02:00
|
|
|
if (lf->lfItalic) fmt->dwEffects |= CFM_ITALIC;
|
|
|
|
if (lf->lfUnderline) fmt->dwEffects |= CFM_UNDERLINE;
|
2016-10-14 11:05:03 +02:00
|
|
|
fmt->bUnderlineType = CFU_UNDERLINE;
|
2006-07-14 19:43:00 +02:00
|
|
|
if (lf->lfStrikeOut) fmt->dwEffects |= CFM_STRIKEOUT;
|
|
|
|
fmt->bPitchAndFamily = lf->lfPitchAndFamily;
|
2007-01-23 22:00:27 +01:00
|
|
|
fmt->bCharSet = lf->lfCharSet;
|
2006-07-14 19:43:00 +02:00
|
|
|
}
|
2005-03-08 17:26:23 +01:00
|
|
|
|
2007-08-16 22:57:12 +02:00
|
|
|
static BOOL ME_IsFontEqual(const LOGFONTW *p1, const LOGFONTW *p2)
|
2005-03-08 17:26:23 +01:00
|
|
|
{
|
|
|
|
if (memcmp(p1, p2, sizeof(LOGFONTW)-sizeof(p1->lfFaceName)))
|
|
|
|
return FALSE;
|
|
|
|
if (lstrcmpW(p1->lfFaceName, p2->lfFaceName))
|
|
|
|
return FALSE;
|
|
|
|
return TRUE;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
2008-01-01 22:05:33 +01:00
|
|
|
HFONT ME_SelectStyleFont(ME_Context *c, ME_Style *s)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
|
|
|
HFONT hOldFont;
|
2005-03-08 17:26:23 +01:00
|
|
|
LOGFONTW lf;
|
|
|
|
int i, nEmpty, nAge = 0x7FFFFFFF;
|
|
|
|
ME_FontCacheItem *item;
|
|
|
|
assert(s);
|
|
|
|
|
2008-01-01 22:05:33 +01:00
|
|
|
ME_LogFontFromStyle(c, &lf, s);
|
2005-03-08 17:26:23 +01:00
|
|
|
|
|
|
|
for (i=0; i<HFONT_CACHE_SIZE; i++)
|
2008-01-01 22:05:33 +01:00
|
|
|
c->editor->pFontCache[i].nAge++;
|
2005-03-08 17:26:23 +01:00
|
|
|
for (i=0, nEmpty=-1, nAge=0; i<HFONT_CACHE_SIZE; i++)
|
|
|
|
{
|
2008-01-01 22:05:33 +01:00
|
|
|
item = &c->editor->pFontCache[i];
|
2005-03-08 17:26:23 +01:00
|
|
|
if (!item->nRefs)
|
|
|
|
{
|
|
|
|
if (item->nAge > nAge)
|
|
|
|
nEmpty = i, nAge = item->nAge;
|
|
|
|
}
|
2006-02-01 12:30:26 +01:00
|
|
|
if (item->hFont && ME_IsFontEqual(&item->lfSpecs, &lf))
|
2005-03-08 17:26:23 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i < HFONT_CACHE_SIZE) /* found */
|
|
|
|
{
|
2008-01-01 22:05:33 +01:00
|
|
|
item = &c->editor->pFontCache[i];
|
2005-10-12 23:05:52 +02:00
|
|
|
TRACE_(richedit_style)("font reused %d\n", i);
|
2005-03-08 17:26:23 +01:00
|
|
|
item->nRefs++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-01-01 22:05:33 +01:00
|
|
|
item = &c->editor->pFontCache[nEmpty]; /* this legal even when nEmpty == -1, as we don't dereference it */
|
2005-03-08 17:26:23 +01:00
|
|
|
|
|
|
|
assert(nEmpty != -1); /* otherwise we leak cache entries or get too many fonts at once*/
|
|
|
|
if (item->hFont) {
|
2005-10-12 23:05:52 +02:00
|
|
|
TRACE_(richedit_style)("font deleted %d\n", nEmpty);
|
2005-03-08 17:26:23 +01:00
|
|
|
DeleteObject(item->hFont);
|
|
|
|
item->hFont = NULL;
|
|
|
|
}
|
2015-11-09 17:11:41 +01:00
|
|
|
item->hFont = CreateFontIndirectW(&lf);
|
2005-10-12 23:05:52 +02:00
|
|
|
TRACE_(richedit_style)("font created %d\n", nEmpty);
|
2005-03-08 17:26:23 +01:00
|
|
|
item->nRefs = 1;
|
2008-03-13 21:52:32 +01:00
|
|
|
item->lfSpecs = lf;
|
2005-03-08 17:26:23 +01:00
|
|
|
}
|
2015-11-09 17:11:41 +01:00
|
|
|
s->font_cache = item;
|
|
|
|
hOldFont = SelectObject(c->hDC, item->hFont);
|
2005-03-08 17:26:23 +01:00
|
|
|
/* should be cached too, maybe ? */
|
2008-01-01 22:05:33 +01:00
|
|
|
GetTextMetricsW(c->hDC, &s->tm);
|
2005-03-05 12:19:14 +01:00
|
|
|
return hOldFont;
|
|
|
|
}
|
|
|
|
|
2015-11-09 17:11:41 +01:00
|
|
|
static void release_font_cache(ME_FontCacheItem *item)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2015-11-09 17:11:41 +01:00
|
|
|
if (item->nRefs > 0)
|
2005-03-08 17:26:23 +01:00
|
|
|
{
|
2015-11-09 17:11:41 +01:00
|
|
|
item->nRefs--;
|
|
|
|
item->nAge = 0;
|
2005-03-08 17:26:23 +01:00
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
2015-11-09 17:11:41 +01:00
|
|
|
void ME_UnselectStyleFont(ME_Context *c, ME_Style *s, HFONT hOldFont)
|
|
|
|
{
|
|
|
|
SelectObject(c->hDC, hOldFont);
|
|
|
|
release_font_cache(s->font_cache);
|
|
|
|
s->font_cache = NULL;
|
|
|
|
}
|
|
|
|
|
2015-11-09 17:11:43 +01:00
|
|
|
void ME_DestroyStyle(ME_Style *s)
|
2015-11-09 17:11:41 +01:00
|
|
|
{
|
2015-11-09 17:11:43 +01:00
|
|
|
list_remove( &s->entry );
|
2015-11-09 17:11:41 +01:00
|
|
|
if (s->font_cache)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2015-11-09 17:11:41 +01:00
|
|
|
release_font_cache( s->font_cache );
|
|
|
|
s->font_cache = NULL;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2014-01-15 14:06:43 +01:00
|
|
|
ScriptFreeCache( &s->script_cache );
|
2018-02-03 23:59:46 +01:00
|
|
|
heap_free(s);
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ME_AddRefStyle(ME_Style *s)
|
|
|
|
{
|
|
|
|
assert(s->nRefs>0); /* style with 0 references isn't supposed to exist */
|
|
|
|
s->nRefs++;
|
|
|
|
all_refs++;
|
2009-08-10 16:53:53 +02:00
|
|
|
TRACE_(richedit_style)("ME_AddRefStyle %p, new refs=%d, total refs=%d\n", s, s->nRefs, all_refs);
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ME_ReleaseStyle(ME_Style *s)
|
|
|
|
{
|
|
|
|
s->nRefs--;
|
|
|
|
all_refs--;
|
|
|
|
if (s->nRefs==0)
|
2005-10-12 23:05:52 +02:00
|
|
|
TRACE_(richedit_style)("destroy style %p, total refs=%d\n", s, all_refs);
|
2005-03-05 12:19:14 +01:00
|
|
|
else
|
2005-10-12 23:05:52 +02:00
|
|
|
TRACE_(richedit_style)("release style %p, new refs=%d, total refs=%d\n", s, s->nRefs, all_refs);
|
2005-05-11 17:56:34 +02:00
|
|
|
if (!all_refs) TRACE("all style references freed (good!)\n");
|
2005-03-05 12:19:14 +01:00
|
|
|
assert(s->nRefs>=0);
|
|
|
|
if (!s->nRefs)
|
|
|
|
ME_DestroyStyle(s);
|
|
|
|
}
|
|
|
|
|
2009-08-12 15:05:46 +02:00
|
|
|
ME_Style *ME_GetInsertStyle(ME_TextEditor *editor, int nCursor)
|
|
|
|
{
|
2005-03-05 12:19:14 +01:00
|
|
|
if (ME_IsSelection(editor))
|
|
|
|
{
|
2009-08-12 15:05:46 +02:00
|
|
|
ME_Cursor *from, *to;
|
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_GetSelection(editor, &from, &to);
|
2009-08-12 15:05:46 +02:00
|
|
|
ME_AddRefStyle(from->pRun->member.run.style);
|
|
|
|
return from->pRun->member.run.style;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
if (editor->pBuffer->pCharStyle) {
|
|
|
|
ME_AddRefStyle(editor->pBuffer->pCharStyle);
|
|
|
|
return editor->pBuffer->pCharStyle;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ME_Cursor *pCursor = &editor->pCursors[nCursor];
|
|
|
|
ME_DisplayItem *pRunItem = pCursor->pRun;
|
|
|
|
ME_DisplayItem *pPrevItem = NULL;
|
|
|
|
if (pCursor->nOffset) {
|
|
|
|
ME_Run *pRun = &pRunItem->member.run;
|
|
|
|
ME_AddRefStyle(pRun->style);
|
|
|
|
return pRun->style;
|
|
|
|
}
|
|
|
|
pPrevItem = ME_FindItemBack(pRunItem, diRunOrParagraph);
|
|
|
|
if (pPrevItem->type == diRun)
|
|
|
|
{
|
|
|
|
ME_AddRefStyle(pPrevItem->member.run.style);
|
|
|
|
return pPrevItem->member.run.style;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ME_AddRefStyle(pRunItem->member.run.style);
|
|
|
|
return pRunItem->member.run.style;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-05 11:08:25 +02:00
|
|
|
void ME_SaveTempStyle(ME_TextEditor *editor, ME_Style *style)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
|
|
|
ME_Style *old_style = editor->pBuffer->pCharStyle;
|
2016-10-05 11:08:25 +02:00
|
|
|
|
|
|
|
if (style) ME_AddRefStyle( style );
|
|
|
|
editor->pBuffer->pCharStyle = style;
|
|
|
|
if (old_style) ME_ReleaseStyle( old_style );
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ME_ClearTempStyle(ME_TextEditor *editor)
|
|
|
|
{
|
|
|
|
if (!editor->pBuffer->pCharStyle) return;
|
|
|
|
ME_ReleaseStyle(editor->pBuffer->pCharStyle);
|
|
|
|
editor->pBuffer->pCharStyle = NULL;
|
|
|
|
}
|
2015-11-09 17:11:42 +01:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* ME_SetDefaultCharFormat
|
|
|
|
*
|
|
|
|
* Applies a style change to the default character style.
|
|
|
|
*
|
|
|
|
* The default style is special in that it is mutable - runs
|
|
|
|
* in the document that have this style should change if the
|
|
|
|
* default style changes. That means we need to fix up this
|
|
|
|
* style manually.
|
|
|
|
*/
|
|
|
|
void ME_SetDefaultCharFormat(ME_TextEditor *editor, CHARFORMAT2W *mod)
|
|
|
|
{
|
|
|
|
ME_Style *style, *def = editor->pBuffer->pDefaultStyle;
|
|
|
|
|
|
|
|
assert(mod->cbSize == sizeof(CHARFORMAT2W));
|
2015-11-09 17:11:43 +01:00
|
|
|
style = ME_ApplyStyle(editor, def, mod);
|
2015-11-09 17:11:42 +01:00
|
|
|
def->fmt = style->fmt;
|
|
|
|
def->tm = style->tm;
|
|
|
|
if (def->font_cache)
|
|
|
|
{
|
|
|
|
release_font_cache( def->font_cache );
|
|
|
|
def->font_cache = NULL;
|
|
|
|
}
|
|
|
|
ScriptFreeCache( &def->script_cache );
|
|
|
|
ME_ReleaseStyle( style );
|
|
|
|
ME_MarkAllForWrapping( editor );
|
|
|
|
}
|