Java Code Examples for com.lowagie.text.Element#ALIGN_CENTER

The following examples show how to use com.lowagie.text.Element#ALIGN_CENTER . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BarcodeInter25.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
/** Creates new BarcodeInter25 */
public BarcodeInter25() {
    try {
        x = 0.8f;
        n = 2;
        font = BaseFont.createFont("Helvetica", "winansi", false);
        size = 8;
        baseline = size;
        barHeight = size * 3;
        textAlignment = Element.ALIGN_CENTER;
        generateChecksum = false;
        checksumText = false;
    }
    catch (Exception e) {
        throw new ExceptionConverter(e);
    }
}
 
Example 2
Source File: PdfLogicalPageDrawable.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
private int mapAlignment( final RenderableComplexText node ) {
  ElementAlignment alignment;
  if ( node.getNext() == null ) {
    alignment = paragraphContext.getLastLineAlignment();
  } else {
    alignment = paragraphContext.getTextAlignment();
  }
  if ( ElementAlignment.LEFT.equals( alignment ) ) {
    return Element.ALIGN_LEFT;
  } else if ( ElementAlignment.RIGHT.equals( alignment ) ) {
    return Element.ALIGN_RIGHT;
  } else if ( ElementAlignment.CENTER.equals( alignment ) ) {
    return Element.ALIGN_CENTER;
  } else {
    return Element.ALIGN_JUSTIFIED;
  }
}
 
Example 3
Source File: PdfLogicalPageDrawable.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public ColumnText reconfigure( PdfContentByte cb, Phrase p ) {
  float filledWidth = ColumnText.getWidth( p, runDirection, 0 ) + 0.5f;
  ColumnText ct = new ColumnText( cb );
  ct.setRunDirection( runDirection );
  if ( alignment == Element.ALIGN_LEFT ) {
    ct.setSimpleColumn( llx, lly, llx + filledWidth, ury, leading, alignment );
  } else if ( alignment == Element.ALIGN_RIGHT ) {
    ct.setSimpleColumn( urx - filledWidth, lly, urx, ury, leading, alignment );
  } else if ( alignment == Element.ALIGN_CENTER ) {
    float delta = ( ( urx - llx ) - filledWidth ) / 2;
    ct.setSimpleColumn( urx + delta, lly, urx - delta, ury, leading, alignment );
  } else {
    ct.setSimpleColumn( llx, lly, urx, ury, leading, alignment );
  }
  return ct;
}
 
Example 4
Source File: HtmlEncoder.java    From itext2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
* Translates the alignment value.
*
* @param   alignment   the alignment value
* @return  the translated value
*/
   
   public static String getAlignment(int alignment) {
       switch(alignment) {
           case Element.ALIGN_LEFT:
               return HtmlTags.ALIGN_LEFT;
           case Element.ALIGN_CENTER:
               return HtmlTags.ALIGN_CENTER;
           case Element.ALIGN_RIGHT:
               return HtmlTags.ALIGN_RIGHT;
           case Element.ALIGN_JUSTIFIED:
           case Element.ALIGN_JUSTIFIED_ALL:
               return HtmlTags.ALIGN_JUSTIFIED;
           case Element.ALIGN_TOP:
               return HtmlTags.ALIGN_TOP;
           case Element.ALIGN_MIDDLE:
               return HtmlTags.ALIGN_MIDDLE;
           case Element.ALIGN_BOTTOM:
               return HtmlTags.ALIGN_BOTTOM;
           case Element.ALIGN_BASELINE:
               return HtmlTags.ALIGN_BASELINE;
               default:
                   return "";
       }
   }
 
Example 5
Source File: BarcodeCodabar.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
/** Creates a new BarcodeCodabar.
 */    
