예제 #1
0
파일: font.c 프로젝트: Nikers/T-Clock
 //================================================================================================
//--------------------------------------------------------------+++--> Create a Font For the Clock:
HFONT CreateMyFont(char* fontname, int fontsize, LONG weight, LONG italic, int angle) { //--+++-->
	LOGFONT lf;	POINT pt;	HDC hdc;	WORD langid;
	char s[11];	int cp, i;	BYTE charset; int FontQty;
	
  memset(&lf, 0, sizeof(LOGFONT));
  langid = (WORD)GetMyRegLong("Format", "Locale", (int)GetUserDefaultLangID());
  FontQty = GetMyRegLong("Clock", "FontQuality", CLEARTYPE_QUALITY);
  cp = CP_ACP;

  if(GetLocaleInfo(langid, LOCALE_IDEFAULTANSICODEPAGE, s, 10) > 0) {
	 char *p;
	 p = s;
	 cp = 0;
	 while('0' <= *p && *p <= '9') cp = cp * 10 + *p++ - '0';
	 if(!IsValidCodePage(cp)) cp = CP_ACP;
  }
	
  charset = 0;
  for(i = 0; codepage_charset[i].cp; i++) {
	  if(cp == codepage_charset[i].cp) {
		 charset = codepage_charset[i].charset; break;
	  }
  }
	
  hdc = GetDC(NULL);
	
	// find a font named "fontname"
  if(charset == 0) charset = GetTextCharset(hdc);
  lf.lfCharSet = charset;
  if(EnumFontFamiliesEx(hdc, &lf, (FONTENUMPROC)EnumFontFamExProc, (LPARAM)fontname, 0)) {
	 lf.lfCharSet = OEM_CHARSET;
	 if(EnumFontFamiliesEx(hdc, &lf, (FONTENUMPROC)EnumFontFamExProc, (LPARAM)fontname, 0)) {
		lf.lfCharSet = ANSI_CHARSET;
		EnumFontFamiliesEx(hdc, &lf, (FONTENUMPROC)EnumFontFamExProc, (LPARAM)fontname, 0);
	 }
  }
	
	pt.x = 0;
	pt.y = MulDiv(fontsize, GetDeviceCaps(hdc, LOGPIXELSY), 72);
	DPtoLP(hdc, &pt, 1);
	lf.lfHeight = -pt.y;
	
	ReleaseDC(NULL, hdc);
	
	lf.lfWidth = lf.lfEscapement = lf.lfOrientation = 0;
	lf.lfWeight = weight;
	lf.lfItalic = (BYTE)italic;
	lf.lfUnderline = 0;
	lf.lfStrikeOut = 0;
	if(angle >0) lf.lfEscapement = angle;
	lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
	lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;

	lf.lfQuality = FontQty; // This Just HAD To be Adjustable.

	lf.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
	strcpy(lf.lfFaceName, fontname);
	
 return CreateFontIndirect(&lf);
}
예제 #2
0
MOZCE_SHUNT_API UINT GetTextCharsetInfo(HDC inDC, LPFONTSIGNATURE outSig, DWORD inFlags)
{
#ifdef API_LOGGING
    mozce_printf("GetTextCharsetInfo called\n");
#endif

    // Zero out the FONTSIGNATURE as we do not know how to fill it out properly.
    if(NULL != outSig)
    {
        memset(outSig, 0, sizeof(FONTSIGNATURE));
    }

    return GetTextCharset(inDC);
}
예제 #3
0
파일: font.c 프로젝트: Dietr1ch/wine
static void test_logfont(void)
{
    LOGFONTA lfa, lfa2;
    GpFont *font;
    GpFontFamily *family;
    GpStatus stat;
    GpGraphics *graphics;
    HDC hdc = GetDC(0);
    INT style;
    REAL rval;
    UINT16 em_height, line_spacing;
    Unit unit;

    GdipCreateFromHDC(hdc, &graphics);

    memset(&lfa, 0, sizeof(LOGFONTA));
    memset(&lfa2, 0xff, sizeof(LOGFONTA));
    lstrcpyA(lfa.lfFaceName, "Tahoma");

    stat = GdipCreateFontFromLogfontA(hdc, &lfa, &font);
    expect(Ok, stat);
    stat = GdipGetLogFontA(font, graphics, &lfa2);
    expect(Ok, stat);

    ok(lfa2.lfHeight < 0, "Expected negative height\n");
    expect(0, lfa2.lfWidth);
    expect(0, lfa2.lfEscapement);
    expect(0, lfa2.lfOrientation);
    ok((lfa2.lfWeight >= 100) && (lfa2.lfWeight <= 900), "Expected weight to be set\n");
    expect(0, lfa2.lfItalic);
    expect(0, lfa2.lfUnderline);
    expect(0, lfa2.lfStrikeOut);
    ok(lfa2.lfCharSet == GetTextCharset(hdc) || lfa2.lfCharSet == ANSI_CHARSET,
        "Expected %x or %x, got %x\n", GetTextCharset(hdc), ANSI_CHARSET, lfa2.lfCharSet);
    expect(0, lfa2.lfOutPrecision);
    expect(0, lfa2.lfClipPrecision);
    expect(0, lfa2.lfQuality);
    expect(0, lfa2.lfPitchAndFamily);

    GdipDeleteFont(font);

    memset(&lfa, 0, sizeof(LOGFONTA));
    lfa.lfHeight = 25;
    lfa.lfWidth = 25;
    lfa.lfEscapement = lfa.lfOrientation = 50;
    lfa.lfItalic = lfa.lfUnderline = lfa.lfStrikeOut = TRUE;

    memset(&lfa2, 0xff, sizeof(LOGFONTA));
    lstrcpyA(lfa.lfFaceName, "Tahoma");

    stat = GdipCreateFontFromLogfontA(hdc, &lfa, &font);
    expect(Ok, stat);
    stat = GdipGetLogFontA(font, graphics, &lfa2);
    expect(Ok, stat);

    ok(lfa2.lfHeight < 0, "Expected negative height\n");
    expect(0, lfa2.lfWidth);
    expect(0, lfa2.lfEscapement);
    expect(0, lfa2.lfOrientation);
    ok((lfa2.lfWeight >= 100) && (lfa2.lfWeight <= 900), "Expected weight to be set\n");
    expect(TRUE, lfa2.lfItalic);
    expect(TRUE, lfa2.lfUnderline);
    expect(TRUE, lfa2.lfStrikeOut);
    ok(lfa2.lfCharSet == GetTextCharset(hdc) || lfa2.lfCharSet == ANSI_CHARSET,
        "Expected %x or %x, got %x\n", GetTextCharset(hdc), ANSI_CHARSET, lfa2.lfCharSet);
    expect(0, lfa2.lfOutPrecision);
    expect(0, lfa2.lfClipPrecision);
    expect(0, lfa2.lfQuality);
    expect(0, lfa2.lfPitchAndFamily);

    stat = GdipGetFontStyle(font, &style);
    expect(Ok, stat);
    ok (style == (FontStyleItalic | FontStyleUnderline | FontStyleStrikeout),
            "Expected , got %d\n", style);

    stat = GdipGetFontUnit(font, &unit);
    expect(Ok, stat);
    expect(UnitWorld, unit);

    stat = GdipGetFontHeight(font, graphics, &rval);
    expect(Ok, stat);
    expectf(25.347656, rval);
    stat = GdipGetFontSize(font, &rval);
    expect(Ok, stat);
    expectf(21.0, rval);

    stat = GdipGetFamily(font, &family);
    expect(Ok, stat);
    stat = GdipGetEmHeight(family, FontStyleRegular, &em_height);
    expect(Ok, stat);
    expect(2048, em_height);
    stat = GdipGetLineSpacing(family, FontStyleRegular, &line_spacing);
    expect(Ok, stat);
    expect(2472, line_spacing);
    GdipDeleteFontFamily(family);

    GdipDeleteFont(font);

    memset(&lfa, 0, sizeof(lfa));
    lfa.lfHeight = -25;
    lstrcpyA(lfa.lfFaceName, "Tahoma");
    stat = GdipCreateFontFromLogfontA(hdc, &lfa, &font);
    expect(Ok, stat);
    memset(&lfa2, 0xff, sizeof(lfa2));
    stat = GdipGetLogFontA(font, graphics, &lfa2);
    expect(Ok, stat);
    expect(lfa.lfHeight, lfa2.lfHeight);

    stat = GdipGetFontUnit(font, &unit);
    expect(Ok, stat);
    expect(UnitWorld, unit);

    stat = GdipGetFontHeight(font, graphics, &rval);
    expect(Ok, stat);
    expectf(30.175781, rval);
    stat = GdipGetFontSize(font, &rval);
    expect(Ok, stat);
    expectf(25.0, rval);

    stat = GdipGetFamily(font, &family);
    expect(Ok, stat);
    stat = GdipGetEmHeight(family, FontStyleRegular, &em_height);
    expect(Ok, stat);
    expect(2048, em_height);
    stat = GdipGetLineSpacing(family, FontStyleRegular, &line_spacing);
    expect(Ok, stat);
    expect(2472, line_spacing);
    GdipDeleteFontFamily(family);

    GdipDeleteFont(font);

    GdipDeleteGraphics(graphics);
    ReleaseDC(0, hdc);
}
예제 #4
0
static void test_logfont(void)
{
    LOGFONTW lfw, lfw2;
    GpFont *font;
    GpStatus stat;
    GpGraphics *graphics;
    HDC hdc = GetDC(0);
    INT style;

    GdipCreateFromHDC(hdc, &graphics);
    memset(&lfw, 0, sizeof(LOGFONTW));
    memset(&lfw2, 0xff, sizeof(LOGFONTW));

    /* empty FaceName */
    lfw.lfFaceName[0] = 0;
    stat = GdipCreateFontFromLogfontW(hdc, &lfw, &font);

    expect(NotTrueTypeFont, stat);

    memcpy(&lfw.lfFaceName, arial, 6 * sizeof(WCHAR));

    stat = GdipCreateFontFromLogfontW(hdc, &lfw, &font);
    if (stat == FileNotFound)
    {
        skip("Arial not installed.\n");
        return;
    }
    expect(Ok, stat);
    stat = GdipGetLogFontW(font, graphics, &lfw2);
    expect(Ok, stat);

    ok(lfw2.lfHeight < 0, "Expected negative height\n");
    expect(0, lfw2.lfWidth);
    expect(0, lfw2.lfEscapement);
    expect(0, lfw2.lfOrientation);
    ok((lfw2.lfWeight >= 100) && (lfw2.lfWeight <= 900), "Expected weight to be set\n");
    expect(0, lfw2.lfItalic);
    expect(0, lfw2.lfUnderline);
    expect(0, lfw2.lfStrikeOut);
    expect(GetTextCharset(hdc), lfw2.lfCharSet);
    expect(0, lfw2.lfOutPrecision);
    expect(0, lfw2.lfClipPrecision);
    expect(0, lfw2.lfQuality);
    expect(0, lfw2.lfPitchAndFamily);

    GdipDeleteFont(font);

    memset(&lfw, 0, sizeof(LOGFONTW));
    lfw.lfHeight = 25;
    lfw.lfWidth = 25;
    lfw.lfEscapement = lfw.lfOrientation = 50;
    lfw.lfItalic = lfw.lfUnderline = lfw.lfStrikeOut = TRUE;

    memset(&lfw2, 0xff, sizeof(LOGFONTW));
    memcpy(&lfw.lfFaceName, arial, 6 * sizeof(WCHAR));

    stat = GdipCreateFontFromLogfontW(hdc, &lfw, &font);
    expect(Ok, stat);
    stat = GdipGetLogFontW(font, graphics, &lfw2);
    expect(Ok, stat);

    ok(lfw2.lfHeight < 0, "Expected negative height\n");
    expect(0, lfw2.lfWidth);
    expect(0, lfw2.lfEscapement);
    expect(0, lfw2.lfOrientation);
    ok((lfw2.lfWeight >= 100) && (lfw2.lfWeight <= 900), "Expected weight to be set\n");
    expect(TRUE, lfw2.lfItalic);
    expect(TRUE, lfw2.lfUnderline);
    expect(TRUE, lfw2.lfStrikeOut);
    expect(GetTextCharset(hdc), lfw2.lfCharSet);
    expect(0, lfw2.lfOutPrecision);
    expect(0, lfw2.lfClipPrecision);
    expect(0, lfw2.lfQuality);
    expect(0, lfw2.lfPitchAndFamily);

    stat = GdipGetFontStyle(font, &style);
    expect(Ok, stat);
    ok (style == (FontStyleItalic | FontStyleUnderline | FontStyleStrikeout),
            "Expected , got %d\n", style);

    GdipDeleteFont(font);

    GdipDeleteGraphics(graphics);
    ReleaseDC(0, hdc);
}
예제 #5
0
파일: drawtext.c 프로젝트: conioh/os-design
int DrawTextExA(
    HDC hdc,
    LPSTR lpchText,
    int cchText,
    LPRECT lprc,
    UINT format,
    LPDRAWTEXTPARAMS lpdtp)
{
    LPWSTR lpwstr;
    int iRet;
    int iUniString;
    WORD wCodePage = (WORD)GdiGetCodePage(hdc);

    if (cchText == -1) {
        // USER_AWCONV_COUNTSTRINGSZ does not count/convert trailing \0.
        cchText = USER_AWCONV_COUNTSTRINGSZ;
    } else if (cchText < -1) {
        return 0;
    }

    if ((iUniString = MBToWCSEx(wCodePage, lpchText, cchText, &lpwstr, -1, TRUE)) == 0) {
        if (cchText == USER_AWCONV_COUNTSTRINGSZ) {
            lpwstr = (LPWSTR)gwszNullStr;
            format &= ~DT_MODIFYSTRING;
        } else {
            return 0;
        }
    }

    /*
     * Grow the buffer to accomodate the ellipsis (see AddEllipsisAndDrawLine)
     */
    if (format & DT_MODIFYSTRING) {
        int iNewLen = (iUniString + CCHELLIPSIS + 1) * sizeof(*lpwstr);
        LPWSTR lpwstrNew = UserLocalReAlloc(lpwstr, iNewLen, HEAP_ZERO_MEMORY);
        if (lpwstrNew == NULL) {
            UserLocalFree((HANDLE)lpwstr);
            return FALSE;
        }
        lpwstr = lpwstrNew;
    }

    iRet = DrawTextExWorker(hdc, lpwstr, iUniString, lprc, format, lpdtp, GetTextCharset(hdc));

    if (format & DT_MODIFYSTRING) {
        /*
         * Note that if the buffer grew and the caller provided the string size,
         *  then we won't return the additional characters... fixing this
         *  might break some apps so let's leave it alone until some one complains
         */
        if (cchText < 0) {
            UserAssert(cchText == USER_AWCONV_COUNTSTRINGSZ);
            // Guess how many bytes we can put in the buffer...
            // We can safely assume the maximum bytes available.
            // At worst, even for DBCS, the buffer size required
            // will be smaller than or equal to the orignal size,
            // because some DBCS characters would be substituted
            // to SBC ".", which is one byte each.
            // On the other hand, the number of characters converted
            // is limited by both iUniString and cchText.
            //
            if (IS_DBCS_ENABLED()) {
                cchText = iUniString * DBCS_CHARSIZE;
            } else {
                cchText = iUniString * sizeof(CHAR);
            }
        }
        WCSToMBEx(wCodePage, lpwstr, iUniString, &lpchText, cchText, FALSE);
    }

    if (lpwstr != gwszNullStr) {
        UserLocalFree((HANDLE)lpwstr);
    }

    return iRet;
}