Exemplo n.º 1
0
void QSysNoteHistory::setupUI()
{
    QHBoxLayout *hlay = new QHBoxLayout(this);
    m_edit = new QTextEdit(this);
    m_edit->setEnabled(true);
    hlay->setMargin(0);
    hlay->setSpacing(0);
    hlay->addWidget(m_edit);
    resize(400,500);
    QFile *f = new QFile("note.dat",this);
    if (!f->exists())
        return;
    if (!f->open(QIODevice::ReadOnly))
        return;
    QString txt;
    txt = QString::fromLocal8Bit(f->readAll());
    QFont font = m_edit->font();
    font.setBold(true);
    font.setKerning(true);
    font.setWeight( font.weight() + 2);
    m_edit->setFont(font);
    m_edit->setTextColor(Qt::red);
    m_edit->setText(txt);
    f->close();
}
Exemplo n.º 2
0
int main(int argc, char **argv)
{
	QGuiApplication app(argc, argv);

	if (app.arguments().size() < 2) {
		qStdOut() << "Usage: fontinfo <family>\n";
		qStdOut() << "       fontinfo -list";
		return -1;
	}

	if (app.arguments().at(1) == "-list") {
		printFontList();
		return 0;
	}

	QFont f;
	f.setStyleHint(QFont::TypeWriter, QFont::StyleStrategy(QFont::PreferDefault | QFont::ForceIntegerMetrics));
	f.setFamily(QStringList(app.arguments().mid(1)).join(" "));
	f.setFixedPitch(true);
	f.setKerning(false);

	printFontInfo(f);
	for (int i=10; i<=18; i++) {
		qStdOut() << "Font size: " << i << endl;
		f.setPointSize(i);
		printFontMetrics(f);
	}
	return 0;
}
Exemplo n.º 3
0
void tst_QTextFormat::testFontStyleSetters()
{
    QTextCharFormat format;

    // test the setters
    format.setFontStyleHint(QFont::Serif);
    QCOMPARE(format.font().styleHint(), QFont::Serif);
    QCOMPARE(format.font().styleStrategy(), QFont::PreferDefault);
    format.setFontStyleStrategy(QFont::PreferOutline);
    QCOMPARE(format.font().styleStrategy(), QFont::PreferOutline);

    // test setting properties through setFont()
    QFont font;
    font.setStyleHint(QFont::SansSerif, QFont::PreferAntialias);
    format.setFont(font);
    QCOMPARE(format.font().styleHint(), QFont::SansSerif);
    QCOMPARE(format.font().styleStrategy(), QFont::PreferAntialias);

    // test kerning
    format.setFontKerning(false);
    QCOMPARE(format.font().kerning(), false);
    format.setFontKerning(true);
    QCOMPARE(format.font().kerning(), true);
    font.setKerning(false);
    format.setFont(font);
    QCOMPARE(format.font().kerning(), false);
}
Exemplo n.º 4
0
void QmitkTextOverlay::UpdateFontProperties( mitk::PropertyList::Pointer pl )
{
    if ( pl.IsNull() )
        return;

    mitk::PropertyList::Pointer propertyList = pl;
    QPalette palette = QPalette();
    QFont font = QFont();

    // get the desired color of the textOverlays
    mitk::ColorProperty::Pointer colorProp =
        dynamic_cast<mitk::ColorProperty*>( propertyList->GetProperty( "overlay.color" ) );

    if ( colorProp.IsNull() )
    {
        colorProp = mitk::ColorProperty::New( 127.0, 196.0, 232.0 );
    }

    mitk::Color color = colorProp->GetColor();
    palette.setColor( QPalette::Foreground, QColor( color[0],color[1],color[2],255 ) );
    palette.setColor( QPalette::Window, Qt::transparent);
    m_Label->setPalette( palette );

    // get the desired opacity of the overlays
    //mitk::FloatProperty::Pointer opacityProperty =
    //  dynamic_cast<mitk::FloatProperty*>( propertyList->GetProperty( "overlay.opacity" ) );

    //if ( opacityProperty.IsNull() )
    //{
    //  m_Label->setWindowOpacity( 1 );
    //}
    //else
    //{
    //  m_Label->setWindowOpacity( opacityProperty->GetValue() );
    //}

    //set the desired font-size of the overlays
    int fontSize = 0;
    if ( !propertyList->GetIntProperty( "overlay.fontSize", fontSize ) )
    {
        fontSize = 9;
    }
    font.setPointSize( fontSize );

    bool useKerning = false;
    if ( !propertyList->GetBoolProperty( "overlay.kerning", useKerning ) )
    {
        useKerning = true;
    }
    font.setKerning( useKerning );

    std::string fontFamily = "";
    if ( !propertyList->GetStringProperty( "overlay.fontFamily", fontFamily ) )
    {
        fontFamily = "Verdana";
    }
    font.setFamily(  QString(fontFamily.c_str()) );

    m_Label->setFont( font );
}
void MozQWidgetFast::paint(QPainter* aPainter,
                           const QStyleOptionGraphicsItem*,
                           QWidget*)
{
  // toolbar height
  int toolbarHeight = 80;
  // Offset of favicon starting from left toolbar edge
  int faviconOffset = 25;
  // favicon size
  int faviconSize = 32;
  // width of left and right TOOLBAR_SPLASH part
  // |------------------------------|
  // |LeftPart|tile...part|RightPart|
  float toolbarPartWidth = 77;
  // width of TOOLBAR_SPLASH part after toolbarPartWidth,
  // that can be used for tiled toolbar area
  int tileWidth = 2;
  // Paint left toolbar part
  aPainter->drawPixmap(QRect(0, 0, toolbarPartWidth, toolbarHeight),
                       mToolbar, QRect(0, 0, toolbarPartWidth, toolbarHeight));

  // Paint Tile pixmap of middle toolbar part
  QPixmap tile(tileWidth, toolbarHeight);
  QPainter p(&tile);
  p.drawPixmap(QRect(0, 0, tileWidth, toolbarHeight), mToolbar,
               QRect(toolbarPartWidth, 0, tileWidth, toolbarHeight));
  aPainter->drawTiledPixmap(QRect(toolbarPartWidth, 0, rect().width() - toolbarPartWidth * 2,
                                  toolbarHeight),
                            tile);
  // Paint Favicon
  aPainter->drawPixmap(QRect(faviconOffset, faviconOffset,
                             faviconSize, faviconSize),
                       mIcon);
  if (!mUrl.isEmpty()) {
    // Height or URL string (font height)
    float urlHeight = 24.0f;
    // Start point of URL string, relative to window 0,0
    int urlOffsetX = 80;
    int urlOffsetY = 48;
    QFont font = aPainter->font();
    font.setPixelSize(urlHeight);
    font.setFamily(QString("Nokia Sans"));
    font.setKerning(true);
    aPainter->setFont(font);
    aPainter->setRenderHint(QPainter::TextAntialiasing, true);
    aPainter->drawText(urlOffsetX, urlOffsetY,
                       aPainter->fontMetrics().elidedText(mUrl, Qt::ElideRight, rect().width() - urlOffsetX * 2));
  }

  // Paint Right toolbar part
  aPainter->drawPixmap(QRect(rect().width() - toolbarPartWidth,
                             0, toolbarPartWidth,
                             toolbarHeight),
                       mToolbar,
                       QRect(mToolbar.width() - toolbarPartWidth, 0,
                             toolbarPartWidth, toolbarHeight));

  nsFastStartup::GetSingleton()->painted();
}
Exemplo n.º 6
0
/**
 * Get the font with the given name
 *
 */