public BarcodeCodabar() {
    try {
        x = 0.8f;
        n = 2;
        font = BaseFont.createFont("Helvetica", "winansi", false);
        size = 8;
        baseline = size;
        barHeight = size * 3;
        textAlignment = Element.ALIGN_CENTER;
        generateChecksum = false;
        checksumText = false;
        startStopText = false;
        codeType = CODABAR;
    }
    catch (Exception e) {
        throw new ExceptionConverter(e);
    }
}
 
Example 6
Source File: HtmlEncoder.java    From MesquiteCore with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
* Translates the alignment value.
*
* @param   alignment   the alignment value
* @return  the translated value
*/
   
   public static String getAlignment(int alignment) {
       switch(alignment) {
           case Element.ALIGN_LEFT:
               return HtmlTags.ALIGN_LEFT;
           case Element.ALIGN_CENTER:
               return HtmlTags.ALIGN_CENTER;
           case Element.ALIGN_RIGHT:
               return HtmlTags.ALIGN_RIGHT;
           case Element.ALIGN_JUSTIFIED:
           case Element.ALIGN_JUSTIFIED_ALL:
               return HtmlTags.ALIGN_JUSTIFIED;
           case Element.ALIGN_TOP:
               return HtmlTags.ALIGN_TOP;
           case Element.ALIGN_MIDDLE:
               return HtmlTags.ALIGN_MIDDLE;
           case Element.ALIGN_BOTTOM:
               return HtmlTags.ALIGN_BOTTOM;
           case Element.ALIGN_BASELINE:
               return HtmlTags.ALIGN_BASELINE;
               default:
                   return "";
       }
   }
 
Example 7
Source File: HtmlEncoder.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
/**
* Translates the alignment value.
*
* @param   alignment   the alignment value
* @return  the translated value
*/
   
   public static String getAlignment(int alignment) {
       switch(alignment) {
           case Element.ALIGN_LEFT:
               return HtmlTags.ALIGN_LEFT;
           case Element.ALIGN_CENTER:
               return HtmlTags.ALIGN_CENTER;
           case Element.ALIGN_RIGHT:
               return HtmlTags.ALIGN_RIGHT;
           case Element.ALIGN_JUSTIFIED:
           case Element.ALIGN_JUSTIFIED_ALL:
               return HtmlTags.ALIGN_JUSTIFIED;
           case Element.ALIGN_TOP:
               return HtmlTags.ALIGN_TOP;
           case Element.ALIGN_MIDDLE:
               return HtmlTags.ALIGN_MIDDLE;
           case Element.ALIGN_BOTTOM:
               return HtmlTags.ALIGN_BOTTOM;
           case Element.ALIGN_BASELINE:
               return HtmlTags.ALIGN_BASELINE;
               default:
                   return "";
       }
   }
 
Example 8
Source File: BarcodeInter25.java    From itext2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
/** Creates new BarcodeInter25 */
public BarcodeInter25() {
    try {
        x = 0.8f;
        n = 2;
        font = BaseFont.createFont("Helvetica", "winansi", false);
        size = 8;
        baseline = size;
        barHeight = size * 3;
        textAlignment = Element.ALIGN_CENTER;
        generateChecksum = false;
        checksumText = false;
    }
    catch (Exception e) {
        throw new ExceptionConverter(e);
    }
}
 
Example 9
Source File: PdfLine.java    From MesquiteCore with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Returns the left indentation of the line taking the alignment of the line into account.
 *
 * @return	a value
 */

float indentLeft() {
    if (isRTL) {
        switch (alignment) {
            case Element.ALIGN_LEFT:
                return left + width;
            case Element.ALIGN_CENTER:
                return left + (width / 2f);
            default:
                return left;
        }
    }
    else {
        switch (alignment) {
            case Element.ALIGN_RIGHT:
                return left + width;
            case Element.ALIGN_CENTER:
                return left + (width / 2f);
            default:
                return left;
        }
    }
}
 
Example 10
Source File: Barcode39.java    From itext2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
/** Creates a new Barcode39.
 */    
