FX_BOOL CFX_PSRenderer::DrawPath(const CFX_PathData* pPathData, const CFX_AffineMatrix* pObject2Device, const CFX_GraphStateData* pGraphState, FX_DWORD fill_color, FX_DWORD stroke_color, int fill_mode, int alpha_flag, void* pIccTransform ) { StartRendering(); int fill_alpha = FXGETFLAG_COLORTYPE(alpha_flag) ? FXGETFLAG_ALPHA_FILL(alpha_flag) : FXARGB_A(fill_color); int stroke_alpha = FXGETFLAG_COLORTYPE(alpha_flag) ? FXGETFLAG_ALPHA_STROKE(alpha_flag) : FXARGB_A(stroke_color); if (fill_alpha && fill_alpha < 255) { return FALSE; } if (stroke_alpha && stroke_alpha < 255) { return FALSE; } if (fill_alpha == 0 && stroke_alpha == 0) { return FALSE; } if (stroke_alpha) { SetGraphState(pGraphState); if (pObject2Device) { CFX_ByteTextBuf buf; buf << FX_BSTRC("mx Cm [") << pObject2Device->a << FX_BSTRC(" ") << pObject2Device->b << FX_BSTRC(" ") << pObject2Device->c << FX_BSTRC(" ") << pObject2Device->d << FX_BSTRC(" ") << pObject2Device->e << FX_BSTRC(" ") << pObject2Device->f << FX_BSTRC("]cm "); m_pOutput->OutputPS((FX_LPCSTR)buf.GetBuffer(), buf.GetSize()); } } OutputPath(pPathData, stroke_alpha ? NULL : pObject2Device); if (fill_mode && fill_alpha) { SetColor(fill_color, alpha_flag, pIccTransform); if ((fill_mode & 3) == FXFILL_WINDING) { if (stroke_alpha) { OUTPUT_PS("q f Q "); } else { OUTPUT_PS("f"); } } else if ((fill_mode & 3) == FXFILL_ALTERNATE) { if (stroke_alpha) { OUTPUT_PS("q F Q "); } else { OUTPUT_PS("F"); } } } if (stroke_alpha) { SetColor(stroke_color, alpha_flag, pIccTransform); if (pObject2Device) { OUTPUT_PS("s sm"); } else { OUTPUT_PS("s"); } } OUTPUT_PS("\n"); return TRUE; }
FX_BOOL CFX_PSRenderer::SetDIBits(const CFX_DIBSource* pSource, FX_DWORD color, int left, int top, int alpha_flag, void* pIccTransform) { StartRendering(); CFX_AffineMatrix matrix((FX_FLOAT)(pSource->GetWidth()), 0.0f, 0.0f, -(FX_FLOAT)(pSource->GetHeight()), (FX_FLOAT)(left), (FX_FLOAT)(top + pSource->GetHeight())); return DrawDIBits(pSource, color, &matrix, 0, alpha_flag, pIccTransform); }
FX_BOOL CFX_PSRenderer::StretchDIBits(const CFX_DIBSource* pSource, FX_DWORD color, int dest_left, int dest_top, int dest_width, int dest_height, FX_DWORD flags, int alpha_flag, void* pIccTransform) { StartRendering(); CFX_AffineMatrix matrix((FX_FLOAT)(dest_width), 0.0f, 0.0f, (FX_FLOAT)(-dest_height), (FX_FLOAT)(dest_left), (FX_FLOAT)(dest_top + dest_height)); return DrawDIBits(pSource, color, &matrix, flags, alpha_flag, pIccTransform); }
void SGDisplayDATATYPE::HandleRedraw(SGRedrawInfo *RedrawInfo, SGMiscInfo *MiscInfo) { // First, inform the system that we are about to start rendering this item StartRendering(RedrawInfo, MiscInfo); DocRect MyRect(FormatRect); // Get my redraw position from the cached FormatRect RenderRegion *Renderer = RedrawInfo->Renderer; INT32 OnePixel = (INT32) DevicePixels(MiscInfo, 1); INT32 TwoPixels = (INT32) DevicePixels(MiscInfo, 2); Renderer->SetLineWidth(0); Renderer->SetLineColour(RedrawInfo->Transparent); // First, render the icon at the left end of our rectangle DocRect IconRect(MyRect); IconRect.hi.x = IconRect.lo.x + IconRect.Height(); // Make it a square MyRect.lo.x = IconRect.hi.x + TwoPixels; // And exclude it from 'MyRect' // Redraw the icon GridLockRect(MiscInfo, &IconRect); // Ensure it maps exactly to specific pixels IconRect.Inflate(-OnePixel, -OnePixel); // Leave a bit of space around the edge Renderer->SetFillColour(DocColour(COLOUR_RED)); Renderer->DrawRect(&IconRect); GridLockRect(MiscInfo, &MyRect); // Ensure the new 'MyRect' is pixel-grid-aligned // Set up the colours for rendering our text, and fill the background if selected if (Flags.Selected) { // Fill the entire background with the 'selected' colour, so we don't // get gaps between bits of text or uneven rectangles in multiple selections Renderer->SetFillColour(RedrawInfo->SelBackground); Renderer->DrawRect(&MyRect); Renderer->SetFixedSystemTextColours(&RedrawInfo->SelForeground, &RedrawInfo->SelBackground); } else Renderer->SetFixedSystemTextColours(&RedrawInfo->Foreground, &RedrawInfo->Background); MyRect.lo.x += SG_GapBeforeText; // Leave a small gap before text begins // And render the text String_256 MyText; GetNameText(&MyText); Renderer->DrawFixedSystemText(&MyText, MyRect); // Finally, inform the system that we have completed rendering this item StopRendering(RedrawInfo, MiscInfo); }
void CFX_PSRenderer::RestoreState(FX_BOOL bKeepSaved) { StartRendering(); if (bKeepSaved) { OUTPUT_PS("Q\nq\n"); } else { OUTPUT_PS("Q\n"); } m_bColorSet = m_bGraphStateSet = FALSE; m_ClipBox = m_ClipBoxStack.GetAt(m_ClipBoxStack.GetSize() - 1); if (!bKeepSaved) { m_ClipBoxStack.RemoveAt(m_ClipBoxStack.GetSize() - 1); } }
void CFX_PSRenderer::SetClip_PathFill(const CFX_PathData* pPathData, const CFX_AffineMatrix* pObject2Device, int fill_mode ) { StartRendering(); OutputPath(pPathData, pObject2Device); CFX_FloatRect rect = pPathData->GetBoundingBox(); if (pObject2Device) { rect.Transform(pObject2Device); } m_ClipBox.Intersect(rect.GetOutterRect()); if ((fill_mode & 3) == FXFILL_WINDING) { OUTPUT_PS("W n\n"); } else { OUTPUT_PS("W* n\n"); } }
FX_BOOL CFX_PSRenderer::DrawText(int nChars, const FXTEXT_CHARPOS* pCharPos, CFX_Font* pFont, CFX_FontCache* pCache, const CFX_AffineMatrix* pObject2Device, FX_FLOAT font_size, FX_DWORD color, int alpha_flag, void* pIccTransform) { StartRendering(); int alpha = FXGETFLAG_COLORTYPE(alpha_flag) ? FXGETFLAG_ALPHA_FILL(alpha_flag) : FXARGB_A(color); if (alpha < 255) { return FALSE; } if ((pObject2Device->a == 0 && pObject2Device->b == 0) || (pObject2Device->c == 0 && pObject2Device->d == 0)) { return TRUE; } SetColor(color, alpha_flag, pIccTransform); CFX_ByteTextBuf buf; buf << FX_BSTRC("q[") << pObject2Device->a << FX_BSTRC(" ") << pObject2Device->b << FX_BSTRC(" ") << pObject2Device->c << FX_BSTRC(" ") << pObject2Device->d; buf << FX_BSTRC(" ") << pObject2Device->e << FX_BSTRC(" ") << pObject2Device->f << "]cm\n"; if (pCache == NULL) { pCache = CFX_GEModule::Get()->GetFontCache(); } CFX_FaceCache* pFaceCache = pCache->GetCachedFace(pFont); FX_FONTCACHE_DEFINE(pCache, pFont); int last_fontnum = -1; for (int i = 0; i < nChars; i ++) { int ps_fontnum, ps_glyphindex; FindPSFontGlyph(pFaceCache, pFont, pCharPos[i], ps_fontnum, ps_glyphindex); if (last_fontnum != ps_fontnum) { buf << FX_BSTRC("/X") << ps_fontnum << FX_BSTRC(" Ff ") << font_size << FX_BSTRC(" Fs Sf "); last_fontnum = ps_fontnum; } buf << pCharPos[i].m_OriginX << FX_BSTRC(" ") << pCharPos[i].m_OriginY << FX_BSTRC(" m"); CFX_ByteString hex; hex.Format("<%02X>", ps_glyphindex); buf << hex << FX_BSTRC("Tj\n"); } buf << FX_BSTRC("Q\n"); m_pOutput->OutputPS((FX_LPCSTR)buf.GetBuffer(), buf.GetSize()); return TRUE; }
void CFX_PSRenderer::SetClip_PathStroke(const CFX_PathData* pPathData, const CFX_AffineMatrix* pObject2Device, const CFX_GraphStateData* pGraphState ) { StartRendering(); SetGraphState(pGraphState); if (pObject2Device) { CFX_ByteTextBuf buf; buf << FX_BSTRC("mx Cm [") << pObject2Device->a << FX_BSTRC(" ") << pObject2Device->b << FX_BSTRC(" ") << pObject2Device->c << FX_BSTRC(" ") << pObject2Device->d << FX_BSTRC(" ") << pObject2Device->e << FX_BSTRC(" ") << pObject2Device->f << FX_BSTRC("]cm "); m_pOutput->OutputPS((FX_LPCSTR)buf.GetBuffer(), buf.GetSize()); } OutputPath(pPathData, NULL); CFX_FloatRect rect = pPathData->GetBoundingBox(pGraphState->m_LineWidth, pGraphState->m_MiterLimit); rect.Transform(pObject2Device); m_ClipBox.Intersect(rect.GetOutterRect()); if (pObject2Device) { OUTPUT_PS("strokepath W n sm\n"); } else { OUTPUT_PS("strokepath W n\n"); } }
void CFX_PSRenderer::SaveState() { StartRendering(); OUTPUT_PS("q\n"); m_ClipBoxStack.Add(m_ClipBox); }
FX_BOOL CFX_PSRenderer::DrawDIBits(const CFX_DIBSource* pSource, FX_DWORD color, const CFX_AffineMatrix* pMatrix, FX_DWORD flags, int alpha_flag, void* pIccTransform) { StartRendering(); if ((pMatrix->a == 0 && pMatrix->b == 0) || (pMatrix->c == 0 && pMatrix->d == 0)) { return TRUE; } if (pSource->HasAlpha()) { return FALSE; } int alpha = FXGETFLAG_COLORTYPE(alpha_flag) ? FXGETFLAG_ALPHA_FILL(color) : FXARGB_A(color); if (pSource->IsAlphaMask() && (alpha < 255 || pSource->GetBPP() != 1)) { return FALSE; } OUTPUT_PS("q\n"); CFX_ByteTextBuf buf; buf << FX_BSTRC("[") << pMatrix->a << FX_BSTRC(" ") << pMatrix->b << FX_BSTRC(" ") << pMatrix->c << FX_BSTRC(" ") << pMatrix->d << FX_BSTRC(" ") << pMatrix->e << FX_BSTRC(" ") << pMatrix->f << FX_BSTRC("]cm "); int width = pSource->GetWidth(); int height = pSource->GetHeight(); buf << width << FX_BSTRC(" ") << height; if (pSource->GetBPP() == 1 && pSource->GetPalette() == NULL) { int pitch = (width + 7) / 8; FX_DWORD src_size = height * pitch; FX_LPBYTE src_buf = FX_Alloc(FX_BYTE, src_size); if (!src_buf) { return FALSE; } for (int row = 0; row < height; row ++) { FX_LPCBYTE src_scan = pSource->GetScanline(row); FXSYS_memcpy32(src_buf + row * pitch, src_scan, pitch); } FX_LPBYTE output_buf; FX_DWORD output_size; FaxCompressData(src_buf, width, height, output_buf, output_size); if (pSource->IsAlphaMask()) { SetColor(color, alpha_flag, pIccTransform); m_bColorSet = FALSE; buf << FX_BSTRC(" true["); } else { buf << FX_BSTRC(" 1["); } buf << width << FX_BSTRC(" 0 0 -") << height << FX_BSTRC(" 0 ") << height << FX_BSTRC("]currentfile/ASCII85Decode filter "); if (output_buf != src_buf) buf << FX_BSTRC("<</K -1/EndOfBlock false/Columns ") << width << FX_BSTRC("/Rows ") << height << FX_BSTRC(">>/CCITTFaxDecode filter "); if (pSource->IsAlphaMask()) { buf << FX_BSTRC("iM\n"); } else { buf << FX_BSTRC("false 1 colorimage\n"); } m_pOutput->OutputPS((FX_LPCSTR)buf.GetBuffer(), buf.GetSize()); WritePSBinary(output_buf, output_size); FX_Free(output_buf); } else { CFX_DIBSource* pConverted = (CFX_DIBSource*)pSource; if (pIccTransform) { FXDIB_Format format = m_bCmykOutput ? FXDIB_Cmyk : FXDIB_Rgb; pConverted = pSource->CloneConvert(format, NULL, pIccTransform); } else { switch (pSource->GetFormat()) { case FXDIB_1bppRgb: case FXDIB_Rgb32: pConverted = pSource->CloneConvert(FXDIB_Rgb); break; case FXDIB_8bppRgb: if (pSource->GetPalette() != NULL) { pConverted = pSource->CloneConvert(FXDIB_Rgb); } break; case FXDIB_1bppCmyk: pConverted = pSource->CloneConvert(FXDIB_Cmyk); break; case FXDIB_8bppCmyk: if (pSource->GetPalette() != NULL) { pConverted = pSource->CloneConvert(FXDIB_Cmyk); } break; default: break; } } if (pConverted == NULL) { OUTPUT_PS("\nQ\n"); return FALSE; } int Bpp = pConverted->GetBPP() / 8; FX_LPBYTE output_buf = NULL; FX_STRSIZE output_size = 0; FX_LPCSTR filter = NULL; if (flags & FXRENDER_IMAGE_LOSSY) { CCodec_ModuleMgr* pEncoders = CFX_GEModule::Get()->GetCodecModule(); if (pEncoders && pEncoders->GetJpegModule()->Encode(pConverted, output_buf, output_size)) { filter = "/DCTDecode filter "; } } if (filter == NULL) { int src_pitch = width * Bpp; output_size = height * src_pitch; output_buf = FX_Alloc(FX_BYTE, output_size); if (!output_buf) { if (pConverted != pSource) { delete pConverted; pConverted = NULL; } return FALSE; } for (int row = 0; row < height; row ++) { FX_LPCBYTE src_scan = pConverted->GetScanline(row); FX_LPBYTE dest_scan = output_buf + row * src_pitch; if (Bpp == 3) { for (int col = 0; col < width; col ++) { *dest_scan++ = src_scan[2]; *dest_scan++ = src_scan[1]; *dest_scan++ = *src_scan; src_scan += 3; } } else { FXSYS_memcpy32(dest_scan, src_scan, src_pitch); } } FX_LPBYTE compressed_buf; FX_DWORD compressed_size; PSCompressData(m_PSLevel, output_buf, output_size, compressed_buf, compressed_size, filter); if (output_buf != compressed_buf) { FX_Free(output_buf); } output_buf = compressed_buf; output_size = compressed_size; } if (pConverted != pSource) { delete pConverted; pConverted = NULL; } buf << FX_BSTRC(" 8["); buf << width << FX_BSTRC(" 0 0 -") << height << FX_BSTRC(" 0 ") << height << FX_BSTRC("]"); buf << FX_BSTRC("currentfile/ASCII85Decode filter "); if (filter) { buf << filter; } buf << FX_BSTRC("false ") << Bpp; buf << FX_BSTRC(" colorimage\n"); m_pOutput->OutputPS((FX_LPCSTR)buf.GetBuffer(), buf.GetSize()); WritePSBinary(output_buf, output_size); FX_Free(output_buf); } OUTPUT_PS("\nQ\n"); return TRUE; }