23 #include <com/sun/star/i18n/CharType.hpp>
24 #include <com/sun/star/i18n/WordType.hpp>
25 #include <com/sun/star/i18n/XBreakIterator.hpp>
45 explicit SwCapitalInfo(
const OUString& rOrigText ) :
46 rString( rOrigText ), nIdx( 0 ), nLen( 0 ) {};
47 const OUString& rString;
61 const OUString& rOrigString,
68 OSL_ENSURE( sal_Int32(nEnd) <= rOrigString.getLength(),
"sw_CalcCaseMap: Wrong parameters" );
71 const bool bTitle = SvxCaseMap::Capitalize == rFnt.
GetCaseMap();
74 OUString aTmp(rOrigString.copy(sal_Int32(
i), 1));
78 rOrigString, sal_Int32(
i),
80 WordType::ANYWORD_IGNOREWHITESPACES ) )
83 j += aTmp.getLength();
102 virtual void Do() = 0;
106 void SetCapInf( SwCapitalInfo& rNew ) { m_pCapInf = &rNew; }
118 virtual ~SwDoGetCapitalSize() {}
120 virtual void Do()
override;
121 const Size& GetSize()
const {
return m_aTextSize; }
129 m_aTextSize.setWidth(0);
132 void SwDoGetCapitalSize::Do()
134 m_aTextSize.AdjustWidth(m_rInf.GetSize().Width());
135 if( m_rInf.GetUpper() )
136 m_aTextSize.setHeight(m_rInf.GetSize().Height());
147 SwDoGetCapitalSize aDo( rInf );
149 Size aTextSize( aDo.GetSize() );
152 if( !aTextSize.Height() )
172 , m_nTextWidth(nWidth)
175 virtual ~SwDoGetCapitalBreak() {}
177 virtual void Do()
override;
187 void SwDoGetCapitalBreak::Do()
192 if (m_rInf.GetSize().Width() < m_nTextWidth)
193 m_nTextWidth -= m_rInf.GetSize().Width();
197 m_nBreak =
TextFrameIndex(GetOut().GetTextBreak(m_rInf.GetText(), m_nTextWidth,
198 sal_Int32(m_rInf.GetIdx()),
199 sal_Int32(m_rInf.GetLen()), m_rInf.GetKern()));
208 if ( GetCapInf()->nLen != m_rInf.GetLen() )
210 GetCapInf()->rString,
212 GetCapInf()->nLen, m_nBreak );
214 m_nBreak = m_nBreak + GetCapInf()->nIdx;
227 SwDrawTextInfo aInfo(pSh, *const_cast<OutputDevice*>(pOut), pScript, rText, nIdx, nLen,
239 SwDoGetCapitalBreak aDo(aInfo, nTextWidth);
241 return aDo.getBreak();
255 , m_pUpperFnt(nullptr)
256 , m_pLowerFnt(nullptr)
258 virtual ~SwDoDrawCapital() {}
260 virtual void Do()
override;
261 void DrawSpace( Point &rPos );
268 m_pUpperFnt = pUpperFont;
269 m_pLowerFnt = pLowerFont;
272 void SwDoDrawCapital::Do()
275 const sal_uInt16 nOrgWidth = m_rInf.GetWidth();
276 m_rInf.SetWidth( sal_uInt16(m_rInf.GetSize().Width()) );
277 if ( m_rInf.GetUpper() )
278 m_pUpperFnt->DrawText(m_rInf);
281 bool bOldBullet = m_rInf.GetBullet();
282 m_rInf.SetBullet(
false );
283 m_pLowerFnt->DrawText(m_rInf);
284 m_rInf.SetBullet( bOldBullet );
287 OSL_ENSURE(m_pUpperFnt,
"No upper font, dying soon!");
288 m_rInf.Shift(m_pUpperFnt->GetFont().GetOrientation());
289 m_rInf.SetWidth( nOrgWidth );
292 void SwDoDrawCapital::DrawSpace( Point &rPos )
294 tools::Long nDiff = m_rInf.GetPos().X() - rPos.X();
297 const bool bSwitchL2R = m_rInf.GetFrame()->IsRightToLeft() &&
298 ! m_rInf.IsIgnoreFrameRTL();
301 m_rInf.GetFrame()->SwitchLTRtoRTL( aPos );
304 const bool bBidiPor = ( bSwitchL2R !=
310 if ( m_rInf.GetFrame()->IsVertical() )
311 m_rInf.GetFrame()->SwitchHorizontalToVertical( aPos );
315 m_rInf.ApplyAutoColor();
316 GetOut().DrawStretchText( aPos, nDiff,
319 rPos.setX( m_rInf.GetPos().X() + m_rInf.GetWidth() );
329 SwDoDrawCapital aDo( rInf );
344 SwDoCapitalCursorOfst(
SwDrawTextInfo& rInfo,
const sal_uInt16 nOfs)
346 , m_pUpperFnt(nullptr)
347 , m_pLowerFnt(nullptr)
351 virtual ~SwDoCapitalCursorOfst() {}
353 virtual void Do()
override;
360 void SwDoCapitalCursorOfst::Init(
SwFntObj *pUpperFont,
SwFntObj *pLowerFont )
362 m_pUpperFnt = pUpperFont;
363 m_pLowerFnt = pLowerFont;
366 void SwDoCapitalCursorOfst::Do()
371 if (static_cast<tools::Long>(m_nOfst) > m_rInf.GetSize().Width())
373 m_nOfst -= m_rInf.GetSize().Width();
374 m_nCursor = m_nCursor + m_rInf.GetLen();
379 m_rInf.GetScriptInfo(),
382 m_rInf.GetLen(), 0,
false );
384 aDrawInf.SetKern( m_rInf.GetKern() );
385 aDrawInf.SetKanaComp( m_rInf.GetKanaComp() );
386 aDrawInf.SetFrame( m_rInf.GetFrame() );
387 aDrawInf.SetFont( m_rInf.GetFont() );
389 if ( m_rInf.GetUpper() )
391 aDrawInf.SetSpace( 0 );
392 m_nCursor = m_nCursor + m_pUpperFnt->GetModelPositionForViewPoint(aDrawInf);
396 aDrawInf.SetSpace( m_rInf.GetSpace() );
397 m_nCursor = m_nCursor + m_pLowerFnt->GetModelPositionForViewPoint(aDrawInf);
407 SwDoCapitalCursorOfst aDo( rInf, rInf.
GetOffset() );
412 return aDo.GetCursor();
417 class SwDoDrawStretchCapital :
public SwDoDrawCapital
420 const sal_uInt16 m_nCapWidth;
421 const sal_uInt16 m_nOrgWidth;
424 virtual void Do()
override;
426 SwDoDrawStretchCapital(
SwDrawTextInfo& rInfo,
const sal_uInt16 nCapitalWidth)
427 : SwDoDrawCapital(rInfo)
428 , m_nStrLen(rInfo.
GetLen())
429 , m_nCapWidth(nCapitalWidth)
430 , m_nOrgWidth(rInfo.GetWidth())
436 void SwDoDrawStretchCapital::Do()
441 if( m_rInf.GetLen() )
447 nDiff *= sal_Int32(m_rInf.GetLen());
448 nDiff /= sal_Int32(m_nStrLen);
454 m_rInf.ApplyAutoColor();
456 Point aPos( m_rInf.GetPos() );
457 const bool bSwitchL2R = m_rInf.GetFrame()->IsRightToLeft() &&
458 ! m_rInf.IsIgnoreFrameRTL();
461 m_rInf.GetFrame()->SwitchLTRtoRTL( aPos );
463 if ( m_rInf.GetFrame()->IsVertical() )
464 m_rInf.GetFrame()->SwitchHorizontalToVertical( aPos );
468 GetOut().DrawText(aPos, m_rInf.GetText(), sal_Int32(m_rInf.GetIdx()),
469 sal_Int32(m_rInf.GetLen()));
471 GetOut().DrawStretchText(aPos, nPartWidth, m_rInf.GetText(),
472 sal_Int32(m_rInf.GetIdx()), sal_Int32(m_rInf.GetLen()));
474 const_cast<Point&
>(m_rInf.GetPos()).AdjustX(nPartWidth );
485 const sal_uInt16 nCapWidth = o3tl::narrowing<sal_uInt16>(
GetCapitalSize( rInf ).
Width() );
491 SwDoDrawStretchCapital aDo( rInf, nCapWidth );
497 OSL_ENSURE(
pLastFont,
"SwFont::DoOnCapitals: No LastFont?!" );
510 nMaxPos = nMaxPos + nPos;
514 SwCapitalInfo aCapInf(oldText);
515 bool bCaseMapLengthDiffers(aText.getLength() != oldText.getLength());
516 if ( bCaseMapLengthDiffers )
520 std::unique_ptr<SwFntAccess> pBigFontAccess;
522 std::unique_ptr<SwFntAccess> pSpaceFontAccess;
525 const void* nFontCacheId2 =
nullptr;
526 sal_uInt16 nIndex2 = 0;
533 const bool bWordWise = bTextLines && aFont.IsWordLineMode() &&
542 pSpaceFontAccess.reset(
new SwFntAccess( nFontCacheId2, nIndex2, &aFont,
544 pSpaceFont = pSpaceFontAccess->Get();
553 nFontCacheId2 =
nullptr;
555 pBigFontAccess.reset(
new SwFntAccess( nFontCacheId2, nIndex2, &aFont,
557 pBigFont = pBigFontAccess->Get();
569 nFontCacheId2 =
nullptr;
571 std::unique_ptr<SwFntAccess> pSmallFontAccess(
new SwFntAccess( nFontCacheId2, nIndex2, &aFont,
573 SwFntObj *pSmallFont = pSmallFontAccess->Get();
575 rDo.
Init( pBigFont, pSmallFont );
587 oldText, sal_Int32(nPos),
591 else if( nPos > nMaxPos )
595 while( nOldPos < nMaxPos )
599 if( nOldPos != nPos )
606 if( bCaseMapLengthDiffers )
612 oldText.copy(sal_Int32(nOldPos), sal_Int32(nPos-nOldPos)));
613 aCapInf.nIdx = nOldPos;
614 aCapInf.nLen = nPos - nOldPos;
627 if( nTmpKern && nPos < nMaxPos )
634 oldText, sal_Int32(nPos),
638 OSL_ENSURE( nPos,
"nextCharBlock not implemented?" );
639 #if OSL_DEBUG_LEVEL > 1
644 if( nOldPos != nPos )
657 while (nTmp < nPos &&
CH_BLANK == oldText[sal_Int32(nTmp)])
664 static_cast<SwDoDrawCapital&
>(rDo).DrawSpace( aStartPos );
670 if( bCaseMapLengthDiffers )
676 oldText.copy(sal_Int32(nOldPos), sal_Int32(nTmp-nOldPos)));
677 aCapInf.nIdx = nOldPos;
678 aCapInf.nLen = nTmp - nOldPos;
694 aPartSize.
AdjustWidth(nSpaceAdd * sal_Int32(nTmp - nOldPos));
695 if( nTmpKern && nPos < nMaxPos )
703 while (nTmp < nPos &&
CH_BLANK != oldText[sal_Int32(nTmp)])
711 if( bCaseMapLengthDiffers )
717 oldText.copy(sal_Int32(nOldPos), sal_Int32(nTmp-nOldPos)));
718 aCapInf.nIdx = nOldPos;
719 aCapInf.nLen = nTmp - nOldPos;
735 if (
CH_BLANK == oldText[sal_Int32(nI)])
739 if( nTmpKern && nPos < nMaxPos )
745 }
while( nOldPos != nPos );
748 oldText, sal_Int32(nPos),
752 OSL_ENSURE( nPos,
"endOfCharBlock not implemented?" );
753 #if OSL_DEBUG_LEVEL > 1
760 if( pBigFont != pOldLast )
761 pBigFontAccess.reset();
769 static_cast<SwDoDrawCapital&
>( rDo ).DrawSpace( aStartPos );
772 pSpaceFontAccess.reset();
777 pSmallFontAccess.reset();
void SetSmartTags(sw::WrongListIterator *const pNew)
OutputDevice * GetPrt() const
SwNodeOffset min(const SwNodeOffset &a, const SwNodeOffset &b)
SwViewShell const * GetShell() const
sal_uInt8 GetPropr() const
vcl::RenderContext * GetpOut() const
bool m_bSmallCapsPercentage66
TextFrameIndex GetCapitalCursorOfst(SwDrawTextInfo &rInf)
void SetCapInf(SwCapitalInfo &rNew)
bool GetDrawSpace() const
#define SMALL_CAPS_PERCENTAGE
void SetSize(const Size &rNew)
LanguageType GetLanguage(SfxItemSet const &aSet, sal_uInt16 nLangWhichId)
void SetIdx(TextFrameIndex const nNew)
void SetUnderline(const FontLineStyle eUnderline)
tools::Long GetLen(const Point &rPnt)
const SvxFont & GetActualFont() const
void SetKanaComp(short nNew)
void SetPos(const Point &rNew)
void DrawCapital(SwDrawTextInfo &rInf)
constexpr tools::Long Width() const
TextFrameIndex sw_CalcCaseMap(const SwFont &rFnt, const OUString &rOrigString, TextFrameIndex const nOfst, TextFrameIndex const nLen, TextFrameIndex const nIdx)
void SetOut(OutputDevice &rNew)
void SetKern(tools::Long nNew)
void SetKanaDiff(tools::Long nNew)
virtual void Init(SwFntObj *pUpperFont, SwFntObj *pLowerFont)=0
SvxCaseMap GetCaseMap() const
SwCapitalInfo * m_pCapInf
void SetWrong(sw::WrongListIterator *const pNew)
void SetLen(TextFrameIndex const nNew)
const OUString & GetText() const
void SetOverline(const FontLineStyle eOverline)
tools::Long GetKanaDiff() const
void SetWordLineMode(const bool bWordLineMode)
void SetOffset(sal_Int32 nNew)
void DrawStretchCapital(SwDrawTextInfo &rInf)
Size GetCapitalSize(SwDrawTextInfo &rInf)
const sal_Unicode CH_BLANK
TextFrameIndex GetCapitalBreak(SwViewShell const *pSh, const OutputDevice *pOut, const SwScriptInfo *pScript, const OUString &rText, tools::Long nTextWidth, TextFrameIndex nIdx, TextFrameIndex nLen)
void SetProportion(const sal_uInt8 nNewPropr)
#define LANGUAGE_DONTKNOW
void SetSpace(tools::Long nNew)
void SetGrammarCheck(sw::WrongListIterator *const pNew)
void DoOnCapitals(SwDoCapitals &rDo)
void SetDrawSpace(bool bNew)
css::uno::Reference< css::i18n::XBreakIterator > const & GetBreakIter() const
const css::lang::Locale & GetLocale(const LanguageType aLang)
SwCapitalInfo * GetCapInf() const
void SetDevFont(const SwViewShell *pSh, OutputDevice &rOut)
LanguageType GetLanguage() const
void DoOnCapitals(SwDoCapitals &rDo)
tools::Long GetSpace() const
const Point & GetPos() const
void SetTextIdxLen(const OUString &rNewStr, TextFrameIndex const nNewIdx, TextFrameIndex const nNewLen)
tools::Long GetTextHeight() const
TextFrameIndex GetLen() const
tools::Long AdjustWidth(tools::Long n)
OUString CalcCaseMap(const OUString &rTxt) const
vcl::RenderContext & GetOut() const
tools::Long GetKern() const
constexpr sal_Int32 COMPLETE_STRING
void setHeight(tools::Long nHeight)
#define SPACING_PRECISION_FACTOR
void SetText(const OUString &rNew)
TextFrameIndex GetIdx() const
void SetFont(SwFont *pNew)
SwDrawTextInfo & GetInf()
sal_Int32 GetOffset() const
void SetStrikeout(const FontStrikeout eStrikeout)
o3tl::strong_int< sal_Int32, struct Tag_TextFrameIndex > TextFrameIndex
Denotes a character index in a text frame at a layout level, after extent mapping from a text node at...
Size GetTextSize(SwDrawTextInfo &rInf)
determine the TextSize (of the printer)
bool m_bDetectedRangeSegmentation false
SwDoCapitals(SwDrawTextInfo &rInfo)
void SetIdxLen(TextFrameIndex const nNewIdx, TextFrameIndex const nNewLen)