summaryrefslogtreecommitdiff
path: root/drawinglayer
diff options
context:
space:
mode:
authorChris Sherlock <chris.sherlock79@gmail.com>2019-12-04 19:51:30 +1100
committerThorsten Behrens <Thorsten.Behrens@CIB.de>2019-12-19 17:51:45 +0100
commitac793c7d9d3dda330aa25345f092b188e2a79a6d (patch)
tree373f3493a7345916d7170b1402fa898faa900b8a /drawinglayer
parent0c764bfd7abf0b4f21ece732d79bf9b02d7a42d9 (diff)
tdf#129188 drawinglayer: implement EMF+ SetTextContrast
Change-Id: I5e249d5ba85df020ab90c6e543c0d8aefe0b572f Reviewed-on: https://gerrit.libreoffice.org/84455 Tested-by: Jenkins Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de> Tested-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
Diffstat (limited to 'drawinglayer')
-rw-r--r--drawinglayer/source/tools/emfphelperdata.cxx50
-rw-r--r--drawinglayer/source/tools/emfphelperdata.hxx2
2 files changed, 47 insertions, 5 deletions
diff --git a/drawinglayer/source/tools/emfphelperdata.cxx b/drawinglayer/source/tools/emfphelperdata.cxx
index 99d88a27bdb4..3a0ffc4d793b 100644
--- a/drawinglayer/source/tools/emfphelperdata.cxx
+++ b/drawinglayer/source/tools/emfphelperdata.cxx
@@ -39,6 +39,7 @@
#include <drawinglayer/primitive2d/transformprimitive2d.hxx>
#include <drawinglayer/attribute/fontattribute.hxx>
#include <basegfx/color/bcolor.hxx>
+#include <basegfx/color/bcolormodifier.hxx>
#include <basegfx/matrix/b2dhommatrixtools.hxx>
#include <basegfx/polygon/b2dpolygonclipper.hxx>
#include <basegfx/polygon/b2dpolygontools.hxx>
@@ -49,6 +50,8 @@
#include <vcl/settings.hxx>
#include <i18nlangtag/languagetag.hxx>
+#include <algorithm>
+
namespace emfplushelper
{
const char* emfTypeToName(sal_uInt16 type)
@@ -79,7 +82,7 @@ namespace emfplushelper
case EmfPlusRecordTypeSetRenderingOrigin: return "EmfPlusRecordTypeSetRenderingOrigin";
case EmfPlusRecordTypeSetAntiAliasMode: return "EmfPlusRecordTypeSetAntiAliasMode";
case EmfPlusRecordTypeSetTextRenderingHint: return "EmfPlusRecordTypeSetTextRenderingHint";
- case EmfPlusRecordTypeSetTextContrast: return "EmfPlusRectordTypeSetTextContrast";
+ case EmfPlusRecordTypeSetTextContrast: return "EmfPlusRecordTypeSetTextContrast";
case EmfPlusRecordTypeSetInterpolationMode: return "EmfPlusRecordTypeSetInterpolationMode";
case EmfPlusRecordTypeSetPixelOffsetMode: return "EmfPlusRecordTypeSetPixelOffsetMode";
case EmfPlusRecordTypeSetCompositingQuality: return "EmfPlusRecordTypeSetCompositingQuality";
@@ -899,6 +902,7 @@ namespace emfplushelper
mnOriginY(0),
mnHDPI(0),
mnVDPI(0),
+ mbSetTextContrast(false),
mnFrameLeft(0),
mnFrameTop(0),
mnFrameRight(0),
@@ -1537,7 +1541,29 @@ namespace emfplushelper
::basegfx::B2DSize(font->emSize, font->emSize),
::basegfx::B2DPoint(lx + stringAlignmentHorizontalOffset, ly + font->emSize));
- const Color color = EMFPGetBrushColorOrARGBColor(flags, brushId);
+ Color uncorrectedColor = EMFPGetBrushColorOrARGBColor(flags, brushId);
+ Color color;
+
+ if (mbSetTextContrast)
+ {
+ const auto gammaVal = mnTextContrast / 1000;
+ const basegfx::BColorModifier_gamma gamma(gammaVal);
+
+ // gamma correct transparency color
+ sal_uInt16 alpha = uncorrectedColor.GetTransparency();
+ alpha = std::clamp(std::pow(alpha, 1.0 / gammaVal), 0.0, 1.0) * 255;
+
+ basegfx::BColor modifiedColor(gamma.getModifiedColor(uncorrectedColor.getBColor()));
+ color.SetRed(modifiedColor.getRed() * 255);
+ color.SetGreen(modifiedColor.getGreen() * 255);
+ color.SetBlue(modifiedColor.getBlue() * 255);
+ color.SetTransparency(alpha);
+ }
+ else
+ {
+ color = uncorrectedColor;
+ }
+
mrPropertyHolders.Current().setTextColor(color.getBColor());
mrPropertyHolders.Current().setTextColorActive(true);
@@ -1620,11 +1646,25 @@ namespace emfplushelper
SAL_INFO("drawinglayer", "EMF+ SetRenderingOrigin, [x,y]: " << mnOriginX << "," << mnOriginY);
break;
}
+ case EmfPlusRecordTypeSetTextContrast:
+ {
+ const sal_uInt16 LOWERGAMMA = 1000;
+ const sal_uInt16 UPPERGAMMA = 2200;
+
+ mbSetTextContrast = true;
+ mnTextContrast = flags & 0xFFF;
+ SAL_WARN_IF(mnTextContrast > UPPERGAMMA || mnTextContrast < LOWERGAMMA,
+ "drawinglayer", "Gamma value is not with bounds 1000 to 2200, value is " << mnTextContrast);
+ mnTextContrast = std::min(mnTextContrast, UPPERGAMMA);
+ mnTextContrast = std::max(mnTextContrast, LOWERGAMMA);
+ SAL_INFO("drawinglayer", "EMF+\t Text contrast: " << (mnTextContrast / 1000) << " gamma");
+ break;
+ }
case EmfPlusRecordTypeSetTextRenderingHint:
{
sal_uInt8 nTextRenderingHint = (flags & 0xFF) >> 1;
SAL_INFO("drawinglayer", "EMF+\t Text rendering hint: " << TextRenderingHintToString(nTextRenderingHint));
- SAL_INFO("drawinglayer", "TODO\t EMF+ SetTextRenderingHint");
+ SAL_WARN("drawinglayer", "TODO\t EMF+ SetTextRenderingHint");
break;
}
case EmfPlusRecordTypeSetAntiAliasMode:
@@ -1633,14 +1673,14 @@ namespace emfplushelper
sal_uInt8 nSmoothingMode = (flags & 0xFE00) >> 1;
SAL_INFO("drawinglayer", "EMF+\t Antialiasing: " << (bUseAntiAlias ? "enabled" : "disabled"));
SAL_INFO("drawinglayer", "EMF+\t Smoothing mode: " << SmoothingModeToString(nSmoothingMode));
- SAL_INFO("drawinglayer", "TODO\t EMF+ SetAntiAliasMode");
+ SAL_WARN("drawinglayer", "TODO\t EMF+ SetAntiAliasMode");
break;
}
case EmfPlusRecordTypeSetInterpolationMode:
{
sal_uInt16 nInterpolationMode = flags & 0xFF;
SAL_INFO("drawinglayer", "EMF+\t Interpolation mode: " << InterpolationModeToString(nInterpolationMode));
- SAL_INFO("drawinglayer", "TODO\t EMF+ InterpolationMode");
+ SAL_WARN("drawinglayer", "TODO\t EMF+ InterpolationMode");
break;
}
case EmfPlusRecordTypeSetPixelOffsetMode:
diff --git a/drawinglayer/source/tools/emfphelperdata.hxx b/drawinglayer/source/tools/emfphelperdata.hxx
index a6560359fe52..76e4b657dbe1 100644
--- a/drawinglayer/source/tools/emfphelperdata.hxx
+++ b/drawinglayer/source/tools/emfphelperdata.hxx
@@ -189,6 +189,8 @@ namespace emfplushelper
sal_Int32 mnOriginY;
sal_uInt32 mnHDPI;
sal_uInt32 mnVDPI;
+ bool mbSetTextContrast;
+ sal_uInt16 mnTextContrast;
/* EMF+ emf header info */
sal_Int32 mnFrameLeft;