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.
25 #include "pt_common.h"
27 #include "pt_optionmapping.h"
30 * This API let the app set page ranges option for active printer, if not find active printer, will use default printer
31 * @return If success, return PT_ERR_NONE, else return the other error code as defined in pt_err_t
32 * @param[in] ranges page range string
34 int pt_set_print_option_page_range(const char *ranges)
36 PRINT_SERVICE_FUNC_ENTER;
37 PT_RETV_IF(g_pt_info == NULL, PT_ERR_INVALID_PARAM, "Invalid argument");
38 PT_RETV_IF(ranges == NULL, PT_ERR_INVALID_PARAM, "Invalid argument");
40 char buf[MAX_SIZE] = {0};
41 snprintf(buf, MAX_SIZE, "%s", ranges);
42 g_pt_info->num_options = cupsAddOption("page-ranges", buf, g_pt_info->num_options, &g_pt_info->job_options);
43 PT_DEBUG("num is %d", g_pt_info->num_options);
44 PT_DEBUG("options is %p", g_pt_info->job_options);
46 PRINT_SERVICE_FUNC_LEAVE;
51 * This API let the app set copies option for active printer, if not find active printer, will use default printer
52 * @return If success, return PT_ERR_NONE, else return the other error code as defined in pt_err_t
53 * @param[in] copies the copy number
55 int pt_set_print_option_copies(int copies)
57 PRINT_SERVICE_FUNC_ENTER;
58 PT_RETV_IF(g_pt_info == NULL, PT_ERR_INVALID_PARAM, "Invalid argument");
59 PT_RETV_IF(copies <= 0, PT_ERR_INVALID_PARAM, "Invalid argument");
61 char buf[MAX_SIZE] = {0};
62 snprintf(buf, MAX_SIZE, "%d", copies);
63 g_pt_info->num_options = cupsAddOption("copies", buf, g_pt_info->num_options, &g_pt_info->job_options);
64 PT_DEBUG("num is %d", g_pt_info->num_options);
65 PT_DEBUG("options is %p", g_pt_info->job_options);
67 PRINT_SERVICE_FUNC_LEAVE;
72 * This API let the app set copies option for active printer, if not find active printer, will use default printer
73 * @return If success, return PT_ERR_NONE, else return the other error code as defined in pt_err_t
76 int pt_set_print_option_color(void)
78 PRINT_SERVICE_FUNC_ENTER;
79 PT_RETV_IF(g_pt_info == NULL, PT_ERR_INVALID_PARAM, "Invalid argument");
81 ppd_choice_t *choi = pt_selected_choice(PT_OPTION_ID_GRAYSCALE, PT_ORIENTATION_PORTRAIT);
83 g_pt_info->num_options = cupsAddOption(choi->option->keyword, choi->choice, g_pt_info->num_options, &g_pt_info->job_options);
86 PT_DEBUG("num is %d", g_pt_info->num_options);
87 PT_DEBUG("options is %p", g_pt_info->job_options);
89 PT_DEBUG("%s=%s", choi->option->keyword, choi->choice);
92 PRINT_SERVICE_FUNC_LEAVE;
96 int pt_set_print_option_paper_type(void)
98 PRINT_SERVICE_FUNC_ENTER;
99 PT_RETV_IF(g_pt_info == NULL, PT_ERR_INVALID_PARAM, "Invalid argument");
101 ppd_choice_t *choi = pt_selected_choice(PT_OPTION_ID_PAPER, PT_ORIENTATION_PORTRAIT);
103 g_pt_info->num_options = cupsAddOption(choi->option->keyword, choi->choice, g_pt_info->num_options, &g_pt_info->job_options);
106 PT_DEBUG("num is %d", g_pt_info->num_options);
107 PT_DEBUG("options is %p", g_pt_info->job_options);
109 PT_DEBUG("%s=%s", choi->option->keyword, choi->choice);
112 PRINT_SERVICE_FUNC_LEAVE;
116 int pt_set_print_option_quality(void)
118 PRINT_SERVICE_FUNC_ENTER;
119 PT_RETV_IF(g_pt_info == NULL, PT_ERR_INVALID_PARAM, "Invalid argument");
121 ppd_choice_t *choi = pt_selected_choice(PT_OPTION_ID_QUALITY, PT_ORIENTATION_PORTRAIT);
123 g_pt_info->num_options = cupsAddOption(choi->option->keyword, choi->choice, g_pt_info->num_options, &g_pt_info->job_options);
126 PT_DEBUG("num is %d", g_pt_info->num_options);
127 PT_DEBUG("options is %p", g_pt_info->job_options);
129 PT_DEBUG("%s=%s", choi->option->keyword, choi->choice);
132 PRINT_SERVICE_FUNC_LEAVE;
137 * This API let the app set paper size option for active printer, if not find active printer, will use default printer
138 * @return If success, return PT_ERR_NONE, else return the other error code as defined in pt_err_t
141 int pt_set_print_option_papersize(void)
143 PRINT_SERVICE_FUNC_ENTER;
145 ppd_choice_t *choi = pt_selected_choice(PT_OPTION_ID_PAPERSIZE, PT_ORIENTATION_PORTRAIT);
147 g_pt_info->num_options = cupsAddOption(choi->option->keyword, choi->choice, g_pt_info->num_options, &g_pt_info->job_options);
150 PT_DEBUG("num is %d", g_pt_info->num_options);
151 PT_DEBUG("options is %p", g_pt_info->job_options);
153 PT_DEBUG("%s=%s", choi->option->keyword, choi->choice);
156 PRINT_SERVICE_FUNC_LEAVE;
161 * This API let the app set duplex option for active printer, if not find active printer, will use default printer
162 * @return If success, return PT_ERR_NONE, else return the other error code as defined in pt_err_t
163 * @param[in] papersize the paper size
165 int pt_set_print_option_duplex(pt_orientation_e orientation)
167 PRINT_SERVICE_FUNC_ENTER;
169 ppd_choice_t *choi = pt_selected_choice(PT_OPTION_ID_DUPLEX, orientation);
171 g_pt_info->num_options = cupsAddOption(choi->option->keyword, choi->choice, g_pt_info->num_options, &g_pt_info->job_options);
174 PT_DEBUG("num is %d", g_pt_info->num_options);
175 PT_DEBUG("options is %p", g_pt_info->job_options);
177 PT_DEBUG("%s=%s", choi->option->keyword, choi->choice);
180 PRINT_SERVICE_FUNC_LEAVE;
185 * This API let the app set orientation option for active printer, if not find active printer, will use default printer
186 * @return If success, return PT_ERR_NONE, else return the other error code as defined in pt_err_t
187 * @param[in] orientation the orientation value(0:portrait, 1:landscape)
189 int pt_set_print_option_orientation(pt_orientation_e orientation)
191 PRINT_SERVICE_FUNC_ENTER;
192 PT_RETV_IF(g_pt_info == NULL, PT_ERR_INVALID_PARAM, "Invalid argument");
193 PT_RETV_IF((orientation < PT_ORIENTATION_PORTRAIT) || (orientation > PT_ORIENTATION_LANDSCAPE)
194 , PT_ERR_INVALID_PARAM, "Invalid argument");
196 if (orientation == PT_ORIENTATION_PORTRAIT) {
197 g_pt_info->num_options = cupsAddOption("landscape", "off", g_pt_info->num_options, &g_pt_info->job_options);
198 } else if (orientation == PT_ORIENTATION_LANDSCAPE) {
199 g_pt_info->num_options = cupsAddOption("landscape", "on", g_pt_info->num_options, &g_pt_info->job_options);
201 PT_DEBUG("CUPS will do auto-rotate when landscape option is not specified");
204 PT_DEBUG("num is %d", g_pt_info->num_options);
205 PT_DEBUG("options is %p", g_pt_info->job_options);
207 PRINT_SERVICE_FUNC_LEAVE;
212 * This API let the app set image fit for the page size, if not find active printer, will use default printer
213 * @return If success, return PT_ERR_NONE, else return the other error code as defined in pt_err_t
215 int pt_set_print_option_scaleimage(pt_scaling_e scaling)
217 PRINT_SERVICE_FUNC_ENTER;
218 PT_RETV_IF(g_pt_info == NULL, PT_ERR_INVALID_PARAM, "Invalid argument");
220 char scaling_option[MAX_SIZE] = {0};
221 char percent_size[MAX_SIZE] = {0};
223 case PT_SCALING_2_PAGES:
224 strcpy(scaling_option, "number-up"); // 2 pages in 1 sheet
225 strcpy(percent_size, "2");
227 case PT_SCALING_4_PAGES:
228 strcpy(scaling_option, "number-up"); // 4 pages in 1 sheet
229 strcpy(percent_size, "4");
231 case PT_SCALING_FIT_TO_PAGE:
233 strcpy(scaling_option, "scaling"); // fit-to-paper
234 strcpy(percent_size, "100");
238 // do not send number-up option to CUPS daemon.
239 // imagetoraster do not support number-up
240 // To print image to resolve OOM, apply number-up option to pdf in advance.
241 g_pt_info->num_options = cupsAddOption(scaling_option, percent_size, g_pt_info->num_options, &g_pt_info->job_options);
242 PT_DEBUG("num is %d", g_pt_info->num_options);
243 PT_DEBUG("options is %p", g_pt_info->job_options);
244 PT_DEBUG("scaling option:[%s %s]", scaling_option, percent_size);
246 PRINT_SERVICE_FUNC_LEAVE;
251 * This API let the app set image fit for the page size, if not find active printer, will use default printer
252 * @return If success, return PT_ERR_NONE, else return the other error code as defined in pt_err_t
254 int pt_set_print_option_imagesize(pt_imagesize_t *crop_image_info, const char *filepath, int res_x, int res_y)
256 PRINT_SERVICE_FUNC_ENTER;
257 PT_RETV_IF(g_pt_info == NULL, PT_ERR_INVALID_PARAM, "Invalid argument");
258 PT_RETV_IF(filepath == NULL, PT_ERR_INVALID_PARAM, "Invalid argument");
260 char imagesize_option[MAX_SIZE] = {0};
261 char ppi_value[MAX_SIZE] = {0};
266 switch (crop_image_info->imagesize) {
267 case PT_SIZE_5X7: /** 13 cm X 18 cm */
268 PT_DEBUG("selected PT_SIZE_5X7");
271 case PT_SIZE_4X6: /** 10 cm X 15 cm */
272 PT_DEBUG("selected PT_SIZE_4X6");
275 case PT_SIZE_3_5X5: /** 9 cm X 13 cm */
276 PT_DEBUG("selected PT_SIZE_3_5X5");
279 case PT_SIZE_WALLET: /** 6.4cm X 8.4 cm */
280 PT_DEBUG("selected PT_SIZE_WALLET");
284 PT_DEBUG("selected PT_SIZE_CUSTOM");
285 if (crop_image_info->unit == 1) { // cm to inch
286 crop_image_info->resolution_width = crop_image_info->resolution_width / 2.54;
287 crop_image_info->resolution_height = crop_image_info->resolution_height / 2.54;
288 crop_image_info->unit = 2;
289 crop_image_info->ratio = crop_image_info->resolution_width / crop_image_info->resolution_height;
292 if (crop_image_info->resolution_width < crop_image_info->resolution_height) {
293 divisor = crop_image_info->resolution_height;
295 divisor = crop_image_info->resolution_width;
300 PT_DEBUG("[ERROR] Undefined imagesize(%d)",crop_image_info->imagesize);
301 return PT_ERR_INVALID_PARAM;
305 ppi = (int) ceil((double)(res_y) / (double)divisor);
307 ppi = (int) ceil((double)(res_x) / (double)divisor);
309 strcpy(imagesize_option, "ppi");
310 snprintf(ppi_value, MAX_SIZE, "%d", ppi);
312 g_pt_info->num_options = cupsAddOption(imagesize_option, ppi_value, g_pt_info->num_options, &g_pt_info->job_options);
313 PT_DEBUG("num is %d", g_pt_info->num_options);
314 PT_DEBUG("options is %p", g_pt_info->job_options);
315 PT_DEBUG("imagesize_option :[%s %s]", imagesize_option, ppi_value);
317 PRINT_SERVICE_FUNC_LEAVE;