Fix selection of fonts based on styleName
By carrying the styleName through from QFontDef to bestFoundry and giving it to bestStyle that can use it we can accurately match fonts based on styleName. This makes it possible to match styles such as DejaVu Sans Condensed and Ubuntu Medium. The example fontsampler is updated so it can actually sample all the different styles it lists. Change-Id: I381effc74130311f98794cd07d30be10dee4fe45 Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>bb10
parent
b3431a9553
commit
a0b021d136
|
|
@ -143,7 +143,9 @@ void MainWindow::showFont(QTreeWidgetItem *item)
|
|||
QString oldText = textEdit->toPlainText().trimmed();
|
||||
bool modified = textEdit->document()->isModified();
|
||||
textEdit->clear();
|
||||
textEdit->document()->setDefaultFont(QFont(family, 32, weight, italic));
|
||||
QFont font(family, 32, weight, italic);
|
||||
font.setStyleName(style);
|
||||
textEdit->document()->setDefaultFont(font);
|
||||
|
||||
QTextCursor cursor = textEdit->textCursor();
|
||||
QTextBlockFormat blockFormat;
|
||||
|
|
@ -324,6 +326,7 @@ void MainWindow::printPage(int index, QPainter *painter, QPrinter *printer)
|
|||
// Calculate the maximum width and total height of the text.
|
||||
foreach (int size, sampleSizes) {
|
||||
QFont font(family, size, weight, italic);
|
||||
font.setStyleName(style);
|
||||
font = QFont(font, painter->device());
|
||||
QFontMetricsF fontMetrics(font);
|
||||
QRectF rect = fontMetrics.boundingRect(
|
||||
|
|
@ -357,6 +360,7 @@ void MainWindow::printPage(int index, QPainter *painter, QPrinter *printer)
|
|||
// Draw each line of text.
|
||||
foreach (int size, sampleSizes) {
|
||||
QFont font(family, size, weight, italic);
|
||||
font.setStyleName(style);
|
||||
font = QFont(font, painter->device());
|
||||
QFontMetricsF fontMetrics(font);
|
||||
QRectF rect = fontMetrics.boundingRect(QString("%1 %2").arg(
|
||||
|
|
|
|||
|
|
@ -931,7 +931,7 @@ static
|
|||
unsigned int bestFoundry(int script, unsigned int score, int styleStrategy,
|
||||
const QtFontFamily *family, const QString &foundry_name,
|
||||
QtFontStyle::Key styleKey, int pixelSize, char pitch,
|
||||
QtFontDesc *desc, int force_encoding_id)
|
||||
QtFontDesc *desc, int force_encoding_id, QString styleName = QString())
|
||||
{
|
||||
Q_UNUSED(force_encoding_id);
|
||||
Q_UNUSED(script);
|
||||
|
|
@ -953,7 +953,7 @@ unsigned int bestFoundry(int script, unsigned int score, int styleStrategy,
|
|||
FM_DEBUG(" looking for matching style in foundry '%s' %d",
|
||||
foundry->name.isEmpty() ? "-- none --" : foundry->name.toLatin1().constData(), foundry->count);
|
||||
|
||||
QtFontStyle *style = bestStyle(foundry, styleKey);
|
||||
QtFontStyle *style = bestStyle(foundry, styleKey, styleName);
|
||||
|
||||
if (!style->smoothScalable && (styleStrategy & QFont::ForceOutline)) {
|
||||
FM_DEBUG(" ForceOutline set, but not smoothly scalable");
|
||||
|
|
@ -1140,13 +1140,13 @@ static int match(int script, const QFontDef &request,
|
|||
unsigned int newscore =
|
||||
bestFoundry(script, score, request.styleStrategy,
|
||||
test.family, foundry_name, styleKey, request.pixelSize, pitch,
|
||||
&test, force_encoding_id);
|
||||
&test, force_encoding_id, request.styleName);
|
||||
if (test.foundry == 0) {
|
||||
// the specific foundry was not found, so look for
|
||||
// any foundry matching our requirements
|
||||
newscore = bestFoundry(script, score, request.styleStrategy, test.family,
|
||||
QString(), styleKey, request.pixelSize,
|
||||
pitch, &test, force_encoding_id);
|
||||
pitch, &test, force_encoding_id, request.styleName);
|
||||
}
|
||||
|
||||
if (newscore < score) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue