2004-04-09 13:05:39 +00:00
|
|
|
/* ====================================================================
|
2006-12-22 19:18:16 +00:00
|
|
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
|
contributor license agreements. See the NOTICE file distributed with
|
|
|
|
|
this work for additional information regarding copyright ownership.
|
|
|
|
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
|
|
|
|
(the "License"); you may not use this file except in compliance with
|
|
|
|
|
the License. You may obtain a copy of the License at
|
2004-04-09 13:05:39 +00:00
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
|
limitations under the License.
|
|
|
|
|
==================================================================== */
|
2004-08-23 08:52:54 +00:00
|
|
|
|
2004-04-09 11:45:38 +00:00
|
|
|
package org.apache.poi.hssf.usermodel;
|
|
|
|
|
|
2012-06-26 11:21:13 +00:00
|
|
|
import org.apache.poi.ddf.*;
|
|
|
|
|
import org.apache.poi.hssf.record.*;
|
2008-01-24 10:10:55 +00:00
|
|
|
import org.apache.poi.ss.usermodel.RichTextString;
|
|
|
|
|
|
2004-04-09 11:45:38 +00:00
|
|
|
/**
|
|
|
|
|
* A textbox is a shape that may hold a rich text string.
|
|
|
|
|
*
|
|
|
|
|
* @author Glen Stampoultzis (glens at apache.org)
|
|
|
|
|
*/
|
2012-06-26 11:21:13 +00:00
|
|
|
public class HSSFTextbox extends HSSFSimpleShape {
|
|
|
|
|
public final static short OBJECT_TYPE_TEXT = 6;
|
2004-04-09 11:45:38 +00:00
|
|
|
|
2008-03-29 16:41:25 +00:00
|
|
|
/**
|
|
|
|
|
* How to align text horizontally
|
|
|
|
|
*/
|
2012-06-26 11:21:13 +00:00
|
|
|
public final static short HORIZONTAL_ALIGNMENT_LEFT = 1;
|
|
|
|
|
public final static short HORIZONTAL_ALIGNMENT_CENTERED = 2;
|
|
|
|
|
public final static short HORIZONTAL_ALIGNMENT_RIGHT = 3;
|
|
|
|
|
public final static short HORIZONTAL_ALIGNMENT_JUSTIFIED = 4;
|
|
|
|
|
public final static short HORIZONTAL_ALIGNMENT_DISTRIBUTED = 7;
|
2008-03-29 16:41:25 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* How to align text vertically
|
|
|
|
|
*/
|
2012-06-26 11:21:13 +00:00
|
|
|
public final static short VERTICAL_ALIGNMENT_TOP = 1;
|
|
|
|
|
public final static short VERTICAL_ALIGNMENT_CENTER = 2;
|
|
|
|
|
public final static short VERTICAL_ALIGNMENT_BOTTOM = 3;
|
|
|
|
|
public final static short VERTICAL_ALIGNMENT_JUSTIFY = 4;
|
|
|
|
|
public final static short VERTICAL_ALIGNMENT_DISTRIBUTED = 7;
|
2008-03-29 16:41:25 +00:00
|
|
|
|
2012-06-26 11:21:13 +00:00
|
|
|
public HSSFTextbox(EscherContainerRecord spContainer, ObjRecord objRecord, TextObjectRecord textObjectRecord) {
|
2012-07-11 12:08:38 +00:00
|
|
|
super(spContainer, objRecord, textObjectRecord);
|
2012-06-26 11:21:13 +00:00
|
|
|
}
|
|
|
|
|
|
2004-04-09 11:45:38 +00:00
|
|
|
HSSFRichTextString string = new HSSFRichTextString("");
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Construct a new textbox with the given parent and anchor.
|
2012-06-26 11:21:13 +00:00
|
|
|
*
|
2004-04-09 11:45:38 +00:00
|
|
|
* @param parent
|
2012-06-26 11:21:13 +00:00
|
|
|
* @param anchor One of HSSFClientAnchor or HSSFChildAnchor
|
2004-04-09 11:45:38 +00:00
|
|
|
*/
|
2012-06-26 11:21:13 +00:00
|
|
|
public HSSFTextbox(HSSFShape parent, HSSFAnchor anchor) {
|
|
|
|
|
super(parent, anchor);
|
|
|
|
|
setHorizontalAlignment(HORIZONTAL_ALIGNMENT_LEFT);
|
|
|
|
|
setVerticalAlignment(VERTICAL_ALIGNMENT_TOP);
|
|
|
|
|
setString(new HSSFRichTextString(""));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected ObjRecord createObjRecord() {
|
|
|
|
|
ObjRecord obj = new ObjRecord();
|
|
|
|
|
CommonObjectDataSubRecord c = new CommonObjectDataSubRecord();
|
2012-07-11 12:08:38 +00:00
|
|
|
c.setObjectType(HSSFTextbox.OBJECT_TYPE_TEXT);
|
2012-06-26 11:21:13 +00:00
|
|
|
c.setLocked( true );
|
|
|
|
|
c.setPrintable( true );
|
|
|
|
|
c.setAutofill( true );
|
|
|
|
|
c.setAutoline( true );
|
|
|
|
|
EndSubRecord e = new EndSubRecord();
|
|
|
|
|
obj.addSubRecord( c );
|
|
|
|
|
obj.addSubRecord( e );
|
2012-07-11 12:08:38 +00:00
|
|
|
return obj; }
|
2012-06-26 11:21:13 +00:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected EscherContainerRecord createSpContainer() {
|
|
|
|
|
EscherContainerRecord spContainer = new EscherContainerRecord();
|
|
|
|
|
EscherSpRecord sp = new EscherSpRecord();
|
|
|
|
|
EscherOptRecord opt = new EscherOptRecord();
|
|
|
|
|
EscherClientDataRecord clientData = new EscherClientDataRecord();
|
|
|
|
|
EscherTextboxRecord escherTextbox = new EscherTextboxRecord();
|
|
|
|
|
|
|
|
|
|
spContainer.setRecordId(EscherContainerRecord.SP_CONTAINER);
|
|
|
|
|
spContainer.setOptions((short) 0x000F);
|
|
|
|
|
sp.setRecordId(EscherSpRecord.RECORD_ID);
|
|
|
|
|
sp.setOptions((short) ((EscherAggregate.ST_TEXTBOX << 4) | 0x2));
|
2008-03-29 16:41:25 +00:00
|
|
|
|
2012-06-26 11:21:13 +00:00
|
|
|
sp.setFlags(EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE);
|
|
|
|
|
opt.setRecordId(EscherOptRecord.RECORD_ID);
|
|
|
|
|
opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.TEXT__TEXTID, 0));
|
|
|
|
|
opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.TEXT__WRAPTEXT, 0));
|
|
|
|
|
opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.TEXT__ANCHORTEXT, 0));
|
|
|
|
|
opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GROUPSHAPE__PRINT, 0x00080000));
|
|
|
|
|
|
2012-06-28 10:56:55 +00:00
|
|
|
opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.TEXT__TEXTLEFT, 0));
|
|
|
|
|
opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.TEXT__TEXTRIGHT, 0));
|
|
|
|
|
opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.TEXT__TEXTTOP, 0));
|
|
|
|
|
opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.TEXT__TEXTBOTTOM, 0));
|
|
|
|
|
|
2012-07-01 09:38:08 +00:00
|
|
|
opt.setEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__LINEDASHING, LINESTYLE_SOLID));
|
2012-07-06 17:00:20 +00:00
|
|
|
opt.setEscherProperty( new EscherBoolProperty( EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x00080008));
|
2012-07-01 09:38:08 +00:00
|
|
|
opt.setEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__LINEWIDTH, LINEWIDTH_DEFAULT));
|
|
|
|
|
opt.setEscherProperty(new EscherRGBProperty(EscherProperties.FILL__FILLCOLOR, FILL__FILLCOLOR_DEFAULT));
|
|
|
|
|
opt.setEscherProperty(new EscherRGBProperty(EscherProperties.LINESTYLE__COLOR, LINESTYLE__COLOR_DEFAULT));
|
2012-07-11 12:08:38 +00:00
|
|
|
opt.setEscherProperty(new EscherBoolProperty(EscherProperties.FILL__NOFILLHITTEST, NO_FILLHITTEST_FALSE));
|
2012-07-06 17:00:20 +00:00
|
|
|
opt.setEscherProperty(new EscherBoolProperty( EscherProperties.GROUPSHAPE__PRINT, 0x080000));
|
2012-06-28 10:56:55 +00:00
|
|
|
|
2012-06-26 11:21:13 +00:00
|
|
|
EscherRecord anchor = getAnchor().getEscherAnchor();
|
|
|
|
|
clientData.setRecordId(EscherClientDataRecord.RECORD_ID);
|
|
|
|
|
clientData.setOptions((short) 0x0000);
|
|
|
|
|
escherTextbox.setRecordId(EscherTextboxRecord.RECORD_ID);
|
|
|
|
|
escherTextbox.setOptions((short) 0x0000);
|
|
|
|
|
|
|
|
|
|
spContainer.addChildRecord(sp);
|
|
|
|
|
spContainer.addChildRecord(opt);
|
|
|
|
|
spContainer.addChildRecord(anchor);
|
|
|
|
|
spContainer.addChildRecord(clientData);
|
|
|
|
|
spContainer.addChildRecord(escherTextbox);
|
|
|
|
|
|
|
|
|
|
return spContainer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setString(RichTextString string) {
|
|
|
|
|
HSSFRichTextString rtr = (HSSFRichTextString) string;
|
Merged revisions 638786-638802,638805-638811,638813-638814,638816-639230,639233-639241,639243-639253,639255-639486,639488-639601,639603-639835,639837-639917,639919-640056,640058-640710,640712-641156,641158-641184,641186-641795,641797-641798,641800-641933,641935-641963,641965-641966,641968-641995,641997-642230,642232-642562,642564-642565,642568-642570,642572-642573,642576-642736,642739-642877,642879,642881-642890,642892-642903,642905-642945,642947-643624,643626-643653,643655-643669,643671,643673-643830,643832-643833,643835-644342,644344-644472,644474-644508,644510-645347,645349-645351,645353-645559,645561-645565,645568-645951,645953-646193,646195-646311,646313-646404,646406-646665,646667-646853,646855-646869,646871-647151,647153-647185,647187-647277,647279-647566,647568-647573,647575,647578-647711,647714-647737,647739-647823,647825-648155,648157-648202,648204-648273,648275,648277-648302,648304-648333,648335-650914,650916-650920 via svnmerge from
https://svn.apache.org:443/repos/asf/poi/trunk
........
r648589 | yegor | 2008-04-16 08:47:16 +0100 (Wed, 16 Apr 2008) | 1 line
bug #41071 is fixed in trunk. Added a unit test and resolved.
........
r648623 | yegor | 2008-04-16 09:43:08 +0100 (Wed, 16 Apr 2008) | 1 line
Rich text in HSSFTextbox must have at least one format run. Make sure it is so and apply th default fopnt if no formats were applied.
........
r648624 | yegor | 2008-04-16 09:44:07 +0100 (Wed, 16 Apr 2008) | 1 line
Misc improvements in Freeform shape
........
r648674 | yegor | 2008-04-16 12:57:15 +0100 (Wed, 16 Apr 2008) | 1 line
Support for getting OLE object data from slide show
........
r649142 | yegor | 2008-04-17 16:06:01 +0100 (Thu, 17 Apr 2008) | 1 line
added a unit test and closed bug #28774
........
r649143 | yegor | 2008-04-17 16:08:03 +0100 (Thu, 17 Apr 2008) | 1 line
initial support for rendering powerpoint slides into images
........
r649145 | yegor | 2008-04-17 16:09:37 +0100 (Thu, 17 Apr 2008) | 1 line
updated the list of changes
........
r649557 | yegor | 2008-04-18 15:57:07 +0100 (Fri, 18 Apr 2008) | 1 line
improved rendering of text
........
r649796 | yegor | 2008-04-19 12:09:59 +0100 (Sat, 19 Apr 2008) | 1 line
Support for getting embedded sounds from slide show
........
r649797 | yegor | 2008-04-19 12:16:53 +0100 (Sat, 19 Apr 2008) | 1 line
properly set shapeId for new shapes
........
r649798 | yegor | 2008-04-19 12:17:37 +0100 (Sat, 19 Apr 2008) | 1 line
misc improvements in slide rendering
........
r649800 | yegor | 2008-04-19 12:52:36 +0100 (Sat, 19 Apr 2008) | 1 line
updated the docs
........
r649911 | yegor | 2008-04-20 12:17:48 +0100 (Sun, 20 Apr 2008) | 1 line
more improvements in slide rendering
........
r649914 | yegor | 2008-04-20 12:58:08 +0100 (Sun, 20 Apr 2008) | 1 line
set version.id=3.0.3-beta1
........
r650129 | yegor | 2008-04-21 13:51:47 +0100 (Mon, 21 Apr 2008) | 1 line
more improvements in slide rendering
........
r650130 | yegor | 2008-04-21 13:52:23 +0100 (Mon, 21 Apr 2008) | 1 line
a couple of HSLF examples
........
r650133 | yegor | 2008-04-21 14:10:33 +0100 (Mon, 21 Apr 2008) | 1 line
update current version to 3.1-beta1
........
r650138 | yegor | 2008-04-21 14:29:59 +0100 (Mon, 21 Apr 2008) | 1 line
unfinished release guide. It would be nice to have a html version.
........
r650139 | yegor | 2008-04-21 14:31:53 +0100 (Mon, 21 Apr 2008) | 1 line
unfinished release guide. It would be nice to have a html version.
........
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@650938 13f79535-47bb-0310-9956-ffa450edef68
2008-04-23 16:49:18 +00:00
|
|
|
// If font is not set we must set the default one
|
2012-06-26 11:21:13 +00:00
|
|
|
if (rtr.numFormattingRuns() == 0) rtr.applyFont((short) 0);
|
2012-07-11 12:08:38 +00:00
|
|
|
getTextObjectRecord().setStr(rtr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
void afterInsert(HSSFPatriarch patriarch){
|
|
|
|
|
EscherAggregate agg = patriarch._getBoundAggregate();
|
|
|
|
|
agg.associateShapeToObjRecord(getEscherContainer().getChildById(EscherClientDataRecord.RECORD_ID), getObjRecord());
|
|
|
|
|
agg.associateShapeToObjRecord(getEscherContainer().getChildById(EscherTextboxRecord.RECORD_ID), getTextObjectRecord());
|
2004-04-09 11:45:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2012-06-26 11:21:13 +00:00
|
|
|
* @return Returns the left margin within the textbox.
|
2004-04-09 11:45:38 +00:00
|
|
|
*/
|
2012-06-26 11:21:13 +00:00
|
|
|
public int getMarginLeft() {
|
2012-07-11 12:08:38 +00:00
|
|
|
EscherSimpleProperty property = getOptRecord().lookup(EscherProperties.TEXT__TEXTLEFT);
|
2012-06-26 11:21:13 +00:00
|
|
|
return property == null ? 0: property.getPropertyValue();
|
2004-04-09 11:45:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the left margin within the textbox.
|
|
|
|
|
*/
|
2012-06-26 11:21:13 +00:00
|
|
|
public void setMarginLeft(int marginLeft) {
|
|
|
|
|
setPropertyValue(new EscherSimpleProperty(EscherProperties.TEXT__TEXTLEFT, marginLeft));
|
2004-04-09 11:45:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2012-06-26 11:21:13 +00:00
|
|
|
* @return returns the right margin within the textbox.
|
2004-04-09 11:45:38 +00:00
|
|
|
*/
|
2012-06-26 11:21:13 +00:00
|
|
|
public int getMarginRight() {
|
2012-07-11 12:08:38 +00:00
|
|
|
EscherSimpleProperty property = getOptRecord().lookup(EscherProperties.TEXT__TEXTRIGHT);
|
2012-06-26 11:21:13 +00:00
|
|
|
return property == null ? 0: property.getPropertyValue();
|
2004-04-09 11:45:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the right margin within the textbox.
|
|
|
|
|
*/
|
2012-06-26 11:21:13 +00:00
|
|
|
public void setMarginRight(int marginRight) {
|
|
|
|
|
setPropertyValue(new EscherSimpleProperty(EscherProperties.TEXT__TEXTRIGHT, marginRight));
|
2004-04-09 11:45:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2012-06-26 11:21:13 +00:00
|
|
|
* @return returns the top margin within the textbox.
|
2004-04-09 11:45:38 +00:00
|
|
|
*/
|
2012-06-26 11:21:13 +00:00
|
|
|
public int getMarginTop() {
|
2012-07-11 12:08:38 +00:00
|
|
|
EscherSimpleProperty property = getOptRecord().lookup(EscherProperties.TEXT__TEXTTOP);
|
2012-06-26 11:21:13 +00:00
|
|
|
return property == null ? 0: property.getPropertyValue();
|
2004-04-09 11:45:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the top margin within the textbox.
|
|
|
|
|
*/
|
2012-06-26 11:21:13 +00:00
|
|
|
public void setMarginTop(int marginTop) {
|
|
|
|
|
setPropertyValue(new EscherSimpleProperty(EscherProperties.TEXT__TEXTTOP, marginTop));
|
2004-04-09 11:45:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the bottom margin within the textbox.
|
|
|
|
|
*/
|
2012-06-26 11:21:13 +00:00
|
|
|
public int getMarginBottom() {
|
2012-07-11 12:08:38 +00:00
|
|
|
EscherSimpleProperty property = getOptRecord().lookup(EscherProperties.TEXT__TEXTBOTTOM);
|
2012-06-26 11:21:13 +00:00
|
|
|
return property == null ? 0: property.getPropertyValue();
|
2004-04-09 11:45:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the bottom margin within the textbox.
|
|
|
|
|
*/
|
2012-06-26 11:21:13 +00:00
|
|
|
public void setMarginBottom(int marginBottom) {
|
|
|
|
|
setPropertyValue(new EscherSimpleProperty(EscherProperties.TEXT__TEXTBOTTOM, marginBottom));
|
2004-04-09 11:45:38 +00:00
|
|
|
}
|
2008-03-29 16:41:25 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the horizontal alignment.
|
|
|
|
|
*/
|
2012-06-26 11:21:13 +00:00
|
|
|
public short getHorizontalAlignment() {
|
2012-07-11 12:08:38 +00:00
|
|
|
return (short) getTextObjectRecord().getHorizontalTextAlignment();
|
2008-03-29 16:41:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the horizontal alignment.
|
|
|
|
|
*/
|
2012-06-26 11:21:13 +00:00
|
|
|
public void setHorizontalAlignment(short align) {
|
2012-07-11 12:08:38 +00:00
|
|
|
getTextObjectRecord().setHorizontalTextAlignment(align);
|
2008-03-29 16:41:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the vertical alignment.
|
|
|
|
|
*/
|
2012-06-26 11:21:13 +00:00
|
|
|
public short getVerticalAlignment() {
|
2012-07-11 12:08:38 +00:00
|
|
|
return (short) getTextObjectRecord().getVerticalTextAlignment();
|
2008-03-29 16:41:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the vertical alignment.
|
|
|
|
|
*/
|
2012-06-26 11:21:13 +00:00
|
|
|
public void setVerticalAlignment(short align) {
|
2012-07-11 12:08:38 +00:00
|
|
|
getTextObjectRecord().setVerticalTextAlignment(align);
|
2012-06-26 11:21:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2012-07-11 12:08:38 +00:00
|
|
|
public void setShapeType(int shapeType) {
|
|
|
|
|
throw new IllegalStateException("Shape type can not be changed in "+this.getClass().getSimpleName());
|
|
|
|
|
}
|
2012-07-19 19:02:43 +00:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public HSSFShape cloneShape() {
|
|
|
|
|
TextObjectRecord txo = (TextObjectRecord) getTextObjectRecord().cloneViaReserialise();
|
|
|
|
|
EscherContainerRecord spContainer = new EscherContainerRecord();
|
|
|
|
|
byte [] inSp = getEscherContainer().serialize();
|
|
|
|
|
spContainer.fillFields(inSp, 0, new DefaultEscherRecordFactory());
|
|
|
|
|
ObjRecord obj = (ObjRecord) getObjRecord().cloneViaReserialise();
|
|
|
|
|
return new HSSFTextbox(spContainer, obj, txo);
|
|
|
|
|
}
|
2004-04-09 11:45:38 +00:00
|
|
|
}
|