FX_BOOL CPDF_ImageRenderer::StartBitmapAlpha() { if (m_pDIBSource->IsOpaqueImage()) { CFX_PathData path; path.AppendRect(0, 0, 1, 1); path.Transform(&m_ImageMatrix); FX_DWORD fill_color = ArgbEncode(0xff, m_BitmapAlpha, m_BitmapAlpha, m_BitmapAlpha); m_pRenderStatus->m_pDevice->DrawPath(&path, NULL, NULL, fill_color, 0, FXFILL_WINDING); } else { const CFX_DIBSource* pAlphaMask = m_pDIBSource->IsAlphaMask() ? m_pDIBSource : m_pDIBSource->GetAlphaMask(); if (FXSYS_fabs(m_ImageMatrix.b) >= 0.5f || FXSYS_fabs(m_ImageMatrix.c) >= 0.5f) { int left, top; CFX_DIBitmap* pTransformed = pAlphaMask->TransformTo(&m_ImageMatrix, left, top); if (pTransformed == NULL) { return TRUE; } m_pRenderStatus->m_pDevice->SetBitMask(pTransformed, left, top, ArgbEncode(0xff, m_BitmapAlpha, m_BitmapAlpha, m_BitmapAlpha)); delete pTransformed; } else { CFX_FloatRect image_rect_f = m_ImageMatrix.GetUnitRect(); FX_RECT image_rect = image_rect_f.GetOutterRect(); int dest_width = m_ImageMatrix.a > 0 ? image_rect.Width() : -image_rect.Width(); int dest_height = m_ImageMatrix.d > 0 ? -image_rect.Height() : image_rect.Height(); int left = dest_width > 0 ? image_rect.left : image_rect.right; int top = dest_height > 0 ? image_rect.top : image_rect.bottom; m_pRenderStatus->m_pDevice->StretchBitMask(pAlphaMask, left, top, dest_width, dest_height, ArgbEncode(0xff, m_BitmapAlpha, m_BitmapAlpha, m_BitmapAlpha)); } if (m_pDIBSource != pAlphaMask) { delete pAlphaMask; } } return FALSE; }
FX_BOOL CFX_QuartzDeviceDriver::GetDIBits(CFX_DIBitmap* bitmap, FX_INT32 left, FX_INT32 top, void* pIccTransform, FX_BOOL bDEdge) { if (FXDC_PRINTER == _deviceClass) { return FALSE; } if (bitmap->GetBPP() < 32) { return FALSE; } if (!(_renderCaps | FXRC_GET_BITS)) { return FALSE; } CGPoint pt = CGPointMake(left, top); pt = CGPointApplyAffineTransform(pt, _foxitDevice2User); CGAffineTransform ctm = CGContextGetCTM(_context); pt.x *= FXSYS_fabs(ctm.a); pt.y *= FXSYS_fabs(ctm.d); CGImageRef image = CGBitmapContextCreateImage(_context); if (NULL == image) { return FALSE; } CGFloat width = (CGFloat) bitmap->GetWidth(); CGFloat height = (CGFloat) bitmap->GetHeight(); if (width + pt.x > _width) { width -= (width + pt.x - _width); } if (height + pt.y > _height) { height -= (height + pt.y - _height); } CGImageRef subImage = CGImageCreateWithImageInRect(image, CGRectMake(pt.x, pt.y, width, height)); CGContextRef context = createContextWithBitmap(bitmap); CGRect rect = CGContextGetClipBoundingBox(context); CGContextClearRect(context, rect); CGContextDrawImage(context, rect, subImage); CGContextRelease(context); CGImageRelease(subImage); CGImageRelease(image); if (bitmap->HasAlpha()) { for (int row = 0; row < bitmap->GetHeight(); row ++) { FX_LPBYTE pScanline = (FX_LPBYTE)bitmap->GetScanline(row); for (int col = 0; col < bitmap->GetWidth(); col ++) { if (pScanline[3] > 0) { pScanline[0] = (pScanline[0] * 255.f / pScanline[3] + .5f); pScanline[1] = (pScanline[1] * 255.f / pScanline[3] + .5f); pScanline[2] = (pScanline[2] * 255.f / pScanline[3] + .5f); } pScanline += 4; } } } return TRUE; }
CFX_GlyphBitmap* CPDF_Type3Cache::RenderGlyph(CPDF_Type3Glyphs* pSize, FX_DWORD charcode, const CFX_AffineMatrix* pMatrix, FX_FLOAT retinaScaleX, FX_FLOAT retinaScaleY) { const CPDF_Type3Char* pChar = m_pFont->LoadChar(charcode); if (!pChar || !pChar->m_pBitmap) return nullptr; CFX_DIBitmap* pBitmap = pChar->m_pBitmap; CFX_AffineMatrix image_matrix, text_matrix; image_matrix = pChar->m_ImageMatrix; text_matrix.Set(pMatrix->a, pMatrix->b, pMatrix->c, pMatrix->d, 0, 0); image_matrix.Concat(text_matrix); CFX_DIBitmap* pResBitmap = NULL; int left, top; if (FXSYS_fabs(image_matrix.b) < FXSYS_fabs(image_matrix.a) / 100 && FXSYS_fabs(image_matrix.c) < FXSYS_fabs(image_matrix.d) / 100) { int top_line, bottom_line; top_line = _DetectFirstLastScan(pBitmap, TRUE); bottom_line = _DetectFirstLastScan(pBitmap, FALSE); if (top_line == 0 && bottom_line == pBitmap->GetHeight() - 1) { FX_FLOAT top_y = image_matrix.d + image_matrix.f; FX_FLOAT bottom_y = image_matrix.f; FX_BOOL bFlipped = top_y > bottom_y; if (bFlipped) { FX_FLOAT temp = top_y; top_y = bottom_y; bottom_y = temp; } pSize->AdjustBlue(top_y, bottom_y, top_line, bottom_line); pResBitmap = pBitmap->StretchTo( (int)(FXSYS_round(image_matrix.a) * retinaScaleX), (int)((bFlipped ? top_line - bottom_line : bottom_line - top_line) * retinaScaleY)); top = top_line; if (image_matrix.a < 0) { image_matrix.Scale(retinaScaleX, retinaScaleY); left = FXSYS_round(image_matrix.e + image_matrix.a); } else { left = FXSYS_round(image_matrix.e); } } else { } } if (pResBitmap == NULL) { image_matrix.Scale(retinaScaleX, retinaScaleY); pResBitmap = pBitmap->TransformTo(&image_matrix, left, top); } if (pResBitmap == NULL) { return NULL; } CFX_GlyphBitmap* pGlyph = new CFX_GlyphBitmap; pGlyph->m_Left = left; pGlyph->m_Top = -top; pGlyph->m_Bitmap.TakeOver(pResBitmap); delete pResBitmap; return pGlyph; }
void CFDE_Path::AddLine(const CFX_PointF& pt1, const CFX_PointF& pt2) { FX_PATHPOINT* pLast = GetLastPoint(); if (!pLast || FXSYS_fabs(pLast->m_PointX - pt1.x) > 0.001 || FXSYS_fabs(pLast->m_PointY - pt1.y) > 0.001) { MoveTo(pt1); } LineTo(pt2); }
static void DrawTextString(CFX_RenderDevice* pDevice, const CPDF_Point& pt, CPDF_Font* pFont, FX_FLOAT fFontSize, CPDF_Matrix* pUser2Device, const CFX_ByteString& str, FX_ARGB crTextFill, FX_ARGB crTextStroke, int32_t nHorzScale) { FX_FLOAT x = pt.x, y = pt.y; pUser2Device->Transform(x, y); if (pFont) { if (nHorzScale != 100) { CPDF_Matrix mt(nHorzScale / 100.0f, 0, 0, 1, 0, 0); mt.Concat(*pUser2Device); CPDF_RenderOptions ro; ro.m_Flags = RENDER_CLEARTYPE; ro.m_ColorMode = RENDER_COLOR_NORMAL; if (crTextStroke != 0) { CPDF_Point pt1(0, 0), pt2(1, 0); pUser2Device->Transform(pt1.x, pt1.y); pUser2Device->Transform(pt2.x, pt2.y); CFX_GraphStateData gsd; gsd.m_LineWidth = (FX_FLOAT)FXSYS_fabs((pt2.x + pt2.y) - (pt1.x + pt1.y)); CPDF_TextRenderer::DrawTextString(pDevice, x, y, pFont, fFontSize, &mt, str, crTextFill, crTextStroke, &gsd, &ro); } else CPDF_TextRenderer::DrawTextString(pDevice, x, y, pFont, fFontSize, &mt, str, crTextFill, 0, NULL, &ro); } else { CPDF_RenderOptions ro; ro.m_Flags = RENDER_CLEARTYPE; ro.m_ColorMode = RENDER_COLOR_NORMAL; if (crTextStroke != 0) { CPDF_Point pt1(0, 0), pt2(1, 0); pUser2Device->Transform(pt1.x, pt1.y); pUser2Device->Transform(pt2.x, pt2.y); CFX_GraphStateData gsd; gsd.m_LineWidth = (FX_FLOAT)FXSYS_fabs((pt2.x + pt2.y) - (pt1.x + pt1.y)); CPDF_TextRenderer::DrawTextString(pDevice, x, y, pFont, fFontSize, pUser2Device, str, crTextFill, crTextStroke, &gsd, &ro); } else CPDF_TextRenderer::DrawTextString(pDevice, x, y, pFont, fFontSize, pUser2Device, str, crTextFill, 0, NULL, &ro); } } }
FX_BOOL CGdiPrinterDriver::StartDIBits(const CFX_DIBSource* pSource, int bitmap_alpha, FX_DWORD color, const CFX_AffineMatrix* pMatrix, FX_DWORD render_flags, void*& handle, int alpha_flag, void* pIccTransform, int blend_type) { if (bitmap_alpha < 255 || pSource->HasAlpha() || (pSource->IsAlphaMask() && (pSource->GetBPP() != 1 || !m_bSupportROP))) { return FALSE; } CFX_FloatRect unit_rect = pMatrix->GetUnitRect(); FX_RECT full_rect = unit_rect.GetOutterRect(); if (FXSYS_fabs(pMatrix->b) < 0.5f && pMatrix->a != 0 && FXSYS_fabs(pMatrix->c) < 0.5f && pMatrix->d != 0) { FX_BOOL bFlipX = pMatrix->a < 0; FX_BOOL bFlipY = pMatrix->d > 0; return StretchDIBits(pSource, color, bFlipX ? full_rect.right : full_rect.left, bFlipY ? full_rect.bottom : full_rect.top, bFlipX ? -full_rect.Width() : full_rect.Width(), bFlipY ? -full_rect.Height() : full_rect.Height(), NULL, 0, alpha_flag, pIccTransform, blend_type); } if (FXSYS_fabs(pMatrix->a) < 0.5f && FXSYS_fabs(pMatrix->d) < 0.5f) { CFX_DIBitmap* pTransformed = pSource->SwapXY(pMatrix->c > 0, pMatrix->b < 0); if (pTransformed == NULL) { return FALSE; } FX_BOOL ret = StretchDIBits( pTransformed, color, full_rect.left, full_rect.top, full_rect.Width(), full_rect.Height(), NULL, 0, alpha_flag, pIccTransform, blend_type); delete pTransformed; return ret; } if (pSource->GetBPP() == 1) { CFX_DIBitmap* pTransformed = Transform1bppBitmap(pSource, pMatrix); if (pIccTransform == NULL) { return FALSE; } SaveState(); CFX_PathData path; path.AppendRect(0, 0, 1.0f, 1.0f); SetClip_PathFill(&path, pMatrix, WINDING); FX_BOOL ret = StretchDIBits( pTransformed, color, full_rect.left, full_rect.top, full_rect.Width(), full_rect.Height(), NULL, 0, alpha_flag, pIccTransform, blend_type); RestoreState(); delete pTransformed; handle = NULL; return ret; } return FALSE; }
static void _MatchFloatRange(FX_FLOAT f1, FX_FLOAT f2, int& i1, int& i2) { int length = (int)FXSYS_ceil(f2 - f1); int i1_1 = (int)FXSYS_floor(f1); int i1_2 = (int)FXSYS_ceil(f1); FX_FLOAT error1 = f1 - i1_1 + (FX_FLOAT)FXSYS_fabs(f2 - i1_1 - length); FX_FLOAT error2 = i1_2 - f1 + (FX_FLOAT)FXSYS_fabs(f2 - i1_2 - length); i1 = (error1 > error2) ? i1_2 : i1_1; i2 = i1 + length; }
FX_BOOL CBC_QRAlignmentPattern::AboutEquals(FX_FLOAT moduleSize, FX_FLOAT i, FX_FLOAT j) { if ((FXSYS_fabs(i - GetY()) <= moduleSize) && (FXSYS_fabs(j - GetX()) <= moduleSize)) { FX_FLOAT moduleSizeDiff = FXSYS_fabs(moduleSize - m_moduleSize); return (moduleSizeDiff <= 1.0f) || (moduleSizeDiff / m_moduleSize <= 1.0f); } return FALSE; }
void CFX_Matrix::MatchRect(const CFX_FloatRect& dest, const CFX_FloatRect& src) { FX_FLOAT fDiff = src.left - src.right; a = FXSYS_fabs(fDiff) < 0.001f ? 1 : (dest.left - dest.right) / fDiff; fDiff = src.bottom - src.top; d = FXSYS_fabs(fDiff) < 0.001f ? 1 : (dest.bottom - dest.top) / fDiff; e = dest.left - src.left * a; f = dest.bottom - src.bottom * d; b = 0; c = 0; }
void CFDE_Path::AddPolygon(const CFX_PointsF& points) { int32_t iCount = points.GetSize(); if (iCount < 2) return; AddLines(points); const CFX_PointF* p = points.GetData(); if (FXSYS_fabs(p[0].x - p[iCount - 1].x) < 0.01f || FXSYS_fabs(p[0].y - p[iCount - 1].y) < 0.01f) { LineTo(p[0]); } CloseFigure(); }
FX_BOOL CFX_ImageTransformer::Start() { CFX_FloatRect unit_rect = m_pMatrix->GetUnitRect(); FX_RECT result_rect = unit_rect.GetClosestRect(); FX_RECT result_clip = result_rect; if (m_pClip) result_clip.Intersect(*m_pClip); if (result_clip.IsEmpty()) return FALSE; m_result = result_clip; if (FXSYS_fabs(m_pMatrix->a) < FXSYS_fabs(m_pMatrix->b) / 20 && FXSYS_fabs(m_pMatrix->d) < FXSYS_fabs(m_pMatrix->c) / 20 && FXSYS_fabs(m_pMatrix->a) < 0.5f && FXSYS_fabs(m_pMatrix->d) < 0.5f) { int dest_width = result_rect.Width(); int dest_height = result_rect.Height(); result_clip.Offset(-result_rect.left, -result_rect.top); result_clip = FXDIB_SwapClipBox(result_clip, dest_width, dest_height, m_pMatrix->c > 0, m_pMatrix->b < 0); m_Stretcher = WrapUnique(new CFX_ImageStretcher( &m_Storer, m_pSrc, dest_height, dest_width, result_clip, m_Flags)); m_Stretcher->Start(); m_Status = 1; return TRUE; } if (FXSYS_fabs(m_pMatrix->b) < FIX16_005 && FXSYS_fabs(m_pMatrix->c) < FIX16_005) { int dest_width = m_pMatrix->a > 0 ? (int)FXSYS_ceil(m_pMatrix->a) : (int)FXSYS_floor(m_pMatrix->a); int dest_height = m_pMatrix->d > 0 ? (int)-FXSYS_ceil(m_pMatrix->d) : (int)-FXSYS_floor(m_pMatrix->d); result_clip.Offset(-result_rect.left, -result_rect.top); m_Stretcher = WrapUnique(new CFX_ImageStretcher( &m_Storer, m_pSrc, dest_width, dest_height, result_clip, m_Flags)); m_Stretcher->Start(); m_Status = 2; return TRUE; } int stretch_width = (int)FXSYS_ceil(FXSYS_sqrt2(m_pMatrix->a, m_pMatrix->b)); int stretch_height = (int)FXSYS_ceil(FXSYS_sqrt2(m_pMatrix->c, m_pMatrix->d)); CFX_Matrix stretch2dest(1.0f, 0.0f, 0.0f, -1.0f, 0.0f, (FX_FLOAT)(stretch_height)); stretch2dest.Concat( m_pMatrix->a / stretch_width, m_pMatrix->b / stretch_width, m_pMatrix->c / stretch_height, m_pMatrix->d / stretch_height, m_pMatrix->e, m_pMatrix->f); m_dest2stretch.SetReverse(stretch2dest); CFX_FloatRect clip_rect_f(result_clip); clip_rect_f.Transform(&m_dest2stretch); m_StretchClip = clip_rect_f.GetOuterRect(); m_StretchClip.Intersect(0, 0, stretch_width, stretch_height); m_Stretcher = WrapUnique(new CFX_ImageStretcher(&m_Storer, m_pSrc, stretch_width, stretch_height, m_StretchClip, m_Flags)); m_Stretcher->Start(); m_Status = 3; return TRUE; }
FX_BOOL CTextBaseLine::CanMerge(CTextBaseLine* pOther) { FX_FLOAT inter_top, inter_bottom; if (!GetIntersection(m_Bottom, m_Top, pOther->m_Bottom, pOther->m_Top, inter_bottom, inter_top)) { return FALSE; } FX_FLOAT inter_h = inter_top - inter_bottom; if (inter_h < (m_Top - m_Bottom) / 2 && inter_h < (pOther->m_Top - pOther->m_Bottom) / 2) { return FALSE; } FX_FLOAT dy = (FX_FLOAT)FXSYS_fabs(m_BaseLine - pOther->m_BaseLine); for (int i = 0; i < m_TextList.GetSize(); i ++) { CTextBox* pText = (CTextBox*)m_TextList.GetAt(i); for (int j = 0; j < pOther->m_TextList.GetSize(); j ++) { CTextBox* pOtherText = (CTextBox*)pOther->m_TextList.GetAt(j); FX_FLOAT inter_left, inter_right; if (!GetIntersection(pText->m_Left, pText->m_Right, pOtherText->m_Left, pOtherText->m_Right, inter_left, inter_right)) { continue; } FX_FLOAT inter_w = inter_right - inter_left; if (inter_w < pText->m_SpaceWidth / 2 && inter_w < pOtherText->m_SpaceWidth / 2) { continue; } if (dy >= (pText->m_Bottom - pText->m_Top) / 2 || dy >= (pOtherText->m_Bottom - pOtherText->m_Top) / 2) { return FALSE; } } } return TRUE; }
int32_t CBC_PDF417Reader::getMinWidth(CBC_ResultPoint* p1, CBC_ResultPoint* p2) { if (p1 == NULL || p2 == NULL) { return Integer_MAX_VALUE; } return (int32_t)FXSYS_fabs(p1->GetX() - p2->GetX()); }
void CFDE_Path::ArcTo(FX_BOOL bStart, const CFX_RectF& rect, FX_FLOAT startAngle, FX_FLOAT endAngle) { FX_FLOAT rx = rect.width / 2; FX_FLOAT ry = rect.height / 2; FX_FLOAT cx = rect.left + rx; FX_FLOAT cy = rect.top + ry; FX_FLOAT alpha = FXSYS_atan2(rx * FXSYS_sin(startAngle), ry * FXSYS_cos(startAngle)); FX_FLOAT beta = FXSYS_atan2(rx * FXSYS_sin(endAngle), ry * FXSYS_cos(endAngle)); if (FXSYS_fabs(beta - alpha) > FX_PI) { if (beta > alpha) beta -= 2 * FX_PI; else alpha -= 2 * FX_PI; } FX_FLOAT half_delta = (beta - alpha) / 2; FX_FLOAT bcp = 4.0f / 3 * (1 - FXSYS_cos(half_delta)) / FXSYS_sin(half_delta); FX_FLOAT sin_alpha = FXSYS_sin(alpha); FX_FLOAT sin_beta = FXSYS_sin(beta); FX_FLOAT cos_alpha = FXSYS_cos(alpha); FX_FLOAT cos_beta = FXSYS_cos(beta); if (bStart) MoveTo(CFX_PointF(cx + rx * cos_alpha, cy + ry * sin_alpha)); BezierTo(CFX_PointF(cx + rx * (cos_alpha - bcp * sin_alpha), cy + ry * (sin_alpha + bcp * cos_alpha)), CFX_PointF(cx + rx * (cos_beta + bcp * sin_beta), cy + ry * (sin_beta - bcp * cos_beta)), CFX_PointF(cx + rx * cos_beta, cy + ry * sin_beta)); }
int32_t CBC_PDF417Reader::getMaxWidth(CBC_ResultPoint* p1, CBC_ResultPoint* p2) { if (p1 == NULL || p2 == NULL) { return 0; } return (int32_t)FXSYS_fabs(p1->GetX() - p2->GetX()); }
void IFWL_Widget::SetWidgetRect(const CFX_RectF& rect) { CFX_RectF rtOld = m_pProperties->m_rtWidget; m_pProperties->m_rtWidget = rect; if (IsChild()) { if (FXSYS_fabs(rtOld.width - rect.width) > 0.5f || FXSYS_fabs(rtOld.height - rect.height) > 0.5f) { CFWL_EvtSizeChanged ev; ev.m_pSrcTarget = this; ev.m_rtOld = rtOld; ev.m_rtNew = rect; if (IFWL_WidgetDelegate* pDelegate = GetDelegate()) pDelegate->OnProcessEvent(&ev); } return; } m_pWidgetMgr->SetWidgetRect_Native(this, rect); }
bool CPDF_ImageRenderer::StartBitmapAlpha() { if (m_pDIBSource->IsOpaqueImage()) { CFX_PathData path; path.AppendRect(0, 0, 1, 1); path.Transform(&m_ImageMatrix); uint32_t fill_color = ArgbEncode(0xff, m_BitmapAlpha, m_BitmapAlpha, m_BitmapAlpha); m_pRenderStatus->m_pDevice->DrawPath(&path, nullptr, nullptr, fill_color, 0, FXFILL_WINDING); return false; } CFX_MaybeOwned<CFX_DIBSource> pAlphaMask; if (m_pDIBSource->IsAlphaMask()) pAlphaMask = const_cast<CFX_DIBSource*>(m_pDIBSource); else pAlphaMask = m_pDIBSource->CloneAlphaMask(); if (FXSYS_fabs(m_ImageMatrix.b) >= 0.5f || FXSYS_fabs(m_ImageMatrix.c) >= 0.5f) { int left; int top; std::unique_ptr<CFX_DIBitmap> pTransformed = pAlphaMask->TransformTo(&m_ImageMatrix, left, top); if (!pTransformed) return true; m_pRenderStatus->m_pDevice->SetBitMask( pTransformed.get(), left, top, ArgbEncode(0xff, m_BitmapAlpha, m_BitmapAlpha, m_BitmapAlpha)); return false; } CFX_FloatRect image_rect_f = m_ImageMatrix.GetUnitRect(); FX_RECT image_rect = image_rect_f.GetOuterRect(); int dest_width = m_ImageMatrix.a > 0 ? image_rect.Width() : -image_rect.Width(); int dest_height = m_ImageMatrix.d > 0 ? -image_rect.Height() : image_rect.Height(); int left = dest_width > 0 ? image_rect.left : image_rect.right; int top = dest_height > 0 ? image_rect.top : image_rect.bottom; m_pRenderStatus->m_pDevice->StretchBitMask( pAlphaMask.Get(), left, top, dest_width, dest_height, ArgbEncode(0xff, m_BitmapAlpha, m_BitmapAlpha, m_BitmapAlpha)); return false; }
void CPDF_ReflowedPage::FocusGetData(const CFX_AffineMatrix matrix, FX_INT32 x, FX_INT32 y, CFX_ByteString& str) { if (NULL == m_pReflowed) { return; } CFX_AffineMatrix revMatrix; revMatrix.SetReverse(matrix); FX_FLOAT x1, y1; revMatrix.Transform((float)x, (float)y, x1, y1); int count = m_pReflowed->GetSize(); FX_FLOAT dx = 1000, dy = 1000; FX_INT32 pos = 0; FX_INT32 i; for(i = 0; i < count; i++) { CRF_Data* pData = (*m_pReflowed)[i]; FX_FLOAT tempdy = FXSYS_fabs(pData->m_PosY - y1); if(FXSYS_fabs(tempdy - dy) < 1) { continue; } CFX_FloatRect rect (0, pData->m_PosY + pData->m_Height, this->m_PageWidth, pData->m_PosY); if(rect.Contains(x1, y1)) { pos = i; dx = 0; dy = 0; break; } else if(tempdy < dy) { dy = tempdy; dx = FXSYS_fabs(pData->m_PosX - x1); pos = i; } else if (tempdy == dy) { FX_FLOAT tempdx = FXSYS_fabs(pData->m_PosX - x1); if(tempdx < dx) { dx = tempdx; pos = i; } } else if (tempdy > dy) { break; } } if(dx != 0 || dy != 0) { count = count < (pos + 10) ? count : (pos + 10); for(i = 0 > (pos - 10) ? 0 : (pos - 10); i < count; i++) { CRF_Data* pData = (*m_pReflowed)[i]; FX_FLOAT tempdy = FXSYS_fabs(pData->m_PosY - y1); if(tempdy < dy) { dy = tempdy; dx = FXSYS_fabs(pData->m_PosX - x1); pos = i; } else if (tempdy == dy) { FX_FLOAT tempdx = FXSYS_fabs(pData->m_PosX - x1); if(tempdx < dx) { dx = tempdx; pos = i; } } } } str.Format("%d", pos); }
CFX_DIBitmap* CPDF_RenderStatus::GetBackdrop(const CPDF_PageObject* pObj, const FX_RECT& rect, int& left, int& top, FX_BOOL bBackAlphaRequired) { FX_RECT bbox = rect; bbox.Intersect(m_pDevice->GetClipBox()); left = bbox.left; top = bbox.top; CFX_Matrix deviceCTM = m_pDevice->GetCTM(); FX_FLOAT scaleX = FXSYS_fabs(deviceCTM.a); FX_FLOAT scaleY = FXSYS_fabs(deviceCTM.d); int width = FXSYS_round(bbox.Width() * scaleX); int height = FXSYS_round(bbox.Height() * scaleY); std::unique_ptr<CFX_DIBitmap> pBackdrop(new CFX_DIBitmap); if (bBackAlphaRequired && !m_bDropObjects) pBackdrop->Create(width, height, FXDIB_Argb); else m_pDevice->CreateCompatibleBitmap(pBackdrop.get(), width, height); if (!pBackdrop->GetBuffer()) return nullptr; FX_BOOL bNeedDraw; if (pBackdrop->HasAlpha()) bNeedDraw = !(m_pDevice->GetRenderCaps() & FXRC_ALPHA_OUTPUT); else bNeedDraw = !(m_pDevice->GetRenderCaps() & FXRC_GET_BITS); if (!bNeedDraw) { m_pDevice->GetDIBits(pBackdrop.get(), left, top); return pBackdrop.release(); } CFX_Matrix FinalMatrix = m_DeviceMatrix; FinalMatrix.TranslateI(-left, -top); FinalMatrix.Scale(scaleX, scaleY); pBackdrop->Clear(pBackdrop->HasAlpha() ? 0 : 0xffffffff); CFX_FxgeDevice device; device.Attach(pBackdrop.get(), false, nullptr, false); m_pContext->Render(&device, pObj, &m_Options, &FinalMatrix); return pBackdrop.release(); }
FX_BOOL CXFA_Stroke::SameStyles(CXFA_Stroke stroke, uint32_t dwFlags) const { if (m_pNode == stroke.GetNode()) return TRUE; if (FXSYS_fabs(GetThickness() - stroke.GetThickness()) >= 0.01f) return FALSE; if ((dwFlags & XFA_STROKE_SAMESTYLE_NoPresence) == 0 && IsVisible() != stroke.IsVisible()) { return FALSE; } if (GetStrokeType() != stroke.GetStrokeType()) return FALSE; if (GetColor() != stroke.GetColor()) return FALSE; if ((dwFlags & XFA_STROKE_SAMESTYLE_Corner) != 0 && FXSYS_fabs(GetRadius() - stroke.GetRadius()) >= 0.01f) { return FALSE; } return TRUE; }
CFX_Matrix_3by3 CFX_Matrix_3by3::Inverse() { FX_FLOAT det = a * (e * i - f * h) - b * (i * d - f * g) + c * (d * h - e * g); if (FXSYS_fabs(det) < 0.0000001) return CFX_Matrix_3by3(); return CFX_Matrix_3by3( (e * i - f * h) / det, -(b * i - c * h) / det, (b * f - c * e) / det, -(d * i - f * g) / det, (a * i - c * g) / det, -(a * f - c * d) / det, (d * h - e * g) / det, -(a * h - b * g) / det, (a * e - b * d) / det); }
FX_BOOL CPDF_TilingPattern::Load() { if (m_pForm != NULL) { return TRUE; } CPDF_Dictionary* pDict = m_pPatternObj->GetDict(); if (pDict == NULL) { return FALSE; } m_bColored = pDict->GetInteger(FX_BSTRC("PaintType")) == 1; m_XStep = (FX_FLOAT)FXSYS_fabs(pDict->GetNumber(FX_BSTRC("XStep"))); m_YStep = (FX_FLOAT)FXSYS_fabs(pDict->GetNumber(FX_BSTRC("YStep"))); if (m_pPatternObj->GetType() != PDFOBJ_STREAM) { return FALSE; } CPDF_Stream* pStream = (CPDF_Stream*)m_pPatternObj; m_pForm = FX_NEW CPDF_Form(m_pDocument, NULL, pStream); m_pForm->ParseContent(NULL, &m_ParentMatrix, NULL, NULL); m_BBox = pDict->GetRect(FX_BSTRC("BBox")); return TRUE; }
bool CPDF_TilingPattern::Load() { if (m_pForm) return true; CPDF_Dictionary* pDict = m_pPatternObj->GetDict(); if (!pDict) return false; m_bColored = pDict->GetIntegerFor("PaintType") == 1; m_XStep = (FX_FLOAT)FXSYS_fabs(pDict->GetNumberFor("XStep")); m_YStep = (FX_FLOAT)FXSYS_fabs(pDict->GetNumberFor("YStep")); CPDF_Stream* pStream = m_pPatternObj->AsStream(); if (!pStream) return false; m_pForm.reset(new CPDF_Form(m_pDocument, nullptr, pStream)); m_pForm->ParseContent(nullptr, &m_ParentMatrix, nullptr); m_BBox = pDict->GetRectFor("BBox"); return true; }
FX_BOOL CFX_ImageTransformer::Start(const CFX_DIBSource* pSrc, const CFX_AffineMatrix* pDestMatrix, int flags, const FX_RECT* pDestClip) { m_pMatrix = (CFX_AffineMatrix*)pDestMatrix; CFX_FloatRect unit_rect = pDestMatrix->GetUnitRect(); FX_RECT result_rect = unit_rect.GetClosestRect(); FX_RECT result_clip = result_rect; if (pDestClip) { result_clip.Intersect(*pDestClip); } if (result_clip.IsEmpty()) { return FALSE; } m_ResultLeft = result_clip.left; m_ResultTop = result_clip.top; m_ResultWidth = result_clip.Width(); m_ResultHeight = result_clip.Height(); m_Flags = flags; if (FXSYS_fabs(pDestMatrix->a) < FXSYS_fabs(pDestMatrix->b) / 20 && FXSYS_fabs(pDestMatrix->d) < FXSYS_fabs(pDestMatrix->c) / 20 && FXSYS_fabs(pDestMatrix->a) < 0.5f && FXSYS_fabs(pDestMatrix->d) < 0.5f) { int dest_width = result_rect.Width(); int dest_height = result_rect.Height(); result_clip.Offset(-result_rect.left, -result_rect.top); result_clip = _FXDIB_SwapClipBox(result_clip, dest_width, dest_height, pDestMatrix->c > 0, pDestMatrix->b < 0); m_Stretcher.Start(&m_Storer, pSrc, dest_height, dest_width, result_clip, flags); m_Status = 1; return TRUE; } if (FXSYS_fabs(pDestMatrix->b) < FIX16_005 && FXSYS_fabs(pDestMatrix->c) < FIX16_005) { int dest_width = pDestMatrix->a > 0 ? (int)FXSYS_ceil(pDestMatrix->a) : (int)FXSYS_floor(pDestMatrix->a); int dest_height = pDestMatrix->d > 0 ? (int) - FXSYS_ceil(pDestMatrix->d) : (int) - FXSYS_floor(pDestMatrix->d); result_clip.Offset(-result_rect.left, -result_rect.top); m_Stretcher.Start(&m_Storer, pSrc, dest_width, dest_height, result_clip, flags); m_Status = 2; return TRUE; } int stretch_width = (int)FXSYS_ceil(FXSYS_sqrt2(pDestMatrix->a, pDestMatrix->b)); int stretch_height = (int)FXSYS_ceil(FXSYS_sqrt2(pDestMatrix->c, pDestMatrix->d)); CFX_AffineMatrix stretch2dest(1.0f, 0.0f, 0.0f, -1.0f, 0.0f, (FX_FLOAT)(stretch_height)); stretch2dest.Concat(pDestMatrix->a / stretch_width, pDestMatrix->b / stretch_width, pDestMatrix->c / stretch_height, pDestMatrix->d / stretch_height, pDestMatrix->e, pDestMatrix->f); m_dest2stretch.SetReverse(stretch2dest); CFX_FloatRect clip_rect_f(result_clip); clip_rect_f.Transform(&m_dest2stretch); m_StretchClip = clip_rect_f.GetOutterRect(); m_StretchClip.Intersect(0, 0, stretch_width, stretch_height); m_Stretcher.Start(&m_Storer, pSrc, stretch_width, stretch_height, m_StretchClip, flags); m_Status = 3; return TRUE; }
FX_BOOL CPDF_RenderStatus::GetObjectClippedRect(const CPDF_PageObject* pObj, const CFX_Matrix* pObj2Device, FX_BOOL bLogical, FX_RECT& rect) const { rect = pObj->GetBBox(pObj2Device); FX_RECT rtClip = m_pDevice->GetClipBox(); if (!bLogical) { CFX_Matrix dCTM = m_pDevice->GetCTM(); FX_FLOAT a = FXSYS_fabs(dCTM.a); FX_FLOAT d = FXSYS_fabs(dCTM.d); if (a != 1.0f || d != 1.0f) { rect.right = rect.left + (int32_t)FXSYS_ceil((FX_FLOAT)rect.Width() * a); rect.bottom = rect.top + (int32_t)FXSYS_ceil((FX_FLOAT)rect.Height() * d); rtClip.right = rtClip.left + (int32_t)FXSYS_ceil((FX_FLOAT)rtClip.Width() * a); rtClip.bottom = rtClip.top + (int32_t)FXSYS_ceil((FX_FLOAT)rtClip.Height() * d); } } rect.Intersect(rtClip); return rect.IsEmpty(); }
void CFX_Matrix::SetReverse(const CFX_Matrix& m) { FX_FLOAT i = m.a * m.d - m.b * m.c; if (FXSYS_fabs(i) == 0) { return; } FX_FLOAT j = -i; a = m.d / i; b = m.b / j; c = m.c / j; d = m.a / i; e = (m.c * m.f - m.d * m.e) / i; f = (m.a * m.f - m.b * m.e) / j; }
FX_BOOL CPDF_DeviceBuffer::Initialize(CPDF_RenderContext* pContext, CFX_RenderDevice* pDevice, FX_RECT* pRect, const CPDF_PageObject* pObj, int max_dpi) { m_pDevice = pDevice; m_pContext = pContext; m_Rect = *pRect; m_pObject = pObj; m_Matrix.TranslateI(-pRect->left, -pRect->top); #if _FXM_PLATFORM_ != _FXM_PLATFORM_APPLE_ int horz_size = pDevice->GetDeviceCaps(FXDC_HORZ_SIZE); int vert_size = pDevice->GetDeviceCaps(FXDC_VERT_SIZE); if (horz_size && vert_size && max_dpi) { int dpih = pDevice->GetDeviceCaps(FXDC_PIXEL_WIDTH) * 254 / (horz_size * 10); int dpiv = pDevice->GetDeviceCaps(FXDC_PIXEL_HEIGHT) * 254 / (vert_size * 10); if (dpih > max_dpi) { m_Matrix.Scale((FX_FLOAT)(max_dpi) / dpih, 1.0f); } if (dpiv > max_dpi) { m_Matrix.Scale(1.0f, (FX_FLOAT)(max_dpi) / (FX_FLOAT)dpiv); } } #endif CFX_Matrix ctm = m_pDevice->GetCTM(); FX_FLOAT fScaleX = FXSYS_fabs(ctm.a); FX_FLOAT fScaleY = FXSYS_fabs(ctm.d); m_Matrix.Concat(fScaleX, 0, 0, fScaleY, 0, 0); CFX_FloatRect rect(*pRect); m_Matrix.TransformRect(rect); FX_RECT bitmap_rect = rect.GetOuterRect(); m_pBitmap.reset(new CFX_DIBitmap); m_pBitmap->Create(bitmap_rect.Width(), bitmap_rect.Height(), FXDIB_Argb); return TRUE; }
int FPDFText_ProcessInterObj(const CPDF_TextObject* pPrevObj, const CPDF_TextObject* pObj) { if(FPDFText_IsSameTextObject(pPrevObj, pObj)) { return -1; } CPDF_TextObjectItem item; int nItem = pPrevObj->CountItems(); pPrevObj->GetItemInfo(nItem - 1, &item); FX_WCHAR preChar = 0, curChar = 0; CFX_WideString wstr = pPrevObj->GetFont()->UnicodeFromCharCode(item.m_CharCode); if(wstr.GetLength()) { preChar = wstr.GetAt(0); } FX_FLOAT last_pos = item.m_OriginX; int nLastWidth = GetCharWidth(item.m_CharCode, pPrevObj->GetFont()); FX_FLOAT last_width = nLastWidth * pPrevObj->GetFontSize() / 1000; last_width = FXSYS_fabs(last_width); pObj->GetItemInfo(0, &item); wstr = pObj->GetFont()->UnicodeFromCharCode(item.m_CharCode); if(wstr.GetLength()) { curChar = wstr.GetAt(0); } int nThisWidth = GetCharWidth(item.m_CharCode, pObj->GetFont()); FX_FLOAT this_width = nThisWidth * pObj->GetFontSize() / 1000; this_width = FXSYS_fabs(this_width); FX_FLOAT threshold = last_width > this_width ? last_width / 4 : this_width / 4; CFX_AffineMatrix prev_matrix, prev_reverse; pPrevObj->GetTextMatrix(&prev_matrix); prev_reverse.SetReverse(prev_matrix); FX_FLOAT x = pObj->GetPosX(), y = pObj->GetPosY(); prev_reverse.Transform(x, y); if (FXSYS_fabs(y) > threshold * 2) { return 2; } threshold = (FX_FLOAT)(nLastWidth > nThisWidth ? nLastWidth : nThisWidth); threshold = threshold > 400 ? (threshold < 700 ? threshold / 4 : threshold / 5) : (threshold / 2); threshold *= nLastWidth > nThisWidth ? FXSYS_fabs(pPrevObj->GetFontSize()) : FXSYS_fabs(pObj->GetFontSize()); threshold /= 1000; if (FXSYS_fabs(last_pos + last_width - x) > threshold && curChar != L' ' && preChar != L' ') if(curChar != L' ' && preChar != L' ') { if((x - last_pos - last_width) > threshold || (last_pos - x - last_width) > threshold) { return 1; } if(x < 0 && (last_pos - x - last_width) > threshold) { return 1; } if((x - last_pos - last_width) > this_width || (x - last_pos - this_width) > last_width ) { return 1; } } if(last_pos + last_width > x + this_width && curChar == L' ') { return 3; } return 0; }
static int _AdjustBlue(FX_FLOAT pos, int& count, int blues[]) { FX_FLOAT min_distance = 1000000.0f * 1.0f; int closest_pos = -1; for (int i = 0; i < count; i++) { FX_FLOAT distance = (FX_FLOAT)FXSYS_fabs(pos - (FX_FLOAT)blues[i]); if (distance < 1.0f * 80.0f / 100.0f && distance < min_distance) { min_distance = distance; closest_pos = i; } } if (closest_pos >= 0) { return blues[closest_pos]; } int new_pos = FXSYS_round(pos); if (count == TYPE3_MAX_BLUES) { return new_pos; } blues[count++] = new_pos; return new_pos; }
FX_BOOL FPDFText_IsSameTextObject(const CPDF_TextObject* pTextObj1, const CPDF_TextObject* pTextObj2) { if (!pTextObj1 || !pTextObj2) { return FALSE; } CFX_FloatRect rcPreObj(pTextObj2->m_Left, pTextObj2->m_Bottom, pTextObj2->m_Right, pTextObj2->m_Top); CFX_FloatRect rcCurObj(pTextObj1->m_Left, pTextObj1->m_Bottom, pTextObj1->m_Right, pTextObj1->m_Top); if (rcPreObj.IsEmpty() && rcCurObj.IsEmpty()) { return TRUE; } if (!rcPreObj.IsEmpty() || !rcCurObj.IsEmpty()) { rcPreObj.Intersect(rcCurObj); if (rcPreObj.IsEmpty()) { return FALSE; } if (FXSYS_fabs(rcPreObj.Width() - rcCurObj.Width()) > rcCurObj.Width() / 2) { return FALSE; } if (pTextObj2->GetFontSize() != pTextObj1->GetFontSize()) { return FALSE; } } int nPreCount = pTextObj2->CountItems(); int nCurCount = pTextObj1->CountItems(); if (nPreCount != nCurCount) { return FALSE; } for (int i = 0; i < nPreCount; i++) { CPDF_TextObjectItem itemPer, itemCur; pTextObj2->GetItemInfo(i, &itemPer); pTextObj1->GetItemInfo(i, &itemCur); if (itemCur.m_CharCode != itemPer.m_CharCode) { return FALSE; } } return TRUE; }