bool pdf_plot_disc(int x, int y, int radius, const plot_style_t *style) { #ifdef PDF_DEBUG NSLOG(netsurf, INFO, "."); #endif if (style->fill_type != PLOT_OP_TYPE_NONE) { apply_clip_and_mode(false, style->fill_colour, NS_TRANSPARENT, 1., DashPattern_eNone); HPDF_Page_Circle(pdf_page, x, page_height - y, radius); HPDF_Page_Fill(pdf_page); } if (style->stroke_type != PLOT_OP_TYPE_NONE) { /* FIXME: line width 1 is ok ? */ apply_clip_and_mode(false, NS_TRANSPARENT, style->stroke_colour, 1., DashPattern_eNone); HPDF_Page_Circle(pdf_page, x, page_height - y, radius); HPDF_Page_Stroke(pdf_page); } return true; }
bool pdf_plot_rectangle(int x0, int y0, int x1, int y1, const plot_style_t *pstyle) { DashPattern_e dash; #ifdef PDF_DEBUG NSLOG(netsurf, INFO, "%d %d %d %d %f %X", x0, y0, x1, y1, page_height - y0, pstyle->fill_colour); #endif if (pstyle->fill_type != PLOT_OP_TYPE_NONE) { apply_clip_and_mode(false, pstyle->fill_colour, NS_TRANSPARENT, 0., DashPattern_eNone); /* Normalize boundaries of the area - to prevent overflows. It is needed only in a few functions, where integers are subtracted. When the whole browser window is meant min and max int values are used what must be handled in paged output. */ x0 = min(max(x0, 0), page_width); y0 = min(max(y0, 0), page_height); x1 = min(max(x1, 0), page_width); y1 = min(max(y1, 0), page_height); HPDF_Page_Rectangle(pdf_page, x0, page_height - y1, x1 - x0, y1 - y0); HPDF_Page_Fill(pdf_page); } if (pstyle->stroke_type != PLOT_OP_TYPE_NONE) { switch (pstyle->stroke_type) { case PLOT_OP_TYPE_DOT: dash = DashPattern_eDotted; break; case PLOT_OP_TYPE_DASH: dash = DashPattern_eDash; break; default: dash = DashPattern_eNone; break; } apply_clip_and_mode(false, NS_TRANSPARENT, pstyle->stroke_colour, plot_style_int_to_fixed(pstyle->stroke_width), dash); HPDF_Page_Rectangle(pdf_page, x0, page_height - y0, x1 - x0, -(y1 - y0)); HPDF_Page_Stroke(pdf_page); } return true; }
void pdf_end(void) { #ifdef PDF_DEBUG NSLOG(netsurf, INFO, "pdf_end begins"); #endif clip_update_needed = false; if (pdf_page != NULL) { apply_clip_and_mode(false, NS_TRANSPARENT, NS_TRANSPARENT, 0., DashPattern_eNone); pdfw_gs_restore(pdf_page); } #ifdef PDF_DEBUG_DUMPGRID if (pdf_page != NULL) { pdf_plot_grid(10, 10, 0xCCCCCC); pdf_plot_grid(100, 100, 0xCCCCFF); } #endif assert(settings->output != NULL); /*Encryption on*/ if (option_enable_PDF_password) guit->misc->pdf_password(&owner_pass, &user_pass, (void *)settings->output); else save_pdf(settings->output); #ifdef PDF_DEBUG NSLOG(netsurf, INFO, "pdf_end finishes"); #endif }
bool pdf_plot_bitmap_tile(int x, int y, int width, int height, struct bitmap *bitmap, colour bg, bitmap_flags_t flags) { HPDF_Image image; HPDF_REAL current_x, current_y ; HPDF_REAL max_width, max_height; #ifdef PDF_DEBUG NSLOG(netsurf, INFO, "%d %d %d %d %p 0x%x", x, y, width, height, bitmap, bg); #endif if (width == 0 || height == 0) return true; apply_clip_and_mode(false, NS_TRANSPARENT, NS_TRANSPARENT, 0., DashPattern_eNone); image = pdf_extract_image(bitmap); if (!image) return false; /*The position of the next tile*/ max_width = (flags & BITMAPF_REPEAT_X) ? page_width : width; max_height = (flags & BITMAPF_REPEAT_Y) ? page_height : height; for (current_y = 0; current_y < max_height; current_y += height) for (current_x = 0; current_x < max_width; current_x += width) HPDF_Page_DrawImage(pdf_page, image, current_x + x, page_height - current_y - y - height, width, height); return true; }
bool pdf_plot_text(int x, int y, const char *text, size_t length, const plot_font_style_t *fstyle) { #ifdef PDF_DEBUG NSLOG(netsurf, INFO, ". %d %d %.*s", x, y, (int)length, text); #endif char *word; HPDF_Font pdf_font; HPDF_REAL size; if (length == 0) return true; apply_clip_and_mode(true, fstyle->foreground, NS_TRANSPARENT, 0., DashPattern_eNone); haru_nsfont_apply_style(fstyle, pdf_doc, pdf_page, &pdf_font, &size); pdfw_gs_font(pdf_page, pdf_font, size); /* FIXME: UTF-8 to current font encoding needs to done. Or the font * encoding needs to be UTF-8 or other Unicode encoding. */ word = (char *)malloc( sizeof(char) * (length+1) ); if (word == NULL) return false; memcpy(word, text, length); word[length] = '\0'; HPDF_Page_TextOut (pdf_page, x, page_height - y, word); free(word); return true; }
bool pdf_plot_polygon(const int *p, unsigned int n, const plot_style_t *style) { unsigned int i; #ifdef PDF_DEBUG int pmaxx = p[0], pmaxy = p[1]; int pminx = p[0], pminy = p[1]; NSLOG(netsurf, INFO, "."); #endif if (n == 0) return true; apply_clip_and_mode(false, style->fill_colour, NS_TRANSPARENT, 0., DashPattern_eNone); HPDF_Page_MoveTo(pdf_page, p[0], page_height - p[1]); for (i = 1 ; i<n ; i++) { HPDF_Page_LineTo(pdf_page, p[i*2], page_height - p[i*2+1]); #ifdef PDF_DEBUG pmaxx = max(pmaxx, p[i*2]); pmaxy = max(pmaxy, p[i*2+1]); pminx = min(pminx, p[i*2]); pminy = min(pminy, p[i*2+1]); #endif } #ifdef PDF_DEBUG NSLOG(netsurf, INFO, "%d %d %d %d %f", pminx, pminy, pmaxx, pmaxy, page_height - pminy); #endif HPDF_Page_Fill(pdf_page); return true; }
bool pdf_plot_line(int x0, int y0, int x1, int y1, const plot_style_t *pstyle) { DashPattern_e dash; switch (pstyle->stroke_type) { case PLOT_OP_TYPE_DOT: dash = DashPattern_eDotted; break; case PLOT_OP_TYPE_DASH: dash = DashPattern_eDash; break; default: dash = DashPattern_eNone; break; } apply_clip_and_mode(false, NS_TRANSPARENT, pstyle->stroke_colour, plot_style_int_to_fixed(pstyle->stroke_width), dash); HPDF_Page_MoveTo(pdf_page, x0, page_height - y0); HPDF_Page_LineTo(pdf_page, x1, page_height - y1); HPDF_Page_Stroke(pdf_page); return true; }
bool pdf_plot_arc(int x, int y, int radius, int angle1, int angle2, const plot_style_t *style) { #ifdef PDF_DEBUG LOG(("%d %d %d %d %d %X", x, y, radius, angle1, angle2, style->stroke_colour)); #endif /* FIXME: line width 1 is ok ? */ apply_clip_and_mode(false, NS_TRANSPARENT, style->fill_colour, 1., DashPattern_eNone); /* Normalize angles */ angle1 %= 360; angle2 %= 360; if (angle1 > angle2) angle1 -= 360; HPDF_Page_Arc(pdf_page, x, page_height - y, radius, angle1, angle2); HPDF_Page_Stroke(pdf_page); return true; }
bool pdf_next_page(void) { #ifdef PDF_DEBUG NSLOG(netsurf, INFO, "pdf_next_page begins"); #endif clip_update_needed = false; if (pdf_page != NULL) { apply_clip_and_mode(false, NS_TRANSPARENT, NS_TRANSPARENT, 0., DashPattern_eNone); pdfw_gs_restore(pdf_page); } #ifdef PDF_DEBUG_DUMPGRID if (pdf_page != NULL) { pdf_plot_grid(10, 10, 0xCCCCCC); pdf_plot_grid(100, 100, 0xCCCCFF); } #endif pdf_page = HPDF_AddPage(pdf_doc); if (pdf_page == NULL) return false; HPDF_Page_SetWidth (pdf_page, settings->page_width); HPDF_Page_SetHeight(pdf_page, settings->page_height); HPDF_Page_Concat(pdf_page, 1, 0, 0, 1, FIXTOFLT(settings->margins[MARGINLEFT]), 0); pdfw_gs_save(pdf_page); #ifdef PDF_DEBUG NSLOG(netsurf, INFO, "%f %f", page_width, page_height); #endif return true; }
bool pdf_plot_path(const float *p, unsigned int n, colour fill, float width, colour c, const float transform[6]) { unsigned int i; bool empty_path; #ifdef PDF_DEBUG NSLOG(netsurf, INFO, "."); #endif if (n == 0) return true; if (c == NS_TRANSPARENT && fill == NS_TRANSPARENT) return true; if (p[0] != PLOTTER_PATH_MOVE) return false; apply_clip_and_mode(false, fill, c, width, DashPattern_eNone); empty_path = true; for (i = 0 ; i < n ; ) { if (p[i] == PLOTTER_PATH_MOVE) { HPDF_Page_MoveTo(pdf_page, transform_x(transform, p[i+1], p[i+2]), transform_y(transform, p[i+1], p[i+2])); i+= 3; } else if (p[i] == PLOTTER_PATH_CLOSE) { if (!empty_path) HPDF_Page_ClosePath(pdf_page); i++; } else if (p[i] == PLOTTER_PATH_LINE) { HPDF_Page_LineTo(pdf_page, transform_x(transform, p[i+1], p[i+2]), transform_y(transform, p[i+1], p[i+2])); i+=3; empty_path = false; } else if (p[i] == PLOTTER_PATH_BEZIER) { HPDF_Page_CurveTo(pdf_page, transform_x(transform, p[i+1], p[i+2]), transform_y(transform, p[i+1], p[i+2]), transform_x(transform, p[i+3], p[i+4]), transform_y(transform, p[i+3], p[i+4]), transform_x(transform, p[i+5], p[i+6]), transform_y(transform, p[i+5], p[i+6])); i += 7; empty_path = false; } else { NSLOG(netsurf, INFO, "bad path command %f", p[i]); return false; } } if (empty_path) { HPDF_Page_EndPath(pdf_page); return true; } if (fill != NS_TRANSPARENT) { if (c != NS_TRANSPARENT) HPDF_Page_FillStroke(pdf_page); else HPDF_Page_Fill(pdf_page); } else HPDF_Page_Stroke(pdf_page); return true; }