< prev index next >

src/java.desktop/share/classes/javax/swing/text/GlyphPainter2.java

Print this page




 140         int offs = pos - v.getStartOffset();
 141         Rectangle2D alloc = a.getBounds2D();
 142         TextHitInfo hit = (bias == Position.Bias.Forward) ?
 143             TextHitInfo.afterOffset(offs) : TextHitInfo.beforeOffset(offs);
 144         float[] locs = layout.getCaretInfo(hit);
 145 
 146         // vertical at the baseline, should use slope and check if glyphs
 147         // are being rendered vertically.
 148         alloc.setRect(alloc.getX() + locs[0], alloc.getY(), 1, alloc.getHeight());
 149         return alloc;
 150     }
 151 
 152     /**
 153      * Provides a mapping from the view coordinate space to the logical
 154      * coordinate space of the model.
 155      *
 156      * @param v the view containing the view coordinates
 157      * @param x the X coordinate
 158      * @param y the Y coordinate
 159      * @param a the allocated region to render into
 160      * @param biasReturn either <code>Position.Bias.Forward</code>
 161      *  or <code>Position.Bias.Backward</code> is returned as the
 162      *  zero-th element of this array
 163      * @return the location within the model that best represents the
 164      *  given point of view
 165      * @see View#viewToModel
 166      */
 167     public int viewToModel(GlyphView v, float x, float y, Shape a,
 168                            Position.Bias[] biasReturn) {
 169 
 170         Rectangle2D alloc = (a instanceof Rectangle2D) ? (Rectangle2D)a : a.getBounds2D();
 171         //Move the y co-ord of the hit onto the baseline.  This is because TextLayout supports
 172         //italic carets and we do not.
 173         TextHitInfo hit = layout.hitTestChar(x - (float)alloc.getX(), 0);
 174         int pos = hit.getInsertionIndex();
 175 
 176         if (pos == v.getEndOffset()) {
 177             pos--;
 178         }
 179 
 180         biasReturn[0] = hit.isLeadingEdge() ? Position.Bias.Forward : Position.Bias.Backward;
 181         return pos + v.getStartOffset();




 140         int offs = pos - v.getStartOffset();
 141         Rectangle2D alloc = a.getBounds2D();
 142         TextHitInfo hit = (bias == Position.Bias.Forward) ?
 143             TextHitInfo.afterOffset(offs) : TextHitInfo.beforeOffset(offs);
 144         float[] locs = layout.getCaretInfo(hit);
 145 
 146         // vertical at the baseline, should use slope and check if glyphs
 147         // are being rendered vertically.
 148         alloc.setRect(alloc.getX() + locs[0], alloc.getY(), 1, alloc.getHeight());
 149         return alloc;
 150     }
 151 
 152     /**
 153      * Provides a mapping from the view coordinate space to the logical
 154      * coordinate space of the model.
 155      *
 156      * @param v the view containing the view coordinates
 157      * @param x the X coordinate
 158      * @param y the Y coordinate
 159      * @param a the allocated region to render into
 160      * @param biasReturn either {@code Position.Bias.Forward}
 161      *  or {@code Position.Bias.Backward} is returned as the
 162      *  zero-th element of this array
 163      * @return the location within the model that best represents the
 164      *  given point of view
 165      * @see View#viewToModel
 166      */
 167     public int viewToModel(GlyphView v, float x, float y, Shape a,
 168                            Position.Bias[] biasReturn) {
 169 
 170         Rectangle2D alloc = (a instanceof Rectangle2D) ? (Rectangle2D)a : a.getBounds2D();
 171         //Move the y co-ord of the hit onto the baseline.  This is because TextLayout supports
 172         //italic carets and we do not.
 173         TextHitInfo hit = layout.hitTestChar(x - (float)alloc.getX(), 0);
 174         int pos = hit.getInsertionIndex();
 175 
 176         if (pos == v.getEndOffset()) {
 177             pos--;
 178         }
 179 
 180         biasReturn[0] = hit.isLeadingEdge() ? Position.Bias.Forward : Position.Bias.Backward;
 181         return pos + v.getStartOffset();


< prev index next >