src/demo/share/java2d/J2DBench/src/j2dbench/tests/text/TextMeasureTests.java

Print this page




 215             } while (--numReps >= 0);
 216         }
 217     }
 218 
 219     public static class GVContext extends G2DContext {
 220         GlyphVector gv;
 221 
 222         public void init(TestEnvironment env, Result results) {
 223             super.init(env, results);
 224 
 225             int flags = Font.LAYOUT_LEFT_TO_RIGHT;
 226             if (Bidi.requiresBidi(chars, 0, chars.length)) { // assume rtl
 227                 flags = Font.LAYOUT_RIGHT_TO_LEFT;
 228             }
 229             gv = font.layoutGlyphVector(frc, chars, 0, chars.length, flags);
 230 
 231             // gv options
 232         }
 233     }
 234 
 235     public static abstract class GVMeasureTest extends TextMeasureTests {
 236         protected GVMeasureTest(Group parent, String nodeName, String description) {
 237             super(parent, nodeName, description);
 238         }
 239 
 240         public Context createContext() {
 241             return new GVContext();
 242         }
 243     }
 244 
 245     public static class GVWidth extends GVMeasureTest {
 246         public GVWidth() {
 247             super(measuretestroot, "gvWidth", "Measuring GV Width");
 248         }
 249 
 250         public void runTest(Object ctx, int numReps) {
 251             GVContext gvctx = (GVContext)ctx;
 252             GlyphVector gv = gvctx.gv;
 253             double wid = 0;
 254             do {
 255                 wid += gv.getGlyphPosition(gv.getNumGlyphs()).getX();


 414             GlyphMetrics gm;
 415             do {
 416                 for (int i = 0, e = gv.getNumGlyphs(); i < e; ++i) {
 417                     gm = gv.getGlyphMetrics(i);
 418                 }
 419             } while (--numReps >= 0);
 420         }
 421     }
 422 
 423     public static class TLContext extends G2DContext {
 424         TextLayout tl;
 425 
 426         public void init(TestEnvironment env, Result results) {
 427             super.init(env, results);
 428 
 429             // need more tl options here
 430             tl = new TextLayout(text, font, frc);
 431         }
 432     }
 433 
 434     public static abstract class TLMeasureTest extends TextMeasureTests {
 435         protected TLMeasureTest(Group parent, String nodeName, String description) {
 436             super(parent, nodeName, description);
 437         }
 438 
 439         public Context createContext() {
 440             return new TLContext();
 441         }
 442     }
 443 
 444     public static class TLAdvance extends TLMeasureTest {
 445         public TLAdvance() {
 446             super(measuretestroot, "tlAdvance", "Measuring TL advance");
 447         }
 448 
 449         public void runTest(Object ctx, int numReps) {
 450             TLContext tlctx = (TLContext)ctx;
 451             TextLayout tl = tlctx.tl;
 452             double wid = 0;
 453             do {
 454                 wid += tl.getAdvance();


 489     static class TLExContext extends TLContext {
 490         TextHitInfo[] hits;
 491         Rectangle2D lb;
 492 
 493         public void init(TestEnvironment env, Result results) {
 494             super.init(env, results);
 495 
 496             ArrayList list = new ArrayList(text.length() * 2 + 2);
 497             TextHitInfo hit = TextHitInfo.trailing(-1);
 498             do {
 499                 list.add(hit);
 500                 hit = tl.getNextRightHit(hit);
 501             } while (hit != null);
 502             hits = (TextHitInfo[])list.toArray(new TextHitInfo[list.size()]);
 503 
 504             lb = tl.getBounds();
 505             lb.setRect(lb.getMinX() - 10, lb.getMinY(), lb.getWidth() + 20, lb.getHeight());
 506         }
 507     }
 508 
 509     public static abstract class TLExtendedMeasureTest extends TLMeasureTest {
 510         protected TLExtendedMeasureTest(Group parent, String nodeName, String description) {
 511             super(parent, nodeName, description);
 512         }
 513 
 514         public Context createContext() {
 515             return new TLExContext();
 516         }
 517     }
 518 
 519     public static class TLGetCaretInfo extends TLExtendedMeasureTest {
 520         public TLGetCaretInfo() {
 521             super(measuretestroot, "tlGetCaretInfo", "Measuring TL caret info");
 522         }
 523 
 524         public void runTest(Object ctx, int numReps) {
 525             TLExContext tlctx = (TLExContext)ctx;
 526             TextLayout tl = tlctx.tl;
 527             TextHitInfo[] hits = tlctx.hits;
 528             do {
 529                 for (int i = 0; i < hits.length; ++i) {




 215             } while (--numReps >= 0);
 216         }
 217     }
 218 
 219     public static class GVContext extends G2DContext {
 220         GlyphVector gv;
 221 
 222         public void init(TestEnvironment env, Result results) {
 223             super.init(env, results);
 224 
 225             int flags = Font.LAYOUT_LEFT_TO_RIGHT;
 226             if (Bidi.requiresBidi(chars, 0, chars.length)) { // assume rtl
 227                 flags = Font.LAYOUT_RIGHT_TO_LEFT;
 228             }
 229             gv = font.layoutGlyphVector(frc, chars, 0, chars.length, flags);
 230 
 231             // gv options
 232         }
 233     }
 234 
 235     public abstract static class GVMeasureTest extends TextMeasureTests {
 236         protected GVMeasureTest(Group parent, String nodeName, String description) {
 237             super(parent, nodeName, description);
 238         }
 239 
 240         public Context createContext() {
 241             return new GVContext();
 242         }
 243     }
 244 
 245     public static class GVWidth extends GVMeasureTest {
 246         public GVWidth() {
 247             super(measuretestroot, "gvWidth", "Measuring GV Width");
 248         }
 249 
 250         public void runTest(Object ctx, int numReps) {
 251             GVContext gvctx = (GVContext)ctx;
 252             GlyphVector gv = gvctx.gv;
 253             double wid = 0;
 254             do {
 255                 wid += gv.getGlyphPosition(gv.getNumGlyphs()).getX();


 414             GlyphMetrics gm;
 415             do {
 416                 for (int i = 0, e = gv.getNumGlyphs(); i < e; ++i) {
 417                     gm = gv.getGlyphMetrics(i);
 418                 }
 419             } while (--numReps >= 0);
 420         }
 421     }
 422 
 423     public static class TLContext extends G2DContext {
 424         TextLayout tl;
 425 
 426         public void init(TestEnvironment env, Result results) {
 427             super.init(env, results);
 428 
 429             // need more tl options here
 430             tl = new TextLayout(text, font, frc);
 431         }
 432     }
 433 
 434     public abstract static class TLMeasureTest extends TextMeasureTests {
 435         protected TLMeasureTest(Group parent, String nodeName, String description) {
 436             super(parent, nodeName, description);
 437         }
 438 
 439         public Context createContext() {
 440             return new TLContext();
 441         }
 442     }
 443 
 444     public static class TLAdvance extends TLMeasureTest {
 445         public TLAdvance() {
 446             super(measuretestroot, "tlAdvance", "Measuring TL advance");
 447         }
 448 
 449         public void runTest(Object ctx, int numReps) {
 450             TLContext tlctx = (TLContext)ctx;
 451             TextLayout tl = tlctx.tl;
 452             double wid = 0;
 453             do {
 454                 wid += tl.getAdvance();


 489     static class TLExContext extends TLContext {
 490         TextHitInfo[] hits;
 491         Rectangle2D lb;
 492 
 493         public void init(TestEnvironment env, Result results) {
 494             super.init(env, results);
 495 
 496             ArrayList list = new ArrayList(text.length() * 2 + 2);
 497             TextHitInfo hit = TextHitInfo.trailing(-1);
 498             do {
 499                 list.add(hit);
 500                 hit = tl.getNextRightHit(hit);
 501             } while (hit != null);
 502             hits = (TextHitInfo[])list.toArray(new TextHitInfo[list.size()]);
 503 
 504             lb = tl.getBounds();
 505             lb.setRect(lb.getMinX() - 10, lb.getMinY(), lb.getWidth() + 20, lb.getHeight());
 506         }
 507     }
 508 
 509     public abstract static class TLExtendedMeasureTest extends TLMeasureTest {
 510         protected TLExtendedMeasureTest(Group parent, String nodeName, String description) {
 511             super(parent, nodeName, description);
 512         }
 513 
 514         public Context createContext() {
 515             return new TLExContext();
 516         }
 517     }
 518 
 519     public static class TLGetCaretInfo extends TLExtendedMeasureTest {
 520         public TLGetCaretInfo() {
 521             super(measuretestroot, "tlGetCaretInfo", "Measuring TL caret info");
 522         }
 523 
 524         public void runTest(Object ctx, int numReps) {
 525             TLExContext tlctx = (TLExContext)ctx;
 526             TextLayout tl = tlctx.tl;
 527             TextHitInfo[] hits = tlctx.hits;
 528             do {
 529                 for (int i = 0; i < hits.length; ++i) {