bool FontPlatformData::isFixedPitch() const
{
#if ENABLE(GDI_FONTS_ON_WINDOWS)
    // TEXTMETRICS have this. Set m_treatAsFixedPitch based off that.
    HWndDC dc(0);
    HGDIOBJ oldFont = SelectObject(dc, hfont());

    // Yes, this looks backwards, but the fixed pitch bit is actually set if the font
    // is *not* fixed pitch. Unbelievable but true.
    TEXTMETRIC textMetric = { 0 };
    if (!GetTextMetrics(dc, &textMetric)) {
        if (ensureFontLoaded(hfont())) {
            // Retry GetTextMetrics.
            // FIXME: Handle gracefully the error if this call also fails.
            // See http://crbug.com/6401.
            if (!GetTextMetrics(dc, &textMetric))
                WTF_LOG_ERROR("Unable to get the text metrics after second attempt");
        }
    }

    bool treatAsFixedPitch = !(textMetric.tmPitchAndFamily & TMPF_FIXED_PITCH);

    SelectObject(dc, oldFont);

    return treatAsFixedPitch;
#else
    return typeface() && typeface()->isFixedPitch();
#endif
}
SCRIPT_FONTPROPERTIES* FontPlatformData::scriptFontProperties() const
{
    if (!m_scriptFontProperties) {
        m_scriptFontProperties = new SCRIPT_FONTPROPERTIES;
        memset(m_scriptFontProperties, 0, sizeof(SCRIPT_FONTPROPERTIES));
        m_scriptFontProperties->cBytes = sizeof(SCRIPT_FONTPROPERTIES);
        HRESULT result = ScriptGetFontProperties(0, scriptCache(),
                         m_scriptFontProperties);
        if (result == E_PENDING) {
            HDC dc = GetDC(0);
            HGDIOBJ oldFont = SelectObject(dc, hfont());
            HRESULT hr = ScriptGetFontProperties(dc, scriptCache(),
                                                 m_scriptFontProperties);
            if (S_OK != hr) {
                if (ChromiumBridge::ensureFontLoaded(hfont())) {
                    // FIXME: Handle gracefully the error if this call also fails.
                    hr = ScriptGetFontProperties(dc, scriptCache(),
                                                 m_scriptFontProperties);
                    if (S_OK != hr) {
                        ASSERT_NOT_REACHED();
                    }
                }
            }

            SelectObject(dc, oldFont);
            ReleaseDC(0, dc);
        }
    }
    return m_scriptFontProperties;
}
SCRIPT_FONTPROPERTIES* FontPlatformData::scriptFontProperties() const
{
    if (!m_scriptFontProperties) {
        m_scriptFontProperties = new SCRIPT_FONTPROPERTIES;
        memset(m_scriptFontProperties, 0, sizeof(SCRIPT_FONTPROPERTIES));
        m_scriptFontProperties->cBytes = sizeof(SCRIPT_FONTPROPERTIES);
        HRESULT result = ScriptGetFontProperties(0, scriptCache(),
                                                 m_scriptFontProperties);
        if (result == E_PENDING) {
            HWndDC dc(0);
            HGDIOBJ oldFont = SelectObject(dc, hfont());
            HRESULT hr = ScriptGetFontProperties(dc, scriptCache(),
                                                 m_scriptFontProperties);
            if (S_OK != hr) {
                if (PlatformSupport::ensureFontLoaded(hfont())) {
                    // FIXME: Handle gracefully the error if this call also fails.
                    hr = ScriptGetFontProperties(dc, scriptCache(),
                                                 m_scriptFontProperties);
                    if (S_OK != hr) {
                        LOG_ERROR("Unable to get the font properties after second attempt");
                    }
                }
            }

            SelectObject(dc, oldFont);
        }
    }
    return m_scriptFontProperties;
}
Example #4
0
// Routine Description:
// - Add the font described by the LOGFONT structure to the font table if
//      it's not already there.
int
AddFont(
    ENUMLOGFONT *pelf,
    NEWTEXTMETRIC* /*pntm*/,
    int /*nFontType*/,
    HDC hDC)
{
    wil::unique_hfont hfont(CreateFontIndirectW(&pelf->elfLogFont));
    RETURN_LAST_ERROR_IF_NULL(hfont);

    hfont.reset(SelectFont(hDC, hfont.release()));

    TEXTMETRIC tm;
    GetTextMetricsW(hDC, &tm);

    SIZE sz;
    GetTextExtentPoint32W(hDC, L"0", 1, &sz);

    wprintf(L"  Actual Size: (X: %d, Y: %d)\r\n", sz.cx, tm.tmHeight + tm.tmExternalLeading);

    // restore original DC font
    hfont.reset(SelectFont(hDC, hfont.release()));

    return CONTINUE_ENUM;
}
Example #5
0
/*
 * hfont_
 */
