Hi

I am not sure where a check is missing. It could be added to the
Label.setOffset()  method
or to the POIRecord.write() method.
Please can you habe a look at it?

I've written a patch (attached) which implements writing out
the labels with offsets divided by 2.  Will therefore
allow twice as much label space.

There is also a check for overflow in the patch.

The required code to read labels with this flag set was already implemented, so the patch is quite small.

I think it is probably best to not attempt to work out if the multiplier is required or not and just always use it.

..Steve
Index: src/uk/me/parabola/imgfmt/app/lbl/LBLHeader.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/uk/me/parabola/imgfmt/app/lbl/LBLHeader.java	(revision 2678)
+++ src/uk/me/parabola/imgfmt/app/lbl/LBLHeader.java	(revision )
@@ -112,7 +112,7 @@
 		writer.putInt(HEADER_LEN + sortDescriptionLength);
 		writer.putInt(getLabelSize());
 
-		writer.put((byte) 0);
+		writer.put((byte) offsetMultiplier);
 		writer.put((byte) encodingType);
 
 		placeHeader.writeFileHeader(writer);
@@ -177,5 +177,9 @@
 
 	public PlacesHeader getPlaceHeader() {
 		return placeHeader;
+	}
+
+	public void setOffsetMultiplier(int offsetMultiplier) {
+		this.offsetMultiplier = offsetMultiplier;
 	}
 }
Index: src/uk/me/parabola/imgfmt/app/lbl/LBLFile.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/uk/me/parabola/imgfmt/app/lbl/LBLFile.java	(revision 2678)
+++ src/uk/me/parabola/imgfmt/app/lbl/LBLFile.java	(revision )
@@ -19,6 +19,7 @@
 import java.util.HashMap;
 import java.util.Map;
 
+import uk.me.parabola.imgfmt.MapFailedException;
 import uk.me.parabola.imgfmt.Utils;
 import uk.me.parabola.imgfmt.app.BufferedImgFileWriter;
 import uk.me.parabola.imgfmt.app.Exit;
@@ -57,9 +58,13 @@
 	private final PlacesFile places = new PlacesFile();
 	private Sort sort;
 
+	// Shift value for the label offset.
+	private final int offsetMultiplier = 1;
+
 	public LBLFile(ImgChannel chan, Sort sort) {
 		this.sort = sort;
 		lblHeader.setSort(sort);
+		lblHeader.setOffsetMultiplier(offsetMultiplier);
 		setHeader(lblHeader);
 
 		setWriter(new BufferedImgFileWriter(chan));
@@ -68,6 +73,7 @@
 
 		// The zero offset is for no label.
 		getWriter().put((byte) 0);
+		alignForNext();
 
 		places.init(this, lblHeader.getPlaceHeader());
 		places.setSort(sort);
@@ -133,11 +139,35 @@
 			l = new Label(text);
 			labelCache.put(text, l);
 
-			l.setOffset(position() - (LBLHeader.HEADER_LEN + lblHeader.getSortDescriptionLength()));
+			l.setOffset(getNextLabelOffset());
 			l.write(getWriter(), textEncoder);
+
+			alignForNext();
+
+			if (l.getOffset() > 0x3fffff)
+				throw new MapFailedException("Overflow of LBL section");
 		}
 
 		return l;
+	}
+
+	/**
+	 * Align for the next label.
+	 *
+	 * Only has any effect when offsetMultiplier is not zero.
+	 */
+	private void alignForNext() {
+		// Align ready for next label
+		while ((getCurrentLabelOffset() & ((1 << offsetMultiplier) - 1)) != 0)
+			getWriter().put((byte) 0);
+	}
+
+	private int getNextLabelOffset() {
+		return getCurrentLabelOffset() >> offsetMultiplier;
+	}
+
+	private int getCurrentLabelOffset() {
+		return position() - (LBLHeader.HEADER_LEN + lblHeader.getSortDescriptionLength());
 	}
 
 	public POIRecord createPOI(String name) {
_______________________________________________
mkgmap-dev mailing list
[email protected]
http://lists.mkgmap.org.uk/mailman/listinfo/mkgmap-dev

Reply via email to