コード例 #1
0
ファイル: font.cpp プロジェクト: alilloyd/livecode
const char *MCF_getweightstring(uint2 style)
{
	uint2 weight = MCF_getweightint(style);
	if (weight > MCFW_ULTRABOLD)
		weight = MCFW_UNDEFINED;
	return weightstrings[weight];
}
コード例 #2
0
ファイル: lnxflstold.cpp プロジェクト: Bjoernke/livecode
XFontStruct *MCOldFonttablenode::loadfont(uint2 size, uint2 style)
{
	char fontname[XLFD_LENGTH];
	const char *wptr = "medium";
	const char *iptr = "r";
	Boolean bold = False;
	Boolean italic = False;

	if (MCF_getweightint(style) > (FA_DEFAULT_STYLE & FA_WEIGHT))
	{
		wptr = bstring;
		bold = True;
	}
	if (style & FA_ITALIC)
	{
		iptr = "i";
		italic = True;
	}
	if (bold)
		if (italic)
			size = matchsize(size, bisizes, nbolditalic);
		else
			size = matchsize(size, bsizes, nbold);
	else
		if (italic)
			size = matchsize(size, isizes, nitalic);
		else
			size = matchsize(size, psizes, nplain);
	sprintf(fontname, "-*-%s-%s-%s-normal-*-%d-*-%s",
	        name, wptr, iptr, size, charset);
	XFontStruct *fsptr = XLoadQueryFont(MCdpy, fontname);
	if (fsptr == NULL)
	{
		sprintf(fontname, "-*-%s-%s-%s-normal-*-%d-0-0-0-*-0-%s",
		        name, wptr, iptr, size, charset);
		fsptr = XLoadQueryFont(MCdpy, fontname);
	}
	if (fsptr == NULL && italic)
	{
		iptr = "o";
		sprintf(fontname, "-*-%s-%s-%s-normal-*-%d-*-%s",
		        name, wptr, iptr, size, charset);
		fsptr = XLoadQueryFont(MCdpy, fontname);
	}
	if (fsptr == NULL)
	{
		sprintf(fontname, "-*-%s-%s-%s-normal-*-%d-*", name, wptr, iptr, size);
		fsptr = XLoadQueryFont(MCdpy, fontname);
		if (fsptr == NULL && italic)
		{
			iptr = "i";
			sprintf(fontname, "-*-%s-%s-%s-normal-*-%d-*", name, wptr, iptr, size);
			fsptr = XLoadQueryFont(MCdpy, fontname);
		}
	}
	if (fsptr == NULL)
	{
		sprintf(fontname, "-*-%s-%s-%s-*-%d-*-%s",
		        name, wptr, iptr, size, charset);
		fsptr = XLoadQueryFont(MCdpy, fontname);
		if (fsptr == NULL && italic)
		{
			iptr = "o";
			sprintf(fontname, "-*-%s-%s-%s-*-%d-*-%s",
			        name, wptr, iptr, size, charset);
			fsptr = XLoadQueryFont(MCdpy, fontname);
		}
	}
	if (fsptr == NULL)
	{
		sprintf(fontname, "-*-%s-%s-%s-*-%d-*", name, wptr, iptr, size);
		fsptr = XLoadQueryFont(MCdpy, fontname);
		if (fsptr == NULL && italic)
		{
			iptr = "i";
			sprintf(fontname, "-*-%s-%s-%s-*-%d-*", name, wptr, iptr, size);
			fsptr = XLoadQueryFont(MCdpy, fontname);
		}
	}
	if (fsptr == NULL)
	{
		sprintf(fontname, "-*-%s-*--%d-*", name, size);
		fsptr = XLoadQueryFont(MCdpy, fontname);
	}
		
	return fsptr;
}
コード例 #3
0
ファイル: font.cpp プロジェクト: alilloyd/livecode
Exec_stat MCF_unparsetextatts(Properties which, uint4 flags, MCStringRef name, uint2 height, uint2 size, uint2 style, MCValueRef &r_result)
{
	switch (which)
	{
	case P_TEXT_ALIGN:
		switch (flags & F_ALIGNMENT)
		{
		case F_ALIGN_LEFT:
            r_result = MCSTR(MCleftstring);
            break;
		case F_ALIGN_CENTER:
			r_result = MCSTR(MCcenterstring);
			break;
		case F_ALIGN_RIGHT:
			r_result = MCSTR(MCrightstring);
			break;
		case F_ALIGN_JUSTIFY:
			r_result = MCSTR(MCjustifystring);
            break;
		}
		break;
	case P_TEXT_FONT:
        r_result = MCValueRetain(name);
		break;
	case P_TEXT_HEIGHT:
        {
        MCAutoNumberRef t_height;
        /* UNCHECKED */ MCNumberCreateWithUnsignedInteger(height, &t_height);
        r_result = MCValueRetain(*t_height);
		break;
        }
	case P_TEXT_SIZE:
        {
        MCAutoNumberRef t_size;
        /* UNCHECKED */ MCNumberCreateWithUnsignedInteger(size, &t_size);
            r_result = MCValueRetain(*t_size);
		break;
        }
	case P_TEXT_STYLE:
		{
			if (style == FA_DEFAULT_STYLE)
			{
                r_result = MCSTR(MCplainstring);
				return ES_NORMAL;
			}

			if (r_result != nil)
                MCValueRelease(r_result);
            MCAutoListRef t_list;
            /* UNCHECKED */ MCListCreateMutable(',', &t_list);
			if (MCF_getweightint(style) != MCFW_MEDIUM)
                MCListAppendCString(*t_list, MCF_getweightstring(style));
			if (style & FA_ITALIC || style & FA_OBLIQUE)
                MCListAppendCString(*t_list, MCF_getslantlongstring(style));
			if (style & FA_BOX)
                MCListAppendCString(*t_list, MCboxstring);
			if (style & FA_3D_BOX)
                MCListAppendCString(*t_list, MCthreedboxstring);
			if (style & FA_UNDERLINE)
                MCListAppendCString(*t_list, MCunderlinestring);
			if (style & FA_STRIKEOUT)
                MCListAppendCString(*t_list, MCstrikeoutstring);
			if (style & FA_LINK)
                MCListAppendCString(*t_list, MClinkstring);
			if (MCF_getexpandint(style) != FE_NORMAL)
                MCListAppendCString(*t_list, MCF_getexpandstring(style));
            
            MCAutoStringRef t_string;
            /* UNCHECKED */ MCListCopyAsString(*t_list, &t_string);
            r_result = MCValueRetain(*t_string);
		}
		break;
	default:
		break;
	}
	return ES_NORMAL;
}
コード例 #4
0
ファイル: w32flst.cpp プロジェクト: elphinkuo/livecode
MCFontnode::MCFontnode(const MCString &fname, uint2 &size,
                       uint2 style, Boolean printer)
{
	reqname = fname.clone();
	reqsize = size;
	reqstyle = style;
	reqprinter = printer;
	font = new MCFontStruct;
	if (MCnoui)
	{
		memset(font, 0, sizeof(MCFontStruct));
		return;
	}
	LOGFONTA logfont;
	memset(&logfont, 0, sizeof(LOGFONTA));
	uint4 maxlength = MCU_min(LF_FACESIZE - 1U, fname.getlength());
	strncpy(logfont.lfFaceName, fname.getstring(), maxlength);
	logfont.lfFaceName[maxlength] = '\0';

	// MW-2012-05-03: [[ Bug 10180 ]] Make sure the default charset for the font
	//   is chosen - otherwise things like WingDings don't work!
	logfont.lfCharSet = DEFAULT_CHARSET;

	//parse font and encoding
	char *sptr = logfont.lfFaceName;
	if (sptr = strchr(logfont.lfFaceName, ','))
	{
		*sptr = '\0';
		sptr++;
	}
	HDC hdc;

	// MW-2013-11-07: [[ Bug 11393 ]] 'printer' in the fontstruct now means use ideal
	//   metrics for rendering and measuring.
	MCScreenDC *pms = (MCScreenDC *)MCscreen;
	hdc = pms->getsrchdc();
	logfont.lfHeight = MulDiv(MulDiv(size, 7, 8),
	                          SCREEN_WIDTH_FOR_FONT_USE, 72);

	logfont.lfWeight = weighttable[MCF_getweightint(style)];
	if (style & FA_ITALIC)
		logfont.lfItalic = TRUE;
	if (style & FA_OBLIQUE)
		logfont.lfOrientation = 3600 - 150; /* 15 degree forward slant */
	
	HFONT newfont = CreateFontIndirectA(&logfont);
	SelectObject(hdc, newfont);
	char testname[LF_FACESIZE];
	memset(testname, 0, LF_FACESIZE);
	GetTextFaceA(hdc, LF_FACESIZE, testname);

	// MW-2012-02-13: If we failed to find an exact match then remap the font name and
	//   try again.
	if (newfont == NULL || (MCU_strncasecmp(testname, logfont.lfFaceName, strlen(testname) + 1)))
	{
		if (newfont != NULL)
			DeleteObject(newfont);

		mapfacename(logfont.lfFaceName, logfont.lfFaceName, printer == True);

		// Force the resulting font to be TrueType and with ANSI charset (otherwise
		// we get strange UI symbol font on XP).
		logfont.lfCharSet = ANSI_CHARSET;
		logfont.lfOutPrecision = OUT_TT_ONLY_PRECIS;
		newfont = CreateFontIndirectA(&logfont);
		SelectObject(hdc, newfont);
	}

	// At this point we will have either found an exact match for the textFont, mapped
	// using the defaults table and found a match, or been given a default truetype font.

	TEXTMETRICA tm;
	GetTextMetricsA(hdc, &tm);
	font->fid = (MCSysFontHandle)newfont;
	font->size = size;
	// MW-2013-12-19: [[ Bug 11606 ]] Use Mac-style metric adjustment in printer (ideal
	//   layout mode).
	if (!printer)
	{
		font->ascent = MulDiv(tm.tmAscent, 15, 16);
		font->descent = tm.tmDescent;
	}
	else
	{
		font -> ascent = size - 1;
		font -> descent = size * 2 / 14 + 1;
	}
	font->printer = printer;
}
コード例 #5
0
ファイル: font.cpp プロジェクト: elphinkuo/livecode
Exec_stat MCF_unparsetextatts(Properties which, MCExecPoint &ep, uint4 flags,
                              const char *name, uint2 height, uint2 size,
                              uint2 style)
{
	switch (which)
	{
	case P_TEXT_ALIGN:
		switch (flags & F_ALIGNMENT)
		{
		case F_ALIGN_LEFT:
			ep.setstaticcstring(MCleftstring);
			break;
		case F_ALIGN_CENTER:
			ep.setstaticcstring(MCcenterstring);
			break;
		case F_ALIGN_RIGHT:
			ep.setstaticcstring(MCrightstring);
			break;
		case F_ALIGN_JUSTIFY:
			ep.setstaticcstring(MCjustifystring);
			break;
		}
		break;
	case P_TEXT_FONT:
		ep.setsvalue(name);
		break;
	case P_TEXT_HEIGHT:
		ep.setint(height);
		break;
	case P_TEXT_SIZE:
		ep.setint(size);
		break;
	case P_TEXT_STYLE:
		{
			if (style == FA_DEFAULT_STYLE)
			{
				ep.setstaticcstring(MCplainstring);
				return ES_NORMAL;
			}
			
			uint32_t j;
			j = 0;

			ep.clear();
			if (MCF_getweightint(style) != MCFW_MEDIUM)
				ep.concatcstring(MCF_getweightstring(style), EC_COMMA, j++ == 0);
			if (style & FA_ITALIC || style & FA_OBLIQUE)
				ep.concatcstring(MCF_getslantlongstring(style), EC_COMMA, j++ == 0);
			if (style & FA_BOX)
				ep.concatcstring(MCboxstring, EC_COMMA, j++ == 0);
			if (style & FA_3D_BOX)
				ep.concatcstring(MCthreedboxstring, EC_COMMA, j++ == 0);
			if (style & FA_UNDERLINE)
				ep.concatcstring(MCunderlinestring, EC_COMMA, j++ == 0);
			if (style & FA_STRIKEOUT)
				ep.concatcstring(MCstrikeoutstring, EC_COMMA, j++ == 0);
			if (style & FA_LINK)
				ep.concatcstring(MClinkstring, EC_COMMA, j++ == 0);
			if (MCF_getexpandint(style) != FE_NORMAL)
				ep.concatcstring(MCF_getexpandstring(style), EC_COMMA, j++ == 0);
		}
		break;
	default:
		break;
	}
	return ES_NORMAL;
}