textshape.java
来自「EXCEL read and write」· Java 代码 · 共 578 行 · 第 1/2 页
JAVA
578 行
} } else { valign = prop.getPropertyValue(); } return valign; } /** * Sets the type of vertical alignment for the text. * One of the <code>Anchor*</code> constants defined in this class. * * @param align - the type of alignment */ public void setVerticalAlignment(int align){ setEscherProperty(EscherProperties.TEXT__ANCHORTEXT, align); } /** * Sets the type of horizontal alignment for the text. * One of the <code>Align*</code> constants defined in this class. * * @param align - the type of horizontal alignment */ public void setHorizontalAlignment(int align){ TextRun tx = getTextRun(); if(tx != null) tx.getRichTextRuns()[0].setAlignment(align); } /** * Gets the type of horizontal alignment for the text. * One of the <code>Align*</code> constants defined in this class. * * @return align - the type of horizontal alignment */ public int getHorizontalAlignment(){ TextRun tx = getTextRun(); return tx == null ? -1 : tx.getRichTextRuns()[0].getAlignment(); } /** * Returns the distance (in points) between the bottom of the text frame * and the bottom of the inscribed rectangle of the shape that contains the text. * Default value is 1/20 inch. * * @return the botom margin */ public float getMarginBottom(){ EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID); EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.TEXT__TEXTBOTTOM); int val = prop == null ? EMU_PER_INCH/20 : prop.getPropertyValue(); return (float)val/EMU_PER_POINT; } /** * Sets the botom margin. * @see #getMarginBottom() * * @param margin the bottom margin */ public void setMarginBottom(float margin){ setEscherProperty(EscherProperties.TEXT__TEXTBOTTOM, (int)(margin*EMU_PER_POINT)); } /** * Returns the distance (in points) between the left edge of the text frame * and the left edge of the inscribed rectangle of the shape that contains * the text. * Default value is 1/10 inch. * * @return the left margin */ public float getMarginLeft(){ EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID); EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.TEXT__TEXTLEFT); int val = prop == null ? EMU_PER_INCH/10 : prop.getPropertyValue(); return (float)val/EMU_PER_POINT; } /** * Sets the left margin. * @see #getMarginLeft() * * @param margin the left margin */ public void setMarginLeft(float margin){ setEscherProperty(EscherProperties.TEXT__TEXTLEFT, (int)(margin*EMU_PER_POINT)); } /** * Returns the distance (in points) between the right edge of the * text frame and the right edge of the inscribed rectangle of the shape * that contains the text. * Default value is 1/10 inch. * * @return the right margin */ public float getMarginRight(){ EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID); EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.TEXT__TEXTRIGHT); int val = prop == null ? EMU_PER_INCH/10 : prop.getPropertyValue(); return (float)val/EMU_PER_POINT; } /** * Sets the right margin. * @see #getMarginRight() * * @param margin the right margin */ public void setMarginRight(float margin){ setEscherProperty(EscherProperties.TEXT__TEXTRIGHT, (int)(margin*EMU_PER_POINT)); } /** * Returns the distance (in points) between the top of the text frame * and the top of the inscribed rectangle of the shape that contains the text. * Default value is 1/20 inch. * * @return the top margin */ public float getMarginTop(){ EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID); EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.TEXT__TEXTTOP); int val = prop == null ? EMU_PER_INCH/20 : prop.getPropertyValue(); return (float)val/EMU_PER_POINT; } /** * Sets the top margin. * @see #getMarginTop() * * @param margin the top margin */ public void setMarginTop(float margin){ setEscherProperty(EscherProperties.TEXT__TEXTTOP, (int)(margin*EMU_PER_POINT)); } /** * Returns the value indicating word wrap. * * @return the value indicating word wrap. * Must be one of the <code>Wrap*</code> constants defined in this class. */ public int getWordWrap(){ EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID); EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.TEXT__WRAPTEXT); return prop == null ? WrapSquare : prop.getPropertyValue(); } /** * Specifies how the text should be wrapped * * @param wrap the value indicating how the text should be wrapped. * Must be one of the <code>Wrap*</code> constants defined in this class. */ public void setWordWrap(int wrap){ setEscherProperty(EscherProperties.TEXT__WRAPTEXT, wrap); } /** * @return id for the text. */ public int getTextId(){ EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID); EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.TEXT__TEXTID); return prop == null ? 0 : prop.getPropertyValue(); } /** * Sets text ID * * @param id of the text */ public void setTextId(int id){ setEscherProperty(EscherProperties.TEXT__TEXTID, id); } /** * @return the TextRun object for this text box */ public TextRun getTextRun(){ if(_txtrun == null) initTextRun(); return _txtrun; } public void setSheet(Sheet sheet) { _sheet = sheet; // Initialize _txtrun object. // (We can't do it in the constructor because the sheet // is not assigned then, it's only built once we have // all the records) TextRun tx = getTextRun(); if (tx != null) { // Supply the sheet to our child RichTextRuns tx.setSheet(_sheet); RichTextRun[] rt = tx.getRichTextRuns(); for (int i = 0; i < rt.length; i++) { rt[i].supplySlideShow(_sheet.getSlideShow()); } } } protected void initTextRun(){ EscherTextboxWrapper txtbox = getEscherTextboxWrapper(); Sheet sheet = getSheet(); if(sheet == null || txtbox == null) return; OutlineTextRefAtom ota = null; Record[] child = txtbox.getChildRecords(); for (int i = 0; i < child.length; i++) { if (child[i] instanceof OutlineTextRefAtom) { ota = (OutlineTextRefAtom)child[i]; break; } } TextRun[] runs = _sheet.getTextRuns(); if (ota != null) { int idx = ota.getTextIndex(); for (int i = 0; i < runs.length; i++) { if(runs[i].getIndex() == idx){ _txtrun = runs[i]; break; } } if(_txtrun == null) { logger.log(POILogger.WARN, "text run not found for OutlineTextRefAtom.TextIndex=" + idx); } } else { int shapeId = _escherContainer.getChildById(EscherSpRecord.RECORD_ID).getShapeId(); if(runs != null) for (int i = 0; i < runs.length; i++) { if(runs[i].getShapeId() == shapeId){ _txtrun = runs[i]; break; } } } } public void draw(Graphics2D graphics){ AffineTransform at = graphics.getTransform(); ShapePainter.paint(this, graphics); new TextPainter(this).paint(graphics); graphics.setTransform(at); } /** * Return <code>OEPlaceholderAtom</code>, the atom that describes a placeholder. * * @return <code>OEPlaceholderAtom</code> or <code>null</code> if not found */ public OEPlaceholderAtom getPlaceholderAtom(){ return (OEPlaceholderAtom)getClientDataRecord(RecordTypes.OEPlaceholderAtom.typeID); } /** * * Assigns a hyperlink to this text shape * * @param linkId id of the hyperlink, @see org.apache.poi.hslf.usermodel.SlideShow#addHyperlink(Hyperlink) * @param beginIndex the beginning index, inclusive. * @param endIndex the ending index, exclusive. * @see org.apache.poi.hslf.usermodel.SlideShow#addHyperlink(Hyperlink) */ public void setHyperlink(int linkId, int beginIndex, int endIndex){ //TODO validate beginIndex and endIndex and throw IllegalArgumentException InteractiveInfo info = new InteractiveInfo(); InteractiveInfoAtom infoAtom = info.getInteractiveInfoAtom(); infoAtom.setAction(InteractiveInfoAtom.ACTION_HYPERLINK); infoAtom.setHyperlinkType(InteractiveInfoAtom.LINK_Url); infoAtom.setHyperlinkID(linkId); _txtbox.appendChildRecord(info); TxInteractiveInfoAtom txiatom = new TxInteractiveInfoAtom(); txiatom.setStartIndex(beginIndex); txiatom.setEndIndex(endIndex); _txtbox.appendChildRecord(txiatom); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?