void CFX_PSRenderer::SetColor(FX_DWORD color, int alpha_flag, void* pIccTransform) { if (!CFX_GEModule::Get()->GetCodecModule() || !CFX_GEModule::Get()->GetCodecModule()->GetIccModule()) { pIccTransform = NULL; } FX_BOOL bCMYK = FALSE; if (pIccTransform) { ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule(); color = FXGETFLAG_COLORTYPE(alpha_flag) ? FXCMYK_TODIB(color) : FXARGB_TODIB(color); FX_LPBYTE pColor = (FX_LPBYTE)&color; pIccModule->TranslateScanline(pIccTransform, pColor, pColor, 1); color = m_bCmykOutput ? FXCMYK_TODIB(color) : FXARGB_TODIB(color); bCMYK = m_bCmykOutput; } else { bCMYK = FXGETFLAG_COLORTYPE(alpha_flag); } if (bCMYK != m_bCmykOutput || !m_bColorSet || m_LastColor != color) { CFX_ByteTextBuf buf; if (bCMYK) { buf << FXSYS_GetCValue(color) / 255.0 << FX_BSTRC(" ") << FXSYS_GetMValue(color) / 255.0 << FX_BSTRC(" ") << FXSYS_GetYValue(color) / 255.0 << FX_BSTRC(" ") << FXSYS_GetKValue(color) / 255.0 << FX_BSTRC(" k\n"); } else { buf << FXARGB_R(color) / 255.0 << FX_BSTRC(" ") << FXARGB_G(color) / 255.0 << FX_BSTRC(" ") << FXARGB_B(color) / 255.0 << FX_BSTRC(" rg\n"); } if (bCMYK == m_bCmykOutput) { m_bColorSet = TRUE; m_LastColor = color; } m_pOutput->OutputPS((FX_LPCSTR)buf.GetBuffer(), buf.GetSize()); } }
void CFX_PSRenderer::SetGraphState(const CFX_GraphStateData* pGraphState) { CFX_ByteTextBuf buf; if (!m_bGraphStateSet || m_CurGraphState.m_LineCap != pGraphState->m_LineCap) { buf << pGraphState->m_LineCap << FX_BSTRC(" J\n"); } if (!m_bGraphStateSet || m_CurGraphState.m_DashCount != pGraphState->m_DashCount || FXSYS_memcmp32(m_CurGraphState.m_DashArray, pGraphState->m_DashArray, sizeof(FX_FLOAT)*m_CurGraphState.m_DashCount)) { buf << FX_BSTRC("["); for (int i = 0; i < pGraphState->m_DashCount; i ++) { buf << pGraphState->m_DashArray[i] << FX_BSTRC(" "); } buf << FX_BSTRC("]") << pGraphState->m_DashPhase << FX_BSTRC(" d\n"); } if (!m_bGraphStateSet || m_CurGraphState.m_LineJoin != pGraphState->m_LineJoin) { buf << pGraphState->m_LineJoin << FX_BSTRC(" j\n"); } if (!m_bGraphStateSet || m_CurGraphState.m_LineWidth != pGraphState->m_LineWidth) { buf << pGraphState->m_LineWidth << FX_BSTRC(" w\n"); } if (!m_bGraphStateSet || m_CurGraphState.m_MiterLimit != pGraphState->m_MiterLimit) { buf << pGraphState->m_MiterLimit << FX_BSTRC(" M\n"); } m_CurGraphState.Copy(*pGraphState); m_bGraphStateSet = TRUE; if (buf.GetSize()) { m_pOutput->OutputPS((FX_LPCSTR)buf.GetBuffer(), buf.GetSize()); } }
FX_BOOL CPDFSDK_InterForm::SubmitForm(const CFX_WideString& sDestination, FX_BOOL bUrlEncoded) { if (sDestination.IsEmpty()) return FALSE; if (!m_pDocument || !m_pInterForm) return FALSE; CPDFSDK_Environment* pEnv = m_pDocument->GetEnv(); CFX_WideString wsPDFFilePath = m_pDocument->GetPath(); CFDF_Document* pFDFDoc = m_pInterForm->ExportToFDF(wsPDFFilePath.AsStringC(), false); if (!pFDFDoc) return FALSE; CFX_ByteTextBuf FdfBuffer; FX_BOOL bRet = pFDFDoc->WriteBuf(FdfBuffer); delete pFDFDoc; if (!bRet) return FALSE; uint8_t* pBuffer = FdfBuffer.GetBuffer(); FX_STRSIZE nBufSize = FdfBuffer.GetLength(); if (bUrlEncoded && !FDFToURLEncodedData(pBuffer, nBufSize)) return FALSE; pEnv->JS_docSubmitForm(pBuffer, nBufSize, sDestination.c_str()); if (bUrlEncoded) FX_Free(pBuffer); return TRUE; }
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 Document::mailForm(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) { ASSERT(m_pDocument != NULL); if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE; int iLength = params.size(); FX_BOOL bUI = iLength > 0 ? params[0].ToBool() : TRUE; CFX_WideString cTo = iLength > 1 ? params[1].ToCFXWideString() : L""; CFX_WideString cCc = iLength > 2 ? params[2].ToCFXWideString() : L""; CFX_WideString cBcc = iLength > 3 ? params[3].ToCFXWideString() : L""; CFX_WideString cSubject = iLength > 4 ? params[4].ToCFXWideString() : L""; CFX_WideString cMsg = iLength > 5 ? params[5].ToCFXWideString() : L""; CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); ASSERT(pInterForm != NULL); CFX_ByteTextBuf textBuf; if (!pInterForm->ExportFormToFDFTextBuf(textBuf)) return FALSE; CJS_Context* pContext = (CJS_Context*)cc; ASSERT(pContext != NULL); CPDFDoc_Environment* pEnv = pContext->GetReaderApp(); ASSERT(pEnv != NULL); CJS_Runtime* pRuntime = pContext->GetJSRuntime(); ASSERT(pRuntime != NULL); pRuntime->BeginBlock(); pEnv->JS_docmailForm(textBuf.GetBuffer(), textBuf.GetLength(), bUI, cTo.c_str(), cSubject.c_str(), cCc.c_str(), cBcc.c_str(), cMsg.c_str()); pRuntime->EndBlock(); return TRUE; }
CFX_ByteString CPDF_StreamParser::ReadHexString() { if (!PositionIsInBounds()) return CFX_ByteString(); CFX_ByteTextBuf buf; bool bFirst = true; int code = 0; while (PositionIsInBounds()) { int ch = m_pBuf[m_Pos++]; if (ch == '>') break; if (!std::isxdigit(ch)) continue; int val = FXSYS_toHexDigit(ch); if (bFirst) { code = val * 16; } else { code += val; buf.AppendByte((uint8_t)code); } bFirst = !bFirst; } if (!bFirst) buf.AppendChar((char)code); if (buf.GetLength() > MAX_STRING_LENGTH) return CFX_ByteString(buf.GetBuffer(), MAX_STRING_LENGTH); return buf.GetByteString(); }
FX_BOOL CFDF_Document::WriteFile(IFX_FileWrite *pFile) const { CFX_ByteTextBuf buf; WriteBuf(buf); FX_BOOL bRet = pFile->WriteBlock(buf.GetBuffer(), buf.GetSize()); if (bRet) { pFile->Flush(); } return bRet; }
CFX_ByteString CPDF_StreamParser::ReadHexString() { if (m_Size <= m_Pos) { return CFX_ByteString(); } int ch = m_pBuf[m_Pos++]; CFX_ByteTextBuf buf; FX_BOOL bFirst = TRUE; int code = 0; while (1) { if (ch == '>') { break; } if (ch >= '0' && ch <= '9') { if (bFirst) { code = (ch - '0') * 16; } else { code += ch - '0'; buf.AppendChar((char)code); } bFirst = !bFirst; } else if (ch >= 'A' && ch <= 'F') { if (bFirst) { code = (ch - 'A' + 10) * 16; } else { code += ch - 'A' + 10; buf.AppendChar((char)code); } bFirst = !bFirst; } else if (ch >= 'a' && ch <= 'f') { if (bFirst) { code = (ch - 'a' + 10) * 16; } else { code += ch - 'a' + 10; buf.AppendChar((char)code); } bFirst = !bFirst; } if (m_Size <= m_Pos) { break; } ch = m_pBuf[m_Pos++]; } if (!bFirst) { buf.AppendChar((char)code); } if (buf.GetLength() > MAX_STRING_LENGTH) { return CFX_ByteString(buf.GetBuffer(), MAX_STRING_LENGTH); } return buf.GetByteString(); }
void CFX_PSRenderer::OutputPath(const CFX_PathData* pPathData, const CFX_AffineMatrix* pObject2Device) { int nPoints = pPathData->GetPointCount(); CFX_ByteTextBuf buf; buf.EstimateSize(nPoints * 10); for (int i = 0; i < nPoints; i ++) { FX_BYTE flag = pPathData->GetFlag(i); FX_FLOAT x = pPathData->GetPointX(i); FX_FLOAT y = pPathData->GetPointY(i); if (pObject2Device) { pObject2Device->Transform(x, y); } buf << x << FX_BSTRC(" ") << y; switch (flag & FXPT_TYPE) { case FXPT_MOVETO: buf << FX_BSTRC(" m "); break; case FXPT_LINETO: if (flag & FXPT_CLOSEFIGURE) { buf << FX_BSTRC(" l h "); } else { buf << FX_BSTRC(" l "); } break; case FXPT_BEZIERTO: { FX_FLOAT x1 = pPathData->GetPointX(i + 1); FX_FLOAT x2 = pPathData->GetPointX(i + 2); FX_FLOAT y1 = pPathData->GetPointY(i + 1); FX_FLOAT y2 = pPathData->GetPointY(i + 2); if (pObject2Device) { pObject2Device->Transform(x1, y1); pObject2Device->Transform(x2, y2); } buf << FX_BSTRC(" ") << x1 << FX_BSTRC(" ") << y1 << FX_BSTRC(" ") << x2 << FX_BSTRC(" ") << y2; if (flag & FXPT_CLOSEFIGURE) { buf << FX_BSTRC(" c h\n"); } else { buf << FX_BSTRC(" c\n"); } i += 2; break; } } } m_pOutput->OutputPS((FX_LPCSTR)buf.GetBuffer(), buf.GetSize()); }
FX_BOOL CPDFSDK_InterForm::SubmitFields( const CFX_WideString& csDestination, const std::vector<CPDF_FormField*>& fields, bool bIncludeOrExclude, bool bUrlEncoded) { CPDFSDK_Environment* pEnv = m_pDocument->GetEnv(); CFX_ByteTextBuf textBuf; ExportFieldsToFDFTextBuf(fields, bIncludeOrExclude, textBuf); uint8_t* pBuffer = textBuf.GetBuffer(); FX_STRSIZE nBufSize = textBuf.GetLength(); if (bUrlEncoded && !FDFToURLEncodedData(pBuffer, nBufSize)) return FALSE; pEnv->JS_docSubmitForm(pBuffer, nBufSize, csDestination.c_str()); return TRUE; }
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 CPDF_PageContentGenerator::GenerateContent() { CFX_ByteTextBuf buf; CPDF_Dictionary* pPageDict = m_pPage->m_pFormDict; for (int i = 0; i < m_pageObjects.GetSize(); ++i) { CPDF_PageObject* pPageObj = m_pageObjects[i]; if (!pPageObj || !pPageObj->IsImage()) { continue; } ProcessImage(buf, pPageObj->AsImage()); } CPDF_Object* pContent = pPageDict ? pPageDict->GetDirectObjectFor("Contents") : nullptr; if (pContent) pPageDict->RemoveFor("Contents"); CPDF_Stream* pStream = new CPDF_Stream; pStream->SetData(buf.GetBuffer(), buf.GetLength()); pPageDict->SetReferenceFor("Contents", m_pDocument, m_pDocument->AddIndirectObject(pStream)); }
void CPDF_PageContentGenerate::GenerateContent() { CFX_ByteTextBuf buf; CPDF_Dictionary* pPageDict = m_pPage->m_pFormDict; for (int i = 0; i < m_pageObjects.GetSize(); ++i) { CPDF_PageObject* pPageObj = (CPDF_PageObject*)m_pageObjects[i]; if (!pPageObj || pPageObj->m_Type != PDFPAGE_IMAGE) { continue; } ProcessImage(buf, (CPDF_ImageObject*)pPageObj); } CPDF_Object* pContent = pPageDict ? pPageDict->GetElementValue("Contents") : NULL; if (pContent != NULL) { pPageDict->RemoveAt("Contents"); } CPDF_Stream* pStream = new CPDF_Stream(NULL, 0, NULL); pStream->SetData(buf.GetBuffer(), buf.GetLength(), FALSE, FALSE); m_pDocument->AddIndirectObject(pStream); pPageDict->SetAtReference("Contents", m_pDocument, pStream->GetObjNum()); }
FX_BOOL CPDFSDK_InterForm::FDFToURLEncodedData(uint8_t*& pBuf, FX_STRSIZE& nBufSize) { CFDF_Document* pFDF = CFDF_Document::ParseMemory(pBuf, nBufSize); if (!pFDF) return TRUE; CPDF_Dictionary* pMainDict = pFDF->GetRoot()->GetDictFor("FDF"); if (!pMainDict) return FALSE; CPDF_Array* pFields = pMainDict->GetArrayFor("Fields"); if (!pFields) return FALSE; CFX_ByteTextBuf fdfEncodedData; for (uint32_t i = 0; i < pFields->GetCount(); i++) { CPDF_Dictionary* pField = pFields->GetDictAt(i); if (!pField) continue; CFX_WideString name; name = pField->GetUnicodeTextFor("T"); CFX_ByteString name_b = CFX_ByteString::FromUnicode(name); CFX_ByteString csBValue = pField->GetStringFor("V"); CFX_WideString csWValue = PDF_DecodeText(csBValue); CFX_ByteString csValue_b = CFX_ByteString::FromUnicode(csWValue); fdfEncodedData << name_b.GetBuffer(name_b.GetLength()); name_b.ReleaseBuffer(); fdfEncodedData << "="; fdfEncodedData << csValue_b.GetBuffer(csValue_b.GetLength()); csValue_b.ReleaseBuffer(); if (i != pFields->GetCount() - 1) fdfEncodedData << "&"; } nBufSize = fdfEncodedData.GetLength(); pBuf = FX_Alloc(uint8_t, nBufSize); FXSYS_memcpy(pBuf, fdfEncodedData.GetBuffer(), nBufSize); 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 Revision6_Hash(const uint8_t* password, uint32_t size, const uint8_t* salt, const uint8_t* vector, uint8_t* hash) { int iBlockSize = 32; uint8_t sha[128]; CRYPT_SHA256Start(sha); CRYPT_SHA256Update(sha, password, size); CRYPT_SHA256Update(sha, salt, 8); if (vector) { CRYPT_SHA256Update(sha, vector, 48); } uint8_t digest[32]; CRYPT_SHA256Finish(sha, digest); CFX_ByteTextBuf buf; uint8_t* input = digest; uint8_t* key = input; uint8_t* iv = input + 16; uint8_t* E = buf.GetBuffer(); int iBufLen = buf.GetLength(); CFX_ByteTextBuf interDigest; int i = 0; uint8_t* aes = FX_Alloc(uint8_t, 2048); while (i < 64 || i < E[iBufLen - 1] + 32) { int iRoundSize = size + iBlockSize; if (vector) { iRoundSize += 48; } iBufLen = iRoundSize * 64; buf.EstimateSize(iBufLen); E = buf.GetBuffer(); CFX_ByteTextBuf content; for (int j = 0; j < 64; ++j) { content.AppendBlock(password, size); content.AppendBlock(input, iBlockSize); if (vector) { content.AppendBlock(vector, 48); } } CRYPT_AESSetKey(aes, 16, key, 16, TRUE); CRYPT_AESSetIV(aes, iv); CRYPT_AESEncrypt(aes, E, content.GetBuffer(), iBufLen); int iHash = 0; switch (BigOrder64BitsMod3(E)) { case 0: iHash = 0; iBlockSize = 32; break; case 1: iHash = 1; iBlockSize = 48; break; default: iHash = 2; iBlockSize = 64; break; } interDigest.EstimateSize(iBlockSize); input = interDigest.GetBuffer(); if (iHash == 0) { CRYPT_SHA256Generate(E, iBufLen, input); } else if (iHash == 1) { CRYPT_SHA384Generate(E, iBufLen, input); } else if (iHash == 2) { CRYPT_SHA512Generate(E, iBufLen, input); } key = input; iv = input + 16; ++i; } FX_Free(aes); if (hash) { FXSYS_memcpy(hash, input, 32); } }
DLLEXPORT FPDF_BOOL STDCALL FPDFPage_TransFormWithClip(FPDF_PAGE page, FS_MATRIX* matrix, FS_RECTF* clipRect) { CPDF_Page* pPage = CPDFPageFromFPDFPage(page); if (!pPage) return FALSE; CFX_ByteTextBuf textBuf; textBuf << "q "; CFX_FloatRect rect(clipRect->left, clipRect->bottom, clipRect->right, clipRect->top); rect.Normalize(); CFX_ByteString bsClipping; bsClipping.Format("%f %f %f %f re W* n ", rect.left, rect.bottom, rect.Width(), rect.Height()); textBuf << bsClipping; CFX_ByteString bsMatix; bsMatix.Format("%f %f %f %f %f %f cm ", matrix->a, matrix->b, matrix->c, matrix->d, matrix->e, matrix->f); textBuf << bsMatix; CPDF_Dictionary* pPageDic = pPage->m_pFormDict; CPDF_Object* pContentObj = pPageDic ? pPageDic->GetElement("Contents") : nullptr; if (!pContentObj) pContentObj = pPageDic ? pPageDic->GetArrayBy("Contents") : nullptr; if (!pContentObj) return FALSE; CPDF_Dictionary* pDic = new CPDF_Dictionary; CPDF_Stream* pStream = new CPDF_Stream(nullptr, 0, pDic); pStream->SetData(textBuf.GetBuffer(), textBuf.GetSize(), FALSE, FALSE); CPDF_Document* pDoc = pPage->m_pDocument; if (!pDoc) return FALSE; pDoc->AddIndirectObject(pStream); pDic = new CPDF_Dictionary; CPDF_Stream* pEndStream = new CPDF_Stream(nullptr, 0, pDic); pEndStream->SetData((const uint8_t*)" Q", 2, FALSE, FALSE); pDoc->AddIndirectObject(pEndStream); CPDF_Array* pContentArray = nullptr; if (CPDF_Array* pArray = ToArray(pContentObj)) { pContentArray = pArray; CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum()); pContentArray->InsertAt(0, pRef); pContentArray->AddReference(pDoc, pEndStream); } else if (CPDF_Reference* pReference = ToReference(pContentObj)) { CPDF_Object* pDirectObj = pReference->GetDirect(); if (pDirectObj) { if (CPDF_Array* pArray = pDirectObj->AsArray()) { pContentArray = pArray; CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum()); pContentArray->InsertAt(0, pRef); pContentArray->AddReference(pDoc, pEndStream); } else if (pDirectObj->IsStream()) { pContentArray = new CPDF_Array(); pContentArray->AddReference(pDoc, pStream->GetObjNum()); pContentArray->AddReference(pDoc, pDirectObj->GetObjNum()); pContentArray->AddReference(pDoc, pEndStream); pPageDic->SetAtReference("Contents", pDoc, pDoc->AddIndirectObject(pContentArray)); } } } // Need to transform the patterns as well. CPDF_Dictionary* pRes = pPageDic->GetDictBy("Resources"); if (pRes) { CPDF_Dictionary* pPattenDict = pRes->GetDictBy("Pattern"); if (pPattenDict) { for (const auto& it : *pPattenDict) { CPDF_Object* pObj = it.second; if (pObj->IsReference()) pObj = pObj->GetDirect(); CPDF_Dictionary* pDict = nullptr; if (pObj->IsDictionary()) pDict = pObj->AsDictionary(); else if (CPDF_Stream* pStream = pObj->AsStream()) pDict = pStream->GetDict(); else continue; CFX_Matrix m = pDict->GetMatrixBy("Matrix"); CFX_Matrix t = *(CFX_Matrix*)matrix; m.Concat(t); pDict->SetAtMatrix("Matrix", m); } } } return TRUE; }
DLLEXPORT void STDCALL FPDFPage_InsertClipPath(FPDF_PAGE page, FPDF_CLIPPATH clipPath) { CPDF_Page* pPage = CPDFPageFromFPDFPage(page); if (!pPage) return; CPDF_Dictionary* pPageDic = pPage->m_pFormDict; CPDF_Object* pContentObj = pPageDic ? pPageDic->GetElement("Contents") : nullptr; if (!pContentObj) pContentObj = pPageDic ? pPageDic->GetArrayBy("Contents") : nullptr; if (!pContentObj) return; CFX_ByteTextBuf strClip; CPDF_ClipPath* pClipPath = (CPDF_ClipPath*)clipPath; FX_DWORD i; for (i = 0; i < pClipPath->GetPathCount(); i++) { CPDF_Path path = pClipPath->GetPath(i); int iClipType = pClipPath->GetClipType(i); if (path.GetPointCount() == 0) { // Empty clipping (totally clipped out) strClip << "0 0 m W n "; } else { OutputPath(strClip, path); if (iClipType == FXFILL_WINDING) strClip << "W n\n"; else strClip << "W* n\n"; } } CPDF_Dictionary* pDic = new CPDF_Dictionary; CPDF_Stream* pStream = new CPDF_Stream(nullptr, 0, pDic); pStream->SetData(strClip.GetBuffer(), strClip.GetSize(), FALSE, FALSE); CPDF_Document* pDoc = pPage->m_pDocument; if (!pDoc) return; pDoc->AddIndirectObject(pStream); CPDF_Array* pContentArray = nullptr; if (CPDF_Array* pArray = ToArray(pContentObj)) { pContentArray = pArray; CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum()); pContentArray->InsertAt(0, pRef); } else if (CPDF_Reference* pReference = ToReference(pContentObj)) { CPDF_Object* pDirectObj = pReference->GetDirect(); if (pDirectObj) { if (CPDF_Array* pArray = pDirectObj->AsArray()) { pContentArray = pArray; CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum()); pContentArray->InsertAt(0, pRef); } else if (pDirectObj->IsStream()) { pContentArray = new CPDF_Array(); pContentArray->AddReference(pDoc, pStream->GetObjNum()); pContentArray->AddReference(pDoc, pDirectObj->GetObjNum()); pPageDic->SetAtReference("Contents", pDoc, pDoc->AddIndirectObject(pContentArray)); } } } }
CFX_ByteString CPDF_StreamParser::ReadString() { if (m_Size <= m_Pos) { return CFX_ByteString(); } int ch = m_pBuf[m_Pos++]; CFX_ByteTextBuf buf; int parlevel = 0; int status = 0, iEscCode = 0; while (1) { switch (status) { case 0: if (ch == ')') { if (parlevel == 0) { if (buf.GetLength() > MAX_STRING_LENGTH) { return CFX_ByteString(buf.GetBuffer(), MAX_STRING_LENGTH); } return buf.GetByteString(); } parlevel --; buf.AppendChar(')'); } else if (ch == '(') { parlevel ++; buf.AppendChar('('); } else if (ch == '\\') { status = 1; } else { buf.AppendChar((char)ch); } break; case 1: if (ch >= '0' && ch <= '7') { iEscCode = ch - '0'; status = 2; break; } if (ch == 'n') { buf.AppendChar('\n'); } else if (ch == 'r') { buf.AppendChar('\r'); } else if (ch == 't') { buf.AppendChar('\t'); } else if (ch == 'b') { buf.AppendChar('\b'); } else if (ch == 'f') { buf.AppendChar('\f'); } else if (ch == '\r') { status = 4; break; } else if (ch == '\n') { } else { buf.AppendChar(ch); } status = 0; break; case 2: if (ch >= '0' && ch <= '7') { iEscCode = iEscCode * 8 + ch - '0'; status = 3; } else { buf.AppendChar(iEscCode); status = 0; continue; } break; case 3: if (ch >= '0' && ch <= '7') { iEscCode = iEscCode * 8 + ch - '0'; buf.AppendChar(iEscCode); status = 0; } else { buf.AppendChar(iEscCode); status = 0; continue; } break; case 4: status = 0; if (ch != '\n') { continue; } break; } if (m_Size <= m_Pos) { break; } ch = m_pBuf[m_Pos++]; } if (m_Size > m_Pos) { ch = m_pBuf[m_Pos++]; } if (buf.GetLength() > MAX_STRING_LENGTH) { return CFX_ByteString(buf.GetBuffer(), MAX_STRING_LENGTH); } return buf.GetByteString(); }
DLLEXPORT FPDF_BOOL STDCALL FPDFPage_TransFormWithClip(FPDF_PAGE page, FS_MATRIX* matrix, FS_RECTF* clipRect) { if(!page) return FALSE; CFX_ByteTextBuf textBuf; textBuf<<"q "; CFX_FloatRect rect(clipRect->left, clipRect->bottom, clipRect->right, clipRect->top); rect.Normalize(); CFX_ByteString bsClipping; bsClipping.Format("%f %f %f %f re W* n ", rect.left, rect.bottom, rect.Width(), rect.Height()); textBuf<<bsClipping; CFX_ByteString bsMatix; bsMatix.Format("%f %f %f %f %f %f cm ", matrix->a, matrix->b,matrix->c,matrix->d,matrix->e,matrix->f); textBuf<<bsMatix; CPDF_Page* pPage = (CPDF_Page*)page; CPDF_Dictionary* pPageDic = pPage->m_pFormDict; CPDF_Object* pContentObj = pPageDic->GetElement("Contents"); if(!pContentObj) pContentObj = pPageDic->GetArray("Contents"); if(!pContentObj) return FALSE; CPDF_Dictionary* pDic = FX_NEW CPDF_Dictionary; CPDF_Stream* pStream = FX_NEW CPDF_Stream(NULL,0, pDic); pStream->SetData(textBuf.GetBuffer(), textBuf.GetSize(), FALSE, FALSE); CPDF_Document* pDoc = pPage->m_pDocument; if(!pDoc) return FALSE; pDoc->AddIndirectObject(pStream); pDic = FX_NEW CPDF_Dictionary; CPDF_Stream* pEndStream = FX_NEW CPDF_Stream(NULL,0, pDic); pEndStream->SetData((FX_LPCBYTE)" Q", 2, FALSE, FALSE); pDoc->AddIndirectObject(pEndStream); CPDF_Array* pContentArray = NULL; if (pContentObj && pContentObj->GetType() == PDFOBJ_ARRAY) { pContentArray = (CPDF_Array*)pContentObj; CPDF_Reference* pRef = FX_NEW CPDF_Reference(pDoc, pStream->GetObjNum()); pContentArray->InsertAt(0, pRef); pContentArray->AddReference(pDoc,pEndStream); } else if(pContentObj && pContentObj->GetType() == PDFOBJ_REFERENCE) { CPDF_Reference* pReference = (CPDF_Reference*)pContentObj; CPDF_Object* pDirectObj = pReference->GetDirect(); if(pDirectObj != NULL) { if(pDirectObj->GetType() == PDFOBJ_ARRAY) { pContentArray = (CPDF_Array*)pDirectObj; CPDF_Reference* pRef = FX_NEW CPDF_Reference(pDoc, pStream->GetObjNum()); pContentArray->InsertAt(0, pRef); pContentArray->AddReference(pDoc,pEndStream); } else if(pDirectObj->GetType() == PDFOBJ_STREAM) { pContentArray = FX_NEW CPDF_Array(); pContentArray->AddReference(pDoc,pStream->GetObjNum()); pContentArray->AddReference(pDoc,pDirectObj->GetObjNum()); pContentArray->AddReference(pDoc, pEndStream); pPageDic->SetAtReference("Contents", pDoc, pDoc->AddIndirectObject(pContentArray)); } } } //Need to transform the patterns as well. CPDF_Dictionary* pRes = pPageDic->GetDict(FX_BSTRC("Resources")); if(pRes) { CPDF_Dictionary* pPattenDict = pRes->GetDict(FX_BSTRC("Pattern")); if(pPattenDict) { FX_POSITION pos = pPattenDict->GetStartPos(); while(pos) { CPDF_Dictionary* pDict = NULL; CFX_ByteString key; CPDF_Object* pObj = pPattenDict->GetNextElement(pos, key); if(pObj->GetType() == PDFOBJ_REFERENCE) pObj = pObj->GetDirect(); if(pObj->GetType() == PDFOBJ_DICTIONARY) { pDict = (CPDF_Dictionary*)pObj; } else if(pObj->GetType() == PDFOBJ_STREAM) { pDict = ((CPDF_Stream*)pObj)->GetDict(); } else continue; CFX_AffineMatrix m = pDict->GetMatrix(FX_BSTRC("Matrix")); CFX_AffineMatrix t = *(CFX_AffineMatrix*)matrix; m.Concat(t); pDict->SetAtMatrix(FX_BSTRC("Matrix"), m); } } } return TRUE; }
DLLEXPORT void STDCALL FPDFPage_InsertClipPath(FPDF_PAGE page,FPDF_CLIPPATH clipPath) { if(!page) return; CPDF_Page* pPage = (CPDF_Page*)page; CPDF_Dictionary* pPageDic = pPage->m_pFormDict; CPDF_Object* pContentObj = pPageDic->GetElement("Contents"); if(!pContentObj) pContentObj = pPageDic->GetArray("Contents"); if(!pContentObj) return; CFX_ByteTextBuf strClip; CPDF_ClipPath* pClipPath = (CPDF_ClipPath*)clipPath; FX_DWORD i; for (i = 0; i < pClipPath->GetPathCount(); i ++) { CPDF_Path path = pClipPath->GetPath(i); int iClipType = pClipPath->GetClipType(i); if (path.GetPointCount() == 0) { // Empty clipping (totally clipped out) strClip << "0 0 m W n "; } else { OutputPath(strClip, path); if (iClipType == FXFILL_WINDING) strClip << "W n\n"; else strClip << "W* n\n"; } } CPDF_Dictionary* pDic = FX_NEW CPDF_Dictionary; CPDF_Stream* pStream = FX_NEW CPDF_Stream(NULL,0, pDic); pStream->SetData(strClip.GetBuffer(), strClip.GetSize(), FALSE, FALSE); CPDF_Document* pDoc = pPage->m_pDocument; if(!pDoc) return; pDoc->AddIndirectObject(pStream); CPDF_Array* pContentArray = NULL; if (pContentObj && pContentObj->GetType() == PDFOBJ_ARRAY) { pContentArray = (CPDF_Array*)pContentObj; CPDF_Reference* pRef = FX_NEW CPDF_Reference(pDoc, pStream->GetObjNum()); pContentArray->InsertAt(0, pRef); } else if(pContentObj && pContentObj->GetType() == PDFOBJ_REFERENCE) { CPDF_Reference* pReference = (CPDF_Reference*)pContentObj; CPDF_Object* pDirectObj = pReference->GetDirect(); if(pDirectObj != NULL) { if(pDirectObj->GetType() == PDFOBJ_ARRAY) { pContentArray = (CPDF_Array*)pDirectObj; CPDF_Reference* pRef = FX_NEW CPDF_Reference(pDoc, pStream->GetObjNum()); pContentArray->InsertAt(0, pRef); } else if(pDirectObj->GetType() == PDFOBJ_STREAM) { pContentArray = FX_NEW CPDF_Array(); pContentArray->AddReference(pDoc,pStream->GetObjNum()); pContentArray->AddReference(pDoc,pDirectObj->GetObjNum()); pPageDic->SetAtReference("Contents", pDoc, pDoc->AddIndirectObject(pContentArray)); } } } }
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; }
DLLEXPORT void STDCALL FPDFPage_InsertClipPath(FPDF_PAGE page, FPDF_CLIPPATH clipPath) { CPDF_Page* pPage = CPDFPageFromFPDFPage(page); if (!pPage) return; CPDF_Dictionary* pPageDic = pPage->m_pFormDict; CPDF_Object* pContentObj = pPageDic ? pPageDic->GetObjectFor("Contents") : nullptr; if (!pContentObj) pContentObj = pPageDic ? pPageDic->GetArrayFor("Contents") : nullptr; if (!pContentObj) return; CFX_ByteTextBuf strClip; CPDF_ClipPath* pClipPath = (CPDF_ClipPath*)clipPath; uint32_t i; for (i = 0; i < pClipPath->GetPathCount(); i++) { CPDF_Path path = pClipPath->GetPath(i); int iClipType = pClipPath->GetClipType(i); if (path.GetPoints().empty()) { // Empty clipping (totally clipped out) strClip << "0 0 m W n "; } else { OutputPath(strClip, path); if (iClipType == FXFILL_WINDING) strClip << "W n\n"; else strClip << "W* n\n"; } } CPDF_Document* pDoc = pPage->m_pDocument; if (!pDoc) return; CPDF_Stream* pStream = pDoc->NewIndirect<CPDF_Stream>( nullptr, 0, pdfium::MakeUnique<CPDF_Dictionary>(pDoc->GetByteStringPool())); pStream->SetData(strClip.GetBuffer(), strClip.GetSize()); CPDF_Array* pArray = ToArray(pContentObj); if (pArray) { pArray->InsertNewAt<CPDF_Reference>(0, pDoc, pStream->GetObjNum()); return; } CPDF_Reference* pReference = ToReference(pContentObj); if (!pReference) return; CPDF_Object* pDirectObj = pReference->GetDirect(); if (!pDirectObj) return; CPDF_Array* pObjArray = pDirectObj->AsArray(); if (pObjArray) { pObjArray->InsertNewAt<CPDF_Reference>(0, pDoc, pStream->GetObjNum()); return; } if (pDirectObj->IsStream()) { CPDF_Array* pContentArray = pDoc->NewIndirect<CPDF_Array>(); pContentArray->AddNew<CPDF_Reference>(pDoc, pStream->GetObjNum()); pContentArray->AddNew<CPDF_Reference>(pDoc, pDirectObj->GetObjNum()); pPageDic->SetNewFor<CPDF_Reference>("Contents", pDoc, pContentArray->GetObjNum()); } }
void CFX_PSRenderer::FindPSFontGlyph(CFX_FaceCache* pFaceCache, CFX_Font* pFont, const FXTEXT_CHARPOS& charpos, int& ps_fontnum, int &ps_glyphindex) { for (int i = 0; i < (int)m_PSFontList.GetSize(); i ++) { CPSFont* pPSFont = m_PSFontList[i]; for (int j = 0; j < pPSFont->m_nGlyphs; j ++) if (pPSFont->m_Glyphs[j].m_pFont == pFont && pPSFont->m_Glyphs[j].m_GlyphIndex == charpos.m_GlyphIndex) { if ((!pPSFont->m_Glyphs[j].m_bGlyphAdjust && !charpos.m_bGlyphAdjust) || (pPSFont->m_Glyphs[j].m_bGlyphAdjust && charpos.m_bGlyphAdjust && (FXSYS_fabs(pPSFont->m_Glyphs[j].m_AdjustMatrix[0] - charpos.m_AdjustMatrix[0]) < 0.01 && FXSYS_fabs(pPSFont->m_Glyphs[j].m_AdjustMatrix[1] - charpos.m_AdjustMatrix[1]) < 0.01 && FXSYS_fabs(pPSFont->m_Glyphs[j].m_AdjustMatrix[2] - charpos.m_AdjustMatrix[2]) < 0.01 && FXSYS_fabs(pPSFont->m_Glyphs[j].m_AdjustMatrix[3] - charpos.m_AdjustMatrix[3]) < 0.01))) { ps_fontnum = i; ps_glyphindex = j; return; } } } if (m_PSFontList.GetSize() == 0 || m_PSFontList[m_PSFontList.GetSize() - 1]->m_nGlyphs == 256) { CPSFont* pPSFont = new CPSFont; pPSFont->m_nGlyphs = 0; m_PSFontList.Add(pPSFont); CFX_ByteTextBuf buf; buf << FX_BSTRC("8 dict begin/FontType 3 def/FontMatrix[1 0 0 1 0 0]def\n" "/FontBBox[0 0 0 0]def/Encoding 256 array def 0 1 255{Encoding exch/.notdef put}for\n" "/CharProcs 1 dict def CharProcs begin/.notdef {} def end\n" "/BuildGlyph{1 0 -10 -10 10 10 setcachedevice exch/CharProcs get exch 2 copy known not{pop/.notdef}if get exec}bind def\n" "/BuildChar{1 index/Encoding get exch get 1 index/BuildGlyph get exec}bind def\n" "currentdict end\n"); buf << FX_BSTRC("/X") << m_PSFontList.GetSize() - 1 << FX_BSTRC(" exch definefont pop\n"); m_pOutput->OutputPS((FX_LPCSTR)buf.GetBuffer(), buf.GetSize()); buf.Clear(); } ps_fontnum = m_PSFontList.GetSize() - 1; CPSFont* pPSFont = m_PSFontList[ps_fontnum]; ps_glyphindex = pPSFont->m_nGlyphs; pPSFont->m_Glyphs[ps_glyphindex].m_GlyphIndex = charpos.m_GlyphIndex; pPSFont->m_Glyphs[ps_glyphindex].m_pFont = pFont; pPSFont->m_Glyphs[ps_glyphindex].m_bGlyphAdjust = charpos.m_bGlyphAdjust; if (charpos.m_bGlyphAdjust) { pPSFont->m_Glyphs[ps_glyphindex].m_AdjustMatrix[0] = charpos.m_AdjustMatrix[0]; pPSFont->m_Glyphs[ps_glyphindex].m_AdjustMatrix[1] = charpos.m_AdjustMatrix[1]; pPSFont->m_Glyphs[ps_glyphindex].m_AdjustMatrix[2] = charpos.m_AdjustMatrix[2]; pPSFont->m_Glyphs[ps_glyphindex].m_AdjustMatrix[3] = charpos.m_AdjustMatrix[3]; } pPSFont->m_nGlyphs ++; CFX_AffineMatrix matrix; if (charpos.m_bGlyphAdjust) matrix.Set(charpos.m_AdjustMatrix[0], charpos.m_AdjustMatrix[1], charpos.m_AdjustMatrix[2], charpos.m_AdjustMatrix[3], 0, 0); matrix.Concat(1.0f, 0, 0, 1.0f, 0, 0); const CFX_PathData* pPathData = pFaceCache->LoadGlyphPath(pFont, charpos.m_GlyphIndex, charpos.m_FontCharWidth); if (pPathData == NULL) { return; } CFX_PathData TransformedPath(*pPathData); if (charpos.m_bGlyphAdjust) { TransformedPath.Transform(&matrix); } CFX_ByteTextBuf buf; buf << FX_BSTRC("/X") << ps_fontnum << FX_BSTRC(" Ff/CharProcs get begin/") << ps_glyphindex << FX_BSTRC("{"); buf << FX_BSTRC("n "); for (int p = 0; p < TransformedPath.GetPointCount(); p ++) { FX_FLOAT x = TransformedPath.GetPointX(p), y = TransformedPath.GetPointY(p); switch (TransformedPath.GetFlag(p) & FXPT_TYPE) { case FXPT_MOVETO: { buf << x << FX_BSTRC(" ") << y << FX_BSTRC(" m\n"); break; } case FXPT_LINETO: { buf << x << FX_BSTRC(" ") << y << FX_BSTRC(" l\n"); break; } case FXPT_BEZIERTO: { buf << x << FX_BSTRC(" ") << y << FX_BSTRC(" ") << TransformedPath.GetPointX(p + 1) << FX_BSTRC(" ") << TransformedPath.GetPointY(p + 1) << FX_BSTRC(" ") << TransformedPath.GetPointX(p + 2) << FX_BSTRC(" ") << TransformedPath.GetPointY(p + 2) << FX_BSTRC(" c\n"); p += 2; break; } } } buf << FX_BSTRC("f"); buf << FX_BSTRC("}bind def end\n"); buf << FX_BSTRC("/X") << ps_fontnum << FX_BSTRC(" Ff/Encoding get ") << ps_glyphindex << FX_BSTRC("/") << ps_glyphindex << FX_BSTRC(" put\n"); m_pOutput->OutputPS((FX_LPCSTR)buf.GetBuffer(), buf.GetSize()); }