|
| 1 | +/****************************************************************************** |
| 2 | + * MODULE : mupdf_qt_ui_element.cpp |
| 3 | + * DESCRIPTION: Modified QT glue widget render process to adapt to MuPDF render |
| 4 | + * COPYRIGHT : (C) 2025 The Mogan Stem Authors |
| 5 | + ******************************************************************************* |
| 6 | + * This software falls under the GNU general public license version 3 or later. |
| 7 | + * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE |
| 8 | + * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>. |
| 9 | + ******************************************************************************/ |
| 10 | + |
| 11 | +#include "MuPDF/mupdf_renderer.hpp" |
| 12 | +#include "qt_ui_element.hpp" |
| 13 | + |
| 14 | +QTMPixmapOrImage |
| 15 | +qt_glue_widget_rep::render () { |
| 16 | + if (w > 128 || h > 128) { |
| 17 | + // Reduce pixmap width and height to improve performance |
| 18 | + SI factor= max (w, h) / 128; |
| 19 | + w/= factor; |
| 20 | + h/= factor; |
| 21 | + } |
| 22 | + fz_pixmap* pix= fz_new_pixmap ( |
| 23 | + mupdf_context (), fz_device_rgb (mupdf_context ()), w, h, NULL, 1); |
| 24 | + mupdf_renderer_rep* ren= the_mupdf_renderer (); |
| 25 | + ren->begin (pix); |
| 26 | + rectangle r= rectangle (0, 0, w, h); |
| 27 | + ren->set_origin (0, 0); |
| 28 | + ren->encode (r->x1, r->y1); |
| 29 | + ren->encode (r->x2, r->y2); |
| 30 | + ren->set_clipping (r->x1, r->y2, r->x2, r->y1); |
| 31 | + if (col == "") { |
| 32 | + // do nothing |
| 33 | + } |
| 34 | + else { |
| 35 | + if (is_atomic (col)) { |
| 36 | + color c= named_color (col->label); |
| 37 | + ren->set_background (c); |
| 38 | + ren->set_pencil (c); |
| 39 | + ren->fill (r->x1, r->y2, r->x2, r->y1); |
| 40 | + } |
| 41 | + else { |
| 42 | + ren->set_shrinking_factor (std_shrinkf); |
| 43 | + brush old_b= ren->get_background (); |
| 44 | + ren->set_background (col); |
| 45 | + ren->clear_pattern (5 * r->x1, 5 * r->y2, 5 * r->x2, 5 * r->y1); |
| 46 | + ren->set_background (old_b); |
| 47 | + ren->set_shrinking_factor (1); |
| 48 | + } |
| 49 | + } |
| 50 | + ren->end (); |
| 51 | + |
| 52 | + return get_QTMPixmapOrImage_from_pixmap (pix); |
| 53 | +} |
0 commit comments