public Barcode39() {
    try {
        x = 0.8f;
        n = 2;
        font = BaseFont.createFont("Helvetica", "winansi", false);
        size = 8;
        baseline = size;
        barHeight = size * 3;
        textAlignment = Element.ALIGN_CENTER;
        generateChecksum = false;
        checksumText = false;
        startStopText = true;
        extended = false;
    }
    catch (Exception e) {
        throw new ExceptionConverter(e);
    }
}
 
Example 11
Source File: Barcode128.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/** Creates new Barcode128 */
public Barcode128() {
    try {
        x = 0.8f;
        font = BaseFont.createFont("Helvetica", "winansi", false);
        size = 8;
        baseline = size;
        barHeight = size * 3;
        textAlignment = Element.ALIGN_CENTER;
        codeType = CODE128;
    }
    catch (Exception e) {
        throw new ExceptionConverter(e);
    }
}
 
Example 12
Source File: Barcode128.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/** Creates new Barcode128 */
public Barcode128() {
    try {
        x = 0.8f;
        font = BaseFont.createFont("Helvetica", "winansi", false);
        size = 8;
        baseline = size;
        barHeight = size * 3;
        textAlignment = Element.ALIGN_CENTER;
        codeType = CODE128;
    }
    catch (Exception e) {
        throw new ExceptionConverter(e);
    }
}
 
Example 13
Source File: TextField.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Gets a new text field.
 * @throws IOException on error
 * @throws DocumentException on error
 * @return a new text field
 */    
public PdfFormField getTextField() throws IOException, DocumentException {
    if (maxCharacterLength <= 0)
        options &= ~COMB;
    if ((options & COMB) != 0)
        options &= ~MULTILINE;
    PdfFormField field = PdfFormField.createTextField(writer, false, false, maxCharacterLength);
    field.setWidget(box, PdfAnnotation.HIGHLIGHT_INVERT);
    switch (alignment) {
        case Element.ALIGN_CENTER:
            field.setQuadding(PdfFormField.Q_CENTER);
            break;
        case Element.ALIGN_RIGHT:
            field.setQuadding(PdfFormField.Q_RIGHT);
            break;
    }
    if (rotation != 0)
        field.setMKRotation(rotation);
    if (fieldName != null) {
        field.setFieldName(fieldName);
        if (!"".equals(text))
        	field.setValueAsString(text);
        if (defaultText != null)
            field.setDefaultValueAsString(defaultText);
        if ((options & READ_ONLY) != 0)
            field.setFieldFlags(PdfFormField.FF_READ_ONLY);
        if ((options & REQUIRED) != 0)
            field.setFieldFlags(PdfFormField.FF_REQUIRED);
        if ((options & MULTILINE) != 0)
            field.setFieldFlags(PdfFormField.FF_MULTILINE);
        if ((options & DO_NOT_SCROLL) != 0)
            field.setFieldFlags(PdfFormField.FF_DONOTSCROLL);
        if ((options & PASSWORD) != 0)
            field.setFieldFlags(PdfFormField.FF_PASSWORD);
        if ((options & FILE_SELECTION) != 0)
            field.setFieldFlags(PdfFormField.FF_FILESELECT);
        if ((options & DO_NOT_SPELL_CHECK) != 0)
            field.setFieldFlags(PdfFormField.FF_DONOTSPELLCHECK);
        if ((options & COMB) != 0)
            field.setFieldFlags(PdfFormField.FF_COMB);
    }
    field.setBorderStyle(new PdfBorderDictionary(borderWidth, borderStyle, new PdfDashPattern(3)));
    PdfAppearance tp = getAppearance();
    field.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, tp);
    PdfAppearance da = (PdfAppearance)tp.getDuplicate();
    da.setFontAndSize(getRealFont(), fontSize);
    if (textColor == null)
        da.setGrayFill(0);
    else
        da.setColorFill(textColor);
    field.setDefaultAppearanceString(da);
    if (borderColor != null)
        field.setMKBorderColor(borderColor);
    if (backgroundColor != null)
        field.setMKBackgroundColor(backgroundColor);
    switch (visibility) {
        case HIDDEN:
            field.setFlags(PdfAnnotation.FLAGS_PRINT | PdfAnnotation.FLAGS_HIDDEN);
            break;
        case VISIBLE_BUT_DOES_NOT_PRINT:
            break;
        case HIDDEN_BUT_PRINTABLE:
            field.setFlags(PdfAnnotation.FLAGS_PRINT | PdfAnnotation.FLAGS_NOVIEW);
            break;
        default:
            field.setFlags(PdfAnnotation.FLAGS_PRINT);
            break;
    }
    return field;
}
 
