bool ImageHandler::insertImage(GFile * file, double x, double y) { XOJ_CHECK_TYPE(ImageHandler); GError * err = NULL; GFileInputStream * in = g_file_read(file, NULL, &err); g_object_unref(file); GdkPixbuf * pixbuf = NULL; if (!err) { pixbuf = gdk_pixbuf_new_from_stream(G_INPUT_STREAM(in), NULL, &err); g_input_stream_close(G_INPUT_STREAM(in), NULL, NULL); } else { GtkWidget * dialog = gtk_message_dialog_new((GtkWindow*) *control->getWindow(), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("This image could not be loaded. Error message: %s"), err->message); gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(this->control->getWindow()->getWindow())); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); g_error_free(err); return false; } Image * img = new Image(); img->setX(x); img->setY(y); img->setImage(pixbuf); int width = gdk_pixbuf_get_width(pixbuf); int height = gdk_pixbuf_get_height(pixbuf); gdk_pixbuf_unref(pixbuf); double zoom = 1; PageRef page = view->getPage(); if (x + width > page.getWidth() || y + height > page.getHeight()) { double maxZoomX = (page.getWidth() - x) / width; double maxZoomY = (page.getHeight() - y) / height; if (maxZoomX < maxZoomY) { zoom = maxZoomX; } else { zoom = maxZoomY; } } img->setWidth(width * zoom); img->setHeight(height * zoom); page.getSelectedLayer()->addElement(img); InsertUndoAction * insertUndo = new InsertUndoAction(page, page.getSelectedLayer(), img, view); control->getUndoRedoHandler()->addUndoAction(insertUndo); view->rerenderElement(img); return true; }
bool PdfExport::writePagesindex() { XOJ_CHECK_TYPE(PdfExport); this->xref->setXref(1, this->writer->getDataCount()); //Pages root this->writer->write("1 0 obj\n"); this->writer->write("<</Type /Pages\n"); this->writer->write("/Kids ["); int pageCount = 0; for (GList* l = this->pageIds; l != NULL; l = l->next) { int id = *((int*) l->data); this->writer->writef("%i 0 R ", id); pageCount++; } this->writer->write("]\n"); this->writer->writef("/Count %i\n", pageCount); PageRef page = doc->getPage(0); this->writer->writef("/MediaBox [0 0 %.2F %.2F]\n", page->getWidth(), page->getHeight()); this->writer->write(">>\n"); this->writer->write("endobj\n"); return true; }
/** * Drawing first step * @param page The page to draw * @param cr Draw to thgis context * @param dontRenderEditingStroke false to draw currently drawing stroke */ void DocumentView::initDrawing(PageRef page, cairo_t* cr, bool dontRenderEditingStroke) { XOJ_CHECK_TYPE(DocumentView); this->cr = cr; this->page = page; this->width = page->getWidth(); this->height = page->getHeight(); this->dontRenderEditingStroke = dontRenderEditingStroke; }
bool PdfExport::writePage(int pageNr) { XOJ_CHECK_TYPE(PdfExport); PageRef page = doc->getPage(pageNr); if (!page) { return false; } int* pageId = (int*) g_malloc(sizeof(int)); *pageId = this->writer->getObjectId(); this->pageIds = g_list_append(this->pageIds, pageId); this->writer->writeObj(); this->writer->write("<</Type /Page\n"); this->writer->write("/Parent 1 0 R\n"); this->writer->writef("/MediaBox [0 0 %.2F %.2F]\n", page->getWidth(), page->getHeight()); this->writer->write("/Resources 2 0 R\n"); // if (isset($this->PageLinks[$n])) { // //Links // $annots = '/Annots ['; //foreach ($this->PageLinks[$n] as $pl) // { // $rect=sprintf('%.2F %.2F %.2F %.2F',$pl[0],$pl[1],$pl[0]+$pl[2],$pl[1]-$pl[3]); // $annots.='<</Type /Annot /Subtype /Link /Rect ['.$rect.'] /Border [0 0 0] '; // if(is_string($pl[4])) // $annots.='/A <</S /URI /URI '.$this->_textstring($pl[4]).'>>>>'; // else // { // $l=$this->links[$pl[4]]; // $h=isset($this->PageSizes[$l[0]]) ? $this->PageSizes[$l[0]][1] : $hPt; // $annots.=sprintf('/Dest [%d 0 R /XYZ 0 %.2F null]>>',1+2*$l[0],$h-$l[1]*$this->k); // } // } // $this->_out($annots.']'); //} this->writer->writef("/Contents %i 0 R>>\n", this->writer->getObjectId()); this->writer->write("endobj\n"); //Page content this->writer->writeObj(); this->writer->startStream(); addPopplerDocument(doc->getPdfDocument()); currentPdfDoc = doc->getPdfDocument(); if (page->getBackgroundType() == BACKGROUND_TYPE_PDF) { XojPopplerPage* pdf = doc->getPdfPage(page->getPdfPageNr()); if (!addPopplerPage(pdf, currentPdfDoc)) { return false; } } currentPdfDoc = cPdf.getDocument(); if (!addPopplerPage(cPdf.getPage(pageNr), currentPdfDoc)) { return false; } this->writer->endStream(); this->writer->write("endobj\n"); return true; }