void
hfont_(
	char	*fontfile,
	int	*len1,
	int	len2)
{
	char	buf[BUFSIZ];

	strncpy(buf, fontfile, len2);
	buf[*len1] = 0;

	hfont(buf);
}
Example #6
0
PassRefPtr<SharedBuffer> FontPlatformData::openTypeTable(uint32_t table) const
{
    HWndDC hdc(0);
    HGDIOBJ oldFont = SelectObject(hdc, hfont());

    DWORD size = GetFontData(hdc, table, 0, 0, 0);
    RefPtr<SharedBuffer> buffer;
    if (size != GDI_ERROR) {
        buffer = SharedBuffer::create(size);
        DWORD result = GetFontData(hdc, table, 0, (PVOID)buffer->data(), size);
        ASSERT(result == size);
    }

    SelectObject(hdc, oldFont);
    return buffer.release();
}
String FontPlatformData::fontFamilyName() const
{
#if ENABLE(GDI_FONTS_ON_WINDOWS)
    HWndDC dc(0);
    HGDIOBJ oldFont = static_cast<HFONT>(SelectObject(dc, hfont()));
    WCHAR name[LF_FACESIZE];
    unsigned resultLength = GetTextFace(dc, LF_FACESIZE, name);
    if (resultLength > 0)
        resultLength--; // ignore the null terminator
    SelectObject(dc, oldFont);
    return String(name, resultLength);
#else
    // FIXME: This returns the requested name, perhaps a better solution would be to
    // return the list of names provided by SkTypeface::createFamilyNameIterator.
    ASSERT(typeface());
    SkString familyName;
    typeface()->getFamilyName(&familyName);
    return String::fromUTF8(familyName.c_str());
#endif
}
Example #8
0
/*
 * display all the hershey fonts and demonstrate textang
 */
main()
{
	char	buf[50];
	char	*str1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;
	char	*str2 = "abcdefghijklmnopqrstuvwxyz" ;
	char	*str3 = "1234567890+-=!@#$%^&*(){}[]" ;
	char	*str4 = "<>,./?~`\\|_BONK,blark" ;
	int	i;
	short	val;

	vinit("mswin");
	winopen("circtxt");

	hleftjustify(1);

	unqdevice(INPUTCHANGE);
	qdevice(KEYBD);
	/* 
	 * Wait for REDRAW event ...
	 */
	while (qread(&val) != REDRAW)
		;

	color(BLACK);
	clear();

	ortho2(-14.0, 14.0, -14.0, 14.0);	/* define the world space */

	for(i = 0; i < 22; i++) {

		/*
		 * textang is used to specify the orientation of text. As
		 * we want the title to come out straight we make sure it is
		 * zero each time we go through this loop.
		 */
		htextang(0.0);

		/*
		 * do the title
		 */
		color(YELLOW);
		hfont("futura.m");
		sprintf(buf, "This is hershey font %s", fonts[i]);
		hboxtext(-11.0, 12.0, 20.0, 1.0, buf);

		/*
		 * draw a box around the title
		 */
		rect(-11.0, 12.0, 9.0, 13.0);

		color(GREEN);

		hfont(fonts[i]);		/* grab a font from the table */

		htextsize(1.5, 1.5);		/* show the outer ring */
		ShowCircularText(11.0, str1);

		htextsize(1.3, 1.3);		/* show the second ring */
		ShowCircularText(8.5, str2);

		htextsize(1.1, 1.1);		/* show the third ring */
		ShowCircularText(7.0, str3);

		htextsize(0.9, 0.9);		/* show the inside ring */
		ShowCircularText(5.0, str4);

		if (qread(&val)) {
			if (val == 'q') {
				gexit();
				exit(0);
			}
		}

		color(BLACK);
		clear();
	}

	gexit();
}
Example #9
0
/*
 * a demonstration of objects
 */
