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.
21 #include <ui-gadget.h>
23 #include <page_preview.h>
24 #include <paper_size.h>
25 #include <previewgen.h>
28 #include "pts_common.h"
29 #include "pts_main_view.h"
31 #include "preview_content.h"
33 #define DEFAULT_PPD_FILE RESDIR "/ppd/default.ppd"
35 int is_printer_grayscale(const pt_printer_mgr_t *active_printer)
37 switch (pt_get_selected(PT_OPTION_ID_GRAYSCALE)) {
38 case PT_GRAYSCALE_COLOUR:
45 enum page_orientation printer_get_setting_orientation(
46 const pt_printer_mgr_t *active_printer)
48 /* should be taken from settings */
49 switch (active_printer->landscape) {
50 // case PT_ORIENTATION_AUTO:
51 /* TODO: check for page size, n-up */
52 // return PAGE_ORIENTATION_AUTO;
53 case PT_ORIENTATION_PORTRAIT:
54 return PAGE_ORIENTATION_PORTRAIT;
55 case PT_ORIENTATION_LANDSCAPE:
56 return PAGE_ORIENTATION_LANDSCAPE;
58 return PAGE_ORIENTATION_PORTRAIT;
61 int printer_get_setting_n_up(const pt_printer_mgr_t *active_printer)
63 /* should be taken from settings */
64 switch (active_printer->scaling) {
65 case PT_SCALING_2_PAGES:
67 case PT_SCALING_4_PAGES:
70 case PT_SCALING_8_PAGES:
80 * @brief Get paper size and paper name for CUPS utilities cmd usage
81 * @param[out] paper_size paper_size should be local variable
82 * to keep further store we should provide a copy
84 int printer_get_paper_size(struct paper_size_pts *paper_size)
87 /* get paper size of active printer from print-service */
88 pt_pagesize_t current_pagesize;
89 int result = pt_get_selected_paper_size_pts(¤t_pagesize);
90 PTS_RETV_IF(result < 0, -1, "pt_get_selected_paper_size_pts returns error");
92 /* get really selected papersize name for command line commands */
93 paper_size->name = pt_get_print_option_papersize_cmd(
94 pt_get_selected(PT_OPTION_ID_PAPERSIZE));
95 paper_size->s.x = current_pagesize.x;
96 paper_size->s.y = current_pagesize.y;
102 int pts_image_size_t2page_scale(pts_image_size_e pts_size,
103 struct page_scale *scale)
105 PTS_RETV_IF(scale == NULL, -1, "scale is NULL");
111 case PTS_SIZE_FIT_TO_PAPER:
112 scale->type = SCALE_FIT_TO_PAPER;
126 case PTS_SIZE_WALLET:
133 scale->type = SCALE_FIT_TO_PAPER;
137 scale->type = SCALE_CUSTOM;
143 * @brief This function generates preview images
144 * @param[in] ugd the pointer to the main data structure
147 int generate_preview_images(pts_appdata_t *ad,
148 app_device_orientation_e dev_orientation)
151 PTS_RETV_IF(ad == NULL , -1 , "ad is NULL");
155 struct paper_size_pts paper_size;
156 enum page_orientation orientation;
157 struct page_scale scale = {0, 0, 0};
160 pt_printer_mgr_t *active_printer = ad->list_info.active_printer;
163 /* currently supported: only one PDF or multiple images;
164 mixed images-pdf unsupported */
166 PTS_RETV_IF(ad->printing_data.num_of_files <= 0, -1 , "Invalid argument");
168 /* should be taken from settings */
169 if (active_printer != NULL) {
170 ppd = active_printer->ppd;
171 printer_get_paper_size(&paper_size);
172 orientation = printer_get_setting_orientation(active_printer);
173 n_up = printer_get_setting_n_up(active_printer);
174 pts_image_size_t2page_scale(ad->size_popup_info.image_size, &scale);
175 if (ad->size_popup_info.image_size == PTS_SIZE_CUSTOM) {
176 scale.w = ad->size_popup_info.custom_width;
177 scale.h = ad->size_popup_info.custom_height;
178 scale.type = SCALE_CUSTOM;
180 is_grayscale = is_printer_grayscale(active_printer);
182 PTS_DEBUG("No active printer preview");
184 ppd = DEFAULT_PPD_FILE;
185 get_paper_size_pts("A4", &paper_size);
186 orientation = PAGE_ORIENTATION_PORTRAIT;
187 //is_original_zoom = 0;
188 scale.type = SCALE_FIT_TO_PAPER;
193 PTS_DEBUG("USING PPD: %s", ppd);
194 PTS_DEBUG("PAPER NAME: %s", paper_size.name);
195 PTS_DEBUG("PAPER SIZE: %f, %f", paper_size.s.x, paper_size.s.y);
196 PTS_DEBUG("ALBUM, N_UP, ZOOM: %d, %d, %d", orientation, n_up, scale.type);
198 result = evas_smart_smsc_set_file(ad->main_info.smsc,
199 ad->printing_data.request_files, ad->printing_data.num_of_files,
200 ppd, &paper_size, orientation, n_up, &scale,
202 PTS_DEBUG("evas_smart_smsc_set_file: %d", result);