writerfilter/source/dmapper/DomainMapper.cxx | 41 ----------- writerfilter/source/doctok/resources.xmi | 93 ------------------------- writerfilter/source/rtftok/rtfdocumentimpl.cxx | 84 +++++++++++++++------- writerfilter/source/rtftok/rtfdocumentimpl.hxx | 16 +++- 4 files changed, 69 insertions(+), 165 deletions(-)
New commits: commit 1484eee9437346fce788fb4afc8488900a5c4fd1 Author: Miklos Vajna <vmik...@collabora.co.uk> Date: Wed Mar 5 21:00:51 2014 +0100 writerfilter: remove handling of never-generated sprm:CRgFtc{0,1,2} tokens Change-Id: Idbdd4d9b8e0498f09c9a66391a8e8d0bd31606ea diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx index 6e0f4e3..e30f83a 100644 --- a/writerfilter/source/dmapper/DomainMapper.cxx +++ b/writerfilter/source/dmapper/DomainMapper.cxx @@ -1506,47 +1506,6 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, PropertyMapPtr rContext, SprmType case NS_ooxml::LN_EG_RPrBase_kern: // auto kerning is bound to a minimum font size in Word - but not in Writer :-( rContext->Insert(PROP_CHAR_AUTO_KERNING, uno::makeAny( sal_Bool(nIntValue) ) ); break; - case NS_sprm::LN_CRgFtc0: // sprmCRgFtc0 //ascii font index - case NS_sprm::LN_CRgFtc1: // sprmCRgFtc1 //Asian font index - case NS_sprm::LN_CRgFtc2: // sprmCRgFtc2 //CTL font index - { - FontTablePtr pFontTable = m_pImpl->GetFontTable(); - if(nIntValue >= 0 && pFontTable->size() > sal_uInt32(nIntValue)) - { - PropertyIds eFontName = PROP_CHAR_FONT_NAME; - PropertyIds eFontStyle = PROP_CHAR_FONT_STYLE; - PropertyIds eFontFamily = PROP_CHAR_FONT_FAMILY; - PropertyIds eFontCharSet = PROP_CHAR_FONT_CHAR_SET; - PropertyIds eFontPitch = PROP_CHAR_FONT_PITCH; - switch(nSprmId) - { - case NS_sprm::LN_CRgFtc0: - //already initialized - break; - case NS_sprm::LN_CRgFtc1: - eFontName = PROP_CHAR_FONT_NAME_ASIAN; - eFontStyle = PROP_CHAR_FONT_STYLE_ASIAN; - eFontFamily = PROP_CHAR_FONT_FAMILY_ASIAN; - eFontCharSet = PROP_CHAR_FONT_CHAR_SET_ASIAN; - eFontPitch = PROP_CHAR_FONT_PITCH_ASIAN; - break; - case NS_sprm::LN_CRgFtc2: - eFontName = PROP_CHAR_FONT_NAME_COMPLEX; - eFontStyle = PROP_CHAR_FONT_STYLE_COMPLEX; - eFontFamily = PROP_CHAR_FONT_FAMILY_COMPLEX; - eFontCharSet = PROP_CHAR_FONT_CHAR_SET_COMPLEX; - eFontPitch = PROP_CHAR_FONT_PITCH_COMPLEX; - break; - } - (void)eFontFamily; - (void)eFontStyle; - const FontEntry::Pointer_t pFontEntry(pFontTable->getFontEntry(sal_uInt32(nIntValue))); - rContext->Insert(eFontName, uno::makeAny( pFontEntry->sFontName )); - rContext->Insert(eFontCharSet, uno::makeAny( (sal_Int16)pFontEntry->nTextEncoding )); - rContext->Insert(eFontPitch, uno::makeAny( pFontEntry->nPitchRequest )); - } - } - break; case NS_ooxml::LN_EG_RPrBase_w: rContext->Insert(PROP_CHAR_SCALE_WIDTH, uno::makeAny( sal_Int16(nIntValue) )); diff --git a/writerfilter/source/doctok/resources.xmi b/writerfilter/source/doctok/resources.xmi index 7c955d1..5f2b4d8 100644 --- a/writerfilter/source/doctok/resources.xmi +++ b/writerfilter/source/doctok/resources.xmi @@ -100,99 +100,6 @@ </UML:ModelElement.taggedValue> </UML:Class> <!--SPRM sprmCIco--> - <!--SPRM sprmCRgFtc0--> - <UML:Class xmi.id="sprmCRgFtc0" name="sprmCRgFtc0"> - <UML:ModelElement.stereotype> - <UML:Stereotype xmi.idref="ww8sprm"/> - </UML:ModelElement.stereotype> - <UML:ModelElement.taggedValue> - <UML:TaggedValue> - <UML:TaggedValue.dataValue>0x4A4F</UML:TaggedValue.dataValue> - <UML:TaggedValue.type> - <UML:TagDefinition xmi.idref="sprmcode"/> - </UML:TaggedValue.type> - </UML:TaggedValue> - </UML:ModelElement.taggedValue> - <UML:ModelElement.taggedValue> - <UML:TaggedValue> - <UML:TaggedValue.dataValue>rtf:sprmCRgFtc0</UML:TaggedValue.dataValue> - <UML:TaggedValue.type> - <UML:TagDefinition xmi.idref="sprmid"/> - </UML:TaggedValue.type> - </UML:TaggedValue> - </UML:ModelElement.taggedValue> - <UML:ModelElement.taggedValue> - <UML:TaggedValue> - <UML:TaggedValue.dataValue>character</UML:TaggedValue.dataValue> - <UML:TaggedValue.type> - <UML:TagDefinition xmi.idref="kind"/> - </UML:TaggedValue.type> - </UML:TaggedValue> - </UML:ModelElement.taggedValue> - </UML:Class> - <!--SPRM sprmCRgFtc0--> - <!--SPRM sprmCRgFtc1--> - <UML:Class xmi.id="sprmCRgFtc1" name="sprmCRgFtc1"> - <UML:ModelElement.stereotype> - <UML:Stereotype xmi.idref="ww8sprm"/> - </UML:ModelElement.stereotype> - <UML:ModelElement.taggedValue> - <UML:TaggedValue> - <UML:TaggedValue.dataValue>0x4A50</UML:TaggedValue.dataValue> - <UML:TaggedValue.type> - <UML:TagDefinition xmi.idref="sprmcode"/> - </UML:TaggedValue.type> - </UML:TaggedValue> - </UML:ModelElement.taggedValue> - <UML:ModelElement.taggedValue> - <UML:TaggedValue> - <UML:TaggedValue.dataValue>rtf:sprmCRgFtc1</UML:TaggedValue.dataValue> - <UML:TaggedValue.type> - <UML:TagDefinition xmi.idref="sprmid"/> - </UML:TaggedValue.type> - </UML:TaggedValue> - </UML:ModelElement.taggedValue> - <UML:ModelElement.taggedValue> - <UML:TaggedValue> - <UML:TaggedValue.dataValue>character</UML:TaggedValue.dataValue> - <UML:TaggedValue.type> - <UML:TagDefinition xmi.idref="kind"/> - </UML:TaggedValue.type> - </UML:TaggedValue> - </UML:ModelElement.taggedValue> - </UML:Class> - <!--SPRM sprmCRgFtc1--> - <!--SPRM sprmCRgFtc2--> - <UML:Class xmi.id="sprmCRgFtc2" name="sprmCRgFtc2"> - <UML:ModelElement.stereotype> - <UML:Stereotype xmi.idref="ww8sprm"/> - </UML:ModelElement.stereotype> - <UML:ModelElement.taggedValue> - <UML:TaggedValue> - <UML:TaggedValue.dataValue>0x4A51</UML:TaggedValue.dataValue> - <UML:TaggedValue.type> - <UML:TagDefinition xmi.idref="sprmcode"/> - </UML:TaggedValue.type> - </UML:TaggedValue> - </UML:ModelElement.taggedValue> - <UML:ModelElement.taggedValue> - <UML:TaggedValue> - <UML:TaggedValue.dataValue>rtf:sprmCRgFtc2</UML:TaggedValue.dataValue> - <UML:TaggedValue.type> - <UML:TagDefinition xmi.idref="sprmid"/> - </UML:TaggedValue.type> - </UML:TaggedValue> - </UML:ModelElement.taggedValue> - <UML:ModelElement.taggedValue> - <UML:TaggedValue> - <UML:TaggedValue.dataValue>character</UML:TaggedValue.dataValue> - <UML:TaggedValue.type> - <UML:TagDefinition xmi.idref="kind"/> - </UML:TaggedValue.type> - </UML:TaggedValue> - </UML:ModelElement.taggedValue> - </UML:Class> - <!--SPRM sprmCRgFtc2--> <!--SPRM sprmSTextFlow--> <UML:Class xmi.id="sprmSTextFlow" name="sprmSTextFlow"> <UML:ModelElement.stereotype> commit bbe3627eece0c3486e7ea11f2f13377aaa3a8fed Author: Miklos Vajna <vmik...@collabora.co.uk> Date: Wed Mar 5 20:54:26 2014 +0100 rtftok: stop sending sprm:CRgFtc{0,1,2} tokens Change-Id: I5009fb6214da763750fba3aa7067e1e28441d7dd diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx index 60966e6..a60d1a5 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx @@ -106,6 +106,15 @@ static void lcl_putNestedSprm(RTFSprms& rSprms, Id nParent, Id nId, RTFValue::Po lcl_putNestedAttribute(rSprms, nParent, nId, pValue, bOverwrite, false); } +static RTFValue::Pointer_t lcl_getNestedAttribute(RTFSprms& rSprms, Id nParent, Id nId) +{ + RTFValue::Pointer_t pParent = rSprms.find(nParent); + if (!pParent) + return RTFValue::Pointer_t(); + RTFSprms& rAttributes = pParent->getAttributes(); + return rAttributes.find(nId); +} + static bool lcl_eraseNestedAttribute(RTFSprms& rSprms, Id nParent, Id nId) { RTFValue::Pointer_t pParent = rSprms.find(nParent); @@ -237,7 +246,6 @@ RTFDocumentImpl::RTFDocumentImpl(uno::Reference<uno::XComponentContext> const& x m_xStatusIndicator(xStatusIndicator), m_aDefaultState(this), m_bSkipUnknown(false), - m_aFontEncodings(), m_aFontIndexes(), m_aColorTable(), m_bFirstRun(true), @@ -272,6 +280,8 @@ RTFDocumentImpl::RTFDocumentImpl(uno::Reference<uno::XComponentContext> const& x m_bObject(false), m_aFontTableEntries(), m_nCurrentFontIndex(0), + m_nCurrentEncoding(0), + m_nDefaultFontIndex(-1), m_aStyleTableEntries(), m_nCurrentStyleIndex(0), m_bFormField(false), @@ -399,10 +409,10 @@ void RTFDocumentImpl::checkFirstRun() setNeedSect(); // first call that succeeds // set the requested default font, if there are none - RTFValue::Pointer_t pFont = m_aDefaultState.aCharacterSprms.find(NS_sprm::LN_CRgFtc0); - RTFValue::Pointer_t pCurrentFont = m_aStates.top().aCharacterSprms.find(NS_sprm::LN_CRgFtc0); + RTFValue::Pointer_t pFont = lcl_getNestedAttribute(m_aDefaultState.aCharacterSprms, NS_ooxml::LN_EG_RPrBase_rFonts, NS_ooxml::LN_CT_Fonts_ascii); + RTFValue::Pointer_t pCurrentFont = lcl_getNestedAttribute(m_aStates.top().aCharacterSprms, NS_ooxml::LN_EG_RPrBase_rFonts, NS_ooxml::LN_CT_Fonts_ascii); if (pFont && !pCurrentFont) - dispatchValue(RTF_F, pFont->getInt()); + lcl_putNestedAttribute(m_aStates.top().aCharacterSprms, NS_ooxml::LN_EG_RPrBase_rFonts, NS_ooxml::LN_CT_Fonts_ascii, pFont); } } @@ -610,17 +620,25 @@ sal_uInt32 RTFDocumentImpl::getColorTable(sal_uInt32 nIndex) return m_pSuperstream->getColorTable(nIndex); } -rtl_TextEncoding RTFDocumentImpl::getEncoding(sal_uInt32 nFontIndex) +rtl_TextEncoding RTFDocumentImpl::getEncoding(OUString aFontName) { if (!m_pSuperstream) { - std::map<int, rtl_TextEncoding>::iterator it = m_aFontEncodings.find(nFontIndex); + std::map<OUString, rtl_TextEncoding>::iterator it = m_aFontEncodings.find(aFontName); if (it != m_aFontEncodings.end()) return it->second; return msfilter::util::getBestTextEncodingFromLocale(Application::GetSettings().GetLanguageTag().getLocale()); } else - return m_pSuperstream->getEncoding(nFontIndex); + return m_pSuperstream->getEncoding(aFontName); +} + +OUString RTFDocumentImpl::getFontName(int nIndex) +{ + if (!m_pSuperstream) + return m_aFontNames[nIndex]; + else + return m_pSuperstream->getFontName(nIndex); } int RTFDocumentImpl::getFontIndex(int nIndex) @@ -1069,8 +1087,14 @@ void RTFDocumentImpl::text(OUString& rString) case DESTINATION_FONTTABLE: case DESTINATION_FONTENTRY: { - RTFValue::Pointer_t pValue(new RTFValue(m_aStates.top().aDestinationText.makeStringAndClear())); - m_aStates.top().aTableAttributes.set(NS_ooxml::LN_CT_Font_name, pValue); + OUString aName = m_aStates.top().aDestinationText.makeStringAndClear(); + m_aFontNames[m_nCurrentFontIndex] = aName; + if (m_nCurrentEncoding > 0) + { + m_aFontEncodings[aName] = m_nCurrentEncoding; + m_nCurrentEncoding = 0; + } + m_aStates.top().aTableAttributes.set(NS_ooxml::LN_CT_Font_name, RTFValue::Pointer_t(new RTFValue(aName))); writerfilter::Reference<Properties>::Pointer_t const pProp( new RTFReferenceProperties(m_aStates.top().aTableAttributes, m_aStates.top().aTableSprms) @@ -2474,9 +2498,9 @@ int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword) case RTF_PLAIN: { m_aStates.top().aCharacterSprms = getDefaultState().aCharacterSprms; - RTFValue::Pointer_t pValue = m_aStates.top().aCharacterSprms.find(NS_sprm::LN_CRgFtc0); - if (pValue.get()) - m_aStates.top().nCurrentEncoding = getEncoding(pValue->getInt()); + RTFValue::Pointer_t pValue = lcl_getNestedAttribute(m_aStates.top().aCharacterSprms, NS_ooxml::LN_EG_RPrBase_rFonts, NS_ooxml::LN_CT_Fonts_ascii); + if (pValue) + m_aStates.top().nCurrentEncoding = getEncoding(pValue->getString()); m_aStates.top().aCharacterAttributes = getDefaultState().aCharacterAttributes; } break; @@ -3120,9 +3144,9 @@ int RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam) case RTF_F: case RTF_AF: if (nKeyword == RTF_F) - nSprm = NS_sprm::LN_CRgFtc0; + nSprm = NS_ooxml::LN_CT_Fonts_ascii; else - nSprm = (m_aStates.top().bIsCjk ? NS_sprm::LN_CRgFtc1 : NS_sprm::LN_CRgFtc2); + nSprm = (m_aStates.top().bIsCjk ? NS_ooxml::LN_CT_Fonts_eastAsia : NS_ooxml::LN_CT_Fonts_cs); if (m_aStates.top().nDestinationState == DESTINATION_FONTTABLE || m_aStates.top().nDestinationState == DESTINATION_FONTENTRY) { m_aFontIndexes.push_back(nParam); @@ -3130,13 +3154,13 @@ int RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam) } else if (m_aStates.top().nDestinationState == DESTINATION_LISTLEVEL) { - RTFSprms aFontSprms; - aFontSprms.set(nSprm, RTFValue::Pointer_t(new RTFValue(getFontIndex(nParam)))); + RTFSprms aFontAttributes; + aFontAttributes.set(nSprm, RTFValue::Pointer_t(new RTFValue(m_aFontNames[getFontIndex(nParam)]))); // In the context of listlevels, \af seems to imply \f. if (nKeyword == RTF_AF) - aFontSprms.set(NS_sprm::LN_CRgFtc0, RTFValue::Pointer_t(new RTFValue(getFontIndex(nParam)))); + aFontAttributes.set(NS_ooxml::LN_CT_Fonts_ascii, RTFValue::Pointer_t(new RTFValue(m_aFontNames[getFontIndex(nParam)]))); RTFSprms aRunPropsSprms; - aRunPropsSprms.set(NS_ooxml::LN_EG_RPrBase_rFonts, RTFValue::Pointer_t(new RTFValue(RTFSprms(), aFontSprms))); + aRunPropsSprms.set(NS_ooxml::LN_EG_RPrBase_rFonts, RTFValue::Pointer_t(new RTFValue(aFontAttributes))); // If there are multiple \f or \af tokens, only handle the first one. if (!m_aStates.top().aTableSprms.find(NS_ooxml::LN_CT_Lvl_rPr)) m_aStates.top().aTableSprms.set(NS_ooxml::LN_CT_Lvl_rPr, RTFValue::Pointer_t(new RTFValue(RTFSprms(), aRunPropsSprms))); @@ -3144,9 +3168,9 @@ int RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam) else { int nFontIndex = getFontIndex(nParam); - RTFValue::Pointer_t pValue(new RTFValue(nFontIndex)); - m_aStates.top().aCharacterSprms.set(nSprm, pValue); - m_aStates.top().nCurrentEncoding = getEncoding(nFontIndex); + RTFValue::Pointer_t pValue(new RTFValue(getFontName(nFontIndex))); + lcl_putNestedAttribute(m_aStates.top().aCharacterSprms, NS_ooxml::LN_EG_RPrBase_rFonts, nSprm, pValue); + m_aStates.top().nCurrentEncoding = getEncoding(getFontName(nFontIndex)); } break; case RTF_RED: @@ -3172,7 +3196,7 @@ int RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam) // not found return 0; - m_aFontEncodings[m_nCurrentFontIndex] = rtl_getTextEncodingFromWindowsCodePage(aRTFEncodings[i].codepage); + m_nCurrentEncoding = rtl_getTextEncodingFromWindowsCodePage(aRTFEncodings[i].codepage); } break; case RTF_ANSICPG: @@ -3182,7 +3206,7 @@ int RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam) } break; case RTF_CPG: - m_aFontEncodings[m_nCurrentFontIndex] = rtl_getTextEncodingFromWindowsCodePage(nParam); + m_nCurrentEncoding = rtl_getTextEncodingFromWindowsCodePage(nParam); break; case RTF_CF: { @@ -3226,7 +3250,7 @@ int RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam) } break; case RTF_DEFF: - m_aDefaultState.aCharacterSprms.set(NS_sprm::LN_CRgFtc0, pIntValue); + m_nDefaultFontIndex = nParam; break; case RTF_DEFLANG: case RTF_ADEFLANG: @@ -3809,9 +3833,10 @@ int RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam) break; case RTF_PNF: { - int nFontIndex = getFontIndex(nParam); - RTFValue::Pointer_t pValue(new RTFValue(nFontIndex)); - lcl_putNestedSprm(m_aStates.top().aTableSprms, NS_ooxml::LN_CT_Lvl_rPr, NS_sprm::LN_CRgFtc0, pValue); + RTFValue::Pointer_t pValue(new RTFValue(m_aFontNames[getFontIndex(nParam)])); + RTFSprms aAttributes; + aAttributes.set(NS_ooxml::LN_CT_Fonts_ascii, pValue); + lcl_putNestedSprm(m_aStates.top().aTableSprms, NS_ooxml::LN_CT_Lvl_rPr, NS_ooxml::LN_EG_RPrBase_rFonts, RTFValue::Pointer_t(new RTFValue(aAttributes))); } break; case RTF_VIEWSCALE: @@ -4192,6 +4217,11 @@ int RTFDocumentImpl::popState() { writerfilter::Reference<Table>::Pointer_t const pTable(new RTFReferenceTable(m_aFontTableEntries)); Mapper().table(NS_ooxml::LN_FONTTABLE, pTable); + if (m_nDefaultFontIndex >= 0) + { + RTFValue::Pointer_t pValue(new RTFValue(m_aFontNames[getFontIndex(m_nDefaultFontIndex)])); + lcl_putNestedAttribute(m_aDefaultState.aCharacterSprms, NS_ooxml::LN_EG_RPrBase_rFonts, NS_ooxml::LN_CT_Fonts_ascii, pValue); + } } break; case DESTINATION_STYLESHEET: diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.hxx b/writerfilter/source/rtftok/rtfdocumentimpl.hxx index 1c9ff06..b1a1b8e 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx @@ -353,10 +353,12 @@ namespace writerfilter { void setNeedPar(bool bNeedPar); /// Return the dmapper index of an RTF index for fonts. int getFontIndex(int nIndex); + /// Return the name of the font, based on a dmapper index. + OUString getFontName(int nIndex); /// Return the style name of an RTF style index. OUString getStyleName(int nIndex); - /// Return the encoding associated with a dmapper font index. - rtl_TextEncoding getEncoding(sal_uInt32 nFontIndex); + /// Return the encoding associated with a font name. + rtl_TextEncoding getEncoding(OUString aFontName); /// Get the default parser state. RTFParserState& getDefaultState(); oox::GraphicHelper& getGraphicHelper(); @@ -420,8 +422,10 @@ namespace writerfilter { /// Read by RTF_PARD. RTFParserState m_aDefaultState; bool m_bSkipUnknown; - /// Font index <-> encoding map, *not* part of the parser state - std::map<int, rtl_TextEncoding> m_aFontEncodings; + /// Font name <-> encoding map, *not* part of the parser state + std::map<OUString, rtl_TextEncoding> m_aFontEncodings; + /// Font index <-> name map. + std::map<int, OUString> m_aFontNames; /// Maps the non-continuous font indexes to the continuous dmapper indexes. std::vector<int> m_aFontIndexes; /// Maps style indexes to style names. @@ -510,6 +514,10 @@ namespace writerfilter { RTFReferenceTable::Entries_t m_aFontTableEntries; int m_nCurrentFontIndex; + /// Used only during font table parsing till we don't know the font name. + int m_nCurrentEncoding; + /// Used only before font table parsing. + int m_nDefaultFontIndex; RTFReferenceTable::Entries_t m_aStyleTableEntries; int m_nCurrentStyleIndex; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits