]> granicus.if.org Git - graphviz/commitdiff
gdiplus plugin: remove manual memory management of font pointers
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 18 Apr 2021 00:11:33 +0000 (17:11 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 24 Apr 2021 03:14:26 +0000 (20:14 -0700)
plugin/gdiplus/gvplugin_gdiplus.h
plugin/gdiplus/gvrender_gdiplus.cpp
plugin/gdiplus/gvtextlayout_gdiplus.cpp

index 28f6f78020a4120aff0a3eab864a71f3d15c6d23..0fb9e3ae9707a7385b8cc322f49471648ecfcfe9 100644 (file)
@@ -11,6 +11,7 @@
 #ifndef GVPLUGIN_GDIPLUS_H
 #define GVPLUGIN_GDIPLUS_H
 
+#include <memory>
 #include <vector>
 
 #include <Windows.h>
@@ -50,11 +51,10 @@ struct DeviceContext
 
 struct Layout
 {
-       Gdiplus::Font* font;
+       std::unique_ptr<Gdiplus::Font> font;
        std::vector<WCHAR> text;
        
        Layout(char *fontname, double fontsize, char* string);
-       ~Layout();
 };
 
 static const int BYTES_PER_PIXEL = 4;          /* bytes per pixel */
index ae18cd57c80d3bd4d2f37d998837ce2739531687..f2dba8a45ea0dd899c82f4848b8be76d633ced6c 100644 (file)
@@ -176,7 +176,7 @@ static void gdiplusgen_textspan(GVJ_t *job, pointf p, textspan_t *span)
 
                /* draw the text */
                SolidBrush brush(Color(job->obj->pencolor.u.rgba [3], job->obj->pencolor.u.rgba [0], job->obj->pencolor.u.rgba [1], job->obj->pencolor.u.rgba [2]));
-       context->DrawString(&layout->text[0], layout->text.size(), layout->font, PointF(p.x, -p.y), GetGenericTypographic(), &brush);
+       context->DrawString(&layout->text[0], layout->text.size(), layout->font.get(), PointF(p.x, -p.y), GetGenericTypographic(), &brush);
        
        if (span->free_layout != &gdiplus_free_layout)
                delete layout;
index 03953b4125aae5ee4e620ebfc9f24c0de72f96be..07a49a1993ab5f985b081ceaccaf157fdab284b1 100644 (file)
@@ -10,6 +10,7 @@
 
 #include "config.h"
 
+#include <memory>
 #include <stdlib.h>
 #include <string.h>
 
@@ -53,15 +54,10 @@ Layout::Layout(char *fontname, double fontsize, char* string)
                0) == 0) {
                found_font.lfHeight = (LONG)-fontsize;
                found_font.lfWidth = 0;
-               font = new Font(reference.hdc, &found_font);
+               font = std::unique_ptr<Font>(new Font(reference.hdc, &found_font));
        }
        else
-               font = new Font(FontFamily::GenericSerif(), fontsize);
-}
-
-Layout::~Layout()
-{
-       delete font;
+               font = std::unique_ptr<Font>(new Font(FontFamily::GenericSerif(), fontsize));
 }
 
 void gdiplus_free_layout(void *layout)
@@ -86,7 +82,7 @@ boolean gdiplus_textlayout(textspan_t *span, char **fontpath)
        measureGraphics.MeasureString(
                &layout->text[0],
                layout->text.size(),
-               layout->font,
+               layout->font.get(),
                PointF(0.0f, 0.0f),
                GetGenericTypographic(),
                &boundingBox);