|
Lines 20-27
Link Here
|
| 20 |
import org.eclipse.rwt.Fixture; |
20 |
import org.eclipse.rwt.Fixture; |
| 21 |
import org.eclipse.rwt.graphics.Graphics; |
21 |
import org.eclipse.rwt.graphics.Graphics; |
| 22 |
import org.eclipse.swt.SWT; |
22 |
import org.eclipse.swt.SWT; |
| 23 |
import org.eclipse.swt.graphics.Font; |
23 |
import org.eclipse.swt.graphics.*; |
| 24 |
import org.eclipse.swt.graphics.Point; |
|
|
| 25 |
import org.eclipse.swt.internal.graphics.TextSizeDetermination.ICalculationItem; |
24 |
import org.eclipse.swt.internal.graphics.TextSizeDetermination.ICalculationItem; |
| 26 |
import org.eclipse.swt.internal.graphics.TextSizeProbeStore.IProbe; |
25 |
import org.eclipse.swt.internal.graphics.TextSizeProbeStore.IProbe; |
| 27 |
import org.eclipse.swt.internal.graphics.TextSizeProbeStore.IProbeResult; |
26 |
import org.eclipse.swt.internal.graphics.TextSizeProbeStore.IProbeResult; |
|
Lines 53-63
Link Here
|
| 53 |
Point storedSize = new Point( 100, 10 ); |
52 |
Point storedSize = new Point( 100, 10 ); |
| 54 |
IProbe[] probeRequests = TextSizeProbeStore.getProbeRequests(); |
53 |
IProbe[] probeRequests = TextSizeProbeStore.getProbeRequests(); |
| 55 |
assertEquals( 1, probeRequests.length ); |
54 |
assertEquals( 1, probeRequests.length ); |
| 56 |
assertSame( font, probeRequests[ 0 ].getFont() ); |
55 |
assertSame( font.getFontData()[ 0 ], probeRequests[ 0 ].getFontData() ); |
| 57 |
|
56 |
|
| 58 |
TextSizeProbeStore probeStore = TextSizeProbeStore.getInstance(); |
57 |
TextSizeProbeStore probeStore = TextSizeProbeStore.getInstance(); |
| 59 |
probeStore.createProbeResult( probeRequests[ 0 ], new Point( 10, 10 ) ); |
58 |
probeStore.createProbeResult( probeRequests[ 0 ], new Point( 10, 10 ) ); |
| 60 |
TextSizeDataBase.store( font, TEST_STRING, SWT.DEFAULT, storedSize ); |
59 |
TextSizeDataBase.store( font.getFontData()[ 0 ], |
|
|
60 |
TEST_STRING, |
| 61 |
SWT.DEFAULT, |
| 62 |
storedSize ); |
| 61 |
calculated = TextSizeDetermination.stringExtent( font, TEST_STRING ); |
63 |
calculated = TextSizeDetermination.stringExtent( font, TEST_STRING ); |
| 62 |
assertEquals( storedSize, calculated ); |
64 |
assertEquals( storedSize, calculated ); |
| 63 |
|
65 |
|
|
Lines 110-116
Link Here
|
| 110 |
|
112 |
|
| 111 |
probeRequests = TextSizeProbeStore.getProbeRequests(); |
113 |
probeRequests = TextSizeProbeStore.getProbeRequests(); |
| 112 |
assertEquals( 1, probeRequests.length ); |
114 |
assertEquals( 1, probeRequests.length ); |
| 113 |
assertSame( font0, probeRequests[ 0 ].getFont() ); |
115 |
assertSame( font0.getFontData()[ 0 ], probeRequests[ 0 ].getFontData() ); |
| 114 |
|
116 |
|
| 115 |
TextSizeProbeStore probeStore = TextSizeProbeStore.getInstance(); |
117 |
TextSizeProbeStore probeStore = TextSizeProbeStore.getInstance(); |
| 116 |
Point probeSize = new Point( 10, 13 ); |
118 |
Point probeSize = new Point( 10, 13 ); |
|
Lines 130-136
Link Here
|
| 130 |
|
132 |
|
| 131 |
probeRequests = TextSizeProbeStore.getProbeRequests(); |
133 |
probeRequests = TextSizeProbeStore.getProbeRequests(); |
| 132 |
assertEquals( 1, probeRequests.length ); |
134 |
assertEquals( 1, probeRequests.length ); |
| 133 |
assertSame( font0, probeRequests[ 0 ].getFont() ); |
135 |
assertSame( font0.getFontData()[ 0 ], probeRequests[ 0 ].getFontData() ); |
| 134 |
|
136 |
|
| 135 |
TextSizeProbeStore probeStore = TextSizeProbeStore.getInstance(); |
137 |
TextSizeProbeStore probeStore = TextSizeProbeStore.getInstance(); |
| 136 |
Point probeSize = new Point( TextSizeProbeStore.DEFAULT_PROBE.length() * 4, 10 ); |
138 |
Point probeSize = new Point( TextSizeProbeStore.DEFAULT_PROBE.length() * 4, 10 ); |
|
Lines 141-156
Link Here
|
| 141 |
|
143 |
|
| 142 |
public void testFontSizeDataBase() { |
144 |
public void testFontSizeDataBase() { |
| 143 |
Font font0 = Graphics.getFont( "arial", 10, SWT.NORMAL ); |
145 |
Font font0 = Graphics.getFont( "arial", 10, SWT.NORMAL ); |
|
|
146 |
FontData fontData0 = font0.getFontData()[ 0 ]; |
| 144 |
Font font1 = Graphics.getFont( "helvetia", 12, SWT.NORMAL ); |
147 |
Font font1 = Graphics.getFont( "helvetia", 12, SWT.NORMAL ); |
|
|
148 |
FontData fontData1 = font1.getFontData()[ 0 ]; |
| 145 |
|
149 |
|
| 146 |
Point textSize = TextSizeDataBase.lookup( font0, TEST_STRING, SWT.DEFAULT ); |
150 |
Point textSize; |
|
|
151 |
textSize = TextSizeDataBase.lookup( fontData0, TEST_STRING, SWT.DEFAULT ); |
| 147 |
assertNull( textSize ); |
152 |
assertNull( textSize ); |
| 148 |
textSize = TextSizeDataBase.lookup( font1, TEST_STRING, SWT.DEFAULT ); |
153 |
textSize = TextSizeDataBase.lookup( fontData1, TEST_STRING, SWT.DEFAULT ); |
| 149 |
assertNull( textSize ); |
154 |
assertNull( textSize ); |
| 150 |
|
155 |
|
| 151 |
try { |
156 |
try { |
| 152 |
Point point = new Point( 1, 1 ); |
157 |
Point point = new Point( 1, 1 ); |
| 153 |
TextSizeDataBase.store( font1, TEST_STRING, SWT.DEFAULT, point ); |
158 |
TextSizeDataBase.store( fontData1, TEST_STRING, SWT.DEFAULT, point ); |
| 154 |
fail( "No probe available." ); |
159 |
fail( "No probe available." ); |
| 155 |
} catch( final IllegalStateException ise ) { |
160 |
} catch( final IllegalStateException ise ) { |
| 156 |
} |
161 |
} |
|
Lines 163-226
Link Here
|
| 163 |
probeStore.createProbeResult( findRequestedProbe( 1 ), probeSize1 ); |
168 |
probeStore.createProbeResult( findRequestedProbe( 1 ), probeSize1 ); |
| 164 |
|
169 |
|
| 165 |
Point calculatedTextSize0 = new Point( 100, 10 ); |
170 |
Point calculatedTextSize0 = new Point( 100, 10 ); |
| 166 |
TextSizeDataBase.store( font0, |
171 |
TextSizeDataBase.store( fontData0, |
| 167 |
TEST_STRING, |
172 |
TEST_STRING, |
| 168 |
SWT.DEFAULT, |
173 |
SWT.DEFAULT, |
| 169 |
calculatedTextSize0 ); |
174 |
calculatedTextSize0 ); |
| 170 |
Point calculatedTextSize1 = new Point( 100, 12 ); |
175 |
Point calculatedTextSize1 = new Point( 100, 12 ); |
| 171 |
TextSizeDataBase.store( font1, |
176 |
TextSizeDataBase.store( fontData1, |
| 172 |
TEST_STRING, |
177 |
TEST_STRING, |
| 173 |
SWT.DEFAULT, |
178 |
SWT.DEFAULT, |
| 174 |
calculatedTextSize1 ); |
179 |
calculatedTextSize1 ); |
| 175 |
textSize = TextSizeDataBase.lookup( font0, TEST_STRING, SWT.DEFAULT ); |
180 |
textSize = TextSizeDataBase.lookup( fontData0, TEST_STRING, SWT.DEFAULT ); |
| 176 |
assertEquals( calculatedTextSize0, textSize ); |
181 |
assertEquals( calculatedTextSize0, textSize ); |
| 177 |
textSize = TextSizeDataBase.lookup( font1, TEST_STRING, SWT.DEFAULT ); |
182 |
textSize = TextSizeDataBase.lookup( fontData1, TEST_STRING, SWT.DEFAULT ); |
| 178 |
assertEquals( calculatedTextSize1, textSize ); |
183 |
assertEquals( calculatedTextSize1, textSize ); |
| 179 |
} |
184 |
} |
| 180 |
|
185 |
|
| 181 |
private IProbe findRequestedProbe( final int i ) { |
186 |
private IProbe findRequestedProbe( final int i ) { |
| 182 |
IProbe[] probeRequests = TextSizeProbeStore.getProbeRequests(); |
187 |
IProbe[] probeRequests = TextSizeProbeStore.getProbeRequests(); |
| 183 |
return TextSizeProbeStore.getProbe( probeRequests[ i ].getFont() ); |
188 |
return TextSizeProbeStore.getProbe( probeRequests[ i ].getFontData() ); |
| 184 |
} |
189 |
} |
| 185 |
|
190 |
|
| 186 |
public void testProbeStorage() { |
191 |
public void testProbeStorage() { |
| 187 |
Font font0 = Graphics.getFont( "arial", 10, SWT.NORMAL ); |
192 |
Font font0 = Graphics.getFont( "arial", 10, SWT.NORMAL ); |
|
|
193 |
FontData fontData0 = font0.getFontData()[ 0 ]; |
| 188 |
IProbe[] probeList = TextSizeProbeStore.getProbeList(); |
194 |
IProbe[] probeList = TextSizeProbeStore.getProbeList(); |
| 189 |
assertEquals( 0, probeList.length ); |
195 |
assertEquals( 0, probeList.length ); |
| 190 |
IProbe probe0 = TextSizeProbeStore.getProbe( font0 ); |
196 |
IProbe probe0 = TextSizeProbeStore.getProbe( fontData0 ); |
| 191 |
assertNull( probe0 ); |
197 |
assertNull( probe0 ); |
| 192 |
|
198 |
|
| 193 |
String probeText0 = "ProbeText0"; |
199 |
String probeText0 = "ProbeText0"; |
| 194 |
probe0 = TextSizeProbeStore.createProbe( font0, probeText0 ); |
200 |
probe0 = TextSizeProbeStore.createProbe( fontData0, probeText0 ); |
| 195 |
probeList = TextSizeProbeStore.getProbeList(); |
201 |
probeList = TextSizeProbeStore.getProbeList(); |
| 196 |
assertEquals( 1, probeList.length ); |
202 |
assertEquals( 1, probeList.length ); |
| 197 |
assertSame( probe0, probeList[ 0 ] ); |
203 |
assertSame( probe0, probeList[ 0 ] ); |
| 198 |
assertSame( probe0, TextSizeProbeStore.getProbe( font0 ) ); |
204 |
assertSame( probe0, TextSizeProbeStore.getProbe( fontData0 ) ); |
| 199 |
assertTrue( TextSizeProbeStore.containsProbe( font0 ) ); |
205 |
assertTrue( TextSizeProbeStore.containsProbe( fontData0 ) ); |
| 200 |
assertSame( probe0.getFont(), font0 ); |
206 |
assertSame( probe0.getFontData(), fontData0 ); |
| 201 |
assertSame( probe0.getString(), probeText0 ); |
207 |
assertSame( probe0.getString(), probeText0 ); |
| 202 |
|
208 |
|
| 203 |
Font font1 = Graphics.getFont( "arial", 12, SWT.NORMAL ); |
209 |
Font font1 = Graphics.getFont( "arial", 12, SWT.NORMAL ); |
| 204 |
assertFalse( TextSizeProbeStore.containsProbe( font1 ) ); |
210 |
FontData fontData1 = font1.getFontData()[ 0 ]; |
|
|
211 |
assertFalse( TextSizeProbeStore.containsProbe( fontData1 ) ); |
| 205 |
|
212 |
|
| 206 |
TextSizeProbeStore probeStore = TextSizeProbeStore.getInstance(); |
213 |
TextSizeProbeStore probeStore = TextSizeProbeStore.getInstance(); |
| 207 |
IProbeResult probeResult0 = probeStore.getProbeResult( font0 ); |
214 |
IProbeResult probeResult0 = probeStore.getProbeResult( fontData0 ); |
| 208 |
assertNull( probeResult0 ); |
215 |
assertNull( probeResult0 ); |
| 209 |
|
216 |
|
| 210 |
Point probeSize0 = new Point( 10, 10 ); |
217 |
Point probeSize0 = new Point( 10, 10 ); |
| 211 |
probeResult0 = probeStore.createProbeResult( probe0, probeSize0 ); |
218 |
probeResult0 = probeStore.createProbeResult( probe0, probeSize0 ); |
| 212 |
assertSame( probeResult0.getProbe(), probe0 ); |
219 |
assertSame( probeResult0.getProbe(), probe0 ); |
| 213 |
assertSame( probeResult0.getSize(), probeSize0 ); |
220 |
assertSame( probeResult0.getSize(), probeSize0 ); |
| 214 |
assertTrue( probeStore.containsProbeResult( font0 ) ); |
221 |
assertTrue( probeStore.containsProbeResult( fontData0 ) ); |
| 215 |
assertFalse( probeStore.containsProbeResult( font1 ) ); |
222 |
assertFalse( probeStore.containsProbeResult( fontData1 ) ); |
| 216 |
} |
223 |
} |
| 217 |
|
224 |
|
| 218 |
public void testDefaultFontSizeStorage() throws IOException { |
225 |
public void testDefaultFontSizeStorage() throws IOException { |
| 219 |
DefaultTextSizeStorage storage = new DefaultTextSizeStorage(); |
226 |
DefaultTextSizeStorage storage = new DefaultTextSizeStorage(); |
| 220 |
Font font0 = Graphics.getFont( "arial", 10, SWT.NORMAL ); |
227 |
Font font0 = Graphics.getFont( "arial", 10, SWT.NORMAL ); |
|
|
228 |
FontData fontData0 = font0.getFontData()[ 0 ]; |
| 221 |
Font font1 = Graphics.getFont( "helvetia", 12, SWT.NORMAL ); |
229 |
Font font1 = Graphics.getFont( "helvetia", 12, SWT.NORMAL ); |
| 222 |
storage.storeFont( font0 ); |
230 |
FontData fontData1 = font1.getFontData()[ 0 ]; |
| 223 |
storage.storeFont( font1 ); |
231 |
storage.storeFont( fontData0 ); |
|
|
232 |
storage.storeFont( fontData1 ); |
| 224 |
|
233 |
|
| 225 |
Point point0 = new Point( 9, 10 ); |
234 |
Point point0 = new Point( 9, 10 ); |
| 226 |
Integer key0 = new Integer( 0 ); |
235 |
Integer key0 = new Integer( 0 ); |
|
Lines 252-268
Link Here
|
| 252 |
assertEquals( point0, actual ); |
261 |
assertEquals( point0, actual ); |
| 253 |
actual = storage.lookupTextSize( key1 ); |
262 |
actual = storage.lookupTextSize( key1 ); |
| 254 |
assertEquals( point1, actual ); |
263 |
assertEquals( point1, actual ); |
| 255 |
Font[] fontList = storage.getFontList(); |
264 |
FontData[] fontDatas = storage.getFontList(); |
| 256 |
List fonts = Arrays.asList( fontList ); |
265 |
assertEquals( 2, fontDatas.length ); |
| 257 |
assertEquals( 2, fonts.size() ); |
266 |
List fontDataList = Arrays.asList( fontDatas ); |
| 258 |
assertTrue( fonts.contains( font0 ) ); |
267 |
assertTrue( fontDataList.contains( fontData0 ) ); |
| 259 |
assertTrue( fonts.contains( font1 ) ); |
268 |
assertTrue( fontDataList.contains( fontData1 ) ); |
| 260 |
} |
269 |
} |
| 261 |
|
270 |
|
| 262 |
public void testStorageOverflow() { |
271 |
public void testStorageOverflow() { |
| 263 |
DefaultTextSizeStorage storage = new DefaultTextSizeStorage(); |
272 |
DefaultTextSizeStorage storage = new DefaultTextSizeStorage(); |
| 264 |
int storeSize = DefaultTextSizeStorage.MIN_STORE_SIZE; |
273 |
int storeSize = DefaultTextSizeStorage.MIN_STORE_SIZE; |
| 265 |
DefaultTextSizeStorage.setStoreSize( storeSize ); |
274 |
storage.setStoreSize( storeSize ); |
| 266 |
|
275 |
|
| 267 |
for( int i = 0; i < storeSize - 1; i++ ) { |
276 |
for( int i = 0; i < storeSize - 1; i++ ) { |
| 268 |
Integer key = new Integer( i ); |
277 |
Integer key = new Integer( i ); |
|
Lines 286-300
Link Here
|
| 286 |
} |
295 |
} |
| 287 |
|
296 |
|
| 288 |
public void testTextSizeDatabaseKey() { |
297 |
public void testTextSizeDatabaseKey() { |
| 289 |
final Font font = Graphics.getFont( "name", 10, SWT.NORMAL ); |
298 |
Font font = Graphics.getFont( "name", 10, SWT.NORMAL ); |
|
|
299 |
final FontData fontData = font.getFontData()[ 0 ]; |
| 290 |
Set takenKeys = new HashSet(); |
300 |
Set takenKeys = new HashSet(); |
| 291 |
StringBuffer generatedText = new StringBuffer(); |
301 |
StringBuffer generatedText = new StringBuffer(); |
| 292 |
for( int i = 0; i < 100; i++ ) { |
302 |
for( int i = 0; i < 100; i++ ) { |
| 293 |
generatedText.append( "a" ); |
303 |
generatedText.append( "a" ); |
| 294 |
final String text = generatedText.toString(); |
304 |
final String text = generatedText.toString(); |
| 295 |
IProbe probe = new IProbe() { |
305 |
IProbe probe = new IProbe() { |
| 296 |
public Font getFont() { |
306 |
public FontData getFontData() { |
| 297 |
return font; |
307 |
return fontData; |
| 298 |
} |
308 |
} |
| 299 |
public String getString() { |
309 |
public String getString() { |
| 300 |
return text; |
310 |
return text; |
|
Lines 305-316
Link Here
|
| 305 |
}; |
315 |
}; |
| 306 |
Point size = new Point( 1, 2 ); |
316 |
Point size = new Point( 1, 2 ); |
| 307 |
TextSizeProbeStore.getInstance().createProbeResult( probe, size ); |
317 |
TextSizeProbeStore.getInstance().createProbeResult( probe, size ); |
| 308 |
Integer key = TextSizeDataBase.getKey( font, text, -1 ); |
318 |
Integer key = TextSizeDataBase.getKey( fontData, text, -1 ); |
| 309 |
assertFalse( takenKeys.contains( key ) ); |
319 |
assertFalse( takenKeys.contains( key ) ); |
| 310 |
takenKeys.add( key ); |
320 |
takenKeys.add( key ); |
| 311 |
} |
321 |
} |
| 312 |
} |
322 |
} |
| 313 |
|
323 |
|
| 314 |
protected void setUp() throws Exception { |
324 |
protected void setUp() throws Exception { |
| 315 |
Fixture.setUp(); |
325 |
Fixture.setUp(); |
| 316 |
TextSizeDataBase.reset(); |
326 |
TextSizeDataBase.reset(); |