< prev index next >

modules/javafx.graphics/src/test/java/test/com/sun/javafx/pgstub/StubTextLayout.java

Print this page

  1 /*
  2  * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.  Oracle designates this
  8  * particular file as subject to the "Classpath" exception as provided
  9  * by Oracle in the LICENSE file that accompanied this code.
 10  *
 11  * This code is distributed in the hope that it will be useful, but WITHOUT
 12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  * version 2 for more details (a copy is included in the LICENSE file that
 15  * accompanied this code).
 16  *
 17  * You should have received a copy of the GNU General Public License version
 18  * 2 along with this work; if not, write to the Free Software Foundation,
 19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  *
 21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22  * or visit www.oracle.com if you need additional information or have any

 25 
 26 package test.com.sun.javafx.pgstub;
 27 
 28 import com.sun.javafx.geom.BaseBounds;
 29 import com.sun.javafx.geom.Path2D;
 30 import com.sun.javafx.geom.RectBounds;
 31 import com.sun.javafx.geom.Shape;
 32 import com.sun.javafx.scene.text.*;
 33 import javafx.scene.shape.PathElement;
 34 import javafx.scene.text.Font;
 35 
 36 public class StubTextLayout implements TextLayout {
 37 
 38     @Override
 39     public boolean setContent(TextSpan[] spans) {
 40         return true;
 41     }
 42 
 43     private String text;
 44     private Font font;


 45     @Override
 46     public boolean setContent(String text, Object font) {
 47         this.text = text;
 48         final StubFontLoader.StubFont stub = ((StubFontLoader.StubFont)font);
 49         this.font = stub == null ? null : stub.font;
 50         return true;
 51     }
 52 
 53     @Override
 54     public boolean setAlignment(int alignment) {
 55         return true;
 56     }
 57 
 58     @Override
 59     public boolean setWrapWidth(float wrapWidth) {
 60         return true;
 61     }
 62 
 63     @Override
 64     public boolean setLineSpacing(float spacing) {

 70         return true;
 71     }
 72 
 73     @Override
 74     public boolean setBoundsType(int type) {
 75         return true;
 76     }
 77 
 78     @Override
 79     public BaseBounds getBounds() {
 80         return getBounds(null, new RectBounds());
 81     }
 82 
 83     @Override
 84     public BaseBounds getBounds(TextSpan filter, BaseBounds bounds) {
 85         final double fontSize = (font == null ? 0 : ((Font)font).getSize());
 86         final String[] lines = text.split("\n");
 87         double width = 0.0;
 88         double height = fontSize * lines.length;
 89         for (String line : lines) {
 90             width = Math.max(width, fontSize * line.length());



















 91         }
 92         return bounds.deriveWithNewBounds(0, (float)-fontSize, 0,
 93                 (float)width, (float)(height-fontSize), 0);
 94     }
 95 
 96     class StubTextLine implements TextLine {
 97         @Override public GlyphList[] getRuns() {
 98             return new GlyphList[0];
 99         }
100         @Override public RectBounds getBounds() {
101             return new RectBounds();
102         }
103         @Override public float getLeftSideBearing() {
104             return 0;
105         }
106         @Override public float getRightSideBearing() {
107             return 0;
108         }
109         @Override public int getStart() {
110             return 0;

156 
157         return new Hit(offset + charPos, -1, true);
158     }
159 
160     @Override
161     public PathElement[] getCaretShape(int offset, boolean isLeading, float x,
162             float y) {
163         return new PathElement[0];
164     }
165 
166     @Override
167     public PathElement[] getRange(int start, int end, int type, float x, float y) {
168         return new PathElement[0];
169     }
170 
171     @Override
172     public BaseBounds getVisualBounds(int type) {
173         return new RectBounds();
174     }
175 











176 }

  1 /*
  2  * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.  Oracle designates this
  8  * particular file as subject to the "Classpath" exception as provided
  9  * by Oracle in the LICENSE file that accompanied this code.
 10  *
 11  * This code is distributed in the hope that it will be useful, but WITHOUT
 12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  * version 2 for more details (a copy is included in the LICENSE file that
 15  * accompanied this code).
 16  *
 17  * You should have received a copy of the GNU General Public License version
 18  * 2 along with this work; if not, write to the Free Software Foundation,
 19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  *
 21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22  * or visit www.oracle.com if you need additional information or have any

 25 
 26 package test.com.sun.javafx.pgstub;
 27 
 28 import com.sun.javafx.geom.BaseBounds;
 29 import com.sun.javafx.geom.Path2D;
 30 import com.sun.javafx.geom.RectBounds;
 31 import com.sun.javafx.geom.Shape;
 32 import com.sun.javafx.scene.text.*;
 33 import javafx.scene.shape.PathElement;
 34 import javafx.scene.text.Font;
 35 
 36 public class StubTextLayout implements TextLayout {
 37 
 38     @Override
 39     public boolean setContent(TextSpan[] spans) {
 40         return true;
 41     }
 42 
 43     private String text;
 44     private Font font;
 45     private int tabSize = DEFAULT_TAB_SIZE;
 46 
 47     @Override
 48     public boolean setContent(String text, Object font) {
 49         this.text = text;
 50         final StubFontLoader.StubFont stub = ((StubFontLoader.StubFont)font);
 51         this.font = stub == null ? null : stub.font;
 52         return true;
 53     }
 54 
 55     @Override
 56     public boolean setAlignment(int alignment) {
 57         return true;
 58     }
 59 
 60     @Override
 61     public boolean setWrapWidth(float wrapWidth) {
 62         return true;
 63     }
 64 
 65     @Override
 66     public boolean setLineSpacing(float spacing) {

 72         return true;
 73     }
 74 
 75     @Override
 76     public boolean setBoundsType(int type) {
 77         return true;
 78     }
 79 
 80     @Override
 81     public BaseBounds getBounds() {
 82         return getBounds(null, new RectBounds());
 83     }
 84 
 85     @Override
 86     public BaseBounds getBounds(TextSpan filter, BaseBounds bounds) {
 87         final double fontSize = (font == null ? 0 : ((Font)font).getSize());
 88         final String[] lines = text.split("\n");
 89         double width = 0.0;
 90         double height = fontSize * lines.length;
 91         for (String line : lines) {
 92             int tabs = 0;
 93             final int length;
 94             if (line.contains("\t")) {
 95                 // count chars but when encountering a tab round up to a tabSize boundary
 96                 char [] chrs = line.toCharArray();
 97                 int spaces = 0;
 98                 for (int i = 0; i < chrs.length; i++) {
 99                     if (chrs[i] == '\t') {
100                         if (tabSize != 0) {
101                             while ((++spaces % tabSize) != 0) {}
102                         }
103                     } else {
104                         spaces++;
105                     }
106                 }
107                 length = spaces;
108             } else {
109                 length = line.length();
110             }
111             width = Math.max(width, fontSize * length);
112         }
113         return bounds.deriveWithNewBounds(0, (float)-fontSize, 0,
114                 (float)width, (float)(height-fontSize), 0);
115     }
116 
117     class StubTextLine implements TextLine {
118         @Override public GlyphList[] getRuns() {
119             return new GlyphList[0];
120         }
121         @Override public RectBounds getBounds() {
122             return new RectBounds();
123         }
124         @Override public float getLeftSideBearing() {
125             return 0;
126         }
127         @Override public float getRightSideBearing() {
128             return 0;
129         }
130         @Override public int getStart() {
131             return 0;

177 
178         return new Hit(offset + charPos, -1, true);
179     }
180 
181     @Override
182     public PathElement[] getCaretShape(int offset, boolean isLeading, float x,
183             float y) {
184         return new PathElement[0];
185     }
186 
187     @Override
188     public PathElement[] getRange(int start, int end, int type, float x, float y) {
189         return new PathElement[0];
190     }
191 
192     @Override
193     public BaseBounds getVisualBounds(int type) {
194         return new RectBounds();
195     }
196 
197     @Override
198     public boolean setTabSize(int spaces) {
199         if (spaces < 1)
200             spaces = 1;
201         if (tabSize != spaces) {
202             tabSize = spaces;
203             return true;
204         }
205         return false;
206     }
207 
208 }
< prev index next >