use of org.ebookdroid.core.Page in project LibreraReader by foobnix.
the class VerticalModeController method saveChanges.
@Override
public void saveChanges(final List<PointF> points, final int color) {
if (SettingsManager.getBookSettings().cropPages) {
onCrop();
return;
}
final float zoom = ctr.getZoomModel().getZoom();
int scrollX = ctr.getDocumentController().getView().getScrollX();
int scrollY = ctr.getDocumentController().getView().getScrollY();
final Map<Integer, List<PointF>> result = new HashMap<Integer, List<PointF>>();
final int first = ctr.getDocumentController().getFirstVisiblePage();
final int last = ctr.getDocumentController().getLastVisiblePage() + 1;
LOG.d("first", first, "last", last);
for (PointF p : points) {
RectF tapRect = new RectF(p.x, p.y, p.x, p.y);
tapRect.offset(scrollX, scrollY);
Iterable<Page> pages = ctr.getDocumentModel().getPages(first, last);
for (Page page : pages) {
RectF pbounds = page.getBounds(zoom);
float aspect = page.getAspectRatio();
float k = page.cpi.width / pbounds.width();
LOG.d("PAGE #", page.index.viewIndex);
LOG.d("PAGE wxh", page.cpi.width, page.cpi.height);
LOG.d("PAGE dpi", page.cpi.dpi, page.cpi.dpi);
LOG.d("pbounds p", pbounds, "zoom", zoom, "aspect", aspect);
LOG.d("pbounds p", pbounds, "zoom", zoom, "aspect", aspect);
if (RectF.intersects(pbounds, tapRect)) {
int pNumber = page.index.docIndex;
List<PointF> list = result.get(pNumber);
if (list == null) {
list = new ArrayList<PointF>();
}
p.x += scrollX;
p.y += scrollY - pbounds.top;
p.x = p.x * k;
p.y = p.y * k;
list.add(p);
result.put(pNumber, list);
}
}
}
float width = AppState.get().editLineWidth * 3;
float alpha = AppState.get().editAlphaColor;
ctr.getDecodeService().addAnnotation(result, color, width, alpha, new ResultResponse<Pair<Integer, List<Annotation>>>() {
@Override
public boolean onResultRecive(Pair<Integer, List<Annotation>> p) {
ctr.getDocumentModel().getPageObject(p.first).annotations = p.second;
ctr.getDocumentController().toggleRenderingEffects();
return false;
}
});
}
use of org.ebookdroid.core.Page in project LibreraReader by foobnix.
the class VerticalModeController method underlineText.
@Override
public void underlineText(int color, float width, AnnotationType type) {
if (ctr == null || ctr.getDocumentController() == null || ctr.getDocumentModel() == null) {
LOG.d("Can't underlineText");
return;
}
final int first = ctr.getDocumentController().getFirstVisiblePage();
final int last = ctr.getDocumentController().getLastVisiblePage();
for (int i = first; i < last + 1; i++) {
final Page page = ctr.getDocumentModel().getPageByDocIndex(i);
if (page == null || page.selectedText == null) {
continue;
}
List<TextWord> texts = page.selectedText;
final ArrayList<PointF> quadPoints = new ArrayList<PointF>();
for (TextWord text : texts) {
RectF rect = text.getOriginal();
quadPoints.add(new PointF(rect.left, rect.bottom));
quadPoints.add(new PointF(rect.right, rect.bottom));
quadPoints.add(new PointF(rect.right, rect.top));
quadPoints.add(new PointF(rect.left, rect.top));
}
PointF[] array = quadPoints.toArray(new PointF[quadPoints.size()]);
ctr.getDecodeService().underlineText(i, array, color, type, new ResultResponse<List<Annotation>>() {
@Override
public boolean onResultRecive(List<Annotation> arg0) {
page.annotations = arg0;
page.selectedText = new ArrayList<TextWord>();
ctr.getDocumentController().toggleRenderingEffects();
return false;
}
});
}
}
use of org.ebookdroid.core.Page in project LibreraReader by foobnix.
the class PdfSurfaceView method getScrollScaleRatio.
/**
* {@inheritDoc}
*
* @see org.ebookdroid.ui.viewer.IView#getScrollScaleRatio()
*/
@Override
public float getScrollScaleRatio() {
final Page page = base.getDocumentModel().getCurrentPageObject();
final float zoom = base.getZoomModel().getZoom();
if (page == null || page.getBounds(zoom) == null) {
return 0;
}
return getWidth() * zoom / page.getBounds(zoom).width();
}
use of org.ebookdroid.core.Page in project LibreraReader by foobnix.
the class DocumentModel method initPages.
public void initPages(final IActivityController base, final IProgressIndicator task) {
recyclePages();
final BookSettings bs = SettingsManager.getBookSettings();
if (base == null || bs == null || context == null || decodeService == null) {
return;
}
final IView view = base.getView();
final CodecPageInfo defCpi = new CodecPageInfo();
defCpi.width = (view.getWidth());
defCpi.height = (view.getHeight());
int viewIndex = 0;
try {
final ArrayList<Page> list = new ArrayList<Page>();
final CodecPageInfo[] infos = retrievePagesInfo(base, bs, task);
for (int docIndex = 0; docIndex < infos.length; docIndex++) {
if (TempHolder.get().loadingCancelled) {
return;
}
if (!AppState.get().isCut) {
CodecPageInfo cpi = infos[docIndex] != null ? infos[docIndex] : defCpi;
final Page page = new Page(base, new PageIndex(docIndex, viewIndex++), PageType.FULL_PAGE, cpi);
list.add(page);
} else {
final Page page1 = new Page(base, new PageIndex(docIndex, viewIndex++), PageType.LEFT_PAGE, infos[docIndex]);
final Page page2 = new Page(base, new PageIndex(docIndex, viewIndex++), PageType.RIGHT_PAGE, infos[docIndex]);
if (AppState.get().isCutRTL) {
list.add(page2);
list.add(page1);
} else {
list.add(page1);
list.add(page2);
}
}
}
pages = list.toArray(new Page[list.size()]);
} finally {
}
}
use of org.ebookdroid.core.Page in project LibreraReader by foobnix.
the class DocumentModel method recyclePages.
public void recyclePages() {
if (LengthUtils.isNotEmpty(pages)) {
final List<Bitmaps> bitmapsToRecycle = new ArrayList<Bitmaps>();
for (final Page page : pages) {
page.recycle(bitmapsToRecycle);
}
BitmapManager.release(bitmapsToRecycle);
BitmapManager.release();
}
pages = EMPTY_PAGES;
}
Aggregations