src/hbcore/utils/hbfontspec.cpp
changeset 5 627c4a0fd0e7
parent 1 f7ac710697a9
child 7 923ff622b8b9
equal deleted inserted replaced
3:11d3954df52a 5:627c4a0fd0e7
    31 
    31 
    32 #include <QVariant>
    32 #include <QVariant>
    33 #include <QFont>
    33 #include <QFont>
    34 
    34 
    35 /*!
    35 /*!
    36 	@stable
    36     @stable
    37     @hbcore
    37     @hbcore
    38     \class HbFontSpec
    38     \class HbFontSpec
    39     \brief HbFontSpec is used to request a system font.
    39     \brief HbFontSpec is used to request a system font.
    40 
    40 
    41     It introduces a list of font roles, which can be used to request system
    41     It introduces a list of font roles, which can be used to request system
   140 qreal HbFontSpecPrivate::textHeight() const
   140 qreal HbFontSpecPrivate::textHeight() const
   141 {
   141 {
   142 #ifdef HB_BOOTSTRAPPED
   142 #ifdef HB_BOOTSTRAPPED
   143     return 0;
   143     return 0;
   144 #else
   144 #else
   145     if ( (mRole != HbFontSpec::Undefined) && (mTextHeight < 0) ) {
   145     if ((mRole != HbFontSpec::Undefined) && (mTextHeight < 0)) {
   146         qreal parameterValue;
   146         qreal parameterValue;
   147         QString parameterName;
   147         QString parameterName;
   148         switch (mRole){
   148         switch (mRole) {
   149             case HbFontSpec::Primary:
   149         case HbFontSpec::Primary:
   150                 parameterName = "hb-param-text-height-primary";
   150             parameterName = "hb-param-text-height-primary";
   151                 break;
   151             break;
   152             case HbFontSpec::Secondary:
   152         case HbFontSpec::Secondary:
   153                 parameterName = "hb-param-text-height-secondary";
   153             parameterName = "hb-param-text-height-secondary";
   154                 break;
   154             break;
   155             case HbFontSpec::Title:    
   155         case HbFontSpec::Title:
   156                 parameterName = "hb-param-text-height-title";
   156             parameterName = "hb-param-text-height-title";
   157                 break;
   157             break;
   158             case HbFontSpec::PrimarySmall:
   158         case HbFontSpec::PrimarySmall:
   159                 parameterName = "hb-param-text-height-tiny";
   159             parameterName = "hb-param-text-height-tiny";
   160                 break;
   160             break;
   161             case HbFontSpec::Digital:
   161         case HbFontSpec::Digital:
   162             default: // Usage of Secondary as the default system typeface
   162         default: // Usage of Secondary as the default system typeface
   163                 parameterName = "hb-param-text-height-secondary";
   163             parameterName = "hb-param-text-height-secondary";
   164                 break;
   164             break;
   165         }
   165         }
   166         HbInstance::instance()->style()->parameter( parameterName, parameterValue );
   166         HbInstance::instance()->style()->parameter(parameterName, parameterValue);
   167         mTextHeight = parameterValue;
   167         mTextHeight = parameterValue;
   168     }
   168     }
   169 	return mTextHeight;
   169     return mTextHeight;
   170 #endif
   170 #endif
   171 }
   171 }
   172 
   172 
   173 /*!
   173 /*!
   174 \internal
   174 \internal
   176 QFont HbFontSpecPrivate::font() const
   176 QFont HbFontSpecPrivate::font() const
   177 {
   177 {
   178 #ifdef HB_BOOTSTRAPPED
   178 #ifdef HB_BOOTSTRAPPED
   179     return QFont();
   179     return QFont();
   180 #else
   180 #else
   181     if ( mRole == HbFontSpec::Undefined ) {
   181     if (mRole == HbFontSpec::Undefined) {
   182         return QFont();
   182         return QFont();
   183     }
   183     }
   184     QString typefaceFamily;
   184     QString typefaceFamily;
   185     int weight;
   185     int weight;
   186 
   186 
   191 
   191 
   192     font.setWeight(weight);
   192     font.setWeight(weight);
   193 
   193 
   194     // Sets default size if text height is not set explicitly.
   194     // Sets default size if text height is not set explicitly.
   195     qreal height = textHeight();
   195     qreal height = textHeight();
   196 	int downSizedSize = tInfo->textHeightToSizeInPixels(typefaceFamily, weight, height);
   196     int downSizedSize = tInfo->textHeightToSizeInPixels(typefaceFamily, weight, height);
   197     font.setPixelSize(downSizedSize);
   197     font.setPixelSize(downSizedSize);
   198 
   198 
   199     return font;
   199     return font;
   200 #endif
   200 #endif
   201 }
   201 }
   210 }
   210 }
   211 
   211 
   212 /*!
   212 /*!
   213     Constructs a new font spec with the given font \a role.
   213     Constructs a new font spec with the given font \a role.
   214 */
   214 */
   215 HbFontSpec::HbFontSpec(HbFontSpec::Role role) 
   215 HbFontSpec::HbFontSpec(HbFontSpec::Role role)
   216     : d(new HbFontSpecPrivate())
   216     : d(new HbFontSpecPrivate())
   217 {
   217 {
   218     d->mRole = role;
   218     d->mRole = role;
   219 }
   219 }
   220 
   220 
   305 
   305 
   306 /*!
   306 /*!
   307     Returns true if this fontSpec is equal to \a other fontSpec; otherwise returns false.
   307     Returns true if this fontSpec is equal to \a other fontSpec; otherwise returns false.
   308 */
   308 */
   309 bool HbFontSpec::operator==(const HbFontSpec &other) const
   309 bool HbFontSpec::operator==(const HbFontSpec &other) const
   310 {    
   310 {
   311     return ((d->mRole == other.d->mRole)
   311     return ((d->mRole == other.d->mRole)
   312         && qFuzzyCompare(d->textHeight(), other.d->textHeight()));
   312             && qFuzzyCompare(d->textHeight(), other.d->textHeight()));
   313 }
   313 }
   314 
   314 
   315 /*!
   315 /*!
   316     Returns true if this fontSpec is not equal to \a other fontSpec; otherwise returns false.
   316     Returns true if this fontSpec is not equal to \a other fontSpec; otherwise returns false.
   317 */
   317 */
   327 
   327 
   328     \sa HbFontSpec::setTextHeight
   328     \sa HbFontSpec::setTextHeight
   329 */
   329 */
   330 qreal HbFontSpec::textHeight() const
   330 qreal HbFontSpec::textHeight() const
   331 {
   331 {
   332 	return d->textHeight();
   332     return d->textHeight();
   333 }
   333 }
   334 
   334 
   335 /*!
   335 /*!
   336     Sets the height of the text into which the requested font is to fit.
   336     Sets the height of the text into which the requested font is to fit.
   337     When the \a font method is called, the returned font will have been
   337     When the \a font method is called, the returned font will have been