diff options
author | Marco Cecchetti <marco.cecchetti@collabora.com> | 2017-09-03 20:29:05 +0200 |
---|---|---|
committer | Jan Holesovsky <kendy@collabora.com> | 2017-09-06 19:25:46 +0200 |
commit | ad06345e8b5080324d4284fa428afd228bc1f87c (patch) | |
tree | 62fe481fc69939501949d54eddbf89b0e1e581e8 | |
parent | 31ad6275de88b1dd5aba86ff45e3c9a159e4a48e (diff) |
lok - support for watermark
Extends doc_renderFont in order to generate text of requested size.
Change-Id: I0ebd48f8714b7772b764f3aba3e13754869c5117
Reviewed-on: https://gerrit.libreoffice.org/41899
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Jan Holesovsky <kendy@collabora.com>
-rw-r--r-- | desktop/source/lib/init.cxx | 49 |
1 files changed, 44 insertions, 5 deletions
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index fca53b297529..ad88ab270252 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -2872,6 +2872,8 @@ unsigned char* doc_renderFont(SAL_UNUSED_PARAMETER LibreOfficeKitDocument* /*pTh pDocSh->GetItem(SID_ATTR_CHAR_FONTLIST)); const FontList* pList = pFonts ? pFonts->GetFontList() : nullptr; + const int nDefaultFontSize = 25; + if ( pList ) { sal_uInt16 nFontCount = pList->GetFontNameCount(); @@ -2890,30 +2892,67 @@ unsigned char* doc_renderFont(SAL_UNUSED_PARAMETER LibreOfficeKitDocument* /*pTh nullptr, Size(1, 1), DeviceFormat::DEFAULT)); ::tools::Rectangle aRect; vcl::Font aFont(rFontMetric); - aFont.SetFontSize(Size(0, 25)); + aFont.SetFontSize(Size(0, nDefaultFontSize)); aDevice->SetFont(aFont); aDevice->GetTextBoundRect(aRect, aText); if (aRect.IsEmpty()) break; int nFontWidth = aRect.BottomRight().X() + 1; - *pFontWidth = nFontWidth; int nFontHeight = aRect.BottomRight().Y() + 1; - *pFontHeight = nFontHeight; + if (!(nFontWidth > 0 && nFontHeight > 0)) break; + if (*pFontWidth > 0 && *pFontHeight > 0) + { + double fScaleX = *pFontWidth / static_cast<double>(nFontWidth); + double fScaleY = *pFontHeight / static_cast<double>(nFontHeight); + + double fScale = std::min(fScaleX, fScaleY); + + if (fScale >= 1.0) + { + int nFontSize = fScale * nDefaultFontSize; + aFont.SetFontSize(Size(0, nFontSize)); + aDevice->SetFont(aFont); + } + + aRect = tools::Rectangle(0, 0, *pFontWidth, *pFontHeight); + + nFontWidth = *pFontWidth; + nFontHeight = *pFontHeight; + + } + unsigned char* pBuffer = static_cast<unsigned char*>(malloc(4 * nFontWidth * nFontHeight)); if (!pBuffer) break; memset(pBuffer, 0, nFontWidth * nFontHeight * 4); - aDevice->SetBackground(Wallpaper(COL_TRANSPARENT)); aDevice->SetOutputSizePixelScaleOffsetAndBuffer( Size(nFontWidth, nFontHeight), Fraction(1.0), Point(), pBuffer); - aDevice->DrawText(Point(0,0), aText); + + if (*pFontWidth > 0 && *pFontHeight > 0) + { + DrawTextFlags nStyle = + DrawTextFlags::Center + | DrawTextFlags::VCenter + | DrawTextFlags::MultiLine + | DrawTextFlags::WordBreakHyphenation;// | DrawTextFlags::WordBreak ; + + aDevice->DrawText(aRect, aText, nStyle); + } + else + { + *pFontWidth = nFontWidth; + *pFontHeight = nFontHeight; + + aDevice->DrawText(Point(0,0), aText); + } + return pBuffer; } |