diff --git a/engine/org.eclipse.birt.report.engine.emitter.pptx/src/org/eclipse/birt/report/engine/emitter/pptx/TableWriter.java b/engine/org.eclipse.birt.report.engine.emitter.pptx/src/org/eclipse/birt/report/engine/emitter/pptx/TableWriter.java index 6ddd8c65c04..0badc3dadd5 100644 --- a/engine/org.eclipse.birt.report.engine.emitter.pptx/src/org/eclipse/birt/report/engine/emitter/pptx/TableWriter.java +++ b/engine/org.eclipse.birt.report.engine.emitter.pptx/src/org/eclipse/birt/report/engine/emitter/pptx/TableWriter.java @@ -13,13 +13,18 @@ import org.eclipse.birt.report.engine.nLayout.area.impl.RowArea; import org.eclipse.birt.report.engine.nLayout.area.impl.TableArea; import org.eclipse.birt.report.engine.nLayout.area.style.BackgroundImageInfo; +import org.eclipse.birt.report.engine.nLayout.area.style.BorderInfo; import org.eclipse.birt.report.engine.nLayout.area.style.BoxStyle; import org.eclipse.birt.report.engine.nLayout.area.style.DiagonalInfo; import org.eclipse.birt.report.engine.ooxml.writer.OOXmlWriter; public class TableWriter { - + + private static final String RIGHTBORDERLINE = "a:lnR"; + private static final String LEFTBORDERLINE = "a:lnL"; + private static final String TOPBORDERLINE = "a:lnT"; + private static final String BOTTOMBORDERLINE = "a:lnB"; private int currentX; private int currentY; protected Stack rowStyleStack = new Stack(); @@ -29,7 +34,7 @@ public class TableWriter private final PPTXCanvas canvas; protected OOXmlWriter writer; private static int TableIndex = 1; - + public TableWriter( PPTXRender render ) { this.render = render; @@ -45,7 +50,7 @@ public void outputTable( TableArea table ) { drawTable( table ); } - + protected void drawTable( TableArea table) { if ( table.needClip( ) ) @@ -53,9 +58,10 @@ protected void drawTable( TableArea table) render.startClip( table); } - startTable(table); + currentX += getX( table); currentY += getY( table ); + startTable(table); Iterator iter = table.getChildren( ); while ( iter.hasNext( ) ) { @@ -74,10 +80,10 @@ protected void drawTable( TableArea table) currentY -= getY( table); endTable(); } - + private void startTable( TableArea tablearea ) { - + int X = PPTXUtil.convertToEnums( currentX ); int Y = PPTXUtil.convertToEnums( currentY ); int width = PPTXUtil.convertToEnums( tablearea.getWidth( )); @@ -103,7 +109,7 @@ private void startTable( TableArea tablearea ) writer.openTag("a:tbl"); writeColumnsWidth(tablearea); } - + private void endTable() { writer.closeTag( "a:tbl" ); @@ -126,7 +132,7 @@ private void writeColumnsWidth( TableArea tablearea ) } writer.closeTag( "a:tblGrid" ); } - + protected void drawRow( RowArea row) { currentX += getX( row); @@ -144,7 +150,7 @@ protected void drawRow( RowArea row) currentX -= getX( row); currentY -= getY( row); } - + private void startRow( RowArea row ) { writer.openTag("a:tr"); @@ -155,11 +161,15 @@ private void startRow( RowArea row ) private void endRow( ) { writer.closeTag( "a:tr" ); - + } - + protected void drawCell( CellArea cell) { + int rowid = cell.getRowID( ); + System.out.println("rowid: "+ rowid ); + int colid = cell.getColumnID( ); + System.out.println("colid: "+ colid ); currentX += getX( cell); currentY += getY( cell); startCell( cell ); @@ -170,7 +180,7 @@ protected void drawCell( CellArea cell) currentX -= getX( cell); currentY -= getY( cell); } - + /** * start cell tag with all properties: styling @@ -178,7 +188,7 @@ protected void drawCell( CellArea cell) */ private void startCell( CellArea cell ) { - writer.openTag( "a:tc" ); + writer.openTag( "a:tc" ); int colspan = cell.getColSpan( ); if( colspan > 1) @@ -230,71 +240,60 @@ protected void visitChildren( IContainerArea container ) } updateRenderXY(); } - + + /** + * draw the cells properties + * @param cell + */ protected void drawCellBox( CellArea cell ) { + drawBorders( cell ); drawCellDiagonal( cell ); - Color rowbc = null; - BackgroundImageInfo rowbi = null; - BoxStyle rowStyle = null; - - // get the style of the row - if ( rowStyleStack.size( ) > 0 ) + BoxStyle style = cell.getBoxStyle( ); + Color backgroundcolor = style.getBackgroundColor( ); + BackgroundImageInfo bgimginfo = style.getBackgroundImage( ); + + if( !rowStyleStack.isEmpty( ) && (backgroundcolor == null || bgimginfo == null) ) { - rowStyle = rowStyleStack.peek( ); - if(rowStyle!=null) + BoxStyle rowStyle = rowStyleStack.peek( ); + if(rowStyle!=null) { - rowbc = rowStyle.getBackgroundColor( ); - rowbi = rowStyle.getBackgroundImage( ); - } + if(backgroundcolor == null ) + { + backgroundcolor = rowStyle.getBackgroundColor( ); + } + if(bgimginfo == null) + { + bgimginfo = rowStyle.getBackgroundImage( ); + } + } } - BoxStyle style = cell.getBoxStyle( ); - Color bc = style.getBackgroundColor( ); - BackgroundImageInfo bi = style.getBackgroundImage( ); -// render.drawBorders( cell ); - //String imageUrl = EmitterUtil.getBackgroundImageUrl( style,reportDesign ); - if ( rowbc != null || rowbi != null || bc != null - || bi != null ) - { - // the container's start position (the left top corner of the - // container) - int startX = currentX; - int startY = currentY; - - // the dimension of the container - int width = getWidth( cell ); - int height = getHeight( cell ); + // the container's start position (the left top corner of the + // container) + int startX = currentX; + int startY = currentY; + // the dimension of the container + int width = getWidth( cell ); + int height = getHeight( cell ); - if ( rowbc != null ) - { -// graphics.drawBackgroundColor( rowbc, startX, startY, width, height ); - canvas.setColor( rowbc ); - } - if ( rowbi != null ) - { - render.drawBackgroundImage( rowbi, startX, startY,width, height ); - } - if ( bc != null ) - { - // Draws background color for the container, if the background - // color is NOT set, draws nothing. -// graphics.drawBackgroundColor( bc, startX, startY, width, height ); - canvas.setColor( bc ); - } - if ( bi != null ) - { - // Draws background image for the container. if the background - // image is NOT set, draws nothing. - render.drawBackgroundImage( bi, startX, startY, width, height ); - } + if ( backgroundcolor != null ) + { + canvas.setColor( backgroundcolor ); + } + if ( bgimginfo != null ) + { + render.drawBackgroundImage( bgimginfo, startX, startY,width, height ); +// canvas.fillImage( bgimginfo., offsetX, offsetY, ToTile ); + //call internal function to only get imagefill: + //current implementation produce bug as it is inside shape tag } - + } - + protected void drawCellDiagonal( CellArea cell ) { DiagonalInfo diagonalInfo = cell.getDiagonalInfo( ); @@ -341,10 +340,73 @@ protected void drawCellDiagonal( CellArea cell ) getScaledValue( dw ), diagonalInfo.getDiagonalColor( ), ds ); break; } - + } } - + + /** + * assume leftborder is always draw + * @param container + */ + protected void drawBorders( IContainerArea container ) + { + BoxStyle style = container.getBoxStyle( ); + if( style == null) return; + + BorderInfo baseborderinfo = style.getLeftBorder( ); + + writeSingleBorder( LEFTBORDERLINE, baseborderinfo ); + + BorderInfo currentborderinfo = style.getRightBorder( ); + if( currentborderinfo != null) + { + writeSingleBorder( RIGHTBORDERLINE, currentborderinfo ); + baseborderinfo = currentborderinfo; + } + else + { //draw if border is empty: + writeSingleBorder( RIGHTBORDERLINE, baseborderinfo ); + } + + currentborderinfo = style.getTopBorder( ); + if( currentborderinfo != null) + { + writeSingleBorder( TOPBORDERLINE, currentborderinfo); + baseborderinfo = currentborderinfo; + } + else + { //draw if border is empty: + writeSingleBorder( TOPBORDERLINE, baseborderinfo ); + } + + currentborderinfo = style.getBottomBorder(); + if( currentborderinfo != null) + { + writeSingleBorder( BOTTOMBORDERLINE, style.getBottomBorder()); + } + else + { //draw if border is empty: + writeSingleBorder( BOTTOMBORDERLINE, baseborderinfo ); + } + + } + + private void writeSingleBorder( String borderSide, BorderInfo borderinfo ) + { + if( borderinfo == null) + { + return; + } + writer.openTag( borderSide ); + int width = PPTXUtil.convertToEnums( borderinfo.getWidth( )); + writer.attribute( "w", width ); //convert to EMU + canvas.setColor( borderinfo.getColor( ) ); + writer.openTag( "a:prstDash"); + //TODO: get the right style naming + writer.attribute( "val", PPTXUtil.parseStyle( borderinfo.getStyle( )) ); + writer.closeTag( "a:prstDash" ); + writer.closeTag( borderSide ); + } private int getY(IContainerArea area) { @@ -365,12 +427,12 @@ private int getWidth(CellArea area) { return getScaledValue( area.getWidth()); } - + protected int getScaledValue( int value ) { return (int) ( value * scale ); } - + protected void updateRenderXY(){ render.setCurrentX( currentX ); render.setCurrentY( currentY ); diff --git a/engine/org.eclipse.birt.report.engine.emitter.pptx/src/org/eclipse/birt/report/engine/emitter/pptx/util/PPTXUtil.java b/engine/org.eclipse.birt.report.engine.emitter.pptx/src/org/eclipse/birt/report/engine/emitter/pptx/util/PPTXUtil.java index f51f3c4ae56..bc10316a00e 100644 --- a/engine/org.eclipse.birt.report.engine.emitter.pptx/src/org/eclipse/birt/report/engine/emitter/pptx/util/PPTXUtil.java +++ b/engine/org.eclipse.birt.report.engine.emitter.pptx/src/org/eclipse/birt/report/engine/emitter/pptx/util/PPTXUtil.java @@ -1,27 +1,49 @@ -/******************************************************************************* - * Copyright (c) 2013 Actuate Corporation. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Actuate Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.birt.report.engine.emitter.pptx.util; - -import org.eclipse.birt.report.engine.ooxml.util.OOXmlUtil; - -public class PPTXUtil -{ - public static int convertToPointer(int milliPointerValue) - { - return milliPointerValue / 1000; - } - - public static int convertToEnums( double milliPointerValue ) - { - return (int) OOXmlUtil.convertPointerToEmus( milliPointerValue / 1000 ); - } -} +/******************************************************************************* + * Copyright (c) 2013 Actuate Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Actuate Corporation - initial API and implementation + *******************************************************************************/ + +package org.eclipse.birt.report.engine.emitter.pptx.util; + +import org.eclipse.birt.report.engine.nLayout.area.style.BoxStyle; +import org.eclipse.birt.report.engine.ooxml.util.OOXmlUtil; + +public class PPTXUtil +{ + public static int convertToPointer(int milliPointerValue) + { + return milliPointerValue / 1000; + } + + public static int convertToEnums( double milliPointerValue ) + { + return (int) OOXmlUtil.convertPointerToEmus( milliPointerValue / 1000 ); + } + + /** + * The default will be solid, double is not implemented as cell does not support it + * @param style + * @return + */ + public static String parseStyle( int style ) + { + //set by default solid + switch( style ){ + + case BoxStyle.BORDER_STYLE_DASHED : return "dash"; + + case BoxStyle.BORDER_STYLE_DOTTED : return "dot"; + + //double is not specified in the cell dash. + + } + + return "solid"; + } +}