Add wxGraphicsRenderer::CreateFontAtDPI to support font with fractional pixel-size
This commit is contained in:
@@ -2792,7 +2792,7 @@ wxD2DPenData* wxGetD2DPenData(const wxGraphicsPen& pen)
|
||||
class wxD2DFontData : public wxGraphicsObjectRefData
|
||||
{
|
||||
public:
|
||||
wxD2DFontData(wxGraphicsRenderer* renderer, const wxFont& font, const wxColor& color);
|
||||
wxD2DFontData(wxGraphicsRenderer* renderer, const wxFont& font, const wxRealPoint& dpi, const wxColor& color);
|
||||
|
||||
wxCOMPtr<IDWriteTextLayout> CreateTextLayout(const wxString& text) const;
|
||||
|
||||
@@ -2817,7 +2817,7 @@ private:
|
||||
bool m_strikethrough;
|
||||
};
|
||||
|
||||
wxD2DFontData::wxD2DFontData(wxGraphicsRenderer* renderer, const wxFont& font, const wxColor& color) :
|
||||
wxD2DFontData::wxD2DFontData(wxGraphicsRenderer* renderer, const wxFont& font, const wxRealPoint& dpi, const wxColor& color) :
|
||||
wxGraphicsObjectRefData(renderer), m_brushData(renderer, wxBrush(color)),
|
||||
m_underlined(font.GetUnderlined()), m_strikethrough(font.GetStrikethrough())
|
||||
{
|
||||
@@ -2870,13 +2870,17 @@ wxD2DFontData::wxD2DFontData(wxGraphicsRenderer* renderer, const wxFont& font, c
|
||||
hr = familyNames->GetString(0, name, length+1);
|
||||
wxCHECK_HRESULT_RET(hr);
|
||||
|
||||
FLOAT fontSize = (FLOAT)(!dpi.y
|
||||
? font.GetPixelSize().GetHeight()
|
||||
: (font.GetFractionalPointSize() * dpi.y / 72.0f));
|
||||
|
||||
hr = wxDWriteFactory()->CreateTextFormat(
|
||||
name,
|
||||
NULL,
|
||||
m_font->GetWeight(),
|
||||
m_font->GetStyle(),
|
||||
m_font->GetStretch(),
|
||||
(FLOAT)(font.GetPixelSize().GetHeight()),
|
||||
fontSize,
|
||||
L"en-us",
|
||||
&m_textFormat);
|
||||
|
||||
@@ -3644,7 +3648,7 @@ public:
|
||||
|
||||
void Flush() wxOVERRIDE;
|
||||
|
||||
void GetDPI(wxDouble* dpiX, wxDouble* dpiY) wxOVERRIDE;
|
||||
void GetDPI(wxDouble* dpiX, wxDouble* dpiY) const wxOVERRIDE;
|
||||
|
||||
wxD2DContextSupplier::ContextType GetContext() wxOVERRIDE
|
||||
{
|
||||
@@ -4570,7 +4574,7 @@ void wxD2DContext::Flush()
|
||||
GetRenderTarget()->SetTransform(&currTransform);
|
||||
}
|
||||
|
||||
void wxD2DContext::GetDPI(wxDouble* dpiX, wxDouble* dpiY)
|
||||
void wxD2DContext::GetDPI(wxDouble* dpiX, wxDouble* dpiY) const
|
||||
{
|
||||
FLOAT x, y;
|
||||
GetRenderTarget()->GetDpi(&x, &y);
|
||||
@@ -4653,6 +4657,10 @@ public :
|
||||
int flags = wxFONTFLAG_DEFAULT,
|
||||
const wxColour& col = *wxBLACK) wxOVERRIDE;
|
||||
|
||||
virtual wxGraphicsFont CreateFontAtDPI(const wxFont& font,
|
||||
const wxRealPoint& dpi,
|
||||
const wxColour& col) wxOVERRIDE;
|
||||
|
||||
// create a graphics bitmap from a native bitmap
|
||||
wxGraphicsBitmap CreateBitmapFromNativeBitmap(void* bitmap) wxOVERRIDE;
|
||||
|
||||
@@ -4886,7 +4894,30 @@ wxImage wxD2DRenderer::CreateImageFromBitmap(const wxGraphicsBitmap& bmp)
|
||||
|
||||
wxGraphicsFont wxD2DRenderer::CreateFont(const wxFont& font, const wxColour& col)
|
||||
{
|
||||
wxD2DFontData* fontData = new wxD2DFontData(this, font, col);
|
||||
return CreateFontAtDPI(font, wxRealPoint(), col);
|
||||
}
|
||||
|
||||
wxGraphicsFont wxD2DRenderer::CreateFont(
|
||||
double sizeInPixels, const wxString& facename,
|
||||
int flags,
|
||||
const wxColour& col)
|
||||
{
|
||||
// Use the same DPI as wxFont will use in SetPixelSize, so these cancel
|
||||
// each other out and we are left with the actual pixel size.
|
||||
ScreenHDC hdc;
|
||||
wxRealPoint dpi(::GetDeviceCaps(hdc, LOGPIXELSX),
|
||||
::GetDeviceCaps(hdc, LOGPIXELSY));
|
||||
|
||||
return CreateFontAtDPI(
|
||||
wxFontInfo(wxSize(sizeInPixels, sizeInPixels)).AllFlags(flags).FaceName(facename),
|
||||
dpi, col);
|
||||
}
|
||||
|
||||
wxGraphicsFont wxD2DRenderer::CreateFontAtDPI(const wxFont& font,
|
||||
const wxRealPoint& dpi,
|
||||
const wxColour& col)
|
||||
{
|
||||
wxD2DFontData* fontData = new wxD2DFontData(this, font, dpi, col);
|
||||
if ( !fontData->GetFont() )
|
||||
{
|
||||
// Apparently a non-TrueType font is given and hence
|
||||
@@ -4901,16 +4932,6 @@ wxGraphicsFont wxD2DRenderer::CreateFont(const wxFont& font, const wxColour& col
|
||||
return graphicsFont;
|
||||
}
|
||||
|
||||
wxGraphicsFont wxD2DRenderer::CreateFont(
|
||||
double sizeInPixels, const wxString& facename,
|
||||
int flags,
|
||||
const wxColour& col)
|
||||
{
|
||||
return CreateFont(
|
||||
wxFontInfo(wxSize(sizeInPixels, sizeInPixels)).AllFlags(flags).FaceName(facename),
|
||||
col);
|
||||
}
|
||||
|
||||
// create a sub-image from a native image representation
|
||||
wxGraphicsBitmap wxD2DRenderer::CreateSubBitmap(const wxGraphicsBitmap& bitmap, wxDouble x, wxDouble y, wxDouble w, wxDouble h)
|
||||
{
|
||||
|
Reference in New Issue
Block a user