OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "xfa/fxgraphics/include/cfx_graphics.h" | 7 #include "xfa/fxgraphics/include/cfx_graphics.h" |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 941 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
952 return RenderDeviceShowText(point, text, matrix); | 952 return RenderDeviceShowText(point, text, matrix); |
953 return FX_ERR_Property_Invalid; | 953 return FX_ERR_Property_Invalid; |
954 } | 954 } |
955 | 955 |
956 FX_ERR CFX_Graphics::CalcTextRect(CFX_RectF& rect, | 956 FX_ERR CFX_Graphics::CalcTextRect(CFX_RectF& rect, |
957 const CFX_WideString& text, | 957 const CFX_WideString& text, |
958 FX_BOOL isMultiline, | 958 FX_BOOL isMultiline, |
959 CFX_Matrix* matrix) { | 959 CFX_Matrix* matrix) { |
960 if (m_type == FX_CONTEXT_Device && m_renderDevice) { | 960 if (m_type == FX_CONTEXT_Device && m_renderDevice) { |
961 int32_t length = text.GetLength(); | 961 int32_t length = text.GetLength(); |
962 FX_DWORD* charCodes = FX_Alloc(FX_DWORD, length); | 962 uint32_t* charCodes = FX_Alloc(uint32_t, length); |
963 FXTEXT_CHARPOS* charPos = FX_Alloc(FXTEXT_CHARPOS, length); | 963 FXTEXT_CHARPOS* charPos = FX_Alloc(FXTEXT_CHARPOS, length); |
964 CalcTextInfo(text, charCodes, charPos, rect); | 964 CalcTextInfo(text, charCodes, charPos, rect); |
965 FX_Free(charPos); | 965 FX_Free(charPos); |
966 FX_Free(charCodes); | 966 FX_Free(charCodes); |
967 return FX_ERR_Succeeded; | 967 return FX_ERR_Succeeded; |
968 } | 968 } |
969 return FX_ERR_Property_Invalid; | 969 return FX_ERR_Property_Invalid; |
970 } | 970 } |
971 | 971 |
972 FX_ERR CFX_Graphics::Transfer(CFX_Graphics* graphics, | 972 FX_ERR CFX_Graphics::Transfer(CFX_Graphics* graphics, |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1275 FXSYS_round(r.top - top))) { | 1275 FXSYS_round(r.top - top))) { |
1276 return FX_ERR_Succeeded; | 1276 return FX_ERR_Succeeded; |
1277 } | 1277 } |
1278 return FX_ERR_Indefinite; | 1278 return FX_ERR_Indefinite; |
1279 } | 1279 } |
1280 | 1280 |
1281 FX_ERR CFX_Graphics::RenderDeviceShowText(const CFX_PointF& point, | 1281 FX_ERR CFX_Graphics::RenderDeviceShowText(const CFX_PointF& point, |
1282 const CFX_WideString& text, | 1282 const CFX_WideString& text, |
1283 CFX_Matrix* matrix) { | 1283 CFX_Matrix* matrix) { |
1284 int32_t length = text.GetLength(); | 1284 int32_t length = text.GetLength(); |
1285 FX_DWORD* charCodes = FX_Alloc(FX_DWORD, length); | 1285 uint32_t* charCodes = FX_Alloc(uint32_t, length); |
1286 FXTEXT_CHARPOS* charPos = FX_Alloc(FXTEXT_CHARPOS, length); | 1286 FXTEXT_CHARPOS* charPos = FX_Alloc(FXTEXT_CHARPOS, length); |
1287 CFX_RectF rect; | 1287 CFX_RectF rect; |
1288 rect.Set(point.x, point.y, 0, 0); | 1288 rect.Set(point.x, point.y, 0, 0); |
1289 CalcTextInfo(text, charCodes, charPos, rect); | 1289 CalcTextInfo(text, charCodes, charPos, rect); |
1290 CFX_Matrix m; | 1290 CFX_Matrix m; |
1291 m.Set(m_info.CTM.a, m_info.CTM.b, m_info.CTM.c, m_info.CTM.d, m_info.CTM.e, | 1291 m.Set(m_info.CTM.a, m_info.CTM.b, m_info.CTM.c, m_info.CTM.d, m_info.CTM.e, |
1292 m_info.CTM.f); | 1292 m_info.CTM.f); |
1293 m.Translate(0, m_info.fontSize * m_info.fontHScale); | 1293 m.Translate(0, m_info.fontSize * m_info.fontHScale); |
1294 if (matrix) { | 1294 if (matrix) { |
1295 m.Concat(*matrix); | 1295 m.Concat(*matrix); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1371 bmp.Create(width, height, FXDIB_Argb); | 1371 bmp.Create(width, height, FXDIB_Argb); |
1372 m_renderDevice->GetDIBits(&bmp, 0, 0); | 1372 m_renderDevice->GetDIBits(&bmp, 0, 0); |
1373 int32_t pitch = bmp.GetPitch(); | 1373 int32_t pitch = bmp.GetPitch(); |
1374 FX_BOOL result = FALSE; | 1374 FX_BOOL result = FALSE; |
1375 switch (m_info.fillColor->m_shading->m_type) { | 1375 switch (m_info.fillColor->m_shading->m_type) { |
1376 case FX_SHADING_Axial: { | 1376 case FX_SHADING_Axial: { |
1377 FX_FLOAT x_span = end_x - start_x; | 1377 FX_FLOAT x_span = end_x - start_x; |
1378 FX_FLOAT y_span = end_y - start_y; | 1378 FX_FLOAT y_span = end_y - start_y; |
1379 FX_FLOAT axis_len_square = (x_span * x_span) + (y_span * y_span); | 1379 FX_FLOAT axis_len_square = (x_span * x_span) + (y_span * y_span); |
1380 for (int32_t row = 0; row < height; row++) { | 1380 for (int32_t row = 0; row < height; row++) { |
1381 FX_DWORD* dib_buf = (FX_DWORD*)(bmp.GetBuffer() + row * pitch); | 1381 uint32_t* dib_buf = (uint32_t*)(bmp.GetBuffer() + row * pitch); |
1382 for (int32_t column = 0; column < width; column++) { | 1382 for (int32_t column = 0; column < width; column++) { |
1383 FX_FLOAT x = (FX_FLOAT)(column); | 1383 FX_FLOAT x = (FX_FLOAT)(column); |
1384 FX_FLOAT y = (FX_FLOAT)(row); | 1384 FX_FLOAT y = (FX_FLOAT)(row); |
1385 FX_FLOAT scale = | 1385 FX_FLOAT scale = |
1386 (((x - start_x) * x_span) + ((y - start_y) * y_span)) / | 1386 (((x - start_x) * x_span) + ((y - start_y) * y_span)) / |
1387 axis_len_square; | 1387 axis_len_square; |
1388 if (scale < 0) { | 1388 if (scale < 0) { |
1389 if (!m_info.fillColor->m_shading->m_isExtendedBegin) { | 1389 if (!m_info.fillColor->m_shading->m_isExtendedBegin) { |
1390 continue; | 1390 continue; |
1391 } | 1391 } |
(...skipping 11 matching lines...) Expand all Loading... |
1403 result = TRUE; | 1403 result = TRUE; |
1404 break; | 1404 break; |
1405 } | 1405 } |
1406 case FX_SHADING_Radial: { | 1406 case FX_SHADING_Radial: { |
1407 FX_FLOAT start_r = m_info.fillColor->m_shading->m_beginRadius; | 1407 FX_FLOAT start_r = m_info.fillColor->m_shading->m_beginRadius; |
1408 FX_FLOAT end_r = m_info.fillColor->m_shading->m_endRadius; | 1408 FX_FLOAT end_r = m_info.fillColor->m_shading->m_endRadius; |
1409 FX_FLOAT a = ((start_x - end_x) * (start_x - end_x)) + | 1409 FX_FLOAT a = ((start_x - end_x) * (start_x - end_x)) + |
1410 ((start_y - end_y) * (start_y - end_y)) - | 1410 ((start_y - end_y) * (start_y - end_y)) - |
1411 ((start_r - end_r) * (start_r - end_r)); | 1411 ((start_r - end_r) * (start_r - end_r)); |
1412 for (int32_t row = 0; row < height; row++) { | 1412 for (int32_t row = 0; row < height; row++) { |
1413 FX_DWORD* dib_buf = (FX_DWORD*)(bmp.GetBuffer() + row * pitch); | 1413 uint32_t* dib_buf = (uint32_t*)(bmp.GetBuffer() + row * pitch); |
1414 for (int32_t column = 0; column < width; column++) { | 1414 for (int32_t column = 0; column < width; column++) { |
1415 FX_FLOAT x = (FX_FLOAT)(column); | 1415 FX_FLOAT x = (FX_FLOAT)(column); |
1416 FX_FLOAT y = (FX_FLOAT)(row); | 1416 FX_FLOAT y = (FX_FLOAT)(row); |
1417 FX_FLOAT b = -2 * (((x - start_x) * (end_x - start_x)) + | 1417 FX_FLOAT b = -2 * (((x - start_x) * (end_x - start_x)) + |
1418 ((y - start_y) * (end_y - start_y)) + | 1418 ((y - start_y) * (end_y - start_y)) + |
1419 (start_r * (end_r - start_r))); | 1419 (start_r * (end_r - start_r))); |
1420 FX_FLOAT c = ((x - start_x) * (x - start_x)) + | 1420 FX_FLOAT c = ((x - start_x) * (x - start_x)) + |
1421 ((y - start_y) * (y - start_y)) - (start_r * start_r); | 1421 ((y - start_y) * (y - start_y)) - (start_r * start_r); |
1422 FX_FLOAT s; | 1422 FX_FLOAT s; |
1423 if (a == 0) { | 1423 if (a == 0) { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1488 int32_t left, top; | 1488 int32_t left, top; |
1489 std::unique_ptr<CFX_DIBitmap> bmp1(source->FlipImage(FALSE, TRUE)); | 1489 std::unique_ptr<CFX_DIBitmap> bmp1(source->FlipImage(FALSE, TRUE)); |
1490 std::unique_ptr<CFX_DIBitmap> bmp2( | 1490 std::unique_ptr<CFX_DIBitmap> bmp2( |
1491 bmp1->TransformTo((CFX_Matrix*)&m, left, top)); | 1491 bmp1->TransformTo((CFX_Matrix*)&m, left, top)); |
1492 m_renderDevice->SetDIBits(bmp2.get(), left, top); | 1492 m_renderDevice->SetDIBits(bmp2.get(), left, top); |
1493 } | 1493 } |
1494 return FX_ERR_Succeeded; | 1494 return FX_ERR_Succeeded; |
1495 } | 1495 } |
1496 | 1496 |
1497 FX_ERR CFX_Graphics::CalcTextInfo(const CFX_WideString& text, | 1497 FX_ERR CFX_Graphics::CalcTextInfo(const CFX_WideString& text, |
1498 FX_DWORD* charCodes, | 1498 uint32_t* charCodes, |
1499 FXTEXT_CHARPOS* charPos, | 1499 FXTEXT_CHARPOS* charPos, |
1500 CFX_RectF& rect) { | 1500 CFX_RectF& rect) { |
1501 std::unique_ptr<CFX_UnicodeEncoding> encoding( | 1501 std::unique_ptr<CFX_UnicodeEncoding> encoding( |
1502 new CFX_UnicodeEncoding(m_info.font)); | 1502 new CFX_UnicodeEncoding(m_info.font)); |
1503 int32_t length = text.GetLength(); | 1503 int32_t length = text.GetLength(); |
1504 FX_FLOAT penX = (FX_FLOAT)rect.left; | 1504 FX_FLOAT penX = (FX_FLOAT)rect.left; |
1505 FX_FLOAT penY = (FX_FLOAT)rect.top; | 1505 FX_FLOAT penY = (FX_FLOAT)rect.top; |
1506 FX_FLOAT left = (FX_FLOAT)(0); | 1506 FX_FLOAT left = (FX_FLOAT)(0); |
1507 FX_FLOAT top = (FX_FLOAT)(0); | 1507 FX_FLOAT top = (FX_FLOAT)(0); |
1508 charCodes[0] = text.GetAt(0); | 1508 charCodes[0] = text.GetAt(0); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1559 CTM = other.CTM; | 1559 CTM = other.CTM; |
1560 isActOnDash = other.isActOnDash; | 1560 isActOnDash = other.isActOnDash; |
1561 strokeColor = other.strokeColor; | 1561 strokeColor = other.strokeColor; |
1562 fillColor = other.fillColor; | 1562 fillColor = other.fillColor; |
1563 font = other.font; | 1563 font = other.font; |
1564 fontSize = other.fontSize; | 1564 fontSize = other.fontSize; |
1565 fontHScale = other.fontHScale; | 1565 fontHScale = other.fontHScale; |
1566 fontSpacing = other.fontSpacing; | 1566 fontSpacing = other.fontSpacing; |
1567 return *this; | 1567 return *this; |
1568 } | 1568 } |
OLD | NEW |