summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@google.com>2022-10-17 18:22:08 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2022-10-17 18:22:08 +0000
commitc1100649efb3f984c4da5ad5c7357b04f580aed4 (patch)
tree9f709a01eedb36c8adacfffcda9283703293e91f
parent5c4289a572e1841118f51aa96443125bce06600f (diff)
parentfaebfda353cda2bf5c8a2447e87d8f77018ee4e9 (diff)
downloadBuiltInPrintService-c1100649efb3f984c4da5ad5c7357b04f580aed4.tar.gz
Merge "if source document == selected paper size, do not scale" into tm-qpr-dev
-rwxr-xr-x[-rw-r--r--]jni/include/lib_printable_area.h4
-rwxr-xr-x[-rw-r--r--]jni/include/lib_wprint.h3
-rwxr-xr-x[-rw-r--r--]jni/lib/lib_wprint.c4
-rwxr-xr-x[-rw-r--r--]jni/lib/printable_area.c17
-rwxr-xr-x[-rw-r--r--]jni/lib/wprintJNI.c15
-rwxr-xr-x[-rw-r--r--]jni/plugins/plugin_pcl.c0
-rwxr-xr-x[-rw-r--r--]jni/plugins/wprint_image.c33
-rwxr-xr-x[-rw-r--r--]jni/plugins/wprint_image.h0
-rwxr-xr-x[-rw-r--r--]src/com/android/bips/ipp/StartJobTask.java14
-rwxr-xr-x[-rw-r--r--]src/com/android/bips/jni/LocalJobParams.java5
10 files changed, 89 insertions, 6 deletions
diff --git a/jni/include/lib_printable_area.h b/jni/include/lib_printable_area.h
index 8167a01..6ecf16e 100644..100755
--- a/jni/include/lib_printable_area.h
+++ b/jni/include/lib_printable_area.h
@@ -24,8 +24,8 @@
/*
* Fills printable area parameter in job_params given margins
*/
-extern void printable_area_get(wprint_job_params_t *job_params, float top_margin,
- float left_margin, float right_margin, float bottom_margin);
+extern void printable_area_get(wprint_job_params_t *job_params,
+ float top_margin, float left_margin, float right_margin, float bottom_margin);
/*
* Returns default margins for given printer specified in the job params struct
diff --git a/jni/include/lib_wprint.h b/jni/include/lib_wprint.h
index f9cb7b3..b60e539 100644..100755
--- a/jni/include/lib_wprint.h
+++ b/jni/include/lib_wprint.h
@@ -203,6 +203,9 @@ typedef struct {
bool accepts_app_version;
bool accepts_os_name;
bool accepts_os_version;
+
+ float source_width;
+ float source_height;
} wprint_job_params_t;
typedef struct wprint_connect_info_st wprint_connect_info_t;
diff --git a/jni/lib/lib_wprint.c b/jni/lib/lib_wprint.c
index cc6b10a..ebdec13 100644..100755
--- a/jni/lib/lib_wprint.c
+++ b/jni/lib/lib_wprint.c
@@ -1900,8 +1900,8 @@ status_t wprintGetFinalJobParams(wprint_job_params_t *job_params,
printable_area_get_default_margins(job_params, printer_cap, &margins[TOP_MARGIN],
&margins[LEFT_MARGIN], &margins[RIGHT_MARGIN], &margins[BOTTOM_MARGIN]);
- printable_area_get(job_params, margins[TOP_MARGIN], margins[LEFT_MARGIN], margins[RIGHT_MARGIN],
- margins[BOTTOM_MARGIN]);
+ printable_area_get(job_params, margins[TOP_MARGIN], margins[LEFT_MARGIN],
+ margins[RIGHT_MARGIN], margins[BOTTOM_MARGIN]);
job_params->accepts_app_name = printer_cap->docSourceAppName;
job_params->accepts_app_version = printer_cap->docSourceAppVersion;
diff --git a/jni/lib/printable_area.c b/jni/lib/printable_area.c
index ee6781b..81534b7 100644..100755
--- a/jni/lib/printable_area.c
+++ b/jni/lib/printable_area.c
@@ -23,8 +23,8 @@
#define TAG "printable_area"
-void printable_area_get(wprint_job_params_t *job_params, float top_margin, float left_margin,
- float right_margin, float bottom_margin) {
+void printable_area_get(wprint_job_params_t *job_params, float top_margin,
+ float left_margin, float right_margin, float bottom_margin) {
if (job_params == NULL) return;
job_params->printable_area_width = job_params->printable_area_height = 0.0f;
@@ -41,6 +41,14 @@ void printable_area_get(wprint_job_params_t *job_params, float top_margin, float
job_params->page_height = SupportedMediaSizes[i].HeightInInches / 1000;
}
}
+
+ // Threshold value for catering slight variation b/w source dims and page dims
+ const float PAGE_SIZE_EPSILON = 0.04f;
+ if (fabsf(job_params->source_width - job_params->page_width) < PAGE_SIZE_EPSILON &&
+ fabsf(job_params->source_height - job_params->page_height) < PAGE_SIZE_EPSILON) {
+ top_margin = left_margin = right_margin = bottom_margin = 0.0f;
+ }
+
// don't adjust for margins if job is PCLm. dimensions of image will not
// match (will be bigger than) the dimensions of the page size and a corrupt image will render
// in genPCLm
@@ -96,6 +104,11 @@ void printable_area_get(wprint_job_params_t *job_params, float top_margin, float
(job_params->print_left_margin + job_params->print_right_margin));
job_params->height = (job_params->printable_area_height -
(job_params->print_top_margin + job_params->print_bottom_margin));
+
+ LOGD("printable_area_get(): source dimensions: %fx%f",
+ job_params->source_width, job_params->source_height);
+ LOGD("printable_area_get(): page dimensions: %fx%f",
+ job_params->page_width, job_params->page_height);
}
void printable_area_get_default_margins(const wprint_job_params_t *job_params,
diff --git a/jni/lib/wprintJNI.c b/jni/lib/wprintJNI.c
index 669c036..1a3e757 100644..100755
--- a/jni/lib/wprintJNI.c
+++ b/jni/lib/wprintJNI.c
@@ -61,6 +61,8 @@ static jfieldID _LocalJobParamsField__document_scaling;
static jfieldID _LocalJobParamsField__job_name;
static jfieldID _LocalJobParamsField__job_originating_user_name;
static jfieldID _LocalJobParamsField__pdf_render_resolution;
+static jfieldID _LocalJobParamsField__source_width;
+static jfieldID _LocalJobParamsField__source_height;
static jclass _LocalPrinterCapabilitiesClass;
static jfieldID _LocalPrinterCapabilitiesField__name;
@@ -522,6 +524,10 @@ static void _initJNI(JNIEnv *env, jobject callbackReceiver, jstring fakeDir) {
env, _LocalJobParamsClass, "job_originating_user_name", "Ljava/lang/String;");
_LocalJobParamsField__pdf_render_resolution = (*env)->GetFieldID(env, _LocalJobParamsClass,
"pdf_render_resolution", "I");
+ _LocalJobParamsField__source_width = (*env)->GetFieldID(env, _LocalJobParamsClass,
+ "source_width", "F");
+ _LocalJobParamsField__source_height = (*env)->GetFieldID(env, _LocalJobParamsClass,
+ "source_height", "F");
// fill out static accessors for LocalPrinterCapabilities
_LocalPrinterCapabilitiesClass = (jclass) (*env)->NewGlobalRef(env, (*env)->FindClass(
@@ -956,6 +962,10 @@ static int _convertJobParams_to_C(JNIEnv *env, jobject javaJobParams,
env, javaJobParams, _LocalJobParamsField__job_margin_right);
wprintJobParams->job_bottom_margin = (float) (*env)->GetFloatField(
env, javaJobParams, _LocalJobParamsField__job_margin_bottom);
+ wprintJobParams->source_height = (float) (*env)->GetFloatField(
+ env, javaJobParams, _LocalJobParamsField__source_height);
+ wprintJobParams->source_width = (float) (*env)->GetFloatField(
+ env, javaJobParams, _LocalJobParamsField__source_width);
if ((*env)->GetBooleanField(env, javaJobParams, _LocalJobParamsField__portrait_mode)) {
wprintJobParams->render_flags |= RENDER_FLAG_PORTRAIT_MODE;
@@ -975,6 +985,7 @@ static int _convertJobParams_to_C(JNIEnv *env, jobject javaJobParams,
int alignment = ((*env)->GetIntField(env, javaJobParams, _LocalJobParamsField__alignment));
if (alignment != 0) {
+ LOGD("Alignment value %d", alignment);
wprintJobParams->render_flags &= ~(RENDER_FLAG_CENTER_VERTICAL |
RENDER_FLAG_CENTER_HORIZONTAL |
RENDER_FLAG_CENTER_ON_ORIENTATION);
@@ -1139,6 +1150,10 @@ static int _covertJobParams_to_Java(JNIEnv *env, jobject javaJobParams,
wprintJobParams->job_right_margin);
(*env)->SetFloatField(env, javaJobParams, _LocalJobParamsField__job_margin_bottom,
wprintJobParams->job_bottom_margin);
+ (*env)->SetFloatField(env, javaJobParams, _LocalJobParamsField__source_width,
+ wprintJobParams->source_width);
+ (*env)->SetFloatField(env, javaJobParams, _LocalJobParamsField__source_height,
+ wprintJobParams->source_height);
return OK;
}
diff --git a/jni/plugins/plugin_pcl.c b/jni/plugins/plugin_pcl.c
index 4170173..4170173 100644..100755
--- a/jni/plugins/plugin_pcl.c
+++ b/jni/plugins/plugin_pcl.c
diff --git a/jni/plugins/wprint_image.c b/jni/plugins/wprint_image.c
index fc0dc9e..f5e148e 100644..100755
--- a/jni/plugins/wprint_image.c
+++ b/jni/plugins/wprint_image.c
@@ -548,6 +548,39 @@ status_t wprint_image_set_output_properties(wprint_image_info_t *image_info,
break;
}
+ LOGD("wprint_image_set_output_properties(): input render flags - %d (0x%8.8x)",
+ input_render_flags, input_render_flags);
+ LOGD("wprint_image_set_output_properties(): printable area - %dx%d",
+ printable_width, printable_height);
+ LOGD("wprint_image_set_output_properties(): input margins: Top:%d Left:%d Right:%d Bottom:%d",
+ top_margin, left_margin, right_margin, bottom_margin);
+ LOGD("wprint_image_set_output_properties(): padding options: %d (0x%2.2x)",
+ image_info->padding_options, image_info->padding_options);
+ LOGD("wprint_image_set_output_properties(): concurrent stripes - %d",
+ image_info->concurrent_stripes);
+ LOGD("wprint_image_set_output_properties(): stripe height - %d", image_info->stripe_height);
+ LOGD("wprint_image_set_output_properties(): image dimensions: %dx%d",
+ image_info->width, image_info->height);
+ LOGD("wprint_image_set_output_properties(): image rotation: %d", image_info->rotation);
+ LOGD("wprint_image_set_output_properties(): final render flags - %d (0x%8.8x)",
+ image_info->render_flags, image_info->render_flags);
+ LOGD("wprint_image_set_output_properties(): printable area after margins - %dx%d",
+ image_info->printable_width, image_info->printable_height);
+ LOGD("wprint_image_set_output_properties(): output_padding: Top:%d Left:%d Right:%d Bottom:%d",
+ image_info->output_padding_top, image_info->output_padding_left,
+ image_info->output_padding_right, image_info->output_padding_bottom);
+ LOGD("wprint_image_set_output_properties(): output dimensions: %dx%d", image_info->output_width,
+ image_info->output_height);
+ LOGD("wprint_image_set_output_properties(): subsampled image dimensions - %dx%d",
+ image_info->sampled_width, image_info->sampled_height);
+ LOGD("wprint_image_set_output_properties(): scaled image dimensions - %dx%d",
+ image_info->scaled_width, image_info->scaled_height);
+ LOGD("wprint_image_set_output_properties(): image offsets - row: %d, col: %d",
+ image_info->row_offset, image_info->col_offset);
+ LOGD("wprint_image_set_output_properties(): margins - top: %d, left: %d, right: %d, bottom: %d",
+ image_info->output_padding_top, image_info->output_padding_left,
+ image_info->output_padding_right, image_info->output_padding_bottom);
+
return OK;
}
diff --git a/jni/plugins/wprint_image.h b/jni/plugins/wprint_image.h
index e03b9a4..e03b9a4 100644..100755
--- a/jni/plugins/wprint_image.h
+++ b/jni/plugins/wprint_image.h
diff --git a/src/com/android/bips/ipp/StartJobTask.java b/src/com/android/bips/ipp/StartJobTask.java
index 36ae93e..c176231 100644..100755
--- a/src/com/android/bips/ipp/StartJobTask.java
+++ b/src/com/android/bips/ipp/StartJobTask.java
@@ -18,6 +18,7 @@
package com.android.bips.ipp;
import android.content.Context;
+import android.graphics.pdf.PdfRenderer;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
@@ -161,6 +162,19 @@ class StartJobTask extends AsyncTask<Void, Void, Integer> {
// Fill in job parameters from capabilities and print job info.
populateJobParams();
+ try (PdfRenderer renderer = new PdfRenderer(
+ ParcelFileDescriptor.open(pdfFile, ParcelFileDescriptor.MODE_READ_ONLY));
+ PdfRenderer.Page page = renderer.openPage(0)) {
+ if (mJobParams.portrait_mode) {
+ mJobParams.source_height = (float) page.getHeight() / 72;
+ mJobParams.source_width = (float) page.getWidth() / 72;
+ } else {
+ mJobParams.source_width = (float) page.getHeight() / 72;
+ mJobParams.source_height = (float) page.getWidth() / 72;
+ }
+ } catch (IOException e) {
+ Log.w(TAG, "Error while getting source width, height", e);
+ }
// Finalize job parameters
mBackend.nativeGetFinalJobParameters(mJobParams, mCapabilities);
diff --git a/src/com/android/bips/jni/LocalJobParams.java b/src/com/android/bips/jni/LocalJobParams.java
index 9e5df5d..c2a0193 100644..100755
--- a/src/com/android/bips/jni/LocalJobParams.java
+++ b/src/com/android/bips/jni/LocalJobParams.java
@@ -62,6 +62,9 @@ public final class LocalJobParams {
public int alignment = 0;
public boolean document_scaling;
+ public float source_width;
+ public float source_height;
+
@Override
public String toString() {
return "LocalJobParams{"
@@ -99,6 +102,8 @@ public final class LocalJobParams {
+ " nativeData=" + !(nativeData == null)
+ " alignment=" + alignment
+ " document_scaling=" + document_scaling
+ + " source_width=" + source_width
+ + " source_height=" + source_height
+ "}";
}
}