void PDF_ExtGState_SetAlphaStroke(sLONG_PTR *pResult, PackagePtr pParams) { C_TEXT Param1; C_REAL Param2; C_LONGINT returnValue; Param1.fromParamAtIndex(pParams, 1); Param2.fromParamAtIndex(pParams, 2); HPDF_ExtGState ext_gstate = (HPDF_ExtGState)_fromHex(Param1); HPDF_REAL value = (HPDF_REAL)Param2.getDoubleValue(); returnValue.setIntValue(HPDF_ExtGState_SetAlphaStroke(ext_gstate, value)); returnValue.setReturn(pResult); }
void WPdfImage::setChanged(WFlags<PainterChangeFlag> flags) { if (!flags.empty()) { HPDF_Page_GRestore(page_); HPDF_Page_GSave(page_); HPDF_ExtGState gstate; gstate = HPDF_CreateExtGState (pdf_); currentFont_ = WFont(); if (painter()->hasClipping()) { const WTransform& t = painter()->clipPathTransform(); if (!painter()->clipPath().isEmpty()) { applyTransform(t); drawPlainPath(painter()->clipPath()); HPDF_Page_Clip(page_); HPDF_Page_EndPath(page_); applyTransform(t.inverted()); } } applyTransform(painter()->combinedTransform()); const WPen& pen = painter()->pen(); if (pen.style() != PenStyle::None) { const WColor& color = pen.color(); HPDF_Page_SetRGBStroke(page_, color.red() / 255., color.green() / 255., color.blue() / 255.); HPDF_ExtGState_SetAlphaStroke (gstate, color.alpha()/255.); WLength w = painter()->normalizedPenWidth(pen.width(), false); HPDF_Page_SetLineWidth(page_, w.toPixels()); switch (pen.capStyle()) { case PenCapStyle::Flat: HPDF_Page_SetLineCap(page_, HPDF_BUTT_END); break; case PenCapStyle::Square: HPDF_Page_SetLineCap(page_, HPDF_PROJECTING_SCUARE_END); // scuary ! break; case PenCapStyle::Round: HPDF_Page_SetLineCap(page_, HPDF_ROUND_END); break; } switch (pen.joinStyle()) { case PenJoinStyle::Miter: HPDF_Page_SetLineJoin(page_, HPDF_MITER_JOIN); break; case PenJoinStyle::Bevel: HPDF_Page_SetLineJoin(page_, HPDF_BEVEL_JOIN); break; case PenJoinStyle::Round: HPDF_Page_SetLineJoin(page_, HPDF_ROUND_JOIN); break; } switch (pen.style()) { case PenStyle::None: break; case PenStyle::SolidLine: HPDF_Page_SetDash(page_, nullptr, 0, 0); break; case PenStyle::DashLine: { const HPDF_UINT16 dash_ptn[] = { 4, 2 }; HPDF_Page_SetDash(page_, dash_ptn, 2, 0); break; } case PenStyle::DotLine: { const HPDF_UINT16 dash_ptn[] = { 1, 2 }; HPDF_Page_SetDash(page_, dash_ptn, 2, 0); break; } case PenStyle::DashDotLine: { const HPDF_UINT16 dash_ptn[] = { 4, 2, 1, 2 }; HPDF_Page_SetDash(page_, dash_ptn, 4, 0); break; } case PenStyle::DashDotDotLine: { const HPDF_UINT16 dash_ptn[] = { 4, 2, 1, 2, 1, 2 }; HPDF_Page_SetDash(page_, dash_ptn, 6, 0); break; } } } const WBrush& brush = painter()->brush(); if (brush.style() != BrushStyle::None) { const WColor& color = painter()->brush().color(); HPDF_Page_SetRGBFill(page_, color.red() / 255., color.green() / 255., color.blue() / 255.); HPDF_ExtGState_SetAlphaFill (gstate, color.alpha()/255.); } HPDF_Page_SetExtGState (page_, gstate); const WFont& font = painter()->font(); if (font == currentFont_ && !trueTypeFonts_->busy()) return; /* * First, try a true type font. */ std::string ttfFont; if (trueTypeFonts_->busy()) { /* * We have a resolved true type font. */ ttfFont = trueTypeFonts_->drawingFontPath(); } else { FontSupport::FontMatch match = trueTypeFonts_->matchFont(font); if (match.matched()) ttfFont = match.fileName(); } LOG_DEBUG("font: " << ttfFont); if (font == currentFont_ && !ttfFont.empty() && currentTtfFont_ == ttfFont) return; currentFont_ = font; const char *font_name = nullptr; font_ = nullptr; if (!ttfFont.empty()) { bool fontOk = false; std::map<std::string, const char *>::const_iterator i = ttfFonts_.find(ttfFont); if (i != ttfFonts_.end()) { font_name = i->second; fontOk = true; } else if (ttfFont.length() > 4) { std::string suffix = Utils::lowerCase(ttfFont.substr(ttfFont.length() - 4)); if (suffix == ".ttf") { font_name = HPDF_LoadTTFontFromFile (pdf_, ttfFont.c_str(), HPDF_TRUE); } else if (suffix == ".ttc") { /* Oops, pango didn't tell us which font to load ... */ font_name = HPDF_LoadTTFontFromFile2(pdf_, ttfFont.c_str(), 0, HPDF_TRUE); } if (!font_name) HPDF_ResetError (pdf_); else { ttfFonts_[ttfFont] = font_name; fontOk = true; } } if (!fontOk) LOG_ERROR("cannot read font: '" << ttfFont << "': " "expecting a true type font (.ttf, .ttc)"); } if (!font_ && font_name) { font_ = HPDF_GetFont (pdf_, font_name, "UTF-8"); if (!font_) HPDF_ResetError (pdf_); else { trueTypeFont_ = true; currentTtfFont_ = ttfFont; } } if (!font_) { trueTypeFont_ = false; currentTtfFont_.clear(); std::string name = Pdf::toBase14Font(font); font_ = HPDF_GetFont(pdf_, name.c_str(), nullptr); } fontSize_ = font.sizeLength(12).toPixels(); HPDF_Page_SetFontAndSize (page_, font_, fontSize_); } }
int main (int argc, char **argv) { HPDF_Doc pdf; HPDF_Page page; char fname[256]; HPDF_Font hfont; HPDF_ExtGState gstate; const HPDF_REAL PAGE_WIDTH = 600; const HPDF_REAL PAGE_HEIGHT = 900; 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; } hfont = HPDF_GetFont (pdf, "Helvetica-Bold", NULL); /* add a new page object. */ page = HPDF_AddPage (pdf); HPDF_Page_SetFontAndSize (page, hfont, 10); HPDF_Page_SetHeight (page, PAGE_HEIGHT); HPDF_Page_SetWidth (page, PAGE_WIDTH); /* normal */ HPDF_Page_GSave (page); draw_circles (page, "normal", 40.0f, PAGE_HEIGHT - 170); HPDF_Page_GRestore (page); /* transparency (0.8) */ HPDF_Page_GSave (page); gstate = HPDF_CreateExtGState (pdf); HPDF_ExtGState_SetAlphaFill (gstate, 0.8); HPDF_ExtGState_SetAlphaStroke (gstate, 0.8); HPDF_Page_SetExtGState (page, gstate); draw_circles (page, "alpha fill = 0.8", 230.0f, PAGE_HEIGHT - 170); HPDF_Page_GRestore (page); /* transparency (0.4) */ HPDF_Page_GSave (page); gstate = HPDF_CreateExtGState (pdf); HPDF_ExtGState_SetAlphaFill (gstate, 0.4); HPDF_Page_SetExtGState (page, gstate); draw_circles (page, "alpha fill = 0.4", 420.0f, PAGE_HEIGHT - 170); HPDF_Page_GRestore (page); /* blend-mode=HPDF_BM_MULTIPLY */ HPDF_Page_GSave (page); gstate = HPDF_CreateExtGState (pdf); HPDF_ExtGState_SetBlendMode (gstate, HPDF_BM_MULTIPLY); HPDF_Page_SetExtGState (page, gstate); draw_circles (page, "HPDF_BM_MULTIPLY", 40.0f, PAGE_HEIGHT - 340); HPDF_Page_GRestore (page); /* blend-mode=HPDF_BM_SCREEN */ HPDF_Page_GSave (page); gstate = HPDF_CreateExtGState (pdf); HPDF_ExtGState_SetBlendMode (gstate, HPDF_BM_SCREEN); HPDF_Page_SetExtGState (page, gstate); draw_circles (page, "HPDF_BM_SCREEN", 230.0f, PAGE_HEIGHT - 340); HPDF_Page_GRestore (page); /* blend-mode=HPDF_BM_OVERLAY */ HPDF_Page_GSave (page); gstate = HPDF_CreateExtGState (pdf); HPDF_ExtGState_SetBlendMode (gstate, HPDF_BM_OVERLAY); HPDF_Page_SetExtGState (page, gstate); draw_circles (page, "HPDF_BM_OVERLAY", 420.0f, PAGE_HEIGHT - 340); HPDF_Page_GRestore (page); /* blend-mode=HPDF_BM_DARKEN */ HPDF_Page_GSave (page); gstate = HPDF_CreateExtGState (pdf); HPDF_ExtGState_SetBlendMode (gstate, HPDF_BM_DARKEN); HPDF_Page_SetExtGState (page, gstate); draw_circles (page, "HPDF_BM_DARKEN", 40.0f, PAGE_HEIGHT - 510); HPDF_Page_GRestore (page); /* blend-mode=HPDF_BM_LIGHTEN */ HPDF_Page_GSave (page); gstate = HPDF_CreateExtGState (pdf); HPDF_ExtGState_SetBlendMode (gstate, HPDF_BM_LIGHTEN); HPDF_Page_SetExtGState (page, gstate); draw_circles (page, "HPDF_BM_LIGHTEN", 230.0f, PAGE_HEIGHT - 510); HPDF_Page_GRestore (page); /* blend-mode=HPDF_BM_COLOR_DODGE */ HPDF_Page_GSave (page); gstate = HPDF_CreateExtGState (pdf); HPDF_ExtGState_SetBlendMode (gstate, HPDF_BM_COLOR_DODGE); HPDF_Page_SetExtGState (page, gstate); draw_circles (page, "HPDF_BM_COLOR_DODGE", 420.0f, PAGE_HEIGHT - 510); HPDF_Page_GRestore (page); /* blend-mode=HPDF_BM_COLOR_BUM */ HPDF_Page_GSave (page); gstate = HPDF_CreateExtGState (pdf); HPDF_ExtGState_SetBlendMode (gstate, HPDF_BM_COLOR_BUM); HPDF_Page_SetExtGState (page, gstate); draw_circles (page, "HPDF_BM_COLOR_BUM", 40.0f, PAGE_HEIGHT - 680); HPDF_Page_GRestore (page); /* blend-mode=HPDF_BM_HARD_LIGHT */ HPDF_Page_GSave (page); gstate = HPDF_CreateExtGState (pdf); HPDF_ExtGState_SetBlendMode (gstate, HPDF_BM_HARD_LIGHT); HPDF_Page_SetExtGState (page, gstate); draw_circles (page, "HPDF_BM_HARD_LIGHT", 230.0f, PAGE_HEIGHT - 680); HPDF_Page_GRestore (page); /* blend-mode=HPDF_BM_SOFT_LIGHT */ HPDF_Page_GSave (page); gstate = HPDF_CreateExtGState (pdf); HPDF_ExtGState_SetBlendMode (gstate, HPDF_BM_SOFT_LIGHT); HPDF_Page_SetExtGState (page, gstate); draw_circles (page, "HPDF_BM_SOFT_LIGHT", 420.0f, PAGE_HEIGHT - 680); HPDF_Page_GRestore (page); /* blend-mode=HPDF_BM_DIFFERENCE */ HPDF_Page_GSave (page); gstate = HPDF_CreateExtGState (pdf); HPDF_ExtGState_SetBlendMode (gstate, HPDF_BM_DIFFERENCE); HPDF_Page_SetExtGState (page, gstate); draw_circles (page, "HPDF_BM_DIFFERENCE", 40.0f, PAGE_HEIGHT - 850); HPDF_Page_GRestore (page); /* blend-mode=HPDF_BM_EXCLUSHON */ HPDF_Page_GSave (page); gstate = HPDF_CreateExtGState (pdf); HPDF_ExtGState_SetBlendMode (gstate, HPDF_BM_EXCLUSHON); HPDF_Page_SetExtGState (page, gstate); draw_circles (page, "HPDF_BM_EXCLUSHON", 230.0f, PAGE_HEIGHT - 850); HPDF_Page_GRestore (page); /* save the document to a file */ HPDF_SaveToFile (pdf, fname); /* clean up */ HPDF_Free (pdf); return 0; }