[Libreoffice-commits] core.git: 2 commits - chart2/source include/vcl

Jan Holesovsky kendy at collabora.com
Sun May 25 02:43:38 PDT 2014


 chart2/source/view/main/3DChartObjects.cxx |   10 +---
 include/vcl/outdev.hxx                     |   59 ++++++++++++++++++++++++++++-
 2 files changed, 61 insertions(+), 8 deletions(-)

New commits:
commit 04e3af7a04f3c4d299ab1f60766dbc052292be26
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Sun May 25 11:12:59 2014 +0200

    Improve computation of the text area to make it nicer.
    
    Change-Id: I24fb1caedc55dcc297fb013acb63b3c660fcf0a2

diff --git a/chart2/source/view/main/3DChartObjects.cxx b/chart2/source/view/main/3DChartObjects.cxx
index c77a273..3432bac 100644
--- a/chart2/source/view/main/3DChartObjects.cxx
+++ b/chart2/source/view/main/3DChartObjects.cxx
@@ -78,18 +78,14 @@ const BitmapEx& TextCache::getText(OUString rText)
     Font aFont = aDevice.GetFont();
     aFont.SetSize(Size(0, 96));
     aFont.SetColor(COL_BLACK);
-    ::Rectangle aRect;
     aDevice.SetFont(aFont);
     aDevice.Erase();
-    aDevice.GetTextBoundRect(aRect, rText);
-    Size aSize = aRect.GetSize();
-    aSize.Width() += 5;
-    aSize.Height() *= 1.6;
-    aDevice.SetOutputSizePixel(aSize);
+
+    aDevice.SetOutputSize(Size(aDevice.GetTextWidth(rText), aDevice.GetTextHeight()));
     aDevice.SetBackground(Wallpaper(COL_TRANSPARENT));
     aDevice.DrawText(Point(0,0), rText);
 
-    BitmapEx* pText = new BitmapEx(aDevice.GetBitmapEx(Point(0,0), aSize));
+    BitmapEx* pText = new BitmapEx(aDevice.GetBitmapEx(Point(0,0), aDevice.GetOutputSize()));
     maTextCache.insert(rText, pText);
     return *pText;
 }
commit 8847171b6b848ee92c6679cbdffd6ed06f29ca3b
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Sun May 25 11:35:08 2014 +0200

    vcl: Document GetTextBoundRect() / GetTextWidth() / GetTextHeight().
    
    GetTextBoundRect() fits different situations than the GetTextWidth() /
    GetTextHeight() combination, so make it clear in the documentation.
    
    These are complex enough that people shouldn't read the code just to
    understand the difference, and misunderstanding of purpose of each leads
    to visually not nice results.
    
    Change-Id: Ida71477cdffbd8290328551bd6ddb4805b96c415

diff --git a/include/vcl/outdev.hxx b/include/vcl/outdev.hxx
index 0c18525..8e57855 100644
--- a/include/vcl/outdev.hxx
+++ b/include/vcl/outdev.hxx
@@ -941,6 +941,55 @@ public:
                                              TextRectInfo* pInfo = NULL,
                                              const ::vcl::ITextLayout* _pTextLayout = NULL ) const;
 
+    /** Return the exact bounding rectangle of rStr.
+
+        The text is then drawn exactly from rRect.TopLeft() to
+        rRect.BottomRight(), don't assume that rRect.TopLeft() is [0, 0].
+
+        Please note that you don't always want to use GetTextBoundRect(); in
+        many cases you actually want to use GetTextHeight(), because
+        GetTextBoundRect() gives you the exact bounding rectangle regardless
+        what is the baseline of the text.
+
+        Code snippet to get just exactly the text (no filling around that) as
+        a bitmap via a VirtualDevice (regardless what is the baseline):
+
+        <code>
+        VirtualDevice aDevice;
+        Font aFont = aDevice.GetFont();
+        aFont.SetSize(Size(0, 96));
+        aFont.SetColor(COL_BLACK);
+        aDevice.SetFont(aFont);
+        aDevice.Erase();
+
+        ::Rectangle aRect;
+        aDevice.GetTextBoundRect(aRect, aText);
+        aDevice.SetOutputSize(Size(aRect.BottomRight().X() + 1, aRect.BottomRight().Y() + 1));
+        aDevice.SetBackground(Wallpaper(COL_TRANSPARENT));
+        aDevice.DrawText(Point(0,0), aText);
+
+        // exactly only the text, regardless of the baseline
+        Bitmap aBitmap(aDevice.GetBitmap(aRect.TopLeft(), aRect.GetSize()));
+        </code>
+
+        Code snippet to get the text as a bitmap via a Virtual device that
+        contains even the filling so that the baseline is always preserved
+        (ie. the text will not jump up and down according to whether it
+        contains 'y' or not etc.)
+
+        <code>
+        VirtualDevice aDevice;
+        // + the appropriate font / device setup, see above
+
+        aDevice.SetOutputSize(Size(aDevice.GetTextWidth(aText), aDevice.GetTextHeight()));
+        aDevice.SetBackground(Wallpaper(COL_TRANSPARENT));
+        aDevice.DrawText(Point(0,0), aText);
+
+        // bitmap that contains even the space around the text,
+        // that means, preserves the baseline etc.
+        Bitmap aBitmap(aDevice.GetBitmap(Point(0, 0), aDevice.GetOutputSize()));
+        </code>
+    */
     bool                        GetTextBoundRect( Rectangle& rRect,
                                                   const OUString& rStr, sal_Int32 nBase = 0, sal_Int32 nIndex = 0, sal_Int32 nLen = -1,
                                                   sal_uLong nLayoutWidth = 0, const sal_Int32* pDXArray = NULL ) const;
@@ -1009,8 +1058,16 @@ public:
     void                        SetTextAlign( TextAlign eAlign );
     TextAlign                   GetTextAlign() const { return maFont.GetAlign(); }
 
+    /** Width of the text.
+
+        See also GetTextBoundRect() for more explanation + code examples.
+    */
     long                        GetTextWidth( const OUString& rStr, sal_Int32 nIndex = 0, sal_Int32 nLen = -1 ) const;
-    /// Height where any character of the current font fits; in logic coordinates.
+
+    /** Height where any character of the current font fits; in logic coordinates.
+
+        See also GetTextBoundRect() for more explanation + code examples.
+    */
     long                        GetTextHeight() const;
     float                       approximate_char_width() const;
 


More information about the Libreoffice-commits mailing list