📄 metado.java
字号:
break; case META_SETTEXTCOLOR: state.setCurrentTextColor(in.readColor()); break; case META_SETTEXTALIGN: state.setTextAlign(in.readWord()); break; case META_SETBKMODE: state.setBackgroundMode(in.readWord()); break; case META_SETPOLYFILLMODE: state.setPolyFillMode(in.readWord()); break; case META_SETPIXEL: { Color color = in.readColor(); int y = in.readShort(); int x = in.readShort(); cb.saveState(); cb.setColorFill(color); cb.rectangle(state.transformX(x), state.transformY(y), .2f, .2f); cb.fill(); cb.restoreState(); break; } case META_DIBSTRETCHBLT: case META_STRETCHDIB: { int rop = in.readInt(); if (function == META_STRETCHDIB) { /*int usage = */ in.readWord(); } int srcHeight = in.readShort(); int srcWidth = in.readShort(); int ySrc = in.readShort(); int xSrc = in.readShort(); float destHeight = state.transformY(in.readShort()) - state.transformY(0); float destWidth = state.transformX(in.readShort()) - state.transformX(0); float yDest = state.transformY(in.readShort()); float xDest = state.transformX(in.readShort()); byte b[] = new byte[(tsize * 2) - (in.getLength() - lenMarker)]; for (int k = 0; k < b.length; ++k) b[k] = (byte)in.readByte(); try { ByteArrayInputStream inb = new ByteArrayInputStream(b); Image bmp = BmpImage.getImage(inb, true, b.length); cb.saveState(); cb.rectangle(xDest, yDest, destWidth, destHeight); cb.clip(); cb.newPath(); bmp.scaleAbsolute(destWidth * bmp.getWidth() / srcWidth, -destHeight * bmp.getHeight() / srcHeight); bmp.setAbsolutePosition(xDest - destWidth * xSrc / srcWidth, yDest + destHeight * ySrc / srcHeight - bmp.getScaledHeight()); cb.addImage(bmp); cb.restoreState(); } catch (Exception e) { // empty on purpose } break; } } in.skip((tsize * 2) - (in.getLength() - lenMarker)); } state.cleanup(cb); } public void outputText(int x, int y, int flag, int x1, int y1, int x2, int y2, String text) { MetaFont font = state.getCurrentFont(); float refX = state.transformX(x); float refY = state.transformY(y); float angle = state.transformAngle(font.getAngle()); float sin = (float)Math.sin(angle); float cos = (float)Math.cos(angle); float fontSize = font.getFontSize(state); BaseFont bf = font.getFont(); int align = state.getTextAlign(); float textWidth = bf.getWidthPoint(text, fontSize); float tx = 0; float ty = 0; float descender = bf.getFontDescriptor(BaseFont.DESCENT, fontSize); float ury = bf.getFontDescriptor(BaseFont.BBOXURY, fontSize); cb.saveState(); cb.concatCTM(cos, sin, -sin, cos, refX, refY); if ((align & MetaState.TA_CENTER) == MetaState.TA_CENTER) tx = -textWidth / 2; else if ((align & MetaState.TA_RIGHT) == MetaState.TA_RIGHT) tx = -textWidth; if ((align & MetaState.TA_BASELINE) == MetaState.TA_BASELINE) ty = 0; else if ((align & MetaState.TA_BOTTOM) == MetaState.TA_BOTTOM) ty = -descender; else ty = -ury; Color textColor; if (state.getBackgroundMode() == MetaState.OPAQUE) { textColor = state.getCurrentBackgroundColor(); cb.setColorFill(textColor); cb.rectangle(tx, ty + descender, textWidth, ury - descender); cb.fill(); } textColor = state.getCurrentTextColor(); cb.setColorFill(textColor); cb.beginText(); cb.setFontAndSize(bf, fontSize); cb.setTextMatrix(tx, ty); cb.showText(text); cb.endText(); if (font.isUnderline()) { cb.rectangle(tx, ty - fontSize / 4, textWidth, fontSize / 15); cb.fill(); } if (font.isStrikeout()) { cb.rectangle(tx, ty + fontSize / 3, textWidth, fontSize / 15); cb.fill(); } cb.restoreState(); } public boolean isNullStrokeFill(boolean isRectangle) { MetaPen pen = state.getCurrentPen(); MetaBrush brush = state.getCurrentBrush(); boolean noPen = (pen.getStyle() == MetaPen.PS_NULL); int style = brush.getStyle(); boolean isBrush = (style == MetaBrush.BS_SOLID || (style == MetaBrush.BS_HATCHED && state.getBackgroundMode() == MetaState.OPAQUE)); boolean result = noPen && !isBrush; if (!noPen) { if (isRectangle) state.setLineJoinRectangle(cb); else state.setLineJoinPolygon(cb); } return result; } public void strokeAndFill(){ MetaPen pen = state.getCurrentPen(); MetaBrush brush = state.getCurrentBrush(); int penStyle = pen.getStyle(); int brushStyle = brush.getStyle(); if (penStyle == MetaPen.PS_NULL) { cb.closePath(); if (state.getPolyFillMode() == MetaState.ALTERNATE) { cb.eoFill(); } else { cb.fill(); } } else { boolean isBrush = (brushStyle == MetaBrush.BS_SOLID || (brushStyle == MetaBrush.BS_HATCHED && state.getBackgroundMode() == MetaState.OPAQUE)); if (isBrush) { if (state.getPolyFillMode() == MetaState.ALTERNATE) cb.closePathEoFillStroke(); else cb.closePathFillStroke(); } else { cb.closePathStroke(); } } } static float getArc(float xCenter, float yCenter, float xDot, float yDot) { double s = Math.atan2(yDot - yCenter, xDot - xCenter); if (s < 0) s += Math.PI * 2; return (float)(s / Math.PI * 180); } public static byte[] wrapBMP(Image image) throws IOException { if (image.getOriginalType() != Image.ORIGINAL_BMP) throw new IOException("Only BMP can be wrapped in WMF."); InputStream imgIn; byte data[] = null; if (image.getOriginalData() == null) { imgIn = image.getUrl().openStream(); ByteArrayOutputStream out = new ByteArrayOutputStream(); int b = 0; while ((b = imgIn.read()) != -1) out.write(b); imgIn.close(); data = out.toByteArray(); } else data = image.getOriginalData(); int sizeBmpWords = (data.length - 14 + 1) >>> 1; ByteArrayOutputStream os = new ByteArrayOutputStream(); // write metafile header writeWord(os, 1); writeWord(os, 9); writeWord(os, 0x0300); writeDWord(os, 9 + 4 + 5 + 5 + (13 + sizeBmpWords) + 3); // total metafile size writeWord(os, 1); writeDWord(os, 14 + sizeBmpWords); // max record size writeWord(os, 0); // write records writeDWord(os, 4); writeWord(os, META_SETMAPMODE); writeWord(os, 8); writeDWord(os, 5); writeWord(os, META_SETWINDOWORG); writeWord(os, 0); writeWord(os, 0); writeDWord(os, 5); writeWord(os, META_SETWINDOWEXT); writeWord(os, (int)image.getHeight()); writeWord(os, (int)image.getWidth()); writeDWord(os, 13 + sizeBmpWords); writeWord(os, META_DIBSTRETCHBLT); writeDWord(os, 0x00cc0020); writeWord(os, (int)image.getHeight()); writeWord(os, (int)image.getWidth()); writeWord(os, 0); writeWord(os, 0); writeWord(os, (int)image.getHeight()); writeWord(os, (int)image.getWidth()); writeWord(os, 0); writeWord(os, 0); os.write(data, 14, data.length - 14); if ((data.length & 1) == 1) os.write(0);// writeDWord(os, 14 + sizeBmpWords);// writeWord(os, META_STRETCHDIB);// writeDWord(os, 0x00cc0020);// writeWord(os, 0);// writeWord(os, (int)image.height());// writeWord(os, (int)image.width());// writeWord(os, 0);// writeWord(os, 0);// writeWord(os, (int)image.height());// writeWord(os, (int)image.width());// writeWord(os, 0);// writeWord(os, 0);// os.write(data, 14, data.length - 14);// if ((data.length & 1) == 1)// os.write(0); writeDWord(os, 3); writeWord(os, 0); os.close(); return os.toByteArray(); } public static void writeWord(OutputStream os, int v) throws IOException { os.write(v & 0xff); os.write((v >>> 8) & 0xff); } public static void writeDWord(OutputStream os, int v) throws IOException { writeWord(os, v & 0xffff); writeWord(os, (v >>> 16) & 0xffff); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -