/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
/** * The color of hyperlinks is taken from the associated character attribute, * depending on its 'visited' state. There are actually two cases, which * should override the colors from the character attribute: * 1. We never take the 'visited' color during printing/pdf export/preview * 2. The user has chosen to override these colors in the view options
*/ staticbool lcl_ChgHyperLinkColor( const SwTextAttr& rAttr, const SfxPoolItem& rItem, const SwViewShell* pShell,
Color* pColor )
{ if ( !pShell ||
RES_TXTATR_INETFMT != rAttr.Which() ||
RES_CHRATR_COLOR != rItem.Which() ) returnfalse;
// #i15455# // 1. case: // We do not want to show visited links: // (printing, pdf export, page preview)
SwTextINetFormat & rINetAttr(const_cast<SwTextINetFormat&>(
static_txtattr_cast<SwTextINetFormat const&>(rAttr))); if ( pShell->GetOut()->GetOutDevType() == OUTDEV_PRINTER ||
pShell->GetViewOptions()->IsPDFExport() ||
pShell->GetViewOptions()->IsPagePreview() )
{ if (rINetAttr.IsVisited())
{ if ( pColor )
{ // take color from character format 'unvisited link'
rINetAttr.SetVisited(false); const SwCharFormat* pTmpFormat = rINetAttr.GetCharFormat(); if (const SvxColorItem* pItem = pTmpFormat->GetItemIfSet(RES_CHRATR_COLOR))
*pColor = pItem->GetValue();
rINetAttr.SetVisited(true);
} returntrue;
}
returnfalse;
}
// 2. case: // We do not want to apply the color set in the hyperlink // attribute, instead we take the colors from the view options:
if ( pShell->GetWin() &&
(
(rINetAttr.IsVisited() && pShell->GetViewOptions()->IsVisitedLinks()) ||
(!rINetAttr.IsVisited() && pShell->GetViewOptions()->IsLinks())
)
)
{ if ( pColor )
{ if (rINetAttr.IsVisited())
{ // take color from view option 'visited link color'
*pColor = pShell->GetViewOptions()->GetVisitedLinksColor();
} else
{ // take color from view option 'unvisited link color'
*pColor = pShell->GetViewOptions()->GetLinksColor();
}
} returntrue;
}
// do we have to apply additional paragraph attributes?
m_bVertLayout = bVL;
m_bVertLayoutLRBT = bVertLayoutLRBT;
if ( pAS && pAS->Count() )
{
SfxItemIter aIter( *pAS );
sal_uInt16 nWhich; const SfxPoolItem* pItem = aIter.GetCurItem(); do
{
nWhich = pItem->Which(); if (isCHRATR(nWhich))
{
m_pDefaultArray[ StackPos[ nWhich ] ] = pItem;
FontChg( *pItem, rFnt, true );
}
pItem = aIter.NextItem();
} while (pItem);
}
// It is possible, that Init is called more than once, e.g., in a // SwTextFrame::FormatOnceMore situation or (since sw_redlinehide) // from SwAttrIter::Seek(); in the latter case SwTextSizeInfo::m_pFnt // is an alias of m_pFnt so it must not be deleted! if (m_oFnt)
*m_oFnt = rFnt; else
m_oFnt.emplace(rFnt);
}
void SwAttrHandler::Reset( )
{ for (auto& i : m_aAttrStack)
i.clear();
}
void SwAttrHandler::PushAndChg( const SwTextAttr& rAttr, SwFont& rFnt )
{ // these special attributes in fact represent a collection of attributes // they have to be pushed to each stack they belong to if ( RES_TXTATR_INETFMT == rAttr.Which() ||
RES_TXTATR_CHARFMT == rAttr.Which() ||
RES_PARATR_LIST_AUTOFMT == rAttr.Which() ||
RES_TXTATR_AUTOFMT == rAttr.Which() )
{ const SfxItemSet* pSet = rAttr.Which() == RES_PARATR_LIST_AUTOFMT
? rAttr.GetAttr().StaticWhichCast(RES_PARATR_LIST_AUTOFMT).GetStyleHandle().get()
: CharFormat::GetItemSet( rAttr.GetAttr() ); if ( !pSet ) return;
boolconst inParent{rAttr.Which() != RES_TXTATR_AUTOFMT && rAttr.Which() != RES_PARATR_LIST_AUTOFMT}; for ( sal_uInt16 i = RES_CHRATR_BEGIN; i < RES_CHRATR_END; i++)
{ const SfxPoolItem* pItem; bool bRet = SfxItemState::SET == pSet->GetItemState(i, inParent, &pItem);
if ( bRet )
{ // we push rAttr onto the appropriate stack if ( Push( rAttr, *pItem ) )
{ // we let pItem change rFnt
Color aColor; if (lcl_ChgHyperLinkColor(rAttr, *pItem, m_pShell, &aColor))
{
SvxColorItem aItemNext( aColor, RES_CHRATR_COLOR );
FontChg( aItemNext, rFnt, true );
} else
FontChg( *pItem, rFnt, true );
}
}
}
if (rAttr.Which() == RES_TXTATR_INETFMT)
{ if (m_nINETFMT == 0)
rFnt.SetURL(true);
++m_nINETFMT;
}
} // this is the usual case, we have a basic attribute, push it onto the // stack and change the font else
{ if ( Push( rAttr, rAttr.GetAttr() ) ) // we let pItem change rFnt
FontChg( rAttr.GetAttr(), rFnt, true );
}
}
// attributes originating from redlining have highest priority // second priority are hyperlink attributes, which have a color replacement const SwTextAttr* pTopAttr = GetTop(nStack); if ( !pTopAttr
|| rAttr.IsPriorityAttr()
|| ( !pTopAttr->IsPriorityAttr()
&& !lcl_ChgHyperLinkColor(*pTopAttr, rItem, m_pShell, nullptr)))
{
m_aAttrStack[nStack].push_back(&rAttr); returntrue;
}
constauto it = m_aAttrStack[nStack].end() - 1;
m_aAttrStack[nStack].insert(it, &rAttr); returnfalse;
}
// these special attributes in fact represent a collection of attributes // they have to be removed from each stack they belong to if ( RES_TXTATR_INETFMT == rAttr.Which() ||
RES_TXTATR_CHARFMT == rAttr.Which() ||
RES_TXTATR_AUTOFMT == rAttr.Which() )
{ const SfxItemSet* pSet = CharFormat::GetItemSet( rAttr.GetAttr() ); if ( !pSet ) return;
if (rAttr.Which() == RES_TXTATR_INETFMT)
{
assert(m_nINETFMT > 0);
--m_nINETFMT; if (m_nINETFMT == 0)
rFnt.SetURL(false);
}
for ( sal_uInt16 i = RES_CHRATR_BEGIN; i < RES_CHRATR_END; i++)
{ const SfxPoolItem* pItem; bool bRet = SfxItemState::SET == pSet->GetItemState( i, RES_TXTATR_AUTOFMT != rAttr.Which(), &pItem ); if ( bRet )
{ // we remove rAttr from the appropriate stack
RemoveFromStack(i, rAttr); // reset font according to attribute on top of stack // or default value
ActivateTop( rFnt, i );
}
}
} // this is the usual case, we have a basic attribute, remove it from the // stack and reset the font else
{
RemoveFromStack(rAttr.Which(), rAttr); // reset font according to attribute on top of stack // or default value
ActivateTop( rFnt, rAttr.Which() );
}
}
/// Only used during redlining void SwAttrHandler::Pop( const SwTextAttr& rAttr )
{
OSL_ENSURE( rAttr.Which() < RES_TXTATR_WITHEND_END, "I do not have this attribute, nWhich >= RES_TXTATR_WITHEND_END" );
// two line is activated, if // 1. no ruby attribute is set and // 2. attribute is active if ( !bRuby && rItem.StaticWhichCast(RES_CHRATR_TWO_LINES).GetValue() )
{
rFnt.SetVertical( 0_deg10, m_bVertLayout ); break;
}
// a deactivating two line attribute is on top of stack, // check if rotate attribute has to be enabled if ( bRuby ) break;
if ( pRotateAttr )
{ constauto& rRotateItem = *CharFormat::GetItem( *pRotateAttr, RES_CHRATR_ROTATE );
rFnt.SetVertical( rRotateItem.GetValue(), m_bVertLayout );
} else
rFnt.SetVertical(m_pDefaultArray[ nRotateStack ]->StaticWhichCast(RES_CHRATR_ROTATE).GetValue(), m_bVertLayout); break;
} case RES_TXTATR_CJK_RUBY :
rFnt.SetVertical( 0_deg10, m_bVertLayout ); break; case RES_TXTATR_REFMARK : if ( bPush )
rFnt.GetRef()++; else
rFnt.GetRef()--; break; case RES_TXTATR_TOXMARK : if ( bPush )
rFnt.GetTox()++; else
rFnt.GetTox()--; break; case RES_TXTATR_META: case RES_TXTATR_METAFIELD: if ( bPush )
rFnt.GetMeta()++; else
rFnt.GetMeta()--; break; case RES_TXTATR_CONTENTCONTROL: if (bPush)
{
rFnt.GetContentControl()++;
} else
{
rFnt.GetContentControl()--;
} break; case RES_TXTATR_INPUTFIELD : if ( bPush )
rFnt.GetInputField()++; else
rFnt.GetInputField()--; break;
}
}
/// Takes the default font and calculated the ascent and height void SwAttrHandler::GetDefaultAscentAndHeight( SwViewShell const * pShell, OutputDevice const & rOut,
sal_uInt16& nAscent, sal_uInt16& nHeight ) const
{
OSL_ENSURE(m_oFnt, "No font available for GetDefaultAscentAndHeight");
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.