Example 14
Source File: TextField.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
/**
 * Gets a new text field.
 * @throws IOException on error
 * @throws DocumentException on error
 * @return a new text field
 */    
public PdfFormField getTextField() throws IOException, DocumentException {
    if (maxCharacterLength <= 0)
        options &= ~COMB;
    if ((options & COMB) != 0)
        options &= ~MULTILINE;
    PdfFormField field = PdfFormField.createTextField(writer, false, false, maxCharacterLength);
    field.setWidget(box, PdfAnnotation.HIGHLIGHT_INVERT);
    switch (alignment) {
        case Element.ALIGN_CENTER:
            field.setQuadding(PdfFormField.Q_CENTER);
            break;
        case Element.ALIGN_RIGHT:
            field.setQuadding(PdfFormField.Q_RIGHT);
            break;
    }
    if (rotation != 0)
        field.setMKRotation(rotation);
    if (fieldName != null) {
        field.setFieldName(fieldName);
        if (!"".equals(text))
        	field.setValueAsString(text);
        if (defaultText != null)
            field.setDefaultValueAsString(defaultText);
        if ((options & READ_ONLY) != 0)
            field.setFieldFlags(PdfFormField.FF_READ_ONLY);
        if ((options & REQUIRED) != 0)
            field.setFieldFlags(PdfFormField.FF_REQUIRED);
        if ((options & MULTILINE) != 0)
            field.setFieldFlags(PdfFormField.FF_MULTILINE);
        if ((options & DO_NOT_SCROLL) != 0)
            field.setFieldFlags(PdfFormField.FF_DONOTSCROLL);
        if ((options & PASSWORD) != 0)
            field.setFieldFlags(PdfFormField.FF_PASSWORD);
        if ((options & FILE_SELECTION) != 0)
            field.setFieldFlags(PdfFormField.FF_FILESELECT);
        if ((options & DO_NOT_SPELL_CHECK) != 0)
            field.setFieldFlags(PdfFormField.FF_DONOTSPELLCHECK);
        if ((options & COMB) != 0)
            field.setFieldFlags(PdfFormField.FF_COMB);
    }
    field.setBorderStyle(new PdfBorderDictionary(borderWidth, borderStyle, new PdfDashPattern(3)));
    PdfAppearance tp = getAppearance();
    field.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, tp);
    PdfAppearance da = (PdfAppearance)tp.getDuplicate();
    da.setFontAndSize(getRealFont(), fontSize);
    if (textColor == null)
        da.setGrayFill(0);
    else
        da.setColorFill(textColor);
    field.setDefaultAppearanceString(da);
    if (borderColor != null)
        field.setMKBorderColor(borderColor);
    if (backgroundColor != null)
        field.setMKBackgroundColor(backgroundColor);
    switch (visibility) {
        case HIDDEN:
            field.setFlags(PdfAnnotation.FLAGS_PRINT | PdfAnnotation.FLAGS_HIDDEN);
            break;
        case VISIBLE_BUT_DOES_NOT_PRINT:
            break;
        case HIDDEN_BUT_PRINTABLE:
            field.setFlags(PdfAnnotation.FLAGS_PRINT | PdfAnnotation.FLAGS_NOVIEW);
            break;
        default:
            field.setFlags(PdfAnnotation.FLAGS_PRINT);
            break;
    }
    return field;
}
 
