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
 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     public static class Hit {
 79         int charIndex;
 80         int insertionIndex;
 81         boolean leading;
 82 
 83         public Hit(int charIndex, int insertionIndex, boolean leading) {
 84             this.charIndex = charIndex;
 85             this.insertionIndex = insertionIndex;
 86             this.leading = leading;
 87         }
 88 
 89         public int getCharIndex() { return charIndex; }
 90         public int getInsertionIndex() { return insertionIndex; }
 91         public boolean isLeading() { return leading; }
 92     }
 93 
 94     /**
 95      * Sets the content for the TextLayout. Supports multiple spans (rich text).
 96      *
 97      * @return returns true is the call modifies the layout internal state.
 98      */
 99     public boolean setContent(TextSpan[] spans);
100 
101     /**
102      * Sets the content for the TextLayout. Shorthand for single span text
103      * (no rich text).
104      *
105      * @return returns true is the call modifies the layout internal state.
106      */
107     public boolean setContent(String string, Object font);
108 
109     /**
110      * Sets the alignment for the TextLayout.
111      *
112      * @return returns true is the call modifies the layout internal state.
113      */
114     public boolean setAlignment(/*TextAlignment*/ int alignment);
115 
116     /**
117      * Sets the wrap width for the TextLayout.
118      *
119      * @return returns true is the call modifies the layout internal state.
120      */
121     public boolean setWrapWidth(float wrapWidth);
122 
123     /**
124      * Sets the line spacing for the TextLayout.
125      *
126      * @return returns true is the call modifies the layout internal state.
127      */
128     public boolean setLineSpacing(float spacing);
129 
130     /**
131      * Sets the direction (bidi algorithm's) for the TextLayout.
132      *
133      * @return returns true is the call modifies the layout internal state.
134      */
135     public boolean setDirection(int direction);
136 
137     /**
138      * Sets the bounds type for the TextLayout.
139      *
140      * @return returns true is the call modifies the layout internal state.
141      */
142     public boolean setBoundsType(int type);
143 
144     /**
145      * Returns the (logical) bounds of the layout
146      * minX is always zero
147      * minY is the ascent of the first line (negative)
148      * width the width of the widest line
149      * height the sum of all lines height
150      *
151      * Note that this width is different the wrapping width!
152      *
153      * @return the layout bounds
154      */
155     public BaseBounds getBounds();
156 
157     public BaseBounds getBounds(TextSpan filter, BaseBounds bounds);
158 
159     /**
160      * Returns the visual bounds of the layout using glyph bounding box
161      *
162      * @return the visual bounds
163      */
164     public BaseBounds getVisualBounds(int type);
165 
166     /**
167      * Returns the lines of text layout.
168      *
169      * @return the text lines
170      */
171     public TextLine[] getLines();
172 
173     /**
174      * Returns the GlyphList of text layout.
175      * The runs are returned order visually (rendering order), starting
176      * from the first line.
177      *
178      * @return the runs
179      */
180     public GlyphList[] getRuns();
181 
182     /**
183      * Returns the shape of the entire text layout relative to the baseline
184      * of the first line.
185      *
186      * @param type the type of the shapes to include
187      * @return the shape
188      */
189     public Shape getShape(int type, TextSpan filter);
190 
191     public Hit getHitInfo(float x, float y);
192 
193     public PathElement[] getCaretShape(int offset, boolean isLeading,
194                                        float x, float y);
195     public PathElement[] getRange(int start, int end, int type,
196                                   float x, float y);
197 }