diff options
Diffstat (limited to 'android/experimental/LOAndroid3/src/java')
9 files changed, 73 insertions, 57 deletions
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java index 9dde7906d020..9d0dec73c086 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java @@ -17,15 +17,8 @@ public class LOKitShell { private static final String LOGTAG = LOKitShell.class.getSimpleName(); public static int getDpi() { - return 96; - } - - public static int getScreenDepth() { - return 24; - } - - public static float computeRenderIntegrity() { - return 0.0f; + DisplayMetrics metrics = LibreOfficeMainActivity.mAppContext.getResources().getDisplayMetrics(); + return (int) metrics.density * 200; } public static ByteBuffer allocateDirectBuffer(int size) { @@ -44,7 +37,6 @@ public class LOKitShell { return directBuffer; } - public static void freeDirectBuffer(ByteBuffer buffer) { if (buffer == null) { return; diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java index 90825759d21e..7539d718b9b8 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java @@ -8,6 +8,7 @@ import android.graphics.Rect; import android.util.JsonWriter; import android.util.Log; +import org.mozilla.gecko.gfx.SubTile; import org.mozilla.gecko.gfx.ViewportMetrics; import java.io.IOException; @@ -47,15 +48,8 @@ public class LOKitThread extends Thread { Log.i(LOGTAG, "Filling tiles.."); - int x = 0; - int y = 0; - for (Bitmap bitmap : mTileProvider.getTileIterator()) { - application.getLayerClient().addTile(bitmap, x, y); - x += TILE_SIZE; - if (x > pageWidth) { - x = 0; - y += TILE_SIZE; - } + for (SubTile tile : mTileProvider.getTileIterator()) { + application.getLayerClient().addTile(tile); } Log.i(LOGTAG, "End Draw"); diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java index 4b6d8faac932..e43e40165efa 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java @@ -3,6 +3,8 @@ package org.libreoffice; import android.graphics.Bitmap; import android.util.Log; +import org.mozilla.gecko.gfx.BufferedCairoImage; +import org.mozilla.gecko.gfx.CairoImage; import org.mozilla.gecko.gfx.LayerController; import java.nio.ByteBuffer; @@ -11,6 +13,7 @@ import java.util.Iterator; import org.libreoffice.kit.LibreOfficeKit; import org.libreoffice.kit.Office; import org.libreoffice.kit.Document; +import org.mozilla.gecko.gfx.SubTile; public class LOKitTileProvider implements TileProvider { private final LayerController mLayerController; @@ -20,8 +23,19 @@ public class LOKitTileProvider implements TileProvider { public final Office mOffice; public final Document mDocument; + private double mDPI; + + private double twipToPixel(double input, double dpi) { + return input / 1440.0 * dpi; + } + + private double pixelToTwip(double input, double dpi) { + return (input / dpi) * 1440.0; + } + public LOKitTileProvider(LayerController layerController) { - this.mLayerController = layerController; + mLayerController = layerController; + mDPI = (double) LOKitShell.getDpi(); LibreOfficeKit.putenv("SAL_LOG=+WARN+INFO-INFO.legacy.osl-INFO.i18nlangtag"); LibreOfficeKit.init(LibreOfficeMainActivity.mAppContext); @@ -32,62 +46,69 @@ public class LOKitTileProvider implements TileProvider { @Override public int getPageWidth() { - return (int) (mDocument.getDocumentWidth() / 1440.0 * LOKitShell.getDpi()); + return (int) twipToPixel(mDocument.getDocumentWidth(), mDPI); } @Override public int getPageHeight() { - return (int) (mDocument.getDocumentHeight() / 1440.0 * LOKitShell.getDpi()); + return (int) twipToPixel(mDocument.getDocumentHeight(), mDPI); } public TileIterator getTileIterator() { return new LoKitTileIterator(); } - public class LoKitTileIterator implements TileIterator, Iterator<Bitmap> { + public class LoKitTileIterator implements TileIterator, Iterator<SubTile> { private final double mTileWidth; private final double mTileHeight; - private boolean mShouldContinue = true; - private double mPositionWidth = 0; private double mPositionHeight = 0; + private int mX = 0; + private int mY = 0; private double mPageWidth; private double mPageHeight; public LoKitTileIterator() { - mTileWidth = (TILE_SIZE / (double) LOKitShell.getDpi()) * 1440.0; - mTileHeight = (TILE_SIZE / (double) LOKitShell.getDpi()) * 1440.0; + mTileWidth = pixelToTwip(TILE_SIZE, mDPI); + mTileHeight = pixelToTwip(TILE_SIZE, mDPI); + mPageWidth = mDocument.getDocumentWidth(); mPageHeight = mDocument.getDocumentHeight(); } @Override public boolean hasNext() { - return mShouldContinue; + return mPositionHeight <= mPageHeight; } @Override - public Bitmap next() { + public SubTile next() { ByteBuffer buffer = ByteBuffer.allocateDirect(TILE_SIZE * TILE_SIZE * 4); Bitmap bitmap = Bitmap.createBitmap(TILE_SIZE, TILE_SIZE, Bitmap.Config.ARGB_8888); - mDocument.paintTile(buffer, TILE_SIZE, TILE_SIZE, (int) mPositionWidth, (int) mPositionHeight, (int) mTileWidth, (int) mTileHeight); + mDocument.paintTile(buffer, TILE_SIZE, TILE_SIZE, (int) Math.round(mPositionWidth), (int) Math.round(mPositionHeight), (int) Math.round(mTileWidth + pixelToTwip(1, mDPI)), (int) Math.round(mTileHeight+ pixelToTwip(1, mDPI))); + + + bitmap.copyPixelsFromBuffer(buffer); + + CairoImage image = new BufferedCairoImage(bitmap); + SubTile tile = new SubTile(image, mX, mY); + tile.beginTransaction(); mPositionWidth += mTileWidth; + mX += TILE_SIZE; if (mPositionWidth > mPageWidth) { mPositionHeight += mTileHeight; - mPositionWidth = 0; - } + mY += TILE_SIZE; - if (mPositionHeight > mPageHeight || mPositionHeight > 20000) { - mShouldContinue = false; + mPositionWidth = 0; + mX = 0; } - bitmap.copyPixelsFromBuffer(buffer); - return bitmap; + return tile; } @Override @@ -96,7 +117,7 @@ public class LOKitTileProvider implements TileProvider { } @Override - public Iterator<Bitmap> iterator() { + public Iterator<SubTile> iterator() { return this; } } diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/MockTileProvider.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/MockTileProvider.java index 04ebfb464a23..ab535a9d46fc 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/MockTileProvider.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/MockTileProvider.java @@ -3,13 +3,17 @@ package org.libreoffice; import android.graphics.Bitmap; import org.apache.http.MethodNotSupportedException; +import org.mozilla.gecko.gfx.BufferedCairoImage; +import org.mozilla.gecko.gfx.CairoImage; import org.mozilla.gecko.gfx.LayerController; +import org.mozilla.gecko.gfx.SubTile; import java.util.Iterator; import java.util.List; public class MockTileProvider implements TileProvider { private final LayerController layerController; + private static final int TILE_SIZE = 256; public MockTileProvider(LayerController layerController) { this.layerController = layerController; @@ -29,11 +33,14 @@ public class MockTileProvider implements TileProvider { return new MockTileIterator(layerController); } - public class MockTileIterator implements TileIterator, Iterator<Bitmap> { + public class MockTileIterator implements TileIterator, Iterator<SubTile> { private final LayerController layerController; private int tileNumber = 1; + private int x = 0; + private int y = 0; + public MockTileIterator(LayerController layerController) { this.layerController = layerController; } @@ -44,11 +51,23 @@ public class MockTileProvider implements TileProvider { } @Override - public Bitmap next() { + public SubTile next() { String imageName = "d" + tileNumber; tileNumber++; Bitmap bitmap = layerController.getDrawable(imageName); - return bitmap; + + CairoImage image = new BufferedCairoImage(bitmap); + SubTile tile = new SubTile(image, x, y); + tile.beginTransaction(); + + x += TILE_SIZE; + + if (x > getPageWidth()) { + x = 0; + y += TILE_SIZE; + } + + return tile; } @Override @@ -57,7 +76,7 @@ public class MockTileProvider implements TileProvider { } @Override - public Iterator<Bitmap> iterator() { + public Iterator<SubTile> iterator() { return this; } } diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/TileIterator.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/TileIterator.java index 68c39e53bccc..b0915619e2b0 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/TileIterator.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/TileIterator.java @@ -1,6 +1,6 @@ package org.libreoffice; -import android.graphics.Bitmap; +import org.mozilla.gecko.gfx.SubTile; -public interface TileIterator extends Iterable<Bitmap> { +public interface TileIterator extends Iterable<SubTile> { } diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/TileProvider.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/TileProvider.java index a405fdf827da..dbaa04050ce4 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/TileProvider.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/TileProvider.java @@ -1,13 +1,8 @@ package org.libreoffice; -import android.graphics.Bitmap; - -import java.util.List; - -public interface TileProvider { +public interface TileProvider { int getPageWidth(); - int getPageHeight(); TileIterator getTileIterator(); diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/GeckoSoftwareLayerClient.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/GeckoSoftwareLayerClient.java index 42bc0b6ac52d..58e62632cd52 100644 --- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/GeckoSoftwareLayerClient.java +++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/GeckoSoftwareLayerClient.java @@ -139,9 +139,9 @@ public class GeckoSoftwareLayerClient extends GeckoLayerClient { return TILE_SIZE; } - public void addTile(Bitmap bitmap, int x, int y) { + public void addTile(SubTile tile) { if (mTileLayer instanceof MultiTileLayer) { - ((MultiTileLayer)mTileLayer).addTile(bitmap, x, y); + ((MultiTileLayer)mTileLayer).addTile(tile); } } } diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/MultiTileLayer.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/MultiTileLayer.java index a958a54eb303..56ff5ec9c01e 100644 --- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/MultiTileLayer.java +++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/MultiTileLayer.java @@ -241,9 +241,7 @@ public class MultiTileLayer extends Layer { return validRegion; } - public void addTile(Bitmap bitmap, int x, int y) { - SubTile tile = new SubTile(new BufferedCairoImage(bitmap), x,y); - tile.beginTransaction(); + public void addTile(SubTile tile) { mTiles.add(tile); } } diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/SubTile.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/SubTile.java index 0c40c3c1b7df..b2464bc4c31c 100644 --- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/SubTile.java +++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/SubTile.java @@ -1,8 +1,5 @@ package org.mozilla.gecko.gfx; -/** -* Created by quikee on 29.6.2014. -*/ public class SubTile extends SingleTileLayer { public int x; public int y; |