23#include <com/sun/star/beans/XPropertySet.hpp>
24#include <com/sun/star/text/XText.hpp>
25#include <rtl/ustrbuf.hxx>
27#include <osl/diagnose.h>
31#include <oox/token/namespaces.hxx>
32#include <oox/token/tokens.hxx>
44const sal_uInt8 BIFF12_STRINGFLAG_FONTS = 0x01;
45const sal_uInt8 BIFF12_STRINGFLAG_PHONETICS = 0x02;
67 mxFont = std::make_shared<Font>( rHelper,
false );
89 Reference< XTextRange > xRange;
93 xRange = rxText->getEnd();
94 OSL_ENSURE( xRange.is(),
"RichStringPortion::convert - cannot get text range interface" );
98 xRange->setString(
maText );
102 mxFont->writeToPropertySet( aPropSet );
115 const Font* pFontToUse =
mxFont ?
mxFont.get() : lclNeedsRichTextFormat( pFont ) ? pFont :
nullptr;
121 sal_Int32 nLastParaLoc = -1;
122 sal_Int32 nSearchIndex =
maText.indexOf(
'\n' );
123 sal_Int32 nParaOccurrence = 0;
124 while ( nSearchIndex != -1 )
126 nLastParaLoc = nSearchIndex;
129 nSearchIndex =
maText.indexOf(
'\n', nSearchIndex + 1);
132 rSelection.
nEndPara += nParaOccurrence;
133 if ( nLastParaLoc != -1 )
149 mxFont->writeToPropertySet(aPropSet);
161 OSL_ENSURE(
mvModels.empty() || (
mvModels.back().mnPos <= rPortion.
mnPos),
"FontPortionModelList::appendPortion - wrong char order" );
174 mvModels.reserve( getLimitedValue< size_t, sal_Int64 >(
nCount, 0,
rStrm.getRemaining() / 4 ) );
188 mnType( XML_fullwidthKatakana ),
189 mnAlignment( XML_left )
195 static const sal_Int32 spnTypeIds[] = { XML_halfwidthKatakana, XML_fullwidthKatakana, XML_hiragana, XML_noConversion };
198 static const sal_Int32 spnAlignments[] = { XML_noControl, XML_left, XML_center, XML_distributed };
217 sal_Int32
nType, nAlignment;
218 nFontId =
rStrm.readuInt16();
220 nAlignment =
rStrm.readInt32();
227 sal_uInt16 nFontId, nFlags;
228 nFontId =
rStrm.readuInt16();
229 nFlags =
rStrm.readuInt16();
231 maModel.
setBiffData( extractValue< sal_Int32 >( nFlags, 0, 2 ), extractValue< sal_Int32 >( nFlags, 2, 2 ) );
269 "PhoneticPortionModelList::appendPortion - wrong char order" );
287 mvModels.reserve( getLimitedValue< size_t, sal_Int64 >(
nCount, 0,
rStrm.getRemaining() / 6 ) );
311 auto aAttrSpace = rAttribs.
getString(oox::NMSP_xml | oox::XML_space);
312 if (aAttrSpace && *aAttrSpace ==
"preserve")
319 xPhonetic->importPhoneticRun( rAttribs );
335 if( !
rStrm.isEof() &&
getFlag( nFlags, BIFF12_STRINGFLAG_FONTS ) )
346 if( !
rStrm.isEof() &&
getFlag( nFlags, BIFF12_STRINGFLAG_PHONETICS ) )
361 rPortion.finalizeImport( rHelper );
376 return orString.indexOf(
'\x0A' ) < 0;
388 rxText->setString(rPtn.
getText());
393 bool bReplaceOld =
true;
396 rTextPortion.convert( rxText, bReplaceOld );
405 OUStringBuffer sString;
407 sString.append(rTextPortion.getText());
416 rTextPortion.convert( rEE, aSelection, pFirstPortionFont );
417 pFirstPortionFont =
nullptr;
444 sal_Int32 nStrLen = aText.size();
452 for( ::std::vector< FontPortionModel >::const_iterator aIt = rPortions.
begin(); aIt->mnPos < nStrLen; ++aIt )
454 sal_Int32 nPortionLen = (aIt + 1)->mnPos - aIt->mnPos;
455 if( (0 < nPortionLen) && (aIt->mnPos + nPortionLen <= nStrLen) )
458 rPortion.
setText( OUString(aText.substr( aIt->mnPos, nPortionLen )) );
470 sal_Int32 nStrLen = aText.size();
472 if( rPortions.
empty() )
479 for( ::std::vector< PhoneticPortionModel >::const_iterator aIt = rPortions.
begin(); aIt->mnPos < nStrLen; ++aIt )
481 sal_Int32 nPortionLen = (aIt + 1)->mnPos - aIt->mnPos;
482 if( (0 < nPortionLen) && (aIt->mnPos + nPortionLen <= nStrLen) )
485 xPhonetic->setText( OUString(aText.substr( aIt->mnPos, nPortionLen )) );
486 xPhonetic->setBaseRange( aIt->mnBasePos, aIt->mnBasePos + aIt->mnBaseLen );
std::unique_ptr< EditTextObject > CreateTextObject()
const SfxItemSet & GetEmptyItemSet() const
void QuickSetAttribs(const SfxItemSet &rSet, const ESelection &rSel)
void SetTextCurrentDefaults(const EditTextObject &rTextObject)
SetText and apply defaults already set.
static OUString decodeXString(const OUString &rValue)
std::optional< sal_Int32 > getInteger(sal_Int32 nAttrToken) const
std::optional< OUString > getString(sal_Int32 nAttrToken) const
std::optional< sal_Int32 > getToken(sal_Int32 nAttrToken) const
static OUString readString(SequenceInputStream &rStrm, bool b32BitLen=true)
Reads a BIFF12 string with leading 16-bit or 32-bit length field.
A vector with all font portions in a rich-string.
void push_back(const FontPortionModel &rModel)
::std::vector< FontPortionModel > mvModels
void insert(::std::vector< FontPortionModel >::iterator it, const FontPortionModel &rModel)
::std::vector< FontPortionModel >::iterator begin()
void importPortions(SequenceInputStream &rStrm)
Reads count and font identifiers from the passed stream.
const FontPortionModel & front() const
const FontPortionModel & back() const
void appendPortion(const FontPortionModel &rPortion)
Appends a rich-string font identifier.
void fillToItemSet(SfxItemSet &rItemSet, bool bEditEngineText, bool bSkipPoolDefs=false) const
bool needsRichTextFormat() const
Returns true, if the font requires rich text formatting in Calc.
A vector with all phonetic portions in a rich-string.
::std::vector< PhoneticPortionModel > mvModels
void importPortions(SequenceInputStream &rStrm)
Reads all phonetic portions from the passed stream.
void push_back(const PhoneticPortionModel &rModel)
::std::vector< PhoneticPortionModel >::const_iterator begin() const
const PhoneticPortionModel & back() const
void appendPortion(const PhoneticPortionModel &rPortion)
Appends a rich-string phonetic portion.
void importStringData(SequenceInputStream &rStrm)
Imports phonetic settings from a rich string.
PhoneticSettings(const WorkbookHelper &rHelper)
void importPhoneticPr(const AttributeList &rAttribs)
Imports phonetic settings from the phoneticPr element.
PhoneticDataModel maModel
void setBaseRange(sal_Int32 nBasePos, sal_Int32 nBaseEnd)
Sets the associated range in base text for this phonetic portion.
void importPhoneticRun(const AttributeList &rAttribs)
Imports attributes of a phonetic run (rPh element).
void setText(const OUString &rText)
Sets text data for this phonetic portion.
sal_Int32 mnBaseEnd
Start position in base text.
sal_Int32 mnBasePos
Portion text.
Contains text data and font attributes for a part of a rich formatted string.
FontRef mxFont
Portion text.
void convert(const css::uno::Reference< css::text::XText > &rxText, bool bReplace)
Converts the portion and replaces or appends to the passed XText.
void writeFontProperties(const css::uno::Reference< css::text::XText > &rxText) const
bool mbConverted
Link to global font list.
FontRef const & createFont(const WorkbookHelper &rHelper)
Creates and returns a new font formatting object.
const OUString & getText() const
Returns the text data of this portion.
void setFontId(sal_Int32 nFontId)
Links this portion to a font object from the global font list.
void finalizeImport(const WorkbookHelper &rHelper)
Final processing after import of all strings.
sal_Int32 mnFontId
Embedded portion font, may be empty.
void setText(const OUString &rText)
Sets text data for this portion.
void finalizeImport(const WorkbookHelper &rHelper)
Final processing after import of all strings.
void createPhoneticPortions(std::u16string_view aText, PhoneticPortionModelList &rPortions, sal_Int32 nBaseLen)
Create phonetic text portions from the passed string and portion data.
void importString(SequenceInputStream &rStrm, bool bRich, const WorkbookHelper &rHelper)
Imports a Unicode rich-string from the passed record stream.
void importPhoneticPr(const AttributeList &rAttribs, const WorkbookHelper &rHelper)
Imports phonetic settings from the rPhoneticPr element.
std::unique_ptr< PhoneticSettings > mxPhonSettings
String portions with font data.
std::vector< RichStringPortion > maTextPortions
PhoneticVector maPhonPortions
Phonetic settings for this string.
bool extractPlainString(OUString &orString, const oox::xls::Font *pFirstPortionFont) const
Tries to extract a plain string from this object.
bool mbPreserveSpace
Phonetic text portions.
sal_Int32 createPortion()
Creates, appends, and returns a new empty string portion.
void convert(const css::uno::Reference< css::text::XText > &rxText)
Converts the string and writes it into the passed XText, replace old contents of the text object,...
void setAttributes(const AttributeList &rAttribs)
RichStringPhoneticRef importPhoneticRun(const AttributeList &rAttribs)
Appends and returns a phonetic text object for a new phonetic run (rPh element).
RichStringPortion & getPortion(sal_Int32 nPortionIdx)
sal_Int32 importText(const AttributeList &rAttribs)
Appends and returns an index of a portion object for a plain string (t element).
RichStringPhoneticRef createPhonetic()
Creates, appends, and returns a new empty phonetic text portion.
sal_Int32 importRun()
Appends and returns an index of a portion object for a new formatting run (r element).
void createTextPortions(std::u16string_view aText, FontPortionModelList &rPortions)
Create base text portions from the passed string and character formatting.
FontRef getFont(sal_Int32 nFontId) const
Returns the specified font object.
Helper class to provide access to global workbook data.
StylesBuffer & getStyles() const
Returns all cell formatting objects read from the styles substream.
#define STATIC_ARRAY_SELECT(array, index, def)
std::shared_ptr< RichStringPhonetic > RichStringPhoneticRef
std::shared_ptr< Font > FontRef
bool getFlag(Type nBitField, Type nMask)
Represents a position in a rich-string containing current font identifier.
sal_Int32 mnFontId
First character in the string.
void read(SequenceInputStream &rStrm)
sal_Int32 mnType
Font identifier for text formatting.
sal_Int32 mnAlignment
Phonetic text type.
PhoneticDataModel()
Phonetic portion alignment.
void setBiffData(sal_Int32 nType, sal_Int32 nAlignment)
Sets the passed data from binary import.
Represents a phonetic text portion in a rich-string with phonetic text.
void read(SequenceInputStream &rStrm)
sal_Int32 mnBasePos
First character in phonetic text.
sal_Int32 mnBaseLen
First character in base text.