FX_ARGB CPDF_ApSettings::GetColor(int& iColorType, FX_BSTR csEntry) { iColorType = COLORTYPE_TRANSPARENT; if (m_pDict == NULL) { return 0; } FX_ARGB color = 0; CPDF_Array* pEntry = m_pDict->GetArray(csEntry); if (pEntry == NULL) { return color; } FX_DWORD dwCount = pEntry->GetCount(); if (dwCount == 1) { iColorType = COLORTYPE_GRAY; FX_FLOAT g = pEntry->GetNumber(0) * 255; color = ArgbEncode(255, (int)g, (int)g, (int)g); } else if (dwCount == 3) { iColorType = COLORTYPE_RGB; FX_FLOAT r = pEntry->GetNumber(0) * 255; FX_FLOAT g = pEntry->GetNumber(1) * 255; FX_FLOAT b = pEntry->GetNumber(2) * 255; color = ArgbEncode(255, (int)r, (int)g, (int)b); } else if (dwCount == 4) { iColorType = COLORTYPE_CMYK; FX_FLOAT c = pEntry->GetNumber(0); FX_FLOAT m = pEntry->GetNumber(1); FX_FLOAT y = pEntry->GetNumber(2); FX_FLOAT k = pEntry->GetNumber(3); FX_FLOAT r = 1.0f - FX_MIN(1.0f, c + k); FX_FLOAT g = 1.0f - FX_MIN(1.0f, m + k); FX_FLOAT b = 1.0f - FX_MIN(1.0f, y + k); color = ArgbEncode(255, (int)(r * 255), (int)(g * 255), (int)(b * 255)); } return color; }
FX_BOOL CPDF_DeviceCS::GetRGB(FX_FLOAT* pBuf, FX_FLOAT& R, FX_FLOAT& G, FX_FLOAT& B) const { if (m_Family == PDFCS_DEVICERGB) { R = pBuf[0]; if (R < 0) { R = 0; } else if (R > 1) { R = 1; } G = pBuf[1]; if (G < 0) { G = 0; } else if (G > 1) { G = 1; } B = pBuf[2]; if (B < 0) { B = 0; } else if (B > 1) { B = 1; } } else if (m_Family == PDFCS_DEVICEGRAY) { R = *pBuf; if (R < 0) { R = 0; } else if (R > 1) { R = 1; } G = B = R; } else if (m_Family == PDFCS_DEVICECMYK) { if (!m_dwStdConversion) { AdobeCMYK_to_sRGB(pBuf[0], pBuf[1], pBuf[2], pBuf[3], R, G, B); } else { FX_FLOAT k = pBuf[3]; R = 1.0f - FX_MIN(1.0f, pBuf[0] + k); G = 1.0f - FX_MIN(1.0f, pBuf[1] + k); B = 1.0f - FX_MIN(1.0f, pBuf[2] + k); } } else { ASSERT(m_Family == PDFCS_PATTERN); R = G = B = 0; return FALSE; } return TRUE; }
FX_BOOL CPDFSDK_Annot::GetColor(FX_COLORREF& color) const { ASSERT(m_pAnnot != NULL); ASSERT(m_pAnnot->m_pAnnotDict != NULL); if (CPDF_Array* pEntry = m_pAnnot->m_pAnnotDict->GetArray("C")) { int nCount = pEntry->GetCount(); if (nCount == 1) { FX_FLOAT g = pEntry->GetNumber(0) * 255; color = FXSYS_RGB((int)g, (int)g, (int)g); return TRUE; } else if (nCount == 3) { FX_FLOAT r = pEntry->GetNumber(0) * 255; FX_FLOAT g = pEntry->GetNumber(1) * 255; FX_FLOAT b = pEntry->GetNumber(2) * 255; color = FXSYS_RGB((int)r, (int)g, (int)b); return TRUE; } else if (nCount == 4) { FX_FLOAT c = pEntry->GetNumber(0); FX_FLOAT m = pEntry->GetNumber(1); FX_FLOAT y = pEntry->GetNumber(2); FX_FLOAT k = pEntry->GetNumber(3); FX_FLOAT r = 1.0f - FX_MIN(1.0f, c + k); FX_FLOAT g = 1.0f - FX_MIN(1.0f, m + k); FX_FLOAT b = 1.0f - FX_MIN(1.0f, y + k); color = FXSYS_RGB((int)(r * 255), (int)(g * 255), (int)(b * 255)); return TRUE; } } return FALSE; }
void CPDF_DeviceCS::TranslateImageLine(uint8_t* pDestBuf, const uint8_t* pSrcBuf, int pixels, int image_width, int image_height, FX_BOOL bTransMask) const { if (bTransMask && m_Family == PDFCS_DEVICECMYK) { for (int i = 0; i < pixels; i++) { int k = 255 - pSrcBuf[3]; pDestBuf[0] = ((255 - pSrcBuf[0]) * k) / 255; pDestBuf[1] = ((255 - pSrcBuf[1]) * k) / 255; pDestBuf[2] = ((255 - pSrcBuf[2]) * k) / 255; pDestBuf += 3; pSrcBuf += 4; } return; } if (m_Family == PDFCS_DEVICERGB) { ReverseRGB(pDestBuf, pSrcBuf, pixels); } else if (m_Family == PDFCS_DEVICEGRAY) { for (int i = 0; i < pixels; i++) { *pDestBuf++ = pSrcBuf[i]; *pDestBuf++ = pSrcBuf[i]; *pDestBuf++ = pSrcBuf[i]; } } else { for (int i = 0; i < pixels; i++) { if (!m_dwStdConversion) { AdobeCMYK_to_sRGB1(pSrcBuf[0], pSrcBuf[1], pSrcBuf[2], pSrcBuf[3], pDestBuf[2], pDestBuf[1], pDestBuf[0]); } else { uint8_t k = pSrcBuf[3]; pDestBuf[2] = 255 - FX_MIN(255, pSrcBuf[0] + k); pDestBuf[1] = 255 - FX_MIN(255, pSrcBuf[1] + k); pDestBuf[0] = 255 - FX_MIN(255, pSrcBuf[2] + k); } pSrcBuf += 4; pDestBuf += 3; } } }
void GetOffset(FX_FLOAT& fa, FX_FLOAT& fd, FX_FLOAT& fe, FX_FLOAT& ff, CPDF_Rect rcAnnot, CPDF_Rect rcStream, CFX_AffineMatrix matrix) { FX_FLOAT fStreamWidth = 0.0f; FX_FLOAT fStreamHeight = 0.0f; if (matrix.a != 0 && matrix.d != 0) { fStreamWidth = rcStream.right - rcStream.left; fStreamHeight = rcStream.top - rcStream.bottom; } else { fStreamWidth = rcStream.top - rcStream.bottom; fStreamHeight = rcStream.right - rcStream.left; } FX_FLOAT x1 = matrix.a * rcStream.left + matrix.c * rcStream.bottom + matrix.e; FX_FLOAT y1 = matrix.b * rcStream.left + matrix.d * rcStream.bottom + matrix.f; FX_FLOAT x2 = matrix.a * rcStream.left + matrix.c * rcStream.top + matrix.e; FX_FLOAT y2 = matrix.b * rcStream.left + matrix.d * rcStream.top + matrix.f; FX_FLOAT x3 = matrix.a * rcStream.right + matrix.c * rcStream.bottom + matrix.e; FX_FLOAT y3 = matrix.b * rcStream.right + matrix.d * rcStream.bottom + matrix.f; FX_FLOAT x4 = matrix.a * rcStream.right + matrix.c * rcStream.top + matrix.e; FX_FLOAT y4 = matrix.b * rcStream.right + matrix.d * rcStream.top + matrix.f; FX_FLOAT left = FX_MIN(FX_MIN(x1, x2), FX_MIN(x3, x4)); FX_FLOAT bottom = FX_MIN(FX_MIN(y1, y2), FX_MIN(y3, y4)); fa = (rcAnnot.right - rcAnnot.left)/fStreamWidth; fd = (rcAnnot.top - rcAnnot.bottom)/fStreamHeight; fe = rcAnnot.left - left * fa; ff = rcAnnot.bottom - bottom * fd; }
void CPDF_DefaultAppearance::GetColor(FX_ARGB& color, int& iColorType, FX_BOOL bStrokingOperation) { color = 0; iColorType = COLORTYPE_TRANSPARENT; if (m_csDA.IsEmpty()) { return; } CPDF_SimpleParser syntax(m_csDA); if (syntax.FindTagParam(bStrokingOperation ? "G" : "g", 1)) { iColorType = COLORTYPE_GRAY; FX_FLOAT g = FX_atof((CFX_ByteString)syntax.GetWord()) * 255 + 0.5f; color = ArgbEncode(255, (int)g, (int)g, (int)g); return; } syntax.SetPos(0); if (syntax.FindTagParam(bStrokingOperation ? "RG" : "rg", 3)) { iColorType = COLORTYPE_RGB; FX_FLOAT r = FX_atof((CFX_ByteString)syntax.GetWord()) * 255 + 0.5f; FX_FLOAT g = FX_atof((CFX_ByteString)syntax.GetWord()) * 255 + 0.5f; FX_FLOAT b = FX_atof((CFX_ByteString)syntax.GetWord()) * 255 + 0.5f; color = ArgbEncode(255, (int)r, (int)g, (int)b); return; } syntax.SetPos(0); if (syntax.FindTagParam(bStrokingOperation ? "K" : "k", 4)) { iColorType = COLORTYPE_CMYK; FX_FLOAT c = FX_atof((CFX_ByteString)syntax.GetWord()); FX_FLOAT m = FX_atof((CFX_ByteString)syntax.GetWord()); FX_FLOAT y = FX_atof((CFX_ByteString)syntax.GetWord()); FX_FLOAT k = FX_atof((CFX_ByteString)syntax.GetWord()); FX_FLOAT r = 1.0f - FX_MIN(1.0f, c + k); FX_FLOAT g = 1.0f - FX_MIN(1.0f, m + k); FX_FLOAT b = 1.0f - FX_MIN(1.0f, y + k); color = ArgbEncode(255, (int)(r * 255 + 0.5f), (int)(g * 255 + 0.5f), (int)(b * 255 + 0.5f)); } }
FX_BOOL CFPF_SkiaFont::GetGlyphBBox(FX_INT32 iGlyphIndex, FX_RECT &rtBBox) { if (!m_Face) { return FALSE; } if (FXFT_Is_Face_Tricky(m_Face)) { if (FXFT_Set_Char_Size(m_Face, 0, 1000 * 64, 72, 72)) { return FALSE; } if (FXFT_Load_Glyph(m_Face, iGlyphIndex, FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH)) { FXFT_Set_Pixel_Sizes(m_Face, 0, 64); return FALSE; } FXFT_Glyph glyph; if (FXFT_Get_Glyph(m_Face->glyph, &glyph)) { FXFT_Set_Pixel_Sizes(m_Face, 0, 64); return FALSE; } FXFT_BBox cbox; FXFT_Glyph_Get_CBox(glyph, FXFT_GLYPH_BBOX_PIXELS, &cbox); FX_INT32 x_ppem = m_Face->size->metrics.x_ppem; FX_INT32 y_ppem = m_Face->size->metrics.y_ppem; rtBBox.left = FPF_EM_ADJUST(x_ppem, cbox.xMin); rtBBox.right = FPF_EM_ADJUST(x_ppem, cbox.xMax); rtBBox.top = FPF_EM_ADJUST(y_ppem, cbox.yMax); rtBBox.bottom = FPF_EM_ADJUST(y_ppem, cbox.yMin); rtBBox.top = FX_MIN(rtBBox.top, GetAscent()); rtBBox.bottom = FX_MAX(rtBBox.bottom, GetDescent()); FXFT_Done_Glyph(glyph); return FXFT_Set_Pixel_Sizes(m_Face, 0, 64) == 0; } if (FXFT_Load_Glyph(m_Face, iGlyphIndex, FXFT_LOAD_NO_SCALE | FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH)) { return FALSE; } rtBBox.left = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Glyph_HoriBearingX(m_Face)); rtBBox.bottom = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Glyph_HoriBearingY(m_Face)); rtBBox.right = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Glyph_HoriBearingX(m_Face) + FXFT_Get_Glyph_Width(m_Face)); rtBBox.top = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Glyph_HoriBearingY(m_Face) - FXFT_Get_Glyph_Height(m_Face)); return TRUE; }