Files
libreoffice/svtools/source/control/ctrltool.cxx

878 lines
25 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
re-base on ALv2 code. Includes: Patch contributed by: Jurgen Schmidt remove onlineregistration with dependencies http://svn.apache.org/viewvc?view=revision&revision=1240245 imported patch package_eventlistener.patch http://svn.apache.org/viewvc?view=revision&revision=1172103 Patch contributed by Pedro Giffuni Accept Google Chrome OS fonts as equivalent to MS fonts. http://svn.apache.org/viewvc?view=revision&revision=1233155 http://svn.apache.org/viewvc?view=revision&revision=1233408 Patch contributed by Andre Fischer Do not add targets for junit tests when junit is disabled. http://svn.apache.org/viewvc?view=revision&revision=1241508 Patches contributed by Mathias Bauer (and others) gnumake4 work variously http://svn.apache.org/viewvc?view=revision&revision=1394707 http://svn.apache.org/viewvc?view=revision&revision=1394326 cws mba34issues01: #i114600#: remove forbidden characters from list of unencoded characters http://svn.apache.org/viewvc?view=revision&revision=1172370 Patches contributed by Oliver Rainer-Wittman some clean up in JPEGReader due to memory constraints http://svn.apache.org/viewvc?view=revision&revision=1299729 119114 - method <UpdateDialog::addSpecificError(..)> - create entry with correct type http://svn.apache.org/viewvc?view=revision&revision=1305265 Patches contributed by Ariel Constenla-Haile i118707 - make toolbar control's popup window grab focus http://svn.apache.org/viewvc?view=revision&revision=1225846 Patches contributed by Herbert Duerr #i118662# remove usage of BerkeleyDB in desktop module http://svn.apache.org/viewvc?view=revision&revision=1213171 minor cleanups in dp_persmap.* http://svn.apache.org/viewvc?view=revision&revision=1215064 flush early to prevent problem with extension manager not cleaning up its objects http://svn.apache.org/viewvc?view=revision&revision=1228147 i118726 do not flush *pmap file while reading it http://svn.apache.org/viewvc?view=revision&revision=1230614 #i119048# migrate BDB extension entries using a simple heuristic http://svn.apache.org/viewvc?view=revision&revision=1300972 #i119048# handle edge cases when importing BDB hash files http://svn.apache.org/viewvc?view=revision&revision=1301428 #i119113# fix of-by-one when importing BDB files http://svn.apache.org/viewvc?view=revision&revision=1305420 restore our encryption settings, icon themes, and dictionaries. removed wrapper hacks, kill obsolete bundled extension blob / pre-registration handling, remove duplicated quickstart code. remove OS/2 conditionals.
2012-11-15 17:28:16 +00:00
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
2000-09-18 16:07:07 +00:00
#include <string.h>
2011-11-18 21:03:31 +00:00
#include <comphelper/string.hxx>
2000-09-18 16:07:07 +00:00
#include <tools/debug.hxx>
#include <tools/fract.hxx>
#include <i18nlangtag/mslangid.hxx>
2000-09-18 16:07:07 +00:00
#include <vcl/window.hxx>
#include <vcl/svapp.hxx>
#include <vcl/wrkwin.hxx>
#include <vcl/settings.hxx>
#include <sal/macros.h>
#include <svtools/svtools.hrc>
#include <svtools/svtresid.hxx>
#include <svtools/ctrltool.hxx>
#include <o3tl/typed_flags_set.hxx>
2000-09-18 16:07:07 +00:00
// Standard Fontgroessen fuer scalierbare Fonts
const sal_IntPtr FontList::aStdSizeAry[] =
2000-09-18 16:07:07 +00:00
{
60,
70,
80,
90,
100,
2001-03-28 07:29:03 +00:00
105,
2000-09-18 16:07:07 +00:00
110,
120,
2001-03-28 07:29:03 +00:00
130,
2000-09-18 16:07:07 +00:00
140,
2001-03-28 07:29:03 +00:00
150,
2000-09-18 16:07:07 +00:00
160,
180,
200,
220,
240,
260,
280,
320,
360,
400,
440,
480,
540,
600,
660,
720,
800,
880,
960,
0
};
class ImplFontListFontInfo : public vcl::FontInfo
2000-09-18 16:07:07 +00:00
{
friend class FontList;
private:
VclPtr<OutputDevice> mpDevice;
2000-09-18 16:07:07 +00:00
ImplFontListFontInfo* mpNext;
public:
ImplFontListFontInfo( const vcl::FontInfo& rInfo,
2000-09-18 16:07:07 +00:00
OutputDevice* pDev ) :
vcl::FontInfo( rInfo ), mpNext(NULL)
2000-09-18 16:07:07 +00:00
{
mpDevice = pDev;
}
OutputDevice* GetDevice() const { return mpDevice; }
};
enum class FontListFontNameType
{
NONE = 0x00,
PRINTER = 0x01,
SCREEN = 0x02,
};
namespace o3tl
{
template<> struct typed_flags<FontListFontNameType> : is_typed_flags<FontListFontNameType, 0x3> {};
}
2000-09-18 16:07:07 +00:00
class ImplFontListNameInfo
{
friend class FontList;
private:
OUString maSearchName;
2000-09-18 16:07:07 +00:00
ImplFontListFontInfo* mpFirst;
FontListFontNameType mnType;
2000-09-18 16:07:07 +00:00
ImplFontListNameInfo(const OUString& rSearchName)
: maSearchName(rSearchName)
, mpFirst(NULL)
, mnType(FontListFontNameType::NONE)
{
}
2000-09-18 16:07:07 +00:00
};
//sort normal to the start
static int sortWeightValue(FontWeight eWeight)
{
if (eWeight < WEIGHT_NORMAL)
return eWeight + 1;
if (eWeight > WEIGHT_NORMAL)
return eWeight - 1;
return 0; // eWeight == WEIGHT_NORMAL
}
2000-09-18 16:07:07 +00:00
static sal_Int32 ImplCompareFontInfo( ImplFontListFontInfo* pInfo1,
2000-09-18 16:07:07 +00:00
ImplFontListFontInfo* pInfo2 )
{
//Sort non italic before italics
if ( pInfo1->GetItalic() < pInfo2->GetItalic() )
return -1;
else if ( pInfo1->GetItalic() > pInfo2->GetItalic() )
return 1;
2000-09-18 16:07:07 +00:00
//Sort normal weight to the start, followed by lightest to heaviest weights
int nWeight1 = sortWeightValue(pInfo1->GetWeight());
int nWeight2 = sortWeightValue(pInfo2->GetWeight());
if ( nWeight1 < nWeight2 )
return -1;
else if ( nWeight1 > nWeight2 )
return 1;
2000-09-18 16:07:07 +00:00
return pInfo1->GetStyleName().compareTo( pInfo2->GetStyleName() );
2000-09-18 16:07:07 +00:00
}
static OUString ImplMakeSearchString(const OUString& rStr)
2000-09-18 16:07:07 +00:00
{
return rStr.toAsciiLowerCase();
2000-09-18 16:07:07 +00:00
}
static OUString ImplMakeSearchStringFromName(const OUString& rStr)
2000-09-18 16:07:07 +00:00
{
CWS-TOOLING: integrate CWS graphite01 2009-08-06 11:09:01 +0200 hdu r274708 : #i10000# fix build breaker for SYSTEM_GRAPHITE=NO 2009-07-21 12:01:52 +0200 hdu r274174 : #i93645# fix include files for EXT_USE_STLPORT 2009-07-21 11:51:07 +0200 hdu r274173 : #i93645# convert line-endings of files to be patched 2009-07-21 10:49:01 +0200 hdu r274170 : #i93645# adjust makefile.vc8 for HH-RelEng env (thanks ause) 2009-07-20 05:21:32 +0200 kstribley r274105 : attempt to fix Windows build error caused by NULL variable in nmake file 2009-07-16 10:22:36 +0200 hdu r274032 : #i69129# also use solar minor version to find graphite lib 2009-07-16 05:36:06 +0200 kstribley r274029 : allow windows build to have Graphite disabled with SAL_DISABLE_GRAPHITE 2009-07-15 13:59:22 +0200 hdu r274011 : #i69129# default to ENABLE_GRAPHITE=TRUE 2009-07-15 13:19:54 +0200 hdu r274008 : #i93645# ignore compile warnings for graphite 2009-07-15 13:18:25 +0200 hdu r274006 : #i93645# stlport needs libmath, use solar minor version to find matching libs 2009-07-15 09:21:13 +0200 hdu r273989 : #i100000# avoid compile warning 2009-07-14 12:19:08 +0200 hdu r273963 : CWS-TOOLING: rebase CWS graphite01 to trunk@273858 (milestone: DEV300:m52) 2009-07-13 06:54:56 +0200 kstribley r273912 : change to use standard file headers 2009-07-13 05:39:14 +0200 kstribley r273911 : Remove unnecessary change to configure.in as reported by Rene 2009-07-10 16:58:44 +0200 hdu r273902 : #i100000# fix compile for precompiled-header support 2009-07-02 13:48:26 +0200 kstribley r273647 : #69129# fix a graphite bug which could crash with fonts containing obscure GDL positioning rules 2009-07-02 01:44:02 +0200 rene r273616 : #i10000# we need to link with -licuuc 2009-07-01 04:02:20 +0200 kstribley r273540 : restore missing sdf files from base 2009-07-01 04:01:40 +0200 kstribley r273539 : restore missing sdf files from base 2009-07-01 04:01:12 +0200 kstribley r273538 : restore missing sdf files from base 2009-07-01 03:59:41 +0200 kstribley r273537 : restore missing sdf files from base 2009-06-29 10:16:51 +0200 kstribley r273456 : #i69129# fixes a bug which caused occasional incorrect linebreaking when graphite is asked to render a part of a cluster not containing a base 2009-06-27 10:43:58 +0200 kstribley r273445 : #i69129# added kashida support for justified RTL text 2009-06-01 12:57:06 +0200 kstribley r272476 : CWS-TOOLING: rebase CWS graphite01 to trunk@272291 (milestone: DEV300:m49) 2009-05-26 10:50:06 +0200 kstribley r272286 : #i69129# fixes a build error when NDEBUG is not defined 2009-05-25 13:14:06 +0200 kstribley r272237 : #i69129# enable debugging by fixing compile warnings 2009-05-25 13:07:47 +0200 kstribley r272234 : #i69129# added env variable to disable GRAPHITE at run time on linux and fixed a bug with a rare attachment sequence 2009-04-20 17:39:25 +0200 kstribley r271001 : CWS-TOOLING: rebase CWS graphite01 to trunk@270723 (milestone: DEV300:m46) 2009-04-18 07:11:33 +0200 kstribley r270957 : #i101178# attempt to fix buildbot builds by reordering configure.in 2009-04-14 17:37:07 +0200 kstribley r270801 : #i93645# tweak configure to enable graphite by default on windows and linux to assist testing with tinderbox build 2009-04-14 16:33:17 +0200 kstribley r270796 : #i96925# another fix for rtl fallback and add optional debug info in MultiSalLayout 2009-04-08 13:27:55 +0200 kstribley r270641 : #i69129# fix features after a bad merge 2009-04-08 13:26:34 +0200 kstribley r270640 : #i69129# add a patch for WinFont 2009-03-24 12:37:54 +0100 kstribley r269937 : #i69129# fix build error due to locale being included in method for features 2009-03-24 12:36:10 +0100 kstribley r269936 : #i93645# change patch variable and fix configure 2009-03-20 04:18:56 +0100 kstribley r269776 : CWS-TOOLING: rebase CWS graphite01 to trunk@269297 (milestone: DEV300:m43) 2009-03-01 13:10:59 +0100 kstribley r268622 : added a patch to improve handling of a font with bad graphite language feature tables #i93645# 2009-02-12 04:50:51 +0100 kstribley r267631 : #i93645# fix windows build for graphite 2.3.1 and remove unnecessary patch 2009-02-10 04:48:50 +0100 kstribley r267535 : #i93645# fix a build error with stlport on Ubuntu 8.10 x86 2009-02-10 03:51:10 +0100 kstribley r267534 : #i69129# remove legacy config_office 2009-02-07 19:12:54 +0100 kstribley r267482 : #i93645# upgrade to using silgraphite-2.3.1 2009-02-02 18:17:57 +0100 kstribley r267290 : #i69129# backout unwanted checkin 2009-02-02 17:44:03 +0100 kstribley r267281 : #i69129# backout erroneous update to aclocal.m4 2009-02-01 10:05:03 +0100 kstribley r267236 : #i69129# fix build error due to locale being added to set font attributes 2009-02-01 06:02:52 +0100 kstribley r267235 : #i69129# fix erroneous merge 2009-01-31 16:24:56 +0100 kstribley r267234 : #i69129# update configure.in solenv.in in their new locations with enable graphite 2009-01-31 10:53:18 +0100 kstribley r267232 : CWS-TOOLING: rebase CWS graphite01 to trunk@267171 (milestone: DEV300:m41) 2008-12-17 04:17:33 +0100 kstribley r265577 : #i93645# remove superfluous autoreconf check and autoconf patch 2008-12-16 10:07:20 +0100 rene r265529 : fix aclocal.m4 breakage 2008-12-16 05:13:29 +0100 kstribley r265520 : #i93645# change to autoconf && configure 2008-12-16 04:39:48 +0100 kstribley r265519 : #i93645# modified LD_FLAGS so that system graphite isn't pulled in by accident and fixed autoconf problem 2008-12-15 14:16:25 +0100 rene r265497 : check for working STL 2008-12-15 12:53:39 +0100 rene r265473 : revert broken check 2008-12-15 11:59:21 +0100 kstribley r265472 : #i93645# added check for system STL, since this is a requirement for system graphite to work correctly and moved the position of the check further down 2008-12-15 11:55:34 +0100 kstribley r265471 : #i93645# remove references to gr3ooo to allow system graphite to be used 2008-12-12 18:48:18 +0100 rene r265437 : fix link for system-graphite 2008-12-12 18:46:45 +0100 rene r265436 : the tarball is in graphite, remove obsolete check 2008-12-12 18:22:22 +0100 rene r265433 : typo; re-autoconf 2008-12-12 17:35:26 +0100 rene r265432 : actually implement SYSTEM_GRAPHIT checks (as already checked for in makefile.mks) but remove the checks in graphit itself and move to BUILD_TYPE 2008-12-12 08:08:33 +0100 kstribley r265387 : #i69129# 2 of the patched files need windows line endings so patch works on linux as well as windows 2008-12-12 08:04:41 +0100 kstribley r265386 : #i69129# rtl fallback fix which prevents caching of segments with fallback 2008-12-08 04:28:12 +0100 kstribley r264969 : results of running autoconf with graphite config changes #i69129# 2008-12-05 08:12:47 +0100 kstribley r264886 : backout unintential change at r264884 2008-12-05 06:26:33 +0100 kstribley r264884 : #i96925# fixes for uniscribe fallback 2008-12-05 06:11:37 +0100 kstribley r264883 : #i69129# improvements to windows graphite code, including caching of sila table lookup 2008-12-02 13:28:51 +0100 kstribley r264694 : #i93645# add graphite library and append to patch 2008-11-27 06:47:10 +0100 kstribley r264445 : #69129# fix rtl loop bug and rtl caching problem 2008-11-27 06:42:20 +0100 kstribley r264444 : add caching for GraphiteFontAdaptor 2008-11-14 15:57:03 +0100 kstribley r263681 : #69129# add graphite addtional files from cvs 2008-11-14 15:54:47 +0100 kstribley r263680 : #69129# fix for modified resolution api 2008-11-13 16:24:09 +0100 kstribley r263652 : #69129# add skeleton to build graphite module library 2008-11-13 16:22:19 +0100 kstribley r263651 : #69129# add skeleton to build graphite module library 2008-11-13 16:16:10 +0100 kstribley r263650 : #69129# migrate from cvs 2008-11-13 15:26:54 +0100 kstribley r263646 : #69129# add a module for the graphite library
2009-08-17 14:12:14 +00:00
// check for features before alternate font separator
sal_Int32 nColon = rStr.indexOf(':');
sal_Int32 nSemiColon = rStr.indexOf(';');
if (nColon != -1 && (nSemiColon == -1 || nColon < nSemiColon))
return ImplMakeSearchString(rStr.getToken( 0, ':' ));
return ImplMakeSearchString(rStr.getToken( 0, ';' ));
2000-09-18 16:07:07 +00:00
}
ImplFontListNameInfo* FontList::ImplFind(const OUString& rSearchName, sal_uLong* pIndex) const
2000-09-18 16:07:07 +00:00
{
// Append if there is no enty in the list or if the entry is larger
// then the last one. We only compare to the last entry as the list of VCL
// is returned sorted, which increases the probability that appending
// is more likely
2011-05-02 12:29:34 -04:30
sal_uLong nCnt = maEntries.size();
if ( !nCnt )
2000-09-18 16:07:07 +00:00
{
if ( pIndex )
2011-05-02 12:29:34 -04:30
*pIndex = ULONG_MAX;
2000-09-18 16:07:07 +00:00
return NULL;
}
else
{
2011-05-02 12:29:34 -04:30
const ImplFontListNameInfo* pCmpData = &maEntries[nCnt-1];
sal_Int32 nComp = rSearchName.compareTo( pCmpData->maSearchName );
if (nComp > 0)
2000-09-18 16:07:07 +00:00
{
if ( pIndex )
2011-05-02 12:29:34 -04:30
*pIndex = ULONG_MAX;
2000-09-18 16:07:07 +00:00
return NULL;
}
else if (nComp == 0)
2011-05-02 12:29:34 -04:30
return const_cast<ImplFontListNameInfo*>(pCmpData);
2000-09-18 16:07:07 +00:00
}
// search fonts in the list
2011-05-02 12:29:34 -04:30
const ImplFontListNameInfo* pCompareData;
const ImplFontListNameInfo* pFoundData = NULL;
sal_uLong nLow = 0;
sal_uLong nHigh = nCnt-1;
sal_uLong nMid;
2000-09-18 16:07:07 +00:00
do
{
nMid = (nLow + nHigh) / 2;
2011-05-02 12:29:34 -04:30
pCompareData = &maEntries[nMid];
sal_Int32 nComp = rSearchName.compareTo(pCompareData->maSearchName);
if (nComp < 0)
2000-09-18 16:07:07 +00:00
{
if ( !nMid )
break;
nHigh = nMid-1;
}
else
{
if (nComp > 0)
2000-09-18 16:07:07 +00:00
nLow = nMid + 1;
else
{
pFoundData = pCompareData;
break;
}
}
}
while ( nLow <= nHigh );
if ( pIndex )
{
sal_Int32 nComp = rSearchName.compareTo(pCompareData->maSearchName);
if (nComp > 0)
2000-09-18 16:07:07 +00:00
*pIndex = (nMid+1);
else
*pIndex = nMid;
}
2011-05-02 12:29:34 -04:30
return const_cast<ImplFontListNameInfo*>(pFoundData);
2000-09-18 16:07:07 +00:00
}
ImplFontListNameInfo* FontList::ImplFindByName(const OUString& rStr) const
2000-09-18 16:07:07 +00:00
{
OUString aSearchName = ImplMakeSearchStringFromName(rStr);
2000-09-18 16:07:07 +00:00
return ImplFind( aSearchName, NULL );
}
void FontList::ImplInsertFonts( OutputDevice* pDevice, bool bAll,
bool bInsertData )
2000-09-18 16:07:07 +00:00
{
rtl_TextEncoding eSystemEncoding = osl_getThreadTextEncoding();
2000-09-18 16:07:07 +00:00
FontListFontNameType nType;
if ( pDevice->GetOutDevType() != OUTDEV_PRINTER )
nType = FontListFontNameType::SCREEN;
else
nType = FontListFontNameType::PRINTER;
// inquire all fonts from the device
int n = pDevice->GetDevFontCount();
sal_uInt16 i;
2000-09-18 16:07:07 +00:00
for( i = 0; i < n; i++ )
{
vcl::FontInfo aFontInfo = pDevice->GetDevFont( i );
2000-09-18 16:07:07 +00:00
// ignore raster-fonts if they are not to be displayed
2000-09-18 16:07:07 +00:00
if ( !bAll && (aFontInfo.GetType() == TYPE_RASTER) )
continue;
OUString aSearchName(aFontInfo.GetName());
2000-09-18 16:07:07 +00:00
ImplFontListNameInfo* pData;
sal_uLong nIndex;
aSearchName = ImplMakeSearchString(aSearchName);
2000-09-18 16:07:07 +00:00
pData = ImplFind( aSearchName, &nIndex );
if ( !pData )
{
if ( bInsertData )
{
ImplFontListFontInfo* pNewInfo = new ImplFontListFontInfo( aFontInfo, pDevice );
pData = new ImplFontListNameInfo( aSearchName );
pData->mpFirst = pNewInfo;
pNewInfo->mpNext = NULL;
2011-05-02 12:29:34 -04:30
if (nIndex < maEntries.size())
maEntries.insert(maEntries.begin()+nIndex,pData);
else
maEntries.push_back(pData);
2000-09-18 16:07:07 +00:00
}
}
else
{
if ( bInsertData )
{
bool bInsert = true;
2000-09-18 16:07:07 +00:00
ImplFontListFontInfo* pPrev = NULL;
ImplFontListFontInfo* pTemp = pData->mpFirst;
ImplFontListFontInfo* pNewInfo = new ImplFontListFontInfo( aFontInfo, pDevice );
while ( pTemp )
{
sal_Int32 eComp = ImplCompareFontInfo( pNewInfo, pTemp );
if ( eComp <= 0 )
2000-09-18 16:07:07 +00:00
{
if ( eComp == 0 )
2000-09-18 16:07:07 +00:00
{
// Overwrite charset, because charset should match
// with the system charset
if ( (pTemp->GetCharSet() != eSystemEncoding) &&
(pNewInfo->GetCharSet() == eSystemEncoding) )
{
ImplFontListFontInfo* pTemp2 = pTemp->mpNext;
*static_cast<vcl::FontInfo*>(pTemp) = *static_cast<vcl::FontInfo*>(pNewInfo);
2000-09-18 16:07:07 +00:00
pTemp->mpNext = pTemp2;
}
delete pNewInfo;
bInsert = false;
2000-09-18 16:07:07 +00:00
}
break;
}
pPrev = pTemp;
pTemp = pTemp->mpNext;
}
if ( bInsert )
{
pNewInfo->mpNext = pTemp;
if ( pPrev )
pPrev->mpNext = pNewInfo;
else
pData->mpFirst = pNewInfo;
}
}
}
if ( pData )
pData->mnType |= nType;
2000-09-18 16:07:07 +00:00
}
}
FontList::FontList( OutputDevice* pDevice, OutputDevice* pDevice2, bool bAll )
2000-09-18 16:07:07 +00:00
{
// initialise variables
2000-09-18 16:07:07 +00:00
mpDev = pDevice;
mpDev2 = pDevice2;
mpSizeAry = NULL;
// store style names
maLight = SVT_RESSTR(STR_SVT_STYLE_LIGHT);
maLightItalic = SVT_RESSTR(STR_SVT_STYLE_LIGHT_ITALIC);
maNormal = SVT_RESSTR(STR_SVT_STYLE_NORMAL);
maNormalItalic = SVT_RESSTR(STR_SVT_STYLE_NORMAL_ITALIC);
maBold = SVT_RESSTR(STR_SVT_STYLE_BOLD);
maBoldItalic = SVT_RESSTR(STR_SVT_STYLE_BOLD_ITALIC);
maBlack = SVT_RESSTR(STR_SVT_STYLE_BLACK);
maBlackItalic = SVT_RESSTR(STR_SVT_STYLE_BLACK_ITALIC);
2000-09-18 16:07:07 +00:00
ImplInsertFonts( pDevice, bAll, true );
2000-09-18 16:07:07 +00:00
// if required compare to the screen fonts
// in order to map the duplicates to Equal
bool bCompareWindow = false;
2000-09-18 16:07:07 +00:00
if ( !pDevice2 && (pDevice->GetOutDevType() == OUTDEV_PRINTER) )
{
bCompareWindow = true;
2000-09-18 16:07:07 +00:00
pDevice2 = Application::GetDefaultDevice();
}
if ( pDevice2 &&
(pDevice2->GetOutDevType() != pDevice->GetOutDevType()) )
ImplInsertFonts( pDevice2, bAll, !bCompareWindow );
}
FontList::~FontList()
{
// delete SizeArray if required
delete[] mpSizeAry;
2000-09-18 16:07:07 +00:00
// delete FontInfos
2011-05-02 12:29:34 -04:30
ImplFontListFontInfo *pTemp, *pInfo;
boost::ptr_vector<ImplFontListNameInfo>::iterator it;
for (it = maEntries.begin(); it != maEntries.end(); ++it)
2000-09-18 16:07:07 +00:00
{
2011-05-02 12:29:34 -04:30
pInfo = it->mpFirst;
2000-09-18 16:07:07 +00:00
while ( pInfo )
{
pTemp = pInfo->mpNext;
delete pInfo;
pInfo = pTemp;
}
}
}
FontList* FontList::Clone() const
{
FontList* pReturn = new FontList(
mpDev, mpDev2, GetFontNameCount() == mpDev->GetDevFontCount());
return pReturn;
}
2000-09-18 16:07:07 +00:00
const OUString& FontList::GetStyleName(FontWeight eWeight, FontItalic eItalic) const
{
if ( eWeight > WEIGHT_BOLD )
{
if ( eItalic > ITALIC_NONE )
return maBlackItalic;
else
return maBlack;
}
else if ( eWeight > WEIGHT_MEDIUM )
{
if ( eItalic > ITALIC_NONE )
return maBoldItalic;
else
return maBold;
}
else if ( eWeight > WEIGHT_LIGHT )
{
if ( eItalic > ITALIC_NONE )
return maNormalItalic;
else
return maNormal;
}
else if ( eWeight != WEIGHT_DONTKNOW )
{
if ( eItalic > ITALIC_NONE )
return maLightItalic;
else
return maLight;
}
else
{
if ( eItalic > ITALIC_NONE )
return maNormalItalic;
else
return maNormal;
}
}
OUString FontList::GetStyleName(const vcl::FontInfo& rInfo) const
2000-09-18 16:07:07 +00:00
{
OUString aStyleName = rInfo.GetStyleName();
FontWeight eWeight = rInfo.GetWeight();
FontItalic eItalic = rInfo.GetItalic();
2000-09-18 16:07:07 +00:00
// return synthetic Name if no StyleName was set
if (aStyleName.isEmpty())
aStyleName = GetStyleName(eWeight, eItalic);
else
2000-09-18 16:07:07 +00:00
{
// Translate StyleName to localized name
OUString aCompareStyleName = aStyleName.toAsciiLowerCase();
2011-11-18 21:03:31 +00:00
aCompareStyleName = comphelper::string::remove(aCompareStyleName, ' ');
if (aCompareStyleName == "bold")
aStyleName = maBold;
else if (aCompareStyleName == "bolditalic")
aStyleName = maBoldItalic;
else if (aCompareStyleName == "italic")
aStyleName = maNormalItalic;
else if (aCompareStyleName == "standard")
aStyleName = maNormal;
else if (aCompareStyleName == "regular")
aStyleName = maNormal;
else if (aCompareStyleName == "medium")
aStyleName = maNormal;
else if (aCompareStyleName == "light")
aStyleName = maLight;
else if (aCompareStyleName == "lightitalic")
aStyleName = maLightItalic;
else if (aCompareStyleName == "black")
aStyleName = maBlack;
else if (aCompareStyleName == "blackitalic")
aStyleName = maBlackItalic;
// fix up StyleName, because the PS Printer driver from
// W2000 returns wrong StyleNames (e.g. Bold instead of Bold Italic
// for Helvetica)
if ( eItalic > ITALIC_NONE )
2000-09-18 16:07:07 +00:00
{
if ( (aStyleName == maNormal) ||
(aStyleName == maBold) ||
(aStyleName == maLight) ||
(aStyleName == maBlack) )
aStyleName = GetStyleName( eWeight, eItalic );
2000-09-18 16:07:07 +00:00
}
}
return aStyleName;
}
OUString FontList::GetFontMapText( const vcl::FontInfo& rInfo ) const
{
if ( rInfo.GetName().isEmpty() )
{
return OUString();
}
// Search Fontname
ImplFontListNameInfo* pData = ImplFindByName( rInfo.GetName() );
if ( !pData )
{
if (maMapNotAvailable.isEmpty())
maMapNotAvailable = SVT_RESSTR(STR_SVT_FONTMAP_NOTAVAILABLE);
return maMapNotAvailable;
}
// search for synthetic style
FontListFontNameType nType = pData->mnType;
const OUString& rStyleName = rInfo.GetStyleName();
if (!rStyleName.isEmpty())
{
bool bNotSynthetic = false;
FontWeight eWeight = rInfo.GetWeight();
FontItalic eItalic = rInfo.GetItalic();
ImplFontListFontInfo* pFontInfo = pData->mpFirst;
while ( pFontInfo )
{
if ( (eWeight == pFontInfo->GetWeight()) &&
(eItalic == pFontInfo->GetItalic()) )
{
bNotSynthetic = true;
break;
}
pFontInfo = pFontInfo->mpNext;
}
if ( !bNotSynthetic )
{
if (maMapStyleNotAvailable.isEmpty())
const_cast<FontList*>(this)->maMapStyleNotAvailable = SVT_RESSTR(STR_SVT_FONTMAP_STYLENOTAVAILABLE);
return maMapStyleNotAvailable;
}
}
// Only Printer-Font?
if ( nType == FontListFontNameType::PRINTER )
{
if (maMapPrinterOnly.isEmpty())
const_cast<FontList*>(this)->maMapPrinterOnly = SVT_RESSTR(STR_SVT_FONTMAP_PRINTERONLY);
return maMapPrinterOnly;
}
// Only Screen-Font?
else if ( nType == FontListFontNameType::SCREEN
&& rInfo.GetType() == TYPE_RASTER )
{
if (maMapScreenOnly.isEmpty())
const_cast<FontList*>(this)->maMapScreenOnly = SVT_RESSTR(STR_SVT_FONTMAP_SCREENONLY);
return maMapScreenOnly;
}
else
{
if (maMapBoth.isEmpty())
const_cast<FontList*>(this)->maMapBoth = SVT_RESSTR(STR_SVT_FONTMAP_BOTH);
return maMapBoth;
}
}
namespace
{
vcl::FontInfo makeMissing(ImplFontListFontInfo* pFontNameInfo, const OUString &rName,
FontWeight eWeight, FontItalic eItalic)
{
vcl::FontInfo aInfo;
// if the fontname matches, we copy as much as possible
if (pFontNameInfo)
{
aInfo = *pFontNameInfo;
aInfo.SetStyleName(OUString());
}
aInfo.SetWeight(eWeight);
aInfo.SetItalic(eItalic);
//If this is a known but uninstalled symbol font which we can remap to
//OpenSymbol then toggle its charset to be a symbol font
if (ConvertChar::GetRecodeData(rName, OUString("OpenSymbol")))
aInfo.SetCharSet(RTL_TEXTENCODING_SYMBOL);
return aInfo;
}
}
2000-09-18 16:07:07 +00:00
vcl::FontInfo FontList::Get(const OUString& rName, const OUString& rStyleName) const
2000-09-18 16:07:07 +00:00
{
ImplFontListNameInfo* pData = ImplFindByName( rName );
ImplFontListFontInfo* pFontInfo = NULL;
ImplFontListFontInfo* pFontNameInfo = NULL;
if ( pData )
{
ImplFontListFontInfo* pSearchInfo = pData->mpFirst;
pFontNameInfo = pSearchInfo;
pSearchInfo = pData->mpFirst;
2000-09-18 16:07:07 +00:00
while ( pSearchInfo )
{
if (rStyleName.equalsIgnoreAsciiCase(GetStyleName(*pSearchInfo)))
2000-09-18 16:07:07 +00:00
{
pFontInfo = pSearchInfo;
break;
}
pSearchInfo = pSearchInfo->mpNext;
}
}
// reproduce attributes if data could not be found
vcl::FontInfo aInfo;
2000-09-18 16:07:07 +00:00
if ( !pFontInfo )
{
FontWeight eWeight = WEIGHT_DONTKNOW;
FontItalic eItalic = ITALIC_NONE;
2000-09-18 16:07:07 +00:00
if ( rStyleName == maNormal )
{
eItalic = ITALIC_NONE;
eWeight = WEIGHT_NORMAL;
2000-09-18 16:07:07 +00:00
}
else if ( rStyleName == maNormalItalic )
{
eItalic = ITALIC_NORMAL;
eWeight = WEIGHT_NORMAL;
2000-09-18 16:07:07 +00:00
}
else if ( rStyleName == maBold )
{
eItalic = ITALIC_NONE;
eWeight = WEIGHT_BOLD;
2000-09-18 16:07:07 +00:00
}
else if ( rStyleName == maBoldItalic )
{
eItalic = ITALIC_NORMAL;
eWeight = WEIGHT_BOLD;
2000-09-18 16:07:07 +00:00
}
else if ( rStyleName == maLight )
{
eItalic = ITALIC_NONE;
eWeight = WEIGHT_LIGHT;
2000-09-18 16:07:07 +00:00
}
else if ( rStyleName == maLightItalic )
{
eItalic = ITALIC_NORMAL;
eWeight = WEIGHT_LIGHT;
2000-09-18 16:07:07 +00:00
}
else if ( rStyleName == maBlack )
{
eItalic = ITALIC_NONE;
eWeight = WEIGHT_BLACK;
2000-09-18 16:07:07 +00:00
}
else if ( rStyleName == maBlackItalic )
{
eItalic = ITALIC_NORMAL;
eWeight = WEIGHT_BLACK;
2000-09-18 16:07:07 +00:00
}
aInfo = makeMissing(pFontNameInfo, rName, eWeight, eItalic);
2000-09-18 16:07:07 +00:00
}
else
aInfo = *pFontInfo;
// set Fontname to keep FontAlias
aInfo.SetName( rName );
aInfo.SetStyleName( rStyleName );
return aInfo;
2000-09-18 16:07:07 +00:00
}
vcl::FontInfo FontList::Get(const OUString& rName,
FontWeight eWeight, FontItalic eItalic) const
2000-09-18 16:07:07 +00:00
{
ImplFontListNameInfo* pData = ImplFindByName( rName );
ImplFontListFontInfo* pFontInfo = NULL;
ImplFontListFontInfo* pFontNameInfo = NULL;
if ( pData )
{
ImplFontListFontInfo* pSearchInfo = pData->mpFirst;
pFontNameInfo = pSearchInfo;
while ( pSearchInfo )
{
if ( (eWeight == pSearchInfo->GetWeight()) &&
(eItalic == pSearchInfo->GetItalic()) )
{
pFontInfo = pSearchInfo;
break;
}
pSearchInfo = pSearchInfo->mpNext;
}
}
// reproduce attributes if data could not be found
vcl::FontInfo aInfo;
2000-09-18 16:07:07 +00:00
if ( !pFontInfo )
aInfo = makeMissing(pFontNameInfo, rName, eWeight, eItalic);
2000-09-18 16:07:07 +00:00
else
aInfo = *pFontInfo;
// set Fontname to keep FontAlias
aInfo.SetName( rName );
return aInfo;
2000-09-18 16:07:07 +00:00
}
bool FontList::IsAvailable(const OUString& rName) const
2000-09-18 16:07:07 +00:00
{
return (ImplFindByName( rName ) != 0);
}
const vcl::FontInfo& FontList::GetFontName( sal_uInt16 nFont ) const
2000-09-18 16:07:07 +00:00
{
DBG_ASSERT( nFont < GetFontNameCount(), "FontList::GetFontName(): nFont >= Count" );
2011-05-02 12:29:34 -04:30
return *(maEntries[nFont].mpFirst);
2000-09-18 16:07:07 +00:00
}
sal_Handle FontList::GetFirstFontInfo(const OUString& rName) const
2000-09-18 16:07:07 +00:00
{
ImplFontListNameInfo* pData = ImplFindByName( rName );
if ( !pData )
return nullptr;
2000-09-18 16:07:07 +00:00
else
return static_cast<sal_Handle>(pData->mpFirst);
2000-09-18 16:07:07 +00:00
}
sal_Handle FontList::GetNextFontInfo( sal_Handle hFontInfo )
2000-09-18 16:07:07 +00:00
{
ImplFontListFontInfo* pInfo = static_cast<ImplFontListFontInfo*>(hFontInfo);
return static_cast<sal_Handle>(pInfo->mpNext);
2000-09-18 16:07:07 +00:00
}
const vcl::FontInfo& FontList::GetFontInfo( sal_Handle hFontInfo )
2000-09-18 16:07:07 +00:00
{
ImplFontListFontInfo* pInfo = static_cast<ImplFontListFontInfo*>(hFontInfo);
2000-09-18 16:07:07 +00:00
return *pInfo;
}
const sal_IntPtr* FontList::GetSizeAry( const vcl::FontInfo& rInfo ) const
2000-09-18 16:07:07 +00:00
{
// first delete Size-Array
2000-09-18 16:07:07 +00:00
if ( mpSizeAry )
{
delete[] const_cast<FontList*>(this)->mpSizeAry;
const_cast<FontList*>(this)->mpSizeAry = NULL;
2000-09-18 16:07:07 +00:00
}
// use standarad sizes if no name
if ( rInfo.GetName().isEmpty() )
2000-09-18 16:07:07 +00:00
return aStdSizeAry;
// first search fontname in order to use device from the matching font
2000-09-18 16:07:07 +00:00
OutputDevice* pDevice = mpDev;
ImplFontListNameInfo* pData = ImplFindByName( rInfo.GetName() );
if ( pData )
pDevice = pData->mpFirst->GetDevice();
int nDevSizeCount = pDevice->GetDevFontSizeCount( rInfo );
2000-09-18 16:07:07 +00:00
if ( !nDevSizeCount ||
(pDevice->GetDevFontSize( rInfo, 0 ).Height() == 0) )
return aStdSizeAry;
MapMode aOldMapMode = pDevice->GetMapMode();
MapMode aMap( MAP_10TH_INCH, Point(), Fraction( 1, 72 ), Fraction( 1, 72 ) );
2000-09-18 16:07:07 +00:00
pDevice->SetMapMode( aMap );
sal_uInt16 i;
sal_uInt16 nRealCount = 0;
2000-09-18 16:07:07 +00:00
long nOldHeight = 0;
const_cast<FontList*>(this)->mpSizeAry = new sal_IntPtr[nDevSizeCount+1];
2000-09-18 16:07:07 +00:00
for ( i = 0; i < nDevSizeCount; i++ )
{
Size aSize = pDevice->GetDevFontSize( rInfo, i );
if ( aSize.Height() != nOldHeight )
{
nOldHeight = aSize.Height();
const_cast<FontList*>(this)->mpSizeAry[nRealCount] = nOldHeight;
2000-09-18 16:07:07 +00:00
nRealCount++;
}
}
const_cast<FontList*>(this)->mpSizeAry[nRealCount] = 0;
2000-09-18 16:07:07 +00:00
pDevice->SetMapMode( aOldMapMode );
return mpSizeAry;
}
struct ImplFSNameItem
2000-12-07 15:07:37 +00:00
{
long mnSize;
const char* mszUtf8Name;
2000-12-07 15:07:37 +00:00
};
2011-03-01 16:08:28 +01:00
static const ImplFSNameItem aImplSimplifiedChinese[] =
2000-12-07 15:07:37 +00:00
{
{ 50, "\xe5\x85\xab\xe5\x8f\xb7" },
{ 55, "\xe4\xb8\x83\xe5\x8f\xb7" },
{ 65, "\xe5\xb0\x8f\xe5\x85\xad" },
{ 75, "\xe5\x85\xad\xe5\x8f\xb7" },
{ 90, "\xe5\xb0\x8f\xe4\xba\x94" },
{ 105, "\xe4\xba\x94\xe5\x8f\xb7" },
{ 120, "\xe5\xb0\x8f\xe5\x9b\x9b" },
{ 140, "\xe5\x9b\x9b\xe5\x8f\xb7" },
{ 150, "\xe5\xb0\x8f\xe4\xb8\x89" },
{ 160, "\xe4\xb8\x89\xe5\x8f\xb7" },
{ 180, "\xe5\xb0\x8f\xe4\xba\x8c" },
{ 220, "\xe4\xba\x8c\xe5\x8f\xb7" },
{ 240, "\xe5\xb0\x8f\xe4\xb8\x80" },
{ 260, "\xe4\xb8\x80\xe5\x8f\xb7" },
{ 360, "\xe5\xb0\x8f\xe5\x88\x9d" },
{ 420, "\xe5\x88\x9d\xe5\x8f\xb7" }
2000-12-07 15:07:37 +00:00
};
FontSizeNames::FontSizeNames( LanguageType eLanguage )
2000-12-07 15:07:37 +00:00
{
if ( eLanguage == LANGUAGE_DONTKNOW )
eLanguage = Application::GetSettings().GetUILanguageTag().getLanguageType();
if ( eLanguage == LANGUAGE_SYSTEM )
eLanguage = MsLangId::getSystemUILanguage();
if (MsLangId::isSimplifiedChinese(eLanguage))
2000-12-07 15:07:37 +00:00
{
// equivalent for traditional chinese disabled by popular request, #i89077#
mpArray = aImplSimplifiedChinese;
mnElem = SAL_N_ELEMENTS(aImplSimplifiedChinese);
}
else
{
mpArray = NULL;
mnElem = 0;
}
2000-12-07 15:07:37 +00:00
}
long FontSizeNames::Name2Size( const OUString& rName ) const
2000-12-07 15:07:37 +00:00
{
if ( mnElem )
{
OString aName(OUStringToOString(rName,
2011-11-07 22:24:39 +00:00
RTL_TEXTENCODING_UTF8));
// linear search is sufficient for this rare case
for( long i = mnElem; --i >= 0; )
2011-11-07 22:24:39 +00:00
if ( aName.equals(mpArray[i].mszUtf8Name) )
return mpArray[i].mnSize;
}
2000-12-07 15:07:37 +00:00
return 0;
}
OUString FontSizeNames::Size2Name( long nValue ) const
2000-12-07 15:07:37 +00:00
{
OUString aStr;
2000-12-07 15:07:37 +00:00
// binary search
for( long lower = 0, upper = mnElem - 1; lower <= upper; )
{
long mid = (upper + lower) >> 1;
if ( nValue == mpArray[mid].mnSize )
2001-03-28 07:29:03 +00:00
{
aStr = OUString( mpArray[mid].mszUtf8Name, strlen(mpArray[mid].mszUtf8Name), RTL_TEXTENCODING_UTF8 );
2001-03-28 07:29:03 +00:00
break;
}
else if ( nValue < mpArray[mid].mnSize )
2000-12-07 15:07:37 +00:00
upper = mid - 1;
2001-03-28 07:29:03 +00:00
else /* ( nValue > mpArray[mid].mnSize ) */
2000-12-07 15:07:37 +00:00
lower = mid + 1;
}
return aStr;
2000-12-07 15:07:37 +00:00
}
OUString FontSizeNames::GetIndexName( sal_uLong nIndex ) const
2000-12-07 15:07:37 +00:00
{
OUString aStr;
if ( nIndex < mnElem )
aStr = OUString( mpArray[nIndex].mszUtf8Name, strlen(mpArray[nIndex].mszUtf8Name), RTL_TEXTENCODING_UTF8 );
return aStr;
2000-12-07 15:07:37 +00:00
}
long FontSizeNames::GetIndexSize( sal_uLong nIndex ) const
2000-12-07 15:07:37 +00:00
{
if ( nIndex >= mnElem )
2000-12-07 15:07:37 +00:00
return 0;
return mpArray[nIndex].mnSize;
2000-12-07 15:07:37 +00:00
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */