diff options
author | dante <dante19031999@gmail.com> | 2020-06-22 17:22:49 +0200 |
---|---|---|
committer | Adolfo Jayme Barrientos <fitojb@ubuntu.com> | 2020-06-24 18:58:57 +0200 |
commit | bcec35810326c09dccac168e0411c5bb42475732 (patch) | |
tree | ccbd8c79cd3bf068ae6bcfed29e2ca390cb522b7 /starmath | |
parent | 2f9cc6c14e9577cb88ba3d0f468e21cd29e14e68 (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>
Signed-off-by: Xisco Fauli <xiscofauli@libreoffice.org>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97044
Reviewed-by: Ilmari Lauhakangas <ilmari.lauhakangas@libreoffice.org>
Reviewed-by: Adolfo Jayme Barrientos <fitojb@ubuntu.com>
Diffstat (limited to 'starmath')
-rw-r--r-- | starmath/inc/strings.hrc | 3 | ||||
-rw-r--r-- | starmath/inc/strings.hxx | 2 | ||||
-rw-r--r-- | starmath/inc/token.hxx | 4 | ||||
-rw-r--r-- | starmath/inc/types.hxx | 2 | ||||
-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 | ||||
-rw-r--r-- | starmath/uiconfig/smath/popupmenu/edit.xml | 2 |
9 files changed, 103 insertions, 27 deletions
diff --git a/starmath/inc/strings.hrc b/starmath/inc/strings.hrc index f12677d26eca..b4a22c58e546 100644 --- a/starmath/inc/strings.hrc +++ b/starmath/inc/strings.hrc @@ -189,6 +189,7 @@ #define RID_COLORX_SILVER_HELP NC_("RID_COLORX_SILVER_HELP", "Color Silver" ) #define RID_COLORX_TEAL_HELP NC_("RID_COLORX_TEAL_HELP", "Color Teal" ) #define RID_COLORX_YELLOW_HELP NC_("RID_COLORX_YELLOW_HELP", "Color Yellow" ) +#define RID_COLORX_RGB_HELP NC_("RID_COLORX_RGB_HELP", "Color RGB" ) #define RID_LRGROUPX_HELP NC_("RID_LRGROUPX_HELP", "Group Brackets" ) #define RID_LRPARENTX_HELP NC_("RID_LRPARENTX_HELP", "Round Brackets" ) #define RID_LRBRACKETX_HELP NC_("RID_LRBRACKETX_HELP", "Square Brackets" ) @@ -235,6 +236,7 @@ #define RID_INFINITY_HELP NC_("RID_INFINITY_HELP", "Infinity" ) #define RID_PARTIAL_HELP NC_("RID_PARTIAL_HELP", "Partial" ) #define RID_NABLA_HELP NC_("RID_NABLA_HELP", "Nabla" ) +#define RID_LAPLACE_HELP NC_("RID_LAPLACE_HELP", "Laplace" ) #define RID_WP_HELP NC_("RID_WP_HELP", "Weierstrass p" ) #define RID_DOTSAXIS_HELP NC_("RID_DOTSAXIS_HELP", "Dots In Middle" ) #define RID_DOTSUP_HELP NC_("RID_DOTSUP_HELP", "Dots To Top" ) @@ -308,6 +310,7 @@ #define STR_SILVER NC_("STR_SILVER", "silver" ) #define STR_TEAL NC_("STR_TEAL", "teal" ) #define STR_YELLOW NC_("STR_YELLOW", "yellow" ) +#define STR_RGB NC_("STR_RGB", "rgb" ) #define STR_HIDE NC_("STR_HIDE", "hide" ) #define STR_SIZE NC_("STR_SIZE", "size" ) #define STR_FONT NC_("STR_FONT", "font" ) diff --git a/starmath/inc/strings.hxx b/starmath/inc/strings.hxx index ba7826a3dd75..bedd9534716d 100644 --- a/starmath/inc/strings.hxx +++ b/starmath/inc/strings.hxx @@ -182,6 +182,7 @@ #define RID_COLORX_SILVER "color silver {<?>} " #define RID_COLORX_TEAL "color teal {<?>} " #define RID_COLORX_YELLOW "color yellow {<?>} " +#define RID_COLORX_RGB "color rgb 0 0 0 {<?>} " #define RID_LRGROUPX "{<?>} " #define RID_LRPARENTX "(<?>) " #define RID_LRBRACKETX "[<?>] " @@ -229,6 +230,7 @@ #define RID_PARTIAL "partial " #define RID_NABLA "nabla " #define RID_WP "wp " +#define RID_LAPLACE "laplace " #define RID_DOTSAXIS "dotsaxis " #define RID_DOTSUP "dotsup " #define RID_DOTSDOWN "dotsdown " diff --git a/starmath/inc/token.hxx b/starmath/inc/token.hxx index 1bbe446fcca2..cdc91ddf4838 100644 --- a/starmath/inc/token.hxx +++ b/starmath/inc/token.hxx @@ -44,6 +44,7 @@ enum class TG { Limit = 0x010000, FontAttr = 0x020000 }; + namespace o3tl { template<> struct typed_flags<TG> : is_typed_flags<TG, 0x037fff> {}; } @@ -100,7 +101,8 @@ enum SmTokenType TUNKNOWN, TPRECEDES, TSUCCEEDS, TPRECEDESEQUAL, TSUCCEEDSEQUAL, TPRECEDESEQUIV, TSUCCEEDSEQUIV, TNOTPRECEDES, TNOTSUCCEEDS, TSILVER, TGRAY, TMAROON, TPURPLE, TLIME, TOLIVE, - TNAVY, TTEAL, TAQUA, TFUCHSIA, TINTD + TNAVY, TTEAL, TAQUA, TFUCHSIA, TINTD, + TRGB, TLAPLACE }; struct SmToken diff --git a/starmath/inc/types.hxx b/starmath/inc/types.hxx index 5680e907c6e7..044b2fab05d1 100644 --- a/starmath/inc/types.hxx +++ b/starmath/inc/types.hxx @@ -78,6 +78,7 @@ sal_Unicode const MS_DEF = 0x225D; sal_Unicode const MS_EQUIV = 0x2261; sal_Unicode const MS_PROP = 0x221D; sal_Unicode const MS_PARTIAL = 0x2202; +sal_Unicode const MS_LAPLACE = 0x2112; sal_Unicode const MS_SUBSET = 0x2282; sal_Unicode const MS_SUPSET = 0x2283; @@ -179,6 +180,7 @@ sal_Unicode const MS_LEFTARROW = 0x2190; sal_Unicode const MS_UPARROW = 0x2191; sal_Unicode const MS_RIGHTARROW = 0x2192; sal_Unicode const MS_DOWNARROW = 0x2193; + sal_Unicode const MS_SETN = 0x2115; sal_Unicode const MS_SETZ = 0x2124; sal_Unicode const MS_SETQ = 0x211A; 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 6238416a6bda..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 diff --git a/starmath/uiconfig/smath/popupmenu/edit.xml b/starmath/uiconfig/smath/popupmenu/edit.xml index 85a90675a703..f5a7f0680d6c 100644 --- a/starmath/uiconfig/smath/popupmenu/edit.xml +++ b/starmath/uiconfig/smath/popupmenu/edit.xml @@ -183,6 +183,7 @@ <menu:menuitem menu:label="ital b" menu:id=".uno:InsertCommandText?Text:string=ital <?> "/> <menu:menuitem menu:label="size s b" menu:id=".uno:InsertCommandText?Text:string=size <?> {<?>} "/> <menu:menuitem menu:label="font f b" menu:id=".uno:InsertCommandText?Text:string=font <?> {<?>} "/> + <menu:menuitem menu:label="color rgb" menu:id=".uno:InsertCommandText?Text:string=color rgb 0 0 0 "/> </menu:menupopup> </menu:menu> <menu:menu menu:id=".uno:BracketsMenu"> @@ -251,6 +252,7 @@ <menu:menuitem menu:label="Re" menu:id=".uno:InsertCommandText?Text:string=Re "/> <menu:menuitem menu:label="Im" menu:id=".uno:InsertCommandText?Text:string=Im "/> <menu:menuitem menu:label="wp" menu:id=".uno:InsertCommandText?Text:string=wp "/> + <menu:menuitem menu:label="laplace" menu:id=".uno:InsertCommandText?Text:string=laplace "/> <menu:menuseparator/> <menu:menuitem menu:label="leftarrow" menu:id=".uno:InsertCommandText?Text:string=leftarrow "/> <menu:menuitem menu:label="rightarrow" menu:id=".uno:InsertCommandText?Text:string=rightarrow "/> |