Merge "Do not rotate PDFPrinter pages." into nyc-dev
am: 5d6a4f582e
* commit '5d6a4f582e0e1d6e8aee88fc16b3a7f4850dbd56':
Do not rotate PDFPrinter pages.
Change-Id: Ib428e9af14a8271545862189649780975053de86
This commit is contained in:
@@ -277,18 +277,12 @@ public final class PdfManipulationService extends Service {
|
|||||||
Rect cropBox = new Rect();
|
Rect cropBox = new Rect();
|
||||||
Matrix transform = new Matrix();
|
Matrix transform = new Matrix();
|
||||||
|
|
||||||
final boolean contentPortrait = attributes.getMediaSize().isPortrait();
|
|
||||||
|
|
||||||
final boolean layoutDirectionRtl = getResources().getConfiguration()
|
final boolean layoutDirectionRtl = getResources().getConfiguration()
|
||||||
.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
|
.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
|
||||||
|
|
||||||
// We do not want to rotate the media box, so take into account orientation.
|
// We do not want to rotate the media box, so take into account orientation.
|
||||||
final int dstWidthPts = contentPortrait
|
final int dstWidthPts = pointsFromMils(attributes.getMediaSize().getWidthMils());
|
||||||
? pointsFromMils(attributes.getMediaSize().getWidthMils())
|
final int dstHeightPts = pointsFromMils(attributes.getMediaSize().getHeightMils());
|
||||||
: pointsFromMils(attributes.getMediaSize().getHeightMils());
|
|
||||||
final int dstHeightPts = contentPortrait
|
|
||||||
? pointsFromMils(attributes.getMediaSize().getHeightMils())
|
|
||||||
: pointsFromMils(attributes.getMediaSize().getWidthMils());
|
|
||||||
|
|
||||||
final boolean scaleForPrinting = mEditor.shouldScaleForPrinting();
|
final boolean scaleForPrinting = mEditor.shouldScaleForPrinting();
|
||||||
|
|
||||||
@@ -310,24 +304,12 @@ public final class PdfManipulationService extends Service {
|
|||||||
// Make sure content is top-left after media box resize.
|
// Make sure content is top-left after media box resize.
|
||||||
transform.setTranslate(0, srcHeightPts - dstHeightPts);
|
transform.setTranslate(0, srcHeightPts - dstHeightPts);
|
||||||
|
|
||||||
// Rotate the content if in landscape.
|
|
||||||
if (!contentPortrait) {
|
|
||||||
transform.postRotate(270);
|
|
||||||
transform.postTranslate(0, dstHeightPts);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Scale the content if document allows it.
|
// Scale the content if document allows it.
|
||||||
final float scale;
|
final float scale;
|
||||||
if (scaleForPrinting) {
|
if (scaleForPrinting) {
|
||||||
if (contentPortrait) {
|
scale = Math.min((float) dstWidthPts / srcWidthPts,
|
||||||
scale = Math.min((float) dstWidthPts / srcWidthPts,
|
(float) dstHeightPts / srcHeightPts);
|
||||||
(float) dstHeightPts / srcHeightPts);
|
transform.postScale(scale, scale);
|
||||||
transform.postScale(scale, scale);
|
|
||||||
} else {
|
|
||||||
scale = Math.min((float) dstWidthPts / srcHeightPts,
|
|
||||||
(float) dstHeightPts / srcWidthPts);
|
|
||||||
transform.postScale(scale, scale, mediaBox.left, mediaBox.bottom);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
scale = 1.0f;
|
scale = 1.0f;
|
||||||
}
|
}
|
||||||
@@ -344,10 +326,8 @@ public final class PdfManipulationService extends Service {
|
|||||||
|
|
||||||
// If in RTL mode put the content in the logical top-right corner.
|
// If in RTL mode put the content in the logical top-right corner.
|
||||||
if (layoutDirectionRtl) {
|
if (layoutDirectionRtl) {
|
||||||
final float dx = contentPortrait
|
final float dx = dstWidthPts - (int) (srcWidthPts * scale + 0.5f);
|
||||||
? dstWidthPts - (int) (srcWidthPts * scale + 0.5f) : 0;
|
final float dy = 0;
|
||||||
final float dy = contentPortrait
|
|
||||||
? 0 : - (dstHeightPts - (int) (srcWidthPts * scale + 0.5f));
|
|
||||||
transform.postTranslate(dx, dy);
|
transform.postTranslate(dx, dy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user