View | Details | Raw Unified | Return to bug 113637
Collapse All | Expand All

(-)kcontrol/fonts/fonts.cpp (-41 / +11 lines)
Lines 43-68 Link Here
43
#undef Unsorted
43
#undef Unsorted
44
#undef None
44
#undef None
45
45
46
static const char *aa_greyscale_xpm[]={
47
"12 12 6 1",
48
"a c #dcdcdc",
49
"b c #c3c3c3",
50
"c c #a0a0a0",
51
"d c #808080",
52
"e c #585858",
53
"f c #303030",
54
"ffeeddccbbaa",
55
"ffeeddccbbaa",
56
"ffeeddccbbaa",
57
"ffeeddccbbaa",
58
"ffeeddccbbaa",
59
"ffeeddccbbaa",
60
"ffeeddccbbaa",
61
"ffeeddccbbaa",
62
"ffeeddccbbaa",
63
"ffeeddccbbaa",
64
"ffeeddccbbaa",
65
"ffeeddccbbaa"};
66
static const char *aa_rgb_xpm[]={
46
static const char *aa_rgb_xpm[]={
67
"12 12 3 1",
47
"12 12 3 1",
68
"a c #0000ff",
48
"a c #0000ff",
Lines 132-139 Link Here
132
"aaaaaaaaaaaa",
112
"aaaaaaaaaaaa",
133
"aaaaaaaaaaaa"};
113
"aaaaaaaaaaaa"};
134
114
135
static QPixmap aaPixmaps[]={ QPixmap(aa_greyscale_xpm), QPixmap(aa_rgb_xpm),
115
static QPixmap aaPixmaps[]={ QPixmap(aa_rgb_xpm), QPixmap(aa_bgr_xpm), QPixmap(aa_vrgb_xpm), QPixmap(aa_vbgr_xpm) };
136
                             QPixmap(aa_bgr_xpm), QPixmap(aa_vrgb_xpm), QPixmap(aa_vbgr_xpm) };
137
116
138
/**** DLL Interface ****/
117
/**** DLL Interface ****/
139
typedef KGenericFactory<KFonts, QWidget> FontFactory;
118
typedef KGenericFactory<KFonts, QWidget> FontFactory;
Lines 288-294 Link Here
288
#endif
267
#endif
289
}
268
}
290
269
291
void FontAASettings::load()
270
bool FontAASettings::load()
292
{
271
{
293
  double     from, to;
272
  double     from, to;
294
#ifdef HAVE_FONTCONFIG
273
#ifdef HAVE_FONTCONFIG
Lines 346-354 Link Here
346
#endif
325
#endif
347
326
348
  enableWidgets();
327
  enableWidgets();
328
329
  return xft.getAntiAliasing();
349
}
330
}
350
331
351
bool FontAASettings::save()
332
bool FontAASettings::save( bool useAA )
352
{
333
{
353
#ifdef HAVE_FONTCONFIG
334
#ifdef HAVE_FONTCONFIG
354
  KXftConfig xft(KXftConfig::ExcludeRange|KXftConfig::SubPixelType|KXftConfig::HintStyle);
335
  KXftConfig xft(KXftConfig::ExcludeRange|KXftConfig::SubPixelType|KXftConfig::HintStyle);
Lines 356-364 Link Here
356
  KXftConfig xft(KXftConfig::ExcludeRange|KXftConfig::SubPixelType);
337
  KXftConfig xft(KXftConfig::ExcludeRange|KXftConfig::SubPixelType);
357
#endif
338
#endif
358
  KConfig    kglobals("kdeglobals", false, false);
339
  KConfig    kglobals("kdeglobals", false, false);
359
360
  kglobals.setGroup("General");
340
  kglobals.setGroup("General");
361
341
342
  xft.setAntiAliasing( useAA );
343
362
  if(excludeRange->isChecked())
344
  if(excludeRange->isChecked())
363
    xft.setExcludeRange(excludeFrom->value(), excludeTo->value());
345
    xft.setExcludeRange(excludeFrom->value(), excludeTo->value());
364
  else
346
  else
Lines 635-645 Link Here
635
617
636
   connect(cbAA, SIGNAL(clicked()), SLOT(slotUseAntiAliasing()));
618
   connect(cbAA, SIGNAL(clicked()), SLOT(slotUseAntiAliasing()));
637
619
638
   useAA = QSettings().readBoolEntry("/qt/useXft");
620
   load();
639
   useAA_original = useAA;
640
641
   cbAA->setChecked(useAA);
642
   aaSettingsButton->setEnabled(useAA);
643
}
621
}
644
622
645
KFonts::~KFonts()
623
KFonts::~KFonts()
Lines 658-664 Link Here
658
  for ( int i = 0; i < (int) fontUseList.count(); i++ )