GuiFont
gui_mch_get_font(char_u *name, int giveErrorIfMissing)
{
	QString family = (char*)name;
	QFont font;
	font.setStyleHint(QFont::TypeWriter);

	if ( name == NULL ) { // Fallback font
		font.setFamily("Monospace");
		font.setPointSize(10);
		font.setKerning(false);
		return new QFont(font);
	}

	bool ok;
	int size = family.section(' ', -1).trimmed().toInt(&ok);
	if ( ok ) {
		QString realname = family.section(' ', 0, -2).trimmed();
		font.setFamily(realname);
		font.setPointSize(size);
	} else if ( !font.fromString((char*)name) ) {
		font.setRawName((char*)name);
	}

	// I expected QFont::exactMatch to do this - but I was wrong
	// FIXME: this needs further testing
    // This makes it impossible to set the font to "Monospace".
	if ( QFontInfo(font).family() != font.family() && giveErrorIfMissing ) {
        QString errmsg;
        QTextStream(&errmsg) << "Font called "
            << font.family() << " is actually called "
            << QFontInfo(font).family();
        
        EMSG2(e_font, errmsg.toUtf8().data());
		return NOFONT;
	}

	font.setFixedPitch(true);
	font.setBold(false);
	font.setItalic(false);
	font.setKerning(false);

	return new QFont(font);
}
Exemplo n.º 7
0
QFont ValueMap::readFontEntry(const QString& k, const QFont* defaultVal )
{
   QFont f = *defaultVal;
   std::map<QString,QString>::iterator i = m_map.find( k );
   if ( i!=m_map.end() )
   {
      f.setFamily( subSection( i->second, 0, ',' ) );
      f.setPointSize( subSection( i->second, 1, ',' ).toInt() );
      f.setBold( subSection( i->second, 2, ',' )=="bold" );
   }
   f.setKerning(false);
   return f;
}
Exemplo n.º 8
0
void About::Start()
{
    ds = false;

    ui->ApplicationNameLabel->setText(QApplication::applicationName());

    QFont font;
    font.setPointSize(ui->ApplicationNameLabel->font().pointSize() + 2);
    font.setBold(true);
    font.setKerning(true);

    ui->ApplicationNameLabel->setFont(font);

    if(SLSettings::Language() == QLocale::Persian)
    {
        QString Version = QApplication::applicationVersion();
        Version.replace("0", "۰");
        Version.replace("1", "۱");
        Version.replace("2", "۲");
        Version.replace("3", "۳");
        Version.replace("4", "۴");
        Version.replace("5", "۵");
        Version.replace("6", "۶");
        Version.replace("7", "۷");
        Version.replace("8", "۸");
        Version.replace("9", "۹");
        Version.replace(".", "٫");

        ui->ApplicationVersionLabel->setText(tr("Version") + " " + Version);
    }
    else
    {
        ui->ApplicationVersionLabel->setText(tr("Version") + " " + QApplication::applicationVersion());
    }

    ui->ApplicationBuiltOnDateLabel->setText(QString(tr("Built on") + " " __DATE__ " " __TIME__).replace("  "," "));
}
Exemplo n.º 9
0
QtnPropertyDelegateQFont::QtnPropertyDelegateQFont(QtnPropertyQFontBase& owner)
    : QtnPropertyDelegateTypedEx<QtnPropertyQFontBase>(owner)
{
    QtnPropertyQStringCallback* propertyFamily = new QtnPropertyQStringCallback(0);
    addSubProperty(propertyFamily);
    propertyFamily->setName(owner.tr("Family"));
    propertyFamily->setDescription(owner.tr("Font Family for %1.").arg(owner.name()));
    propertyFamily->setCallbackValueGet([&owner]()->QString {
        return owner.value().family();
    });
    propertyFamily->setCallbackValueSet([&owner](QString value) {
        QFont font = owner.value();
        font.setFamily(value);
        owner.setValue(font);
    });
    QtnPropertyDelegateInfo delegate;
    delegate.name = "List";
    QFontDatabase fDB;
    delegate.attributes["items"] = fDB.families();
    propertyFamily->setDelegate(delegate);

    QtnPropertyUIntCallback* propertyPointSize = new QtnPropertyUIntCallback(0);
    addSubProperty(propertyPointSize);
    propertyPointSize->setName(owner.tr("PointSize"));
    propertyPointSize->setDescription(owner.tr("Point size for %1.").arg(owner.name()));
    propertyPointSize->setCallbackValueGet([&owner]()->quint32 {
        int ps = owner.value().pointSize();
        return ps != -1 ? ps : 1;
    });
    propertyPointSize->setCallbackValueSet([&owner](quint32 value) {
        QFont font = owner.value();
        font.setPointSize((int)value);
        owner.setValue(font);
    });
    propertyPointSize->setMinValue(1);
    propertyPointSize->setMaxValue((quint32)std::numeric_limits<int>::max());

    QtnPropertyBoolCallback* propertyBold = new QtnPropertyBoolCallback(0);
    addSubProperty(propertyBold);
    propertyBold->setName(owner.tr("Bold"));
    propertyBold->setDescription(owner.tr("Bold flag for %1").arg(owner.name()));
    propertyBold->setCallbackValueGet([&owner]()->bool {
        return owner.value().bold();
    });
    propertyBold->setCallbackValueSet([&owner](bool value) {
        QFont font = owner.value();
        font.setBold(value);
        owner.setValue(font);
    });

    QtnPropertyBoolCallback* propertyItalic = new QtnPropertyBoolCallback(0);
    addSubProperty(propertyItalic);
    propertyItalic->setName(owner.tr("Italic"));
    propertyItalic->setDescription(owner.tr("Italic flag for %1").arg(owner.name()));
    propertyItalic->setCallbackValueGet([&owner]()->bool {
        return owner.value().italic();
    });
    propertyItalic->setCallbackValueSet([&owner](bool value) {
        QFont font = owner.value();
        font.setItalic(value);
        owner.setValue(font);
    });

    QtnPropertyBoolCallback* propertyUnderline = new QtnPropertyBoolCallback(0);
    addSubProperty(propertyUnderline);
    propertyUnderline->setName(owner.tr("Underline"));
    propertyUnderline->setDescription(owner.tr("Underline flag for %1").arg(owner.name()));
    propertyUnderline->setCallbackValueGet([&owner]()->bool {
        return owner.value().underline();
    });
    propertyUnderline->setCallbackValueSet([&owner](bool value) {
        QFont font = owner.value();
        font.setUnderline(value);
        owner.setValue(font);
    });

    QtnPropertyBoolCallback* propertyStrikeout = new QtnPropertyBoolCallback(0);
    addSubProperty(propertyStrikeout);
    propertyStrikeout->setName(owner.tr("Strikeout"));
    propertyStrikeout->setDescription(owner.tr("Strikeout flag for %1").arg(owner.name()));
    propertyStrikeout->setCallbackValueGet([&owner]()->bool {
        return owner.value().strikeOut();
    });
    propertyStrikeout->setCallbackValueSet([&owner](bool value) {
        QFont font = owner.value();
        font.setStrikeOut(value);
        owner.setValue(font);
    });

    QtnPropertyBoolCallback* propertyKerning = new QtnPropertyBoolCallback(0);
    addSubProperty(propertyKerning);
    propertyKerning->setName(owner.tr("Kerning"));
    propertyKerning->setDescription(owner.tr("Kerning flag for %1").arg(owner.name()));
    propertyKerning->setCallbackValueGet([&owner]()->bool {
        return owner.value().kerning();
    });
    propertyKerning->setCallbackValueSet([&owner](bool value) {
        QFont font = owner.value();
        font.setKerning(value);
        owner.setValue(font);
    });

    QtnPropertyEnumCallback* propertyAntialiasing = new QtnPropertyEnumCallback(0);
    addSubProperty(propertyAntialiasing);
    propertyAntialiasing->setName(owner.tr("Antialiasing"));
    propertyAntialiasing->setDescription(owner.tr("Antialiasing flag for %1.").arg(owner.name()));
    propertyAntialiasing->setEnumInfo(styleStrategyEnum());
    propertyAntialiasing->setCallbackValueGet([&owner]()->QtnEnumValueType {
        return owner.value().styleStrategy();
    });
    propertyAntialiasing->setCallbackValueSet([&owner](QtnEnumValueType value) {
        QFont font = owner.value();
        font.setStyleStrategy((QFont::StyleStrategy)value);
        owner.setValue(font);
    });
}
Exemplo n.º 10
0
// Convert simple DOM types
QVariant domPropertyToVariant(const DomProperty *p)
{
    // requires non-const virtual nameToIcon, etc.
    switch(p->kind()) {
    case DomProperty::Bool:
        return QVariant(p->elementBool() == QFormBuilderStrings::instance().trueValue);

    case DomProperty::Cstring:
        return QVariant(p->elementCstring().toUtf8());

    case DomProperty::Point: {
        const DomPoint *point = p->elementPoint();
        return QVariant(QPoint(point->elementX(), point->elementY()));
    }

    case DomProperty::PointF: {
        const DomPointF *pointf = p->elementPointF();
        return QVariant(QPointF(pointf->elementX(), pointf->elementY()));
    }

    case DomProperty::Size: {
        const DomSize *size = p->elementSize();
        return QVariant(QSize(size->elementWidth(), size->elementHeight()));
    }

    case DomProperty::SizeF: {
        const DomSizeF *sizef = p->elementSizeF();
        return QVariant(QSizeF(sizef->elementWidth(), sizef->elementHeight()));
    }

    case DomProperty::Rect: {
        const DomRect *rc = p->elementRect();
        const QRect g(rc->elementX(), rc->elementY(), rc->elementWidth(), rc->elementHeight());
        return QVariant(g);
    }

    case DomProperty::RectF: {
        const DomRectF *rcf = p->elementRectF();
        const QRectF g(rcf->elementX(), rcf->elementY(), rcf->elementWidth(), rcf->elementHeight());
        return QVariant(g);
    }

    case DomProperty::String:
        return QVariant(p->elementString()->text());

    case DomProperty::Number:
        return QVariant(p->elementNumber());

    case DomProperty::UInt:
        return QVariant(p->elementUInt());

    case DomProperty::LongLong:
        return QVariant(p->elementLongLong());

    case DomProperty::ULongLong:
        return QVariant(p->elementULongLong());

    case DomProperty::Double:
        return QVariant(p->elementDouble());

    case DomProperty::Char: {
        const DomChar *character = p->elementChar();
        const QChar c(character->elementUnicode());
        return QVariant::fromValue(c);
    }

    case DomProperty::Color: {
        const DomColor *color = p->elementColor();
        QColor c(color->elementRed(), color->elementGreen(), color->elementBlue());
        if (color->hasAttributeAlpha())
            c.setAlpha(color->attributeAlpha());
        return QVariant::fromValue(c);
    }

    case DomProperty::Font: {
        const DomFont *font = p->elementFont();

        QFont f;
        if (font->hasElementFamily() && !font->elementFamily().isEmpty())
            f.setFamily(font->elementFamily());
        if (font->hasElementPointSize() && font->elementPointSize() > 0)
            f.setPointSize(font->elementPointSize());
        if (font->hasElementWeight() && font->elementWeight() > 0)
            f.setWeight(font->elementWeight());
        if (font->hasElementItalic())
            f.setItalic(font->elementItalic());
        if (font->hasElementBold())
            f.setBold(font->elementBold());
        if (font->hasElementUnderline())
            f.setUnderline(font->elementUnderline());
        if (font->hasElementStrikeOut())
            f.setStrikeOut(font->elementStrikeOut());
        if (font->hasElementKerning())
            f.setKerning(font->elementKerning());
        if (font->hasElementAntialiasing())
            f.setStyleStrategy(font->elementAntialiasing() ? QFont::PreferDefault : QFont::NoAntialias);
        if (font->hasElementStyleStrategy()) {
            f.setStyleStrategy(enumKeyOfObjectToValue<QAbstractFormBuilderGadget, QFont::StyleStrategy>("styleStrategy", font->elementStyleStrategy().toLatin1()));
        }
        return QVariant::fromValue(f);
    }

    case DomProperty::Date: {
        const DomDate *date = p->elementDate();
        return QVariant(QDate(date->elementYear(), date->elementMonth(), date->elementDay()));
    }

    case DomProperty::Time: {
        const DomTime *t = p->elementTime();
        return QVariant(QTime(t->elementHour(), t->elementMinute(), t->elementSecond()));
    }

    case DomProperty::DateTime: {
        const DomDateTime *dateTime = p->elementDateTime();
        const QDate d(dateTime->elementYear(), dateTime->elementMonth(), dateTime->elementDay());
        const QTime tm(dateTime->elementHour(), dateTime->elementMinute(), dateTime->elementSecond());
        return QVariant(QDateTime(d, tm));
    }

    case DomProperty::Url: {
        const DomUrl *url = p->elementUrl();
        return QVariant(QUrl(url->elementString()->text()));
    }

#ifndef QT_NO_CURSOR
    case DomProperty::Cursor:
        return QVariant::fromValue(QCursor(static_cast<Qt::CursorShape>(p->elementCursor())));

    case DomProperty::CursorShape:
        return QVariant::fromValue(QCursor(enumKeyOfObjectToValue<QAbstractFormBuilderGadget, Qt::CursorShape>("cursorShape", p->elementCursorShape().toLatin1())));
#endif

    case DomProperty::Locale: {
        const DomLocale *locale = p->elementLocale();
        return QVariant::fromValue(QLocale(enumKeyOfObjectToValue<QAbstractFormBuilderGadget, QLocale::Language>("language", locale->attributeLanguage().toLatin1()),
                    enumKeyOfObjectToValue<QAbstractFormBuilderGadget, QLocale::Country>("country", locale->attributeCountry().toLatin1())));
    }
    case DomProperty::SizePolicy: {
        const DomSizePolicy *sizep = p->elementSizePolicy();

        QSizePolicy sizePolicy;
        sizePolicy.setHorizontalStretch(sizep->elementHorStretch());
        sizePolicy.setVerticalStretch(sizep->elementVerStretch());

        const QMetaEnum sizeType_enum = metaEnum<QAbstractFormBuilderGadget>("sizeType");

        if (sizep->hasElementHSizeType()) {
            sizePolicy.setHorizontalPolicy((QSizePolicy::Policy) sizep->elementHSizeType());
        } else if (sizep->hasAttributeHSizeType()) {
            const QSizePolicy::Policy sp = enumKeyToValue<QSizePolicy::Policy>(sizeType_enum, sizep->attributeHSizeType().toLatin1());
            sizePolicy.setHorizontalPolicy(sp);
        }

        if (sizep->hasElementVSizeType()) {
            sizePolicy.setVerticalPolicy((QSizePolicy::Policy) sizep->elementVSizeType());
        } else if (sizep->hasAttributeVSizeType()) {
            const  QSizePolicy::Policy sp = enumKeyToValue<QSizePolicy::Policy>(sizeType_enum, sizep->attributeVSizeType().toLatin1());
            sizePolicy.setVerticalPolicy(sp);
        }

        return QVariant::fromValue(sizePolicy);
    }

    case DomProperty::StringList:
        return QVariant(p->elementStringList()->elementString());

    default:
        uiLibWarning(QCoreApplication::translate("QFormBuilder", "Reading properties of the type %1 is not supported yet.").arg(p->kind()));
        break;
    }

    return QVariant();
}
Exemplo n.º 11
0
void tst_QFont::serialize_data()
{
    QTest::addColumn<QFont>("font");
    // The version in which the tested feature was added.
    QTest::addColumn<QDataStream::Version>("minimumStreamVersion");

    QFont basicFont;
    // Versions <= Qt 2.1 had broken point size serialization,
    // so we set an integer point size.
    basicFont.setPointSize(9);
    // Versions <= Qt 5.4 didn't serialize styleName, so clear it
    basicFont.setStyleName(QString());

    QFont font = basicFont;
    QTest::newRow("defaultConstructed") << font << QDataStream::Qt_1_0;

    font.setLetterSpacing(QFont::AbsoluteSpacing, 105);
    QTest::newRow("letterSpacing") << font << QDataStream::Qt_4_5;

    font = basicFont;
    font.setWordSpacing(50.0);
    QTest::newRow("wordSpacing") << font << QDataStream::Qt_4_5;

    font = basicFont;
    font.setPointSize(20);
    QTest::newRow("pointSize") << font << QDataStream::Qt_1_0;

    font = basicFont;
    font.setPixelSize(32);
    QTest::newRow("pixelSize") << font << QDataStream::Qt_3_0;

    font = basicFont;
    font.setStyleHint(QFont::Monospace);
    QTest::newRow("styleHint") << font << QDataStream::Qt_1_0;

    font = basicFont;
    font.setStretch(4000);
    QTest::newRow("stretch") << font << QDataStream::Qt_4_3;

    font = basicFont;
    font.setWeight(99);
    QTest::newRow("weight") << font << QDataStream::Qt_1_0;

    font = basicFont;
    font.setUnderline(true);
    QTest::newRow("underline") << font << QDataStream::Qt_1_0;

    font = basicFont;
    font.setStrikeOut(true);
    QTest::newRow("strikeOut") << font << QDataStream::Qt_1_0;

    font = basicFont;
    font.setFixedPitch(true);
    // This fails for versions less than this, as ignorePitch is set to false
    // whenever setFixedPitch() is called, but ignorePitch is considered an
    // extended bit, which were apparently not available until 4.4.
    QTest::newRow("fixedPitch") << font << QDataStream::Qt_4_4;

    font = basicFont;
    font.setLetterSpacing(QFont::AbsoluteSpacing, 10);
    // Fails for 4.4 because letterSpacing wasn't read until 4.5.
    QTest::newRow("letterSpacing") << font << QDataStream::Qt_4_5;

    font = basicFont;
    font.setKerning(false);
    QTest::newRow("kerning") << font << QDataStream::Qt_4_0;

    font = basicFont;
    font.setStyleStrategy(QFont::NoFontMerging);
    // This wasn't read properly until 5.4.
    QTest::newRow("styleStrategy") << font << QDataStream::Qt_5_4;

    font = basicFont;
    font.setHintingPreference(QFont::PreferFullHinting);
    // This wasn't read until 5.4.
    QTest::newRow("hintingPreference") << font << QDataStream::Qt_5_4;

    font = basicFont;
    font.setStyleName("Regular Black Condensed");
    // This wasn't read until 5.4.
    QTest::newRow("styleName") << font << QDataStream::Qt_5_4;

    font = basicFont;
    font.setCapitalization(QFont::AllUppercase);
    // This wasn't read until 5.6.
    QTest::newRow("capitalization") << font << QDataStream::Qt_5_6;
}
Exemplo n.º 12
0
void QFontProto::setKerning(bool enable)
{
  QFont *item = qscriptvalue_cast<QFont*>(thisObject());
  if (item)
    item->setKerning(enable);
}
Exemplo n.º 13
0
    static QFont fontFromObject(QQmlV4Handle object, QV4::ExecutionEngine *v4, bool *ok)
    {
        if (ok)
            *ok = false;
        QFont retn;
        QV4::Scope scope(v4);
        QV4::ScopedObject obj(scope, object);
        if (!obj) {
            if (ok)
                *ok = false;
            return retn;
        }

        QV4::ScopedString s(scope);

        QV4::ScopedValue vbold(scope, obj->get((s = v4->newString(QStringLiteral("bold")))));
        QV4::ScopedValue vcap(scope, obj->get((s = v4->newString(QStringLiteral("capitalization")))));
        QV4::ScopedValue vfam(scope, obj->get((s = v4->newString(QStringLiteral("family")))));
        QV4::ScopedValue vstyle(scope, obj->get((s = v4->newString(QStringLiteral("styleName")))));
        QV4::ScopedValue vital(scope, obj->get((s = v4->newString(QStringLiteral("italic")))));
        QV4::ScopedValue vlspac(scope, obj->get((s = v4->newString(QStringLiteral("letterSpacing")))));
        QV4::ScopedValue vpixsz(scope, obj->get((s = v4->newString(QStringLiteral("pixelSize")))));
        QV4::ScopedValue vpntsz(scope, obj->get((s = v4->newString(QStringLiteral("pointSize")))));
        QV4::ScopedValue vstrk(scope, obj->get((s = v4->newString(QStringLiteral("strikeout")))));
        QV4::ScopedValue vundl(scope, obj->get((s = v4->newString(QStringLiteral("underline")))));
        QV4::ScopedValue vweight(scope, obj->get((s = v4->newString(QStringLiteral("weight")))));
        QV4::ScopedValue vwspac(scope, obj->get((s = v4->newString(QStringLiteral("wordSpacing")))));
        QV4::ScopedValue vhint(scope, obj->get((s = v4->newString(QStringLiteral("hintingPreference")))));
        QV4::ScopedValue vkerning(scope, obj->get((s = v4->newString(QStringLiteral("kerning")))));
        QV4::ScopedValue vshaping(scope, obj->get((s = v4->newString(QStringLiteral("preferShaping")))));

        // pull out the values, set ok to true if at least one valid field is given.
        if (vbold->isBoolean()) {
            retn.setBold(vbold->booleanValue());
            if (ok) *ok = true;
        }
        if (vcap->isInt32()) {
            retn.setCapitalization(static_cast<QFont::Capitalization>(vcap->integerValue()));
            if (ok) *ok = true;
        }
        if (vfam->isString()) {
            retn.setFamily(vfam->toQString());
            if (ok) *ok = true;
        }
        if (vstyle->isString()) {
            retn.setStyleName(vstyle->toQString());
            if (ok) *ok = true;
        }
        if (vital->isBoolean()) {
            retn.setItalic(vital->booleanValue());
            if (ok) *ok = true;
        }
        if (vlspac->isNumber()) {
            retn.setLetterSpacing(QFont::AbsoluteSpacing, vlspac->asDouble());
            if (ok) *ok = true;
        }
        if (vpixsz->isInt32()) {
            retn.setPixelSize(vpixsz->integerValue());
            if (ok) *ok = true;
        }
        if (vpntsz->isNumber()) {
            retn.setPointSize(vpntsz->asDouble());
            if (ok) *ok = true;
        }
        if (vstrk->isBoolean()) {
            retn.setStrikeOut(vstrk->booleanValue());
            if (ok) *ok = true;
        }
        if (vundl->isBoolean()) {
            retn.setUnderline(vundl->booleanValue());
            if (ok) *ok = true;
        }
        if (vweight->isInt32()) {
            retn.setWeight(static_cast<QFont::Weight>(vweight->integerValue()));
            if (ok) *ok = true;
        }
        if (vwspac->isNumber()) {
            retn.setWordSpacing(vwspac->asDouble());
            if (ok) *ok = true;
        }
        if (vhint->isInt32()) {
            retn.setHintingPreference(static_cast<QFont::HintingPreference>(vhint->integerValue()));
            if (ok) *ok = true;
        }
        if (vkerning->isBoolean()) {
            retn.setKerning(vkerning->booleanValue());
            if (ok) *ok = true;
        }
        if (vshaping->isBoolean()) {
            bool enable = vshaping->booleanValue();
            if (enable)
                retn.setStyleStrategy(static_cast<QFont::StyleStrategy>(retn.styleStrategy() & ~QFont::PreferNoShaping));
            else
                retn.setStyleStrategy(static_cast<QFont::StyleStrategy>(retn.styleStrategy() | QFont::PreferNoShaping));
        }

        return retn;
    }
