4 * Copyright 2012 Samsung Electronics Co., Ltd
6 * Licensed under the Flora License, Version 1.1 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://floralicense.org/license/
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
22 #include "paper_size.h"
23 #include "pgen_debug.h"
25 #include "preview_coords.h"
28 void debug_print_preview_page_req(const struct preview_page_req *r)
30 PGEN_DEBUG("+-----------------------------+");
31 PGEN_DEBUG("| struct preview_page_req |");
32 PGEN_DEBUG("+---------------------+-------+");
33 PGEN_DEBUG("| paper_size.x | %5f |", r->paper_size.x);
34 PGEN_DEBUG("| paper_size.y | %5f |", r->paper_size.y);
35 PGEN_DEBUG("| available_size_px.x | %5d |", r->available_size_px.x);
36 PGEN_DEBUG("| available_size_px.y | %5d |", r->available_size_px.y);
37 PGEN_DEBUG("| shadow_offset.x | %5d |", r->shadow_offset.x);
38 PGEN_DEBUG("| shadow_offset.y | %5d |", r->shadow_offset.y);
39 PGEN_DEBUG("| is_rotate90 | %5d |", r->is_rotate90);
40 PGEN_DEBUG("+---------------------+-------+");
44 void debug_print_preview_page_px(const struct preview_page_px *s)
46 PGEN_DEBUG("+------------------------+");
47 PGEN_DEBUG("| struct preview_page_px |");
48 PGEN_DEBUG("+---------------+--------+");
49 PGEN_DEBUG("| full_size.x | %6d |", s->full_size.x);
50 PGEN_DEBUG("| full_size.y | %6d |", s->full_size.y);
51 PGEN_DEBUG("| paper_size.x | %6d |", s->paper_size.x);
52 PGEN_DEBUG("| paper_size.y | %6d |", s->paper_size.y);
53 PGEN_DEBUG("| area_size.x | %6d |", s->area_size.x);
54 PGEN_DEBUG("| area_size.y | %6d |", s->area_size.y);
55 PGEN_DEBUG("| area_offset.x | %6d |", s->area_offset.x);
56 PGEN_DEBUG("| area_offset.y | %6d |", s->area_offset.y);
57 PGEN_DEBUG("| is_grayscale | %6d |", s->is_grayscale);
58 PGEN_DEBUG("| is_rotate90 | %6d |", s->is_rotate90);
59 PGEN_DEBUG("+---------------+--------+");
63 void debug_print_preview_settings_px(const struct preview_settings_px *s)
65 PGEN_DEBUG("+----------------------------+");
66 PGEN_DEBUG("| struct preview_settings_px |");
67 PGEN_DEBUG("+-------------+--------------+");
68 PGEN_DEBUG("| center_off | %9d |", s->center_off);
69 PGEN_DEBUG("| left_off | %9d |", s->left_off);
70 PGEN_DEBUG("| right_off | %9d |", s->right_off);
71 PGEN_DEBUG("| full_size.x | %9d |", s->full_size.x);
72 PGEN_DEBUG("| full_size.y | %9d |", s->full_size.y);
73 PGEN_DEBUG("+-------------+--------------+");
77 int process_preview_page_settings(const struct preview_page_req *req,
78 struct preview_page_px *res)
80 PGEN_RETV_IF(req == NULL || res == NULL, -1, "Invalid argument");
82 /*debug_print_preview_page_req(req);*/
84 if (pts_size2px(&(req->paper_size), &(req->available_size_px),
85 &(res->full_size)) < 0) {
86 PGEN_DEBUG("ERROR: pts_size2px()\n");
90 res->paper_size.x = res->full_size.x - req->shadow_offset.x;
91 res->paper_size.y = res->full_size.y - req->shadow_offset.y;
93 res->area_offset.x = 2;
94 res->area_offset.y = 2;
96 res->area_size.x = res->paper_size.x - res->area_offset.x * 2;
97 res->area_size.y = res->paper_size.y - res->area_offset.y * 2;
99 res->is_grayscale = req->is_grayscale;
100 res->is_rotate90 = req->is_rotate90;
102 /*debug_print_preview_page_px(res);*/
107 /* for backward compatibility */
108 int get_preview_page_settings(const struct preview_page_req *req,
109 struct preview_page_px *res)
111 struct preview_page_req newreq;
113 PGEN_RETV_IF(req == NULL || res == NULL, -1, "Invalid argument");
117 if (req->is_rotate90) {
118 switch_size_pts_coords(&(newreq.paper_size));
121 return process_preview_page_settings(&newreq, res);
125 int get_preview_settings(const struct preview_page_req *req,
126 struct preview_settings_px *res)
128 struct size_pts canvas_size;
131 struct preview_page_req newreq;
133 PGEN_RETV_IF(req == NULL || res == NULL, -1, "Invalid argument");
135 /*debug_print_preview_page_req(req);*/
139 if (req->is_rotate90) {
140 switch_size_pts_coords(&(newreq.paper_size));
143 /* calculate space for page images */
144 /* we will use smaller side of page */
145 side_w_pts = req->paper_size.x * PAGE_SIDE_SHOW_COEFF;
146 space_w_pts = req->paper_size.x * MIN_PAGE_SPACE_COEFF;
147 canvas_size.y = newreq.paper_size.y;
148 canvas_size.x = newreq.paper_size.x + side_w_pts * 2 + space_w_pts * 2;
150 if (pts_size2px(&canvas_size, &(req->available_size_px),
151 &(newreq.available_size_px)) < 0) {
152 PGEN_DEBUG("ERROR: full_size: pts_size2px()\n");
156 /* calculate single-page size */
157 //newreq.available_size_px = res->full_size;
158 process_preview_page_settings(&newreq, &(res->page_px));
160 res->full_size.x = req->available_size_px.x;
161 res->full_size.y = newreq.available_size_px.y;
163 /* calculate offsets */
164 res->center_off = res->full_size.x / 2 - res->page_px.full_size.x / 2;
165 res->left_off = res->page_px.full_size.x * (PAGE_SIDE_SHOW_COEFF - 1);
166 res->right_off = res->full_size.x
167 - res->page_px.full_size.x * PAGE_SIDE_SHOW_COEFF;
169 /*debug_print_preview_settings_px(res);*/