summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2011-12-08 12:39:07 +0000
committerCaolán McNamara <caolanm@redhat.com>2011-12-08 12:41:12 +0000
commit3e6ae8428a2d9da28c392c58bf8b3b15738088ff (patch)
tree43653c59eb488743d0b2476f3ac12eedf4253c19
parent9cb0e7af9d5d123a6e0cb933fb43d0f53ab4b904 (diff)
Resolves: fdo#43337 optimize weak-char overriding
When writer would choose the same bias automatically that word implies or this doc hard-codes, then elide the font-forcing.
-rw-r--r--sw/source/filter/ww8/ww8par.cxx69
1 files changed, 59 insertions, 10 deletions
diff --git a/sw/source/filter/ww8/ww8par.cxx b/sw/source/filter/ww8/ww8par.cxx
index 4d471446342a..99237686e660 100644
--- a/sw/source/filter/ww8/ww8par.cxx
+++ b/sw/source/filter/ww8/ww8par.cxx
@@ -2777,6 +2777,26 @@ namespace
}
return nPos;
}
+
+ sal_Int32 lcl_getWriterScriptType(
+ const uno::Reference<i18n::XBreakIterator>& rBI,
+ const rtl::OUString &rString, sal_Int32 nPos)
+ {
+ sal_Int16 nScript = i18n::ScriptType::WEAK;
+
+ if (rString.isEmpty())
+ return nScript;
+
+ while (nPos >= 0)
+ {
+ nScript = rBI->getScriptType(rString, nPos);
+ if (nScript != i18n::ScriptType::WEAK)
+ break;
+ --nPos;
+ }
+
+ return nScript;
+ }
}
//In writer we categorize text into CJK, CTL and "Western" for everything else.
@@ -2817,6 +2837,14 @@ void SwWW8ImplReader::emulateMSWordAddTextToParagraph(const rtl::OUString& rAddS
sal_Int16 nScript = lcl_getScriptType(xBI, rAddString, 0);
sal_Int32 nLen = rAddString.getLength();
+ rtl::OUString sParagraphText;
+ const SwCntntNode *pCntNd = pPaM->GetCntntNode();
+ const SwTxtNode* pNd = pCntNd ? pCntNd->GetTxtNode() : NULL;
+ if (pNd)
+ sParagraphText = pNd->GetTxt();
+ sal_Int32 nParaOffset = sParagraphText.getLength();
+ sParagraphText = sParagraphText + rAddString;
+
sal_Int32 nPos = 0;
while (nPos < nLen)
{
@@ -2853,20 +2881,41 @@ void SwWW8ImplReader::emulateMSWordAddTextToParagraph(const rtl::OUString& rAddS
break;
}
- const SvxFontItem *pSourceFont = (const SvxFontItem*)GetFmtAttr(nForceFromFontId);
+ //Now we know that word would use the nForceFromFontId font for this range
+ //Try and determine what script writer would assign this range to
+
+ sal_Int32 nWriterScript = lcl_getWriterScriptType(xBI, sParagraphText,
+ nPos + nParaOffset);
+
+ bool bWriterWillUseSameFontAsWordAutomatically = false;
+
+ if (
+ (nWriterScript == i18n::ScriptType::ASIAN && nForceFromFontId == RES_CHRATR_CJK_FONT) ||
+ (nWriterScript == i18n::ScriptType::COMPLEX && nForceFromFontId == RES_CHRATR_CTL_FONT) ||
+ (nWriterScript == i18n::ScriptType::LATIN && nForceFromFontId == RES_CHRATR_FONT)
+ )
+ {
+ bWriterWillUseSameFontAsWordAutomatically = true;
+ }
- for (size_t i = 0; i < SAL_N_ELEMENTS(aIds); ++i)
+ //Writer won't use the same font as word, so force the issue
+ if (!bWriterWillUseSameFontAsWordAutomatically)
{
- const SvxFontItem *pDestFont = (const SvxFontItem*)GetFmtAttr(aIds[i]);
- aForced[i] = aIds[i] != nForceFromFontId && *pSourceFont != *pDestFont;
- if (aForced[i])
+ const SvxFontItem *pSourceFont = (const SvxFontItem*)GetFmtAttr(nForceFromFontId);
+
+ for (size_t i = 0; i < SAL_N_ELEMENTS(aIds); ++i)
{
- pOverriddenItems[i] =
- (const SvxFontItem*)pCtrlStck->GetStackAttr(*pPaM->GetPoint(), aIds[i]);
+ const SvxFontItem *pDestFont = (const SvxFontItem*)GetFmtAttr(aIds[i]);
+ aForced[i] = aIds[i] != nForceFromFontId && *pSourceFont != *pDestFont;
+ if (aForced[i])
+ {
+ pOverriddenItems[i] =
+ (const SvxFontItem*)pCtrlStck->GetStackAttr(*pPaM->GetPoint(), aIds[i]);
- SvxFontItem aForceFont(*pSourceFont);
- aForceFont.SetWhich(aIds[i]);
- pCtrlStck->NewAttr(*pPaM->GetPoint(), aForceFont);
+ SvxFontItem aForceFont(*pSourceFont);
+ aForceFont.SetWhich(aIds[i]);
+ pCtrlStck->NewAttr(*pPaM->GetPoint(), aForceFont);
+ }
}
}
}