From 1119a44cdd5f5710d14a4d6bb9b67f55ba496258 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 30 Jan 2018 01:21:24 +0100 Subject: [PATCH] Simplify and make more portable DWrite font weight translation There doesn't seem to be any need for painstakingly translating STC font weight to DWRITE_FONT_WEIGHT when they seem to use exactly the same numeric values anyhow. This also fixes compilation when using older SDK versions that don't define DWRITE_FONT_WEIGHT_SEMI_LIGHT constant, which is relatively recent (and presence of which can't be easily checked, as it's an enum element and not a preprocessor constant). --- src/stc/PlatWX.cpp | 51 +--------------------------------------------- 1 file changed, 1 insertion(+), 50 deletions(-) diff --git a/src/stc/PlatWX.cpp b/src/stc/PlatWX.cpp index 22339fb672..431d7a7361 100644 --- a/src/stc/PlatWX.cpp +++ b/src/stc/PlatWX.cpp @@ -710,8 +710,6 @@ SurfaceFontDataD2D::SurfaceFontDataD2D(const FontParameters& fp) wxCOMPtr pTextLayout; wxString faceName = fp.faceName; wxString extentTest(EXTENT_TEST); - int weight = fp.weight; - DWRITE_FONT_WEIGHT fontWeight; DWRITE_FONT_STYLE fontStyle; DWRITE_TEXT_METRICS textmetrics = {0,0,0,0,0,0,0,0,0}; const int maxLines = 2; @@ -720,59 +718,12 @@ SurfaceFontDataD2D::SurfaceFontDataD2D(const FontParameters& fp) FLOAT emHeight = 0; HRESULT hr; - if ( weight <= 100 ) - { - fontWeight = DWRITE_FONT_WEIGHT_THIN; - } - else if ( weight <= 200 ) - { - fontWeight = DWRITE_FONT_WEIGHT_EXTRA_LIGHT; - } - else if ( weight <= 300 ) - { - fontWeight = DWRITE_FONT_WEIGHT_LIGHT; - } -#ifndef __MINGW64_TOOLCHAIN__ - else if ( weight <= 350 ) - { - fontWeight = DWRITE_FONT_WEIGHT_SEMI_LIGHT; - } -#endif - else if ( weight <= 400 ) - { - fontWeight = DWRITE_FONT_WEIGHT_NORMAL; - } - else if ( weight <= 500 ) - { - fontWeight = DWRITE_FONT_WEIGHT_MEDIUM; - } - else if ( weight <= 600 ) - { - fontWeight = DWRITE_FONT_WEIGHT_SEMI_BOLD; - } - else if ( weight <= 700 ) - { - fontWeight = DWRITE_FONT_WEIGHT_BOLD; - } - else if ( weight <= 800 ) - { - fontWeight = DWRITE_FONT_WEIGHT_EXTRA_BOLD; - } - else if ( weight <= 900 ) - { - fontWeight = DWRITE_FONT_WEIGHT_HEAVY; - } - else - { - fontWeight = DWRITE_FONT_WEIGHT_EXTRA_BLACK; - } - fontStyle = fp.italic?DWRITE_FONT_STYLE_ITALIC:DWRITE_FONT_STYLE_NORMAL; hr = pDWriteFactory->CreateTextFormat( faceName.wc_str(), NULL, - fontWeight, + static_cast(fp.weight), fontStyle, DWRITE_FONT_STRETCH_NORMAL, fp.size,