Resolves tdf#137059 - Use application colors for font preview

Background is set to document's application color now
(options > application colors > document) to provide
a true WYSIWYG experience (except for modifications
to the page background color).

Change-Id: Ifd78e667f3eeff3573ff09bcb4d2a9634dd49c99
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105011
Tested-by: Jenkins
Tested-by: Caolán McNamara <caolanm@redhat.com>
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
diff --git a/cui/source/dialogs/FontFeaturesDialog.cxx b/cui/source/dialogs/FontFeaturesDialog.cxx
index a34912d..c1e79b4 100644
--- a/cui/source/dialogs/FontFeaturesDialog.cxx
+++ b/cui/source/dialogs/FontFeaturesDialog.cxx
@@ -26,9 +26,6 @@ FontFeaturesDialog::FontFeaturesDialog(weld::Window* pParent, OUString const& rF
    , m_xContentGrid(m_xBuilder->weld_container("contentGrid"))
    , m_xPreviewWindow(new weld::CustomWeld(*m_xBuilder, "preview", m_aPreviewWindow))
{
    svtools::ColorConfig aColorConfig;
    Color aFillColor(aColorConfig.GetColorValue(svtools::DOCCOLOR).nColor);
    m_aPreviewWindow.SetBackColor(aFillColor);
    initialize();
}

diff --git a/cui/source/tabpages/chardlg.cxx b/cui/source/tabpages/chardlg.cxx
index 4ec72e2..1000dbf 100644
--- a/cui/source/tabpages/chardlg.cxx
+++ b/cui/source/tabpages/chardlg.cxx
@@ -1346,15 +1346,6 @@ void SvxCharEffectsPage::EnableNoneFontColor()
    m_bEnableNoneFontColor = true;
}

Color SvxCharEffectsPage::GetPreviewFontColor(const Color& rColor) const
{
    if (rColor == COL_AUTO)
        return COL_BLACK;
    if (m_bEnableNoneFontColor && rColor == COL_NONE_COLOR)
        return COL_BLACK;
    return rColor;
}

SvxCharEffectsPage::~SvxCharEffectsPage()
{
    m_xUnderlineColorLB.reset();
@@ -1431,9 +1422,10 @@ void SvxCharEffectsPage::UpdatePreview_Impl()
    SvxFont& rCTLFont = GetPreviewCTLFont();

    const Color& rSelectedColor = m_xFontColorLB->GetSelectEntryColor();
    rFont.SetColor(GetPreviewFontColor(rSelectedColor));
    rCJKFont.SetColor(GetPreviewFontColor(rSelectedColor));
    rCTLFont.SetColor(GetPreviewFontColor(rSelectedColor));
    rFont.SetColor(rSelectedColor);
    rCJKFont.SetColor(rSelectedColor);
    rCTLFont.SetColor(rSelectedColor);
    m_aPreviewWin.AutoCorrectFontColor(); // handle color COL_AUTO

    FontLineStyle eUnderline = static_cast<FontLineStyle>(m_xUnderlineLB->get_active_id().toInt32());
    FontLineStyle eOverline = static_cast<FontLineStyle>(m_xOverlineLB->get_active_id().toInt32());
@@ -1544,9 +1536,10 @@ void SvxCharEffectsPage::ResetColor_Impl( const SfxItemSet& rSet )

            const SvxColorItem& rItem = static_cast<const SvxColorItem&>(rSet.Get( nWhich ));
            Color aColor = rItem.GetValue();
            rFont.SetColor(GetPreviewFontColor(aColor));
            rCJKFont.SetColor(GetPreviewFontColor(aColor));
            rCTLFont.SetColor(GetPreviewFontColor(aColor));
            rFont.SetColor(aColor);
            rCJKFont.SetColor(aColor);
            rCTLFont.SetColor(aColor);
            m_aPreviewWin.AutoCorrectFontColor(); // handle color COL_AUTO

            m_aPreviewWin.Invalidate();

diff --git a/include/svx/fntctrl.hxx b/include/svx/fntctrl.hxx
index c84289a..1751c3a 100644
--- a/include/svx/fntctrl.hxx
+++ b/include/svx/fntctrl.hxx
@@ -49,7 +49,6 @@ public:
    SvxFont&            GetCTLFont();
    void                SetColor( const Color& rColor );
    void                ResetColor();
    void                SetBackColor( const Color& rColor );
    void                SetTextLineColor(const Color& rColor);
    void                SetOverlineColor(const Color& rColor);
    void                Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& ) override;
diff --git a/reportdesign/source/ui/dlg/Condition.cxx b/reportdesign/source/ui/dlg/Condition.cxx
index 9f7b8bb..2b44e1e 100644
--- a/reportdesign/source/ui/dlg/Condition.cxx
+++ b/reportdesign/source/ui/dlg/Condition.cxx
@@ -324,7 +324,6 @@ void Condition::updateToolbar(const uno::Reference< report::XReportControlFormat
        aFont.SetRelief( static_cast< FontRelief >( _xReportControlFormat->getCharRelief() ) );
        aFont.SetColor( Color(_xReportControlFormat->getCharColor()) );
        m_aPreview.SetFont( aFont, aFont, aFont );
        m_aPreview.SetBackColor( Color(_xReportControlFormat->getControlBackground()) );
        m_aPreview.SetTextLineColor( Color( _xReportControlFormat->getCharUnderlineColor() ) );
    }
    catch( const Exception& )
