27#include <com/sun/star/i18n/ScriptType.hpp>
36#include <svx/svxids.hrc>
45#include <editeng/editeng.hxx>
48#include <editeng/editids.hrc>
111 rImplFont = rNewFont;
112 rImplFont.SetTransparent(
true);
120OUString removeCRLF(
const OUString& rText)
122 return rText.replace(0xa,
' ').replace(0xd,
' ').trim();
132 , scriptType(scrptType)
225 "*FontPrevWin_Impl::Is100PercentFontWidthValid(): 100PercentFontWidth's not synchronous" );
237 assert(!
maText.isEmpty());
249 auto aScript = aEditEngine.GetScriptType({ 0, 0, 0, 0 });
252 auto aNextScript = aEditEngine.GetScriptType({ 0,
i, 0,
i });
253 if (aNextScript != aScript)
257 aScript = aNextScript;
275 sal_Int32 nStart = 0;
286 nEnd =
maText.getLength();
287 aScript = SvtScriptType::LATIN;
299 const SvxFont& rFont = (aScript == SvtScriptType::ASIAN) ?
301 ((aScript == SvtScriptType::COMPLEX) ?
313 case SvtScriptType::ASIAN:
314 calcFontHeightAnyAscent(rRenderContext,
maCJKFont, nCJKHeight, nCJKAscent);
316 case SvtScriptType::COMPLEX:
317 calcFontHeightAnyAscent(rRenderContext,
maCTLFont, nCTLHeight, nCTLAscent);
320 calcFontHeightAnyAscent(rRenderContext, rFont, nHeight,
mnAscent);
323 if (nEnd <
maText.getLength() && nIdx < nCnt)
335 nCJKHeight -= nCJKAscent;
336 nCTLHeight -= nCTLAscent;
338 if (nHeight < nCJKHeight)
339 nHeight = nCJKHeight;
344 if (nHeight < nCTLHeight)
345 nHeight = nCTLHeight;
352 Size aTxtSize(nTxtWidth, nHeight);
368 sal_Int32 nStart = 0;
379 nEnd =
maText.getLength();
380 aScript = SvtScriptType::LATIN;
384 const SvxFont& rFont = (aScript == SvtScriptType::ASIAN)
386 : ((aScript == SvtScriptType::COMPLEX)
391 rFont.
DrawPrev(&rRenderContext, _pPrinter, rPt,
maText, nStart, nEnd - nStart);
394 if (nEnd <
maText.getLength() && nIdx < nCnt)
447 rFont.SetPitch(rFontItem.
GetPitch());
488 CustomWidgetController::SetDrawingArea(pDrawingArea);
498 if (!
pImpl->mpPrinter)
501 pImpl->mbDelPrinter =
true;
503 initFont(
pImpl->maFont);
504 initFont(
pImpl->maCJKFont);
505 initFont(
pImpl->maCTLFont);
520 return pImpl->maCTLFont;
525 return pImpl->maCJKFont;
530 pImpl->Invalidate100PercentFontWidth();
531 return pImpl->maFont;
536 return pImpl->maFont;
541 pImpl->maText = rString;
542 pImpl->mbTextInited =
true;
547 pImpl->mbUseFontNameAsText =
true;
552 setFont(rNormalOutFont,
pImpl->maFont);
553 setFont(rCJKOutFont,
pImpl->maCJKFont);
554 setFont(rCTLFont,
pImpl->maCTLFont);
556 pImpl->Invalidate100PercentFontWidth();
562 pImpl->mxColor = rColor;
568 pImpl->mxColor.reset();
574 pImpl->mxTextLineColor = rColor;
580 pImpl->mxOverlineColor = rColor;
590 rRenderContext.
Erase();
609 if (!
pImpl->mbSelection && !
pImpl->mbTextInited)
611 using namespace css::i18n::ScriptType;
615 if (pSh && !
pImpl->mbGetSelection && !
pImpl->mbUseFontNameAsText)
618 pImpl->mbGetSelection =
true;
619 pImpl->mbSelection = !(
pImpl->maText.isEmpty());
622 if (!
pImpl->mbSelection ||
pImpl->mbUseFontNameAsText)
627 if ((
pImpl->m_bCJKEnabled) || (
pImpl->m_bCTLEnabled))
630 pImpl->maText = rFont.GetFamilyName();
632 if (
pImpl->m_bCJKEnabled)
634 if (!
pImpl->maText.isEmpty())
635 pImpl->maText +=
" ";
639 if (
pImpl->m_bCTLEnabled)
641 if (!
pImpl->maText.isEmpty())
642 pImpl->maText +=
" ";
647 if (
pImpl->maText.isEmpty())
658 pImpl->maText =
pImpl->maText.copy(0, nSpaceIdx);
665 pImpl->ScaleFontWidth(rRenderContext);
667 pImpl->CheckScript();
668 Size aTxtSize =
pImpl->CalcTextSize(rRenderContext, pPrinter, rFont);
678 if (
pImpl->mxBackColor)
701 if (
pImpl->mxTextLineColor)
706 if (
pImpl->mxOverlineColor)
717 Size aOldSize =
pImpl->maCJKFont.GetFontSize();
718 setFontSize(aSmallFont);
719 setFontSize(
pImpl->maCJKFont);
724 if (
pImpl->mcStartBracket)
726 OUString sBracket(
pImpl->mcStartBracket);
729 if (
pImpl->mcEndBracket)
731 OUString sBracket(
pImpl->mcEndBracket);
734 nTextWidth =
pImpl->CalcTextSize(rRenderContext, pPrinter, aSmallFont).Width();
736 nResultWidth += nEndBracketWidth;
737 nResultWidth += nTextWidth;
744 tools::Long nOffset = (nStdAscent - nSmallAscent) / 2;
746 if (
pImpl->mcStartBracket)
748 OUString sBracket(
pImpl->mcStartBracket);
749 rFont.
DrawPrev(&rRenderContext, pPrinter,
Point(_nX, nY - nOffset - 4), sBracket);
750 _nX += nStartBracketWidth;
753 Point aTmpPoint1(_nX, nY - nSmallAscent - 2);
754 Point aTmpPoint2(_nX, nY);
755 pImpl->DrawPrev(rRenderContext, pPrinter, aTmpPoint1, aSmallFont);
756 pImpl->DrawPrev(rRenderContext, pPrinter, aTmpPoint2, aSmallFont);
759 if (
pImpl->mcEndBracket)
761 Point aTmpPoint( _nX + 1, nY - nOffset - 4);
762 OUString sBracket(
pImpl->mcEndBracket);
763 rFont.
DrawPrev(&rRenderContext, pPrinter, aTmpPoint, sBracket);
765 pImpl->maCJKFont.SetFontSize(aOldSize);
777 Point aTmpPoint(nX, nY);
778 pImpl->DrawPrev(rRenderContext, pPrinter, aTmpPoint, rFont);
781 rRenderContext.
Pop();
786 return pImpl->mbTwoLines;
791 pImpl->mbTwoLines = bSet;
796 pImpl->mcStartBracket = cStart;
797 pImpl->mcEndBracket = cEnd;
802 if (
pImpl->SetFontWidthScale(
n))
809 if (
pImpl->mxBackColor ) aColor = *
pImpl->mxBackColor;
810 const bool bIsDark(aColor.
IsDark());
812 aColor =
pImpl->maFont.GetColor();
815 aColor =
pImpl->maCJKFont.GetColor();
818 aColor =
pImpl->maCTLFont.GetColor();
836 rFont.SetFontSize(
Size(0, nH));
847 rFont.SetLanguage(nLang);
858 if(
GetWhich(
rSet, SID_CHAR_DLG_PREVIEW_STRING, nWhich ) )
861 const OUString& aString = rItem.
GetValue();
862 if( !aString.isEmpty() )
873 eUnderline = rItem.GetValue();
878 rFont.SetUnderline( eUnderline );
879 rCJKFont.SetUnderline( eUnderline );
880 rCTLFont.SetUnderline( eUnderline );
887 eOverline = rItem.GetValue();
892 rFont.SetOverline( eOverline );
893 rCJKFont.SetOverline( eOverline );
894 rCTLFont.SetOverline( eOverline );
901 eStrikeout = rItem.GetValue();
906 rFont.SetStrikeout( eStrikeout );
907 rCJKFont.SetStrikeout( eStrikeout );
908 rCTLFont.SetStrikeout( eStrikeout );
911 if(
GetWhich(
rSet, SID_ATTR_CHAR_WORDLINEMODE, nWhich ) )
914 rFont.SetWordLineMode( rItem.GetValue() );
915 rCJKFont.SetWordLineMode( rItem.GetValue() );
916 rCTLFont.SetWordLineMode( rItem.GetValue() );
920 if(
GetWhich(
rSet, SID_ATTR_CHAR_EMPHASISMARK, nWhich ) )
924 rFont.SetEmphasisMark( eMark );
925 rCJKFont.SetEmphasisMark( eMark );
926 rCTLFont.SetEmphasisMark( eMark );
934 rFont.SetRelief( eFontRelief );
935 rCJKFont.SetRelief( eFontRelief );
936 rCTLFont.SetRelief( eFontRelief );
947 rCTLFont.
SetCaseMap( eCaseMap == SvxCaseMap::SmallCaps ? SvxCaseMap::NotMapped : eCaseMap );
954 bool bOutline = rItem.GetValue();
955 rFont.SetOutline( bOutline );
956 rCJKFont.SetOutline( bOutline );
957 rCTLFont.SetOutline( bOutline );
964 bool bShadow = rItem.GetValue();
965 rFont.SetShadow( bShadow );
966 rCJKFont.SetShadow( bShadow );
967 rCTLFont.SetShadow( bShadow );
972 if(
GetWhich(
rSet, bPreviewBackgroundToCharacter ? SID_ATTR_BRUSH : SID_ATTR_BRUSH_CHAR, nWhich ) )
977 rFont.SetFillColor( rColor );
978 rCJKFont.SetFillColor( rColor );
979 rCTLFont.SetFillColor( rColor );
984 rFont.SetTransparent( bTransparent );
985 rCJKFont.SetTransparent( bTransparent );
986 rCTLFont.SetTransparent( bTransparent );
988 if( !bPreviewBackgroundToCharacter )
990 bool bBackColorFound =
false;
1000 bBackColorFound =
true;
1004 if (!bBackColorFound)
1033 rFont.SetColor( aCol );
1035 rCJKFont.SetColor( aCol );
1036 rCTLFont.SetColor( aCol );
1046 rFont.SetFixKerning( nKern );
1047 rCJKFont.SetFixKerning( nKern );
1048 rCTLFont.SetFixKerning( nKern );
1055 if(
GetWhich(
rSet, SID_ATTR_CHAR_ESCAPEMENT, nWhich ) )
1076 if(
GetWhich(
rSet, SID_ATTR_CHAR_SCALEWIDTH, nWhich ) )
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
const OUString & GetValue() const
bool IsTransparent() const
tools::Long GetLineHeight() const
tools::Long GetAscent() const
bool SetFontWidthScale(sal_uInt16 nScaleInPercent)
Size CalcTextSize(vcl::RenderContext &rRenderContext, OutputDevice const *pPrinter, const SvxFont &rFont)
sal_Unicode mcStartBracket
tools::Long mn100PercentFontWidthCTL
bool Is100PercentFontWidthValid() const
std::optional< Color > mxBackColor
void Invalidate100PercentFontWidth()
std::optional< Color > mxOverlineColor
sal_uInt16 mnFontWidthScale
tools::Long mn100PercentFontWidth
void DrawPrev(vcl::RenderContext &rRenderContext, Printer *pPrinter, Point &rPt, const SvxFont &rFont)
std::optional< Color > mxTextLineColor
std::optional< Color > mxColor
std::vector< ScriptInfo > maScriptChanges
VclPtr< Printer > mpPrinter
void ScaleFontWidth(vcl::RenderContext const &rRenderContext)
tools::Long mn100PercentFontWidthCJK
Size GetOutputSize() const
const vcl::Font & GetFont() const
void SetFont(const vcl::Font &rNewFont)
void DrawRect(const tools::Rectangle &rRect)
void DrawLine(const Point &rStartPt, const Point &rEndPt)
SAL_WARN_UNUSED_RESULT Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
void SetTextColor(const Color &rColor)
FontMetric GetFontMetric() const
const Color & GetLineColor() const
void Push(vcl::PushFlags nFlags=vcl::PushFlags::ALL)
const Color & GetFillColor() const
tools::Long AdjustX(tools::Long nHorzMove)
sal_uInt16 GetWhich(sal_uInt16 nSlot, bool bDeep=true) const
virtual MapUnit GetMetric(sal_uInt16 nWhich) const
SfxItemPool * GetPool() const
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
virtual SfxPrinter * GetPrinter(bool bCreate=false)
virtual OUString GetSelectionText(bool bCompleteWords=false, bool bOnlyASample=false)
static SAL_WARN_UNUSED_RESULT SfxViewShell * Current()
constexpr tools::Long Height() const
void setWidth(tools::Long nWidth)
void setHeight(tools::Long nHeight)
constexpr tools::Long Width() const
const Color & GetWindowColor() const
static bool IsCTLFontEnabled()
const Color & GetColor() const
SvxGraphicPosition GetGraphicPos() const
const Color & GetValue() const
FontEmphasisMark GetEmphasisMark() const
sal_uInt8 & GetProportionalHeight()
sal_uInt32 GetHeight() const
FontFamily GetFamily() const
FontPitch GetPitch() const
const OUString & GetStyleName() const
rtl_TextEncoding GetCharSet() const
const OUString & GetFamilyName() const
void SetBrackets(sal_Unicode cStart, sal_Unicode cEnd)
static SVX_DLLPRIVATE void SetFontSize(const SfxItemSet &rSet, sal_uInt16 nSlot, SvxFont &rFont)
void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &) override
void SetTwoLines(bool bSet)
static SVX_DLLPRIVATE void ApplySettings(vcl::RenderContext &rRenderContext)
void SetPreviewText(const OUString &rString)
void SetColor(const Color &rColor)
void SetFontNameAsPreviewText()
void AutoCorrectFontColor()
void SetFont(const SvxFont &rNormalFont, const SvxFont &rCJKFont, const SvxFont &rCTLFont)
void SetTextLineColor(const Color &rColor)
void SetOverlineColor(const Color &rColor)
std::unique_ptr< FontPrevWin_Impl > pImpl
static SVX_DLLPRIVATE void SetFontLang(const SfxItemSet &rSet, sal_uInt16 nSlot, SvxFont &rFont)
void SetFontWidthScale(sal_uInt16 nScaleInPercent)
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea) override
void SetFromItemSet(const SfxItemSet &rSet, bool bPreviewBackgroundToCharacter)
virtual ~SvxFontPrevWindow() override
Size GetTextSize(const OutputDevice &rOut, const OUString &rTxt, const sal_Int32 nIdx=0, const sal_Int32 nLen=SAL_MAX_INT32) const
void SetPropr(const sal_uInt8 nNewPropr)
void SetEscapement(const short nNewEsc)
void SetProprRel(const sal_uInt8 nNewPropr)
void DrawPrev(OutputDevice *pOut, Printer *pPrinter, const Point &rPos, const OUString &rTxt, const sal_Int32 nIdx=0, const sal_Int32 nLen=SAL_MAX_INT32) const
void SetCaseMap(const SvxCaseMap eNew)
static VclPtr< reference_type > Create(Arg &&... arg)
void SetFontSize(const Size &)
void SetAverageFontWidth(tools::Long nWidth)
void SetTransparent(bool bTransparent)
const Size & GetFontSize() const
void SetAlignment(TextAlign)
tools::Long GetAverageFontWidth() const
virtual OutputDevice & get_ref_device()=0
constexpr ::Color COL_WHITE(0xFF, 0xFF, 0xFF)
constexpr ::Color COL_AUTO(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
constexpr ::Color COL_BLACK(0x00, 0x00, 0x00)
constexpr ::Color COL_TRANSPARENT(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
#define DBG_ASSERT(sCon, aError)
Size SFX2_DLLPUBLIC getPreviewStripSize(const OutputDevice &rReference)
#define DFLT_ESC_AUTO_SUB
#define DFLT_ESC_AUTO_SUPER
static bool GetWhich(const SfxItemSet &rSet, sal_uInt16 nSlot, sal_uInt16 &rWhich)
static void SetPrevFont(const SfxItemSet &rSet, sal_uInt16 nSlot, SvxFont &rFont)
static void SetPrevFontStyle(const SfxItemSet &rSet, sal_uInt16 nPosture, sal_uInt16 nWeight, SvxFont &rFont)
static void SetPrevFontEscapement(SvxFont &rFont, sal_uInt8 nProp, sal_uInt8 nEscProp, short nEsc)
LanguageType GetLanguage(SfxItemSet const &aSet, sal_uInt16 nLangWhichId)
SVT_DLLPUBLIC OUString makeRepresentativeTextForFont(sal_Int16 nScriptType, const vcl::Font &rFont)