Example 15
Source File: ColumnText.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
/**
 * Shows a line of text. Only the first line is written.
 * 
 * @param canvas where the text is to be written to
 * @param alignment the alignment. It is not influenced by the run direction
 * @param phrase the <CODE>Phrase</CODE> with the text
 * @param x the x reference position
 * @param y the y reference position
 * @param rotation the rotation to be applied in degrees counterclockwise
 * @param runDirection the run direction
 * @param arabicOptions the options for the arabic shaping
 */
public static void showTextAligned(PdfContentByte canvas, int alignment, Phrase phrase, float x, float y, float rotation, int runDirection, int arabicOptions) {
	if (alignment != Element.ALIGN_LEFT && alignment != Element.ALIGN_CENTER && alignment != Element.ALIGN_RIGHT) {
		alignment = Element.ALIGN_LEFT;
	}
	canvas.saveState();
	ColumnText ct = new ColumnText(canvas);
	float lly = -1;
	float ury = 2;
	float llx;
	float urx;
	switch (alignment) {
		case Element.ALIGN_LEFT:
			llx = 0;
			urx = 20000;
			break;
		case Element.ALIGN_RIGHT:
			llx = -20000;
			urx = 0;
			break;
		default:
			llx = -20000;
			urx = 20000;
			break;
	}
	if (rotation == 0) {
		llx += x;
		lly += y;
		urx += x;
		ury += y;
	} else {
		double alpha = rotation * Math.PI / 180.0;
		float cos = (float) Math.cos(alpha);
		float sin = (float) Math.sin(alpha);
		canvas.concatCTM(cos, sin, -sin, cos, x, y);
	}
	ct.setSimpleColumn(phrase, llx, lly, urx, ury, 2, alignment);
	if (runDirection == PdfWriter.RUN_DIRECTION_RTL) {
		if (alignment == Element.ALIGN_LEFT) {
			alignment = Element.ALIGN_RIGHT;
		} else if (alignment == Element.ALIGN_RIGHT) {
			alignment = Element.ALIGN_LEFT;
		}
	}
	ct.setAlignment(alignment);
	ct.setArabicOptions(arabicOptions);
	ct.setRunDirection(runDirection);
	try {
		ct.go();
	} catch (DocumentException e) {
		throw new ExceptionConverter(e);
	}
	canvas.restoreState();
}
 
Example 16
Source File: ColumnText.java    From MesquiteCore with GNU Lesser General Public License v3.0 4 votes vote down vote up
/** Shows a line of text. Only the first line is written.
 * @param canvas where the text is to be written to
 * @param alignment the alignment. It is not influenced by the run direction
 * @param phrase the <CODE>Phrase</CODE> with the text
 * @param x the x reference position
 * @param y the y reference position
 * @param rotation the rotation to be applied in degrees counterclockwise
 * @param runDirection the run direction
 * @param arabicOptions the options for the arabic shaping
 */    
