diff options
author | dante <dante19031999@gmail.com> | 2020-06-22 17:22:49 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-06-24 12:01:02 +0200 |
commit | e7fee907fa8240c742bd8f6268768d1acad2774f (patch) | |
tree | 4b887c794fc24d7b8e55508cabedfe83281aeb12 /starmath/source | |
parent | 3dcf7a3d221290b290aca4a7f4cb691322873fb6 (diff) |
Change-Id: Id0791609ada5b9f5460e46b20cfc7ce600cd3043
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96890
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'starmath/source')
-rw-r--r-- | starmath/source/ElementsDockingWindow.cxx | 6 | ||||
-rw-r--r-- | starmath/source/mathtype.cxx | 3 | ||||
-rw-r--r-- | starmath/source/node.cxx | 29 | ||||
-rw-r--r-- | starmath/source/parse.cxx | 79 |
4 files changed, 91 insertions, 26 deletions
diff --git a/starmath/source/ElementsDockingWindow.cxx b/starmath/source/ElementsDockingWindow.cxx index ebaa6b9e4fdd..c21933fe1be2 100644 --- a/starmath/source/ElementsDockingWindow.cxx +++ b/starmath/source/ElementsDockingWindow.cxx @@ -184,7 +184,7 @@ const SmElementDescr SmElementsControl::m_aAttributesList[] = {RID_COLORX_LIME, RID_COLORX_LIME_HELP}, {RID_COLORX_MAROON, RID_COLORX_MAROON_HELP}, {RID_COLORX_NAVY, RID_COLORX_NAVY_HELP}, {RID_COLORX_OLIVE, RID_COLORX_OLIVE_HELP}, {RID_COLORX_PURPLE, RID_COLORX_PURPLE_HELP}, {RID_COLORX_SILVER, RID_COLORX_SILVER_HELP}, - {RID_COLORX_TEAL, RID_COLORX_TEAL_HELP} + {RID_COLORX_TEAL, RID_COLORX_TEAL_HELP},{RID_COLORX_RGB, RID_COLORX_RGB_HELP} }; const SmElementDescr SmElementsControl::m_aBracketsList[] = @@ -225,7 +225,7 @@ const SmElementDescr SmElementsControl::m_aOthersList[] = {RID_INFINITY, RID_INFINITY_HELP}, {RID_PARTIAL, RID_PARTIAL_HELP}, {RID_NABLA, RID_NABLA_HELP}, {RID_EXISTS, RID_EXISTS_HELP}, {RID_NOTEXISTS, RID_NOTEXISTS_HELP}, {RID_FORALL, RID_FORALL_HELP}, {RID_HBAR, RID_HBAR_HELP}, {RID_LAMBDABAR, RID_LAMBDABAR_HELP}, {RID_RE, RID_RE_HELP}, - {RID_IM, RID_IM_HELP}, {RID_WP, RID_WP_HELP}, + {RID_IM, RID_IM_HELP}, {RID_WP, RID_WP_HELP}, {RID_LAPLACE, RID_LAPLACE_HELP}, {nullptr, nullptr}, {RID_LEFTARROW, RID_LEFTARROW_HELP}, {RID_RIGHTARROW, RID_RIGHTARROW_HELP}, {RID_UPARROW, RID_UPARROW_HELP}, {RID_DOWNARROW, RID_DOWNARROW_HELP}, @@ -917,6 +917,8 @@ void SmElementsControl::addElements(const SmElementDescr aElementsArray[], sal_u addElement(aParser, "color silver { \"" + SmResId(STR_SILVER) + "\" }", aElement, SmResId(pElementHelp)); else if (aElement == RID_COLORX_TEAL) addElement(aParser, "color teal { \"" + SmResId(STR_TEAL) + "\" }", aElement, SmResId(pElementHelp)); + else if (aElement == RID_COLORX_RGB) + addElement(aParser, "color rgb 0 0 0 { \"" + SmResId(STR_RGB) + "\" }", aElement, SmResId(pElementHelp)); else if (aElement == RID_ALIGNLX) addElement(aParser, "\"" + SmResId(STR_ALIGN_LEFT) + "\"", aElement, SmResId(pElementHelp)); else if (aElement == RID_ALIGNCX) diff --git a/starmath/source/mathtype.cxx b/starmath/source/mathtype.cxx index d0889ce393d8..13297eb7fc34 100644 --- a/starmath/source/mathtype.cxx +++ b/starmath/source/mathtype.cxx @@ -311,6 +311,9 @@ bool MathType::LookupChar(sal_Unicode nChar,OUStringBuffer &rRet,sal_uInt8 nVers case 0x2207: pC = " nabla "; break; + case 0x2112: + pC = " laplace "; + break; case 0x2208: // in case 0x2209: // notin rRet.append(" func ").append(OUStringChar(nChar)).append(" "); diff --git a/starmath/source/node.cxx b/starmath/source/node.cxx index ba62c4d9a484..526b2e3ee010 100644 --- a/starmath/source/node.cxx +++ b/starmath/source/node.cxx @@ -1719,6 +1719,7 @@ void SmAttributNode::Arrange(OutputDevice &rDev, const SmFormat &rFormat) void SmFontNode::CreateTextFromNode(OUStringBuffer &rText) { rText.append("{"); + sal_Int32 nc,r,g,b; switch (GetToken().eType) { @@ -1819,6 +1820,21 @@ void SmFontNode::CreateTextFromNode(OUStringBuffer &rText) case TFUCHSIA: rText.append("color fuchsia "); break; + case TRGB: + rText.append("color rgb "); + nc = GetToken().aText.toInt32(); + b = nc % 256; + nc /= 256; + g = nc % 256; + nc /= 256; + r = nc % 256; + rText.append(r); + rText.append(" "); + rText.append(g); + rText.append(" "); + rText.append(b); + rText.append(" "); + break; case TSANS: rText.append("font sans "); break; @@ -1866,6 +1882,8 @@ void SmFontNode::Arrange(OutputDevice &rDev, const SmFormat &rFormat) { SmNode *pNode = GetSubNode(1); assert(pNode); + sal_Int32 nc; + Color col_perso_rgb_color (0); switch (GetToken().eType) { case TSIZE : @@ -1902,6 +1920,15 @@ void SmFontNode::Arrange(OutputDevice &rDev, const SmFormat &rFormat) case TNAVY : SetColor(COL_BLUE); break; case TAQUA : SetColor(COL_LIGHTCYAN); break; case TFUCHSIA : SetColor(COL_LIGHTMAGENTA); break; + case TRGB : + nc = GetToken().aText.toInt32(); + col_perso_rgb_color.SetBlue(nc % 256); + nc /= 256; + col_perso_rgb_color.SetGreen(nc % 256); + nc /= 256; + col_perso_rgb_color.SetRed(nc % 256); + SetColor(col_perso_rgb_color); + break; default: SAL_WARN("starmath", "unknown case"); @@ -2658,7 +2685,7 @@ void SmSpecialNode::Prepare(const SmFormat &rFormat, const SmDocShell &rDocShell static const sal_Unicode cUppercaseOmega = 0x03A9; sal_Unicode cChar = rTmp[0]; // uppercase letters should be straight and lowercase letters italic - bItalic = (cUppercaseAlpha > cChar || cChar > cUppercaseOmega); + bItalic = cUppercaseAlpha > cChar || cChar > cUppercaseOmega; } } diff --git a/starmath/source/parse.cxx b/starmath/source/parse.cxx index 7a39233a762b..67512e4a44eb 100644 --- a/starmath/source/parse.cxx +++ b/starmath/source/parse.cxx @@ -64,7 +64,7 @@ SmToken::SmToken(SmTokenType eTokenType, { } - +//Definition of math keywords static const SmTokenTableEntry aTokenTable[] = { { "abs", TABS, '\0', TG::UnOper, 13 }, @@ -159,6 +159,7 @@ static const SmTokenTableEntry aTokenTable[] = { "italic", TITALIC, '\0', TG::FontAttr, 5}, { "lambdabar" , TLAMBDABAR, MS_LAMBDABAR, TG::Standalone, 5}, { "langle", TLANGLE, MS_LMATHANGLE, TG::LBrace, 5}, + { "laplace", TLAPLACE, MS_LAPLACE, TG::Standalone, 5}, { "lbrace", TLBRACE, MS_LBRACE, TG::LBrace, 5}, { "lceil", TLCEIL, MS_LCEIL, TG::LBrace, 5}, { "ldbracket", TLDBRACKET, MS_LDBRACKET, TG::LBrace, 5}, @@ -239,6 +240,7 @@ static const SmTokenTableEntry aTokenTable[] = { "re" , TRE, MS_RE, TG::Standalone, 5 }, { "red", TRED, '\0', TG::Color, 0}, { "rfloor", TRFLOOR, MS_RFLOOR, TG::RBrace, 0}, //! 0 to terminate expression + { "rgb", TRGB, '\0', TG::Color, 0}, { "right", TRIGHT, '\0', TG::NONE, 0}, { "rightarrow" , TRIGHTARROW, MS_RIGHTARROW, TG::Standalone, 5}, { "rline", TRLINE, MS_VERTLINE, TG::RBrace, 0}, //! 0 to terminate expression @@ -297,33 +299,37 @@ static const SmTokenTableEntry aTokenTable[] = { "yellow", TYELLOW, '\0', TG::Color, 0} }; +//Checks if keyword is in the list by SmTokenTableEntry. #if !defined NDEBUG static bool sortCompare(const SmTokenTableEntry & lhs, const SmTokenTableEntry & rhs) { return OUString::createFromAscii(lhs.pIdent).compareToIgnoreAsciiCase(OUString::createFromAscii(rhs.pIdent)) < 0; } #endif + +//Checks if keyword is in the list. static bool findCompare(const SmTokenTableEntry & lhs, const OUString & s) { return s.compareToIgnoreAsciiCaseAscii(lhs.pIdent) > 0; } + +//Returns the SmTokenTableEntry for a keyword const SmTokenTableEntry * SmParser::GetTokenTableEntry( const OUString &rName ) { - static bool bSortKeyWords = false; - if( !bSortKeyWords ) + static bool bSortKeyWords = false; // Flag: RTF-token table has been sorted. + if( !bSortKeyWords ) //First time sorts it. { assert( std::is_sorted( std::begin(aTokenTable), std::end(aTokenTable), sortCompare ) ); bSortKeyWords = true; } - if (rName.isEmpty()) - return nullptr; + if (rName.isEmpty())return nullptr; //avoid null pointer exceptions + //Looks for the first keyword after or equal to rName in alphabetical order. auto findIter = std::lower_bound( std::begin(aTokenTable), std::end(aTokenTable), rName, findCompare ); - if ( findIter != std::end(aTokenTable) && rName.equalsIgnoreAsciiCaseAscii( findIter->pIdent )) - return &*findIter; + if ( findIter != std::end(aTokenTable) && rName.equalsIgnoreAsciiCaseAscii( findIter->pIdent ))return &*findIter; //check is equal - return nullptr; + return nullptr; //not found } namespace { @@ -333,42 +339,44 @@ bool IsDelimiter( const OUString &rTxt, sal_Int32 nPos ) { assert(nPos <= rTxt.getLength()); //index out of range - if (nPos == rTxt.getLength()) - return true; + if (nPos == rTxt.getLength())return true; //This is EOF sal_Unicode cChar = rTxt[nPos]; // check if 'cChar' is in the delimiter table static const sal_Unicode aDelimiterTable[] = { - ' ', '\t', '\n', '\r', '+', '-', '*', '/', '=', '#', - '%', '\\', '"', '~', '`', '>', '<', '&', '|', '(', - ')', '{', '}', '[', ']', '^', '_' - }; + ' ', '{', '}', '(', ')', '\t', '\n', '\r', '+', '-', + '*', '/', '=', '[', ']', '^', '_', '#', + '%', '>', '<', '&', '|', '\\', '"', '~', '`' + };//reordered by usage (by eye) for nanoseconds saving. + + //checks the array for (auto const &cDelimiter : aDelimiterTable) { - if (cDelimiter == cChar) - return true; + if (cDelimiter == cChar)return true; } + //special chars support sal_Int16 nTypJp = SM_MOD()->GetSysLocale().GetCharClass().getType( rTxt, nPos ); return ( nTypJp == css::i18n::UnicodeType::SPACE_SEPARATOR || nTypJp == css::i18n::UnicodeType::CONTROL); } -} +}//end namespace +//Text replace onto m_aBufferString void SmParser::Replace( sal_Int32 nPos, sal_Int32 nLen, const OUString &rText ) { - assert( nPos + nLen <= m_aBufferString.getLength() ); + assert( nPos + nLen <= m_aBufferString.getLength() ); //checks if length allows text replace - m_aBufferString = m_aBufferString.replaceAt( nPos, nLen, rText ); + m_aBufferString = m_aBufferString.replaceAt( nPos, nLen, rText ); //replace and reindex sal_Int32 nChg = rText.getLength() - nLen; m_nBufferIndex = m_nBufferIndex + nChg; m_nTokenIndex = m_nTokenIndex + nChg; } -void SmParser::NextToken() +void SmParser::NextToken() //Central part of the parser { // First character may be any alphabetic static const sal_Int32 coStartFlags = @@ -979,7 +987,7 @@ namespace aSubArray[i] = rSubNodes[i].release(); return aSubArray; } -} +} //end namespace // grammar @@ -1474,6 +1482,7 @@ std::unique_ptr<SmNode> SmParser::DoTerm(bool bGroupNumberIdent) case TFORALL : case TPARTIAL : case TNABLA : + case TLAPLACE : case TTOWARD : case TDOTSAXIS : case TDOTSDIAG : @@ -1860,10 +1869,34 @@ std::unique_ptr<SmStructureNode> SmParser::DoColor() // last color rules, get that one SmToken aToken; do - { NextToken(); + { + + NextToken(); if (TokenInGroup(TG::Color)) - { aToken = m_aCurToken; + { + aToken = m_aCurToken; + if(m_aCurToken.eType==TRGB){ + SmToken r,g,b; + sal_Int32 nr, ng, nb, nc; + NextToken(); + if(m_aCurToken.eType!=TNUMBER)return DoError(SmParseError::ColorExpected); + r = m_aCurToken; + NextToken(); + if(m_aCurToken.eType!=TNUMBER)return DoError(SmParseError::ColorExpected); + g = m_aCurToken; + NextToken(); + if(m_aCurToken.eType!=TNUMBER)return DoError(SmParseError::ColorExpected); + b = m_aCurToken; + nr = r.aText.toInt32(); + if( nr < 0 || nr > 255 )return DoError(SmParseError::ColorExpected); + ng = g.aText.toInt32(); + if( ng < 0 || ng > 255 )return DoError(SmParseError::ColorExpected); + nb = b.aText.toInt32(); + if( nb < 0 || nb > 255 )return DoError(SmParseError::ColorExpected); + nc = nb + 256 * ( ng + nr*256 ); + aToken.aText = OUString::number(nc); + } NextToken(); } else |