draw_balls()
{
	if (!inited) {
		inited = 1;
		/*
		 * set up our viewing transformation
		 */
		perspective(900, 1.0, 0.001, 500.0);
		lookat(13.0, 13.0, 8.0, 0.0, 0.0, 0.0, 0);

		/*
		 * Call a routine to make the sphere object
		 */
		makesphere();
		hfont("times.rb");
	}

	/*
	 * Now draw the sphere object scaled down. We use the pushmatrix
	 * and the popmatrix to preserve the transformation matrix so
	 * that only this sphere is drawn scaled.
	 */
	color(CYAN);

	pushmatrix();
		scale(0.5, 0.5, 0.5);
		callobj(SPHERE);
	popmatrix();

	/*
	 * now we draw the same sphere translated, with a different
	 * scale and color.
	 */

	color(WHITE);

	pushmatrix();
		translate(0.0, -1.4 * RADIUS, 1.4 * RADIUS);
		scale(0.3, 0.3, 0.3);
		callobj(SPHERE);
	popmatrix();

	/*
	 * and maybe a few more times....
	 */


	color(RED);

	pushmatrix();
		translate(0.0, RADIUS, 0.7 * RADIUS);
		scale(0.2, 0.2, 0.2);
		callobj(SPHERE);
	popmatrix();

	color(GREEN);

	pushmatrix();
		translate(0.0, 1.5 * RADIUS, -RADIUS);
		scale(0.15, 0.15, 0.15);
		callobj(SPHERE);
	popmatrix();

	color(YELLOW);

	pushmatrix();
		translate(0.0, -RADIUS, -RADIUS);
		scale(0.12, 0.12, 0.12);
		callobj(SPHERE);
	popmatrix();

	color(BLUE);

	pushmatrix();
		translate(0.0, -2.0*RADIUS, -RADIUS);
		scale(0.3, 0.3, 0.3);
		callobj(SPHERE);
	popmatrix();

	ortho2(0.0, 1.0, 0.0, 1.0);
	hcentertext(1);
	htextsize(0.08, 0.15);
	move2(0.8, 0.5);
	htextang(-90.0);
	hcharstr("I'm very ordinary!");
	perspective(900, 1.0, 0.001, 500.0);
	lookat(13.0, 13.0, 8.0, 0.0, 0.0, 0.0, 0);
}
Example #10
0
/*
 * Using polygons, hatching, and filling.
 */
main()
{
	short	val;

	winopen("poly");

	unqdevice(INPUTCHANGE);
	qdevice(KEYBD);		/* enable keyboard */
	/* 
	 * Wait for REDRAW event ...
	 */
	while (qread(&val) != REDRAW)
		;

	color(BLACK);		/* clear to black */
	clear();

	/*
	 * world coordinates are now in the range -10 to 10
	 * in x, y, and z. Note that positive z is towards us.
	 */
	ortho(-10.0, 10.0, -10.0, 10.0, 10.0, -10.0);

	color(YELLOW);

	/*
	 * write out the string "Polygon from poly()" in the
	 * starting at (-8.0, -4.0) and scaled to be 4.0 units long,
	 * 0.5 units high.
	 */
	hfont("futura.m");
	hboxtext(-8.0, -4.0, 4.0, 0.5, "Polygon from poly()/ polf()");

	color(GREEN);

	/*
	 * write out a scaled string starting at (0.0, 6.0)
	 */
	hboxtext(0.0, 6.0, 4.5, 0.5, "Polygon from bgnpoly()/ endpoly()");
	hboxtext(0.0, 5.0, 4.5, 0.5, "             pmv()/ pdr()/ pclos()");

	color(MAGENTA);

	/*
	 * write out a scaled string starting at (0.0, 6.0)
	 */
	hboxtext(3.5, -3.5, 1.9, 0.5, "Arc/ Arcf");

	/*
	 * draw some wire frame polygons
	 */
	drawpoly();

	/*
	 *  rotate so the next polygons will appear in a different place.
	 */
	rot(20.0, 'x');
	rot(30.0, 'y');

	/*
	 * draw some filled polygons.
	 */
	drawpolyf();

	gexit();
}