From 299280cbe069acc335ba2f2d553f840ec4881913 Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Wed, 31 Aug 2016 11:35:45 -0700 Subject: [PATCH] fix windows systemfont bold --- .../cocos/platform/win32/CCDevice-win32.cpp | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/native/cocos/platform/win32/CCDevice-win32.cpp b/native/cocos/platform/win32/CCDevice-win32.cpp index 6b938365f3..6ca37016ec 100644 --- a/native/cocos/platform/win32/CCDevice-win32.cpp +++ b/native/cocos/platform/win32/CCDevice-win32.cpp @@ -99,7 +99,7 @@ public: } - bool setFont(const char * pFontName = nullptr, int nSize = 0) + bool setFont(const char * pFontName = nullptr, int nSize = 0, bool enableBold = false) { bool bRet = false; do @@ -139,16 +139,27 @@ public: tNewFont.lfCharSet = DEFAULT_CHARSET; strcpy_s(tNewFont.lfFaceName, LF_FACESIZE, fontName.c_str()); } + if (nSize) { tNewFont.lfHeight = -nSize; } - GetObjectA(_font, sizeof(tOldFont), &tOldFont); + + if (enableBold) + { + tNewFont.lfWeight = FW_BOLD; + } + else + { + tNewFont.lfWeight = FW_NORMAL; + } + + GetObjectA(_font, sizeof(tOldFont), &tOldFont); if (tOldFont.lfHeight == tNewFont.lfHeight + && tOldFont.lfWeight == tNewFont.lfWeight && 0 == strcmp(tOldFont.lfFaceName, tNewFont.lfFaceName)) { - // already has the font bRet = true; break; } @@ -175,7 +186,7 @@ public: // disable Cleartype tNewFont.lfQuality = ANTIALIASED_QUALITY; - + // create new font _font = CreateFontIndirectA(&tNewFont); if (! _font) @@ -438,7 +449,7 @@ Data Device::getTextureDataForText(const std::string& text, const FontDefinition { BitmapDC& dc = sharedBitmapDC(); - if (! dc.setFont(textDefinition._fontName.c_str(), textDefinition._fontSize)) + if (! dc.setFont(textDefinition._fontName.c_str(), textDefinition._fontSize, textDefinition._enableBold)) { log("Can't found font(%s), use system default", textDefinition._fontName.c_str()); }