Skip to content

Commit

Permalink
windows terminal supports color fonts
Browse files Browse the repository at this point in the history
  • Loading branch information
markisch committed Oct 5, 2017
1 parent 5cf79b7 commit b9b9d8d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
7 changes: 7 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
2017-10-05 Bastian Maerkisch <[email protected]>

* src/win/wd2d.cpp: Enable color font support. This enables colored
emojis, which can be used e.g. as point symbols. Due to the default
font-fallback to "Segoe UI Emoji", this might lead to unexpected
results if a plot relied on non-colored character fallbacks.

2017-10-03 Ethan A Merritt <[email protected]>

* term/gd.trm: Report number of frames in completed animation sequence.
Expand Down
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Changes not in 5.2
* CHANGE remove deprecated option "thru"
* CHANGE special case optimization of nonlinear code to speed up logscale
* CHANGE windows terminal can print using Direct2D
* CHANGE windows terminal supports color fonts (Direct2D)
* FIX allow mixed use of in-key plot titles and manually placed titles

New features, changes and fixes in gnuplot version 5.2
Expand Down
39 changes: 31 additions & 8 deletions src/win/wd2d.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* $Id: wd2d.cpp,v 1.33 2017-08-05 20:04:56 markisch Exp $
* $Id: wd2d.cpp,v 1.34 2017-10-05 08:43:43 markisch Exp $
*/

/*
Expand Down Expand Up @@ -71,6 +71,11 @@ extern "C" {
# define HAVE_UUIDOF
#endif

// Note: This may or may not be declared in an enum in SDK headers.
// Unfortunalely we cannot test for the SDK version here, so we always define it
// ourselves. MinGW headers currently do define that anyway.
# define D2D1_DRAW_TEXT_OPTIONS_ENABLE_COLOR_FONT static_cast<D2D1_DRAW_TEXT_OPTIONS>(0x00000004)

#define MINMAX(a,val,b) (((val) <= (a)) ? (a) : ((val) <= (b) ? (val) : (b)))
const int pattern_num = 8;
const float textbox_width = 3000.f;
Expand All @@ -88,6 +93,7 @@ static IWICImagingFactory * g_wicFactory = NULL;
// All graph windows share a common DC render target
static ID2D1DCRenderTarget * g_pRenderTarget = NULL;
#endif
static bool bHaveColorFonts = false;

static HRESULT d2dCreateStrokeStyle(D2D1_DASH_STYLE dashStyle, BOOL rounded, ID2D1StrokeStyle **ppStrokeStyle);
static HRESULT d2dCreateStrokeStyle(const FLOAT * dashes, UINT dashesCount, BOOL rounded, ID2D1StrokeStyle **ppStrokeStyle);
Expand Down Expand Up @@ -131,7 +137,6 @@ inline void SafeRelease(Interface **ppInterfaceToRelease)

/* Internal state of enhanced text processing.
*/

static struct {
ID2D1RenderTarget * pRenderTarget;
IDWriteTextFormat * pWriteTextFormat;
Expand Down Expand Up @@ -367,6 +372,17 @@ d2dInit(LPGW lpgw)
hr = d2dCreateDeviceSwapChainBitmap(lpgw);
#endif
#endif

// Test for Windows 8.1 or later (version >= 6.3).
// We don't use versionhelpers.h as this is not available for OpenWatcom.
// Note: We should rather do a feature test here.
OSVERSIONINFO versionInfo;
ZeroMemory(&versionInfo, sizeof(OSVERSIONINFO));
versionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&versionInfo);
if ((versionInfo.dwMajorVersion > 6) ||
((versionInfo.dwMajorVersion == 6) && (versionInfo.dwMajorVersion == 3)))
bHaveColorFonts = true;
}
return hr;
}
Expand Down Expand Up @@ -866,9 +882,13 @@ EnhancedPutText(int x, int y, char * text)
if (enhstate.lpgw->angle != 0)
pRenderTarget->SetTransform(D2D1::Matrix3x2F::Rotation(-enhstate.lpgw->angle, D2D1::Point2F(x, y)));
const float align_ofs = 0.;
D2D1_DRAW_TEXT_OPTIONS options = D2D1_DRAW_TEXT_OPTIONS_NONE;
if (bHaveColorFonts)
options = D2D1_DRAW_TEXT_OPTIONS_ENABLE_COLOR_FONT;
pRenderTarget->DrawText(textw, static_cast<UINT32>(wcslen(textw)), enhstate_d2d.pWriteTextFormat,
D2D1::RectF(x + align_ofs, y - enhstate.lpgw->tmAscent,
x + align_ofs + textbox_width, 8888), enhstate_d2d.pBrush);
D2D1::RectF(x + align_ofs, y - enhstate.lpgw->tmAscent,
x + align_ofs + textbox_width, 8888),
enhstate_d2d.pBrush, options);
if (enhstate.lpgw->angle != 0)
pRenderTarget->SetTransform(D2D1::Matrix3x2F::Identity());

Expand Down Expand Up @@ -1571,10 +1591,13 @@ d2d_do_draw(LPGW lpgw, ID2D1RenderTarget * pRenderTarget, LPRECT rect, bool inte
if (textw) {
if (lpgw->angle != 0)
pRenderTarget->SetTransform(D2D1::Matrix3x2F::Rotation(-lpgw->angle, D2D1::Point2F(xdash + hshift, ydash + vshift)));

D2D1_DRAW_TEXT_OPTIONS options = D2D1_DRAW_TEXT_OPTIONS_NONE;
if (bHaveColorFonts)
options = D2D1_DRAW_TEXT_OPTIONS_ENABLE_COLOR_FONT;
pRenderTarget->DrawText(textw, static_cast<UINT32>(wcslen(textw)), pWriteTextFormat,
D2D1::RectF(xdash + hshift + align_ofs, ydash + vshift,
xdash + hshift + align_ofs + textbox_width, 8888), pSolidBrush);
D2D1::RectF(xdash + hshift + align_ofs, ydash + vshift,
xdash + hshift + align_ofs + textbox_width, 8888),
pSolidBrush, options);
if (lpgw->angle != 0)
pRenderTarget->SetTransform(D2D1::Matrix3x2F::Identity());

Expand Down Expand Up @@ -2372,7 +2395,7 @@ d2d_do_draw(LPGW lpgw, ID2D1RenderTarget * pRenderTarget, LPRECT rect, bool inte
}
#endif

// TODO: some of these resource are device independent and could be preserved
// TODO: some of these resources are device independent and could be preserved
SafeRelease(&pSolidBrush);
SafeRelease(&pSolidFillBrush);
SafeRelease(&pPatternFillBrush);
Expand Down

0 comments on commit b9b9d8d

Please sign in to comment.