View Javadoc

1   /*
2    *  MicroEmulator
3    *  Copyright (C) 2006 Bartek Teodorczyk <barteo@barteo.net>
4    *
5    *  This library is free software; you can redistribute it and/or
6    *  modify it under the terms of the GNU Lesser General Public
7    *  License as published by the Free Software Foundation; either
8    *  version 2.1 of the License, or (at your option) any later version.
9    *
10   *  This library is distributed in the hope that it will be useful,
11   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13   *  Lesser General Public License for more details.
14   *
15   *  You should have received a copy of the GNU Lesser General Public
16   *  License along with this library; if not, write to the Free Software
17   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   */
19  
20  package org.microemu.device.swt;
21  
22  import java.net.URL;
23  
24  import org.eclipse.swt.SWT;
25  import org.eclipse.swt.graphics.Font;
26  
27  public class SwtTrueTypeFont implements SwtFont {
28  
29  	private URL url;
30  	
31  	private String style;
32  	
33  	private int size;
34  	
35  	private boolean antialiasing;
36  	
37  	private boolean initialized;
38  	
39  	private Font font;
40  
41  	public SwtTrueTypeFont(URL url, String style, int size, boolean antialiasing) {
42  		this.url = url;
43  		this.style = style.toLowerCase();
44  		this.size = size;
45  		this.antialiasing = antialiasing;
46  		
47  		this.initialized = false;
48  	}
49  
50  	public void setAntialiasing(boolean antialiasing) {
51  		if (this.antialiasing != antialiasing) {
52  			this.antialiasing = antialiasing;
53  			initialized = false;
54  		}
55  	}
56  
57  	public Font getFont() {
58  		checkInitialized();
59  
60  		return font;
61  	}
62  
63  	private synchronized void checkInitialized() {
64  		if (!initialized) {
65  			int swtStyle = 0;
66  			if (style.indexOf("plain") != -1) {
67  				swtStyle |= SWT.NORMAL;
68  			}
69  			if (style.indexOf("bold") != -1) {
70  				swtStyle |= SWT.BOLD;
71  			}
72  			if (style.indexOf("italic") != -1) {
73  				swtStyle |= SWT.ITALIC;
74  			}
75  			if (style.indexOf("underlined") != -1) {
76  				// TODO underlined style not implemented
77  			}
78  
79  //			font = SwtDeviceComponent.getFont(name, size, swtStyle, antialiasing);
80  			initialized = true;
81  			try {
82  				throw new RuntimeException("not implemented");
83  			} catch (RuntimeException ex) {
84  				ex.printStackTrace();
85  				throw ex;
86  			}
87  		}
88  	}
89  
90  	public int charWidth(char ch) {
91  		try {
92  			throw new RuntimeException("not implemented");
93  		} catch (RuntimeException ex) {
94  			ex.printStackTrace();
95  			throw ex;
96  		}
97  	}
98  
99  	public int charsWidth(char[] ch, int offset, int length) {
100 		try {
101 			throw new RuntimeException("not implemented");
102 		} catch (RuntimeException ex) {
103 			ex.printStackTrace();
104 			throw ex;
105 		}
106 	}
107 
108 	public int getBaselinePosition() {
109 		try {
110 			throw new RuntimeException("not implemented");
111 		} catch (RuntimeException ex) {
112 			ex.printStackTrace();
113 			throw ex;
114 		}
115 	}
116 
117 	public int getHeight() {
118 		try {
119 			throw new RuntimeException("not implemented");
120 		} catch (RuntimeException ex) {
121 			ex.printStackTrace();
122 			throw ex;
123 		}
124 	}
125 
126 	public int stringWidth(String str) {
127 		try {
128 			throw new RuntimeException("not implemented");
129 		} catch (RuntimeException ex) {
130 			ex.printStackTrace();
131 			throw ex;
132 		}
133 	}
134 
135 }