Пример #1
0
  /**
   * Synchronize the textLayout and the shape (=frame box, by calling syncFrame) with the model When
   * <code>TextLayout</code> is used, this delegates to <code>getRotation()</code> where computing
   * rotation angle is concerned, and updates the AffineTransform returned by <code>
   * getTextToModelTransform()</code>.
   */
  protected void syncShape() {
    PicText te = (PicText) element;

    //			textLayout = new TextLayout(te.getText().length()==0 ? " " : te.getText(),
    //			    textFont,
    //			    new FontRenderContext(null,false,false));

    text2ModelTr.setToIdentity(); // reset
    PicPoint anchor = te.getCtrlPt(TextEditable.P_ANCHOR, ptBuf);
    text2ModelTr.rotate(getRotation(), anchor.x, anchor.y); // rotate along P_ANCHOR !
    // the reference point of an image is the top-left one, but the refpoint of a text layout is on
    // the baseline
    if (image != null) {
      text2ModelTr.translate(te.getLeftX(), te.getTopY());
      if (te.getWidth() != 0
          && image.getWidth() != 0
          && (te.getDepth() + te.getHeight()) != 0
          && image.getHeight() != 0)
        text2ModelTr.scale(
            te.getWidth() / image.getWidth(),
            -(te.getHeight() + te.getDepth()) / image.getHeight());
    } else {
      // Hack ? Just cheating a little bit ? Ou juste ruse ?
      // we want here to use the dimensions of the textLayout instead of latex dimensions if
      // areDimensionsComputed
      // sinon on va aligner le textlayout en fonction des parametres latex, et l'Utilisateur (qui
      // est bien bete) ne va rien comprendre.
      double latexH = 0;
      double latexD = 0;
      double latexW = 0;
      if (areDimensionsComputed) { // store latex dimensions, and setDimensions to textLayout ones
        latexH = te.getHeight();
        latexD = te.getDepth();
        latexW = te.getWidth();
        te.setDimensions(
            textLayout.getBounds().getWidth(), textLayout.getAscent(), textLayout.getDescent());
      }
      text2ModelTr.translate(te.getLeftX(), te.getBaseLineY());
      if (areDimensionsComputed) { // restore latex dimensions
        te.setDimensions(latexW, latexH, latexD);
      }
      // Autre possibilite= comprimer le texte pour qu'il rentre dans la boite (evite le hack
      // ci-dessus):
      // text2ModelTr.scale(te.getWidth()/textLayout.getWidth(),-(te.getHeight()+te.getDepth())/textLayout.getHeight());
      text2ModelTr.scale(1.0, -1.0);
    }
    syncFrame();
  }
Пример #2
0
 /**
  * update strx stry = location of TextLayout's bottom-Left corner with respect to PicText's
  * anchor-point
  */
 protected void syncStringLocation() {
   PicText te = (PicText) element;
   PicPoint anchor = te.getCtrlPt(TextEditable.P_ANCHOR, ptBuf);
   if (image == null) {
     if (!areDimensionsComputed) {
       te.setDimensions(
           textLayout.getBounds().getWidth(), textLayout.getAscent(), textLayout.getDescent());
     }
     strx = te.getLeftX() - anchor.x;
     stry = te.getBaseLineY() - anchor.y;
   } else { // image not null
     strx = te.getLeftX() - anchor.x;
     stry = te.getBottomY() - anchor.y;
   }
 }
Пример #3
0
  /**
   * Give notification from the model that a change occured to the text this view is responsible for
   * rendering.
   *
   * <p>
   */
  public void changedUpdate(DrawingEvent.EventType eventType) {
    PicText text = (PicText) element;
    if (textLayout == null) {
      // new *************************** begin (by ss & bp)
      textLayout =
          new TextLayout(
              text.getText(text.getTextMode()).length() == 0
                  ? " "
                  : text.getText(text.getTextMode()),
              // new *************************** end (by ss & bp)
              DefaultViewFactory.textFont, // static field
              new FontRenderContext(null, false, false));
    }
    if (eventType == DrawingEvent.EventType.TEXT_CHANGE) {
      // new *************************** begin (by ss & bp)
      textLayout =
          new TextLayout(
              text.getText(text.getTextMode()).length() == 0
                  ? " "
                  : text.getText(text.getTextMode()),
              // new *************************** end (by ss & bp)
              DefaultViewFactory.textFont,
              new FontRenderContext(null, false, false));

      // first try to create a bitmap
      image =
          null; // aka "reset" image => we might temporarily resort to TextLayout until the image is
                // ready
      areDimensionsComputed = false;
      // reset dimensions to the textlayout dimensions
      text.setDimensions(
          textLayout.getBounds().getWidth(), textLayout.getAscent(), textLayout.getDescent());

      // new *************************** begin (by ss & bp)
      if (wantToComputeLatexDimensions && text.getText(text.getTextMode()).length() > 0) {
        // new *************************** end (by ss & bp)
        // don't produce a bitmap for an empty string (LaTeX might not like it)
        // [pending] this should be made dependent on a preference's option
        new Thread(this).start();
      }
      if (image == null) super.changedUpdate(null); // ie resort to TextLayout (update all)
    } else {
      text.updateFrame();
      super.changedUpdate(eventType);
    }
  }
Пример #4
0
  protected void getDimensionsFromLogFile(BufferedReader reader, PicText text) {
    if (reader == null) {
      return;
    }
    String line = ""; // il rale si j'initialise pas ...
    boolean finished = false;
    while (!finished) {
      try {
        line = reader.readLine();
      } catch (IOException ioex) {
        ioex.printStackTrace();
        return;
      }
      if (line == null) {
        System.out.println("Size of text not found in log file...");
        return;
      }

      System.out.println(line);
      Matcher matcher = LogFilePattern.matcher(line);

      if (line != null && matcher.find()) {
        System.out.println("FOUND :" + line);
        finished = true;
        try {
          text.setDimensions(
              0.3515 * Double.parseDouble(matcher.group(1)), // height, pt->mm (1pt=0.3515 mm)
              0.3515 * Double.parseDouble(matcher.group(2)), // width
              0.3515 * Double.parseDouble(matcher.group(3))); // depth
          areDimensionsComputed = true;
        } catch (NumberFormatException e) {
          System.out.println("Logfile number format problem: $line" + e.getMessage());
        } catch (IndexOutOfBoundsException e) {
          System.out.println("Logfile regexp problem: $line" + e.getMessage());
        }
      }
    }
    return;
  }