editeng/source/editeng/impedit3.cxx |   33 +++++++++++++++++++++------------
 1 file changed, 21 insertions(+), 12 deletions(-)

New commits:
commit afc4cf308b02a65b3396ea2e86296272e10b3c88
Author:     Caolán McNamara <[email protected]>
AuthorDate: Mon Jan 12 13:32:42 2026 +0000
Commit:     Xisco Fauli <[email protected]>
CommitDate: Tue Jan 20 10:36:03 2026 +0100

    tdf#167737 chart renders text black on black in dark mode
    
    when there is no chart background and the document mode is to use a dark
    color for the document color.
    
    The intent of this function is to get a color that can be seen against
    the background. So:
    
    a) Always get the background the text is to be rendered on.
    b) We can consult svtools::FONTCOLOR as a potential foreground color,
    but reject it if it will not contrast against the background
    
    Change-Id: If441050423750fdf0a12f07dd686daf8f7e8b165
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/197109
    Reviewed-by: Caolán McNamara <[email protected]>
    Tested-by: Jenkins
    Signed-off-by: Xisco Fauli <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/197201
    Reviewed-by: Adolfo Jayme Barrientos <[email protected]>
    Tested-by: Adolfo Jayme Barrientos <[email protected]>
    (cherry picked from commit bb7152a06685c0710759c0a5701e636b192d76a2)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/197314

diff --git a/editeng/source/editeng/impedit3.cxx 
b/editeng/source/editeng/impedit3.cxx
index 84e85dcc1a9e..c2ba71f5cceb 100644
--- a/editeng/source/editeng/impedit3.cxx
+++ b/editeng/source/editeng/impedit3.cxx
@@ -4957,34 +4957,43 @@ Reference < i18n::XExtendedInputSequenceChecker > const 
& ImpEditEngine::ImplGet
     return mxISC;
 }
 
+static bool hasColorContrast(const Color& rColor, const Color& 
rBackgroundColor)
+{
+    if (rColor.IsDark() && !rBackgroundColor.IsDark())
+        return true;
+    if (rColor.IsBright() && !rBackgroundColor.IsBright())
+        return true;
+    return false;
+}
+
 Color ImpEditEngine::GetAutoColor() const
 {
     Color aColor;
 
+    Color aBackgroundColor = GetBackgroundColor();
+
     const SfxViewShell* pKitSh = comphelper::LibreOfficeKit::isActive() ? 
SfxViewShell::Current() : nullptr;
     if (pKitSh)
     {
-        Color aBackgroundColor = GetBackgroundColor();
         if (aBackgroundColor == COL_AUTO)
             aBackgroundColor = pKitSh->GetColorConfigColor(svtools::DOCCOLOR);
-        if (aBackgroundColor.IsDark())
-            aColor = COL_WHITE;
-        else
-            aColor = COL_BLACK;
     }
     else
     {
+        if (aBackgroundColor == COL_AUTO) // if everything is auto/transparent 
then use doc color
+            aBackgroundColor = 
GetColorConfig().GetColorValue(svtools::DOCCOLOR).nColor;
         aColor = GetColorConfig().GetColorValue(svtools::FONTCOLOR, 
false).nColor;
 
-        if ( aColor == COL_AUTO )
-        {
-            if ( GetBackgroundColor().IsDark()  )
-                aColor = COL_WHITE;
-            else
-                aColor = COL_BLACK;
-        }
+        // allow using FONTCOLOR if it provides contrast to the current 
background color
+        if (aColor != COL_AUTO && hasColorContrast(aColor, aBackgroundColor))
+            return aColor;
     }
 
+    if (aBackgroundColor.IsDark())
+        aColor = COL_WHITE;
+    else
+        aColor = COL_BLACK;
+
     return aColor;
 }
 

Reply via email to