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 ) { pCapInf = &rNew; }
117 virtual ~SwDoGetCapitalSize() {}
119 virtual void Do()
override;
120 const Size &GetSize()
const {
return aTextSize; }
128 aTextSize.setWidth( 0 );
131 void SwDoGetCapitalSize::Do()
133 aTextSize.AdjustWidth(rInf.GetSize().Width() );
134 if( rInf.GetUpper() )
135 aTextSize.setHeight( rInf.GetSize().Height() );
146 SwDoGetCapitalSize aDo( rInf );
148 Size aTextSize( aDo.GetSize() );
151 if( !aTextSize.Height() )
171 , nTextWidth( nWidth )
174 virtual ~SwDoGetCapitalBreak() {}
176 virtual void Do()
override;
186 void SwDoGetCapitalBreak::Do()
191 if ( rInf.GetSize().Width() < nTextWidth )
192 nTextWidth -= rInf.GetSize().Width();
197 rInf.GetText(), nTextWidth, sal_Int32(rInf.GetIdx()),
198 sal_Int32(rInf.GetLen()), rInf.GetKern()));
207 if ( GetCapInf()->nLen != rInf.GetLen() )
209 GetCapInf()->rString,
211 GetCapInf()->nLen, m_nBreak );
213 m_nBreak = m_nBreak + GetCapInf()->nIdx;
226 SwDrawTextInfo aInfo(pSh, *const_cast<OutputDevice*>(pOut), pScript, rText, nIdx, nLen,
238 SwDoGetCapitalBreak aDo(aInfo, nTextWidth);
240 return aDo.getBreak();
252 SwDoCapitals( rInfo ), pUpperFnt(nullptr), pLowerFnt(nullptr)
254 virtual ~SwDoDrawCapital() {}
256 virtual void Do()
override;
257 void DrawSpace( Point &rPos );
264 pUpperFnt = pUpperFont;
265 pLowerFnt = pLowerFont;
268 void SwDoDrawCapital::Do()
271 const sal_uInt16 nOrgWidth = rInf.GetWidth();
272 rInf.SetWidth( sal_uInt16(rInf.GetSize().Width()) );
273 if ( rInf.GetUpper() )
274 pUpperFnt->DrawText( rInf );
277 bool bOldBullet = rInf.GetBullet();
278 rInf.SetBullet(
false );
279 pLowerFnt->DrawText( rInf );
280 rInf.SetBullet( bOldBullet );
283 OSL_ENSURE( pUpperFnt,
"No upper font, dying soon!");
284 rInf.Shift( pUpperFnt->GetFont().GetOrientation() );
285 rInf.SetWidth( nOrgWidth );
288 void SwDoDrawCapital::DrawSpace( Point &rPos )
293 const bool bSwitchL2R = rInf.GetFrame()->IsRightToLeft() &&
294 ! rInf.IsIgnoreFrameRTL();
297 rInf.GetFrame()->SwitchLTRtoRTL( aPos );
300 const bool bBidiPor = ( bSwitchL2R !=
301 ( ComplexTextLayoutFlags::Default != ( ComplexTextLayoutFlags::BiDiRtl & nMode ) ) );
306 if ( rInf.GetFrame()->IsVertical() )
307 rInf.GetFrame()->SwitchHorizontalToVertical( aPos );
311 rInf.ApplyAutoColor();
312 GetOut().DrawStretchText( aPos, nDiff,
315 rPos.setX( rInf.GetPos().X() + rInf.GetWidth() );
325 SwDoDrawCapital aDo( rInf );
339 SwDoCapitalCursorOfst(
SwDrawTextInfo &rInfo,
const sal_uInt16 nOfs ) :
340 SwDoCapitals( rInfo ), pUpperFnt(nullptr), pLowerFnt(nullptr), nCursor( 0 ), nOfst( nOfs )
342 virtual ~SwDoCapitalCursorOfst() {}
344 virtual void Do()
override;
351 void SwDoCapitalCursorOfst::Init(
SwFntObj *pUpperFont,
SwFntObj *pLowerFont )
353 pUpperFnt = pUpperFont;
354 pLowerFnt = pLowerFont;
357 void SwDoCapitalCursorOfst::Do()
362 if ( static_cast<tools::Long>(nOfst) > rInf.GetSize().Width() )
364 nOfst -= rInf.GetSize().Width();
365 nCursor = nCursor + rInf.GetLen();
370 rInf.GetScriptInfo(),
373 rInf.GetLen(), 0, false );
375 aDrawInf.SetKern( rInf.GetKern() );
376 aDrawInf.SetKanaComp( rInf.GetKanaComp() );
377 aDrawInf.SetFrame( rInf.GetFrame() );
378 aDrawInf.SetFont( rInf.GetFont() );
380 if ( rInf.GetUpper() )
382 aDrawInf.SetSpace( 0 );
383 nCursor = nCursor + pUpperFnt->GetModelPositionForViewPoint( aDrawInf );
387 aDrawInf.SetSpace( rInf.GetSpace() );
388 nCursor = nCursor + pLowerFnt->GetModelPositionForViewPoint( aDrawInf );
398 SwDoCapitalCursorOfst aDo( rInf, rInf.
GetOffset() );
403 return aDo.GetCursor();
408 class SwDoDrawStretchCapital :
public SwDoDrawCapital
411 const sal_uInt16 nCapWidth;
412 const sal_uInt16 nOrgWidth;
414 virtual void Do()
override;
416 SwDoDrawStretchCapital(
SwDrawTextInfo &rInfo,
const sal_uInt16 nCapitalWidth )
417 : SwDoDrawCapital( rInfo ),
418 nStrLen( rInfo.
GetLen() ),
419 nCapWidth( nCapitalWidth ),
420 nOrgWidth( rInfo.GetWidth() )
426 void SwDoDrawStretchCapital::Do()
437 nDiff *= sal_Int32(rInf.GetLen());
438 nDiff /= sal_Int32(nStrLen);
444 rInf.ApplyAutoColor();
446 Point aPos( rInf.GetPos() );
447 const bool bSwitchL2R = rInf.GetFrame()->IsRightToLeft() &&
448 ! rInf.IsIgnoreFrameRTL();
451 rInf.GetFrame()->SwitchLTRtoRTL( aPos );
453 if ( rInf.GetFrame()->IsVertical() )
454 rInf.GetFrame()->SwitchHorizontalToVertical( aPos );
458 GetOut().DrawText(aPos, rInf.GetText(), sal_Int32(rInf.GetIdx()),
459 sal_Int32(rInf.GetLen()));
461 GetOut().DrawStretchText(aPos, nPartWidth, rInf.GetText(),
462 sal_Int32(rInf.GetIdx()), sal_Int32(rInf.GetLen()));
464 const_cast<Point&
>(rInf.GetPos()).AdjustX(nPartWidth );
481 SwDoDrawStretchCapital aDo( rInf, nCapWidth );
487 OSL_ENSURE(
pLastFont,
"SwFont::DoOnCapitals: No LastFont?!" );
500 nMaxPos = nMaxPos + nPos;
504 SwCapitalInfo aCapInf(oldText);
505 bool bCaseMapLengthDiffers(aText.getLength() != oldText.getLength());
506 if ( bCaseMapLengthDiffers )
510 std::unique_ptr<SwFntAccess> pBigFontAccess;
512 std::unique_ptr<SwFntAccess> pSpaceFontAccess;
515 const void* nFontCacheId2 =
nullptr;
516 sal_uInt16 nIndex2 = 0;
523 const bool bWordWise = bTextLines && aFont.IsWordLineMode() &&
532 pSpaceFontAccess.reset(
new SwFntAccess( nFontCacheId2, nIndex2, &aFont,
534 pSpaceFont = pSpaceFontAccess->Get();
543 nFontCacheId2 =
nullptr;
545 pBigFontAccess.reset(
new SwFntAccess( nFontCacheId2, nIndex2, &aFont,
547 pBigFont = pBigFontAccess->Get();
559 nFontCacheId2 =
nullptr;
561 std::unique_ptr<SwFntAccess> pSmallFontAccess(
new SwFntAccess( nFontCacheId2, nIndex2, &aFont,
563 SwFntObj *pSmallFont = pSmallFontAccess->Get();
565 rDo.
Init( pBigFont, pSmallFont );
577 oldText, sal_Int32(nPos),
581 else if( nPos > nMaxPos )
585 while( nOldPos < nMaxPos )
589 if( nOldPos != nPos )
596 if( bCaseMapLengthDiffers )
602 oldText.copy(sal_Int32(nOldPos), sal_Int32(nPos-nOldPos)));
603 aCapInf.nIdx = nOldPos;
604 aCapInf.nLen = nPos - nOldPos;
620 if( nTmpKern && nPos < nMaxPos )
627 oldText, sal_Int32(nPos),
631 OSL_ENSURE( nPos,
"nextCharBlock not implemented?" );
632 #if OSL_DEBUG_LEVEL > 1
637 if( nOldPos != nPos )
650 while (nTmp < nPos &&
CH_BLANK == oldText[sal_Int32(nTmp)])
657 static_cast<SwDoDrawCapital&
>(rDo).DrawSpace( aStartPos );
663 if( bCaseMapLengthDiffers )
669 oldText.copy(sal_Int32(nOldPos), sal_Int32(nTmp-nOldPos)));
670 aCapInf.nIdx = nOldPos;
671 aCapInf.nLen = nTmp - nOldPos;
687 aPartSize.
AdjustWidth(nSpaceAdd * sal_Int32(nTmp - nOldPos));
688 if( nTmpKern && nPos < nMaxPos )
696 while (nTmp < nPos &&
CH_BLANK != oldText[sal_Int32(nTmp)])
704 if( bCaseMapLengthDiffers )
710 oldText.copy(sal_Int32(nOldPos), sal_Int32(nTmp-nOldPos)));
711 aCapInf.nIdx = nOldPos;
712 aCapInf.nLen = nTmp - nOldPos;
731 if (
CH_BLANK == oldText[sal_Int32(nI)])
735 if( nTmpKern && nPos < nMaxPos )
741 }
while( nOldPos != nPos );
744 oldText, sal_Int32(nPos),
748 OSL_ENSURE( nPos,
"endOfCharBlock not implemented?" );
749 #if OSL_DEBUG_LEVEL > 1
756 if( pBigFont != pOldLast )
757 pBigFontAccess.reset();
765 static_cast<SwDoDrawCapital&
>( rDo ).DrawSpace( aStartPos );
768 pSpaceFontAccess.reset();
773 pSmallFontAccess.reset();
void SetSmartTags(sw::WrongListIterator *const pNew)
OutputDevice * GetPrt() const
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)
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
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)
tools::Long Width() const
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
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
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...
const sal_Int32 COMPLETE_STRING
Size GetTextSize(SwDrawTextInfo &rInf)
determine the TextSize (of the printer)
SwDoCapitals(SwDrawTextInfo &rInfo)