tdf#40436 tdf#47914 RGB personalized color for math and laplace symbol 2

Change-Id: Id0791609ada5b9f5460e46b20cfc7ce600cd3043
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96890
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
dante 2020-06-22 17:22:49 +02:00 committed by Noel Grandin
parent 3dcf7a3d22
commit e7fee907fa
9 changed files with 103 additions and 27 deletions

View File

@ -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" )

View File

@ -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 "

View File

@ -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

View File

@ -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;

View File

@ -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)

View File

@ -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(" ");

View File

@ -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;
}
}

View File

@ -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

View File

@ -183,6 +183,7 @@
<menu:menuitem menu:label="ital b" menu:id=".uno:InsertCommandText?Text:string=ital &lt;?&gt; "/>
<menu:menuitem menu:label="size s b" menu:id=".uno:InsertCommandText?Text:string=size &lt;?&gt; {&lt;?&gt;} "/>
<menu:menuitem menu:label="font f b" menu:id=".uno:InsertCommandText?Text:string=font &lt;?&gt; {&lt;?&gt;} "/>
<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 "/>