27#include <com/sun/star/rendering/FontRequest.hpp>
28#include <com/sun/star/rendering/PanoseProportion.hpp>
29#include <com/sun/star/rendering/XCanvasFont.hpp>
32#include <rtl/math.hxx>
55 const uno::Reference< rendering::XGraphicDevice >& xGraphicDevice ) :
56 mxGraphicDevice(xGraphicDevice)
65 const std::shared_ptr<Gdiplus::Graphics>& rGraphics,
66 const css::rendering::ViewState& rViewState,
67 const css::rendering::RenderState& rRenderState,
68 const ::basegfx::B2ISize& rOutputOffset,
69 const css::rendering::StringContext& rText,
70 const css::uno::Sequence< double >& rLogicalAdvancements,
71 const css::uno::Sequence< sal_Bool >& rKashidaPositions,
72 const css::uno::Reference<
73 css::rendering::XCanvasFont >& rCanvasFont,
74 const css::geometry::Matrix2D& rFontMatrix,
78 HDC hdc = rGraphics->GetHDC();
81 const ::comphelper::ScopeGuard aGuard(
82 [&rGraphics, &hdc]()
mutable { rGraphics->ReleaseHDC(hdc); } );
86 aSystemGraphicsData.hDC =
reinterpret_cast< ::HDC
>(hdc);
92 xVirtualDevice->SetAntialiasing(AntialiasingFlags::DisableText);
98 "TextLayoutDrawHelper::drawText(): Invalid GraphicDevice" );
103 if( rRenderState.DeviceColor.getLength() > 2 )
105 rRenderState.DeviceColor,
108 xVirtualDevice->SetTextColor(aColor);
111 const css::rendering::FontRequest& rFontRequest = rCanvasFont->getFontRequest();
113 rFontRequest.FontDescription.FamilyName,
114 rFontRequest.FontDescription.StyleName,
115 Size( 0, ::basegfx::fround(rFontRequest.CellSize)));
118 aFont.
SetCharSet( (rFontRequest.FontDescription.IsSymbolFont==css::util::TriState_YES) ? RTL_TEXTENCODING_SYMBOL : RTL_TEXTENCODING_UNICODE );
119 aFont.
SetVertical( rFontRequest.FontDescription.IsVertical==css::util::TriState_YES );
120 aFont.
SetWeight(
static_cast<FontWeight>(rFontRequest.FontDescription.FontDescription.Weight) );
123 rFontRequest.FontDescription.FontDescription.Proportion == rendering::PanoseProportion::MONO_SPACED
133 if (pFont.is() && pFont->getEmphasisMark())
137 if(!::rtl::math::approxEqual(rFontMatrix.m00, rFontMatrix.m11))
139 const Size aSize = xVirtualDevice->GetFontMetric( aFont ).GetFontSize();
140 const double fDividend( rFontMatrix.m10 + rFontMatrix.m11 );
141 double fStretch = rFontMatrix.m00 + rFontMatrix.m01;
143 if( !::basegfx::fTools::equalZero( fDividend) )
144 fStretch /= fDividend;
146 const sal_Int32 nNewWidth = ::basegfx::fround( aSize.
Width() * fStretch );
152 xVirtualDevice->SetFont(aFont);
158 if(!rOutputOffset.equalZero())
160 aWorldTransform.
translate(rOutputOffset.getWidth(), rOutputOffset.getHeight());
164 if(rViewState.Clip.is())
168 ::basegfx::unotools::homMatrixFromAffineMatrix(aMatrix, rViewState.AffineTransform );
170 if(!rOutputOffset.equalZero())
172 aMatrix.
translate(rOutputOffset.getWidth(), rOutputOffset.getHeight());
177 xVirtualDevice->IntersectClipRegion(rClipRegion);
180 if(rRenderState.Clip.is())
185 xVirtualDevice->IntersectClipRegion(rClipRegion);
190 aXForm.eM11 =
static_cast<FLOAT>(aWorldTransform.
get(0, 0));
191 aXForm.eM12 =
static_cast<FLOAT>(aWorldTransform.
get(1, 0));
192 aXForm.eM21 =
static_cast<FLOAT>(aWorldTransform.
get(0, 1));
193 aXForm.eM22 =
static_cast<FLOAT>(aWorldTransform.
get(1, 1));
194 aXForm.eDx =
static_cast<FLOAT>(aWorldTransform.
get(0, 2));
195 aXForm.eDy =
static_cast<FLOAT>(aWorldTransform.
get(1, 2));
200 SetWorldTransform(hdc, &aXForm);
203 const Point aEmptyPoint(0, 0);
206 const OUString aText(rText.Text);
208 if( rLogicalAdvancements.getLength() )
211 const sal_Int32 nLen( rLogicalAdvancements.getLength() );
214 for( sal_Int32
i=0;
i<nLen; ++
i )
220 xVirtualDevice->DrawTextArray( aEmptyPoint,
226 bIsRTL ? SalLayoutFlags::BiDiRtl : SalLayoutFlags::NONE);
231 xVirtualDevice->DrawText( aEmptyPoint,
240 const uno::Sequence< double >& rLogicalAdvancements,
241 const uno::Reference< rendering::XCanvasFont >& rCanvasFont,
242 const geometry::Matrix2D& rFontMatrix )
245 return geometry::RealRectangle2D();
251 aSystemGraphicsData.hDC =
reinterpret_cast< ::HDC
>(
GetDC(
nullptr ));
255 const css::rendering::FontRequest& rFontRequest = rCanvasFont->getFontRequest();
257 rFontRequest.FontDescription.FamilyName,
258 rFontRequest.FontDescription.StyleName,
259 Size( 0, ::basegfx::fround(rFontRequest.CellSize)));
262 aFont.
SetCharSet( (rFontRequest.FontDescription.IsSymbolFont==css::util::TriState_YES) ? RTL_TEXTENCODING_SYMBOL : RTL_TEXTENCODING_UNICODE );
263 aFont.
SetVertical( rFontRequest.FontDescription.IsVertical==css::util::TriState_YES );
264 aFont.
SetWeight(
static_cast<FontWeight>(rFontRequest.FontDescription.FontDescription.Weight) );
267 rFontRequest.FontDescription.FontDescription.Proportion == rendering::PanoseProportion::MONO_SPACED
271 if(!::rtl::math::approxEqual(rFontMatrix.m00, rFontMatrix.m11))
273 const Size aSize = xVirtualDevice->GetFontMetric( aFont ).GetFontSize();
274 const double fDividend( rFontMatrix.m10 + rFontMatrix.m11 );
275 double fStretch = rFontMatrix.m00 + rFontMatrix.m01;
277 if( !::basegfx::fTools::equalZero( fDividend) )
278 fStretch /= fDividend;
280 const sal_Int32 nNewWidth = ::basegfx::fround( aSize.
Width() * fStretch );
286 if (pFont.is() && pFont->getEmphasisMark())
290 xVirtualDevice->SetFont(aFont);
294 const ::FontMetric& aMetric( xVirtualDevice->GetFontMetric() );
296 const sal_Int32 nAboveBaseline( -aMetric.GetInternalLeading() - aMetric.GetAscent() );
297 const sal_Int32 nBelowBaseline( aMetric.GetDescent() );
299 if( rLogicalAdvancements.getLength() )
301 return geometry::RealRectangle2D( 0, nAboveBaseline,
302 rLogicalAdvancements[ rLogicalAdvancements.getLength()-1 ],
307 return geometry::RealRectangle2D( 0, nAboveBaseline,
308 xVirtualDevice->GetTextWidth(
310 ::canvas::tools::numeric_cast<sal_uInt16>(rText.StartPosition),
311 ::canvas::tools::numeric_cast<sal_uInt16>(rText.Length) ),
void SetAlpha(sal_uInt8 nAlpha)
void reserve(size_t nCapacity)
void push_back(sal_Int32 nUnit)
static LanguageType convertToLanguageType(const css::lang::Locale &rLocale, bool bResolveSystem=true)
constexpr tools::Long Width() const
void translate(double fX, double fY)
double get(sal_uInt16 nRow, sal_uInt16 nColumn) const
void transform(const basegfx::B2DHomMatrix &rMatrix)
css::uno::Reference< css::rendering::XGraphicDevice > mxGraphicDevice
css::geometry::RealRectangle2D queryTextBounds(const css::rendering::StringContext &rText, const css::uno::Sequence< double > &rLogicalAdvancements, const css::uno::Reference< css::rendering::XCanvasFont > &rCanvasFont, const css::geometry::Matrix2D &rFontMatrix)
TextLayoutDrawHelper(const css::uno::Reference< css::rendering::XGraphicDevice > &xGraphicDevice)
void drawText(const std::shared_ptr< Gdiplus::Graphics > &rGraphics, const css::rendering::ViewState &rViewState, const css::rendering::RenderState &rRenderState, const ::basegfx::B2ISize &rOutputOffset, const css::rendering::StringContext &rText, const css::uno::Sequence< double > &rLogicalAdvancements, const css::uno::Sequence< sal_Bool > &rKashidaPositions, const css::uno::Reference< css::rendering::XCanvasFont > &rCanvasFont, const css::geometry::Matrix2D &rFontMatrix, bool bAlphaSurface, bool bIsRTL)
void SetVertical(bool bVertical)
void SetAverageFontWidth(tools::Long nWidth)
void SetPitch(FontPitch ePitch)
void SetFillColor(const Color &)
void SetColor(const Color &)
void SetItalic(FontItalic)
void SetWeight(FontWeight)
void SetCharSet(rtl_TextEncoding)
void SetAlignment(TextAlign)
void SetLanguage(LanguageType)
void SetEmphasisMark(FontEmphasisMark)
constexpr ::Color COL_WHITE(0xFF, 0xFF, 0xFF)
#define ENSURE_OR_THROW(c, m)
B2IRange fround(const B2DRange &rRange)