LCOV - code coverage report
Current view: top level - starmath/source - format.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 78 99 78.8 %
Date: 2014-11-03 Functions: 6 7 85.7 %
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 <tools/stream.hxx>
      21             : #include <vcl/svapp.hxx>
      22             : #include <editeng/scripttypeitem.hxx>
      23             : #include "format.hxx"
      24             : 
      25             : 
      26             : 
      27             : // Latin default-fonts
      28             : static const sal_uInt16 aLatinDefFnts[FNT_END] =
      29             : {
      30             :     DEFAULTFONT_SERIF,  // FNT_VARIABLE
      31             :     DEFAULTFONT_SERIF,  // FNT_FUNCTION
      32             :     DEFAULTFONT_SERIF,  // FNT_NUMBER
      33             :     DEFAULTFONT_SERIF,  // FNT_TEXT
      34             :     DEFAULTFONT_SERIF,  // FNT_SERIF
      35             :     DEFAULTFONT_SANS,   // FNT_SANS
      36             :     DEFAULTFONT_FIXED   // FNT_FIXED
      37             :     //OpenSymbol,    // FNT_MATH
      38             : };
      39             : 
      40             : // CJK default-fonts
      41             : //! we use non-asian fonts for variables, functions and numbers since they
      42             : //! look better and even in asia only latin letters will be used for those.
      43             : //! At least that's what I was told...
      44             : static const sal_uInt16 aCJKDefFnts[FNT_END] =
      45             : {
      46             :     DEFAULTFONT_SERIF,          // FNT_VARIABLE
      47             :     DEFAULTFONT_SERIF,          // FNT_FUNCTION
      48             :     DEFAULTFONT_SERIF,          // FNT_NUMBER
      49             :     DEFAULTFONT_CJK_TEXT,       // FNT_TEXT
      50             :     DEFAULTFONT_CJK_TEXT,       // FNT_SERIF
      51             :     DEFAULTFONT_CJK_DISPLAY,    // FNT_SANS
      52             :     DEFAULTFONT_CJK_TEXT        // FNT_FIXED
      53             :     //OpenSymbol,    // FNT_MATH
      54             : };
      55             : 
      56             : // CTL default-fonts
      57             : static const sal_uInt16 aCTLDefFnts[FNT_END] =
      58             : {
      59             :     DEFAULTFONT_CTL_TEXT,    // FNT_VARIABLE
      60             :     DEFAULTFONT_CTL_TEXT,    // FNT_FUNCTION
      61             :     DEFAULTFONT_CTL_TEXT,    // FNT_NUMBER
      62             :     DEFAULTFONT_CTL_TEXT,    // FNT_TEXT
      63             :     DEFAULTFONT_CTL_TEXT,    // FNT_SERIF
      64             :     DEFAULTFONT_CTL_TEXT,    // FNT_SANS
      65             :     DEFAULTFONT_CTL_TEXT     // FNT_FIXED
      66             :     //OpenSymbol,    // FNT_MATH
      67             : };
      68             : 
      69             : 
      70         168 : OUString GetDefaultFontName( LanguageType nLang, sal_uInt16 nIdent )
      71             : {
      72             :     OSL_ENSURE( /*FNT_BEGIN <= nIdent  &&*/  nIdent <= FNT_END,
      73             :             "index out opd range" );
      74             : 
      75         168 :     if (FNT_MATH == nIdent)
      76           0 :         return OUString(FNTNAME_MATH);
      77             :     else
      78             :     {
      79             :         const sal_uInt16 *pTable;
      80         168 :         switch ( SvtLanguageOptions::GetScriptTypeOfLanguage( nLang ) )
      81             :         {
      82         168 :             case SCRIPTTYPE_LATIN :     pTable = aLatinDefFnts; break;
      83           0 :             case SCRIPTTYPE_ASIAN :     pTable = aCJKDefFnts; break;
      84           0 :             case SCRIPTTYPE_COMPLEX :   pTable = aCTLDefFnts; break;
      85             :             default :
      86           0 :                 pTable = aLatinDefFnts;
      87             :                 SAL_WARN("starmath", "unknown script-type");
      88             :         }
      89             : 
      90             :         return OutputDevice::GetDefaultFont(
      91         168 :                         pTable[ nIdent ], nLang,
      92         336 :                         DEFAULTFONT_FLAGS_ONLYONE ).GetName();
      93             :     }
      94             : }
      95             : 
      96             : 
      97             : 
      98         726 : SmFormat::SmFormat()
      99         726 : :   aBaseSize(0, SmPtsTo100th_mm(12))
     100             : {
     101         726 :     nVersion    = SM_FMT_VERSION_NOW;
     102             : 
     103         726 :     eHorAlign       = AlignCenter;
     104         726 :     nGreekCharStyle = 0;
     105         726 :     bIsTextmode     = bScaleNormalBrackets = false;
     106             : 
     107         726 :     vSize[SIZ_TEXT]     = 100;
     108         726 :     vSize[SIZ_INDEX]    = 60;
     109             :     vSize[SIZ_FUNCTION] =
     110         726 :     vSize[SIZ_OPERATOR] = 100;
     111         726 :     vSize[SIZ_LIMITS]   = 60;
     112             : 
     113         726 :     vDist[DIS_HORIZONTAL]           = 10;
     114         726 :     vDist[DIS_VERTICAL]             = 5;
     115         726 :     vDist[DIS_ROOT]                 = 0;
     116             :     vDist[DIS_SUPERSCRIPT]          =
     117         726 :     vDist[DIS_SUBSCRIPT]            = 20;
     118             :     vDist[DIS_NUMERATOR]            =
     119         726 :     vDist[DIS_DENOMINATOR]          = 0;
     120         726 :     vDist[DIS_FRACTION]             = 10;
     121         726 :     vDist[DIS_STROKEWIDTH]          = 5;
     122             :     vDist[DIS_UPPERLIMIT]           =
     123         726 :     vDist[DIS_LOWERLIMIT]           = 0;
     124             :     vDist[DIS_BRACKETSIZE]          =
     125         726 :     vDist[DIS_BRACKETSPACE]         = 5;
     126         726 :     vDist[DIS_MATRIXROW]            = 3;
     127         726 :     vDist[DIS_MATRIXCOL]            = 30;
     128             :     vDist[DIS_ORNAMENTSIZE]         =
     129         726 :     vDist[DIS_ORNAMENTSPACE]        = 0;
     130         726 :     vDist[DIS_OPERATORSIZE]         = 50;
     131         726 :     vDist[DIS_OPERATORSPACE]        = 20;
     132             :     vDist[DIS_LEFTSPACE]            =
     133         726 :     vDist[DIS_RIGHTSPACE]           = 100;
     134             :     vDist[DIS_TOPSPACE]             =
     135         726 :     vDist[DIS_BOTTOMSPACE]          =
     136        1452 :     vDist[DIS_NORMALBRACKETSIZE]    = 0;
     137             : 
     138         726 :     vFont[FNT_VARIABLE] =
     139         726 :     vFont[FNT_FUNCTION] =
     140         726 :     vFont[FNT_NUMBER]   =
     141         726 :     vFont[FNT_TEXT]     =
     142        1452 :     vFont[FNT_SERIF]    = SmFace(OUString(FNTNAME_TIMES), aBaseSize);
     143         726 :     vFont[FNT_SANS]     = SmFace(OUString(FNTNAME_HELV),  aBaseSize);
     144         726 :     vFont[FNT_FIXED]    = SmFace(OUString(FNTNAME_COUR),  aBaseSize);
     145         726 :     vFont[FNT_MATH]     = SmFace(OUString(FNTNAME_MATH),  aBaseSize);
     146             : 
     147         726 :     vFont[FNT_MATH].SetCharSet( RTL_TEXTENCODING_UNICODE );
     148             : 
     149         726 :     vFont[FNT_VARIABLE].SetItalic(ITALIC_NORMAL);
     150         726 :     vFont[FNT_FUNCTION].SetItalic(ITALIC_NONE);
     151         726 :     vFont[FNT_NUMBER]  .SetItalic(ITALIC_NONE);
     152         726 :     vFont[FNT_TEXT]    .SetItalic(ITALIC_NONE);
     153         726 :     vFont[FNT_SERIF]   .SetItalic(ITALIC_NONE);
     154         726 :     vFont[FNT_SANS]    .SetItalic(ITALIC_NONE);
     155         726 :     vFont[FNT_FIXED]   .SetItalic(ITALIC_NONE);
     156             : 
     157        6534 :     for ( sal_uInt16 i = FNT_BEGIN;  i <= FNT_END;  i++ )
     158             :     {
     159        5808 :         SmFace &rFace = vFont[i];
     160        5808 :         rFace.SetTransparent( true );
     161        5808 :         rFace.SetAlign( ALIGN_BASELINE );
     162        5808 :         rFace.SetColor( COL_AUTO );
     163        5808 :         bDefaultFont[i] = false;
     164             :     }
     165         726 : }
     166             : 
     167             : 
     168       11306 : void SmFormat::SetFont(sal_uInt16 nIdent, const SmFace &rFont, bool bDefault )
     169             : {
     170       11306 :     vFont[nIdent] = rFont;
     171       11306 :     vFont[nIdent].SetTransparent( true );
     172       11306 :     vFont[nIdent].SetAlign( ALIGN_BASELINE );
     173             : 
     174       11306 :     bDefaultFont[nIdent] = bDefault;
     175       11306 : }
     176             : 
     177        1380 : SmFormat & SmFormat::operator = (const SmFormat &rFormat)
     178             : {
     179        1380 :     SetBaseSize(rFormat.GetBaseSize());
     180        1380 :     SetVersion (rFormat.GetVersion());
     181        1380 :     SetHorAlign(rFormat.GetHorAlign());
     182        1380 :     SetTextmode(rFormat.IsTextmode());
     183        1380 :     SetGreekCharStyle(rFormat.GetGreekCharStyle());
     184        1380 :     SetScaleNormalBrackets(rFormat.IsScaleNormalBrackets());
     185             : 
     186             :     sal_uInt16  i;
     187       12420 :     for (i = FNT_BEGIN;  i <= FNT_END;  i++)
     188             :     {
     189       11040 :         SetFont(i, rFormat.GetFont(i));
     190       11040 :         SetDefaultFont(i, rFormat.IsDefaultFont(i));
     191             :     }
     192        8280 :     for (i = SIZ_BEGIN;  i <= SIZ_END;  i++)
     193        6900 :         SetRelSize(i, rFormat.GetRelSize(i));
     194       34500 :     for (i = DIS_BEGIN;  i <= DIS_END;  i++)
     195       33120 :         SetDistance(i, rFormat.GetDistance(i));
     196             : 
     197        1380 :     return *this;
     198             : }
     199             : 
     200             : 
     201           0 : bool SmFormat::operator == (const SmFormat &rFormat) const
     202             : {
     203           0 :     bool bRes = aBaseSize == rFormat.aBaseSize  &&
     204           0 :                 eHorAlign == rFormat.eHorAlign  &&
     205           0 :                 nGreekCharStyle == rFormat.nGreekCharStyle &&
     206           0 :                 bIsTextmode == rFormat.bIsTextmode  &&
     207           0 :                 bScaleNormalBrackets  == rFormat.bScaleNormalBrackets;
     208             : 
     209             :     sal_uInt16 i;
     210           0 :     for (i = 0;  i <= SIZ_END && bRes;  ++i)
     211             :     {
     212           0 :         if (vSize[i] != rFormat.vSize[i])
     213           0 :             bRes = false;
     214             :     }
     215           0 :     for (i = 0;  i <= DIS_END && bRes;  ++i)
     216             :     {
     217           0 :         if (vDist[i] != rFormat.vDist[i])
     218           0 :             bRes = false;
     219             :     }
     220           0 :     for (i = 0;  i <= FNT_END && bRes;  ++i)
     221             :     {
     222           0 :         if (vFont[i] != rFormat.vFont[i]  ||
     223           0 :             bDefaultFont[i] != rFormat.bDefaultFont[i])
     224           0 :             bRes = false;
     225             :     }
     226             : 
     227           0 :     return bRes;
     228          72 : }
     229             : 
     230             : 
     231             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10