diff --git a/svx/source/dialog/fntctrl.cxx b/svx/source/dialog/fntctrl.cxx
index edf8b78..1b2eb42 100644
--- a/svx/source/dialog/fntctrl.cxx
+++ b/svx/source/dialog/fntctrl.cxx
@@ -191,7 +191,7 @@ public:
        SvtLanguageOptions aLanguageOptions;
        m_bCJKEnabled = aLanguageOptions.IsAnyEnabled();
        m_bCTLEnabled = aLanguageOptions.IsCTLFontEnabled();

        mxBackColor = svtools::ColorConfig().GetColorValue(svtools::DOCCOLOR).nColor;
        Invalidate100PercentFontWidth();
    }

@@ -501,13 +501,8 @@ static void SetPrevFontEscapement(SvxFont& rFont, sal_uInt8 nProp, sal_uInt8 nEs

void SvxFontPrevWindow::ApplySettings(vcl::RenderContext& rRenderContext)
{
    const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();

    svtools::ColorConfig aColorConfig;
    Color aTextColor(aColorConfig.GetColorValue(svtools::FONTCOLOR).nColor);
    rRenderContext.SetTextColor(aTextColor);

    rRenderContext.SetBackground(rStyleSettings.GetWindowColor());
    rRenderContext.SetTextColor( svtools::ColorConfig().GetColorValue(svtools::FONTCOLOR).nColor );
    rRenderContext.SetBackground( svtools::ColorConfig().GetColorValue(svtools::DOCCOLOR).nColor );
}

void SvxFontPrevWindow::SetDrawingArea(weld::DrawingArea* pDrawingArea)
@@ -596,12 +591,6 @@ void SvxFontPrevWindow::ResetColor()
    Invalidate();
}

void SvxFontPrevWindow::SetBackColor(const Color &rColor)
{
    pImpl->mxBackColor = rColor;
    Invalidate();
}

void SvxFontPrevWindow::SetTextLineColor(const Color &rColor)
{
    pImpl->mxTextLineColor = rColor;
@@ -839,17 +828,19 @@ void SvxFontPrevWindow::SetFontWidthScale( sal_uInt16 n )

void SvxFontPrevWindow::AutoCorrectFontColor()
{
    const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
    Color aFontColor(rStyleSettings.GetWindowTextColor());
    Color aColor(COL_AUTO);
    if ( pImpl->mxBackColor ) aColor = *pImpl->mxBackColor;
    const bool bIsDark(aColor.IsDark());

    if (COL_AUTO == pImpl->maFont.GetColor())
        pImpl->maFont.SetColor(aFontColor);

    if (COL_AUTO == pImpl->maCJKFont.GetColor())
        pImpl->maCJKFont.SetColor(aFontColor);

    if (COL_AUTO == pImpl->maCTLFont.GetColor())
        pImpl->maCTLFont.SetColor(aFontColor);
    aColor = pImpl->maFont.GetColor();
    if (aColor == COL_AUTO)
        pImpl->maFont.SetColor( bIsDark ? COL_WHITE : COL_BLACK );
    aColor = pImpl->maCJKFont.GetColor();
    if (aColor == COL_AUTO)
        pImpl->maCJKFont.SetColor( bIsDark ? COL_WHITE : COL_BLACK );
    aColor = pImpl->maCTLFont.GetColor();
    if (aColor == COL_AUTO)
        pImpl->maCTLFont.SetColor( bIsDark ? COL_WHITE : COL_BLACK );
}

void SvxFontPrevWindow::SetFontSize( const SfxItemSet& rSet, sal_uInt16 nSlot, SvxFont& rFont )
@@ -1017,18 +1008,6 @@ void SvxFontPrevWindow::SetFromItemSet(const SfxItemSet &rSet, bool bPreviewBack
    rCJKFont.SetTransparent( bTransparent );
    rCTLFont.SetTransparent( bTransparent );

    Color aBackCol( COL_TRANSPARENT );
    if( !bPreviewBackgroundToCharacter )
    {
        if( GetWhich( rSet, SID_ATTR_BRUSH, nWhich ) )
        {
            const SvxBrushItem& rBrush = static_cast<const  SvxBrushItem&>( rSet.Get( nWhich ) );
            if( GPOS_NONE == rBrush.GetGraphicPos() )
                aBackCol = rBrush.GetColor();
        }
    }
    SetBackColor( aBackCol );

    // Font
    SetPrevFont( rSet, SID_ATTR_CHAR_FONT, rFont );
    SetPrevFont( rSet, SID_ATTR_CHAR_CJK_FONT, rCJKFont );
diff --git a/sw/source/ui/config/optpage.cxx b/sw/source/ui/config/optpage.cxx
index b6cf6ea..69f873c 100644
--- a/sw/source/ui/config/optpage.cxx
+++ b/sw/source/ui/config/optpage.cxx
@@ -1984,8 +1984,6 @@ void SwRedlineOptionsTabPage::InitFontStyle(SvxFontPrevWindow& rExampleWin, cons

    rExampleWin.SetFont( rFont, rCJKFont,rCTLFont );
    rExampleWin.SetPreviewText(rText);

    rExampleWin.SetBackColor(aBackCol);
}

SwCompareOptionsTabPage::SwCompareOptionsTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet)