Exemplo n.º 1
0
 /**
  * Determines the model location that represents the maximum advance that fits within the given
  * span. This could be used to break the given view. The result should be a location just shy of
  * the given advance. This differs from viewToModel which returns the closest position which might
  * be proud of the maximum advance.
  *
  * @param v the view to find the model location to break at.
  * @param p0 the location in the model where the fragment should start it's representation >= 0.
  * @param pos the graphic location along the axis that the broken view would occupy >= 0. This may
  *     be useful for things like tab calculations.
  * @param len specifies the distance into the view where a potential break is desired >= 0.
  * @return the maximum model location possible for a break.
  * @see View#breakView
  */
 public int getBoundedPosition(GlyphView v, int p0, float x, float len) {
   if (len < 0) throw new IllegalArgumentException("Length must be >= 0.");
   // note: this only works because swing uses TextLayouts that are
   // only pure rtl or pure ltr
   TextHitInfo hit;
   if (layout.isLeftToRight()) {
     hit = layout.hitTestChar(len, 0);
   } else {
     hit = layout.hitTestChar(layout.getAdvance() - len, 0);
   }
   return v.getStartOffset() + hit.getCharIndex();
 }