636
  for ( int i = 0; i < (int) fontUseList.count(); i++ )
659
    fontUseList.at( i )->setDefault();
637
    fontUseList.at( i )->setDefault();
660
638
661
  useAA = false;
639
  useAA = true;
662
  cbAA->setChecked(useAA);
640
  cbAA->setChecked(useAA);
663
  aaSettings->defaults();
641
  aaSettings->defaults();
664
  emit changed(true);
642
  emit changed(true);
Lines 669-681 Link Here
669
  for ( uint i = 0; i < fontUseList.count(); i++ )
647
  for ( uint i = 0; i < fontUseList.count(); i++ )
670
    fontUseList.at( i )->readFont();
648
    fontUseList.at( i )->readFont();
671
649
672
  useAA = QSettings().readBoolEntry("/qt/useXft");
650
  useAA_original = useAA = aaSettings->load();
673
  useAA_original = useAA;
674
  kdDebug(1208) << "AA:" << useAA << endl;
651
  kdDebug(1208) << "AA:" << useAA << endl;
675
  cbAA->setChecked(useAA);
652
  cbAA->setChecked(useAA);
676
653
677
  aaSettings->load();
678
679
  emit changed(false);
654
  emit changed(false);
680
}
655
}
681
656
Lines 699-714 Link Here
699
  config->sync();
674
  config->sync();
700
  delete config;
675
  delete config;
701
676
702
  QSettings().writeEntry("/qt/useXft", useAA);
703
704
  if (useAA)
705
    QSettings().writeEntry("/qt/enableXft", useAA);
706
707
  KIPC::sendMessageAll(KIPC::FontChanged);
677
  KIPC::sendMessageAll(KIPC::FontChanged);
708
678
709
  kapp->processEvents(); // Process font change ourselves
679
  kapp->processEvents(); // Process font change ourselves
