From 275be47007705056326657de1947c4ada6381ef8 Mon Sep 17 00:00:00 2001 From: Yegor Kozlov Date: Wed, 30 Apr 2008 06:21:04 +0000 Subject: [PATCH] more flexible creation of a cluster git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@652290 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/poi/ddf/EscherDggRecord.java | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/java/org/apache/poi/ddf/EscherDggRecord.java b/src/java/org/apache/poi/ddf/EscherDggRecord.java index 0eff3feeef..0ff00016d5 100644 --- a/src/java/org/apache/poi/ddf/EscherDggRecord.java +++ b/src/java/org/apache/poi/ddf/EscherDggRecord.java @@ -38,6 +38,7 @@ public class EscherDggRecord private int field_3_numShapesSaved; private int field_4_drawingsSaved; private FileIdCluster[] field_5_fileIdClusters; + private int maxDgId; public static class FileIdCluster { @@ -87,6 +88,7 @@ public class EscherDggRecord for (int i = 0; i < field_5_fileIdClusters.length; i++) { field_5_fileIdClusters[i] = new FileIdCluster(LittleEndian.getInt( data, pos + size ), LittleEndian.getInt( data, pos + size + 4 )); + maxDgId = Math.max(maxDgId, field_5_fileIdClusters[i].getDrawingGroupId()); size += 8; } bytesRemaining -= size; @@ -229,7 +231,14 @@ public class EscherDggRecord this.field_4_drawingsSaved = field_4_drawingsSaved; } - public FileIdCluster[] getFileIdClusters() + /** + * @return The maximum drawing group ID + */ + public int getMaxDrawingGroupId(){ + return maxDgId; + } + + public FileIdCluster[] getFileIdClusters() { return field_5_fileIdClusters; } @@ -240,10 +249,23 @@ public class EscherDggRecord } public void addCluster( int dgId, int numShapedUsed ) + { + addCluster(dgId, numShapedUsed, true); + } + + /** + * Add a new cluster + * + * @param dgId id of the drawing group (stored in the record options) + * @param numShapedUsed initial value of the numShapedUsed field + * @param sort if true then sort clusters by drawing group id.( + * In Excel the clusters are sorted but in PPT they are not) + */ + public void addCluster( int dgId, int numShapedUsed, boolean sort ) { List clusters = new ArrayList(Arrays.asList(field_5_fileIdClusters)); clusters.add(new FileIdCluster(dgId, numShapedUsed)); - Collections.sort(clusters, new Comparator() + if(sort) Collections.sort(clusters, new Comparator() { public int compare( Object o1, Object o2 ) { @@ -257,6 +279,7 @@ public class EscherDggRecord return +1; } } ); + maxDgId = Math.min(maxDgId, dgId); field_5_fileIdClusters = (FileIdCluster[]) clusters.toArray( new FileIdCluster[clusters.size()] ); } } -- 2.39.5