public static void showTextAligned(PdfContentByte canvas, int alignment, Phrase phrase, float x, float y, float rotation, int runDirection, int arabicOptions) {
    if (alignment != Element.ALIGN_LEFT && alignment != Element.ALIGN_CENTER
        && alignment != Element.ALIGN_RIGHT)
        alignment = Element.ALIGN_LEFT;
    canvas.saveState();
    ColumnText ct = new ColumnText(canvas);
    if (rotation == 0) {
        if (alignment == Element.ALIGN_LEFT)
            ct.setSimpleColumn(phrase, x, y - 1, 20000 + x, y + 2, 2, alignment);
        else if (alignment == Element.ALIGN_RIGHT)
            ct.setSimpleColumn(phrase, x-20000, y-1, x, y+2, 2, alignment);
        else
            ct.setSimpleColumn(phrase, x-20000, y-1, x+20000, y+2, 2, alignment);
    }
    else {
        double alpha = rotation * Math.PI / 180.0;
        float cos = (float)Math.cos(alpha);
        float sin = (float)Math.sin(alpha);
        canvas.concatCTM(cos, sin, -sin, cos, x, y);
        if (alignment == Element.ALIGN_LEFT)
            ct.setSimpleColumn(phrase, 0, -1, 20000, 2, 2, alignment);
        else if (alignment == Element.ALIGN_RIGHT)
            ct.setSimpleColumn(phrase, -20000, -1, 0, 2, 2, alignment);
        else
            ct.setSimpleColumn(phrase, -20000, -1, 20000, 2, 2, alignment);
    }
    if (runDirection == PdfWriter.RUN_DIRECTION_RTL) {
        if (alignment == Element.ALIGN_LEFT)
            alignment = Element.ALIGN_RIGHT;
        else if (alignment == Element.ALIGN_RIGHT)
            alignment = Element.ALIGN_LEFT;
    }
    ct.setAlignment(alignment);
    ct.setArabicOptions(arabicOptions);
    ct.setRunDirection(runDirection);
    try {
        ct.go();
    }
    catch (DocumentException e) {
        throw new ExceptionConverter(e);
    }
    canvas.restoreState();
}
 
Example 17
Source File: RtfParagraphStyle.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Writes the settings of this RtfParagraphStyle.
 * 
 * @param result The <code>OutputStream</code> to write to.
 * @throws IOException On i/o errors.
 */
private void writeParagraphSettings(final OutputStream result) throws IOException {
    if(this.keepTogether) {
        result.write(RtfParagraphStyle.KEEP_TOGETHER);
    }
    if(this.keepTogetherWithNext) {
        result.write(RtfParagraphStyle.KEEP_TOGETHER_WITH_NEXT);
    }
    switch (alignment) {
        case Element.ALIGN_LEFT:
            result.write(RtfParagraphStyle.ALIGN_LEFT);
            break;
        case Element.ALIGN_RIGHT:
            result.write(RtfParagraphStyle.ALIGN_RIGHT);
            break;
        case Element.ALIGN_CENTER:
            result.write(RtfParagraphStyle.ALIGN_CENTER);
            break;
        case Element.ALIGN_JUSTIFIED:
        case Element.ALIGN_JUSTIFIED_ALL:
            result.write(RtfParagraphStyle.ALIGN_JUSTIFY);
            break;
    }
    result.write(FIRST_LINE_INDENT);
    result.write(intToByteArray(this.firstLineIndent));
    result.write(RtfParagraphStyle.INDENT_LEFT);
    result.write(intToByteArray(indentLeft));
    result.write(RtfParagraphStyle.INDENT_RIGHT);
    result.write(intToByteArray(indentRight));
    if(this.spacingBefore > 0) {
        result.write(RtfParagraphStyle.SPACING_BEFORE);
        result.write(intToByteArray(this.spacingBefore));
    }
    if(this.spacingAfter > 0) {
        result.write(RtfParagraphStyle.SPACING_AFTER);
        result.write(intToByteArray(this.spacingAfter));
    }
    if(this.lineLeading > 0) {
        result.write(RtfParagraph.LINE_SPACING);
        result.write(intToByteArray(this.lineLeading));
    }            
}
 
