LCOV - code coverage report
Current view: top level - vcl/source/font - PhysicalFontFace.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 88 119 73.9 %
Date: 2014-11-03 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      165984 : PhysicalFontFace::PhysicalFontFace( const ImplDevFontAttributes& rDFA, int nMagic )
      29             :     : ImplDevFontAttributes( rDFA )
      30             :     , mnWidth(0)
      31             :     , mnHeight(0)
      32             :     , mnMagic( nMagic )
      33      165984 :     , mpNext( NULL )
      34             : {
      35             :     // StarSymbol is a unicode font, but it still deserves the symbol flag
      36      165984 :     if( !IsSymbolFont() )
      37      163800 :         if ( IsStarSymbol( GetFamilyName() ) )
      38        1092 :             SetSymbolFlag( true );
      39      165984 : }
      40             : 
      41     2165088 : sal_Int32 PhysicalFontFace::CompareIgnoreSize( const PhysicalFontFace& rOther ) const
      42             : {
      43             :     // compare their width, weight, italic, style name and family name
      44     2165088 :     if( GetWidthType() < rOther.GetWidthType() )
      45        1872 :         return -1;
      46     2163216 :     else if( GetWidthType() > rOther.GetWidthType() )
      47      110276 :         return 1;
      48             : 
      49     2052940 :     if( GetWeight() < rOther.GetWeight() )
      50       25428 :         return -1;
      51     2027512 :     else if( GetWeight() > rOther.GetWeight() )
      52     1104628 :         return 1;
      53             : 
      54      922884 :     if( GetSlant() < rOther.GetSlant() )
      55       32292 :         return -1;
      56      890592 :     else if( GetSlant() > rOther.GetSlant() )
      57      881856 :         return 1;
      58             : 
      59        8736 :     sal_Int32 nRet = GetFamilyName().compareTo( rOther.GetFamilyName() );
      60             : 
      61        8736 :     if (nRet == 0)
      62             :     {
      63        8736 :         nRet = GetStyleName().compareTo( rOther.GetStyleName() );
      64             :     }
      65             : 
      66        8736 :     return nRet;
      67             : }
      68             : 
      69     1412712 : sal_Int32 PhysicalFontFace::CompareWithSize( const PhysicalFontFace& rOther ) const
      70             : {
      71     1412712 :     sal_Int32 nCompare = CompareIgnoreSize( rOther );
      72     1412712 :     if (nCompare != 0)
      73     1403976 :         return nCompare;
      74             : 
      75        8736 :     if( mnHeight < rOther.mnHeight )
      76           0 :         return -1;
      77        8736 :     else if( mnHeight > rOther.mnHeight )
      78           0 :         return 1;
      79             : 
      80        8736 :     if( mnWidth < rOther.mnWidth )
      81           0 :         return -1;
      82        8736 :     else if( mnWidth > rOther.mnWidth )
      83           0 :         return 1;
      84             : 
      85        8736 :     return 0;
      86             : }
      87             : 
      88       88070 : bool PhysicalFontFace::IsBetterMatch( const FontSelectPattern& rFSD, FontMatchStatus& rStatus ) const
      89             : {
      90       88070 :     int nMatch = 0;
      91             : 
      92       88070 :     const OUString& rFontName = rFSD.maTargetName;
      93       88070 :     if( rFontName.equalsIgnoreAsciiCase( GetFamilyName() ) )
      94       27050 :         nMatch += 240000;
      95             : 
      96       88070 :     if( rStatus.mpTargetStyleName
      97       88070 :     &&  GetStyleName().equalsIgnoreAsciiCase( *rStatus.mpTargetStyleName ) )
      98           0 :         nMatch += 120000;
      99             : 
     100       88070 :     if( (rFSD.GetPitch() != PITCH_DONTKNOW) && (rFSD.GetPitch() == GetPitch()) )
     101       68342 :         nMatch += 20000;
     102             : 
     103             :     // prefer NORMAL font width
     104             :     // TODO: change when the upper layers can tell their width preference
     105       88070 :     if( GetWidthType() == WIDTH_NORMAL )
     106       87246 :         nMatch += 400;
     107         824 :     else if( (GetWidthType() == WIDTH_SEMI_EXPANDED) || (GetWidthType() == WIDTH_SEMI_CONDENSED) )
     108           0 :         nMatch += 300;
     109             : 
     110       88070 :     if( rFSD.GetWeight() != WEIGHT_DONTKNOW )
     111             :     {
     112             :         // if not bold or requiring emboldening prefer light fonts to bold fonts
     113       87566 :         FontWeight ePatternWeight = rFSD.mbEmbolden ? WEIGHT_NORMAL : rFSD.GetWeight();
     114             : 
     115       87566 :         int nReqWeight = (int)ePatternWeight;
     116       87566 :         if ( ePatternWeight > WEIGHT_MEDIUM )
     117       15176 :             nReqWeight += 100;
     118             : 
     119       87566 :         int nGivenWeight = (int)GetWeight();
     120       87566 :         if( GetWeight() > WEIGHT_MEDIUM )
     121       43814 :             nGivenWeight += 100;
     122             : 
     123       87566 :         int nWeightDiff = nReqWeight - nGivenWeight;
     124             : 
     125       87566 :         if ( nWeightDiff == 0 )
     126       43634 :             nMatch += 1000;
     127       43932 :         else if ( nWeightDiff == +1 || nWeightDiff == -1 )
     128          62 :             nMatch += 700;
     129       43870 :         else if ( nWeightDiff < +50 && nWeightDiff > -50)
     130          56 :             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         504 :         if( GetWeight() == WEIGHT_NORMAL )
     137         252 :             nMatch += 450;
     138         252 :         else if( GetWeight() == WEIGHT_MEDIUM )
     139           0 :             nMatch += 350;
     140         252 :         else if( (GetWeight() == WEIGHT_SEMILIGHT) || (GetWeight() == WEIGHT_SEMIBOLD) )
     141           0 :             nMatch += 200;
     142         252 :         else if( GetWeight() == WEIGHT_LIGHT )
     143           0 :             nMatch += 150;
     144             :     }
     145             : 
     146             :     // if requiring custom matrix to fake italic, prefer upright font
     147       88070 :     FontItalic ePatternItalic = rFSD.maItalicMatrix != ItalicMatrix() ? ITALIC_NONE : rFSD.GetSlant();
     148             : 
     149       88070 :     if ( ePatternItalic == ITALIC_NONE )
     150             :     {
     151       80438 :         if( GetSlant() == ITALIC_NONE )
     152       40220 :             nMatch += 900;
     153             :     }
     154             :     else
     155             :     {
     156        7632 :         if( ePatternItalic == GetSlant() )
     157        3764 :             nMatch += 900;
     158        3868 :         else if( GetSlant() != ITALIC_NONE )
     159          52 :             nMatch += 600;
     160             :     }
     161             : 
     162       88070 :     if( mbDevice )
     163           0 :         nMatch += 1;
     164             : 
     165       88070 :     int nHeightMatch = 0;
     166       88070 :     int nWidthMatch = 0;
     167             : 
     168       88070 :     if( IsScalable() )
     169             :     {
     170       88070 :         if( rFSD.mnOrientation != 0 )
     171        2196 :             nMatch += 80;
     172       85874 :         else if( rFSD.mnWidth != 0 )
     173        2016 :             nMatch += 25;
     174             :         else
     175       83858 :             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       88070 :     if( rStatus.mnFaceMatch > nMatch )
     203       59710 :         return false;
     204       28360 :     else if( rStatus.mnFaceMatch < nMatch )
     205             :     {
     206       28360 :         rStatus.mnFaceMatch      = nMatch;
     207       28360 :         rStatus.mnHeightMatch    = nHeightMatch;
     208       28360 :         rStatus.mnWidthMatch     = nWidthMatch;
     209       28360 :         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