pgraphicspdf.java

来自「This is processing for java examples.」· Java 代码 · 共 620 行 · 第 1/2 页

JAVA
620
字号
   * Change the textMode() to either SHAPE or MODEL.   * <br/>   * This resets all renderer settings, and should therefore   * be called <EM>before</EM> any other commands that set the fill()   * or the textFont() or anything. Unlike other renderers,   * use textMode() directly after the size() command.   */  public void textMode(int mode) {    if (textMode != mode) {      if (mode == SHAPE) {        g2.dispose();        g2 = content.createGraphicsShapes(width, height);      } else if (mode == MODEL) {        g2.dispose();        g2 = content.createGraphics(width, height, mapper);//        g2 = template.createGraphics(width, height, mapper);      } else if (mode == SCREEN) {        throw new RuntimeException("textMode(SCREEN) not supported with PDF");      } else {        throw new RuntimeException("That textMode() does not exist");      }    }  }  /**   * Call to explicitly go to the next page from within a single draw().   */  public void nextPage() {	  PStyle savedStyle = getStyle();    g2.dispose();        try {//    writer.setPageEmpty(false);  // maybe useful later      document.newPage();  // is this bad if no addl pages are made?    } catch (Exception e) {      e.printStackTrace();    }    if (textMode == SHAPE) {      g2 = content.createGraphicsShapes(width, height);    } else if (textMode == MODEL) {      g2 = content.createGraphics(width, height, mapper);    }    style(savedStyle);    // should there be a beginDraw/endDraw in here?  }  public void dispose() {    if (document != null) {      g2.dispose();      document.close();  // can't be done in finalize, not always called      document = null;    }    //new Exception().printStackTrace(System.out);  }  /**   * Don't open a window for this renderer, it won't be used.   */  public boolean displayable() {    return false;  }  /*  protected void finalize() throws Throwable {    System.out.println("calling finalize");  //document.close();  // do this in dispose instead?  }  */  //////////////////////////////////////////////////////////////  /*  public void endRecord() {    super.endRecord();    dispose();  }  public void endRaw() {    System.out.println("ending raw");    super.endRaw();    System.out.println("disposing");    dispose();    System.out.println("done");  }  */  //////////////////////////////////////////////////////////////  /*  protected void rectImpl(float x1, float y1, float x2, float y2) {    //rect.setFrame(x1, y1, x2-x1, y2-y1);    //draw_shape(rect);    System.out.println("rect implements");    g2.fillRect((int)x1, (int)y1, (int) (x2-x1), (int) (y2-y1));  }  *  /*  public void clear() {    g2.setColor(Color.red);    g2.fillRect(0, 0, width, height);  }  */  //////////////////////////////////////////////////////////////  /*  protected void imageImplAWT(java.awt.Image awtImage,                              float x1, float y1, float x2, float y2,                              int u1, int v1, int u2, int v2) {    pushMatrix();    translate(x1, y1);    int awtImageWidth = awtImage.getWidth(null);    int awtImageHeight = awtImage.getHeight(null);    scale((x2 - x1) / (float)awtImageWidth,          (y2 - y1) / (float)awtImageHeight);    g2.drawImage(awtImage,                 0, 0, awtImageWidth, awtImageHeight,                 u1, v1, u2, v2, null);    popMatrix();  }  */  //////////////////////////////////////////////////////////////  public void loadPixels() {    nope("loadPixels");  }  public void updatePixels() {    nope("updatePixels");  }  public void updatePixels(int x, int y, int c, int d) {    nope("updatePixels");  }  //  public int get(int x, int y) {    nope("get");    return 0;  // not reached  }  public PImage get(int x, int y, int c, int d) {    nope("get");    return null;  // not reached  }  public PImage get() {    nope("get");    return null;  // not reached  }  public void set(int x, int y, int argb) {    nope("set");  }  public void set(int x, int y, PImage image) {    nope("set");  }  //  public void mask(int alpha[]) {    nope("mask");  }  public void mask(PImage alpha) {    nope("mask");  }  //  public void filter(int kind) {    nope("filter");  }  public void filter(int kind, float param) {    nope("filter");  }  //  public void copy(int sx1, int sy1, int sx2, int sy2,                   int dx1, int dy1, int dx2, int dy2) {    nope("copy");  }  public void copy(PImage src,                   int sx1, int sy1, int sx2, int sy2,                   int dx1, int dy1, int dx2, int dy2) {    nope("copy");  }  //  public void blend(int sx, int sy, int dx, int dy, int mode) {    nope("blend");  }  public void blend(PImage src,                    int sx, int sy, int dx, int dy, int mode) {    nope("blend");  }  public void blend(int sx1, int sy1, int sx2, int sy2,                    int dx1, int dy1, int dx2, int dy2, int mode) {    nope("blend");  }  public void blend(PImage src,                    int sx1, int sy1, int sx2, int sy2,                    int dx1, int dy1, int dx2, int dy2, int mode) {    nope("blend");  }  //  public void save(String filename) {    nope("save");  }  //////////////////////////////////////////////////////////////  /**   * Add a directory that should be searched for font data.   * <br/>   * On Mac OS X, the following directories are added by default:   * <UL>   * <LI>/System/Library/Fonts   * <LI>/Library/Fonts   * <LI>~/Library/Fonts   * </UL>   * On Windows, all drive letters are searched for WINDOWS\Fonts   * or WINNT\Fonts, any that exists is added.   * <br/><br/>   * On Linux or any other platform, you'll need to add the   * directories by hand. (If there are actual standards here that we   * can use as a starting point, please file a bug to make a note of it)   */  public void addFonts(String directory) {    mapper.insertDirectory(directory);  }  /**   * List the fonts known to the PDF renderer. This is like PFont.list(),   * however not all those fonts are available by default.   */  public String[] listFonts() {     /*      //System.out.println("list of fonts");      HashMap map = mapper.getAliases();      //KeySet keys = map.keySet();      Set entries = map.entrySet();      Iterator it = entries.iterator();      while (it.hasNext()) {        Map.Entry entry = (Map.Entry) it.next();        System.out.println(entry.getKey() + "-->" + entry.getValue());      }     */     /*    HashMap map = mapper.getAliases();    KeySet keys = map.keySet();    Iterator it = entries.iterator();    while (it.hasNext()) {      Map.Entry entry = (Map.Entry) it.next();      System.out.println(entry.getKey() + "-->" + entry.getValue());    }     */    HashMap map = mapper.getAliases();    Set entries = map.entrySet();    String list[] = new String[entries.size()];    Iterator it = entries.iterator();    int count = 0;    while (it.hasNext()) {      Map.Entry entry = (Map.Entry) it.next();      //System.out.println(entry.getKey() + "-->" + entry.getValue());      list[count++] = (String) entry.getKey();    }    return PApplet.sort(list);  }  //////////////////////////////////////////////////////////////  protected void nope(String function) {    throw new RuntimeException("No " + function + "() for PGraphicsPDF");  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?