Ejemplo n.º 1
0
void
draw_graph (HPDF_Page   page)
{
    char buf[50];
    int i;

    /* Draw 16 X 15 cells */

    /* Draw vertical lines. */
    HPDF_Page_SetLineWidth (page, 0.5);

    for (i = 0; i <= 17; i++) {
        int x = i * CELL_WIDTH + 40;

        HPDF_Page_MoveTo (page, x, PAGE_HEIGHT - 60);
        HPDF_Page_LineTo (page, x, 40);
        HPDF_Page_Stroke (page);

        if (i > 0 && i <= 16) {
            HPDF_Page_BeginText (page);
            HPDF_Page_MoveTextPos (page, x + 5, PAGE_HEIGHT - 75);
#ifdef __WIN32__
            _snprintf(buf, 5, "%X", i - 1);
#else
            snprintf(buf, 5, "%X", i - 1);
#endif
            HPDF_Page_ShowText (page, buf);
            HPDF_Page_EndText (page);
        }
    }

    /* Draw horizontal lines. */
    for (i = 0; i <= 15; i++) {
       int y = i * CELL_HEIGHT + 40;

        HPDF_Page_MoveTo (page, 40, y);
        HPDF_Page_LineTo (page, PAGE_WIDTH - 40, y);
        HPDF_Page_Stroke (page);

        if (i < 14) {
            HPDF_Page_BeginText (page);
            HPDF_Page_MoveTextPos (page, 45, y + 5);
#ifdef __WIN32__
            _snprintf(buf, 5, "%X", 15 - i);
#else
            snprintf(buf, 5, "%X", 15 - i);
#endif
            HPDF_Page_ShowText (page, buf);
            HPDF_Page_EndText (page);
        }
    }
}
/*
 * Class:     org_libharu_PdfPage
 * Method:    stroke
 * Signature: ()V
 */
