From 8f457be7c2b26ac65df74b122a1e4832bab67f84 Mon Sep 17 00:00:00 2001 From: Carlos Amengual Date: Wed, 18 Dec 2024 22:36:10 +0100 Subject: [PATCH] wmf: remove `RecordStore` class deprecated since 2007, clean up `MetaRecord` --- .../transcoder/wmf/tosvg/MetaRecord.java | 31 +- .../transcoder/wmf/tosvg/RecordStore.java | 283 ------------------ 2 files changed, 13 insertions(+), 301 deletions(-) delete mode 100644 echosvg-transcoder/src/main/java/io/sf/carte/echosvg/transcoder/wmf/tosvg/RecordStore.java diff --git a/echosvg-transcoder/src/main/java/io/sf/carte/echosvg/transcoder/wmf/tosvg/MetaRecord.java b/echosvg-transcoder/src/main/java/io/sf/carte/echosvg/transcoder/wmf/tosvg/MetaRecord.java index 8ee135503..83e2c9d79 100644 --- a/echosvg-transcoder/src/main/java/io/sf/carte/echosvg/transcoder/wmf/tosvg/MetaRecord.java +++ b/echosvg-transcoder/src/main/java/io/sf/carte/echosvg/transcoder/wmf/tosvg/MetaRecord.java @@ -31,29 +31,18 @@ * @author For later modifications, see Git history. * @version $Id$ */ -public class MetaRecord /* implements Serializable */ { +public class MetaRecord implements java.io.Serializable { + + private static final long serialVersionUID = 1L; public int functionId; public int numPoints; - private final List ptVector = new ArrayList<>(); + private final List ptVector = new ArrayList<>(); public MetaRecord() { } - public void EnsureCapacity(int cc) { - } - - /** - * when you are storing Integer-objects, consider using addElement( int ) - * instead. - * - * @param obj - */ - public void AddElement(Object obj) { - ptVector.add(obj); - } - /** * helper method to add int-values. This way we keep the call to * Integer.valueOf() in one place, here. @@ -70,7 +59,7 @@ public final void addElement(int iValue) { * int. */ public Integer ElementAt(int offset) { - return (Integer) ptVector.get(offset); + return ptVector.get(offset); } /** @@ -81,13 +70,16 @@ public Integer ElementAt(int offset) { * @return the intValue of the element at offset */ public final int elementAt(int offset) { - return (Integer) ptVector.get(offset); + return ptVector.get(offset); } /** * A record that contain byte arrays elements. */ public static class ByteRecord extends MetaRecord { + + private static final long serialVersionUID = 1L; + public final byte[] bstr; public ByteRecord(byte[] bstr) { @@ -95,7 +87,10 @@ public ByteRecord(byte[] bstr) { } } - public static class StringRecord extends MetaRecord /* implements Serializable */ { + public static class StringRecord extends MetaRecord { + + private static final long serialVersionUID = 1L; + public final String text; public StringRecord(String newText) { diff --git a/echosvg-transcoder/src/main/java/io/sf/carte/echosvg/transcoder/wmf/tosvg/RecordStore.java b/echosvg-transcoder/src/main/java/io/sf/carte/echosvg/transcoder/wmf/tosvg/RecordStore.java deleted file mode 100644 index 14e28717c..000000000 --- a/echosvg-transcoder/src/main/java/io/sf/carte/echosvg/transcoder/wmf/tosvg/RecordStore.java +++ /dev/null @@ -1,283 +0,0 @@ -/* - - See the NOTICE file distributed with this work for additional - information regarding copyright ownership. - - Licensed 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 - - 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. - - */ - -package io.sf.carte.echosvg.transcoder.wmf.tosvg; - -import java.io.DataInputStream; -import java.io.IOException; -import java.net.URL; -import java.util.Vector; - -import io.sf.carte.echosvg.transcoder.wmf.WMFConstants; - -/** - * An object that stores the vector graphics records. - * - * @deprecated jan '07 : this class is not used anywhere in EchoSVG, it might be - * removed in the future. Probably WMFRecordStore is what you need. - * - * @author Luan O'Carroll - * @author For later modifications, see Git history. - * @version $Id$ - */ -@Deprecated -public class RecordStore { - - public RecordStore() { - reset(); - } - - /** - * Resets the internal storage and viewport coordinates. - */ - public void reset() { - numRecords = 0; - vpX = 0; - vpY = 0; - vpW = 1000; - vpH = 1000; - numObjects = 0; - records = new Vector<>(20, 20); - objectVector = new Vector<>(); - } - - synchronized void setReading(boolean state) { - bReading = state; - } - - synchronized boolean isReading() { - return bReading; - } - - /** - * Reads the Wmf file from the specified Stream. A Wmf file can be produced - * using the GConvert utility found at http://www.asd.ie/Wmf.htm - * - * The Wmf format is slightly more compact than the original WMF format and in - * some cases may produce better handling of colours. - */ - public boolean read(DataInputStream is) throws IOException { - setReading(true); - reset(); - - int functionId = 0; - numRecords = 0; - - numObjects = is.readShort(); - objectVector.ensureCapacity(numObjects); - for (int i = 0; i < numObjects; i++) { - objectVector.add(new GdiObject(i, false)); - } - - while (functionId != -1) { - functionId = is.readShort(); - if (functionId == -1) { - break; - } - - MetaRecord mr; - switch (functionId) { - case WMFConstants.META_TEXTOUT: - case WMFConstants.META_DRAWTEXT: - case WMFConstants.META_EXTTEXTOUT: - case WMFConstants.META_CREATEFONTINDIRECT: { - short len = is.readShort(); - byte[] b = new byte[len]; - for (int i = 0; i < len; i++) { - b[i] = is.readByte(); - } - String str = new String(b); - mr = new MetaRecord.StringRecord(str); - } - break; - - default: - mr = new MetaRecord(); - break; - } - - int numPts = is.readShort(); - mr.numPoints = numPts; - mr.functionId = functionId; - - for (int j = 0; j < numPts; j++) { - mr.AddElement((int) is.readShort()); - } - - records.add(mr); - - numRecords++; - } - - setReading(false); - return true; - } - - /** - * Adds a GdiObject to the internal handle table. Adds the object at the next - * free location. - * - * This function should not normally be called by an application. - */ - public void addObject(int type, Object obj) { - for (int i = 0; i < numObjects; i++) { - GdiObject gdi = objectVector.get(i); - if (!gdi.used) { - gdi.Setup(type, obj); - lastObjectIdx = i; - break; - } - } - } - - /** - * Adds a GdiObject to the internal handle table. Wmf files specify the index as - * given in EMF records such as EMRCREATEPENINDIRECT whereas WMF files always - * use 0. - * - * This function should not normally be called by an application. - */ - public void addObjectAt(int type, Object obj, int idx) { - if ((idx == 0) || (idx > numObjects)) { - addObject(type, obj); - return; - } - lastObjectIdx = idx; - for (int i = 0; i < numObjects; i++) { - GdiObject gdi = objectVector.get(i); - if (i == idx) { - gdi.Setup(type, obj); - break; - } - } - } - - /** - * Returns the current URL - */ - public URL getUrl() { - return url; - } - - /** - * Sets the current URL - */ - public void setUrl(URL newUrl) { - url = newUrl; - } - - /** - * Returns a GdiObject from the handle table - */ - public GdiObject getObject(int idx) { - return objectVector.get(idx); - } - - /** - * Returns a meta record. - */ - public MetaRecord getRecord(int idx) { - return records.get(idx); - } - - /** - * Returns a number of records in the image - */ - public int getNumRecords() { - return numRecords; - } - - /** - * Returns the number of GdiObjects in the handle table - */ - public int getNumObjects() { - return numObjects; - } - - /** - * Returns the viewport x origin - */ - public int getVpX() { - return vpX; - } - - /** - * Returns the viewport y origin - */ - public int getVpY() { - return vpY; - } - - /** - * Returns the viewport width - */ - public int getVpW() { - return vpW; - } - - /** - * Returns the viewport height - */ - public int getVpH() { - return vpH; - } - - /** - * Sets the viewport x origin - */ - public void setVpX(int newValue) { - vpX = newValue; - } - - /** - * Sets the viewport y origin - */ - public void setVpY(int newValue) { - vpY = newValue; - } - - /** - * Sets the viewport width - */ - public void setVpW(int newValue) { - vpW = newValue; - } - - /** - * Sets the viewport height - */ - public void setVpH(int newValue) { - vpH = newValue; - } - - private transient URL url; - - protected transient int numRecords; - protected transient int numObjects; - public transient int lastObjectIdx; - protected transient int vpX; - protected transient int vpY; - protected transient int vpW; - protected transient int vpH; - - protected transient Vector records; - protected transient Vector objectVector; - - protected transient boolean bReading = false; -}