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); }
static void DrawAxialShading(CFX_DIBitmap* pBitmap, CFX_AffineMatrix* pObject2Bitmap, CPDF_Dictionary* pDict, CPDF_Function** pFuncs, int nFuncs, CPDF_ColorSpace* pCS, int alpha) { ASSERT(pBitmap->GetFormat() == FXDIB_Argb); CPDF_Array* pCoords = pDict->GetArray(FX_BSTRC("Coords")); if (pCoords == NULL) { return; } FX_FLOAT start_x = pCoords->GetNumber(0); FX_FLOAT start_y = pCoords->GetNumber(1); FX_FLOAT end_x = pCoords->GetNumber(2); FX_FLOAT end_y = pCoords->GetNumber(3); FX_FLOAT t_min = 0, t_max = 1.0f; CPDF_Array* pArray = pDict->GetArray(FX_BSTRC("Domain")); if (pArray) { t_min = pArray->GetNumber(0); t_max = pArray->GetNumber(1); } FX_BOOL bStartExtend = FALSE, bEndExtend = FALSE; pArray = pDict->GetArray(FX_BSTRC("Extend")); if (pArray) { bStartExtend = pArray->GetInteger(0); bEndExtend = pArray->GetInteger(1); } int width = pBitmap->GetWidth(); int height = pBitmap->GetHeight(); FX_FLOAT x_span = end_x - start_x; FX_FLOAT y_span = end_y - start_y; FX_FLOAT axis_len_square = FXSYS_Mul(x_span, x_span) + FXSYS_Mul(y_span, y_span); CFX_AffineMatrix matrix; matrix.SetReverse(*pObject2Bitmap); int total_results = 0; for (int j = 0; j < nFuncs; j++) { if (pFuncs[j]) { total_results += pFuncs[j]->CountOutputs(); } } if (pCS->CountComponents() > total_results) { total_results = pCS->CountComponents(); } CFX_FixedBufGrow<FX_FLOAT, 16> result_array(total_results); FX_FLOAT* pResults = result_array; FXSYS_memset(pResults, 0, total_results * sizeof(FX_FLOAT)); FX_DWORD rgb_array[SHADING_STEPS]; for (int i = 0; i < SHADING_STEPS; i++) { FX_FLOAT input = (t_max - t_min) * i / SHADING_STEPS + t_min; int offset = 0; for (int j = 0; j < nFuncs; j++) { if (pFuncs[j]) { int nresults = 0; if (pFuncs[j]->Call(&input, 1, pResults + offset, nresults)) { offset += nresults; } } } FX_FLOAT R = 0.0f, G = 0.0f, B = 0.0f; pCS->GetRGB(pResults, R, G, B); rgb_array[i] = FXARGB_TODIB(FXARGB_MAKE(alpha, FXSYS_round(R * 255), FXSYS_round(G * 255), FXSYS_round(B * 255))); } int pitch = pBitmap->GetPitch(); for (int row = 0; row < height; row++) { FX_DWORD* dib_buf = (FX_DWORD*)(pBitmap->GetBuffer() + row * pitch); for (int column = 0; column < width; column++) { FX_FLOAT x = (FX_FLOAT)column, y = (FX_FLOAT)row; matrix.Transform(x, y); FX_FLOAT scale = FXSYS_Div( FXSYS_Mul(x - start_x, x_span) + FXSYS_Mul(y - start_y, y_span), axis_len_square); int index = (int32_t)(scale * (SHADING_STEPS - 1)); if (index < 0) { if (!bStartExtend) { continue; } index = 0; } else if (index >= SHADING_STEPS) { if (!bEndExtend) { continue; } index = SHADING_STEPS - 1; } dib_buf[column] = rgb_array[index]; } } }
static void DrawRadialShading(CFX_DIBitmap* pBitmap, CFX_AffineMatrix* pObject2Bitmap, CPDF_Dictionary* pDict, CPDF_Function** pFuncs, int nFuncs, CPDF_ColorSpace* pCS, int alpha) { ASSERT(pBitmap->GetFormat() == FXDIB_Argb); CPDF_Array* pCoords = pDict->GetArray(FX_BSTRC("Coords")); if (pCoords == NULL) { return; } FX_FLOAT start_x = pCoords->GetNumber(0); FX_FLOAT start_y = pCoords->GetNumber(1); FX_FLOAT start_r = pCoords->GetNumber(2); FX_FLOAT end_x = pCoords->GetNumber(3); FX_FLOAT end_y = pCoords->GetNumber(4); FX_FLOAT end_r = pCoords->GetNumber(5); CFX_AffineMatrix matrix; matrix.SetReverse(*pObject2Bitmap); FX_FLOAT t_min = 0, t_max = 1.0f; CPDF_Array* pArray = pDict->GetArray(FX_BSTRC("Domain")); if (pArray) { t_min = pArray->GetNumber(0); t_max = pArray->GetNumber(1); } FX_BOOL bStartExtend = FALSE, bEndExtend = FALSE; pArray = pDict->GetArray(FX_BSTRC("Extend")); if (pArray) { bStartExtend = pArray->GetInteger(0); bEndExtend = pArray->GetInteger(1); } int total_results = 0; for (int j = 0; j < nFuncs; j++) { if (pFuncs[j]) { total_results += pFuncs[j]->CountOutputs(); } } if (pCS->CountComponents() > total_results) { total_results = pCS->CountComponents(); } CFX_FixedBufGrow<FX_FLOAT, 16> result_array(total_results); FX_FLOAT* pResults = result_array; FXSYS_memset(pResults, 0, total_results * sizeof(FX_FLOAT)); FX_DWORD rgb_array[SHADING_STEPS]; for (int i = 0; i < SHADING_STEPS; i++) { FX_FLOAT input = (t_max - t_min) * i / SHADING_STEPS + t_min; int offset = 0; for (int j = 0; j < nFuncs; j++) { if (pFuncs[j]) { int nresults; if (pFuncs[j]->Call(&input, 1, pResults + offset, nresults)) { offset += nresults; } } } FX_FLOAT R = 0.0f, G = 0.0f, B = 0.0f; pCS->GetRGB(pResults, R, G, B); rgb_array[i] = FXARGB_TODIB(FXARGB_MAKE(alpha, FXSYS_round(R * 255), FXSYS_round(G * 255), FXSYS_round(B * 255))); } FX_FLOAT a = FXSYS_Mul(start_x - end_x, start_x - end_x) + FXSYS_Mul(start_y - end_y, start_y - end_y) - FXSYS_Mul(start_r - end_r, start_r - end_r); int width = pBitmap->GetWidth(); int height = pBitmap->GetHeight(); int pitch = pBitmap->GetPitch(); FX_BOOL bDecreasing = FALSE; if (start_r > end_r) { int length = (int)FXSYS_sqrt((FXSYS_Mul(start_x - end_x, start_x - end_x) + FXSYS_Mul(start_y - end_y, start_y - end_y))); if (length < start_r - end_r) { bDecreasing = TRUE; } } for (int row = 0; row < height; row++) { FX_DWORD* dib_buf = (FX_DWORD*)(pBitmap->GetBuffer() + row * pitch); for (int column = 0; column < width; column++) { FX_FLOAT x = (FX_FLOAT)column, y = (FX_FLOAT)row; matrix.Transform(x, y); FX_FLOAT b = -2 * (FXSYS_Mul(x - start_x, end_x - start_x) + FXSYS_Mul(y - start_y, end_y - start_y) + FXSYS_Mul(start_r, end_r - start_r)); FX_FLOAT c = FXSYS_Mul(x - start_x, x - start_x) + FXSYS_Mul(y - start_y, y - start_y) - FXSYS_Mul(start_r, start_r); FX_FLOAT s; if (a == 0) { s = FXSYS_Div(-c, b); } else { FX_FLOAT b2_4ac = FXSYS_Mul(b, b) - 4 * FXSYS_Mul(a, c); if (b2_4ac < 0) { continue; } FX_FLOAT root = FXSYS_sqrt(b2_4ac); FX_FLOAT s1, s2; if (a > 0) { s1 = FXSYS_Div(-b - root, 2 * a); s2 = FXSYS_Div(-b + root, 2 * a); } else { s2 = FXSYS_Div(-b - root, 2 * a); s1 = FXSYS_Div(-b + root, 2 * a); } if (bDecreasing) { if (s1 >= 0 || bStartExtend) { s = s1; } else { s = s2; } } else { if (s2 <= 1.0f || bEndExtend) { s = s2; } else { s = s1; } } if ((start_r + s * (end_r - start_r)) < 0) { continue; } } int index = (int32_t)(s * (SHADING_STEPS - 1)); if (index < 0) { if (!bStartExtend) { continue; } index = 0; } if (index >= SHADING_STEPS) { if (!bEndExtend) { continue; } index = SHADING_STEPS - 1; } dib_buf[column] = rgb_array[index]; } } }