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.
23 #include "pgen_debug.h"
25 #include "paper_size.h"
28 /* could be used as stub for paper size */
29 struct paper_size_pts paper_sizes[] = {
32 {"Hagaki_Postcard", {1000,1480}},
33 {"Business_card", {540,856}},
35 {"8x10", {2032,2540}},
36 {"Letter", { 612, 792 }},
37 {"11x17", {2794,4318}},
45 void switch_size_pts_coords(struct size_pts *s)
47 PGEN_RET_IF(s == NULL, "Invalid argument");
54 void switch_size_px_coords(struct size_px *s)
56 PGEN_RET_IF(s == NULL, "Invalid argument");
63 void add_size_pts(const struct size_pts *from, struct size_pts *to)
65 PGEN_RET_IF(from == NULL || to == NULL, "Invalid argument");
71 void neg_size_pts(struct size_pts *s)
73 PGEN_RET_IF(s == NULL, "Invalid argument");
80 * @brief Works with fixed list of sizes!
81 * In mobileprint only for usage as stub.
82 * @param[in] name paper name
83 * @param[out] s paper size
85 int get_paper_size_pts(const char *name, struct paper_size_pts *s)
88 struct paper_size_pts *cur_s;
90 PGEN_RETV_IF(name == NULL || s == NULL, -1, "Invalid argument");
92 for (i = 0; paper_sizes[i].name != NULL; ++i) {
93 cur_s = &(paper_sizes[i]);
94 /* call without of limit is safe till we have static page
96 if (strcmp(cur_s->name, name) == 0) {
97 //memcpy(s, cur_s, sizeof(*cur_s));
108 * @brief get raster size for specifyed borders
109 * @param[in] s_pts size in points
110 * @param[in] border_s_px specified borders of available size
111 * @param[out] px raster size
113 int pts_size2px(const struct size_pts *s_pts,
114 const struct size_px *border_s_px,
122 PGEN_RETV_IF(s_pts == NULL || border_s_px == NULL || px == NULL, -1 , "Invalid argument");
124 ratio_x = border_s_px->x / s_pts->x;
125 ratio_y = border_s_px->y / s_pts->y;
127 /* get smallest one */
128 if (ratio_x > ratio_y) {
135 px->x = ratio_x * s_pts->x;
136 px->y = ratio_y * s_pts->y;
138 PGEN_DEBUG("px->x px->y :(%d, %d)",px->x, px->y);