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

977 lines
29 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2000-09-18 16:07:07 +00:00
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2000-09-18 16:07:07 +00:00
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
2000-09-18 16:07:07 +00:00
*
* OpenOffice.org - a multi-platform office productivity suite
2000-09-18 16:07:07 +00:00
*
* This file is part of OpenOffice.org.
2000-09-18 16:07:07 +00:00
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
2000-09-18 16:07:07 +00:00
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
2000-09-18 16:07:07 +00:00
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
2000-09-18 16:07:07 +00:00
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_svtools.hxx"
2000-09-18 16:07:07 +00:00
#define CTRLTOOL_CXX
#include <string.h>
#include <tools/debug.hxx>
#include <i18npool/mslangid.hxx>
2000-09-18 16:07:07 +00:00
#include <vcl/window.hxx>
#include <vcl/svapp.hxx>
#include <vcl/wrkwin.hxx>
#include <sal/macros.h>
#include <svtools/svtools.hrc>
#include <svtools/svtdata.hxx>
#include <svtools/ctrltool.hxx>
2000-09-18 16:07:07 +00:00
// =======================================================================
// Standard Fontgroessen fuer scalierbare Fonts
2011-03-01 16:08:28 +01:00
static const long 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 ImplFontListFonInfo -
// -----------------------------
class ImplFontListFontInfo : public FontInfo
{
friend class FontList;
private:
OutputDevice* mpDevice;
ImplFontListFontInfo* mpNext;
public:
ImplFontListFontInfo( const FontInfo& rInfo,
OutputDevice* pDev ) :
FontInfo( rInfo )
{
mpDevice = pDev;
}
OutputDevice* GetDevice() const { return mpDevice; }
};
// ------------------------------
// - class ImplFontListNameInfo -
// ------------------------------
class ImplFontListNameInfo
{
friend class FontList;
private:
XubString maSearchName;
ImplFontListFontInfo* mpFirst;
sal_uInt16 mnType;
2000-09-18 16:07:07 +00:00
ImplFontListNameInfo( const XubString& rSearchName ) :
maSearchName( rSearchName )
{}
};
// =======================================================================
static StringCompare ImplCompareFontInfo( ImplFontListFontInfo* pInfo1,
ImplFontListFontInfo* pInfo2 )
{
if ( pInfo1->GetWeight() < pInfo2->GetWeight() )
return COMPARE_LESS;
else if ( pInfo1->GetWeight() > pInfo2->GetWeight() )
return COMPARE_GREATER;
if ( pInfo1->GetItalic() < pInfo2->GetItalic() )
return COMPARE_LESS;
else if ( pInfo1->GetItalic() > pInfo2->GetItalic() )
return COMPARE_GREATER;
return pInfo1->GetStyleName().CompareTo( pInfo2->GetStyleName() );
}
// =======================================================================
static void ImplMakeSearchString( XubString& rStr )
{
rStr.ToLowerAscii();
}
// -----------------------------------------------------------------------
static void ImplMakeSearchStringFromName( XubString& rStr )
{
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
if (rStr.Search(':') < rStr.Search(';'))
rStr = rStr.GetToken( 0, ':' );
else
rStr = rStr.GetToken( 0, ';' );
2000-09-18 16:07:07 +00:00
ImplMakeSearchString( rStr );
}
// -----------------------------------------------------------------------
ImplFontListNameInfo* FontList::ImplFind( const XubString& rSearchName, sal_uLong* pIndex ) const
2000-09-18 16:07:07 +00:00
{
// Wenn kein Eintrag in der Liste oder der Eintrag groesser ist als
// der Letzte, dann hinten dranhaengen. Wir vergleichen erst mit dem
// letzten Eintrag, da die Liste von VCL auch sortiert zurueckkommt
// und somit die Wahrscheinlichkeit das hinten angehaengt werden muss
// sehr gross ist.
StringCompare eComp;
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];
2000-09-18 16:07:07 +00:00
eComp = rSearchName.CompareTo( pCmpData->maSearchName );
if ( eComp == COMPARE_GREATER )
{
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 ( eComp == COMPARE_EQUAL )
2011-05-02 12:29:34 -04:30
return const_cast<ImplFontListNameInfo*>(pCmpData);
2000-09-18 16:07:07 +00:00
}
// Fonts in der Liste suchen
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];
2000-09-18 16:07:07 +00:00
eComp = rSearchName.CompareTo( pCompareData->maSearchName );
if ( eComp == COMPARE_LESS )
{
if ( !nMid )
break;
nHigh = nMid-1;
}
else
{
if ( eComp == COMPARE_GREATER )
nLow = nMid + 1;
else
{
pFoundData = pCompareData;
break;
}
}
}
while ( nLow <= nHigh );
if ( pIndex )
{
eComp = rSearchName.CompareTo( pCompareData->maSearchName );
if ( eComp == COMPARE_GREATER )
*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 XubString& rStr ) const
{
XubString aSearchName = rStr;
ImplMakeSearchStringFromName( aSearchName );
return ImplFind( aSearchName, NULL );
}
// -----------------------------------------------------------------------
void FontList::ImplInsertFonts( OutputDevice* pDevice, sal_Bool bAll,
sal_Bool bInsertData )
2000-09-18 16:07:07 +00:00
{
rtl_TextEncoding eSystemEncoding = osl_getThreadTextEncoding();
2000-09-18 16:07:07 +00:00
sal_uInt16 nType;
2000-09-18 16:07:07 +00:00
if ( pDevice->GetOutDevType() != OUTDEV_PRINTER )
nType = FONTLIST_FONTNAMETYPE_SCREEN;
else
nType = FONTLIST_FONTNAMETYPE_PRINTER;
// Alle Fonts vom Device abfragen
int n = pDevice->GetDevFontCount();
sal_uInt16 i;
2000-09-18 16:07:07 +00:00
for( i = 0; i < n; i++ )
{
FontInfo aFontInfo = pDevice->GetDevFont( i );
// Wenn keine Raster-Schriften angezeigt werden sollen,
// dann diese ignorieren
if ( !bAll && (aFontInfo.GetType() == TYPE_RASTER) )
continue;
XubString aSearchName = aFontInfo.GetName();
ImplFontListNameInfo* pData;
sal_uLong nIndex;
2000-09-18 16:07:07 +00:00
ImplMakeSearchString( aSearchName );
pData = ImplFind( aSearchName, &nIndex );
if ( !pData )
{
if ( bInsertData )
{
ImplFontListFontInfo* pNewInfo = new ImplFontListFontInfo( aFontInfo, pDevice );
pData = new ImplFontListNameInfo( aSearchName );
pData->mpFirst = pNewInfo;
pNewInfo->mpNext = NULL;
pData->mnType = 0;
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 )
{
sal_Bool bInsert = sal_True;
2000-09-18 16:07:07 +00:00
ImplFontListFontInfo* pPrev = NULL;
ImplFontListFontInfo* pTemp = pData->mpFirst;
ImplFontListFontInfo* pNewInfo = new ImplFontListFontInfo( aFontInfo, pDevice );
while ( pTemp )
{
StringCompare eComp = ImplCompareFontInfo( pNewInfo, pTemp );
if ( (eComp == COMPARE_LESS) || (eComp == COMPARE_EQUAL) )
{
if ( eComp == COMPARE_EQUAL )
{
// Overwrite charset, because charset should match
// with the system charset
if ( (pTemp->GetCharSet() != eSystemEncoding) &&
(pNewInfo->GetCharSet() == eSystemEncoding) )
{
ImplFontListFontInfo* pTemp2 = pTemp->mpNext;
*((FontInfo*)pTemp) = *((FontInfo*)pNewInfo);
pTemp->mpNext = pTemp2;
}
delete pNewInfo;
bInsert = sal_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;
if ( aFontInfo.GetType() != TYPE_RASTER )
pData->mnType |= FONTLIST_FONTNAMETYPE_SCALABLE;
}
}
}
// =======================================================================
2011-05-02 12:29:34 -04:30
FontList::FontList( OutputDevice* pDevice, OutputDevice* pDevice2, sal_Bool bAll )
2000-09-18 16:07:07 +00:00
{
// Variablen initialisieren
mpDev = pDevice;
mpDev2 = pDevice2;
mpSizeAry = NULL;
// Stylenamen festlegen
maLight = XubString( SvtResId( STR_SVT_STYLE_LIGHT ) );
maLightItalic = XubString( SvtResId( STR_SVT_STYLE_LIGHT_ITALIC ) );
maNormal = XubString( SvtResId( STR_SVT_STYLE_NORMAL ) );
maNormalItalic = XubString( SvtResId( STR_SVT_STYLE_NORMAL_ITALIC ) );
maBold = XubString( SvtResId( STR_SVT_STYLE_BOLD ) );
maBoldItalic = XubString( SvtResId( STR_SVT_STYLE_BOLD_ITALIC ) );
maBlack = XubString( SvtResId( STR_SVT_STYLE_BLACK ) );
maBlackItalic = XubString( SvtResId( STR_SVT_STYLE_BLACK_ITALIC ) );
ImplInsertFonts( pDevice, bAll, sal_True );
2000-09-18 16:07:07 +00:00
// Gegebenenfalls muessen wir mit den Bildschirmfonts vergleichen,
// damit dort die eigentlich doppelten auf Equal mappen koennen
sal_Bool bCompareWindow = sal_False;
2000-09-18 16:07:07 +00:00
if ( !pDevice2 && (pDevice->GetOutDevType() == OUTDEV_PRINTER) )
{
bCompareWindow = sal_True;
2000-09-18 16:07:07 +00:00
pDevice2 = Application::GetDefaultDevice();
}
if ( pDevice2 &&
(pDevice2->GetOutDevType() != pDevice->GetOutDevType()) )
ImplInsertFonts( pDevice2, bAll, !bCompareWindow );
}
// -----------------------------------------------------------------------
FontList::~FontList()
{
// Gegebenenfalls SizeArray loeschen
if ( mpSizeAry )
delete[] mpSizeAry;
2000-09-18 16:07:07 +00:00
// FontInfos loeschen
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 XubString& 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;
}
}
// -----------------------------------------------------------------------
2000-09-18 16:07:07 +00:00
XubString FontList::GetStyleName( const FontInfo& rInfo ) const
{
XubString aStyleName = rInfo.GetStyleName();
FontWeight eWeight = rInfo.GetWeight();
FontItalic eItalic = rInfo.GetItalic();
2000-09-18 16:07:07 +00:00
// Nur wenn kein StyleName gesetzt ist, geben wir einen syntetischen
// Namen zurueck
if ( !aStyleName.Len() )
aStyleName = GetStyleName( eWeight, eItalic );
else
2000-09-18 16:07:07 +00:00
{
// Translate StyleName to localized name
XubString aCompareStyleName = aStyleName;
aCompareStyleName.ToLowerAscii();
aCompareStyleName.EraseAllChars( ' ' );
if ( aCompareStyleName.EqualsAscii( "bold" ) )
aStyleName = maBold;
else if ( aCompareStyleName.EqualsAscii( "bolditalic" ) )
aStyleName = maBoldItalic;
else if ( aCompareStyleName.EqualsAscii( "italic" ) )
aStyleName = maNormalItalic;
else if ( aCompareStyleName.EqualsAscii( "standard" ) )
aStyleName = maNormal;
else if ( aCompareStyleName.EqualsAscii( "regular" ) )
aStyleName = maNormal;
else if ( aCompareStyleName.EqualsAscii( "medium" ) )
aStyleName = maNormal;
else if ( aCompareStyleName.EqualsAscii( "light" ) )
aStyleName = maLight;
else if ( aCompareStyleName.EqualsAscii( "lightitalic" ) )
aStyleName = maLightItalic;
else if ( aCompareStyleName.EqualsAscii( "black" ) )
aStyleName = maBlack;
else if ( aCompareStyleName.EqualsAscii( "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;
}
// -----------------------------------------------------------------------
XubString FontList::GetFontMapText( const FontInfo& rInfo ) const
{
if ( !rInfo.GetName().Len() )
{
XubString aEmptryStr;
return aEmptryStr;
}
// Search Fontname
2000-09-18 16:07:07 +00:00
ImplFontListNameInfo* pData = ImplFindByName( rInfo.GetName() );
if ( !pData )
{
if ( !maMapNotAvailable.Len() )
((FontList*)this)->maMapNotAvailable = XubString( SvtResId( STR_SVT_FONTMAP_NOTAVAILABLE ) );
return maMapNotAvailable;
}
// search for synthetic style
sal_uInt16 nType = pData->mnType;
const XubString& rStyleName = rInfo.GetStyleName();
if ( rStyleName.Len() )
2000-09-18 16:07:07 +00:00
{
sal_Bool bNotSynthetic = sal_False;
sal_Bool bNoneAvailable = sal_False;
2000-09-18 16:07:07 +00:00
FontWeight eWeight = rInfo.GetWeight();
FontItalic eItalic = rInfo.GetItalic();
ImplFontListFontInfo* pFontInfo = pData->mpFirst;
while ( pFontInfo )
2000-09-18 16:07:07 +00:00
{
if ( (eWeight == pFontInfo->GetWeight()) &&
(eItalic == pFontInfo->GetItalic()) )
2000-09-18 16:07:07 +00:00
{
bNotSynthetic = sal_True;
break;
2000-09-18 16:07:07 +00:00
}
pFontInfo = pFontInfo->mpNext;
2000-09-18 16:07:07 +00:00
}
if ( bNoneAvailable )
{
XubString aEmptryStr;
return aEmptryStr;
}
else if ( !bNotSynthetic )
{
if ( !maMapStyleNotAvailable.Len() )
((FontList*)this)->maMapStyleNotAvailable = XubString( SvtResId( STR_SVT_FONTMAP_STYLENOTAVAILABLE ) );
return maMapStyleNotAvailable;
}
}
2000-09-18 16:07:07 +00:00
/* Size not available not implemented yet
if ( !(nType & FONTLIST_FONTNAMETYPE_SCALABLE) )
{
...
{
if ( !maMapSizeNotAvailable.Len() )
((FontList*)this)->maMapSizeNotAvailable = XubString( SvtResId( STR_SVT_FONTMAP_SIZENOTAVAILABLE ) );
return maMapSizeNotAvailable;
2000-09-18 16:07:07 +00:00
}
}
*/
// Only Printer-Font?
if ( (nType & (FONTLIST_FONTNAMETYPE_PRINTER | FONTLIST_FONTNAMETYPE_SCREEN)) == FONTLIST_FONTNAMETYPE_PRINTER )
{
if ( !maMapPrinterOnly.Len() )
((FontList*)this)->maMapPrinterOnly = XubString( SvtResId( STR_SVT_FONTMAP_PRINTERONLY ) );
return maMapPrinterOnly;
}
// Only Screen-Font?
else if ( (nType & (FONTLIST_FONTNAMETYPE_PRINTER | FONTLIST_FONTNAMETYPE_SCREEN)) == FONTLIST_FONTNAMETYPE_SCREEN
&& rInfo.GetType() == TYPE_RASTER )
{
if ( !maMapScreenOnly.Len() )
((FontList*)this)->maMapScreenOnly = XubString( SvtResId( STR_SVT_FONTMAP_SCREENONLY ) );
return maMapScreenOnly;
}
else
{
if ( !maMapBoth.Len() )
((FontList*)this)->maMapBoth = XubString( SvtResId( STR_SVT_FONTMAP_BOTH ) );
return maMapBoth;
}
2000-09-18 16:07:07 +00:00
}
// -----------------------------------------------------------------------
FontInfo FontList::Get( const XubString& rName, const XubString& rStyleName ) const
{
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.EqualsIgnoreCaseAscii( GetStyleName( *pSearchInfo ) ) )
2000-09-18 16:07:07 +00:00
{
pFontInfo = pSearchInfo;
break;
}
pSearchInfo = pSearchInfo->mpNext;
}
}
// Konnten die Daten nicht gefunden werden, dann muessen bestimmte
// Attribute nachgebildet werden
FontInfo aInfo;
2000-09-18 16:07:07 +00:00
if ( !pFontInfo )
{
if ( pFontNameInfo )
aInfo = *pFontNameInfo;
if ( rStyleName == maNormal )
{
aInfo.SetItalic( ITALIC_NONE );
aInfo.SetWeight( WEIGHT_NORMAL );
}
else if ( rStyleName == maNormalItalic )
{
aInfo.SetItalic( ITALIC_NORMAL );
aInfo.SetWeight( WEIGHT_NORMAL );
}
else if ( rStyleName == maBold )
{
aInfo.SetItalic( ITALIC_NONE );
aInfo.SetWeight( WEIGHT_BOLD );
}
else if ( rStyleName == maBoldItalic )
{
aInfo.SetItalic( ITALIC_NORMAL );
aInfo.SetWeight( WEIGHT_BOLD );
}
else if ( rStyleName == maLight )
{
aInfo.SetItalic( ITALIC_NONE );
aInfo.SetWeight( WEIGHT_LIGHT );
}
else if ( rStyleName == maLightItalic )
{
aInfo.SetItalic( ITALIC_NORMAL );
aInfo.SetWeight( WEIGHT_LIGHT );
}
else if ( rStyleName == maBlack )
{
aInfo.SetItalic( ITALIC_NONE );
aInfo.SetWeight( WEIGHT_BLACK );
}
else if ( rStyleName == maBlackItalic )
{
aInfo.SetItalic( ITALIC_NORMAL );
aInfo.SetWeight( WEIGHT_BLACK );
}
else
{
aInfo.SetItalic( ITALIC_NONE );
aInfo.SetWeight( WEIGHT_DONTKNOW );
}
}
else
aInfo = *pFontInfo;
// set Fontname to keep FontAlias
aInfo.SetName( rName );
aInfo.SetStyleName( rStyleName );
return aInfo;
2000-09-18 16:07:07 +00:00
}
// -----------------------------------------------------------------------
FontInfo FontList::Get( const XubString& rName,
FontWeight eWeight, FontItalic eItalic ) const
{
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;
}
}
// Konnten die Daten nicht gefunden werden, dann muessen bestimmte
// Attribute nachgebildet werden
FontInfo aInfo;
2000-09-18 16:07:07 +00:00
if ( !pFontInfo )
{
// Falls der Fontname stimmt, uebernehmen wir soviel wie moeglich
if ( pFontNameInfo )
{
aInfo = *pFontNameInfo;
aInfo.SetStyleName( XubString() );
}
aInfo.SetWeight( eWeight );
aInfo.SetItalic( eItalic );
}
else
aInfo = *pFontInfo;
// set Fontname to keep FontAlias
aInfo.SetName( rName );
return aInfo;
2000-09-18 16:07:07 +00:00
}
// -----------------------------------------------------------------------
sal_Bool FontList::IsAvailable( const XubString& rName ) const
2000-09-18 16:07:07 +00:00
{
return (ImplFindByName( rName ) != 0);
}
// -----------------------------------------------------------------------
const 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_uInt16 FontList::GetFontNameType( sal_uInt16 nFont ) const
2000-09-18 16:07:07 +00:00
{
DBG_ASSERT( nFont < GetFontNameCount(), "FontList::GetFontNameType(): nFont >= Count" );
2011-05-02 12:29:34 -04:30
return maEntries[nFont].mnType;
2000-09-18 16:07:07 +00:00
}
// -----------------------------------------------------------------------
sal_Handle FontList::GetFirstFontInfo( const XubString& rName ) const
{
ImplFontListNameInfo* pData = ImplFindByName( rName );
if ( !pData )
return (sal_Handle)NULL;
else
return (sal_Handle)pData->mpFirst;
}
// -----------------------------------------------------------------------
sal_Handle FontList::GetNextFontInfo( sal_Handle hFontInfo ) const
{
ImplFontListFontInfo* pInfo = (ImplFontListFontInfo*)(void*)hFontInfo;
return (sal_Handle)(pInfo->mpNext);
}
// -----------------------------------------------------------------------
const FontInfo& FontList::GetFontInfo( sal_Handle hFontInfo ) const
{
ImplFontListFontInfo* pInfo = (ImplFontListFontInfo*)(void*)hFontInfo;
return *pInfo;
}
// -----------------------------------------------------------------------
const long* FontList::GetSizeAry( const FontInfo& rInfo ) const
{
// Size-Array vorher loeschen
if ( mpSizeAry )
{
delete[] ((FontList*)this)->mpSizeAry;
2000-09-18 16:07:07 +00:00
((FontList*)this)->mpSizeAry = NULL;
}
// Falls kein Name, dann Standardgroessen
if ( !rInfo.GetName().Len() )
return aStdSizeAry;
// Zuerst nach dem Fontnamen suchen um das Device dann von dem
// entsprechenden Font zu nehmen
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 ) );
pDevice->SetMapMode( aMap );
sal_uInt16 i;
sal_uInt16 nRealCount = 0;
2000-09-18 16:07:07 +00:00
long nOldHeight = 0;
((FontList*)this)->mpSizeAry = new long[nDevSizeCount+1];
for ( i = 0; i < nDevSizeCount; i++ )
{
Size aSize = pDevice->GetDevFontSize( rInfo, i );
if ( aSize.Height() != nOldHeight )
{
nOldHeight = aSize.Height();
((FontList*)this)->mpSizeAry[nRealCount] = nOldHeight;
nRealCount++;
}
}
((FontList*)this)->mpSizeAry[nRealCount] = 0;
pDevice->SetMapMode( aOldMapMode );
return mpSizeAry;
}
// -----------------------------------------------------------------------
const long* FontList::GetStdSizeAry()
{
return aStdSizeAry;
}
2000-12-07 15:07:37 +00:00
// =======================================================================
// ---------------------------------
// - FontSizeNames & FsizeNameItem -
// ---------------------------------
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 )
2001-08-28 09:25:06 +00:00
eLanguage = Application::GetSettings().GetUILanguage();
if ( eLanguage == LANGUAGE_SYSTEM )
eLanguage = MsLangId::getSystemUILanguage();
switch( eLanguage )
2000-12-07 15:07:37 +00:00
{
case LANGUAGE_CHINESE:
case LANGUAGE_CHINESE_SIMPLIFIED:
mpArray = aImplSimplifiedChinese;
mnElem = SAL_N_ELEMENTS(aImplSimplifiedChinese);
break;
#if 0 // #i89077# disabled by popular request
case LANGUAGE_CHINESE_HONGKONG:
case LANGUAGE_CHINESE_SINGAPORE:
case LANGUAGE_CHINESE_MACAU:
case LANGUAGE_CHINESE_TRADITIONAL:
mpArray = aImplTraditionalChinese;
mnElem = SAL_N_ELEMENTS(aImplTraditionalChinese);
break;
#endif
default:
mpArray = NULL;
mnElem = 0;
break;
2000-12-07 15:07:37 +00:00
};
}
//------------------------------------------------------------------------
2000-09-18 16:07:07 +00:00
2000-12-07 15:07:37 +00:00
long FontSizeNames::Name2Size( const String& rName ) const
{
if ( mnElem )
{
ByteString aName( rName, RTL_TEXTENCODING_UTF8 );
// linear search is sufficient for this rare case
for( long i = mnElem; --i >= 0; )
if ( aName == mpArray[i].mszUtf8Name )
return mpArray[i].mnSize;
}
2000-12-07 15:07:37 +00:00
return 0;
}
//------------------------------------------------------------------------
String FontSizeNames::Size2Name( long nValue ) const
2000-12-07 15:07:37 +00:00
{
String 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 = String( mpArray[mid].mszUtf8Name, RTL_TEXTENCODING_UTF8 );
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
}
//------------------------------------------------------------------------
String FontSizeNames::GetIndexName( sal_uLong nIndex ) const
2000-12-07 15:07:37 +00:00
{
String aStr;
if ( nIndex < mnElem )
aStr = String( 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: */