|
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 |