Example #1
0
void RenderJob::rerenderRectangle(RenderJob * renderJob, Rectangle * rect) {
	XOJ_CHECK_TYPE_OBJ(renderJob, RenderJob);

	PageView * view = renderJob->view;
	double zoom = view->xournal->getZoom();
	Document * doc = view->xournal->getDocument();

	doc->lock();

	double pageWidth = view->page.getWidth();
	double pageHeight = view->page.getHeight();

	doc->unlock();

	int x = rect->x * zoom;
	int y = rect->y * zoom;
	int width = rect->width * zoom;
	int height = rect->height * zoom;

	cairo_surface_t * rectBuffer = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
	cairo_t * crRect = cairo_create(rectBuffer);
	cairo_translate(crRect, -x, -y);
	cairo_scale(crRect, zoom, zoom);

	DocumentView v;
	v.limitArea(rect->x, rect->y, rect->width, rect->height);

	if (view->page.getBackgroundType() == BACKGROUND_TYPE_PDF) {
		int pgNo = view->page.getPdfPageNr();
		XojPopplerPage * popplerPage = doc->getPdfPage(pgNo);
		PdfCache * cache = view->xournal->getCache();
		PdfView::drawPage(cache, popplerPage, crRect, zoom, pageWidth, pageHeight);
	}

	doc->lock();
	v.drawPage(view->page, crRect, false);
	doc->unlock();

	cairo_destroy(crRect);

	g_mutex_lock(view->drawingMutex);
	cairo_t * crPageBuffer = cairo_create(view->crBuffer);

	cairo_set_operator(crPageBuffer, CAIRO_OPERATOR_SOURCE);
	cairo_set_source_surface(crPageBuffer, rectBuffer, x, y);
	cairo_rectangle(crPageBuffer, x, y, width, height);
	cairo_fill(crPageBuffer);

	cairo_destroy(crPageBuffer);

	cairo_surface_destroy(rectBuffer);

	g_mutex_unlock(view->drawingMutex);
}
Example #2
0
void PreviewJob::run() {
	XOJ_CHECK_TYPE(PreviewJob);

	GtkAllocation alloc;
	gtk_widget_get_allocation(this->sidebarPreview->widget, &alloc);

	cairo_surface_t * crBuffer = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, alloc.width, alloc.height);

	double zoom = this->sidebarPreview->sidebar->getZoom();

	cairo_t * cr2 = cairo_create(crBuffer);
	cairo_matrix_t defaultMatrix = { 0 };
	cairo_get_matrix(cr2, &defaultMatrix);

	cairo_translate(cr2, Shadow::getShadowTopLeftSize() + 2, Shadow::getShadowTopLeftSize() + 2);

	cairo_scale(cr2, zoom, zoom);

	Document * doc = this->sidebarPreview->sidebar->getControl()->getDocument();
	doc->lock();

	if (this->sidebarPreview->page.getBackgroundType() == BACKGROUND_TYPE_PDF) {
		int pgNo = this->sidebarPreview->page.getPdfPageNr();
		XojPopplerPage * popplerPage = doc->getPdfPage(pgNo);
		PdfView::drawPage(this->sidebarPreview->sidebar->getCache(), popplerPage, cr2, zoom, this->sidebarPreview->page.getWidth(), this->sidebarPreview->page.getHeight());
	}

	DocumentView view;
	view.drawPage(this->sidebarPreview->page, cr2, true);

	cairo_set_matrix(cr2, &defaultMatrix);

	cairo_set_operator(cr2, CAIRO_OPERATOR_SOURCE);

	cairo_set_source_rgb(cr2, 1, 1, 1);
	cairo_rectangle(cr2, 0, 0, Shadow::getShadowTopLeftSize() + 2, alloc.height);
	cairo_rectangle(cr2, 0, 0, alloc.height, Shadow::getShadowTopLeftSize() + 2);

	cairo_rectangle(cr2, alloc.width - Shadow::getShadowBottomRightSize() - 2, 0, Shadow::getShadowBottomRightSize() + 2, alloc.height);
	cairo_rectangle(cr2, 0, alloc.height - Shadow::getShadowBottomRightSize() - 2, alloc.width, Shadow::getShadowBottomRightSize() + 2);

	cairo_fill(cr2);

	cairo_destroy(cr2);


	doc->unlock();

	g_mutex_lock(this->sidebarPreview->drawingMutex);

	if (this->sidebarPreview->crBuffer) {
		cairo_surface_destroy(this->sidebarPreview->crBuffer);
	}
	this->sidebarPreview->crBuffer = crBuffer;

	gdk_threads_enter();
	gtk_widget_queue_draw(this->sidebarPreview->widget);
	gdk_threads_leave();

	g_mutex_unlock(this->sidebarPreview->drawingMutex);
}
Example #3
0
void RenderJob::run() {
	XOJ_CHECK_TYPE(RenderJob);

	if(handler == NULL) {
		handler = new RepaintWidgetHandler(this->view->getXournal()->getWidget());
	}

	double zoom = this->view->xournal->getZoom();

	g_mutex_lock(this->view->repaintRectMutex);

	bool rerenderComplete = this->view->rerenderComplete;
	GList * rerenderRects = this->view->rerenderRects;
	this->view->rerenderRects = NULL;

	this->view->rerenderComplete = false;

	g_mutex_unlock(this->view->repaintRectMutex);


	if (rerenderComplete) {
		Document * doc = this->view->xournal->getDocument();

		int dispWidth = this->view->getDisplayWidth();
		int dispHeight = this->view->getDisplayHeight();

		cairo_surface_t * crBuffer = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, dispWidth, dispHeight);
		cairo_t * cr2 = cairo_create(crBuffer);
		cairo_scale(cr2, zoom, zoom);

		XojPopplerPage * popplerPage = NULL;

		doc->lock();

		if (this->view->page.getBackgroundType() == BACKGROUND_TYPE_PDF) {
			int pgNo = this->view->page.getPdfPageNr();
			popplerPage = doc->getPdfPage(pgNo);
		}

		DocumentView view;
		int width = this->view->page.getWidth();
		int height = this->view->page.getHeight();

		PdfView::drawPage(this->view->xournal->getCache(), popplerPage, cr2, zoom, width, height);
		view.drawPage(this->view->page, cr2, false);

		cairo_destroy(cr2);
		g_mutex_lock(this->view->drawingMutex);

		if (this->view->crBuffer) {
			cairo_surface_destroy(this->view->crBuffer);
		}
		this->view->crBuffer = crBuffer;

		g_mutex_unlock(this->view->drawingMutex);
		doc->unlock();

		handler->repaintComplete();
	} else {
		for (GList * l = rerenderRects; l != NULL; l = l->next) {
			Rectangle * rect = (Rectangle *) l->data;
			rerenderRectangle(rect);

			rect = this->view->rectOnWidget(rect->x, rect->y, rect->width, rect->height);
			handler->repaintRects(rect);
		}
	}


	// delete all rectangles
	for (GList * l = rerenderRects; l != NULL; l = l->next) {
		Rectangle * rect = (Rectangle *) l->data;
		delete rect;
	}
	g_list_free(rerenderRects);
}