/**
 * This program and the accompanying materials
 * are made available under the terms of the License
 * which accompanies this distribution in the file LICENSE.txt
 */
package com.archimatetool.editor;

import java.io.File;

import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.application.ActionBarAdvisor;
import org.eclipse.ui.application.IActionBarConfigurer;
import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
import org.eclipse.ui.application.WorkbenchWindowAdvisor;

import com.archimatetool.editor.actions.ArchiActionBarAdvisor;
import com.archimatetool.editor.preferences.IPreferenceConstants;
import com.archimatetool.editor.preferences.Preferences;



/**
 * Workbench Window Advisor
 * 
 * @author Phillip Beauvoir
 */
public class ArchiWorkbenchWindowAdvisor
extends WorkbenchWindowAdvisor {
    
    /**
     * Constructor
     * @param configurer
     */
    public ArchiWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) {
        super(configurer);
        
        // Status Line
        boolean doShowStatusLine = Preferences.STORE.getBoolean(IPreferenceConstants.SHOW_STATUS_LINE);
        configurer.setShowStatusLine(doShowStatusLine);
    }

    @Override
    public ActionBarAdvisor createActionBarAdvisor(IActionBarConfigurer configurer) {
        return new ArchiActionBarAdvisor(configurer);
    }
    
    @Override
    public void preWindowOpen() {
        // Load user fonts here
        loadFonts();
    }
    
    @Override
    public void postWindowOpen() {
        // Application specific launcher actions
        IPlatformLauncher launcher = ArchiPlugin.INSTANCE.getPlatformLauncher();
        if(launcher != null) {
            launcher.postWindowOpen(getWindowConfigurer().getWindow());
        }
    }
    
    private void loadFonts() {
        // Load fonts in local fonts folder
        loadFonts(ArchiPlugin.INSTANCE.getLocalFontsFolder());
        
        // Load user fonts
        loadFonts(ArchiPlugin.INSTANCE.getUserFontsFolder());
    }

    // Scan a folder looking for fonts and load them
    private void loadFonts(File fontFolder) {
        if(fontFolder.exists()) {
            for(File font : fontFolder.listFiles()) {
                if(font.isFile()) {
                    Display.getDefault().loadFont(font.getAbsolutePath());
                }
            }
        }
    }
}

@@ -202,24 +202,85 @@
 .editor;%0D%0A%0D%0A
+import java.awt.Font;%0D%0Aimport java.awt.GraphicsEnvironment;%0D%0A
 import java.
@@ -755,16 +755,70 @@
 ences;%0D%0A
+import com.archimatetool.editor.utils.PlatformUtils;%0D%0A
 %0D%0A%0D%0A%0D%0A/*
@@ -2000,565 +2000,1963 @@
 oad 
-fonts in local fonts folder%0D%0A        loadFonts(ArchiPlugin.INSTANCE.getLocalFontsFolder());%0D%0A        %0D%0A        // Load user fonts%0D%0A        loadFonts(ArchiPlugin.INSTANCE.getUserFontsFolder());%0D%0A    %7D%0D%0A%0D%0A    // Scan a folder looking for fonts and load them%0D%0A    private void loadFonts(File fontFolder) %7B%0D%0A        if(fontFolder.exists()) %7B%0D%0A            for(File font : fontFolder.listFiles()) %7B%0D%0A                if(font.isFile()) %7B%0D%0A                    Display.getDefault().loadFont(font.getAbsolutePath());%0D%0A                %7D%0D%0A            %7D%0D%0A        %7D%0D%0A    %7D
+AWT fonts%0D%0A        // This is needed for Windows for SVG export, but not for Mac%0D%0A        // Linux will load them if we load them *before* loading then into SWT but they still don't work for SVG%0D%0A        if(PlatformUtils.isWindows()) %7B%0D%0A            loadFontsForAWT(ArchiPlugin.INSTANCE.getLocalFontsFolder());%0D%0A            loadFontsForAWT(ArchiPlugin.INSTANCE.getUserFontsFolder());%0D%0A%0D%0A            // Load Windows fonts installed for user, not %22for all users%22 - fixes SVG export%0D%0A            loadFontsForAWT(new File(System.getProperty(%22user.home%22), %22AppData/Local/Microsoft/Windows/Fonts%22)); //$NON-NLS-1$ //$NON-NLS-2$%0D%0A        %7D%0D%0A        %0D%0A        // Load fonts in local fonts folder%0D%0A        loadFonts(ArchiPlugin.INSTANCE.getLocalFontsFolder());%0D%0A        %0D%0A        // Load user fonts%0D%0A        loadFonts(ArchiPlugin.INSTANCE.getUserFontsFolder());%0D%0A    %7D%0D%0A%0D%0A    // Scan a folder looking for fonts and load them%0D%0A    private void loadFonts(File fontFolder) %7B%0D%0A        if(fontFolder.exists()) %7B%0D%0A            for(File font : fontFolder.listFiles()) %7B%0D%0A                if(font.isFile()) %7B%0D%0A                    Display.getDefault().loadFont(font.getAbsolutePath());%0D%0A                %7D%0D%0A            %7D%0D%0A        %7D%0D%0A    %7D%0D%0A%0D%0A    /**%0D%0A     * Load user fonts into AWT for SVG/PDF image export%0D%0A     * Only needed for Windows. Mac doesn't need it and does nothing on Linux.%0D%0A     */%0D%0A    private void loadFontsForAWT(File fontFolder) %7B%0D%0A        if(fontFolder.exists()) %7B%0D%0A            GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();%0D%0A            %0D%0A            for(File file : fontFolder.listFiles()) %7B%0D%0A                if(file.isFile()) %7B%0D%0A                    try %7B%0D%0A                        Font font = Font.createFont(Font.TRUETYPE_FONT, file);%0D%0A                        ge.registerFont(font);%0D%0A                    %7D%0D%0A                    catch(Exception ex) %7B%0D%0A                    %7D%0D%0A                %7D%0D%0A            %7D%0D%0A        %7D%0D%0A    %7D%0D%0A
 %0D%0A%7D%0D

Load fonts into AWT for SVG export