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

The following examples show how to use com.lowagie.text.Element#ALIGN_JUSTIFIED . 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: 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 2
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 3
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 4
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 5
Source File: PdfLine.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Resets the alignment of this line.
 * <P>
 * The alignment of the last line of for instance a <CODE>Paragraph</CODE> that has to be
 * justified, has to be reset to <VAR>ALIGN_LEFT</VAR>.
 */

public void resetAlignment() {
	if (alignment == Element.ALIGN_JUSTIFIED) {
		alignment = Element.ALIGN_LEFT;
	}
}
 
Example 6
Source File: PdfLine.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Resets the alignment of this line.
 * <P>
 * The alignment of the last line of for instance a <CODE>Paragraph</CODE>
 * that has to be justified, has to be reset to <VAR>ALIGN_LEFT</VAR>.
 */

public void resetAlignment() {
    if (alignment == Element.ALIGN_JUSTIFIED) {
        alignment = Element.ALIGN_LEFT;
    }
}
 
Example 7
Source File: RtfListLevel.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Writes the initialization part of the RtfList
 * 
 * @param result The <code>OutputStream</code> to write to
 * @throws IOException On i/o errors.
 */
public void writeListBeginning(final OutputStream result) throws IOException {
    result.write(RtfParagraph.PARAGRAPH_DEFAULTS);
    if(this.inTable) {
        result.write(RtfParagraph.IN_TABLE);
    }
    switch (this.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;
    }
    writeIndentation(result);
    result.write(RtfFont.FONT_SIZE);
    result.write(intToByteArray(fontNumber.getFontSize() * 2));
    if(this.symbolIndent > 0) {
        result.write(LIST_LEVEL_SYMBOL_INDENT);
        result.write(intToByteArray(this.leftIndent));
    }
}
 
Example 8
Source File: PdfLine.java    From MesquiteCore with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Resets the alignment of this line.
 * <P>
 * The alignment of the last line of for instance a <CODE>Paragraph</CODE>
 * that has to be justified, has to be reset to <VAR>ALIGN_LEFT</VAR>.
 */

public void resetAlignment() {
    if (alignment == Element.ALIGN_JUSTIFIED) {
        alignment = Element.ALIGN_LEFT;
    }
}
 
Example 9
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 10
Source File: RtfRow.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Writes the row definition/settings.
 *
 * @param result The <code>OutputStream</code> to write the definitions to.
 */
private void writeRowDefinition(final OutputStream result) throws IOException {
    result.write(ROW_BEGIN);
    this.document.outputDebugLinebreak(result);
    result.write(ROW_WIDTH_STYLE);
    result.write(ROW_WIDTH);
    result.write(intToByteArray(this.width));
    if(this.parentTable.getCellsFitToPage()) {
        result.write(ROW_KEEP_TOGETHER);
    }
    if(this.rowNumber <= this.parentTable.getHeaderRows()) {
        result.write(ROW_HEADER_ROW);
    }
    switch (this.parentTable.getAlignment()) {
        case Element.ALIGN_LEFT:
        	result.write(ROW_ALIGN_LEFT);
            break;
        case Element.ALIGN_RIGHT:
            result.write(ROW_ALIGN_RIGHT);
            break;
        case Element.ALIGN_CENTER:
            result.write(ROW_ALIGN_CENTER);
            break;
        case Element.ALIGN_JUSTIFIED:
        case Element.ALIGN_JUSTIFIED_ALL:
            result.write(ROW_ALIGN_JUSTIFIED);
            break;
    }
    result.write(ROW_GRAPH);
    RtfBorderGroup borders =this.parentTable.getBorders();
    if(borders != null) {
    	borders.writeContent(result);
    }
    
    if(this.parentTable.getCellSpacing() > 0) {
        result.write(ROW_CELL_SPACING_LEFT);
        result.write(intToByteArray((int) (this.parentTable.getCellSpacing() / 2)));
        result.write(ROW_CELL_SPACING_LEFT_STYLE);
        result.write(ROW_CELL_SPACING_TOP);
        result.write(intToByteArray((int) (this.parentTable.getCellSpacing() / 2)));
        result.write(ROW_CELL_SPACING_TOP_STYLE);
        result.write(ROW_CELL_SPACING_RIGHT);
        result.write(intToByteArray((int) (this.parentTable.getCellSpacing() / 2)));
        result.write(ROW_CELL_SPACING_RIGHT_STYLE);
        result.write(ROW_CELL_SPACING_BOTTOM);
        result.write(intToByteArray((int) (this.parentTable.getCellSpacing() / 2)));
        result.write(ROW_CELL_SPACING_BOTTOM_STYLE);
    }
    
    result.write(ROW_CELL_PADDING_LEFT);
    result.write(intToByteArray((int) (this.parentTable.getCellPadding() / 2)));
    result.write(ROW_CELL_PADDING_RIGHT);
    result.write(intToByteArray((int) (this.parentTable.getCellPadding() / 2)));
    result.write(ROW_CELL_PADDING_LEFT_STYLE);
    result.write(ROW_CELL_PADDING_RIGHT_STYLE);
    
    this.document.outputDebugLinebreak(result);
    
    for(int i = 0; i < this.cells.size(); i++) {
        RtfCell rtfCell = (RtfCell) this.cells.get(i);
        rtfCell.writeDefinition(result);
    }    	
}
 
Example 11
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');    	
}
 
Example 12
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 13
Source File: PdfLine.java    From gcs with Mozilla Public License 2.0 2 votes vote down vote up
/**
 * Checks if this line has to be justified.
 *
 * @return <CODE>true</CODE> if the alignment equals <VAR>ALIGN_JUSTIFIED</VAR> and there is
 *         some width left.
 */

public boolean hasToBeJustified() {
	return (alignment == Element.ALIGN_JUSTIFIED || alignment == Element.ALIGN_JUSTIFIED_ALL) && width != 0;
}
 
Example 14
Source File: PdfLine.java    From itext2 with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Checks if this line has to be justified.
 *
 * @return	<CODE>true</CODE> if the alignment equals <VAR>ALIGN_JUSTIFIED</VAR> and there is some width left.
 */

public boolean hasToBeJustified() {
    return ((alignment == Element.ALIGN_JUSTIFIED || alignment == Element.ALIGN_JUSTIFIED_ALL) && width != 0);
}
 
Example 15
Source File: PdfLine.java    From MesquiteCore with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Checks if this line has to be justified.
 *
 * @return	<CODE>true</CODE> if the alignment equals <VAR>ALIGN_JUSTIFIED</VAR> and there is some width left.
 */

public boolean hasToBeJustified() {
    return ((alignment == Element.ALIGN_JUSTIFIED || alignment == Element.ALIGN_JUSTIFIED_ALL) && width != 0);
}