Example 18
Source File: RtfCell.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
* Write the cell definition part of this RtfCell
*/
  public void writeDefinition(final OutputStream result) throws IOException 
  {
      if(this.mergeType == MERGE_VERT_PARENT) {
          result.write(DocWriter.getISOBytes("\\clvmgf"));
      } else if(this.mergeType == MERGE_VERT_CHILD) {
          result.write(DocWriter.getISOBytes("\\clvmrg"));
      }
      switch (verticalAlignment) {
          case Element.ALIGN_BOTTOM:
              result.write(DocWriter.getISOBytes("\\clvertalb"));
              break;
          case Element.ALIGN_CENTER:
          case Element.ALIGN_MIDDLE:
              result.write(DocWriter.getISOBytes("\\clvertalc"));
              break;
          case Element.ALIGN_TOP:
              result.write(DocWriter.getISOBytes("\\clvertalt"));
              break;
      }
      this.borders.writeContent(result);

      if(this.backgroundColor != null) {
          result.write(DocWriter.getISOBytes("\\clcbpat"));
          result.write(intToByteArray(this.backgroundColor.getColorNumber()));
      }
      this.document.outputDebugLinebreak(result);
      
      result.write(DocWriter.getISOBytes("\\clftsWidth3"));
      this.document.outputDebugLinebreak(result);
      
      result.write(DocWriter.getISOBytes("\\clwWidth"));
      result.write(intToByteArray(this.cellWidth));
      this.document.outputDebugLinebreak(result);
      
      if(this.cellPadding > 0) {
          result.write(DocWriter.getISOBytes("\\clpadl"));
          result.write(intToByteArray(this.cellPadding / 2));
          result.write(DocWriter.getISOBytes("\\clpadt"));
          result.write(intToByteArray(this.cellPadding / 2));
          result.write(DocWriter.getISOBytes("\\clpadr"));
          result.write(intToByteArray(this.cellPadding / 2));
          result.write(DocWriter.getISOBytes("\\clpadb"));
          result.write(intToByteArray(this.cellPadding / 2));
          result.write(DocWriter.getISOBytes("\\clpadfl3"));
          result.write(DocWriter.getISOBytes("\\clpadft3"));
          result.write(DocWriter.getISOBytes("\\clpadfr3"));
          result.write(DocWriter.getISOBytes("\\clpadfb3"));
      }
      result.write(DocWriter.getISOBytes("\\cellx"));
      result.write(intToByteArray(this.cellRight));
  }
 
Example 19
Source File: AbstractPdfTextRenderer.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * 
 */
public void initialize(
	JRPdfExporter pdfExporter, 
	PdfContentByte pdfContentByte,
	JRPrintText text, 
	JRStyledText styledText, 
	int offsetX,
	int offsetY
	)
{
	this.pdfExporter = pdfExporter;
	this.pdfContentByte = pdfContentByte;
	
	horizontalAlignment = Element.ALIGN_LEFT;
	leftOffsetFactor = 0f;
	rightOffsetFactor = 0f;
	
	//FIXMETAB 0.2f was a fair approximation
	switch (text.getHorizontalTextAlign())
	{
		case JUSTIFIED :
		{
			horizontalAlignment = Element.ALIGN_JUSTIFIED;
			leftOffsetFactor = 0f;
			rightOffsetFactor = 0f;
			break;
		}
		case RIGHT :
		{
			if (text.getRunDirectionValue() == RunDirectionEnum.LTR)
			{
				horizontalAlignment = Element.ALIGN_RIGHT;
			}
			else
			{
				horizontalAlignment = Element.ALIGN_LEFT;
			}
			leftOffsetFactor = -0.2f;
			rightOffsetFactor = 0f;
			break;
		}
		case CENTER :
		{
			horizontalAlignment = Element.ALIGN_CENTER;
			leftOffsetFactor = -0.1f;
			rightOffsetFactor = 0.1f;
			break;
		}
		case LEFT :
		default :
		{
			if (text.getRunDirectionValue() == RunDirectionEnum.LTR)
			{
				horizontalAlignment = Element.ALIGN_LEFT;
			}
			else
			{
				horizontalAlignment = Element.ALIGN_RIGHT;
			}
			leftOffsetFactor = 0f;
			rightOffsetFactor = 0.2f;
			break;
		}
	}

	super.initialize(text, styledText, offsetX, offsetY);
}
 
