diff --git a/uppsrc/CtrlCore/Ctrl.cpp b/uppsrc/CtrlCore/Ctrl.cpp index a559f08ce..139e55381 100644 --- a/uppsrc/CtrlCore/Ctrl.cpp +++ b/uppsrc/CtrlCore/Ctrl.cpp @@ -809,6 +809,18 @@ Font FontZ(int face, int height) return Font(face, Ctrl::VertLayoutZoom(height)); } +bool ApplicationHiDPIEnabled; + +void Ctrl::SetHiDPIEnabled(bool set) +{ + ApplicationHiDPIEnabled = set; +} + +bool Ctrl::GetHiDPIEnabled() +{ + return ApplicationHiDPIEnabled; +} + Font StdFontZ(int height) { return FontZ(Font::STDFONT, height); } Font SansSerifZ(int height) { return FontZ(Font::SANSSERIF, height); } Font SerifZ(int height) { return FontZ(Font::SERIF, height); } diff --git a/uppsrc/CtrlCore/CtrlCore.h b/uppsrc/CtrlCore/CtrlCore.h index 0b1e189aa..cebe38dbd 100644 --- a/uppsrc/CtrlCore/CtrlCore.h +++ b/uppsrc/CtrlCore/CtrlCore.h @@ -1201,6 +1201,9 @@ public: static Size LayoutZoom(Size sz); static void NoLayoutZoom(); static void GetZoomRatio(Size& m, Size& d); + + static void SetHiDPIEnabled(bool set = true); + static bool GetHiDPIEnabled(); static int Zx(int cx) { return HorzLayoutZoom(cx); } static int Zy(int cy) { return VertLayoutZoom(cy); } diff --git a/uppsrc/CtrlLib/ChGtk.cpp b/uppsrc/CtrlLib/ChGtk.cpp index 71217c43b..ede783221 100644 --- a/uppsrc/CtrlLib/ChGtk.cpp +++ b/uppsrc/CtrlLib/ChGtk.cpp @@ -495,7 +495,7 @@ void ChHostSkin() if(i == CTRL_DISABLED) GTK_WIDGET_FLAGS (w) &= GTK_SENSITIVE; img = GetGTK(w, GTK_STATE_NORMAL, GTK_SHADOW_IN, "entry", GTK_SHADOW, 20, 20); - if(i == 0) + if(i == 0) efm = max(ImageMargin(img, 4, 0), 1); if(!Qt) img = GetGTK(w, GTK_STATE_NORMAL, GTK_SHADOW_IN, diff --git a/uppsrc/CtrlLib/ChWin32.cpp b/uppsrc/CtrlLib/ChWin32.cpp index b7c5f24fa..75caf9e73 100644 --- a/uppsrc/CtrlLib/ChWin32.cpp +++ b/uppsrc/CtrlLib/ChWin32.cpp @@ -595,6 +595,24 @@ void ChSysInit() CtrlsImg::Reset(); ChReset(); XpClear(); + + BOOL (STDAPICALLTYPE * SetProcessDPIAware)(void); + DllFn(SetProcessDPIAware, "User32.dll", "SetProcessDPIAware"); + if(SetProcessDPIAware/* && Ctrl::IsHiDPIEnabled()*/) + (*SetProcessDPIAware)(); + NONCLIENTMETRICS ncm; +#if (WINVER >= 0x0600) + ncm.cbSize = sizeof(ncm) - sizeof(ncm.iPaddedBorderWidth); // WinXP does not like it... +#else + ncm.cbSize = sizeof(ncm); +#endif + ::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &ncm, 0); + String name = FromSystemCharset(ncm.lfMenuFont.lfFaceName); + int height = abs((int)ncm.lfMenuFont.lfHeight); + + int q = Font::FindFaceNameIndex(name); + if(height > 0 && height < 200) // sanity.. + SetStdFont(Font(q >= 0 ? q : Font::SANSSERIF, height)); GUI_HiDPI_Write(GetStdFontCy() > 22); diff --git a/uppsrc/Draw/Draw.cpp b/uppsrc/Draw/Draw.cpp index df9670ba7..389f5f0fb 100644 --- a/uppsrc/Draw/Draw.cpp +++ b/uppsrc/Draw/Draw.cpp @@ -29,11 +29,6 @@ void Draw::SinCos(int angle, double& sina, double& cosa) } } -Draw::Draw() -{ - hmul = 1; -} - Draw::~Draw() {} Size Draw::GetPixelsPerInch() const @@ -120,11 +115,6 @@ int Draw::GetCloffLevel() const { return 0; } // ------------------------------- -Image Draw::Hmul(const Image& img) -{ - return hmul ? CachedRescale(img, hmul * img.GetSize(), FILTER_LANCZOS3) : img; -} - void Draw::SysDrawImageOp(int x, int y, const Image& img, Color color) { NEVER(); @@ -185,12 +175,12 @@ void Draw::DrawRect(const Rect& rect, Color color) void Draw::DrawRect(int x, int y, int cx, int cy, Color color) { - DrawRectOp(Hmul(x), Hmul(y), Hmul(cx), Hmul(cy), color); + DrawRectOp(x, y, cx, cy, color); } void Draw::DrawImage(int x, int y, int cx, int cy, const Image& img, const Rect& src) { - DrawImageOp(Hmul(x), Hmul(y), Hmul(cx), Hmul(cy), Hmul(img), Hmul(src), Null); + DrawImageOp(x, y, cx, cy, img, src, Null); } void Draw::DrawImage(int x, int y, int cx, int cy, const Image& img) @@ -201,7 +191,7 @@ void Draw::DrawImage(int x, int y, int cx, int cy, const Image& img) void Draw::DrawImage(int x, int y, int cx, int cy, const Image& img, const Rect& src, Color color) { if(IsNull(color)) return; - DrawImageOp(Hmul(x), Hmul(y), Hmul(cx), Hmul(cy), Hmul(img), Hmul(src), color); + DrawImageOp(x, y, cx, cy, img, src, color); } void Draw::DrawImage(int x, int y, int cx, int cy, const Image& img, Color color) @@ -235,36 +225,36 @@ void Draw::DrawImage(const Rect& r, const Image& img, Color color) void Draw::DrawImage(int x, int y, const Image& img, const Rect& src) { Size sz = src.GetSize(); - DrawImageOp(Hmul(x), Hmul(y), Hmul(sz.cx), Hmul(sz.cy), img, Hmul(src), Null); + DrawImageOp(x, y, sz.cx, sz.cy, img, src, Null); } void Draw::DrawImage(int x, int y, const Image& img) { Size sz = img.GetSize(); - DrawImageOp(Hmul(x), Hmul(y), Hmul(sz.cx), Hmul(sz.cy), Hmul(img), Hmul(img.GetSize()), Null); + DrawImageOp(x, y, sz.cx, sz.cy, img, img.GetSize(), Null); } void Draw::DrawImage(int x, int y, const Image& img, const Rect& src, Color color) { if(IsNull(color)) return; - DrawImageOp(Hmul(x), Hmul(y), Hmul(src.Width()), Hmul(src.Height()), Hmul(img), Hmul(src), color); + DrawImageOp(x, y, src.Width(), src.Height(), img, src, color); } void Draw::DrawImage(int x, int y, const Image& img, Color color) { if(IsNull(color)) return; Size sz = img.GetSize(); - DrawImageOp(Hmul(x), Hmul(y), Hmul(sz.cx), Hmul(sz.cy), img, Hmul(sz), color); + DrawImageOp(x, y, sz.cx, sz.cy, img, sz, color); } void Draw::DrawData(int x, int y, int cx, int cy, const String& data, const char *type) { - DrawDataOp(Hmul(x), Hmul(y), Hmul(cx), Hmul(cy), data, type); + DrawDataOp(x, y, cx, cy, data, type); } void Draw::DrawData(const Rect& r, const String& data, const char *type) { - DrawDataOp(Hmul(r.left), Hmul(r.top), Hmul(r.GetWidth()), Hmul(r.GetHeight()), data, type); + DrawDataOp(r.left, r.top, r.GetWidth(), r.GetHeight(), data, type); } void Draw::DrawLine(Point p1, Point p2, int width, Color color) @@ -274,27 +264,15 @@ void Draw::DrawLine(Point p1, Point p2, int width, Color color) void Draw::DrawLine(int x1, int y1, int x2, int y2, int width, Color color) { - DrawLineOp(Hmul(x1), Hmul(y1), Hmul(x2), Hmul(y2), Hmul(width), color); -} - -Buffer Draw::Hmul(const Point *p, int count) -{ - Buffer r(count); - for(int i = 0; i < count; i++) - r[i] = hmul * p[i]; - return r; + DrawLineOp(x1, y1, x2, y2, width, color); } void Draw::DrawPolyPolyline(const Point *vertices, int vertex_count, const int *counts, int count_count, int width, Color color, Color doxor) { - if(hmul != 1) { - Buffer v2 = Hmul(vertices, vertex_count); - DrawPolyPolylineOp(~v2, vertex_count, counts, count_count, Hmul(width), color, doxor); - } - else - DrawPolyPolylineOp(vertices, vertex_count, counts, count_count, width, color, doxor); + DrawPolyPolylineOp(vertices, vertex_count, counts, count_count, width, + color, doxor); } void Draw::DrawPolyPolyline(const Vector& vertices, const Vector& counts, @@ -323,16 +301,9 @@ void Draw::DrawPolyPolyPolygon(const Point *vertices, int vertex_count, int disjunct_polygon_count_count, Color color, int width, Color outline, uint64 pattern, Color doxor) { - if(hmul != 1) { - Buffer v2 = Hmul(vertices, vertex_count); - DrawPolyPolyPolygonOp(~v2, vertex_count, subpolygon_counts, subpolygon_count_count, - disjunct_polygon_counts, disjunct_polygon_count_count, color, - width, outline, pattern, doxor); - } - else - DrawPolyPolyPolygonOp(vertices, vertex_count, subpolygon_counts, subpolygon_count_count, - disjunct_polygon_counts, disjunct_polygon_count_count, color, - width, outline, pattern, doxor); + DrawPolyPolyPolygonOp(vertices, vertex_count, subpolygon_counts, subpolygon_count_count, + disjunct_polygon_counts, disjunct_polygon_count_count, color, + width, outline, pattern, doxor); } void Draw::DrawPolyPolyPolygon(const Vector& vertices, @@ -397,17 +368,17 @@ void Draw::DrawPolygon(const Vector& vertices, void Draw::DrawEllipse(int x, int y, int cx, int cy, Color color, int pen, Color pencolor) { - DrawEllipse(RectC(x, y, cx, cy), color, Hmul(pen), pencolor); + DrawEllipse(RectC(x, y, cx, cy), color, pen, pencolor); } void Draw::DrawEllipse(const Rect& r, Color color, int pen, Color pencolor) { - DrawEllipseOp(Hmul(r), color, Hmul(pen), pencolor); + DrawEllipseOp(r, color, pen, pencolor); } void Draw::DrawArc(const Rect& rc, Point start, Point end, int width, Color color) { - DrawArcOp(Hmul(rc), Hmul(start), Hmul(end), Hmul(width), color); + DrawArcOp(rc, start, end, width, color); } void Draw::Offset(int x, int y) @@ -488,11 +459,10 @@ Drawing AsDrawing(const Painting& pw) return dw.GetResult(); } -void Draw::DrawPaintingOp(const Rect& target_, const Painting& pw) +void Draw::DrawPaintingOp(const Rect& target, const Painting& pw) { if(!HasPainter()) return; - Rect target = Hmul(target_); Size sz = target.GetSize(); if((sz.cx > 2000 || sz.cy > 1500) && IsPrinter()) { int yy = 0; diff --git a/uppsrc/Draw/Draw.h b/uppsrc/Draw/Draw.h index 5f9c114b3..4d39ae649 100644 --- a/uppsrc/Draw/Draw.h +++ b/uppsrc/Draw/Draw.h @@ -412,15 +412,6 @@ void PaintImageBuffer(ImageBuffer& ib, const Drawing& p, int mode = MODE_ANTIALI class Draw : NoCopy { struct DrawingPos; - int hmul; - - int Hmul(int x) { return hmul * x; } - Point Hmul(Point p) { return hmul * p; } - Size Hmul(Size sz) { return hmul * sz; } - Rect Hmul(const Rect& r) { return Rect(Hmul(r.left), Hmul(r.top), Hmul(r.right), Hmul(r.bottom)); } - Buffer Hmul(const Point *p, int count); - Image Hmul(const Image& img); - public: enum { DOTS = 0x001, @@ -610,16 +601,12 @@ public: static void SinCos(int angle, double& sina, double& cosa); - void HDPIMultiplier(int m) { hmul = m; } - // deprecated: static void SetStdFont(Font font) { UPP::SetStdFont(font); } static Font GetStdFont() { return UPP::GetStdFont(); } static Size GetStdFontSize() { return UPP::GetStdFontSize(); } static int GetStdFontCy() { return GetStdFontSize().cy; } Size GetPagePixels() const { return GetPageSize(); } - - Draw(); }; void DrawImageBandRLE(Draw& w, int x, int y, const Image& m, int minp); diff --git a/uppsrc/Draw/DrawText.cpp b/uppsrc/Draw/DrawText.cpp index de62b049b..cd8d112ac 100644 --- a/uppsrc/Draw/DrawText.cpp +++ b/uppsrc/Draw/DrawText.cpp @@ -31,17 +31,6 @@ WString TextUnicode(const char *s, int n, byte cs, Font font) void Draw::DrawText(int x, int y, int angle, const wchar *text, Font font, Color ink, int n, const int *dx) { - Buffer dx2; - if(hmul != 1) { - x = Hmul(x); - y = Hmul(y); - font.Height(Hmul(font.GetHeight())); - if(dx) { - dx2.Alloc(n); - for(int i = 0; i < n; i++) - dx2[i] = Hmul(dx[i]); - } - } #if defined(flagWINGL) || defined(flagLINUXGL) if(IsNull(ink)) return; @@ -124,7 +113,7 @@ void Draw::DrawText(int x, int y, int angle, const wchar *text, Font font, posx += dx ? *dx++ : gi.width; } - if((GetInfo() & DRAWTEXTLINES) && (font0.IsUnderline() || font0.IsStrikeout())) { + if((GetInfo() & DRAWTEXTLINES) && (font0.IsUnderline() || font0.IsStrikeout())) { int hg = abs(font0.GetCy()); if(hg == 0) hg = 10; int thickness = max(hg / 20, 1); @@ -233,7 +222,7 @@ void Draw::DrawText(int x, int y, const String& text, Font font, Color ink, cons Size GetTextSize(const wchar *text, Font font, int n) { #if defined(flagWINGL) || defined(flagLINUXGL) - return GetTextSize(text, resources.GetFont(font), n); + return GetTextSize(text, resources.GetFont(font), n); #else FontInfo fi = font.Info(); if(n < 0) diff --git a/uppsrc/Draw/Font.cpp b/uppsrc/Draw/Font.cpp index a35725c66..6329867ed 100644 --- a/uppsrc/Draw/Font.cpp +++ b/uppsrc/Draw/Font.cpp @@ -163,28 +163,11 @@ void Font::SetStdFont(Font font) void Font::InitStdFont() { - ONCELOCK { + ONCELOCK { // TODO: This is now sort of obsolete function.... Mutex::Lock __(sFontLock); FaceList(); AStdFont = Arial(12); - String name; - int height = 0; - GetStdFontSys(name, height); -#ifdef flagTEST_HIDPI - height *= 2; -#endif -#ifdef PLATFORM_WIN32 - int q = FindFaceNameIndex(name); - if(q <= 0) - q = FindFaceNameIndex("Tahoma"); - if(q <= 0) - q = FindFaceNameIndex("Microsoft Sans Serif"); - if(q <= 0) - q = FindFaceNameIndex("MS Sans Serif"); - if(q > 0) - AStdFont = Font(q, max(height, 1)); SyncStdFont(); -#endif } } diff --git a/uppsrc/Draw/FontFc.cpp b/uppsrc/Draw/FontFc.cpp index 988c396c4..a70fb6da5 100644 --- a/uppsrc/Draw/FontFc.cpp +++ b/uppsrc/Draw/FontFc.cpp @@ -15,11 +15,6 @@ FT_EXPORT( const char* ) FT_Get_X11_Font_Format( FT_Face face ); // Put here to NAMESPACE_UPP -void GetStdFontSys(String& name, int& height) -{ - name = "xxxx"; -} - static FT_Library sFTlib; EXITBLOCK diff --git a/uppsrc/Draw/FontInt.h b/uppsrc/Draw/FontInt.h index bea014e06..fb73e2bed 100644 --- a/uppsrc/Draw/FontInt.h +++ b/uppsrc/Draw/FontInt.h @@ -57,7 +57,6 @@ void InvalidateFontList(); CommonFontInfo GetFontInfoSys(Font font); GlyphInfo GetGlyphInfoSys(Font font, int chr); -void GetStdFontSys(String& name, int& height); Vector GetAllFacesSys(); String GetFontDataSys(Font font); diff --git a/uppsrc/Draw/FontWin32.cpp b/uppsrc/Draw/FontWin32.cpp index ad82260e8..bac51aa91 100644 --- a/uppsrc/Draw/FontWin32.cpp +++ b/uppsrc/Draw/FontWin32.cpp @@ -9,28 +9,6 @@ NAMESPACE_UPP #define LLOG(x) // LOG(x) #define LTIMING(x) // TIMING(x) -void GetStdFontSys(String& name, int& height) -{ -#ifdef PLATFORM_WINCE - name = "Arial"; - height = 10; -#else - BOOL (STDAPICALLTYPE * SetProcessDPIAware)(void); - DllFn(SetProcessDPIAware, "User32.dll", "SetProcessDPIAware"); - if(SetProcessDPIAware) - (*SetProcessDPIAware)(); - NONCLIENTMETRICS ncm; -#if (WINVER >= 0x0600) - ncm.cbSize = sizeof(ncm) - sizeof(ncm.iPaddedBorderWidth); // WinXP does not like it... -#else - ncm.cbSize = sizeof(ncm); -#endif - ::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &ncm, 0); - name = FromSystemCharset(ncm.lfMenuFont.lfFaceName); - height = abs((int)ncm.lfMenuFont.lfHeight); -#endif -} - #define FONTCACHE 96 struct HFontEntry {