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
 23  * questions.
 24  */
 25 
 26 package com.sun.javafx.scene.text;
 27 
 28 import javafx.scene.shape.PathElement;
 29 import com.sun.javafx.geom.BaseBounds;
 30 import com.sun.javafx.geom.Shape;
 31 
 32 public interface TextLayout {
 33 
 34     /* Internal flags Flags */
 35     static final int FLAGS_LINES_VALID      = 1 << 0; /* unused */
 36     static final int FLAGS_ANALYSIS_VALID   = 1 << 1;
 37     static final int FLAGS_HAS_TABS         = 1 << 2;
 38     static final int FLAGS_HAS_BIDI         = 1 << 3;
 39     static final int FLAGS_HAS_COMPLEX      = 1 << 4;
 40     static final int FLAGS_HAS_EMBEDDED     = 1 << 5;
 41     static final int FLAGS_HAS_CJK          = 1 << 6;
 42     static final int FLAGS_WRAPPED          = 1 << 7;
 43     static final int FLAGS_RTL_BASE         = 1 << 8;
 44     static final int FLAGS_CACHED_UNDERLINE      = 1 << 9;
 45     static final int FLAGS_CACHED_STRIKETHROUGH  = 1 << 10;
 46     static final int FLAGS_LAST             = 1 << 11;
 47 
 48     static final int ANALYSIS_MASK = FLAGS_LAST - 1;
 49 
 50     /* Text Layout compact internal representation */
 51     static final int ALIGN_LEFT     = 1 << 18;
 52     static final int ALIGN_CENTER   = 1 << 19;
 53     static final int ALIGN_RIGHT    = 1 << 20;
 54     static final int ALIGN_JUSTIFY  = 1 << 21;
 55 
 56     static final int ALIGN_MASK = ALIGN_LEFT | ALIGN_CENTER |
 57                                   ALIGN_RIGHT | ALIGN_JUSTIFY;
 58 
 59     public static final int DIRECTION_LTR          = 1 << 10;
 60     public static final int DIRECTION_RTL          = 1 << 11;
 61     public static final int DIRECTION_DEFAULT_LTR  = 1 << 12;
 62     public static final int DIRECTION_DEFAULT_RTL  = 1 << 13;
 63 
 64     static final int DIRECTION_MASK = DIRECTION_LTR | DIRECTION_RTL |
 65                                       DIRECTION_DEFAULT_LTR |
 66                                       DIRECTION_DEFAULT_RTL;
 67 
 68     public static final int BOUNDS_CENTER       = 1 << 14;
 69     public static final int BOUNDS_MASK = BOUNDS_CENTER;
 70 
 71     public static final int TYPE_TEXT           = 1 << 0;
 72     public static final int TYPE_UNDERLINE      = 1 << 1;
 73     public static final int TYPE_STRIKETHROUGH  = 1 << 2;
 74     public static final int TYPE_BASELINE       = 1 << 3;
 75     public static final int TYPE_TOP            = 1 << 4;
 76     public static final int TYPE_BEARINGS       = 1 << 5;
 77 
 78     static final int DEFAULT_TAB_SIZE = 8;
 79 
 80     public static class Hit {
 81         int charIndex;
 82         int insertionIndex;
 83         boolean leading;
 84 
 85         public Hit(int charIndex, int insertionIndex, boolean leading) {
 86             this.charIndex = charIndex;
 87             this.insertionIndex = insertionIndex;
 88             this.leading = leading;
 89         }
 90 
 91         public int getCharIndex() { return charIndex; }
 92         public int getInsertionIndex() { return insertionIndex; }
 93         public boolean isLeading() { return leading; }
 94     }
 95 
 96     /**
 97      * Sets the content for the TextLayout. Supports multiple spans (rich text).
 98      *
 99      * @return returns true is the call modifies the layout internal state.
100      */
101     public boolean setContent(TextSpan[] spans);
102 
103     /**
104      * Sets the content for the TextLayout. Shorthand for single span text
105      * (no rich text).
106      *
107      * @return returns true is the call modifies the layout internal state.
108      */
109     public boolean setContent(String string, Object font);
110 
111     /**
112      * Sets the alignment for the TextLayout.
113      *
114      * @return returns true is the call modifies the layout internal state.
115      */
116     public boolean setAlignment(/*TextAlignment*/ int alignment);
117 
118     /**
119      * Sets the wrap width for the TextLayout.
120      *
121      * @return returns true is the call modifies the layout internal state.
122      */
123     public boolean setWrapWidth(float wrapWidth);
124 
125     /**
126      * Sets the line spacing for the TextLayout.
127      *
128      * @return returns true is the call modifies the layout internal state.
129      */
130     public boolean setLineSpacing(float spacing);
131 
132     /**
133      * Sets the direction (bidi algorithm's) for the TextLayout.
134      *
135      * @return returns true is the call modifies the layout internal state.
136      */
137     public boolean setDirection(int direction);
138 
139     /**
140      * Sets the bounds type for the TextLayout.
141      *
142      * @return returns true is the call modifies the layout internal state.
143      */
144     public boolean setBoundsType(int type);
145 
146     /**
147      * Returns the (logical) bounds of the layout
148      * minX is always zero
149      * minY is the ascent of the first line (negative)
150      * width the width of the widest line
151      * height the sum of all lines height
152      *
153      * Note that this width is different the wrapping width!
154      *
155      * @return the layout bounds
156      */
157     public BaseBounds getBounds();
158 
159     public BaseBounds getBounds(TextSpan filter, BaseBounds bounds);
160 
161     /**
162      * Returns the visual bounds of the layout using glyph bounding box
163      *
164      * @return the visual bounds
165      */
166     public BaseBounds getVisualBounds(int type);
167 
168     /**
169      * Returns the lines of text layout.
170      *
171      * @return the text lines
172      */
173     public TextLine[] getLines();
174 
175     /**
176      * Returns the GlyphList of text layout.
177      * The runs are returned order visually (rendering order), starting
178      * from the first line.
179      *
180      * @return the runs
181      */
182     public GlyphList[] getRuns();
183 
184     /**
185      * Returns the shape of the entire text layout relative to the baseline
186      * of the first line.
187      *
188      * @param type the type of the shapes to include
189      * @return the shape
190      */
191     public Shape getShape(int type, TextSpan filter);
192 
193     /**
194      * Sets the tab size for the TextLayout.
195      *
196      * @param spaces the number of spaces represented by a tab. Default is 8.
197      * Minimum is 1, lower values will be clamped to 1.
198      * @return returns true if the call modifies the layout internal state.
199      */
200     public boolean setTabSize(int spaces);
201 
202     public Hit getHitInfo(float x, float y);
203 
204     public PathElement[] getCaretShape(int offset, boolean isLeading,
205                                        float x, float y);
206     public PathElement[] getRange(int start, int end, int type,
207                                   float x, float y);
208 }