JNIEXPORT void JNICALL
Java_org_libharu_PdfPage_stroke(JNIEnv *env, jobject obj) {
    jint page;
    /* Get mHPDFPagePointer */
    page = (*env)->GetIntField(env, obj, mHPDFPagePointer);
    HPDF_Page_Stroke((HPDF_Page) page);
}
JNIEXPORT void JNICALL Java_com_draekko_libharu_PdfPage_stroke
  (JNIEnv *env, jobject obj) {
    haru_setup_error_handler(env, __func__);
    HPDF_Page page = get_HPDF_Page(env, obj); 
    HPDF_Page_Stroke(page);
    haru_clear_error_handler();
}
Ejemplo n.º 4
0
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;
}
Ejemplo n.º 5
0
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;
}
Ejemplo n.º 6
0
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;
}
Ejemplo n.º 7
0
void WPdfImage::drawLine(double x1, double y1, double x2, double y2)
{
  if (painter()->pen().style() != PenStyle::None) {
    HPDF_Page_MoveTo(page_, x1, y1);
    HPDF_Page_LineTo(page_, x2, y2);

    HPDF_Page_Stroke(page_);
  }
}
Ejemplo n.º 8
0
void echo2(HPDF_Page page, char *str1, int i, int j){

    HPDF_Page_EndText (page);

    HPDF_Page_Rectangle (page, 10 + (HPDF_Page_GetWidth(page)/100)*i, HPDF_Page_GetHeight(page)-25 - j*10, 200,
                20);
    HPDF_Page_Stroke (page);

    HPDF_Page_BeginText (page);
    HPDF_Page_TextOut (page, 12 + (HPDF_Page_GetWidth(page)/100)*i, HPDF_Page_GetHeight(page)-20 - j*10, str1);
};
Ejemplo n.º 9
0
int CHaruPdf::Stroke()
{_STT();

	// Sanity checks
	if ( !m_page )
		return 0;

	// Commit drawing
	if ( HPDF_OK != HPDF_Page_Stroke( m_page ) )
		return 0;

	return 1;
}
Ejemplo n.º 10
0
void WPdfImage::paintPath()
{
  if (painter()->pen().style() != NoPen)
    if (painter()->brush().style() != NoBrush)
      HPDF_Page_FillStroke(page_);
    else
      HPDF_Page_Stroke(page_);
  else
    if (painter()->brush().style() != NoBrush)
      HPDF_Page_Fill(page_);
    else
      HPDF_Page_EndPath(page_);
}
Ejemplo n.º 11
0
void WPdfImage::paintPath()
{
  if (painter()->pen().style() != PenStyle::None)
    if (painter()->brush().style() != BrushStyle::None)
      HPDF_Page_FillStroke(page_);
    else
      HPDF_Page_Stroke(page_);
  else
    if (painter()->brush().style() != BrushStyle::None)
      HPDF_Page_Fill(page_);
    else
      HPDF_Page_EndPath(page_);
}
Ejemplo n.º 12
0
void
show_stripe_pattern  (HPDF_Page   page,
                      HPDF_REAL   x,
                      HPDF_REAL   y)
{
    HPDF_UINT iy = 0;

    while (iy < 50) {
        HPDF_Page_SetRGBStroke (page, 0.0, 0.0, 0.5);
        HPDF_Page_SetLineWidth (page, 1);
        HPDF_Page_MoveTo (page, x, y + iy);
        HPDF_Page_LineTo (page, x + HPDF_Page_TextWidth (page, "ABCabc123"),
                    y + iy);
        HPDF_Page_Stroke (page);
        iy += 3;
    }

    HPDF_Page_SetLineWidth (page, 2.5);
}
Ejemplo n.º 13
0
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;
}
Ejemplo n.º 14
0
void table(HPDF_Page page, HPDF_Font font, int row, int col, int X, int Y, int H,
        int *p, char**text){
    int width = HPDF_Page_GetWidth(page);
    //int height = HPDF_Page_GetHeight(page);
    int r=0, c=0, x, y, W = (width-20) / col;
    char tmp[130], tmp2[130];


    for (r = 0; r < row; r++)
    {
        x = 0; W = 0;
        for (c = 0; c < col; c++)
        {
            x = x + W;
            W = ((width-20)/100)*p[c];
            y = Y - (r * H);
            HPDF_Page_Rectangle (page, x +X , y , W, H);
            HPDF_Page_Stroke (page);

            HPDF_Page_BeginText (page);
            HPDF_Page_SetFontAndSize (page, font, 10);

            sprintf(tmp2, "%dx%d", r,c);
            sprintf(tmp,"[%s] %d %d %d %d | %d %d %d %d", tmp2, x , y, W, y, /*!*/ x+5 , y+10, x+W, y-10);
            sprintf(tmp,"[%s] %s", tmp2, text[(r*col)+c]);
            sprintf(tmp, "%s", text[(r*col)+c]);

            HPDF_Page_TextRect (page, x+2 +X+2 , y+15, x+W, y-10,
                    tmp, HPDF_TALIGN_LEFT, NULL);
            HPDF_Page_EndText (page);

            //HPDF_Page_TextRect (page, 10 , 600, 50, 550,
            //break;
        }
        //break;

    }
};
Ejemplo n.º 15
0
int main (int /* argc */, char **argv)
{
    const char *page_title = "Font Demo";
    HPDF_Doc  pdf;
    char fname[256];
    HPDF_Page page;
    HPDF_Font def_font;
    HPDF_REAL tw;
    HPDF_REAL height;
    HPDF_REAL width;
    HPDF_UINT i;
    HPDF_Image image;
    double x;
    double y;
    double iw;
    double ih;
    HPDF_Stream stream;
    
    strcpy (fname, argv[0]);
    strcat (fname, ".pdf");

    pdf = HPDF_New (error_handler, NULL);
    if (!pdf) {
        printf ("error: cannot create PdfDoc object\n");
        return 1;
    }

    if (setjmp(env)) {
        HPDF_Free (pdf);
        return 1;
    }

    /* Add a new page object. */
    page = HPDF_AddPage (pdf);

    height = HPDF_Page_GetHeight (page);
    width = HPDF_Page_GetWidth (page);

    /* Print the lines of the page. */
    HPDF_Page_SetLineWidth (page, 1);
    HPDF_Page_Rectangle (page, 50, 50, width - 100, height - 110);
    HPDF_Page_Stroke (page);

    /* Print the title of the page (with positioning center). */
    def_font = HPDF_GetFont (pdf, "Helvetica", NULL);
    HPDF_Page_SetFontAndSize (page, def_font, 24);

    tw = HPDF_Page_TextWidth (page, page_title);
    HPDF_Page_BeginText (page);
    HPDF_Page_TextOut (page, (width - tw) / 2, height - 50, page_title);
    HPDF_Page_EndText (page);

    /* output subtitle. */
    HPDF_Page_BeginText (page);
    HPDF_Page_SetFontAndSize (page, def_font, 16);
    HPDF_Page_TextOut (page, 60, height - 80, "<Standerd Type1 fonts samples>");
    HPDF_Page_EndText (page);

    HPDF_Page_BeginText (page);
    HPDF_Page_MoveTextPos (page, 60, height - 105);

    i = 0;
    while (font_list[i]) {
        const char* samp_text = "abcdefgABCDEFG12345!#$%&+-@?";
        HPDF_Font font = HPDF_GetFont (pdf, font_list[i], NULL);

        /* print a label of text */
        HPDF_Page_SetFontAndSize (page, def_font, 9);
        HPDF_Page_ShowText (page, font_list[i]);
        HPDF_Page_MoveTextPos (page, 0, -18);

        /* print a sample text. */
        HPDF_Page_SetFontAndSize (page, font, 20);
        HPDF_Page_ShowText (page, samp_text);
        HPDF_Page_MoveTextPos (page, 0, -20);

        i++;
    }

    HPDF_Page_EndText (page);

    /* Add a new page object. */
    page = HPDF_AddPage (pdf);

    height = HPDF_Page_GetHeight (page);
    width = HPDF_Page_GetWidth (page);
    
    /* load image file. */
    image = HPDF_LoadPngImageFromFile (pdf, "test.png");

    x = 100;
    y = 100;
    iw = HPDF_Image_GetWidth (image);
    ih = HPDF_Image_GetHeight (image);
    
    /* Draw image to the canvas. (normal-mode with actual size.)*/
    HPDF_Page_DrawImage (page, image, x, y, iw, ih);
    
    HPDF_SaveToFile (pdf, fname);
    
    /* write something via zlib */
    stream = HPDF_FileWriter_New( pdf->mmgr, "test2.raw" );    
    HPDF_Stream_WriteToStream( image->stream, stream, HPDF_STREAM_FILTER_FLATE_DECODE, NULL );
    HPDF_Stream_Free (stream);
    
    /* clean up */
    HPDF_Free (pdf);

    return 0;
}
Ejemplo n.º 16
0
int main (int argc, char **argv)
{
    const char *page_title = "Font Demo";
    HPDF_Doc  pdf;
    char fname[256];
    HPDF_Page page;
    HPDF_Font def_font;
    HPDF_REAL tw;
    HPDF_REAL height;
    HPDF_REAL width;
    HPDF_UINT i;

    strcpy (fname, argv[0]);
    strcat (fname, ".pdf");

    pdf = HPDF_New (error_handler, NULL);
    if (!pdf) {
        printf ("error: cannot create PdfDoc object\n");
        return 1;
    }

    if (setjmp(env)) {
        HPDF_Free (pdf);
        return 1;
    }

    /* Add a new page object. */
    page = HPDF_AddPage (pdf);

    height = HPDF_Page_GetHeight (page);
    width = HPDF_Page_GetWidth (page);

    /* Print the lines of the page. */
    HPDF_Page_SetLineWidth (page, 1);
    HPDF_Page_Rectangle (page, 50, 50, width - 100, height - 110);
    HPDF_Page_Stroke (page);

    /* Print the title of the page (with positioning center). */
    def_font = HPDF_GetFont (pdf, "Helvetica", NULL);
    HPDF_Page_SetFontAndSize (page, def_font, 24);

    tw = HPDF_Page_TextWidth (page, page_title);
    HPDF_Page_BeginText (page);
    HPDF_Page_TextOut (page, (width - tw) / 2, height - 50, page_title);
    HPDF_Page_EndText (page);

    /* output subtitle. */
    HPDF_Page_BeginText (page);
    HPDF_Page_SetFontAndSize (page, def_font, 16);
    HPDF_Page_TextOut (page, 60, height - 80, "<Standerd Type1 fonts samples>");
    HPDF_Page_EndText (page);

    HPDF_Page_BeginText (page);
    HPDF_Page_MoveTextPos (page, 60, height - 105);

    i = 0;
    while (font_list[i]) {
        const char* samp_text = "ÏðèâåòabcdefgABCDEFG12345!#$%&+-@?";
        HPDF_Font font = HPDF_GetFont (pdf, font_list[i], "CP1251");

        /* print a label of text */
        HPDF_Page_SetFontAndSize (page, def_font, 9);
        HPDF_Page_ShowText (page, font_list[i]);
        HPDF_Page_MoveTextPos (page, 0, -18);

        /* print a sample text. */
        HPDF_Page_SetFontAndSize (page, font, 20);
        HPDF_Page_ShowText (page, samp_text);
        HPDF_Page_MoveTextPos (page, 0, -20);

        i++;
    }

    HPDF_Page_EndText (page);

    HPDF_SaveToFile (pdf, fname);

    /* clean up */
    HPDF_Free (pdf);

    return 0;
}
Ejemplo n.º 17
0
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;
}
Ejemplo n.º 18
0
void hpdf_doc::add_text(et_datachunk &dc)
{
	et_type datatype = dc.type;
	wstring &out_string = dc.w_string;

	char *line = new char[4096];
	memset(line, 0, 4096);
	_locale_t loceng;
	size_t size = 0;

	loceng = _create_locale(LC_ALL, "en-US");

	int len = out_string.length(); // count of space
	int n_TX = (et_cp.TX > 0) ? et_cp.TX : et_cp.T,
		n_TY = (et_cp.TY > 0) ? et_cp.TY : et_cp.T;

	HPDF_REAL f_xpos = dc.rect.left, f_ypos = dc.rect.bottom;
	HPDF_REAL f_advance = 0.0;
	HPDF_REAL f_width = MMTEXT2PTX(et_cp.W * n_TX / 2);
	HPDF_REAL f_gap = MMTEXT2PTX(et_cp.X/2);
	HPDF_REAL f_space = MMTEXT2PTY((et_cp.Z * n_TY) + et_cp.L);

	HPDF_Page_BeginText(h_current_page);

	select_datatype_font(datatype);

	f_space = HPDF_Page_GetCurrentFontSize(h_current_page);

	if (f_space > f_linespace)
		f_linespace = f_space;


	switch (datatype) {
	case ET_LATAN:
		
		/*
		size = _wcstombs_l(line, out_string.c_str(), 4096, loceng);
		if (size == 0) goto END_PROC;

		HPDF_Page_TextOut(h_current_page, f_xpos, f_ypos - f_linespace, line);
		f_advance = HPDF_Page_TextWidth(h_current_page, line); 
		*/
		if (et_cp.CorE == 'C') f_width = f_width * 2;
		text_out_eng(f_xpos, f_ypos, out_string, f_advance, f_width, f_gap, f_space, loceng);
		break;
	case ET_SPACE:
		f_advance += ((f_width + f_gap) * len);
		break;

	case ET_CJK:
	case ET_CJKFORM:
	case ET_BOXDRAW:

		if (et_cp.VorH == 'H' || datatype != ET_CJK)
			horizontal(f_xpos, f_ypos);
		else
			vertical(f_xpos, f_ypos);

		if (datatype == ET_BOXDRAW) resize_font_boxdraw();
		/*
		size = wchar_to_utf8(out_string.c_str(), out_string.length(), line, 4096, NULL);
		if (size == 0) goto END_PROC;
		
		HPDF_Page_TextOut(h_current_page, f_xpos, f_ypos - f_linespace, line);
		//if (datatype == ET_BOXDRAW)
		//	f_advance += (len * ((f_width + f_gap) * 2));
		//else
			f_advance += HPDF_Page_TextWidth(h_current_page, line); //(len * ((f_width + f_gap) * 2));
			*/
		text_out_cjk(f_xpos, f_ypos, out_string, f_advance, f_width, f_gap, f_space);

		break;
	}
	HPDF_Page_EndText(h_current_page);
	
	if (et_cp.U > 0)
	{
		HPDF_Page_SetLineWidth(h_current_page, 0.5);
		HPDF_Page_MoveTo(h_current_page, f_xpos, f_ypos - f_linespace);
		HPDF_Page_LineTo(h_current_page, f_xpos, f_ypos);
		HPDF_Page_Stroke(h_current_page);
	}
	
	f_xpos += f_advance;

	delete [] line; // free buffer

	_free_locale(loceng);
}
Ejemplo n.º 19
0
void
generate_pdf (const char *outname, const char *tmpdirname, int num_fonts,
	      int num_input_files, const JBDATA * data,
	      const struct mapping *maps, int debug_draw_borders)
{
  int i, j;
  /* Create the pdf document */
  l_int32 ncomp = numaGetCount (data->naclass);
  HPDF_Doc pdf = HPDF_New (pdf_error_handler, NULL);

  HPDF_SetCompressionMode (pdf, HPDF_COMP_ALL);
  HPDF_Font *fonts = malloc_guarded (num_fonts * (sizeof (HPDF_Font)));

  int dirlen = strlen (tmpdirname);

  /* Load the fonts */
  for (i = 0; i < num_fonts; i++)
    {
      /* 1 for '/', 8 for %08d, 4 for '.ttf' */
      int fontlen = dirlen + 1 + 8 + 4;
      char *font_tfname = malloc_guarded (fontlen + 1);
      sprintf (font_tfname, "%s/%08d.ttf", tmpdirname, i);

      const char *font_name =
	HPDF_LoadTTFontFromFile (pdf, font_tfname, HPDF_TRUE);
      fonts[i] = HPDF_GetFont (pdf, font_name, "KOI8-R");
      free (font_tfname);
    }

  for (j = 0; j < num_input_files; j++)
    {
      /* Add page to document */
      HPDF_Page pg = HPDF_AddPage (pdf);

      HPDF_Page_SetWidth (pg, data->w);
      HPDF_Page_SetHeight (pg, data->h);

      /* TODO: Boost efficiency by making startcomp go to the next page on the next iteration */
      int start_comp = 0;

      for (i = start_comp; i < ncomp; i++)
	{
	  l_int32 ipage;
	  l_int32 iclass;
	  l_int32 x;
	  l_int32 y;

	  numaGetIValue (data->napage, i, &ipage);

	  if (ipage != j)
	    continue;

	  numaGetIValue (data->naclass, i, &iclass);
	  ptaGetIPt (data->ptaul, i, &x, &y);

	  /*double left = x;
	     double top = data->h - y;
	     double right = x + data->latticew;
	     double bottom = data->h - (y + data->latticeh); */

	  char text[2];
	  text[0] = maps[iclass].code_point;
	  text[1] = '\0';

	  HPDF_Font font = fonts[maps[iclass].font_num];

	  HPDF_Page_BeginText (pg);
	  double fontsize = 100;

	  if (fontsize > 300)
	    {
	      error_quit ("This is a known bug.\n"
			  "libharu can't handle fontsizes bigger than 300, which is what is being requested here.\n"
			  "Please report this bug, and the file that produced this error");
	    }

	  HPDF_Page_SetFontAndSize (pg, font, 100);

	  HPDF_Page_MoveTextPos (pg, x, (data->h - y) - data->latticeh);
	  HPDF_Page_ShowText (pg, text);

	  HPDF_Page_EndText (pg);

	  if (debug_draw_borders)
	    {
	      HPDF_Page_SetRGBStroke (pg, 1, 0, 0);
	      /* In this, x, y is the LOWER LEFT, not UPPER LEFT */
	      HPDF_Page_Rectangle (pg, x, (data->h - y) - data->latticeh,
				   data->latticew, data->latticeh);
	      HPDF_Page_Stroke (pg);
	    }
	}
    }

  /* Output */
  HPDF_SaveToFile (pdf, outname);

  /* Cleanup */
  HPDF_Free (pdf);
  free (fonts);
}
Ejemplo n.º 20
0
		int fileWriter(HPDF_Doc  pdf,
			HPDF_Outline root,
			HPDF_Font font,
			const std::string curFile,
			const std::vector< std::string> vec) {

			auto func_footbar = [](std::string fileName)->std::string {
				std::ostringstream buffer;
				buffer << "  File:" << fileName.c_str() << "   Autor:XCL ";
				return buffer.str();
			};

			auto func_pageOutline = [&](HPDF_Page page, std::string curFile) {
				HPDF_Outline outline;
				HPDF_Destination dst;
				outline = HPDF_CreateOutline(pdf, root, curFile.c_str(), NULL);
				dst = HPDF_Page_CreateDestination(page);
				HPDF_Destination_SetXYZ(dst, 0, HPDF_Page_GetHeight(page), 1);// 1 = 默认百分比100
				HPDF_Outline_SetDestination(outline, dst);
			};
			
			auto func_drawRow = [](HPDF_Page page,std::string rid,std::string row,int y ) {
				HPDF_Page_BeginText(page);
				HPDF_Page_MoveTextPos(page, config::ROWID_WIDTH, y - 2);
				HPDF_Page_ShowText(page, rid.c_str());
				HPDF_Page_ShowText(page, row.c_str());
				HPDF_Page_EndText(page);
			};

			HPDF_Page page = nullptr;			
			HPDF_REAL width,height;		
			HPDF_UINT y = 0;		//  x =0,
			int currID = 0, pageID = 0, currRowCount;
			std::string ss, rid;
	
			for (int i = 0; i < vec.size(); i++) {							
				if (i == 0 || currRowCount >  config::PAGE_ROWNUM) {
					//////////////////////////////////////////////
					page = HPDF_AddPage(pdf);

					width = HPDF_Page_GetWidth(page);
					height = HPDF_Page_GetHeight(page);
//					x = 0;
					y = height - config::ROW_HEIGHT;

					func_pageOutline(page, curFile);
					HPDF_Page_SetSize(page, HPDF_PAGE_SIZE_A4, HPDF_PAGE_PORTRAIT);															

					{
						HPDF_RGBColor c = HPDF_Page_GetRGBFill(page);
						HPDF_Page_SetRGBStroke(page, 0.0, 0.5, 0);
						HPDF_Page_SetFontAndSize(page, font, config::FOOTBAR_FONT_SIZE);
						HPDF_Page_SetLineWidth(page, 0.5);
						HPDF_Page_MoveTo(page, 0, 13);
						HPDF_Page_LineTo(page, width, 16);
						HPDF_Page_Stroke(page);

						HPDF_Page_SetRGBFill(page, 0.0, 0, 0.5);
						HPDF_Page_BeginText(page);
						HPDF_Page_MoveTextPos(page, 40, config::FOOTBAR_FONT_SIZE - 5);
						HPDF_Page_ShowText(page, func_footbar(curFile).c_str());
						HPDF_Page_EndText(page);
						HPDF_Page_SetRGBFill(page, c.r, c.g, c.b);
					};
					
					y = height - config::ROW_HEIGHT * 2;
					HPDF_Page_SetFontAndSize(page, font, config::PAGE_FONT_SIZE);
					pageID++;
					currRowCount = 1;
					//////////////////////////////////////////////
				}
												
				///////////////////////////////////////////			
				 ss = vec[i];
				 HPDF_REAL wrid = HPDF_Page_TextWidth(page, rid.c_str());
			 NEWROW:			
				 HPDF_REAL wss = HPDF_Page_TextWidth(page, ss.c_str());			
				 rid = util::rowidWidth(currRowCount );
				 if (wrid + wss >  width) {
					 //简单处理:超过页宽,直接分成两行.足以应付大部份情况.
					 int center = ss.length() / 2;		 
					 func_drawRow(page, rid,ss.substr(0, center),y);
					 y -= config::ROW_HEIGHT;
					 currRowCount++;
					 ss = ss.substr(center);
					 goto NEWROW;
				 }
				 else {			
					func_drawRow(page, rid, ss,y);				
					y -= config::ROW_HEIGHT;		
					currRowCount++;
				 }
				//////////////////////////////////////////
			}
			return 0;
		} //end func