Example 20
Source File: RtfImage.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Writes the RtfImage content
 */ 
public void writeContent(final OutputStream result) throws IOException
{
	
    if(this.topLevelElement) {
        result.write(RtfParagraph.PARAGRAPH_DEFAULTS);
        switch(alignment) {
            case Element.ALIGN_LEFT:
                result.write(RtfParagraphStyle.ALIGN_LEFT);
                break;
            case Element.ALIGN_RIGHT:
                result.write(RtfParagraphStyle.ALIGN_RIGHT);
                break;
            case Element.ALIGN_CENTER:
                result.write(RtfParagraphStyle.ALIGN_CENTER);
                break;
            case Element.ALIGN_JUSTIFIED:
                result.write(RtfParagraphStyle.ALIGN_JUSTIFY);
                break;
        }
    }
    result.write(OPEN_GROUP);
    result.write(PICTURE_GROUP);
    result.write(OPEN_GROUP);
    result.write(PICTURE);
    switch(imageType) {
    	case Image.ORIGINAL_JPEG:
    	    result.write(PICTURE_JPEG);
    		break;
    	case Image.ORIGINAL_PNG:
        case Image.ORIGINAL_GIF:
    	    result.write(PICTURE_PNG);
    		break;
    	case Image.ORIGINAL_WMF:
    	case Image.ORIGINAL_BMP:
    	    result.write(PICTURE_WMF);
    		break;
    }
    result.write(PICTURE_WIDTH);
    result.write(intToByteArray((int) width));
    result.write(PICTURE_HEIGHT);
    result.write(intToByteArray((int) height));
    if(this.document.getDocumentSettings().isWriteImageScalingInformation()) {
        result.write(PICTURE_SCALE_X);
        result.write(intToByteArray((int)(100 * plainWidth / width)));
        result.write(PICTURE_SCALE_Y);
        result.write(intToByteArray((int)(100 * plainHeight / height)));
    }
    if(this.document.getDocumentSettings().isImagePDFConformance()) {
        result.write(PICTURE_SCALED_WIDTH);
        result.write(intToByteArray((int) (plainWidth * RtfElement.TWIPS_FACTOR)));
        result.write(PICTURE_SCALED_HEIGHT);
        result.write(intToByteArray((int) (plainHeight * RtfElement.TWIPS_FACTOR)));
    } else {
        if(this.width != this.plainWidth || this.imageType == Image.ORIGINAL_BMP) {
            result.write(PICTURE_SCALED_WIDTH);
            result.write(intToByteArray((int) (plainWidth * PIXEL_TWIPS_FACTOR)));
        }
        if(this.height != this.plainHeight || this.imageType == Image.ORIGINAL_BMP) {
            result.write(PICTURE_SCALED_HEIGHT);
            result.write(intToByteArray((int) (plainHeight * PIXEL_TWIPS_FACTOR)));
        }
    }

    if(this.document.getDocumentSettings().isImageWrittenAsBinary()) {
    	//binary
    	result.write('\n');
    	result.write(PICTURE_BINARY_DATA);
    	result.write(intToByteArray(imageDataSize()));
        result.write(DELIMITER);
        if(result instanceof RtfByteArrayBuffer) {
        	((RtfByteArrayBuffer)result).append(imageData);
        } else {
        	for(int k = 0; k < imageData.length; k++) {
	result.write(imageData[k]);
}
        }
    } else {
    	//hex encoded
        result.write(DELIMITER);
    	result.write('\n');
    	writeImageDataHexEncoded(result);
    }
    
    result.write(CLOSE_GROUP);
    result.write(CLOSE_GROUP);
    if(this.topLevelElement) {
        result.write(RtfParagraph.PARAGRAPH);
        result.write(RtfParagraph.PARAGRAPH);
    }
    result.write('\n');    	
}