LCOV - code coverage report
Current view: top level - libreoffice/filter/source/msfilter - util.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 53 145 36.6 %
Date: 2012-12-27 Functions: 5 7 71.4 %
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             :  * Version: MPL 1.1 / GPLv3+ / LGPLv3+
       4             :  *
       5             :  * The contents of this file are subject to the Mozilla Public License Version
       6             :  * 1.1 (the "License"); you may not use this file except in compliance with
       7             :  * the License. You may obtain a copy of the License at
       8             :  * http://www.mozilla.org/MPL/
       9             :  *
      10             :  * Software distributed under the License is distributed on an "AS IS" basis,
      11             :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12             :  * for the specific language governing rights and limitations under the
      13             :  * License.
      14             :  *
      15             :  * The Initial Developer of the Original Code is
      16             :  *       Miklos Vajna <vmiklos@suse.cz> (SUSE, Inc.)
      17             :  * Portions created by the Initial Developer are Copyright (C) 2012 the
      18             :  * Initial Developer. All Rights Reserved.
      19             :  *
      20             :  * Contributor(s):
      21             :  *
      22             :  * Alternatively, the contents of this file may be used under the terms of
      23             :  * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
      24             :  * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
      25             :  * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
      26             :  * instead of those above.
      27             :  */
      28             : 
      29             : #include <rtl/ustring.hxx>
      30             : #include <rtl/strbuf.hxx>
      31             : #include <unotools/fontcvt.hxx>
      32             : #include <unotools/fontdefs.hxx>
      33             : #include <vcl/svapp.hxx>
      34             : #include <filter/msfilter/util.hxx>
      35             : 
      36             : namespace msfilter {
      37             : namespace util {
      38             : 
      39         440 : rtl_TextEncoding getBestTextEncodingFromLocale(const ::com::sun::star::lang::Locale &rLocale)
      40             : {
      41             :     //Obviously not comprehensive, feel free to expand these, they're for ultimate fallbacks
      42             :     //in last-ditch broken-file-format cases to guess the right 8bit encodings
      43         440 :     const rtl::OUString &rLanguage = rLocale.Language;
      44         440 :     if (rLanguage == "cs" || rLanguage == "hu" || rLanguage == "pl")
      45           0 :         return RTL_TEXTENCODING_MS_1250;
      46         440 :     if (rLanguage == "ru" || rLanguage == "uk")
      47           1 :         return RTL_TEXTENCODING_MS_1251;
      48         439 :     if (rLanguage == "el")
      49           0 :         return RTL_TEXTENCODING_MS_1253;
      50         439 :     if (rLanguage == "tr")
      51           0 :         return RTL_TEXTENCODING_MS_1254;
      52         439 :     if (rLanguage == "lt")
      53           1 :         return RTL_TEXTENCODING_MS_1257;
      54         438 :     return RTL_TEXTENCODING_MS_1252;
      55             : }
      56             : 
      57        1357 : sal_uInt32 BGRToRGB(sal_uInt32 nColor)
      58             : {
      59             :     sal_uInt8
      60        1357 :         r(static_cast<sal_uInt8>(nColor&0xFF)),
      61        1357 :         g(static_cast<sal_uInt8>(((nColor)>>8)&0xFF)),
      62        1357 :         b(static_cast<sal_uInt8>((nColor>>16)&0xFF)),
      63        1357 :         t(static_cast<sal_uInt8>((nColor>>24)&0xFF));
      64        1357 :     nColor = (t<<24) + (r<<16) + (g<<8) + b;
      65        1357 :     return nColor;
      66             : }
      67             : 
      68          33 : DateTime DTTM2DateTime( long lDTTM )
      69             : {
      70             :     /*
      71             :     mint    short   :6  0000003F    minutes (0-59)
      72             :     hr      short   :5  000007C0    hours (0-23)
      73             :     dom     short   :5  0000F800    days of month (1-31)
      74             :     mon     short   :4  000F0000    months (1-12)
      75             :     yr      short   :9  1FF00000    years (1900-2411)-1900
      76             :     wdy     short   :3  E0000000    weekday(Sunday=0
      77             :                                             Monday=1
      78             :     ( wdy can be ignored )                  Tuesday=2
      79             :                                             Wednesday=3
      80             :                                             Thursday=4
      81             :                                             Friday=5
      82             :                                             Saturday=6)
      83             :     */
      84          33 :     DateTime aDateTime(Date( 0 ), Time( 0 ));
      85          33 :     if( lDTTM )
      86             :     {
      87          10 :         sal_uInt16 lMin = (sal_uInt16)(lDTTM & 0x0000003F);
      88          10 :         lDTTM >>= 6;
      89          10 :         sal_uInt16 lHour= (sal_uInt16)(lDTTM & 0x0000001F);
      90          10 :         lDTTM >>= 5;
      91          10 :         sal_uInt16 lDay = (sal_uInt16)(lDTTM & 0x0000001F);
      92          10 :         lDTTM >>= 5;
      93          10 :         sal_uInt16 lMon = (sal_uInt16)(lDTTM & 0x0000000F);
      94          10 :         lDTTM >>= 4;
      95          10 :         sal_uInt16 lYear= (sal_uInt16)(lDTTM & 0x000001FF) + 1900;
      96          10 :         aDateTime = DateTime(Date(lDay, lMon, lYear), Time(lHour, lMin));
      97             :     }
      98          33 :     return aDateTime;
      99             : }
     100             : 
     101             : /// Append the number as 2-digit when less than 10.
     102          20 : static void lcl_AppendTwoDigits( rtl::OStringBuffer &rBuffer, sal_Int32 nNum )
     103             : {
     104          20 :     if ( nNum < 0 || nNum > 99 )
     105             :     {
     106           0 :         rBuffer.append( "00" );
     107          20 :         return;
     108             :     }
     109             : 
     110          20 :     if ( nNum < 10 )
     111          13 :         rBuffer.append( '0' );
     112             : 
     113          20 :     rBuffer.append( nNum );
     114             : }
     115             : 
     116           4 : rtl::OString DateTimeToOString( const DateTime& rDateTime )
     117             : {
     118           4 :     DateTime aInUTC( rDateTime );
     119             : // HACK: this is correct according to the spec, but MSOffice believes everybody lives
     120             : // in UTC+0 when reading it back
     121             : //    aInUTC.ConvertToUTC();
     122             : 
     123           4 :     rtl::OStringBuffer aBuffer( 25 );
     124           4 :     aBuffer.append( sal_Int32( aInUTC.GetYear() ) );
     125           4 :     aBuffer.append( '-' );
     126             : 
     127           4 :     lcl_AppendTwoDigits( aBuffer, aInUTC.GetMonth() );
     128           4 :     aBuffer.append( '-' );
     129             : 
     130           4 :     lcl_AppendTwoDigits( aBuffer, aInUTC.GetDay() );
     131           4 :     aBuffer.append( 'T' );
     132             : 
     133           4 :     lcl_AppendTwoDigits( aBuffer, aInUTC.GetHour() );
     134           4 :     aBuffer.append( ':' );
     135             : 
     136           4 :     lcl_AppendTwoDigits( aBuffer, aInUTC.GetMin() );
     137           4 :     aBuffer.append( ':' );
     138             : 
     139           4 :     lcl_AppendTwoDigits( aBuffer, aInUTC.GetSec() );
     140           4 :     aBuffer.append( 'Z' ); // we are in UTC
     141             : 
     142           4 :     return aBuffer.makeStringAndClear();
     143             : }
     144             : 
     145           0 : sal_Unicode bestFitOpenSymbolToMSFont(sal_Unicode cChar,
     146             :     rtl_TextEncoding& rChrSet, rtl::OUString& rFontName, bool bDisableUnicodeSupport)
     147             : {
     148           0 :     StarSymbolToMSMultiFont *pConvert = CreateStarSymbolToMSMultiFont();
     149           0 :     rtl::OUString sFont = pConvert->ConvertChar(cChar);
     150           0 :     delete pConvert;
     151           0 :     if (!sFont.isEmpty())
     152             :     {
     153           0 :         cChar = static_cast< sal_Unicode >(cChar | 0xF000);
     154           0 :         rFontName = sFont;
     155           0 :         rChrSet = RTL_TEXTENCODING_SYMBOL;
     156             :     }
     157           0 :     else if (!bDisableUnicodeSupport && (cChar < 0xE000 || cChar > 0xF8FF))
     158             :     {
     159             :         /*
     160             :           Ok we can't fit into a known windows unicode font, but
     161             :           we are not in the private area, so we are a
     162             :           standardized symbol, so turn off the symbol bit and
     163             :           let words own font substitution kick in
     164             :         */
     165           0 :         rChrSet = RTL_TEXTENCODING_UNICODE;
     166           0 :         xub_StrLen nIndex = 0;
     167           0 :         rFontName = ::GetNextFontToken(rFontName, nIndex);
     168             :     }
     169             :     else
     170             :     {
     171             :         /*
     172             :           Well we don't have an available substition, and we're
     173             :           in our private area, so give up and show a standard
     174             :           bullet symbol
     175             :         */
     176           0 :         rFontName = "Wingdings";
     177           0 :         cChar = static_cast< sal_Unicode >(0x6C);
     178             :     }
     179           0 :     return cChar;
     180             : }
     181             : 
     182             : /*
     183             :   http://social.msdn.microsoft.com/Forums/hu-HU/os_openXML-ecma/thread/1bf1f185-ee49-4314-94e7-f4e1563b5c00
     184             : 
     185             :   The following information is being submitted to the standards working group as
     186             :   a proposed resolution to a defect report and is not yet part of ISO 29500-1.
     187             :   ...
     188             :   For each Unicode character in DrawingML text, the font face can be any of four
     189             :   font “slots”: latin (§21.1.2.3.7), cs (§21.1.2.3.1), ea (§21.1.2.3.3), or sym
     190             :   (§21.1.2.3.10), as specified in the following table. For all ranges not
     191             :   explicitly called out below, the ea font shall be used.
     192             : 
     193             :   U+0000–U+007F Use latin font
     194             :   U+0080–U+00A6 Use latin font
     195             :   U+00A9–U+00AF Use latin font
     196             :   U+00B2–U+00B3 Use latin font
     197             :   U+00B5–U+00D6 Use latin font
     198             :   U+00D8–U+00F6 Use latin font
     199             :   U+00F8–U+058F Use latin font
     200             :   U+0590–U+074F Use cs font
     201             :   U+0780–U+07BF Use cs font
     202             :   U+0900–U+109F Use cs font
     203             :   U+10A0–U+10FF Use latin font
     204             :   U+1200–U+137F Use latin font
     205             :   U+13A0–U+177F Use latin font
     206             :   U+1D00–U+1D7F Use latin font
     207             :   U+1E00–U+1FFF Use latin font
     208             :   U+1780–U+18AF Use cs font
     209             :   U+2000–U+200B Use latin font
     210             :   U+200C–U+200F Use cs font
     211             :   U+2010–U+2029 Use latin font Except, for the quote characters in the range
     212             :     2018 – 201E, use ea font if the text has one of the following language
     213             :     identifiers: ii-CN, ja-JP, ko-KR, zh-CN, zh-HK, zh-MO, zh-SG, zh-TW.
     214             :   U+202A–U+202F Use cs font
     215             :   U+2030–U+2046 Use latin font
     216             :   U+204A–U+245F Use latin font
     217             :   U+2670–U+2671 Use cs font
     218             :   U+27C0–U+2BFF Use latin font
     219             :   U+3099–U+309A Use ea font
     220             :   U+D835 Use latin font
     221             :   U+F000–U+F0FF Symbol, use sym font
     222             :   U+FB00–U+FB17 Use latin font
     223             :   U+FB1D–U+FB4F Use cs font
     224             :   U+FE50–U+FE6F Use latin font
     225             :   Otherwise Use ea font
     226             : */
     227           0 : TextCategory categorizeCodePoint(sal_uInt32 codePoint, const rtl::OUString &rBcp47LanguageTag)
     228             : {
     229           0 :     TextCategory eRet = ea;
     230           0 :     if (codePoint <= 0x007F)
     231           0 :         eRet = latin;
     232           0 :     else if (0x0080 <= codePoint && codePoint <= 0x00A6)
     233           0 :         eRet = latin;
     234           0 :     else if (0x00A9 <= codePoint && codePoint <= 0x00AF)
     235           0 :         eRet = latin;
     236           0 :     else if (0x00B2 <= codePoint && codePoint <= 0x00B3)
     237           0 :         eRet = latin;
     238           0 :     else if (0x00B5 <= codePoint && codePoint <= 0x00D6)
     239           0 :         eRet = latin;
     240           0 :     else if (0x00D8 <= codePoint && codePoint <= 0x00F6)
     241           0 :         eRet = latin;
     242           0 :     else if (0x00F8 <= codePoint && codePoint <= 0x058F)
     243           0 :         eRet = latin;
     244           0 :     else if (0x0590 <= codePoint && codePoint <= 0x074F)
     245           0 :         eRet = cs;
     246           0 :     else if (0x0780 <= codePoint && codePoint <= 0x07BF)
     247           0 :         eRet = cs;
     248           0 :     else if (0x0900 <= codePoint && codePoint <= 0x109F)
     249           0 :         eRet = cs;
     250           0 :     else if (0x10A0 <= codePoint && codePoint <= 0x10FF)
     251           0 :         eRet = latin;
     252           0 :     else if (0x1200 <= codePoint && codePoint <= 0x137F)
     253           0 :         eRet = latin;
     254           0 :     else if (0x13A0 <= codePoint && codePoint <= 0x177F)
     255           0 :         eRet = latin;
     256           0 :     else if (0x1D00 <= codePoint && codePoint <= 0x1D7F)
     257           0 :         eRet = latin;
     258           0 :     else if (0x1E00 <= codePoint && codePoint <= 0x1FFF)
     259           0 :         eRet = latin;
     260           0 :     else if (0x1780 <= codePoint && codePoint <= 0x18AF)
     261           0 :         eRet = cs;
     262           0 :     else if (0x2000 <= codePoint && codePoint <= 0x200B)
     263           0 :         eRet = latin;
     264           0 :     else if (0x200C <= codePoint && codePoint <= 0x200F)
     265           0 :         eRet = cs;
     266           0 :     else if (0x2010 <= codePoint && codePoint <= 0x2029)
     267             :     {
     268           0 :         eRet = latin;
     269           0 :         if (0x2018 <= codePoint && codePoint <= 0x201E)
     270             :         {
     271           0 :             if (rBcp47LanguageTag == "ii-CN" ||
     272           0 :                 rBcp47LanguageTag == "ja-JP" ||
     273           0 :                 rBcp47LanguageTag == "ko-KR" ||
     274           0 :                 rBcp47LanguageTag == "zh-CN" ||
     275           0 :                 rBcp47LanguageTag == "zh-HK" ||
     276           0 :                 rBcp47LanguageTag == "zh-MO" ||
     277           0 :                 rBcp47LanguageTag == "zh-SG" ||
     278           0 :                 rBcp47LanguageTag == "zh-TW")
     279             :             {
     280           0 :                 eRet = ea;
     281             :             }
     282             :         }
     283             :     }
     284           0 :     else if (0x202A <= codePoint && codePoint <= 0x202F)
     285           0 :         eRet = cs;
     286           0 :     else if (0x2030 <= codePoint && codePoint <= 0x2046)
     287           0 :         eRet = latin;
     288           0 :     else if (0x204A <= codePoint && codePoint <= 0x245F)
     289           0 :         eRet = latin;
     290           0 :     else if (0x2670 <= codePoint && codePoint <= 0x2671)
     291           0 :         eRet = latin;
     292           0 :     else if (0x27C0 <= codePoint && codePoint <= 0x2BFF)
     293           0 :         eRet = latin;
     294           0 :     else if (0x3099 <= codePoint && codePoint <= 0x309A)
     295           0 :         eRet = ea;
     296           0 :     else if (0xD835 == codePoint)
     297           0 :         eRet = latin;
     298           0 :     else if (0xF000 <= codePoint && codePoint <= 0xF0FF)
     299           0 :         eRet = sym;
     300           0 :     else if (0xFB00 <= codePoint && codePoint <= 0xFB17)
     301           0 :         eRet = latin;
     302           0 :     else if (0xFB1D <= codePoint && codePoint <= 0xFB4F)
     303           0 :         eRet = cs;
     304           0 :     else if (0xFE50 <= codePoint && codePoint <= 0xFE6F)
     305           0 :         eRet = latin;
     306           0 :     return eRet;
     307             : }
     308             : 
     309             : }
     310             : }
     311             : 
     312             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10