summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordante <dante19031999@gmail.com>2020-11-08 14:32:57 +0100
committerNoel Grandin <noel.grandin@collabora.co.uk>2020-11-11 06:51:22 +0100
commitf3b52717e85621d3b4ee1c6d69700e2a0cca8efc (patch)
treeaa4df032b1ab661ad19b3ebc2e8e2c59babb4b07
parent3d90997fb6f232d8008df4d166d7b97b869c200f (diff)
Improved starmath color
Color.hxx has now documentation ( even if it is quite obvious if you know RGB standar ). Color.hxx has been reordered in more coherent order, but kept format. Some changes on Color.hxx dynamics. Color.hxx starmath colors list Now colors are managed by starmathdatabse. The path is open for simple addition of colors, there are no more infinite switches with color tokens here and there. To add a color, just put it in Color.hxx and register it in starmathdatabse.cxx. Do not forget to change array size in starmathdatabase.hxx. Now mathml supports RGB colors in #RRGGBB format ( import and export ). New colors have been added. Only the HTML Css1 are available via UI. New colors will be added. I intend to finish Css2 and dvipsnames ( latex colors ) on posterior patches. RGBA command has been unlocked for compatibility reasons. However will be displayed as RGB. Added color #RRGGBB. Improved qa color test on mathml to test RGB on mathml. TODO for someone on the UI team: - Add a color picker. - If it is a color with name: - It will add in the code "color " + starmathdatabase::Identify_Color_DVIPSNAMES( colorvalue ).pIdent +" " - If not: - It will add in the code "color " + starmathdatabase::Identify_Color_DVIPSNAMES( colorvalue ).pIdent +" "+ colorvalue.getRed() +" "+ colorvalue.getGreen() +" "+ colorvalue.getBlue() +" " - Note that those will habe eType with value TRGB or TRGBA. Change-Id: I47af37bd191b3099e8e6e08e7a5fb1a8a227bbf2 Change-Id: If971473ddcc34739439818dba9a62ca3494a4473 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105526 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--include/tools/color.hxx306
-rw-r--r--starmath/inc/starmathdatabase.hxx140
-rw-r--r--starmath/inc/strings.hrc8
-rw-r--r--starmath/inc/strings.hxx4
-rw-r--r--starmath/inc/token.hxx156
-rw-r--r--starmath/inc/types.hxx1
-rw-r--r--starmath/inc/visitors.hxx9
-rw-r--r--starmath/qa/extras/data/tdf103430.mml4
-rw-r--r--starmath/qa/extras/mmlimport-test.cxx2
-rw-r--r--starmath/source/ElementsDockingWindow.cxx10
-rw-r--r--starmath/source/mathmlexport.cxx78
-rw-r--r--starmath/source/mathmlimport.cxx57
-rw-r--r--starmath/source/mathmlimport.hxx2
-rw-r--r--starmath/source/node.cxx25
-rw-r--r--starmath/source/parse.cxx66
-rw-r--r--starmath/source/starmathdatabase.cxx139
-rw-r--r--starmath/source/visitors.cxx88
-rw-r--r--tools/source/generic/color.cxx10
-rw-r--r--vcl/source/outdev/bitmap.cxx6
-rw-r--r--vcl/source/outdev/transparent.cxx6
20 files changed, 737 insertions, 380 deletions
diff --git a/include/tools/color.hxx b/include/tools/color.hxx
index afdb30d9e02c..a41a0d454117 100644
--- a/include/tools/color.hxx
+++ b/include/tools/color.hxx
@@ -33,6 +33,11 @@ constexpr sal_uInt32 extractRGB(sal_uInt32 nColorNumber)
return nColorNumber & 0x00FFFFFF;
}
+constexpr sal_uInt8 ColorChannelMerge(sal_uInt8 nDst, sal_uInt8 nSrc, sal_uInt8 nSrcTrans)
+{
+ return sal_uInt8(((sal_Int32(nDst) - nSrc) * nSrcTrans + ((nSrc << 8) | nDst)) >> 8);
+}
+
}
// Color
@@ -74,7 +79,7 @@ public:
{}
constexpr Color(sal_uInt8 nRed, sal_uInt8 nGreen, sal_uInt8 nBlue)
- : Color(0, nRed, nGreen, nBlue)
+ : mValue(sal_uInt32(nBlue) | (sal_uInt32(nGreen) << 8) | (sal_uInt32(nRed) << 16) | (sal_uInt32(0) << 24))
{}
// constructor to create a tools-Color from ::basegfx::BColor
@@ -85,160 +90,270 @@ public:
sal_uInt8(std::lround(rBColor.getBlue() * 255.0)))
{}
- /** Primarily used when passing Color objects to UNO API */
+ /** Casts the color to corresponding uInt32.
+ * Primarily used when passing Color objects to UNO API
+ * @return corresponding sal_uInt32
+ */
constexpr explicit operator sal_uInt32() const
{
return mValue;
}
+ /** Casts the color to corresponding iInt32.
+ * If there is no transparency, will be positive.
+ * @return corresponding sal_Int32
+ */
constexpr explicit operator sal_Int32() const
{
return sal_Int32(mValue);
}
- bool operator<(const Color& aCompareColor) const
- {
- return mValue < aCompareColor.mValue;
- }
+ /* Basic RGBA operations */
- void SetRed(sal_uInt8 nRed);
+ /** Gets the red value.
+ * @return R
+ */
sal_uInt8 GetRed() const
{
return R;
}
- void SetGreen(sal_uInt8 nGreen);
+
+ /** Gets the green value.
+ * @return G
+ */
sal_uInt8 GetGreen() const
{
return G;
}
- void SetBlue(sal_uInt8 nBlue);
+
+ /** Gets the blue value.
+ * @return B
+ */
sal_uInt8 GetBlue() const
{
return B;
}
- void SetTransparency(sal_uInt8 nTransparency);
+
+ /** Gets the transparency value.
+ * @return A
+ */
sal_uInt8 GetTransparency() const
{
return A;
}
- Color GetRGBColor() const
+ /** Sets the red value.
+ * @param nRed
+ */
+ void SetRed(sal_uInt8 nRed)
{
- return color::extractRGB(mValue);
+ R = nRed;
}
- sal_uInt16 GetColorError(const Color& rCompareColor) const;
-
- sal_uInt8 GetLuminance() const;
- void IncreaseLuminance(sal_uInt8 cLumInc);
- void DecreaseLuminance(sal_uInt8 cLumDec);
+ /** Sets the green value.
+ * @param nGreen
+ */
+ void SetGreen(sal_uInt8 nGreen)
+ {
+ G = nGreen;
+ }
- void DecreaseContrast(sal_uInt8 cContDec);
+ /** Sets the blue value.
+ * @param nBlue
+ */
+ void SetBlue(sal_uInt8 nBlue)
+ {
+ B = nBlue;
+ }
- /**
- * Apply tint or shade to a color.
- *
- * The input value is the percentage (in 100th of percent) of how much the
- * color changes towards the black (shade) or white (tint). If the value
- * is positive, the color is tinted, if the value is negative, the color is
- * shaded.
- **/
- void ApplyTintOrShade(sal_Int16 n100thPercent);
+ /** Sets the transparency value.
+ * @param nTransparency
+ */
+ void SetTransparency(sal_uInt8 nTransparency)
+ {
+ A = nTransparency;
+ }
- void Invert();
+ /** Returns the same color but ignoring the transparency value.
+ * @return RGB version
+ */
+ Color GetRGBColor() const
+ {
+ return mValue & 0x00FFFFFF;
+ }
- void Merge(const Color& rMergeColor, sal_uInt8 cTransparency);
+ /* Comparation and operators */
- bool IsRGBEqual(const Color& rColor) const;
+ /** Check if the color RGB value is equal than rColor.
+ * @param rColor
+ * @return is equal
+ */
+ bool IsRGBEqual( const Color& rColor ) const
+ {
+ return ( mValue & 0x00FFFFFF ) == ( rColor.mValue & 0x00FFFFFF );
+ }
- // comparison with luminance thresholds
- bool IsDark() const;
- bool IsBright() const;
+ /** Check if the color value is lower than aCompareColor.
+ * @param aCompareColor
+ * @return is lower
+ */
+ bool operator<(const Color& aCompareColor) const
+ {
+ return mValue < aCompareColor.mValue;
+ }
- // color space conversion tools
- // the range for h/s/b is:
- // Hue: 0-360 degree
- // Saturation: 0-100%
- // Brightness: 0-100%
- static Color HSBtoRGB(sal_uInt16 nHue, sal_uInt16 nSaturation, sal_uInt16 nBrightness);
- void RGBtoHSB(sal_uInt16& nHue, sal_uInt16& nSaturation, sal_uInt16& nBrightness) const;
+ /** Check if the color value is greater than aCompareColor.
+ * @param aCompareColor
+ * @return is greater
+ */
+ bool operator>(const Color& aCompareColor) const
+ {
+ return mValue > aCompareColor.mValue;
+ }
+ /** Check if the color value is equal than rColor.
+ * @param rColor
+ * @return is equal
+ */
bool operator==(const Color& rColor) const
{
return mValue == rColor.mValue;
}
+
+ /** Check if the color value is unequal than rColor.
+ * @param rColor
+ * @return is unequal
+ */
bool operator!=(const Color& rColor) const
{
- return !(Color::operator==(rColor));
+ return mValue != rColor.mValue;
}
- // Return color as RGB hex string
- // for example "00ff00" for green color
- OUString AsRGBHexString() const;
+ /** Gets the color error compared to another.
+ * It describes how different they are.
+ * It takes the abs of differences in parameters.
+ * @param rCompareColor
+ * @return error
+ */
+ sal_uInt16 GetColorError(const Color& rCompareColor) const
+ {
+ return static_cast<sal_uInt16>(
+ abs(static_cast<int>(GetBlue()) - rCompareColor.GetBlue()) +
+ abs(static_cast<int>(GetGreen()) - rCompareColor.GetGreen()) +
+ abs(static_cast<int>(GetRed()) - rCompareColor.GetRed()));
+ }
- // get ::basegfx::BColor from this color
- basegfx::BColor getBColor() const
+ /* Light and contrast */
+
+ /** Gets the color luminance. It means perceived brightness.
+ * @return luminance
+ */
+ sal_uInt8 GetLuminance() const
{
- return basegfx::BColor(GetRed() / 255.0, GetGreen() / 255.0, GetBlue() / 255.0);
+ return sal_uInt8((B * 29UL + G * 151UL + R * 76UL) >> 8);
}
-};
-inline void Color::SetRed( sal_uInt8 nRed )
-{
- R = nRed;
-}
+ /** Increases the color luminance by cLumInc.
+ * @param cLumInc
+ */
+ void IncreaseLuminance(sal_uInt8 cLumInc);
-inline void Color::SetGreen( sal_uInt8 nGreen )
-{
- G = nGreen;
-}
+ /** Decreases the color luminance by cLumDec.
+ * @param cLumDec
+ */
+ void DecreaseLuminance(sal_uInt8 cLumDec);
-inline void Color::SetBlue( sal_uInt8 nBlue )
-{
- B = nBlue;
-}
+ /** Decreases color contrast with white by cContDec.
+ * @param cContDec
+ */
+ void DecreaseContrast(sal_uInt8 cContDec);
-inline void Color::SetTransparency( sal_uInt8 nTransparency )
-{
- A = nTransparency;
-}
+ /** Comparison with luminance thresholds.
+ * @return is dark
+ */
+ bool IsDark() const
+ {
+ return sal_uInt8((B * 29UL + G * 151UL + R * 76UL) >> 8) <= 60;
+ }
-inline bool Color::IsRGBEqual( const Color& rColor ) const
-{
- return color::extractRGB(mValue) == color::extractRGB(rColor.mValue);
-}
+ /** Comparison with luminance thresholds.
+ * @return is dark
+ */
+ bool IsBright() const
+ {
+ return sal_uInt8((B * 29UL + G * 151UL + R * 76UL) >> 8) >= 245;
+ }
-inline sal_uInt8 Color::GetLuminance() const
-{
- return sal_uInt8((B * 29UL + G * 151UL + R * 76UL) >> 8);
-}
+ /* Color filters */
-constexpr sal_uInt8 ColorChannelMerge(sal_uInt8 nDst, sal_uInt8 nSrc, sal_uInt8 nSrcTrans)
-{
- return sal_uInt8(((sal_Int32(nDst) - nSrc) * nSrcTrans + ((nSrc << 8) | nDst)) >> 8);
-}
+ /**
+ * Apply tint or shade to a color.
+ *
+ * The input value is the percentage (in 100th of percent) of how much the
+ * color changes towards the black (shade) or white (tint). If the value
+ * is positive, the color is tinted, if the value is negative, the color is
+ * shaded.
+ **/
+ void ApplyTintOrShade(sal_Int16 n100thPercent);
-inline void Color::Invert()
-{
- R = ~R;
- G = ~G;
- B = ~B;
-}
+ /** Inverts color. 1 and 0 are switched.
+ * Note that the result will be the complementary color.
+ * For example, if you have red, you will get cyan: FF0000 -> 00FFFF.
+ */
+ void Invert()
+ {
+ R = ~R;
+ G = ~G;
+ B = ~B;
+ }
-inline sal_uInt16 Color::GetColorError( const Color& rColor ) const
-{
- return static_cast<sal_uInt16>(
- abs(static_cast<int>(GetBlue()) - rColor.GetBlue()) +
- abs(static_cast<int>(GetGreen()) - rColor.GetGreen()) +
- abs(static_cast<int>(GetRed()) - rColor.GetRed()));
-}
+ /** Merges color with rMergeColor.
+ * Allows to get resulting color when supperposing another.
+ * @param rMergeColor
+ * @param cTransparency
+ */
+ void Merge(const Color& rMergeColor, sal_uInt8 cTransparency)
+ {
+ R = color::ColorChannelMerge(R, rMergeColor.R, cTransparency);
+ G = color::ColorChannelMerge(G, rMergeColor.G, cTransparency);
+ B = color::ColorChannelMerge(B, rMergeColor.B, cTransparency);
+ }
-inline void Color::Merge( const Color& rMergeColor, sal_uInt8 cTransparency )
-{
- R = ColorChannelMerge(R, rMergeColor.R, cTransparency);
- G = ColorChannelMerge(G, rMergeColor.G, cTransparency);
- B = ColorChannelMerge(B, rMergeColor.B, cTransparency);
-}
+ /* Change of format */
+
+ /** Color space conversion tools
+ * The range for h/s/b is:
+ * - Hue: 0-360 degree
+ * - Saturation: 0-100%
+ * - Brightness: 0-100%
+ * @param nHue
+ * @param nSaturation
+ * @param nBrightness
+ * @return rgb color
+ */
+ static Color HSBtoRGB(sal_uInt16 nHue, sal_uInt16 nSaturation, sal_uInt16 nBrightness);
+
+ /** Color space conversion tools
+ * @param nHue
+ * @param nSaturation
+ * @param nBrightness
+ */
+ void RGBtoHSB(sal_uInt16& nHue, sal_uInt16& nSaturation, sal_uInt16& nBrightness) const;
+
+ /* Return color as RGB hex string
+ * for example "00ff00" for green color
+ * @return hex string
+ */
+ OUString AsRGBHexString() const;
+
+ /* get ::basegfx::BColor from this color
+ * @return basegfx color
+ */
+ basegfx::BColor getBColor() const
+ {
+ return basegfx::BColor(R / 255.0, G / 255.0, B / 255.0);
+ }
+};
// to reduce the noise when moving these into and out of Any
inline bool operator >>=( const css::uno::Any & rAny, Color & value )
@@ -254,6 +369,7 @@ inline void operator <<=( css::uno::Any & rAny, Color value )
{
rAny <<= sal_Int32(value);
}
+
namespace com::sun::star::uno {
template<>
inline Any makeAny( Color const & value )
diff --git a/starmath/inc/starmathdatabase.hxx b/starmath/inc/starmathdatabase.hxx
index 999b983f06b3..31e7f4651285 100644
--- a/starmath/inc/starmathdatabase.hxx
+++ b/starmath/inc/starmathdatabase.hxx
@@ -18,39 +18,137 @@
*/
#include "token.hxx"
-#include "types.hxx"
+
+// Starmath color types
+// In order to add them to starmath, edit the SmColorTokenTableEntry lists on
+// /core/starmath/source/starmathdatabase.css .
+
+// HTML
+// https://developer.mozilla.org/en-US/docs/Web/CSS/color_value#Color_Keywords
+/* CSS Level 1 */
+constexpr Color COL_SM_BLACK(0x000000);
+constexpr Color COL_SM_SILVER(0xC0C0C0);
+constexpr Color COL_SM_GRAY(0x808080);
+constexpr Color COL_SM_WHITE(0xFFFFFF);
+constexpr Color COL_SM_MAROON(0x800000);
+constexpr Color COL_SM_RED(0xFF0000);
+constexpr Color COL_SM_PURPLE(0x800080);
+constexpr Color COL_SM_FUCHSIA(0xFF00FF);
+constexpr Color COL_SM_GREEN(0x008000);
+constexpr Color COL_SM_LIME(0x00FF00);
+constexpr Color COL_SM_OLIVE(0x808000);
+constexpr Color COL_SM_YELLOW(0xFFFF00);
+constexpr Color COL_SM_NAVY(0x000080);
+constexpr Color COL_SM_BLUE(0x0000FF);
+constexpr Color COL_SM_TEAL(0x008080);
+constexpr Color COL_SM_AQUA(0x00FFFF);
+/* CSS Level 2 */
+// TODO
+/* CSS Level 3 */
+// TODO
+/* CSS Level 4 */
+constexpr Color COL_SM_REBECCAPURPLE(0x663399);
+/* dvipsnames */
+// For now only five colors.
+// In a future all of them.
+// https://www.overleaf.com/learn/latex/Using_colours_in_LaTeX
+constexpr Color COL_SM_DIV_APRICOT(0xFFB781);
+constexpr Color COL_SM_DIV_AQUAMARINE(0x1BBEC1);
+constexpr Color COL_SM_DIV_BITTERSWEET(0xCF4B16);
+constexpr Color COL_SM_DIV_BLACK(0xCF4B16);
+constexpr Color COL_SM_DIV_BLUE(0x102694);
+/* Iconic colors */
+// https://design.ubuntu.com/brand/colour-palette/
+constexpr Color COL_SM_UBUNTU_ORANGE(0xE95420);
+// https://www.debian.org/logos/ Picked from SVG logo
+constexpr Color COL_SM_DEBIAN_MAGENTA(0xA80030);
+// https://libreoffice.org/
+constexpr Color COL_SM_LO_GREEN(0x00A500);
namespace starmathdatabase
{
+// Variables containing color information.
+extern const SmColorTokenTableEntry aColorTokenTableParse[31];
+extern const SmColorTokenTableEntry aColorTokenTableHTML[20];
+extern const SmColorTokenTableEntry aColorTokenTableDVIPSNAMES[5];
+
/**
- * Identifies operator chars tokens for importing mathml.
- * Identifies from char cChar
- * @param cChar
- * @return closing fences' token
- */
+ * Identifies operator chars tokens for importing mathml.
+ * Identifies from char cChar
+ * @param cChar
+ * @return closing fences' token
+ */
SmToken Identify_SmXMLOperatorContext_Impl(sal_Unicode cChar, bool bIsStretchy = true);
/**
- * Identifies opening / closing brace tokens for importing mathml.
- * Identifies from char cChar
- * @param cChar
- * @return closing fences' token
- */
+ * Identifies opening / closing brace tokens for importing mathml.
+ * Identifies from char cChar
+ * @param cChar
+ * @return closing fences' token
+ */
SmToken Identify_PrefixPostfix_SmXMLOperatorContext_Impl(sal_Unicode cChar);
/**
- * Identifies opening brace tokens for importing mathml.
- * Identifies from char cChar
- * @param cChar
- * @return closing fences' token
- */
+ * Identifies opening brace tokens for importing mathml.
+ * Identifies from char cChar
+ * @param cChar
+ * @return closing fences' token
+ */
SmToken Identify_Prefix_SmXMLOperatorContext_Impl(sal_Unicode cChar);
/**
- * Identifies closing brace tokens for importing mathml.
- * Identifies from char cChar
- * @param cChar
- * @return closing fences' token
- */
+ * Identifies closing brace tokens for importing mathml.
+ * Identifies from char cChar
+ * @param cChar
+ * @return closing fences' token
+ */
SmToken Identify_Postfix_SmXMLOperatorContext_Impl(sal_Unicode cChar);
+
+/**
+ * Identifies color from color code cColor.
+ * It will be returned with the parser syntax.
+ * @param cColor
+ * @param parser color
+ */
+std::unique_ptr<SmColorTokenTableEntry> Identify_Color_Parser(sal_uInt32 cColor);
+
+/**
+ * Identifies color from color code cColor.
+ * It will be returned with the HTML syntax.
+ * @param cColor
+ * @param parser color
+ */
+std::unique_ptr<SmColorTokenTableEntry> Identify_Color_HTML(sal_uInt32 cColor);
+
+/**
+ * Identifies color from color code cColor.
+ * It will be returned with the dvipsnames syntax.
+ * @param cColor
+ * @param parser color
+ */
+std::unique_ptr<SmColorTokenTableEntry> Identify_Color_DVIPSNAMES(sal_uInt32 cColor);
+
+/**
+ * Identifies color from color name.
+ * It will be returned with the parser syntax.
+ * @param cColor
+ * @param parser color
+ */
+std::unique_ptr<SmColorTokenTableEntry> Identify_ColorName_Parser(const OUString& colorname);
+
+/**
+ * Identifies color from color name.
+ * It will be returned with the HTML syntax.
+ * @param cColor
+ * @param parser color
+ */
+std::unique_ptr<SmColorTokenTableEntry> Identify_ColorName_HTML(const OUString& colorname);
+
+/**
+ * Identifies color from color name.
+ * It will be returned with the dvipsnames syntax.
+ * @param cColor
+ * @param parser color
+ */
+std::unique_ptr<SmColorTokenTableEntry> Identify_ColorName_DVIPSNAMES(const OUString& colorname);
}
diff --git a/starmath/inc/strings.hrc b/starmath/inc/strings.hrc
index fb9fecc8e4b5..c93de7c026d1 100644
--- a/starmath/inc/strings.hrc
+++ b/starmath/inc/strings.hrc
@@ -191,8 +191,8 @@
#define RID_COLORX_BLUE_HELP NC_("RID_COLORX_BLUE_HELP", "Color Blue" )
#define RID_COLORX_GREEN_HELP NC_("RID_COLORX_GREEN_HELP", "Color Green" )
#define RID_COLORX_RED_HELP NC_("RID_COLORX_RED_HELP", "Color Red" )
-#define RID_COLORX_CYAN_HELP NC_("RID_COLORX_CYAN_HELP", "Color Cyan" )
-#define RID_COLORX_MAGENTA_HELP NC_("RID_COLORX_MAGENTA_HELP", "Color Magenta" )
+#define RID_COLORX_AQUA_HELP NC_("RID_COLORX_AQUA_HELP", "Color Aqua" )
+#define RID_COLORX_FUCHSIA_HELP NC_("RID_COLORX_FUCHSIA_HELP", "Color Fuchsia" )
#define RID_COLORX_GRAY_HELP NC_("RID_COLORX_GRAY_HELP", "Color Gray" )
#define RID_COLORX_LIME_HELP NC_("RID_COLORX_LIME_HELP", "Color Lime" )
#define RID_COLORX_MAROON_HELP NC_("RID_COLORX_MAROON_HELP", "Color Maroon" )
@@ -326,8 +326,8 @@
#define STR_BLUE NC_("STR_BLUE", "blue" )
#define STR_GREEN NC_("STR_GREEN", "green" )
#define STR_RED NC_("STR_RED", "red" )
-#define STR_CYAN NC_("STR_CYAN", "cyan" )
-#define STR_MAGENTA NC_("STR_MAGENTA", "magenta" )
+#define STR_AQUA NC_("STR_AQUA", "aqua" )
+#define STR_FUCHSIA NC_("STR_FUCHSIA", "fuchsia" )
#define STR_GRAY NC_("STR_GRAY", "gray" )
#define STR_LIME NC_("STR_LIME", "lime" )
#define STR_MAROON NC_("STR_MAROON", "maroon" )
diff --git a/starmath/inc/strings.hxx b/starmath/inc/strings.hxx
index 004e55a8f170..fe537df552b6 100644
--- a/starmath/inc/strings.hxx
+++ b/starmath/inc/strings.hxx
@@ -183,8 +183,8 @@
#define RID_COLORX_BLUE "color blue {<?>} "
#define RID_COLORX_GREEN "color green {<?>} "
#define RID_COLORX_RED "color red {<?>} "
-#define RID_COLORX_CYAN "color cyan {<?>} "
-#define RID_COLORX_MAGENTA "color magenta {<?>} "
+#define RID_COLORX_AQUA "color aqua {<?>} "
+#define RID_COLORX_FUCHSIA "color fuchsia {<?>} "
#define RID_COLORX_GRAY "color gray {<?>} "
#define RID_COLORX_LIME "color lime {<?>} "
#define RID_COLORX_MAROON "color maroon {<?>} "
diff --git a/starmath/inc/token.hxx b/starmath/inc/token.hxx
index d5f90abcada4..0c3788fd8966 100644
--- a/starmath/inc/token.hxx
+++ b/starmath/inc/token.hxx
@@ -30,8 +30,10 @@
#define INCLUDED_STARMATH_INC_TOKEN_HXX
#include <sal/types.h>
+#include "types.hxx"
#include <rtl/ustring.hxx>
#include <o3tl/typed_flags_set.hxx>
+#include <tools/color.hxx>
// TokenGroups
enum class TG {
@@ -135,11 +137,91 @@ enum SmTokenType
TASINH, TACOSH, TATANH, TACOTH, // Arctrigo hyperbolic
TSQRT, TNROOT, TFACT, TABS, // roots, n! |z|
// Color
- TRGB, TRGBA, THEX,
- TAQUA, TBLACK, TBLUE, TCYAN, TFUCHSIA,
- TGRAY, TGREEN, TLIME, TMAGENTA, TMAROON,
- TNAVY, TOLIVE, TPURPLE, TRED, TSILVER,
- TTEAL, TWHITE, TYELLOW
+ TRGB, TRGBA, THEX, THTMLCOL, TDVIPSNAMESCOL,
+ TICONICCOL
+};
+
+struct SmTokenTableEntry
+{
+ const char* pIdent;
+ SmTokenType eType;
+ sal_Unicode cMathChar;
+ TG nGroup;
+ sal_uInt16 nLevel;
+};
+
+struct SmColorTokenTableEntry
+{
+ const char* pIdent;
+ const char* cIdent;
+ SmTokenType eType;
+ Color cColor;
+
+ SmColorTokenTableEntry()
+ : pIdent("")
+ , cIdent("")
+ , eType(TERROR)
+ , cColor()
+ {}
+
+ SmColorTokenTableEntry( const SmColorTokenTableEntry * amColorTokenTableEntry )
+ : pIdent(amColorTokenTableEntry->pIdent)
+ , cIdent(amColorTokenTableEntry->cIdent)
+ , eType(amColorTokenTableEntry->eType)
+ , cColor(amColorTokenTableEntry->cColor)
+ {}
+
+ SmColorTokenTableEntry( const std::unique_ptr<SmColorTokenTableEntry> amColorTokenTableEntry )
+ : pIdent(amColorTokenTableEntry->pIdent)
+ , cIdent(amColorTokenTableEntry->cIdent)
+ , eType(amColorTokenTableEntry->eType)
+ , cColor(amColorTokenTableEntry->cColor)
+ {}
+
+ SmColorTokenTableEntry( const char* name, const char* codename, SmTokenType ctype, Color ncolor)
+ : pIdent(name)
+ , cIdent(codename)
+ , eType(ctype)
+ , cColor(ncolor)
+ {}
+
+ SmColorTokenTableEntry( const char* name, const char* codename, SmTokenType ctype, sal_uInt32 ncolor)
+ : pIdent(name)
+ , cIdent(codename)
+ , eType(ctype)
+ , cColor(ncolor)
+ {}
+
+ bool operator == ( const OUString & colorname ) const
+ {
+ return colorname.compareToIgnoreAsciiCaseAscii( pIdent ) == 0;
+ }
+
+ bool operator == ( sal_uInt32 colorcode ) const
+ {
+ return colorcode == cColor.mValue;
+ }
+
+ bool operator == ( Color colorcode ) const
+ {
+ return colorcode == cColor;
+ }
+
+ bool equals( const OUString & colorname ) const
+ {
+ return colorname.compareToIgnoreAsciiCaseAscii( pIdent ) == 0;
+ }
+
+ bool equals( sal_uInt32 colorcode ) const
+ {
+ return colorcode == cColor.mValue;
+ }
+
+ bool equals( Color colorcode ) const
+ {
+ return colorcode == cColor;
+ }
+
};
struct SmToken
@@ -177,15 +259,63 @@ struct SmToken
, nLevel(nTokenLevel)
, nRow(0)
, nCol(0){}
-};
-struct SmTokenTableEntry
-{
- const char* pIdent;
- SmTokenType eType;
- sal_Unicode cMathChar;
- TG nGroup;
- sal_uInt16 nLevel;
+ void operator = (const SmTokenTableEntry & aTokenTableEntry)
+ {
+ aText = OUString::createFromAscii(aTokenTableEntry.pIdent);
+ eType = aTokenTableEntry.eType;
+ cMathChar = aTokenTableEntry.cMathChar;
+ nGroup = aTokenTableEntry.nGroup;
+ nLevel = aTokenTableEntry.nLevel;
+ nRow = 0;
+ nCol = 0;
+ }
+
+ void operator = (const SmTokenTableEntry * aTokenTableEntry)
+ {
+ aText = OUString::createFromAscii(aTokenTableEntry->pIdent);
+ eType = aTokenTableEntry->eType;
+ cMathChar = aTokenTableEntry->cMathChar;
+ nGroup = aTokenTableEntry->nGroup;
+ nLevel = aTokenTableEntry->nLevel;
+ nRow = 0;
+ nCol = 0;
+ }
+
+ void operator = (const SmColorTokenTableEntry & aTokenTableEntry)
+ {
+ aText = OUString::number(aTokenTableEntry.cColor.mValue, 16);
+ eType = aTokenTableEntry.eType;
+ cMathChar = MS_NULLCHAR;
+ nGroup = TG::Color;
+ nLevel = 0;
+ nRow = 0;
+ nCol = 0;
+ }
+
+ void operator = (const SmColorTokenTableEntry * aTokenTableEntry)
+ {
+ aText = OUString::number(aTokenTableEntry->cColor.mValue, 16);
+ eType = aTokenTableEntry->eType;
+ cMathChar = MS_NULLCHAR;
+ nGroup = TG::Color;
+ nLevel = 0;
+ nRow = 0;
+ nCol = 0;
+ }
+
+ void operator = (const std::unique_ptr<SmColorTokenTableEntry> & aTokenTableEntry)
+ {
+ aText = OUString::number(aTokenTableEntry->cColor.mValue, 16);
+ eType = aTokenTableEntry->eType;
+ cMathChar = MS_NULLCHAR;
+ nGroup = TG::Color;
+ nLevel = 0;
+ nRow = 0;
+ nCol = 0;
+ }
+
+
};
#endif
diff --git a/starmath/inc/types.hxx b/starmath/inc/types.hxx
index 6efd585fb28d..56be51ee92b0 100644
--- a/starmath/inc/types.hxx
+++ b/starmath/inc/types.hxx
@@ -33,6 +33,7 @@ enum SmPrintSize { PRINT_SIZE_NORMAL, PRINT_SIZE_SCALED, PRINT_SIZE_ZOOMED };
//! (see %alpha ... %gamma for example)
sal_Unicode const MS_NONE = '\0';
+sal_Unicode const MS_NULLCHAR = '\0';
sal_Unicode const MS_FACT = 0x0021;
sal_Unicode const MS_INFINITY = 0x221E;
sal_Unicode const MS_SLASH = 0x002F;
diff --git a/starmath/inc/visitors.hxx b/starmath/inc/visitors.hxx
index 4d3c4decae23..ff9ca79261ec 100644
--- a/starmath/inc/visitors.hxx
+++ b/starmath/inc/visitors.hxx
@@ -473,6 +473,15 @@ private:
}
/**
+ * Appends rText to the OUStringBuffer ( maCmdText ).
+ * @param rText
+ * @return
+ */
+ void Append( const char* rText ) {
+ maCmdText.append( OUString::createFromAscii(rText) );
+ }
+
+ /**
* Append a blank for separation, if needed.
* It is needed if last char is not ' '.
* @return
diff --git a/starmath/qa/extras/data/tdf103430.mml b/starmath/qa/extras/data/tdf103430.mml
index 92fba05dc295..f8ea8f8d2d0c 100644
--- a/starmath/qa/extras/data/tdf103430.mml
+++ b/starmath/qa/extras/data/tdf103430.mml
@@ -8,7 +8,9 @@
<mi mathvariant="normal" mathcolor="blue">y</mi>
</mrow>
<mrow>
- <mo fontstyle="italic" fontweight="bold" mathvariant="normal" form="prefix" rspace="0">d</mo>
+ <mstyle mathcolor="#ffb781">
+ <mo fontstyle="italic" fontweight="bold" mathvariant="normal" form="prefix" rspace="0">d</mo>
+ </mstyle>
<mi fontfamily="serif" mathvariant="sans-serif-bold-italic" mathcolor="red">x</mi>
</mrow>
</mfrac>
diff --git a/starmath/qa/extras/mmlimport-test.cxx b/starmath/qa/extras/mmlimport-test.cxx
index 4b204787a3cb..80b608757618 100644
--- a/starmath/qa/extras/mmlimport-test.cxx
+++ b/starmath/qa/extras/mmlimport-test.cxx
@@ -148,7 +148,7 @@ void Test::testtdf99556()
void Test::testTdf103430()
{
loadURL(m_directories.getURLFromSrc("starmath/qa/extras/data/tdf103430.mml"));
- CPPUNIT_ASSERT_EQUAL(OUString("frac { { nitalic d ^ 2 nitalic color blue y } } { { nitalic d font sans bold italic color red x } }"),
+ CPPUNIT_ASSERT_EQUAL(OUString("frac { { nitalic d ^ 2 nitalic color blue y } } { { color apricot nitalic d font sans bold italic color red x } }"),
mxDocShell->GetText());
}
diff --git a/starmath/source/ElementsDockingWindow.cxx b/starmath/source/ElementsDockingWindow.cxx
index ab9d72343be2..63edc2c2bf56 100644
--- a/starmath/source/ElementsDockingWindow.cxx
+++ b/starmath/source/ElementsDockingWindow.cxx
@@ -185,7 +185,7 @@ const SmElementDescr SmElementsControl::m_aAttributesList[] =
{nullptr, nullptr},
{RID_COLORX_BLACK, RID_COLORX_BLACK_HELP}, {RID_COLORX_BLUE, RID_COLORX_BLUE_HELP},
{RID_COLORX_GREEN, RID_COLORX_GREEN_HELP}, {RID_COLORX_RED, RID_COLORX_RED_HELP},
- {RID_COLORX_CYAN, RID_COLORX_CYAN_HELP}, {RID_COLORX_MAGENTA, RID_COLORX_MAGENTA_HELP},
+ {RID_COLORX_AQUA, RID_COLORX_AQUA_HELP}, {RID_COLORX_FUCHSIA, RID_COLORX_FUCHSIA_HELP},
{RID_COLORX_YELLOW, RID_COLORX_YELLOW_HELP}, {RID_COLORX_GRAY, RID_COLORX_GRAY_HELP},
{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},
@@ -911,10 +911,10 @@ void SmElementsControl::addElements(const SmElementDescr aElementsArray[], sal_u
addElement(aParser, "color green { \"" + SmResId(STR_GREEN) + "\" }", aElement, SmResId(pElementHelp));
else if (aElement == RID_COLORX_RED)
addElement(aParser, "color red { \"" + SmResId(STR_RED) + "\" }", aElement, SmResId(pElementHelp));
- else if (aElement == RID_COLORX_CYAN)
- addElement(aParser, "color cyan { \"" + SmResId(STR_CYAN) + "\" }", aElement, SmResId(pElementHelp));
- else if (aElement == RID_COLORX_MAGENTA)
- addElement(aParser, "color magenta { \"" + SmResId(STR_MAGENTA) + "\" }", aElement, SmResId(pElementHelp));
+ else if (aElement == RID_COLORX_AQUA)
+ addElement(aParser, "color aqua { \"" + SmResId(STR_AQUA) + "\" }", aElement, SmResId(pElementHelp));
+ else if (aElement == RID_COLORX_FUCHSIA)
+ addElement(aParser, "color fuchsia { \"" + SmResId(STR_FUCHSIA) + "\" }", aElement, SmResId(pElementHelp));
else if (aElement == RID_COLORX_YELLOW)
addElement(aParser, "color yellow { \"" + SmResId(STR_YELLOW) + "\" }", aElement, SmResId(pElementHelp));
else if (aElement == RID_COLORX_GRAY)
diff --git a/starmath/source/mathmlexport.cxx b/starmath/source/mathmlexport.cxx
index f570ff561552..27d9d2b8696b 100644
--- a/starmath/source/mathmlexport.cxx
+++ b/starmath/source/mathmlexport.cxx
@@ -64,6 +64,7 @@
#include <document.hxx>
#include <utility.hxx>
#include "cfgitem.hxx"
+#include <starmathdatabase.hxx>
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::document;
@@ -1139,6 +1140,7 @@ void SmXMLExport::ExportFont(const SmNode *pNode, int nLevel)
int nItalic = -1; // for the following variables: -1 = yet undefined; 0 = false; 1 = true;
int nSansSerifFixed = -1;
SmTokenType eNodeType = TUNKNOWN;
+
for (;;)
{
eNodeType = pNode->GetToken().eType;
@@ -1168,64 +1170,36 @@ void SmXMLExport::ExportFont(const SmNode *pNode, int nLevel)
break;
}
+ sal_uInt32 nc;
switch (pNode->GetToken().eType)
{
case TPHANTOM:
// No attribute needed. An <mphantom> element will be used below.
break;
- case TBLACK:
- AddAttribute(XML_NAMESPACE_MATH, XML_COLOR, XML_BLACK);
- break;
- case TWHITE:
- AddAttribute(XML_NAMESPACE_MATH, XML_COLOR, XML_WHITE);
- break;
- case TRED:
- AddAttribute(XML_NAMESPACE_MATH, XML_COLOR, XML_RED);
- break;
- case TGREEN:
- AddAttribute(XML_NAMESPACE_MATH, XML_COLOR, XML_GREEN);
- break;
- case TBLUE:
- AddAttribute(XML_NAMESPACE_MATH, XML_COLOR, XML_BLUE);
- break;
- case TCYAN:
- AddAttribute(XML_NAMESPACE_MATH, XML_COLOR, XML_AQUA);
- break;
- case TMAGENTA:
- AddAttribute(XML_NAMESPACE_MATH, XML_COLOR, XML_FUCHSIA);
- break;
- case TYELLOW:
- AddAttribute(XML_NAMESPACE_MATH, XML_COLOR, XML_YELLOW);
- break;
- case TSILVER:
- AddAttribute(XML_NAMESPACE_MATH, XML_COLOR, XML_SILVER);
- break;
- case TGRAY:
- AddAttribute(XML_NAMESPACE_MATH, XML_COLOR, XML_GRAY);
- break;
- case TMAROON:
- AddAttribute(XML_NAMESPACE_MATH, XML_COLOR, XML_MAROON);
- break;
- case TOLIVE:
- AddAttribute(XML_NAMESPACE_MATH, XML_COLOR, XML_OLIVE);
- break;
- case TLIME:
- AddAttribute(XML_NAMESPACE_MATH, XML_COLOR, XML_LIME);
- break;
- case TAQUA:
- AddAttribute(XML_NAMESPACE_MATH, XML_COLOR, XML_AQUA);
- break;
- case TTEAL:
- AddAttribute(XML_NAMESPACE_MATH, XML_COLOR, XML_TEAL);
- break;
- case TNAVY:
- AddAttribute(XML_NAMESPACE_MATH, XML_COLOR, XML_NAVY);
- break;
- case TFUCHSIA:
- AddAttribute(XML_NAMESPACE_MATH, XML_COLOR, XML_FUCHSIA);
+ case THTMLCOL:
+ {
+ std::unique_ptr<SmColorTokenTableEntry> aSmColorTokenTableEntry;
+ nc = pNode->GetToken().aText.toUInt32(16);
+ aSmColorTokenTableEntry = starmathdatabase::Identify_Color_HTML( nc );
+ OUString sssStr = OUString::createFromAscii( aSmColorTokenTableEntry->cIdent );
+ AddAttribute(XML_NAMESPACE_MATH, XML_MATHCOLOR, sssStr);
+ }
break;
- case TPURPLE:
- AddAttribute(XML_NAMESPACE_MATH, XML_COLOR, XML_PURPLE);
+ case TRGB:
+ case TRGBA:
+ case THEX:
+ case TDVIPSNAMESCOL:
+ case TICONICCOL:
+ {
+ OUStringBuffer sStrBuf;
+ sStrBuf.append('#');
+ std::unique_ptr<SmColorTokenTableEntry> aSmColorTokenTableEntry;
+ nc = pNode->GetToken().aText.toUInt32(16);
+ aSmColorTokenTableEntry = starmathdatabase::Identify_Color_HTML( nc );
+ sStrBuf.append( aSmColorTokenTableEntry->cColor.AsRGBHexString() );
+ OUString ssStr(sStrBuf.makeStringAndClear());
+ AddAttribute(XML_NAMESPACE_MATH, XML_MATHCOLOR, ssStr);
+ }
break;
case TSIZE:
{
diff --git a/starmath/source/mathmlimport.cxx b/starmath/source/mathmlimport.cxx
index 587ba3ca6458..7a3ca34b9a5a 100644
--- a/starmath/source/mathmlimport.cxx
+++ b/starmath/source/mathmlimport.cxx
@@ -694,6 +694,19 @@ void SmXMLContext_Helper::ApplyAttrs()
pFontNode->SetSubNodes(nullptr, popOrZero(rNodeStack));
rNodeStack.push_front(std::move(pFontNode));
}
+ if (!sColor.isEmpty())
+ {
+ std::unique_ptr<SmColorTokenTableEntry> aSmColorTokenTableEntry;
+ aSmColorTokenTableEntry = starmathdatabase::Identify_ColorName_HTML( sColor );
+ if( aSmColorTokenTableEntry )
+ {
+ aToken = aSmColorTokenTableEntry;
+ std::unique_ptr<SmFontNode> pFontNode(new SmFontNode(aToken));
+ pFontNode->SetSubNodes(nullptr, popOrZero(rNodeStack));
+ rNodeStack.push_front(std::move(pFontNode));
+ }
+ // If not known, not implemented yet. Giving up.
+ }
if (!sFontFamily.isEmpty())
{
if (sFontFamily.equalsIgnoreAsciiCase(GetXMLToken(XML_FIXED)))
@@ -711,21 +724,6 @@ void SmXMLContext_Helper::ApplyAttrs()
pFontNode->SetSubNodes(nullptr, popOrZero(rNodeStack));
rNodeStack.push_front(std::move(pFontNode));
}
- if (sColor.isEmpty())
- return;
-
- //Again we can only handle a small set of colours in
- //StarMath for now.
- const SvXMLTokenMap& rTokenMap =
- rContext.GetSmImport().GetColorTokenMap();
- sal_uInt16 tok = rTokenMap.Get(XML_NAMESPACE_MATH, sColor);
- if (tok != XML_TOK_UNKNOWN)
- {
- aToken.eType = static_cast<SmTokenType>(tok);
- std::unique_ptr<SmFontNode> pFontNode(new SmFontNode(aToken));
- pFontNode->SetSubNodes(nullptr, popOrZero(rNodeStack));
- rNodeStack.push_front(std::move(pFontNode));
- }
}
namespace {
@@ -1980,35 +1978,6 @@ uno::Reference< xml::sax::XFastContextHandler > SAL_CALL SmXMLFlatDocContext_Imp
}
}
-const SvXMLTokenMapEntry aColorTokenMap[] =
-{
- { XML_NAMESPACE_MATH, XML_BLACK, TBLACK},
- { XML_NAMESPACE_MATH, XML_WHITE, TWHITE},
- { XML_NAMESPACE_MATH, XML_RED, TRED},
- { XML_NAMESPACE_MATH, XML_GREEN, TGREEN},
- { XML_NAMESPACE_MATH, XML_BLUE, TBLUE},
- { XML_NAMESPACE_MATH, XML_AQUA, TAQUA},
- { XML_NAMESPACE_MATH, XML_FUCHSIA, TFUCHSIA},
- { XML_NAMESPACE_MATH, XML_YELLOW, TYELLOW},
- { XML_NAMESPACE_MATH, XML_NAVY, TNAVY},
- { XML_NAMESPACE_MATH, XML_TEAL, TTEAL},
- { XML_NAMESPACE_MATH, XML_MAROON, TMAROON},
- { XML_NAMESPACE_MATH, XML_PURPLE, TPURPLE},
- { XML_NAMESPACE_MATH, XML_OLIVE, TOLIVE},
- { XML_NAMESPACE_MATH, XML_GRAY, TGRAY},
- { XML_NAMESPACE_MATH, XML_SILVER, TSILVER},
- { XML_NAMESPACE_MATH, XML_LIME, TLIME},
- XML_TOKEN_MAP_END
-};
-
-
-const SvXMLTokenMap& SmXMLImport::GetColorTokenMap()
-{
- if (!pColorTokenMap)
- pColorTokenMap.reset(new SvXMLTokenMap(aColorTokenMap));
- return *pColorTokenMap;
-}
-
uno::Reference< xml::sax::XFastContextHandler > SmXMLDocContext_Impl::createFastChildContext(
sal_Int32 nElement,
const uno::Reference<xml::sax::XFastAttributeList>& /*xAttrList*/)
diff --git a/starmath/source/mathmlimport.hxx b/starmath/source/mathmlimport.hxx
index 6789a82b7cc1..2ebaddee9ab7 100644
--- a/starmath/source/mathmlimport.hxx
+++ b/starmath/source/mathmlimport.hxx
@@ -89,8 +89,6 @@ public:
const css::uno::Reference<
css::xml::sax::XFastAttributeList >& xAttrList ) override;
- const SvXMLTokenMap &GetColorTokenMap();
-
SmNodeStack & GetNodeStack() { return aNodeStack; }
bool GetSuccess() const { return bSuccess; }
diff --git a/starmath/source/node.cxx b/starmath/source/node.cxx
index 957c91cb33c6..3c78de3ba5b0 100644
--- a/starmath/source/node.cxx
+++ b/starmath/source/node.cxx
@@ -26,6 +26,7 @@
#include "mathtype.hxx"
#include "tmpdevice.hxx"
#include <visitors.hxx>
+#include <starmathdatabase.hxx>
#include <comphelper/string.hxx>
#include <tools/color.hxx>
@@ -1626,28 +1627,14 @@ void SmFontNode::Arrange(OutputDevice &rDev, const SmFormat &rFormat)
case TNBOLD : ClearAttribut(FontAttribute::Bold); break;
case TNITALIC : ClearAttribut(FontAttribute::Italic); break;
- case TBLACK : SetColor(COL_BLACK); break;
- case TWHITE : SetColor(COL_WHITE); break;
- case TRED : SetColor(COL_LIGHTRED); break;
- case TGREEN : SetColor(COL_GREEN); break;
- case TBLUE : SetColor(COL_LIGHTBLUE); break;
- case TCYAN : SetColor(COL_LIGHTCYAN); break; // as in Calc
- case TMAGENTA : SetColor(COL_LIGHTMAGENTA); break; // as in Calc
- case TYELLOW : SetColor(COL_YELLOW); break;
- case TTEAL : SetColor(COL_CYAN); break;
- case TSILVER : SetColor(COL_LIGHTGRAY); break;
- case TGRAY : SetColor(COL_GRAY); break;
- case TMAROON : SetColor(COL_RED); break;
- case TPURPLE : SetColor(COL_MAGENTA); break;
- case TLIME : SetColor(COL_LIGHTGREEN); break;
- case TOLIVE : SetColor(COL_BROWN); break;
- case TNAVY : SetColor(COL_BLUE); break;
- case TAQUA : SetColor(COL_LIGHTCYAN); break;
- case TFUCHSIA : SetColor(COL_LIGHTMAGENTA); break;
+ // Using HTML CSS Level 1 standard
case TRGB :
case TRGBA :
+ case THTMLCOL :
+ case TDVIPSNAMESCOL:
+ case TICONICCOL :
case THEX :
- nc = GetToken().aText.toUInt32();
+ nc = GetToken().aText.toUInt32(16);
SetColor(Color(nc));
break;
diff --git a/starmath/source/parse.cxx b/starmath/source/parse.cxx
index 803f97425a6d..86864bd612b2 100644
--- a/starmath/source/parse.cxx
+++ b/starmath/source/parse.cxx
@@ -35,6 +35,7 @@
#include "cfgitem.hxx"
#include <cassert>
#include <stack>
+#include <starmathdatabase.hxx>
using namespace ::com::sun::star::i18n;
@@ -261,32 +262,6 @@ const SmTokenTableEntry aTokenTable[] =
{ "wp" , TWP, MS_WP, TG::Standalone, 5}
};
-//Definition of color keywords
-const SmTokenTableEntry aColorTokenTable[] =
-{
- { "aqua", TAQUA, '\0', TG::Color, 0},
- { "black", TBLACK, '\0', TG::Color, 0},
- { "blue", TBLUE, '\0', TG::Color, 0},
- { "cyan", TCYAN, '\0', TG::Color, 0},
- { "fuchsia", TFUCHSIA, '\0', TG::Color, 0},
- { "gray", TGRAY, '\0', TG::Color, 0},
- { "green", TGREEN, '\0', TG::Color, 0},
- { "hex" , THEX, '\0', TG::Color, 0},
- { "lime", TLIME, '\0', TG::Color, 0},
- { "magenta", TMAGENTA, '\0', TG::Color, 0},
- { "maroon", TMAROON, '\0', TG::Color, 0},
- { "navy", TNAVY, '\0', TG::Color, 0},
- { "olive", TOLIVE, '\0', TG::Color, 0},
- { "purple", TPURPLE, '\0', TG::Color, 0},
- { "red", TRED, '\0', TG::Color, 0},
- { "rgb", TRGB, '\0', TG::Color, 0},
- //{ "rgba", TRGBA, '\0', TG::Color, 0},
- { "silver", TSILVER, '\0', TG::Color, 0},
- { "teal", TTEAL, '\0', TG::Color, 0},
- { "white", TWHITE, '\0', TG::Color, 0},
- { "yellow", TYELLOW, '\0', TG::Color, 0}
-};
-
// First character may be any alphabetic
const sal_Int32 coStartFlags = KParseTokens::ANY_LETTER | KParseTokens::IGNORE_LEADING_WS;
@@ -332,18 +307,6 @@ static const SmTokenTableEntry * GetTokenTableEntry( const OUString &rName )
return nullptr; //not found
}
-//Returns the SmTokenTableEntry for a keyword
-static const SmTokenTableEntry * GetColorTokenTableEntry( const OUString &rName )
-{
- 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(aColorTokenTable),
- std::end(aColorTokenTable), rName, findCompare );
- if ( findIter != std::end(aColorTokenTable)
- && rName.equalsIgnoreAsciiCaseAscii( findIter->pIdent ))
- return &*findIter; //check is equal
- return nullptr; //not found
-}
static bool IsDelimiter( const OUString &rTxt, sal_Int32 nPos )
{ // returns 'true' iff cChar is '\0' or a delimiter
@@ -1044,16 +1007,21 @@ void SmParser::NextTokenColor()
sal_Int32 n = aRes.EndPos - nRealStart;
assert(n >= 0);
OUString aName( m_aBufferString.copy( nRealStart, n ) );
- const SmTokenTableEntry *pEntry = GetColorTokenTableEntry( aName );
- if (pEntry)
+ std::unique_ptr<SmColorTokenTableEntry> aSmColorTokenTableEntry;
+ aSmColorTokenTableEntry = starmathdatabase::Identify_ColorName_Parser( aName );
+ if ( aSmColorTokenTableEntry ) m_aCurToken = aSmColorTokenTableEntry;
+ else m_aCurToken.eType = TNONE;
+ }
+ else if (aRes.TokenType & KParseType::ONE_SINGLE_CHAR)
+ {
+ if( m_aBufferString[ nRealStart ] == '#' && !m_aBufferString.match("##", nRealStart) )
{
- m_aCurToken.eType = pEntry->eType;
- m_aCurToken.cMathChar = pEntry->cMathChar;
- m_aCurToken.nGroup = pEntry->nGroup;
- m_aCurToken.nLevel = pEntry->nLevel;
- m_aCurToken.aText = OUString::createFromAscii( pEntry->pIdent );
+ m_aCurToken.eType = THEX;
+ m_aCurToken.cMathChar = '\0';
+ m_aCurToken.nGroup = TG::Color;
+ m_aCurToken.nLevel = 0;
+ m_aCurToken.aText = "hex";
}
- else m_aCurToken.eType = TNONE;
}
else m_aCurToken.eType = TNONE;
if (TEND != m_aCurToken.eType) m_nBufferIndex = aRes.EndPos;
@@ -2142,7 +2110,7 @@ std::unique_ptr<SmStructureNode> SmParser::DoColor()
nb = m_aCurToken.aText.toUInt32();
if( nb > 255 )return DoError(SmParseError::ColorExpected);
nc = nb | ng << 8 | nr << 16 | sal_uInt32(0) << 24;
- aToken.aText = OUString::number(nc);
+ aToken.aText = OUString::number(nc, 16);
}
else if( m_aCurToken.eType == TRGBA ) //loads r, g and b
{
@@ -2168,7 +2136,7 @@ std::unique_ptr<SmStructureNode> SmParser::DoColor()
na = m_aCurToken.aText.toUInt32();
if( na > 255 )return DoError(SmParseError::ColorExpected);
nc = nb | ng << 8 | nr << 16 | na << 24;
- aToken.aText = OUString::number(nc);
+ aToken.aText = OUString::number(nc, 16);
}
else if( m_aCurToken.eType == THEX ) //loads hex code
{
@@ -2177,7 +2145,7 @@ std::unique_ptr<SmStructureNode> SmParser::DoColor()
if( lcl_IsNotWholeNumber16(m_aCurToken.aText) )
return DoError(SmParseError::ColorExpected);
nc = m_aCurToken.aText.toUInt32(16);
- aToken.aText = OUString::number(nc);
+ aToken.aText = OUString::number(nc, 16);
}
NextToken();
}
diff --git a/starmath/source/starmathdatabase.cxx b/starmath/source/starmathdatabase.cxx
index 9b1dd659bef5..ecab361f73c0 100644
--- a/starmath/source/starmathdatabase.cxx
+++ b/starmath/source/starmathdatabase.cxx
@@ -356,3 +356,142 @@ SmToken starmathdatabase::Identify_PrefixPostfix_SmXMLOperatorContext_Impl(sal_U
return SmToken(TERROR, MS_NONE, "", TG::NONE, SAL_MAX_UINT16);
}
}
+
+const SmColorTokenTableEntry starmathdatabase::aColorTokenTableParse[]
+ = { { "apricot", "Apricot", TDVIPSNAMESCOL, COL_SM_DIV_APRICOT },
+ { "aqua", "aqua", THTMLCOL, COL_SM_AQUA },
+ { "aquamarine", "Aquamarine", TDVIPSNAMESCOL, COL_SM_DIV_AQUAMARINE },
+ { "bittersweet", "Bittersweet", TDVIPSNAMESCOL, COL_SM_DIV_BITTERSWEET },
+ { "black", "black", THTMLCOL, COL_SM_BLACK },
+ { "blue", "blue", THTMLCOL, COL_SM_BLUE },
+ { "cyan", "cyan", THTMLCOL, COL_SM_BLACK },
+ { "debian", "", TICONICCOL, COL_SM_DEBIAN_MAGENTA },
+ { "dblack", "Black", TDVIPSNAMESCOL, COL_SM_BLACK },
+ { "dblue", "Blue", TDVIPSNAMESCOL, COL_SM_BLACK },
+ { "fuchsia", "fuchsia", THTMLCOL, COL_SM_FUCHSIA },
+ { "gray", "gray", THTMLCOL, COL_SM_GRAY },
+ { "green", "green", THTMLCOL, COL_SM_GREEN },
+ { "hex", "hex", THEX, COL_SM_BLACK },
+ { "lime", "lime", THTMLCOL, COL_SM_LIME },
+ { "lo", "", TICONICCOL, COL_SM_LO_GREEN },
+ { "magenta", "magenta", THTMLCOL, COL_SM_FUCHSIA },
+ { "maroon", "maroon", THTMLCOL, COL_SM_MAROON },
+ { "navy", "navy", THTMLCOL, COL_SM_NAVY },
+ { "olive", "olive", THTMLCOL, COL_SM_OLIVE },
+ { "purple", "purple", THTMLCOL, COL_SM_PURPLE },
+ { "rebeccapurple", "rebeccapurple", THTMLCOL, COL_SM_REBECCAPURPLE },
+ { "red", "red", THTMLCOL, COL_SM_RED },
+ { "rgb", "rgb", TRGB, COL_AUTO },
+ { "rgba", "rgba", TRGBA, COL_AUTO },
+ { "silver", "silver", THTMLCOL, COL_SM_SILVER },
+ { "teal", "teal", THTMLCOL, COL_SM_TEAL },
+ { "ubuntu", "", TICONICCOL, COL_SM_UBUNTU_ORANGE },
+ { "white", "white", THTMLCOL, COL_SM_WHITE },
+ { "yellow", "yellow", THTMLCOL, COL_SM_YELLOW } };
+
+const SmColorTokenTableEntry starmathdatabase::aColorTokenTableHTML[]
+ = { { "aqua", "aqua", THTMLCOL, COL_SM_AQUA },
+ { "black", "black", THTMLCOL, COL_SM_BLACK },
+ { "blue", "blue", THTMLCOL, COL_SM_BLUE },
+ { "cyan", "cyan", THTMLCOL, COL_SM_BLACK },
+ { "fuchsia", "fuchsia", THTMLCOL, COL_SM_FUCHSIA },
+ { "gray", "gray", THTMLCOL, COL_SM_GRAY },
+ { "green", "green", THTMLCOL, COL_SM_GREEN },
+ { "hex", "hex", THEX, COL_SM_BLACK },
+ { "lime", "lime", THTMLCOL, COL_SM_LIME },
+ { "magenta", "magenta", THTMLCOL, COL_SM_FUCHSIA },
+ { "maroon", "maroon", THTMLCOL, COL_SM_MAROON },
+ { "navy", "navy", THTMLCOL, COL_SM_NAVY },
+ { "olive", "olive", THTMLCOL, COL_SM_OLIVE },
+ { "purple", "purple", THTMLCOL, COL_SM_PURPLE },
+ { "rebeccapurple", "rebeccapurple", THTMLCOL, COL_SM_REBECCAPURPLE },
+ { "red", "red", THTMLCOL, COL_SM_RED },
+ { "silver", "silver", THTMLCOL, COL_SM_SILVER },
+ { "teal", "teal", THTMLCOL, COL_SM_TEAL },
+ { "white", "white", THTMLCOL, COL_SM_WHITE },
+ { "yellow", "yellow", THTMLCOL, COL_SM_YELLOW } };
+
+const SmColorTokenTableEntry starmathdatabase::aColorTokenTableDVIPSNAMES[] = {
+ { "apricot", "Apricot", TDVIPSNAMESCOL, COL_SM_DIV_APRICOT },
+ { "aquamarine", "Aquamarine", TDVIPSNAMESCOL, COL_SM_DIV_AQUAMARINE },
+ { "bittersweet", "Bittersweet", TDVIPSNAMESCOL, COL_SM_DIV_BITTERSWEET },
+ { "dblack", "Black", TDVIPSNAMESCOL, COL_SM_BLACK },
+ { "dblue", "Blue", TDVIPSNAMESCOL, COL_SM_BLACK },
+};
+
+std::unique_ptr<SmColorTokenTableEntry> starmathdatabase::Identify_Color_Parser(sal_uInt32 cColor)
+{
+ for (auto i = std::begin(aColorTokenTableParse); i < std::end(aColorTokenTableParse); ++i)
+ if (i->equals(cColor))
+ return std::unique_ptr<SmColorTokenTableEntry>(new SmColorTokenTableEntry(i));
+ if ((cColor & 0x00FFFFFF) == cColor)
+ return std::unique_ptr<SmColorTokenTableEntry>(
+ new SmColorTokenTableEntry("", "", TRGB, cColor));
+ else
+ return std::unique_ptr<SmColorTokenTableEntry>(
+ new SmColorTokenTableEntry("", "", TRGBA, cColor));
+}
+
+std::unique_ptr<SmColorTokenTableEntry> starmathdatabase::Identify_Color_HTML(sal_uInt32 cColor)
+{
+ for (auto i = std::begin(aColorTokenTableHTML); i < std::end(aColorTokenTableHTML); ++i)
+ if (i->equals(cColor))
+ return std::unique_ptr<SmColorTokenTableEntry>(new SmColorTokenTableEntry(i));
+ if ((cColor & 0x00FFFFFF) == cColor)
+ return std::unique_ptr<SmColorTokenTableEntry>(
+ new SmColorTokenTableEntry("", "", TRGB, cColor));
+ else
+ return std::unique_ptr<SmColorTokenTableEntry>(
+ new SmColorTokenTableEntry("", "", TRGBA, cColor));
+}
+
+std::unique_ptr<SmColorTokenTableEntry>
+starmathdatabase::Identify_Color_DVIPSNAMES(sal_uInt32 cColor)
+{
+ for (auto i = std::begin(aColorTokenTableDVIPSNAMES); i < std::end(aColorTokenTableDVIPSNAMES);
+ ++i)
+ if (i->equals(cColor))
+ return std::unique_ptr<SmColorTokenTableEntry>(new SmColorTokenTableEntry(i));
+ if ((cColor & 0x00FFFFFF) == cColor)
+ return std::unique_ptr<SmColorTokenTableEntry>(
+ new SmColorTokenTableEntry("", "", TRGB, cColor));
+ else
+ return std::unique_ptr<SmColorTokenTableEntry>(
+ new SmColorTokenTableEntry("", "", TRGBA, cColor));
+}
+
+std::unique_ptr<SmColorTokenTableEntry>
+starmathdatabase::Identify_ColorName_Parser(const OUString& colorname)
+{
+ if (colorname.isEmpty())
+ return nullptr;
+ for (auto i = std::begin(aColorTokenTableParse); i < std::end(aColorTokenTableParse); ++i)
+ if (i->equals(colorname))
+ return std::unique_ptr<SmColorTokenTableEntry>(new SmColorTokenTableEntry(i));
+ return nullptr;
+}
+
+std::unique_ptr<SmColorTokenTableEntry>
+starmathdatabase::Identify_ColorName_HTML(const OUString& colorname)
+{
+ if (colorname.isEmpty())
+ return nullptr;
+ for (auto i = std::begin(aColorTokenTableParse); i < std::end(aColorTokenTableParse); ++i)
+ if (i->equals(colorname))
+ return std::unique_ptr<SmColorTokenTableEntry>(new SmColorTokenTableEntry(i));
+ if (colorname[0] == '#' && colorname.getLength() == 7)
+ return std::unique_ptr<SmColorTokenTableEntry>(
+ new SmColorTokenTableEntry("", "", TRGB, colorname.copy(1, 6).toUInt32(16)));
+ return nullptr;
+}
+
+std::unique_ptr<SmColorTokenTableEntry>
+starmathdatabase::Identify_ColorName_DVIPSNAMES(const OUString& colorname)
+{
+ if (colorname.isEmpty())
+ return nullptr;
+ for (auto i = std::begin(aColorTokenTableParse); i < std::end(aColorTokenTableParse); ++i)
+ if (i->equals(colorname))
+ return std::unique_ptr<SmColorTokenTableEntry>(new SmColorTokenTableEntry(i));
+ return nullptr;
+}
diff --git a/starmath/source/visitors.cxx b/starmath/source/visitors.cxx
index 08f9d33e024f..924690282e42 100644
--- a/starmath/source/visitors.cxx
+++ b/starmath/source/visitors.cxx
@@ -16,6 +16,7 @@
#include <cursor.hxx>
#include <cassert>
#include "mathtype.hxx"
+#include <starmathdatabase.hxx>
// SmDefaultingVisitor
@@ -2088,6 +2089,7 @@ void SmNodeToTextVisitor::Visit( SmFontNode* pNode )
{
sal_uInt32 nc;
sal_uInt8 nr, ng, nb;
+ std::unique_ptr<SmColorTokenTableEntry> aSmColorTokenTableEntry;
switch ( pNode->GetToken( ).eType )
{
case TBOLD:
@@ -2133,63 +2135,23 @@ void SmNodeToTextVisitor::Visit( SmFontNode* pNode )
Separate( );
}
break;
- case TBLACK:
- Append( "color black " );
- break;
- case TWHITE:
- Append( "color white " );
- break;
- case TRED:
- Append( "color red " );
- break;
- case TGREEN:
- Append( "color green " );
- break;
- case TBLUE:
- Append( "color blue " );
- break;
- case TCYAN:
- Append( "color cyan " );
- break;
- case TMAGENTA:
- Append( "color magenta " );
- break;
- case TYELLOW:
- Append( "color yellow " );
- break;
- case TGRAY:
- Append( "color gray " );
- break;
- case TLIME:
- Append( "color lime " );
- break;
- case TMAROON:
- Append( "color maroon " );
- break;
- case TNAVY:
- Append( "color navy " );
- break;
- case TOLIVE:
- Append( "color olive " );
- break;
- case TPURPLE:
- Append( "color purple " );
- break;
- case TSILVER:
- Append( "color silver " );
- break;
- case TTEAL:
- Append( "color teal " );
- break;
- case TAQUA:
- Append( "color aqua " );
- break;
- case TFUCHSIA:
- Append("color fuchsia ");
+ case THTMLCOL:
+ case TDVIPSNAMESCOL:
+ case TICONICCOL:
+ nc = pNode->GetToken().aText.toUInt32(16);
+ Append( "color " );
+ aSmColorTokenTableEntry = starmathdatabase::Identify_Color_Parser( nc );
+ Append( aSmColorTokenTableEntry->pIdent );
break;
case TRGB:
+ nc = pNode->GetToken().aText.toUInt32(16);
+ aSmColorTokenTableEntry = starmathdatabase::Identify_Color_Parser( nc );
+ if ( aSmColorTokenTableEntry ) {
+ Append( "color " );
+ Append( aSmColorTokenTableEntry->pIdent );
+ break;
+ }
Append( "color rgb " );
- nc = pNode->GetToken().aText.toUInt32();
nb = nc % 256;
nc /= 256;
ng = nc % 256;
@@ -2203,8 +2165,15 @@ void SmNodeToTextVisitor::Visit( SmFontNode* pNode )
Separate();
break;
case TRGBA:
+ nc = pNode->GetToken().aText.toUInt32(16);
+ aSmColorTokenTableEntry = starmathdatabase::Identify_Color_Parser( nc );
+ if ( aSmColorTokenTableEntry ) {
+ Append( "color " );
+ Append( aSmColorTokenTableEntry->pIdent );
+ break;
+ }
Append( "color rgba " );
- nc = pNode->GetToken().aText.toUInt32();
+ nc = pNode->GetToken().aText.toUInt32(16);
nb = nc % 256;
nc /= 256;
ng = nc % 256;
@@ -2221,8 +2190,15 @@ void SmNodeToTextVisitor::Visit( SmFontNode* pNode )
Separate();
break;
case THEX:
+ nc = pNode->GetToken().aText.toUInt32(16);
+ aSmColorTokenTableEntry = starmathdatabase::Identify_Color_Parser( nc );
+ if ( aSmColorTokenTableEntry ) {
+ Append( "color " );
+ Append( aSmColorTokenTableEntry->pIdent );
+ break;
+ }
Append( "color hex " );
- nc = pNode->GetToken().aText.toUInt32();
+ nc = pNode->GetToken().aText.toUInt32(16);
Append(OUString::number(nc,16));
Separate();
break;
diff --git a/tools/source/generic/color.cxx b/tools/source/generic/color.cxx
index 73be2beaf6de..2b7c5cc35102 100644
--- a/tools/source/generic/color.cxx
+++ b/tools/source/generic/color.cxx
@@ -56,16 +56,6 @@ void Color::DecreaseContrast(sal_uInt8 nContDec)
}
}
-bool Color::IsDark() const
-{
- return GetLuminance() <= 60;
-}
-
-bool Color::IsBright() const
-{
- return GetLuminance() >= 245;
-}
-
// color space conversion
void Color::RGBtoHSB( sal_uInt16& nHue, sal_uInt16& nSat, sal_uInt16& nBri ) const
diff --git a/vcl/source/outdev/bitmap.cxx b/vcl/source/outdev/bitmap.cxx
index 7b6e8ab6be91..7a6615fa4bac 100644
--- a/vcl/source/outdev/bitmap.cxx
+++ b/vcl/source/outdev/bitmap.cxx
@@ -879,11 +879,11 @@ public:
nAlpha = (nAlphaLine1 + nMapFY * ((nAlphaLine2 >> 7) - (nAlphaLine1 >> 7))) >> 7;
- *pDestScanline = ColorChannelMerge(*pDestScanline, nColor1, nAlpha);
+ *pDestScanline = color::ColorChannelMerge(*pDestScanline, nColor1, nAlpha);
pDestScanline++;
- *pDestScanline = ColorChannelMerge(*pDestScanline, nColor2, nAlpha);
+ *pDestScanline = color::ColorChannelMerge(*pDestScanline, nColor2, nAlpha);
pDestScanline++;
- *pDestScanline = ColorChannelMerge(*pDestScanline, nColor3, nAlpha);
+ *pDestScanline = color::ColorChannelMerge(*pDestScanline, nColor3, nAlpha);
pDestScanline++;
pDestScanline++;
}
diff --git a/vcl/source/outdev/transparent.cxx b/vcl/source/outdev/transparent.cxx
index 283cf70dd021..58242661a2ac 100644
--- a/vcl/source/outdev/transparent.cxx
+++ b/vcl/source/outdev/transparent.cxx
@@ -595,9 +595,9 @@ void OutputDevice::EmulateDrawTransparent ( const tools::PolyPolygon& rPolyPoly,
}
if( ( *pRScan & cBit ) == cBlack )
{
- pWScan[ 0 ] = ColorChannelMerge( pWScan[ 0 ], nB, cTrans );
- pWScan[ 1 ] = ColorChannelMerge( pWScan[ 1 ], nG, cTrans );
- pWScan[ 2 ] = ColorChannelMerge( pWScan[ 2 ], nR, cTrans );
+ pWScan[ 0 ] = color::ColorChannelMerge( pWScan[ 0 ], nB, cTrans );
+ pWScan[ 1 ] = color::ColorChannelMerge( pWScan[ 1 ], nG, cTrans );
+ pWScan[ 2 ] = color::ColorChannelMerge( pWScan[ 2 ], nR, cTrans );
}
}
}