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/tokens.hxx>
43const sal_uInt8 BIFF12_STRINGFLAG_FONTS = 0x01;
44const sal_uInt8 BIFF12_STRINGFLAG_PHONETICS = 0x02;
53 if (nCode >=
'0' && nCode <=
'9')
56 if (nCode >=
'A' && nCode <=
'F')
57 return nCode -
'A' + 10;
59 if (nCode >=
'a' && nCode <=
'f')
60 return nCode -
'a' + 10;
69 if (nCode == 0x000D || nCode == 0x000A || nCode == 0x0009 || nCode == 0x005F)
73 if ((nCode >= 0x0020 && nCode <= 0xD7FF) || (nCode >= 0xE000 && nCode <= 0xFFFD))
79OUString lcl_unEscapeUnicodeChars(
const OUString& rSrc)
83 sal_Int32 nLen = rSrc.getLength();
89 const OUString aPrefix =
"_x";
90 sal_Int32 nPrefixStart = rSrc.indexOf(aPrefix, nStart);
92 if (nPrefixStart == -1)
95 OUStringBuffer
aBuf(rSrc);
96 sal_Int32 nOffset = 0;
102 bool bFoundThis =
false;
103 for (sal_Int32 nIdx = 0; nIdx < 5; ++nIdx)
105 sal_Int32 nThisIdx = nPrefixStart + nIdx + 2;
106 if (nThisIdx >= nLen)
110 sal_Int32 nLetter = lcl_getHexLetterValue(nThisCode);
112 if (!nIdx && nLetter < 0)
117 nCode = (nCode << 4) + static_cast<sal_Unicode>(nLetter);
119 else if (nThisCode ==
'_')
134 if (lcl_validEscape(nCode))
137 sal_Int32 nEscStrLen = nEnd - nPrefixStart;
138 aBuf.remove(nPrefixStart - nOffset, nEscStrLen);
139 aBuf.insert(nPrefixStart - nOffset, nCode);
141 nOffset += nEscStrLen - 1;
147 nEnd = nPrefixStart + 2;
151 nPrefixStart = rSrc.indexOf(aPrefix, nStart);
153 while (nPrefixStart != -1);
156 return aBuf.makeStringAndClear();
171 maText = lcl_unEscapeUnicodeChars(rText);
176 mxFont = std::make_shared<Font>( rHelper,
false );
198 Reference< XTextRange > xRange;
202 xRange = rxText->getEnd();
203 OSL_ENSURE( xRange.is(),
"RichStringPortion::convert - cannot get text range interface" );
207 xRange->setString(
maText );
211 mxFont->writeToPropertySet( aPropSet );
224 const Font* pFontToUse =
mxFont ?
mxFont.get() : lclNeedsRichTextFormat( pFont ) ? pFont :
nullptr;
230 sal_Int32 nLastParaLoc = -1;
231 sal_Int32 nSearchIndex =
maText.indexOf(
'\n' );
232 sal_Int32 nParaOccurrence = 0;
233 while ( nSearchIndex != -1 )
235 nLastParaLoc = nSearchIndex;
238 nSearchIndex =
maText.indexOf(
'\n', nSearchIndex + 1);
241 rSelection.
nEndPara += nParaOccurrence;
242 if ( nLastParaLoc != -1 )
258 mxFont->writeToPropertySet(aPropSet);
270 OSL_ENSURE(
mvModels.empty() || (
mvModels.back().mnPos <= rPortion.
mnPos),
"FontPortionModelList::appendPortion - wrong char order" );
283 mvModels.reserve( getLimitedValue< size_t, sal_Int64 >(
nCount, 0,
rStrm.getRemaining() / 4 ) );
297 mnType( XML_fullwidthKatakana ),
298 mnAlignment( XML_left )
304 static const sal_Int32 spnTypeIds[] = { XML_halfwidthKatakana, XML_fullwidthKatakana, XML_hiragana, XML_noConversion };
307 static const sal_Int32 spnAlignments[] = { XML_noControl, XML_left, XML_center, XML_distributed };
326 sal_Int32
nType, nAlignment;
327 nFontId =
rStrm.readuInt16();
329 nAlignment =
rStrm.readInt32();
336 sal_uInt16 nFontId, nFlags;
337 nFontId =
rStrm.readuInt16();
338 nFlags =
rStrm.readuInt16();
340 maModel.
setBiffData( extractValue< sal_Int32 >( nFlags, 0, 2 ), extractValue< sal_Int32 >( nFlags, 2, 2 ) );
378 "PhoneticPortionModelList::appendPortion - wrong char order" );
396 mvModels.reserve( getLimitedValue< size_t, sal_Int64 >(
nCount, 0,
rStrm.getRemaining() / 6 ) );
419 xPhonetic->importPhoneticRun( rAttribs );
435 if( !
rStrm.isEof() &&
getFlag( nFlags, BIFF12_STRINGFLAG_FONTS ) )
446 if( !
rStrm.isEof() &&
getFlag( nFlags, BIFF12_STRINGFLAG_PHONETICS ) )
461 rPortion.finalizeImport( rHelper );
476 return orString.indexOf(
'\x0A' ) < 0;
488 rxText->setString(rPtn.
getText());
493 bool bReplaceOld =
true;
496 rTextPortion.convert( rxText, bReplaceOld );
505 OUStringBuffer sString;
507 sString.append(rTextPortion.getText());
516 rTextPortion.convert( rEE, aSelection, pFirstPortionFont );
517 pFirstPortionFont =
nullptr;
544 sal_Int32 nStrLen = aText.size();
552 for( ::std::vector< FontPortionModel >::const_iterator aIt = rPortions.
begin(); aIt->mnPos < nStrLen; ++aIt )
554 sal_Int32 nPortionLen = (aIt + 1)->mnPos - aIt->mnPos;
555 if( (0 < nPortionLen) && (aIt->mnPos + nPortionLen <= nStrLen) )
558 rPortion.
setText( OUString(aText.substr( aIt->mnPos, nPortionLen )) );
570 sal_Int32 nStrLen = aText.size();
572 if( rPortions.
empty() )
579 for( ::std::vector< PhoneticPortionModel >::const_iterator aIt = rPortions.
begin(); aIt->mnPos < nStrLen; ++aIt )
581 sal_Int32 nPortionLen = (aIt + 1)->mnPos - aIt->mnPos;
582 if( (0 < nPortionLen) && (aIt->mnPos + nPortionLen <= nStrLen) )
585 xPhonetic->setText( OUString(aText.substr( aIt->mnPos, nPortionLen )) );
586 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.
std::optional< sal_Int32 > getInteger(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.
sal_Int32 importText()
Appends and returns an index of a portion object for a plain string (t element).
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.
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,...
RichStringPhoneticRef importPhoneticRun(const AttributeList &rAttribs)
Appends and returns a phonetic text object for a new phonetic run (rPh element).
RichStringPortion & getPortion(sal_Int32 nPortionIdx)
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.