Ejemplo n.º 21
0
int write_pdf(int argc, char ** argv, FILE * pipe_in, FILE * pipe_out, FILE * pipe_err)
{
  char * filename = argc > 1 ? argv[1] : "output.pdf";
  if (argc == 1)
  {
    fprintf(stderr, "no filename specified, using '%s'\n", filename);
  }
  
  float b[3][2] = {
    {FLT_MAX, -FLT_MAX},
    {FLT_MAX, -FLT_MAX},
    {FLT_MAX, -FLT_MAX}
  };
  
  HPDF_Doc pdf;
  
  pdf = HPDF_New(NULL, NULL); 
  if (!pdf)
  {
    fprintf(stderr, "ERROR: cannot create pdf object.\n");
    return 1;
  }
  
  HPDF_SetCompressionMode (pdf, HPDF_COMP_ALL);
  HPDF_SetPageMode (pdf, HPDF_PAGE_MODE_USE_OUTLINE);
  
  int num_shapes = 0;
  struct Shape ** shapes = NULL;
  
  HPDF_Page page;
  page = HPDF_AddPage (pdf);
  
  HPDF_Page_SetSize (page, HPDF_PAGE_SIZE_LETTER, HPDF_PAGE_PORTRAIT);
  
  long i = 0;
  struct Shape * shape = NULL;
  while ((shape = read_shape(pipe_in)))
  {
    num_shapes++;
    shapes = (struct Shape **)realloc(shapes, sizeof(struct Shape*)*num_shapes);
    if (shapes == NULL) { fprintf(stderr, "realloc for shapes failed :(\n"); exit(0); }
    shapes[num_shapes-1] = shape;
    
    long j;
    for (j = 0 ; j < shape->num_vertexs ; j++)
    {
      float * v = get_vertex(shape, 0, j);
      if (v[0] < b[0][0]) b[0][0] = v[0]; if (v[0] > b[0][1]) b[0][1] = v[0];
      if (v[1] < b[1][0]) b[1][0] = v[1]; if (v[1] > b[1][1]) b[1][1] = v[1];
    }
  }
  
  float dx = b[0][1] - b[0][0];
  float dy = b[1][1] - b[1][0];
  float ratio = dy / dx;
  
  HPDF_Page_SetWidth(page, 2000);
  HPDF_Page_SetHeight(page, 2000.0 * ratio);
  
  for (i = 0 ; i < num_shapes ; i++)
  {
    shape = shapes[i];
    //if (shape->vertex_arrays[0].num_dimensions < 2) { fprintf(stderr, "\n"); continue; }
    
    long j;
    for (j = 0 ; j < shape->num_vertexs ; j++)
    {
      float * v = get_vertex(shape, 0, j);
      if (j == 0)
        HPDF_Page_MoveTo(page, (v[0] - b[0][0]) / dx * 2000.0, (v[1] - b[1][0]) / dy * (2000.0 * ratio));
      else
        HPDF_Page_LineTo(page, (float)(v[0] - b[0][0]) / dx * 2000.0, (float)(v[1] - b[1][0]) / dy * (2000.0 * ratio));
    }
    
    if (shape->gl_type == GL_LINE_LOOP)
    {
      float * v = get_vertex(shape, 0, 0);
      HPDF_Page_LineTo(page, (float)(v[0] - b[0][0]) / dx * 2000.0, (float)(v[1] - b[1][0]) / dy * (2000.0 * ratio));
    }
    
    HPDF_Page_Stroke(page);
    free_shape(shape);
  }
  free(shapes);
  
  HPDF_SaveToFile (pdf, filename);
  
  HPDF_Free(pdf);
}