Exemplo n.º 14
0
/**
 * Get the font with the given name
 *
 */
GuiFont
gui_mch_get_font(char_u *name, int giveErrorIfMissing)
{
	QString family = VimWrapper::convertFrom(name);
	QFont font;
	font.setStyleHint(QFont::TypeWriter);
	font.setStyleStrategy(QFont::StyleStrategy(QFont::PreferDefault | QFont::ForceIntegerMetrics) );

	if ( name == NULL ) { // Fallback font
		font.setFamily("Monospace");
		font.setFixedPitch(true);
		font.setPointSize(10);
		font.setKerning(false);
		return new QFont(font);
	}

	bool ok;
	int size = family.section(' ', -1).trimmed().toInt(&ok);
	if ( ok ) {
		QString realname = family.section(' ', 0, -2).trimmed();
		font.setFamily(realname);
		font.setPointSize(size);
	} else if ( !font.fromString(family) ) {
		font.setRawName(family);
	}

	font.setBold(false);
	font.setItalic(false);
	font.setKerning(false);

	//
	// When you ask for a font you may get a different font. This happens
	// when the font system does some form of substitution (such as as virtual fonts).
	// This bit of code checks if the font that is requested is the font that is returned.
	//
	// In a nutshell this is what is done:
	// - If the font exists and has fixed width, load it
	// - If the font does not exist or is not monospace, don't load the font
	// + If giveErrorIfMissing is true, throw an error message, otherwise fail silently
	// * We open an exception for the Monospace font, we ALWAYS load the monospace font
	//
	QFontInfo fi(font);

	if ( fi.family().compare(font.family(), Qt::CaseInsensitive) != 0 && 
		font.family().compare("Monospace", Qt::CaseInsensitive) != 0) {

		if ( giveErrorIfMissing ) {
			EMSG2(e_font, name);
		}
		return NOFONT;
	}

	if ( !fi.fixedPitch() ) {
		if ( giveErrorIfMissing ) {
			EMSG2(e_font, name);
		}
		return NOFONT;
	}

	return new QFont(font);
}