710
680
711
  if(aaSettings->save() || (useAA != useAA_original) ) {
681
  if(aaSettings->save( useAA ) || (useAA != useAA_original) ) {
712
    KMessageBox::information(this,
682
    KMessageBox::information(this,
713
      i18n(
683
      i18n(
714
        "<p>You have changed anti-aliasing related settings. This change will only affect newly started applications.</p>"
684
        "<p>You have changed anti-aliasing related settings. This change will only affect newly started applications.</p>"
(-)kcontrol/fonts/kxftconfig.cpp (-47 / +99 lines)
Lines 29-34 Link Here
29
#include <klocale.h>
29
#include <klocale.h>
30
#include <klargefile.h>
30
#include <klargefile.h>
31
#include <qdir.h>
31
#include <qdir.h>
32
#include <qsettings.h>
33
#include <qfont.h>
32
34
33
#ifdef HAVE_FONTCONFIG
35
#ifdef HAVE_FONTCONFIG
34
#include <stdarg.h>
36
#include <stdarg.h>
Lines 254-262 Link Here
254
256
255
static KXftConfig::SubPixel::Type strToType(const char *str)
257
static KXftConfig::SubPixel::Type strToType(const char *str)
256
{
258
{
257
    if(0==strcmp(str, "\0"))
259
    if(0==strcmp(str, "rgb"))
258
        return KXftConfig::SubPixel::Greyscale;
259
    else if(0==strcmp(str, "rgb"))
260
        return KXftConfig::SubPixel::Rgb;
260
        return KXftConfig::SubPixel::Rgb;
261
    else if(0==strcmp(str, "bgr")) 
261
    else if(0==strcmp(str, "bgr")) 
262
        return KXftConfig::SubPixel::Bgr;
262
        return KXftConfig::SubPixel::Bgr;
Lines 283-291 Link Here
283
#else
283
#else
284
static bool strToType(const char *str, KXftConfig::SubPixel::Type &type)
284
static bool strToType(const char *str, KXftConfig::SubPixel::Type &type)
285
{   
285
{   
286
    if(0==memcmp(str, "\0", 1))
286
    if(0==memcmp(str, "rgb", 3))
287
        type=KXftConfig::SubPixel::Greyscale;
288
    else if(0==memcmp(str, "rgb", 3))
289
        type=KXftConfig::SubPixel::Rgb;
287
        type=KXftConfig::SubPixel::Rgb;
290
    else if(0==memcmp(str, "bgr", 3))
288
    else if(0==memcmp(str, "bgr", 3))
291
        type=KXftConfig::SubPixel::Bgr;
289
        type=KXftConfig::SubPixel::Bgr;
Lines 429-434 Link Here
429
#ifdef HAVE_FONTCONFIG
427
#ifdef HAVE_FONTCONFIG
430
    m_file=getConfigFile(system);
428
    m_file=getConfigFile(system);
431
    kdDebug(1208) << "Using fontconfig file:" << m_file << endl;
429
    kdDebug(1208) << "Using fontconfig file:" << m_file << endl;
430
    m_antiAliasing = aliasingEnabled();
432
#else
431
#else
433
    if(system) 
432
    if(system) 
434
    {
433
    {
Lines 581-586 Link Here
581
#ifdef HAVE_FONTCONFIG
580
#ifdef HAVE_FONTCONFIG
582
            if(m_required&HintStyle)
581
            if(m_required&HintStyle)
583
                newConfig.setHintStyle(m_hint.style);
582
                newConfig.setHintStyle(m_hint.style);
583
            newConfig.setAntiAliasing(m_antiAliasing.set);
584
#else
584
#else
585
            if(m_required&SymbolFamilies)
585
            if(m_required&SymbolFamilies)
586
            {
586
            {
Lines 626-631 Link Here
626
                            applySubPixelType();
626
                            applySubPixelType();
627
                        if(m_required&HintStyle)
627
                        if(m_required&HintStyle)
628
                            applyHintStyle();
628
                            applyHintStyle();
629
                        applyAntiAliasing();
629
                        if(m_required&ExcludeRange)
630
                        if(m_required&ExcludeRange)
630
                        {
631
                        {
631
                            applyExcludeRange(false);
632
                            applyExcludeRange(false);
Lines 774-794 Link Here
774
775
775
bool KXftConfig::getSubPixelType(SubPixel::Type &type)
776
bool KXftConfig::getSubPixelType(SubPixel::Type &type)
776
{
777
{
777
    if(SubPixel::None!=m_subPixel.type && !m_subPixel.toBeRemoved)
778
    type=m_subPixel.type;
778
    {
779
    return SubPixel::None!=m_subPixel.type;
779
        type=m_subPixel.type;
780
        return true;
781
    }
782
    else
783
        return false;
784
}
780
}
785
781
786
void KXftConfig::setSubPixelType(SubPixel::Type type)
782
void KXftConfig::setSubPixelType(SubPixel::Type type)
787
{
783
{
788
    if((SubPixel::None==type && SubPixel::None!=m_subPixel.type && !m_subPixel.toBeRemoved) ||
784
    if(type!=m_subPixel.type)
789
       (SubPixel::None!=type && (type!=m_subPixel.type || m_subPixel.toBeRemoved)) )
790
    {
785
    {
791
        m_subPixel.toBeRemoved=(SubPixel::None==type);
792
        m_subPixel.type=type;
786
        m_subPixel.type=type;
793
        m_madeChanges=true;
787
        m_madeChanges=true;
794
    }
788
    }
Lines 878-885 Link Here
878
        default:
872
        default:
879
        case SubPixel::None:
873
        case SubPixel::None:
880
            return i18n("None");
874
            return i18n("None");
881
        case SubPixel::Greyscale:
882
            return i18n("Grayscale");
883
        case SubPixel::Rgb:
875
        case SubPixel::Rgb:
884
            return i18n("RGB");
876
            return i18n("RGB");
885
        case SubPixel::Bgr:
877
        case SubPixel::Bgr:
Lines 898-905 Link Here
898
        default:
890
        default:
899
        case SubPixel::None:
891
        case SubPixel::None:
900
            return "none";
892
            return "none";
901
        case SubPixel::Greyscale:
902
            return "";
903
        case SubPixel::Rgb:
893
        case SubPixel::Rgb:
904
            return "rgb";
894
            return "rgb";
905
        case SubPixel::Bgr:
895
        case SubPixel::Bgr:
Lines 1066-1071 Link Here
1066
                                    m_hinting.node=n;
1056
                                    m_hinting.node=n;
1067
                                    m_hinting.set=str.lower()!="false";
1057
                                    m_hinting.set=str.lower()!="false";
1068
                                }
1058
                                }
1059
                                else if(!(str=getEntry(ene, "bool", 2, "name", "antialias", "mode", "assign")).isNull())
1060
                                {
1061
                                    m_antiAliasing.node=n;
1062
                                    m_antiAliasing.set=str.lower()!="false";
1063
                                }
1069
                        }
1064
                        }
1070
                        break;
1065
                        break;
1071
                    case 3:
1066
                    case 3:
Lines 1270-1302 Link Here
1270
1265
1271
void KXftConfig::applySubPixelType()
1266
void KXftConfig::applySubPixelType()
1272
{
1267
{
1273
    if(SubPixel::None==m_subPixel.type || m_subPixel.toBeRemoved)
1268
    QDomElement matchNode = m_doc.createElement("match"),
1274
    {
1269
                typeNode  = m_doc.createElement("const"),
1275
        if(!m_subPixel.node.isNull())
1270
                editNode  = m_doc.createElement("edit");
1276
        {
1271
    QDomText    typeText  = m_doc.createTextNode(toStr(m_subPixel.type));
1277
            m_doc.documentElement().removeChild(m_subPixel.node);
1278
            m_subPixel.node.clear();
1279
        }
1280
    }
1281
    else
1282
    {
1283
        QDomElement matchNode = m_doc.createElement("match"),
1284
                    typeNode  = m_doc.createElement("const"),
1285
                    editNode  = m_doc.createElement("edit");
1286
        QDomText    typeText  = m_doc.createTextNode(toStr(m_subPixel.type));
1287
1272
1288
        matchNode.setAttribute("target", "font");
1273
    matchNode.setAttribute("target", "font");
1289
        editNode.setAttribute("mode", "assign");
1274
    editNode.setAttribute("mode", "assign");
1290
        editNode.setAttribute("name", "rgba");
1275
    editNode.setAttribute("name", "rgba");
1291
        editNode.appendChild(typeNode);
1276
    editNode.appendChild(typeNode);
1292
        typeNode.appendChild(typeText);
1277
    typeNode.appendChild(typeText);
1293
        matchNode.appendChild(editNode);
1278
    matchNode.appendChild(editNode);
1294
        if(m_subPixel.node.isNull())
1279
    if(m_subPixel.node.isNull())
1295
            m_doc.documentElement().appendChild(matchNode);
1280
        m_doc.documentElement().appendChild(matchNode);
1296
        else
1281
    else
1297
            m_doc.documentElement().replaceChild(matchNode, m_subPixel.node);
1282
        m_doc.documentElement().replaceChild(matchNode, m_subPixel.node);
1298
        m_subPixel.node=matchNode;
1283
    m_subPixel.node=matchNode;
1299
    }
1300
}
1284
}
1301
1285
1302
void KXftConfig::applyHintStyle()
1286
void KXftConfig::applyHintStyle()
Lines 1451-1457 Link Here
1451
1435
1452
void KXftConfig::outputSubPixelType(std::ofstream &f, bool ifNew)
1436
void KXftConfig::outputSubPixelType(std::ofstream &f, bool ifNew)
1453
{
1437
{
1454
    if(!m_subPixel.toBeRemoved && ((ifNew && NULL==m_subPixel.end) || (!ifNew && NULL!=m_subPixel.end)) && SubPixel::None!=m_subPixel.type)
1438
    if((ifNew && NULL==m_subPixel.end) || (!ifNew && NULL!=m_subPixel.end))
1455
        f << "match edit rgba = " << toStr(m_subPixel.type) << ';' << endl;
1439
        f << "match edit rgba = " << toStr(m_subPixel.type) << ';' << endl;
1456
}
1440
}
1457
1441
Lines 1487-1488 Link Here
1487
}
1471
}
1472
1473
#endif
1474
1475
#ifdef HAVE_FONTCONFIG
1476
bool KXftConfig::getAntiAliasing() const
1477
{
1478
    return m_antiAliasing.set;
1479
}
1480
1481
void KXftConfig::setAntiAliasing( bool set )
1482
{
1483
    m_antiAliasing.set = set;
1484
    m_madeChanges = true;
1485
}
1486
1487
void KXftConfig::applyAntiAliasing()
1488
{
1489
    QDomElement matchNode = m_doc.createElement("match"),
1490
                typeNode  = m_doc.createElement("bool"),
1491
                editNode  = m_doc.createElement("edit");
1492
    QDomText    typeText  = m_doc.createTextNode(m_antiAliasing.set ? "true" : "false");
1493
1494
    matchNode.setAttribute("target", "font");
1495
    editNode.setAttribute("mode", "assign");
1496
    editNode.setAttribute("name", "antialias");
1497
    editNode.appendChild(typeNode);
1498
    typeNode.appendChild(typeText);
1499
    matchNode.appendChild(editNode);
1500
    if(m_antiAliasing.node.isNull())
1501
        m_doc.documentElement().appendChild(matchNode);
1502
    else
1503
        m_doc.documentElement().replaceChild(matchNode, m_antiAliasing.node);
1504
    m_antiAliasing.node=matchNode;
1505
}
1506
1507
// KXftConfig only parses one config file, user's .fonts.conf usually.
1508
// If that one doesn't exist, then KXftConfig doesn't know if antialiasing
1509
// is enabled or not. So try to find out the default value from the default font.
1510
// Maybe there's a better way *shrug*.
1511
bool KXftConfig::aliasingEnabled()
1512
{
1513
    FcPattern *pattern = FcPatternCreate();
1514
    FcConfigSubstitute(0, pattern, FcMatchPattern);
1515
    FcDefaultSubstitute(pattern);
1516
    FcResult result;
1517
    FcPattern *f = FcFontMatch( 0, pattern, &result );
1518
    FcBool antialiased = FcTrue;
1519
    FcPatternGetBool( f, FC_ANTIALIAS, 0, &antialiased );
1520
    FcPatternDestroy( f );
1521
    FcPatternDestroy( pattern );
1522
    return antialiased == FcTrue;
1523
}
1524
1525
#else
1526
1527
void KXftConfig::setAntiAliasing( bool set )
1528
{
1529
  QSettings().writeEntry("/qt/useXft", set);
1530
  if (set)
1531
    QSettings().writeEntry("/qt/enableXft", set);
1532
}
1533
1534
bool KXftConfig::getAntiAliasing() const
1535
{
1536
  return QSettings().readBoolEntry("/qt/useXft");
1537
}
1538
1539
1488
#endif
1540
#endif
(-)kcontrol/fonts/kxftconfig.h (-1 / +15 lines)
Lines 89-95 Link Here
89
        enum Type
89
        enum Type
90
        {
90
        {
91
            None,
91
            None,
92
            Greyscale,
93
            Rgb,
92
            Rgb,
94
            Bgr,
93
            Bgr,
95
            Vrgb,
94
            Vrgb,
Lines 150-155 Link Here
150
149
151
        bool set;
150
        bool set;
152
    };
151
    };
152
153
    struct AntiAliasing : public Item
154
    {
155
        AntiAliasing(bool s, QDomNode &n) : Item(n), set(s) {}
156
        AntiAliasing(bool s=true)         : set(s)          {}
157
158
        void reset() { Item::reset(); set=true; }
159
160
        bool set;
161
    };
153
#endif
162
#endif
154
163
155
    public:
164
    public:
Lines 190-195 Link Here
190
    void        clearSymbolFamilies()                { clearList(m_symbolFamilies); }
199
    void        clearSymbolFamilies()                { clearList(m_symbolFamilies); }
191
    QStringList getSymbolFamilies()                  { return getList(m_symbolFamilies); }
200
    QStringList getSymbolFamilies()                  { return getList(m_symbolFamilies); }
192
#endif
201
#endif
202
    void        setAntiAliasing(bool set);
203
    bool        getAntiAliasing() const;
193
    bool        changed()                            { return m_madeChanges; }
204
    bool        changed()                            { return m_madeChanges; }
194
    static QString description(SubPixel::Type t);
205
    static QString description(SubPixel::Type t);
195
    static const char * toStr(SubPixel::Type t);
206
    static const char * toStr(SubPixel::Type t);
Lines 215-220 Link Here
215
#endif
226
#endif
216
    void        applySubPixelType();
227
    void        applySubPixelType();
217
    void        applyHintStyle();
228
    void        applyHintStyle();
229
    void        applyAntiAliasing();
218
    void        setHinting(bool set);
230
    void        setHinting(bool set);
219
    void        applyHinting();
231
    void        applyHinting();
220
    void        applyExcludeRange(bool pixel);
232
    void        applyExcludeRange(bool pixel);
Lines 236-241 Link Here
236
#ifdef HAVE_FONTCONFIG
248
#ifdef HAVE_FONTCONFIG
237
    Hint               m_hint;
249
    Hint               m_hint;
238
    Hinting            m_hinting;
250
    Hinting            m_hinting;
251
    AntiAliasing       m_antiAliasing;
252
    bool               aliasingEnabled();
239
#else
253
#else
240
    QPtrList<ListItem> m_symbolFamilies;
254
    QPtrList<ListItem> m_symbolFamilies;
241
#endif
255
#endif
(-)kcontrol/fonts/fonts.h.sav (-2 / +2 lines)
Lines 55-62 public: Link Here
55
55
56
    FontAASettings(QWidget *parent);
56
    FontAASettings(QWidget *parent);
57
57
58
    bool save();
58
    bool save( bool useAA );
59
    void load();
59
    bool load();
60
    void defaults();
60
    void defaults();
61
    int getIndex(KXftConfig::SubPixel::Type spType);
61
    int getIndex(KXftConfig::SubPixel::Type spType);
62
    KXftConfig::SubPixel::Type getSubPixelType();
62
    KXftConfig::SubPixel::Type getSubPixelType();

Return to bug 113637