LCOV - code coverage report
Current view: top level - vcl/source/font - PhysicalFontFace.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 87 119 73.1 %
Date: 2015-06-13 12:38:46 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      201865 : PhysicalFontFace::PhysicalFontFace( const ImplDevFontAttributes& rDFA, int nMagic )
      29             :     : ImplDevFontAttributes( rDFA )
      30             :     , mnWidth(0)
      31             :     , mnHeight(0)
      32             :     , mnMagic( nMagic )
      33      201865 :     , mpNext( NULL )
      34             : {
      35             :     // StarSymbol is a unicode font, but it still deserves the symbol flag
      36      201865 :     if( !IsSymbolFont() )
      37      200147 :         if ( IsStarSymbol( GetFamilyName() ) )
      38         859 :             SetSymbolFlag( true );
      39      201865 : }
      40             : 
      41     1895821 : sal_Int32 PhysicalFontFace::CompareIgnoreSize( const PhysicalFontFace& rOther ) const
      42             : {
      43             :     // compare their width, weight, italic, style name and family name
      44     1895821 :     if( GetWidthType() < rOther.GetWidthType() )
      45        1485 :         return -1;
      46     1894336 :     else if( GetWidthType() > rOther.GetWidthType() )
      47       67692 :         return 1;
      48             : 
      49     1826644 :     if( GetWeight() < rOther.GetWeight() )
      50       31632 :         return -1;
      51     1795012 :     else if( GetWeight() > rOther.GetWeight() )
      52     1008981 :         return 1;
      53             : 
      54      786031 :     if( GetSlant() < rOther.GetSlant() )
      55       30175 :         return -1;
      56      755856 :     else if( GetSlant() > rOther.GetSlant() )
      57      719457 :         return 1;
      58             : 
      59       36399 :     sal_Int32 nRet = GetFamilyName().compareTo( rOther.GetFamilyName() );
      60             : 
      61       36399 :     if (nRet == 0)
      62             :     {
      63       36399 :         nRet = GetStyleName().compareTo( rOther.GetStyleName() );
      64             :     }
      65             : 
      66       36399 :     return nRet;
      67             : }
      68             : 
      69     1267265 : sal_Int32 PhysicalFontFace::CompareWithSize( const PhysicalFontFace& rOther ) const
      70             : {
      71     1267265 :     sal_Int32 nCompare = CompareIgnoreSize( rOther );
      72     1267265 :     if (nCompare != 0)
      73     1230866 :         return nCompare;
      74             : 
      75       36399 :     if( mnHeight < rOther.mnHeight )
      76           0 :         return -1;
      77       36399 :     else if( mnHeight > rOther.mnHeight )
      78           0 :         return 1;
      79             : 
      80       36399 :     if( mnWidth < rOther.mnWidth )
      81           0 :         return -1;
      82       36399 :     else if( mnWidth > rOther.mnWidth )
      83           0 :         return 1;
      84             : 
      85       36399 :     return 0;
      86             : }
      87             : 
      88       51202 : bool PhysicalFontFace::IsBetterMatch( const FontSelectPattern& rFSD, FontMatchStatus& rStatus ) const
      89             : {
      90       51202 :     int nMatch = 0;
      91             : 
      92       51202 :     const OUString& rFontName = rFSD.maTargetName;
      93       51202 :     if( rFontName.equalsIgnoreAsciiCase( GetFamilyName() ) )
      94       17378 :         nMatch += 240000;
      95             : 
      96       51202 :     if( rStatus.mpTargetStyleName
      97       51202 :     &&  GetStyleName().equalsIgnoreAsciiCase( *rStatus.mpTargetStyleName ) )
      98           0 :         nMatch += 120000;
      99             : 
     100       51202 :     if( (rFSD.GetPitch() != PITCH_DONTKNOW) && (rFSD.GetPitch() == GetPitch()) )
     101       39034 :         nMatch += 20000;
     102             : 
     103             :     // prefer NORMAL font width
     104             :     // TODO: change when the upper layers can tell their width preference
     105       51202 :     if( GetWidthType() == WIDTH_NORMAL )
     106       50766 :         nMatch += 400;
     107         436 :     else if( (GetWidthType() == WIDTH_SEMI_EXPANDED) || (GetWidthType() == WIDTH_SEMI_CONDENSED) )
     108           0 :         nMatch += 300;
     109             : 
     110       51202 :     if( rFSD.GetWeight() != WEIGHT_DONTKNOW )
     111             :     {
     112             :         // if not bold or requiring emboldening prefer light fonts to bold fonts
     113       50922 :         FontWeight ePatternWeight = rFSD.mbEmbolden ? WEIGHT_NORMAL : rFSD.GetWeight();
     114             : 
     115       50922 :         int nReqWeight = (int)ePatternWeight;
     116       50922 :         if ( ePatternWeight > WEIGHT_MEDIUM )
     117        9136 :             nReqWeight += 100;
     118             : 
     119       50922 :         int nGivenWeight = (int)GetWeight();
     120       50922 :         if( GetWeight() > WEIGHT_MEDIUM )
     121       25476 :             nGivenWeight += 100;
     122             : 
     123       50922 :         int nWeightDiff = nReqWeight - nGivenWeight;
     124             : 
     125       50922 :         if ( nWeightDiff == 0 )
     126       25335 :             nMatch += 1000;
     127       25587 :         else if ( nWeightDiff == +1 || nWeightDiff == -1 )
     128          27 :             nMatch += 700;
     129       25560 :         else if ( nWeightDiff < +50 && nWeightDiff > -50)
     130          84 :             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         280 :         if( GetWeight() == WEIGHT_NORMAL )
     137         140 :             nMatch += 450;
     138         140 :         else if( GetWeight() == WEIGHT_MEDIUM )
     139           0 :             nMatch += 350;
     140         140 :         else if( (GetWeight() == WEIGHT_SEMILIGHT) || (GetWeight() == WEIGHT_SEMIBOLD) )
     141           0 :             nMatch += 200;
     142         140 :         else if( GetWeight() == WEIGHT_LIGHT )
     143           0 :             nMatch += 150;
     144             :     }
     145             : 
     146             :     // if requiring custom matrix to fake italic, prefer upright font
     147       51202 :     FontItalic ePatternItalic = rFSD.maItalicMatrix != ItalicMatrix() ? ITALIC_NONE : rFSD.GetSlant();
     148             : 
     149       51202 :     if ( ePatternItalic == ITALIC_NONE )
     150             :     {
     151       47254 :         if( GetSlant() == ITALIC_NONE )
     152       23627 :             nMatch += 900;
     153             :     }
     154             :     else
     155             :     {
     156        3948 :         if( ePatternItalic == GetSlant() )
     157        1974 :             nMatch += 900;
     158        1974 :         else if( GetSlant() != ITALIC_NONE )
     159           0 :             nMatch += 600;
     160             :     }
     161             : 
     162       51202 :     if( mbDevice )
     163           0 :         nMatch += 1;
     164             : 
     165       51202 :     int nHeightMatch = 0;
     166       51202 :     int nWidthMatch = 0;
     167             : 
     168       51202 :     if( IsScalable() )
     169             :     {
     170       51202 :         if( rFSD.mnOrientation != 0 )
     171         888 :             nMatch += 80;
     172       50314 :         else if( rFSD.mnWidth != 0 )
     173        1280 :             nMatch += 25;
     174             :         else
     175       49034 :             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       51202 :     if( rStatus.mnFaceMatch > nMatch )
     203       34804 :         return false;
     204       16398 :     else if( rStatus.mnFaceMatch < nMatch )
     205             :     {
     206       16398 :         rStatus.mnFaceMatch      = nMatch;
     207       16398 :         rStatus.mnHeightMatch    = nHeightMatch;
     208       16398 :         rStatus.mnWidthMatch     = nWidthMatch;
     209       16398 :         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.11