LCOV - code coverage report
Current view: top level - vcl/source/font - PhysicalFontFace.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 88 119 73.9 %
Date: 2014-04-11 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <sal/types.h>
      21             : 
      22             : #include <tools/fontenum.hxx>
      23             : 
      24             : #include "outfont.hxx"
      25             : 
      26             : #include "PhysicalFontFace.hxx"
      27             : 
      28       96390 : PhysicalFontFace::PhysicalFontFace( const ImplDevFontAttributes& rDFA, int nMagic )
      29             :     : ImplDevFontAttributes( rDFA )
      30             :     , mnWidth(0)
      31             :     , mnHeight(0)
      32             :     , mnMagic( nMagic )
      33       96390 :     , mpNext( NULL )
      34             : {
      35             :     // StarSymbol is a unicode font, but it still deserves the symbol flag
      36       96390 :     if( !IsSymbolFont() )
      37       95472 :         if ( IsStarSymbol( GetFamilyName() ) )
      38         459 :             SetSymbolFlag( true );
      39       96390 : }
      40             : 
      41      879162 : sal_Int32 PhysicalFontFace::CompareIgnoreSize( const PhysicalFontFace& rOther ) const
      42             : {
      43             :     // compare their width, weight, italic, style name and family name
      44      879162 :     if( GetWidthType() < rOther.GetWidthType() )
      45         642 :         return -1;
      46      878520 :     else if( GetWidthType() > rOther.GetWidthType() )
      47       41351 :         return 1;
      48             : 
      49      837169 :     if( GetWeight() < rOther.GetWeight() )
      50       12486 :         return -1;
      51      824683 :     else if( GetWeight() > rOther.GetWeight() )
      52      469072 :         return 1;
      53             : 
      54      355611 :     if( GetSlant() < rOther.GetSlant() )
      55       13566 :         return -1;
      56      342045 :     else if( GetSlant() > rOther.GetSlant() )
      57      326922 :         return 1;
      58             : 
      59       15123 :     sal_Int32 nRet = GetFamilyName().compareTo( rOther.GetFamilyName() );
      60             : 
      61       15123 :     if (nRet == 0)
      62             :     {
      63       15123 :         nRet = GetStyleName().compareTo( rOther.GetStyleName() );
      64             :     }
      65             : 
      66       15123 :     return nRet;
      67             : }
      68             : 
      69      596862 : sal_Int32 PhysicalFontFace::CompareWithSize( const PhysicalFontFace& rOther ) const
      70             : {
      71      596862 :     sal_Int32 nCompare = CompareIgnoreSize( rOther );
      72      596862 :     if (nCompare != 0)
      73      581739 :         return nCompare;
      74             : 
      75       15123 :     if( mnHeight < rOther.mnHeight )
      76           0 :         return -1;
      77       15123 :     else if( mnHeight > rOther.mnHeight )
      78           0 :         return 1;
      79             : 
      80       15123 :     if( mnWidth < rOther.mnWidth )
      81           0 :         return -1;
      82       15123 :     else if( mnWidth > rOther.mnWidth )
      83           0 :         return 1;
      84             : 
      85       15123 :     return 0;
      86             : }
      87             : 
      88       31430 : bool PhysicalFontFace::IsBetterMatch( const FontSelectPattern& rFSD, FontMatchStatus& rStatus ) const
      89             : {
      90       31430 :     int nMatch = 0;
      91             : 
      92       31430 :     const OUString& rFontName = rFSD.maTargetName;
      93       31430 :     if( rFontName.equalsIgnoreAsciiCase( GetFamilyName() ) )
      94       10770 :         nMatch += 240000;
      95             : 
      96       31430 :     if( rStatus.mpTargetStyleName
      97       31430 :     &&  GetStyleName().equalsIgnoreAsciiCase( *rStatus.mpTargetStyleName ) )
      98           0 :         nMatch += 120000;
      99             : 
     100       31430 :     if( (rFSD.GetPitch() != PITCH_DONTKNOW) && (rFSD.GetPitch() == GetPitch()) )
     101       24269 :         nMatch += 20000;
     102             : 
     103             :     // prefer NORMAL font width
     104             :     // TODO: change when the upper layers can tell their width preference
     105       31430 :     if( GetWidthType() == WIDTH_NORMAL )
     106       31082 :         nMatch += 400;
     107         348 :     else if( (GetWidthType() == WIDTH_SEMI_EXPANDED) || (GetWidthType() == WIDTH_SEMI_CONDENSED) )
     108           0 :         nMatch += 300;
     109             : 
     110       31430 :     if( rFSD.GetWeight() != WEIGHT_DONTKNOW )
     111             :     {
     112             :         // if not bold or requiring emboldening prefer light fonts to bold fonts
     113       31214 :         FontWeight ePatternWeight = rFSD.mbEmbolden ? WEIGHT_NORMAL : rFSD.GetWeight();
     114             : 
     115       31214 :         int nReqWeight = (int)ePatternWeight;
     116       31214 :         if ( ePatternWeight > WEIGHT_MEDIUM )
     117        5784 :             nReqWeight += 100;
     118             : 
     119       31214 :         int nGivenWeight = (int)GetWeight();
     120       31214 :         if( GetWeight() > WEIGHT_MEDIUM )
     121       15622 :             nGivenWeight += 100;
     122             : 
     123       31214 :         int nWeightDiff = nReqWeight - nGivenWeight;
     124             : 
     125       31214 :         if ( nWeightDiff == 0 )
     126       15570 :             nMatch += 1000;
     127       15644 :         else if ( nWeightDiff == +1 || nWeightDiff == -1 )
     128           2 :             nMatch += 700;
     129       15642 :         else if ( nWeightDiff < +50 && nWeightDiff > -50)
     130          20 :             nMatch += 200;
     131             :     }
     132             :     else // requested weight == WEIGHT_DONTKNOW
     133             :     {
     134             :         // prefer NORMAL font weight
     135             :         // TODO: change when the upper layers can tell their weight preference
     136         216 :         if( GetWeight() == WEIGHT_NORMAL )
     137         108 :             nMatch += 450;
     138         108 :         else if( GetWeight() == WEIGHT_MEDIUM )
     139           0 :             nMatch += 350;
     140         108 :         else if( (GetWeight() == WEIGHT_SEMILIGHT) || (GetWeight() == WEIGHT_SEMIBOLD) )
     141           0 :             nMatch += 200;
     142         108 :         else if( GetWeight() == WEIGHT_LIGHT )
     143           0 :             nMatch += 150;
     144             :     }
     145             : 
     146             :     // if requiring custom matrix to fake italic, prefer upright font
     147       31430 :     FontItalic ePatternItalic = rFSD.maItalicMatrix != ItalicMatrix() ? ITALIC_NONE : rFSD.GetSlant();
     148             : 
     149       31430 :     if ( ePatternItalic == ITALIC_NONE )
     150             :     {
     151       28462 :         if( GetSlant() == ITALIC_NONE )
     152       14231 :             nMatch += 900;
     153             :     }
     154             :     else
     155             :     {
     156        2968 :         if( ePatternItalic == GetSlant() )
     157        1454 :             nMatch += 900;
     158        1514 :         else if( GetSlant() != ITALIC_NONE )
     159          30 :             nMatch += 600;
     160             :     }
     161             : 
     162       31430 :     if( mbDevice )
     163           0 :         nMatch += 1;
     164             : 
     165       31430 :     int nHeightMatch = 0;
     166       31430 :     int nWidthMatch = 0;
     167             : 
     168       31430 :     if( IsScalable() )
     169             :     {
     170       31430 :         if( rFSD.mnOrientation != 0 )
     171         888 :             nMatch += 80;
     172       30542 :         else if( rFSD.mnWidth != 0 )
     173         884 :             nMatch += 25;
     174             :         else
     175       29658 :             nMatch += 5;
     176             :     }
     177             :     else
     178             :     {
     179           0 :         if( rFSD.mnHeight == mnHeight )
     180             :         {
     181           0 :             nMatch += 20;
     182           0 :             if( rFSD.mnWidth == mnWidth )
     183           0 :                 nMatch += 10;
     184             :         }
     185             :         else
     186             :         {
     187             :             // for non-scalable fonts the size difference is very important
     188             :             // prefer the smaller font face because of clipping/overlapping issues
     189           0 :             int nHeightDiff = (rFSD.mnHeight - mnHeight) * 1000;
     190           0 :             nHeightMatch = (nHeightDiff >= 0) ? -nHeightDiff : 100+nHeightDiff;
     191           0 :             if( rFSD.mnHeight )
     192           0 :                 nHeightMatch /= rFSD.mnHeight;
     193             : 
     194           0 :             if( (rFSD.mnWidth != 0) && (mnWidth != 0) && (rFSD.mnWidth != mnWidth) )
     195             :             {
     196           0 :                 int nWidthDiff = (rFSD.mnWidth - mnWidth) * 100;
     197           0 :                 nWidthMatch = (nWidthDiff >= 0) ? -nWidthDiff : +nWidthDiff;
     198             :             }
     199             :         }
     200             :     }
     201             : 
     202       31430 :     if( rStatus.mnFaceMatch > nMatch )
     203       21103 :         return false;
     204       10327 :     else if( rStatus.mnFaceMatch < nMatch )
     205             :     {
     206       10327 :         rStatus.mnFaceMatch      = nMatch;
     207       10327 :         rStatus.mnHeightMatch    = nHeightMatch;
     208       10327 :         rStatus.mnWidthMatch     = nWidthMatch;
     209       10327 :         return true;
     210             :     }
     211             : 
     212             :     // when two fonts are still competing prefer the
     213             :     // one with the best matching height
     214           0 :     if( rStatus.mnHeightMatch > nHeightMatch )
     215           0 :         return false;
     216           0 :     else if( rStatus.mnHeightMatch < nHeightMatch )
     217             :     {
     218           0 :         rStatus.mnHeightMatch    = nHeightMatch;
     219           0 :         rStatus.mnWidthMatch     = nWidthMatch;
     220           0 :         return true;
     221             :     }
     222             : 
     223           0 :     if( rStatus.mnWidthMatch > nWidthMatch )
     224           0 :         return false;
     225             : 
     226           0 :     rStatus.mnWidthMatch = nWidthMatch;
     227           0 :     return true;
     228             : }
     229             : 
     230             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10