1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 #include "fontentry.hxx"
25 #include "helper.hxx"
26 #include "padialog.hrc"
27 #include "vcl/strhelper.hxx"
28
29 #include "vcl/msgbox.hxx"
30 #include "vcl/fontmanager.hxx"
31
32 #include "osl/thread.h"
33
34 #include "tools/config.hxx"
35
36 using namespace padmin;
37 using namespace osl;
38 using namespace rtl;
39 using namespace psp;
40
41 #if 0
42 static void CreateAfmFile( const INetURLObject& rFontFile )
43 {
44 rtl_TextEncoding aEncoding = gsl_getSystemTextEncoding();
45
46 INetURLObject aFontMap( rFontFile.GetPath(), INET_PROT_FILE, INetURLObject::ENCODE_ALL );
47 aFontMap.Append( String( RTL_CONSTASCII_USTRINGPARAM( "Fontmap" ) ) );
48 INetURLObject aAfmFile( rFontFile );
49 aAfmFile.setExtension( String::CreateFromAscii( "afm", 3 ) );
50
51
52 SvFileStream aMap( aFontMap.PathToFileName(), STREAM_WRITE | STREAM_TRUNC );
53 if( aMap.IsOpen() )
54 {
55 SvFileStream aRead( rFontFile.GetFull(), STREAM_READ );
56 ByteString aLine;
57 ByteString aFullName;
58 int nPos;
59 while( ! aRead.IsEof() &&
60 ( nPos = aLine.Search( "/FullName" ) ) == STRING_NOTFOUND )
61 aRead.ReadLine( aLine );
62 aRead.Close();
63 if( nPos != STRING_NOTFOUND )
64 {
65 aLine.Erase( 0, nPos );
66 aFullName = aLine.GetToken( 1, '(' ).GetToken( 0, ')' );
67
68 aLine = '/';
69 aLine += aFullName;
70 aLine += ' ';
71 aLine += '(';
72 aLine += ByteString( rFontFile.GetName(), aEncoding );
73 aLine += ')';
74 aLine += ';';
75
76 aMap.WriteLine( aLine );
77 }
78 aMap.Close();
79 pid_t nPID = fork();
80 if( ! nPID )
81 {
82 INetURLObject aTmp( rFontFile );
83 aTmp.CutName();
84 ByteString aEnv( "GS_LIB=" );
85 aEnv += ByteString( aTmp.PathToFileName(), aEncoding );
86 putenv( const_cast<char*>(aEnv.GetBuffer()) );
87
88 int nDescr = open( ByteString( aAfmFile.PathToFileName(), aEncoding ).GetBuffer(),
89 O_CREAT | O_TRUNC| O_WRONLY,
90 00755 );
91 #if OSL_DEBUG_LEVEL > 1
92 if( nDescr < 0 )
93 fprintf( stderr, "open( %s ) failed because of %d\n", ByteString( aAfmFile.GetFull(), aEncoding ).GetBuffer(), errno );
94 #endif
95 if( dup2( nDescr, STDOUT_FILENO ) > 0 )
96 {
97 execlp( "gs",
98 "-q",
99 "-dNODISPLAY",
100 "--", "printafm.ps",
101 aFullName.GetBuffer(),
102 NULL );
103 }
104 #if OSL_DEBUG_LEVEL > 1
105 else
106 fprintf( stderr, "dup2( %d, %d ) failed because of %d\n", nDescr, STDOUT_FILENO, errno );
107 #endif
108 _exit( 0 );
109 }
110 if( nPID > 0 )
111 waitpid( nPID, NULL, 0 );
112 MetricConverter::ConvertAFM( aAfmFile );
113 }
114
115 struct stat aStat;
116 ByteString aSysFile( aAfmFile.PathToFileName(), aEncoding );
117 if( stat( aSysFile.GetBuffer(), &aStat ) || ! aStat.st_size )
118 unlink( aSysFile.GetBuffer() );
119 #if OSL_DEBUG_LEVEL > 1
120 fprintf( stderr, " %s\n", ! access( aSysFile.GetBuffer(), F_OK ) ? "success" : "failed" );
121 #endif
122 unlink( ByteString( aFontMap.PathToFileName(), aEncoding ).GetBuffer() );
123 }
124
125 #endif
126
FontNameDlg(Window * pParent)127 FontNameDlg::FontNameDlg( Window *pParent ) :
128 ModalDialog( pParent, PaResId( RID_FONTNAMEDIALOG ) ),
129 m_aOKButton( this, PaResId( RID_FNTNM_BTN_OK ) ),
130 m_aRenameButton( this, PaResId( RID_FNTNM_BTN_RENAME ) ),
131 m_aRemoveButton( this, PaResId( RID_FNTNM_BTN_REMOVE ) ),
132 m_aImportButton( this, PaResId( RID_FNTNM_BTN_IMPORT ) ),
133 m_aFontBox( this, PaResId( RID_FNTNM_LB_FONTS ) ),
134 m_aFixedText( this, PaResId( RID_FNTNM_FIXED ) ),
135 m_aRenameString( PaResId( RID_FNTNM_STR_RENAME ) ),
136 m_aRenameTTCString( PaResId( RID_FNTNM_STR_TTCRENAME ) ),
137 m_aNoRenameString( PaResId( RID_FNTNM_STR_NOTRENAMABLE ) ),
138 m_rFontManager( PrintFontManager::get() )
139 {
140 FreeResource();
141
142 m_aFontBox.EnableMultiSelection( sal_True );
143
144 m_aOKButton.SetClickHdl( LINK( this, FontNameDlg, ClickBtnHdl ) );
145 m_aRenameButton.SetClickHdl( LINK( this, FontNameDlg, ClickBtnHdl ) );
146 m_aRemoveButton.SetClickHdl( LINK( this, FontNameDlg, ClickBtnHdl ) );
147 m_aImportButton.SetClickHdl( LINK( this, FontNameDlg, ClickBtnHdl ) );
148 m_aFontBox.setDelPressedLink( LINK( this, FontNameDlg, DelPressedHdl ) );
149 m_aFontBox.SetSelectHdl( LINK( this, FontNameDlg, SelectHdl ) );
150
151 init();
152 }
153
~FontNameDlg()154 FontNameDlg::~FontNameDlg()
155 {
156 }
157
fillFontEntry(FastPrintFontInfo & rInfo,const String & rFile,bool bAddRegular)158 String FontNameDlg::fillFontEntry( FastPrintFontInfo& rInfo, const String& rFile, bool bAddRegular )
159 {
160 static String aThinTxt( PaResId( RID_TXT_FONT_THIN ) );
161 static String aUltraLightTxt( PaResId( RID_TXT_FONT_ULTRALIGHT ) );
162 static String aLightTxt( PaResId( RID_TXT_FONT_LIGHT ) );
163 static String aSemiLightTxt( PaResId( RID_TXT_FONT_SEMILIGHT ) );
164 static String aSemiBoldTxt( PaResId( RID_TXT_FONT_SEMIBOLD ) );
165 static String aBoldTxt( PaResId( RID_TXT_FONT_BOLD ) );
166 static String aUltraBoldTxt( PaResId( RID_TXT_FONT_ULTRABOLD ) );
167
168 static String aItalicTxt( PaResId( RID_TXT_FONT_ITALIC ) );
169 static String aObliqueTxt( PaResId( RID_TXT_FONT_OBLIQUE ) );
170
171 static String aUltraCondensedTxt( PaResId( RID_TXT_FONT_ULTRACONDENSED ) );
172 static String aExtraCondensedTxt( PaResId( RID_TXT_FONT_EXTRACONDENSED ) );
173 static String aCondensedTxt( PaResId( RID_TXT_FONT_CONDENSED ) );
174 static String aSemiCondensedTxt( PaResId( RID_TXT_FONT_SEMICONDENSED ) );
175 static String aSemiExpandedTxt( PaResId( RID_TXT_FONT_SEMIEXPANDED ) );
176 static String aExpandedTxt( PaResId( RID_TXT_FONT_EXPANDED ) );
177 static String aExtraExpandedTxt( PaResId( RID_TXT_FONT_EXTRAEXPANDED ) );
178 static String aUltraExpandedTxt( PaResId( RID_TXT_FONT_ULTRAEXPANDED ) );
179
180 static String aRegularTxt( PaResId( RID_TXT_FONT_REGULAR ) );
181
182 String aEntry( rInfo.m_aFamilyName );
183 bool bWeight = true, bItalic = true, bWidth = true;
184 switch( rInfo.m_eWeight )
185 {
186 case weight::Thin: aEntry.AppendAscii( ", " ); aEntry.Append( aThinTxt ); break;
187 case weight::UltraLight: aEntry.AppendAscii( ", " ); aEntry.Append( aUltraLightTxt ); break;
188 case weight::Light: aEntry.AppendAscii( ", " ); aEntry.Append( aLightTxt ); break;
189 case weight::SemiLight: aEntry.AppendAscii( ", " ); aEntry.Append( aSemiLightTxt ); break;
190 case weight::SemiBold: aEntry.AppendAscii( ", " ); aEntry.Append( aSemiBoldTxt ); break;
191 case weight::Bold: aEntry.AppendAscii( ", " ); aEntry.Append( aBoldTxt ); break;
192 case weight::UltraBold: aEntry.AppendAscii( ", " ); aEntry.Append( aUltraBoldTxt ); break;
193 default:
194 bWeight = false;
195 break;
196 }
197 switch( rInfo.m_eItalic )
198 {
199 case italic::Oblique: aEntry.AppendAscii( ", " ); aEntry.Append( aObliqueTxt ); break;
200 case italic::Italic: aEntry.AppendAscii( ", " ); aEntry.Append( aItalicTxt ); break;
201 default:
202 bItalic = false;
203 break;
204 }
205 switch( rInfo.m_eWidth )
206 {
207 case width::UltraCondensed: aEntry.AppendAscii( ", " ); aEntry.Append( aUltraCondensedTxt ); break;
208 case width::ExtraCondensed: aEntry.AppendAscii( ", " ); aEntry.Append( aExtraCondensedTxt ); break;
209 case width::Condensed: aEntry.AppendAscii( ", " ); aEntry.Append( aCondensedTxt ); break;
210 case width::SemiCondensed: aEntry.AppendAscii( ", " ); aEntry.Append( aSemiCondensedTxt ); break;
211 case width::SemiExpanded: aEntry.AppendAscii( ", " ); aEntry.Append( aSemiExpandedTxt ); break;
212 case width::Expanded: aEntry.AppendAscii( ", " ); aEntry.Append( aExpandedTxt ); break;
213 case width::ExtraExpanded: aEntry.AppendAscii( ", " ); aEntry.Append( aExtraExpandedTxt ); break;
214 case width::UltraExpanded: aEntry.AppendAscii( ", " ); aEntry.Append( aUltraExpandedTxt ); break;
215 default:
216 bWidth = false;
217 break;
218 }
219
220 if( bAddRegular && ! bItalic && ! bWidth && ! bWeight )
221 {
222 aEntry.AppendAscii( ", " );
223 aEntry.Append( aRegularTxt );
224 }
225
226 aEntry.AppendAscii( " (" );
227 aEntry.Append( rFile );
228 aEntry.AppendAscii( ")" );
229 return aEntry;
230 }
231
fillFontEntry(const::std::list<FastPrintFontInfo> & rInfos,const String & rFile)232 String FontNameDlg::fillFontEntry( const ::std::list< FastPrintFontInfo >& rInfos, const String& rFile )
233 {
234 String aEntry;
235 bool bFirst = true;
236 for( ::std::list< FastPrintFontInfo >::const_iterator it = rInfos.begin(); it != rInfos.end(); ++it )
237 {
238 if( ! bFirst )
239 aEntry.AppendAscii( " & " );
240 aEntry.Append( String( it->m_aFamilyName ) );
241 bFirst = false;
242 }
243
244 aEntry.AppendAscii( " (" );
245 aEntry.Append( rFile );
246 aEntry.AppendAscii( ")" );
247 return aEntry;
248 }
249
init()250 void FontNameDlg::init()
251 {
252 ::std::list< fontID > aFonts;
253 m_rFontManager.getFontList( aFonts );
254 m_aFontBox.Clear();
255 m_aRemoveButton.Enable( sal_False );
256 m_aRenameButton.Enable( sal_False );
257
258 ::std::hash_map< OUString, int, OUStringHash > aFamilies;
259 ::std::list< fontID >::iterator font_it;
260 for( font_it = aFonts.begin(); font_it != aFonts.end(); ++font_it )
261 {
262 if( m_rFontManager.isPrivateFontFile( *font_it ) )
263 {
264 const OUString& rFamily( m_rFontManager.getFontFamily( *font_it ) );
265 if( aFamilies.find( rFamily ) == aFamilies.end() )
266 aFamilies[rFamily] = 0;
267 aFamilies[rFamily]++;
268 }
269 }
270
271 for( font_it = aFonts.begin(); font_it != aFonts.end(); ++font_it )
272 {
273 if( m_rFontManager.isPrivateFontFile( *font_it ) )
274 {
275 OString aFile( m_rFontManager.getFontFileSysPath( *font_it ) );
276 int nLast = aFile.lastIndexOf( '/' );
277 if( nLast != -1 )
278 aFile = aFile.copy( nLast+1 );
279
280 FastPrintFontInfo aInfo;
281 m_rFontManager.getFontFastInfo( *font_it, aInfo );
282 std::list< fontID > aDups;
283 String aEntry;
284 if( m_rFontManager.getFileDuplicates( *font_it, aDups ) )
285 {
286 FastPrintFontInfo aDupInfo;
287 std::list< FastPrintFontInfo > aInfos;
288 aInfos.push_back( aInfo );
289 for( std::list< fontID >::iterator dup = aDups.begin(); dup != aDups.end(); ++dup )
290 {
291 m_rFontManager.getFontFastInfo( *dup, aDupInfo );
292 aInfos.push_back( aDupInfo );
293 aFonts.remove( *dup );
294 }
295 aEntry = fillFontEntry( aInfos, String( ByteString( aFile ), osl_getThreadTextEncoding() ) );
296 }
297 else
298 aEntry = fillFontEntry( aInfo, String( ByteString( aFile ), osl_getThreadTextEncoding() ), aFamilies[ aInfo.m_aFamilyName ] > 1 );
299 sal_uInt16 nEntry = m_aFontBox.InsertEntry( aEntry );
300 m_aFontBox.SetEntryData( nEntry, (void*)(*font_it) );
301 }
302 }
303 }
304
IMPL_LINK(FontNameDlg,SelectHdl,ListBox *,pBox)305 IMPL_LINK( FontNameDlg, SelectHdl, ListBox*, pBox )
306 {
307 if( pBox == &m_aFontBox )
308 {
309 sal_Bool bEnable = m_aFontBox.GetSelectEntryCount() ? sal_True : sal_False;
310 m_aRemoveButton.Enable( bEnable );
311 m_aRenameButton.Enable( bEnable );
312 }
313 return 0;
314 }
315
IMPL_LINK(FontNameDlg,DelPressedHdl,ListBox *,pBox)316 IMPL_LINK( FontNameDlg, DelPressedHdl, ListBox*, pBox )
317 {
318 if( pBox == &m_aFontBox && m_aRemoveButton.IsEnabled() )
319 {
320 ClickBtnHdl( &m_aRemoveButton );
321 }
322 return 0;
323 }
324
IMPL_LINK(FontNameDlg,ClickBtnHdl,Button *,pButton)325 IMPL_LINK( FontNameDlg, ClickBtnHdl, Button*, pButton )
326 {
327
328 int i;
329
330 if( pButton == &m_aOKButton )
331 {
332 EndDialog();
333 }
334 else if( pButton == &m_aRemoveButton && AreYouSure( this, RID_QUERY_REMOVEFONTFROMLIST ) && m_aFontBox.GetSelectEntryCount() )
335 {
336 ::std::list< fontID > aRemoveIDs;
337 for( i = 0; i < m_aFontBox.GetSelectEntryCount(); i++ )
338 {
339 int nSelect = m_aFontBox.GetSelectEntryPos( i );
340 aRemoveIDs.push_back( (fontID)(sal_IntPtr)m_aFontBox.GetEntryData( nSelect ) );
341 }
342 m_rFontManager.removeFonts( aRemoveIDs );
343 init();
344 }
345 else if( pButton == &m_aImportButton )
346 {
347 FontImportDialog aDialog( this );
348 aDialog.Execute();
349 init();
350 }
351 else if( pButton == &m_aRenameButton && m_aFontBox.GetSelectEntryCount() )
352 {
353 for( i = 0; i < m_aFontBox.GetSelectEntryCount(); i++ )
354 {
355 fontID aFont = (fontID)(sal_IntPtr)m_aFontBox.GetEntryData( m_aFontBox.GetSelectEntryPos( i ) );
356 if( ! m_rFontManager.checkChangeFontPropertiesPossible( aFont ) )
357 {
358 String aErrorText( m_aNoRenameString );
359 aErrorText.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "%s" ) ), m_aFontBox.GetSelectEntry( i ) );
360 ErrorBox aBox( this, WB_OK | WB_DEF_OK, aErrorText );
361 aBox.Execute();
362 continue;
363 }
364 ::std::list< fontID > aDuplicates;
365 m_rFontManager.getFileDuplicates( aFont, aDuplicates );
366 aDuplicates.push_front( aFont );
367 int nFonts = aDuplicates.size();
368 for( int n = 0; n < nFonts; n++ )
369 {
370 aFont = aDuplicates.front();
371 aDuplicates.pop_front();
372 String aFamily( m_rFontManager.getFontFamily( aFont ) );
373 ::std::list< OUString > aAlternatives;
374 m_rFontManager.getAlternativeFamilyNames( aFont, aAlternatives );
375 ::std::list< String > aChoices;
376 while( aAlternatives.size() )
377 {
378 aChoices.push_back( aAlternatives.front() );
379 aAlternatives.pop_front();
380 }
381 String aQueryTxt( m_aRenameString );
382 if( nFonts > 1 )
383 {
384 aQueryTxt = m_aRenameTTCString;
385 aQueryTxt.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "%d1" ) ), String::CreateFromInt32( n+1 ) );
386 aQueryTxt.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "%d2" ) ), String::CreateFromInt32( nFonts ) );
387 }
388 aQueryTxt.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "%s" ) ), aFamily );
389 QueryString aQuery( this, aQueryTxt, aFamily, aChoices );
390 if( aQuery.Execute() )
391 {
392 aFamily.SearchAndReplaceAll( '-', ' ' );
393 aFamily.SearchAndReplaceAll( '?', ' ' );
394 aFamily.SearchAndReplaceAll( '*', ' ' );
395 aFamily = WhitespaceToSpace( aFamily );
396 if( aFamily.Len() )
397 {
398 String aXLFD = m_rFontManager.getFontXLFD( aFont );
399 aXLFD.SetToken( 2, '-', aFamily );
400 m_rFontManager.changeFontProperties( aFont, aXLFD );
401 }
402 }
403 }
404 }
405 init();
406 }
407 return 0;
408 }
409
410 //--------------------------------------------------
411
FontImportDialog(Window * pParent)412 FontImportDialog::FontImportDialog( Window* pParent ) :
413 ModalDialog( pParent, PaResId( RID_FONTIMPORT_DIALOG ) ),
414 m_aOKBtn( this, PaResId( RID_FIMP_BTN_OK ) ),
415 m_aCancelBtn( this, PaResId( RID_FIMP_BTN_CANCEL ) ),
416 m_aSelectAllBtn( this, PaResId( RID_FIMP_BTN_SELECTALL ) ),
417 m_aNewFontsBox( this, PaResId( RID_FIMP_BOX_NEWFONTS ) ),
418 m_aFromFL( this, PaResId( RID_FIMP_FL_FROM ) ),
419 m_aFromDirEdt( this, PaResId( RID_FIMP_EDT_FROM ) ),
420 m_aFromBtn( this, PaResId( RID_FIMP_BTN_FROM ) ),
421 m_aSubDirsBox( this, PaResId( RID_FIMP_BOX_SUBDIRS ) ),
422 m_aTargetOptFL( this, PaResId( RID_FIMP_FL_TARGETOPTS ) ),
423 m_aLinkOnlyBox( this, PaResId( RID_FIMP_BOX_LINKONLY ) ),
424 m_aFixedText( this, PaResId( RID_FIMP_TXT_HELP ) ),
425 m_bOverwriteAll( false ),
426 m_bOverwriteNone( false ),
427 m_pProgress( NULL ),
428 m_aImportOperation( PaResId( RID_FIMP_STR_IMPORTOP ) ),
429 m_aOverwriteQueryText( PaResId( RID_FIMP_STR_QUERYOVERWRITE ) ),
430 m_aOverwriteAllText( PaResId( RID_FIMP_STR_OVERWRITEALL ) ),
431 m_aOverwriteNoneText( PaResId( RID_FIMP_STR_OVERWRITENONE ) ),
432 m_aNoAfmText( PaResId( RID_FIMP_STR_NOAFM ) ),
433 m_aAfmCopyFailedText( PaResId( RID_FIMP_STR_AFMCOPYFAILED ) ),
434 m_aFontCopyFailedText( PaResId( RID_FIMP_STR_FONTCOPYFAILED ) ),
435 m_aNoWritableFontsDirText( PaResId( RID_FIMP_STR_NOWRITEABLEFONTSDIR ) ),
436 m_aFontsImportedText( PaResId( RID_FIMP_STR_NUMBEROFFONTSIMPORTED ) ),
437 m_rFontManager( ::psp::PrintFontManager::get() )
438 {
439 FreeResource();
440
441 m_aNewFontsBox.EnableMultiSelection( sal_True );
442
443 m_aOKBtn.SetClickHdl( LINK( this, FontImportDialog, ClickBtnHdl ) );
444 m_aSelectAllBtn.SetClickHdl( LINK( this, FontImportDialog, ClickBtnHdl ) );
445 m_aFromBtn.SetClickHdl( LINK( this, FontImportDialog, ClickBtnHdl ) );
446 m_aFromDirEdt.SetModifyHdl( LINK( this, FontImportDialog, ModifyHdl ) );
447 m_aRefreshTimer.SetTimeoutHdl( LINK( this, FontImportDialog, RefreshTimeoutHdl ) );
448 m_aRefreshTimer.SetTimeout( 2000 );
449 m_aLinkOnlyBox.Check( sal_False );
450 m_aSubDirsBox.Check( sal_True );
451 m_aSubDirsBox.SetToggleHdl( LINK( this, FontImportDialog, ToggleHdl ) );
452
453 Config& rPadminRC( getPadminRC() );
454 rPadminRC.SetGroup( "FontImport" );
455 m_aFromDirEdt.SetText( String( rPadminRC.ReadKey( "FromPath" ), RTL_TEXTENCODING_UTF8 ) );
456 RefreshTimeoutHdl( NULL );
457 }
458
~FontImportDialog()459 FontImportDialog::~FontImportDialog()
460 {
461 Config& rPadminRC( getPadminRC() );
462 rPadminRC.SetGroup( "FontImport" );
463 rPadminRC.WriteKey( "FromPath", ByteString( m_aFromDirEdt.GetText(), RTL_TEXTENCODING_UTF8 ) );
464 }
465
importFontsFailed(::psp::PrintFontManager::ImportFontCallback::FailCondition eReason)466 void FontImportDialog::importFontsFailed( ::psp::PrintFontManager::ImportFontCallback::FailCondition eReason )
467 {
468 String aText;
469 switch( eReason )
470 {
471 case psp::PrintFontManager::ImportFontCallback::NoWritableDirectory:
472 aText = m_aNoWritableFontsDirText;
473 break;
474 default:
475 break;
476 }
477 ErrorBox aBox( m_pProgress ? (Window*)m_pProgress : (Window*)this, WB_OK | WB_DEF_OK, aText );
478 aBox.Execute();
479 }
480
progress(const::rtl::OUString & rFile)481 void FontImportDialog::progress( const ::rtl::OUString& rFile )
482 {
483 m_pProgress->setValue( ++m_nFont );
484 m_pProgress->setFilename( rFile );
485 }
486
queryOverwriteFile(const::rtl::OUString & rFile)487 bool FontImportDialog::queryOverwriteFile( const ::rtl::OUString& rFile )
488 {
489 bool bRet = false;
490
491 if( m_bOverwriteNone )
492 return false;
493 if( m_bOverwriteAll )
494 return true;
495
496 String aText( m_aOverwriteQueryText );
497 aText.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "%s" ) ), rFile );
498
499 QueryBox aQueryBox( m_pProgress ? (Window*)m_pProgress : (Window*)this, WB_YES_NO | WB_DEF_NO, aText );
500 aQueryBox.AddButton( m_aOverwriteAllText, 20, 0 );
501 aQueryBox.AddButton( m_aOverwriteNoneText, 21, 0 );
502
503 int nResult = aQueryBox.Execute();
504 switch( nResult )
505 {
506 case BUTTONID_YES: bRet = true; break;
507 case BUTTONID_NO: bRet = false; break;
508 case 20: bRet = m_bOverwriteAll = true; break;
509 case 21: bRet = false; m_bOverwriteNone = true; break;
510 }
511
512 return bRet;
513 }
514
importFontFailed(const::rtl::OUString & rFile,::psp::PrintFontManager::ImportFontCallback::FailCondition eReason)515 void FontImportDialog::importFontFailed( const ::rtl::OUString& rFile, ::psp::PrintFontManager::ImportFontCallback::FailCondition eReason )
516 {
517 String aText;
518 switch( eReason )
519 {
520 case psp::PrintFontManager::ImportFontCallback::NoAfmMetric:
521 aText = m_aNoAfmText;
522 break;
523 case psp::PrintFontManager::ImportFontCallback::AfmCopyFailed:
524 aText = m_aAfmCopyFailedText;
525 break;
526 case psp::PrintFontManager::ImportFontCallback::FontCopyFailed:
527 aText = m_aFontCopyFailedText;
528 break;
529 default:
530 break;
531 }
532 aText.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "%s" ) ), rFile );
533 ErrorBox aBox( m_pProgress ? (Window*)m_pProgress : (Window*)this, WB_OK | WB_DEF_OK, aText );
534 aBox.Execute();
535 }
536
isCanceled()537 bool FontImportDialog::isCanceled()
538 {
539 return m_pProgress->isCanceled();
540 }
541
IMPL_LINK(FontImportDialog,ModifyHdl,Edit *,EMPTYARG)542 IMPL_LINK( FontImportDialog, ModifyHdl, Edit*, EMPTYARG )
543 {
544 m_aRefreshTimer.Start();
545 return 0;
546 }
547
IMPL_LINK(FontImportDialog,RefreshTimeoutHdl,void *,EMPTYARG)548 IMPL_LINK( FontImportDialog, RefreshTimeoutHdl, void*, EMPTYARG )
549 {
550 rtl_TextEncoding aEncoding = osl_getThreadTextEncoding();
551 std::list< String > aFiles;
552 m_aNewFonts.clear();
553 OUString aDirectory( m_aFromDirEdt.GetText() );
554 FindFiles( aDirectory, aFiles, String( RTL_CONSTASCII_USTRINGPARAM( "PFA;PFB;TTF;TTC;OTF" ) ), m_aSubDirsBox.IsChecked() );
555 OString aDir( OUStringToOString( aDirectory, aEncoding ) );
556 aDir += "/";
557 while( aFiles.begin() != aFiles.end() )
558 {
559 OString aFont( aDir );
560 aFont += OUStringToOString( aFiles.front(), aEncoding );
561 aFiles.pop_front();
562 ::std::list< FastPrintFontInfo > aInfos;
563 if( m_rFontManager.getImportableFontProperties( aFont, aInfos ) )
564 m_aNewFonts[ aFont ] = aInfos;
565 }
566 fillFontBox();
567 return 0;
568 }
569
fillFontBox()570 void FontImportDialog::fillFontBox()
571 {
572 rtl_TextEncoding aEncoding = osl_getThreadTextEncoding();
573 m_aNewFontsBox.Clear();
574
575 ::std::hash_map< OUString, int, OUStringHash > aFamilies;
576 ::std::hash_map< OString, ::std::list< FastPrintFontInfo >, OStringHash >::iterator it;
577 for( it = m_aNewFonts.begin(); it != m_aNewFonts.end(); ++it )
578 {
579 const OUString& rFamily( it->second.front().m_aFamilyName );
580 if( aFamilies.find( rFamily ) == aFamilies.end() )
581 aFamilies[rFamily] = 0;
582 aFamilies[rFamily]++;
583 }
584
585 for( it = m_aNewFonts.begin(); it != m_aNewFonts.end(); ++it )
586 {
587 OString aFileName( it->first.copy( it->first.lastIndexOf( '/' )+1 ) );
588 OUString aFile( OStringToOUString( aFileName, aEncoding ) );
589 String aEntry;
590 if( it->second.size() == 1 )
591 aEntry = FontNameDlg::fillFontEntry( it->second.front(), aFile, aFamilies[ it->second.front().m_aFamilyName ] > 1 );
592 else
593 aEntry = FontNameDlg::fillFontEntry( it->second, aFile );
594 sal_uInt16 nPos = m_aNewFontsBox.InsertEntry( aEntry );
595 m_aNewFontsBox.SetEntryData( nPos, (void*)&(it->first) );
596 }
597 }
598
copyFonts()599 void FontImportDialog::copyFonts()
600 {
601 ::std::list< OString > aFiles;
602 for( int i = 0; i < m_aNewFontsBox.GetSelectEntryCount(); i++ )
603 {
604 OString* pFile = (OString*)m_aNewFontsBox.GetEntryData( m_aNewFontsBox.GetSelectEntryPos( i ) );
605 aFiles.push_back( *pFile );
606 }
607
608 int nSuccess = 0;
609 if( aFiles.size() )
610 {
611 m_nFont = 0;
612 m_pProgress = new ProgressDialog( this );
613 m_pProgress->setRange( 0, aFiles.size() );
614 m_pProgress->startOperation( m_aImportOperation );
615 m_pProgress->Show( sal_True );
616 m_pProgress->setValue( 0 );
617 m_pProgress->Invalidate();
618 m_pProgress->Sync();
619 nSuccess = m_rFontManager.importFonts( aFiles, m_aLinkOnlyBox.IsChecked() ? true : false, this );
620 m_pProgress->Show( sal_False );
621 delete m_pProgress;
622 m_pProgress = NULL;
623 }
624 String aText( m_aFontsImportedText );
625 aText.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "%d" ) ), String::CreateFromInt32( nSuccess ) );
626 InfoBox aBox( this, aText );
627 aBox.Execute();
628 }
629
IMPL_LINK(FontImportDialog,ClickBtnHdl,Button *,pButton)630 IMPL_LINK( FontImportDialog, ClickBtnHdl, Button*, pButton )
631 {
632 if( pButton == &m_aFromBtn )
633 {
634 String aPath( m_aFromDirEdt.GetText() );
635 if( chooseDirectory( aPath ) )
636 {
637 m_aFromDirEdt.SetText( aPath );
638 RefreshTimeoutHdl( NULL );
639 }
640 }
641 else if( pButton == &m_aOKBtn )
642 {
643 copyFonts();
644 EndDialog( 0 );
645 }
646 else if( pButton == &m_aSelectAllBtn )
647 {
648 m_aNewFontsBox.SetUpdateMode( sal_False );
649 for( int i = 0; i < m_aNewFontsBox.GetEntryCount(); i++ )
650 m_aNewFontsBox.SelectEntryPos( i, sal_True );
651 m_aNewFontsBox.SetUpdateMode( sal_True );
652 }
653 return 0;
654 }
655
IMPL_LINK(FontImportDialog,ToggleHdl,CheckBox *,pBox)656 IMPL_LINK( FontImportDialog, ToggleHdl, CheckBox*, pBox )
657 {
658 if( pBox == &m_aSubDirsBox )
659 {
660 RefreshTimeoutHdl( NULL );
661 }
662
663 return 0;
664 }
665