Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(942)

Side by Side Diff: core/src/fxge/apple/fx_quartz_device.cpp

Issue 1513363002: Remove CFX_AffineMatrix/CPDF_Matrix (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Nits Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/src/fxge/apple/fx_apple_platform.cpp ('k') | core/src/fxge/dib/dib_int.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "core/include/fxcrt/fx_ext.h" 7 #include "core/include/fxcrt/fx_ext.h"
8 #include "core/include/fxge/fx_freetype.h" 8 #include "core/include/fxge/fx_freetype.h"
9 #include "core/include/fxge/fx_ge.h" 9 #include "core/include/fxge/fx_ge.h"
10 #include "core/src/fxge/agg/include/fx_agg_driver.h" 10 #include "core/src/fxge/agg/include/fx_agg_driver.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 if (NULL == pDataProvider) { 49 if (NULL == pDataProvider) {
50 return NULL; 50 return NULL;
51 } 51 }
52 CGFontRef pCGFont = CGFontCreateWithDataProvider(pDataProvider); 52 CGFontRef pCGFont = CGFontCreateWithDataProvider(pDataProvider);
53 CGDataProviderRelease(pDataProvider); 53 CGDataProviderRelease(pDataProvider);
54 return pCGFont; 54 return pCGFont;
55 } 55 }
56 void CQuartz2D::DestroyFont(void* pFont) { 56 void CQuartz2D::DestroyFont(void* pFont) {
57 CGFontRelease((CGFontRef)pFont); 57 CGFontRelease((CGFontRef)pFont);
58 } 58 }
59 void CQuartz2D::setGraphicsTextMatrix(void* graphics, 59 void CQuartz2D::setGraphicsTextMatrix(void* graphics, CFX_Matrix* matrix) {
60 CFX_AffineMatrix* matrix) {
61 if (!graphics || !matrix) { 60 if (!graphics || !matrix) {
62 return; 61 return;
63 } 62 }
64 CGContextRef context = (CGContextRef)graphics; 63 CGContextRef context = (CGContextRef)graphics;
65 CGFloat ty = CGBitmapContextGetHeight(context) - matrix->f; 64 CGFloat ty = CGBitmapContextGetHeight(context) - matrix->f;
66 CGContextSetTextMatrix( 65 CGContextSetTextMatrix(
67 context, CGAffineTransformMake(matrix->a, matrix->b, matrix->c, matrix->d, 66 context, CGAffineTransformMake(matrix->a, matrix->b, matrix->c, matrix->d,
68 matrix->e, ty)); 67 matrix->e, ty));
69 } 68 }
70 FX_BOOL CQuartz2D::drawGraphicsString(void* graphics, 69 FX_BOOL CQuartz2D::drawGraphicsString(void* graphics,
71 void* font, 70 void* font,
72 FX_FLOAT fontSize, 71 FX_FLOAT fontSize,
73 FX_WORD* glyphIndices, 72 FX_WORD* glyphIndices,
74 CGPoint* glyphPositions, 73 CGPoint* glyphPositions,
75 int32_t charsCount, 74 int32_t charsCount,
76 FX_ARGB argb, 75 FX_ARGB argb,
77 CFX_AffineMatrix* matrix) { 76 CFX_Matrix* matrix) {
78 if (!graphics) { 77 if (!graphics) {
79 return FALSE; 78 return FALSE;
80 } 79 }
81 CGContextRef context = (CGContextRef)graphics; 80 CGContextRef context = (CGContextRef)graphics;
82 CGContextSetFont(context, (CGFontRef)font); 81 CGContextSetFont(context, (CGFontRef)font);
83 CGContextSetFontSize(context, fontSize); 82 CGContextSetFontSize(context, fontSize);
84 if (matrix) { 83 if (matrix) {
85 CGAffineTransform m = CGContextGetTextMatrix(context); 84 CGAffineTransform m = CGContextGetTextMatrix(context);
86 m = CGAffineTransformConcat( 85 m = CGAffineTransformConcat(
87 m, CGAffineTransformMake(matrix->a, matrix->b, matrix->c, matrix->d, 86 m, CGAffineTransformMake(matrix->a, matrix->b, matrix->c, matrix->d,
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 } 216 }
218 void CFX_QuartzDeviceDriver::RestoreState(FX_BOOL isKeepSaved) { 217 void CFX_QuartzDeviceDriver::RestoreState(FX_BOOL isKeepSaved) {
219 CGContextRestoreGState(_context); 218 CGContextRestoreGState(_context);
220 if (isKeepSaved) { 219 if (isKeepSaved) {
221 CGContextSaveGState(_context); 220 CGContextSaveGState(_context);
222 } else { 221 } else {
223 m_saveCount--; 222 m_saveCount--;
224 } 223 }
225 } 224 }
226 FX_BOOL CFX_QuartzDeviceDriver::SetClip_PathFill(const CFX_PathData* pathData, 225 FX_BOOL CFX_QuartzDeviceDriver::SetClip_PathFill(const CFX_PathData* pathData,
227 const CFX_AffineMatrix* matrix, 226 const CFX_Matrix* matrix,
228 int fillMode) { 227 int fillMode) {
229 SaveState(); 228 SaveState();
230 CGAffineTransform m = CGAffineTransformIdentity; 229 CGAffineTransform m = CGAffineTransformIdentity;
231 if (matrix) { 230 if (matrix) {
232 m = CGAffineTransformMake(matrix->GetA(), matrix->GetB(), matrix->GetC(), 231 m = CGAffineTransformMake(matrix->GetA(), matrix->GetB(), matrix->GetC(),
233 matrix->GetD(), matrix->GetE(), matrix->GetF()); 232 matrix->GetD(), matrix->GetE(), matrix->GetF());
234 } 233 }
235 m = CGAffineTransformConcat(m, _foxitDevice2User); 234 m = CGAffineTransformConcat(m, _foxitDevice2User);
236 CGContextConcatCTM(_context, m); 235 CGContextConcatCTM(_context, m);
237 setPathToContext(pathData); 236 setPathToContext(pathData);
(...skipping 15 matching lines...) Expand all
253 size.height = 1; 252 size.height = 1;
254 CGSize temp = CGSizeApplyAffineTransform(size, ctm); 253 CGSize temp = CGSizeApplyAffineTransform(size, ctm);
255 CGFloat x = 1 / temp.width; 254 CGFloat x = 1 / temp.width;
256 CGFloat y = 1 / temp.height; 255 CGFloat y = 1 / temp.height;
257 lineWidth = x > y ? x : y; 256 lineWidth = x > y ? x : y;
258 } 257 }
259 return lineWidth; 258 return lineWidth;
260 } 259 }
261 FX_BOOL CFX_QuartzDeviceDriver::SetClip_PathStroke( 260 FX_BOOL CFX_QuartzDeviceDriver::SetClip_PathStroke(
262 const CFX_PathData* pathData, 261 const CFX_PathData* pathData,
263 const CFX_AffineMatrix* matrix, 262 const CFX_Matrix* matrix,
264 const CFX_GraphStateData* graphState) { 263 const CFX_GraphStateData* graphState) {
265 SaveState(); 264 SaveState();
266 CGAffineTransform m = CGAffineTransformIdentity; 265 CGAffineTransform m = CGAffineTransformIdentity;
267 if (matrix) { 266 if (matrix) {
268 m = CGAffineTransformMake(matrix->GetA(), matrix->GetB(), matrix->GetC(), 267 m = CGAffineTransformMake(matrix->GetA(), matrix->GetB(), matrix->GetC(),
269 matrix->GetD(), matrix->GetE(), matrix->GetF()); 268 matrix->GetD(), matrix->GetE(), matrix->GetF());
270 } 269 }
271 m = CGAffineTransformConcat(m, _foxitDevice2User); 270 m = CGAffineTransformConcat(m, _foxitDevice2User);
272 CGContextConcatCTM(_context, m); 271 CGContextConcatCTM(_context, m);
273 FX_FLOAT lineWidth = getLineWidth(graphState, m); 272 FX_FLOAT lineWidth = getLineWidth(graphState, m);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 case FXDIB_BLEND_LUMINOSITY: 328 case FXDIB_BLEND_LUMINOSITY:
330 mode = kCGBlendModeLuminosity; 329 mode = kCGBlendModeLuminosity;
331 break; 330 break;
332 default: 331 default:
333 mode = kCGBlendModeNormal; 332 mode = kCGBlendModeNormal;
334 break; 333 break;
335 } 334 }
336 return mode; 335 return mode;
337 } 336 }
338 FX_BOOL CFX_QuartzDeviceDriver::DrawPath(const CFX_PathData* pathData, 337 FX_BOOL CFX_QuartzDeviceDriver::DrawPath(const CFX_PathData* pathData,
339 const CFX_AffineMatrix* matrix, 338 const CFX_Matrix* matrix,
340 const CFX_GraphStateData* graphState, 339 const CFX_GraphStateData* graphState,
341 FX_DWORD fillArgb, 340 FX_DWORD fillArgb,
342 FX_DWORD strokeArgb, 341 FX_DWORD strokeArgb,
343 int fillMode, 342 int fillMode,
344 int alpha_flag, 343 int alpha_flag,
345 void* pIccTransform, 344 void* pIccTransform,
346 int blend_type) { 345 int blend_type) {
347 SaveState(); 346 SaveState();
348 CGBlendMode mode = GetCGBlendMode(blend_type); 347 CGBlendMode mode = GetCGBlendMode(blend_type);
349 if (mode != kCGBlendModeNormal) { 348 if (mode != kCGBlendModeNormal) {
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 CGImageRef image = CGBitmapContextCreateImage(ctx); 728 CGImageRef image = CGBitmapContextCreateImage(ctx);
730 CGContextDrawImage(_context, rect, image); 729 CGContextDrawImage(_context, rect, image);
731 CGImageRelease(image); 730 CGImageRelease(image);
732 CGContextRelease(ctx); 731 CGContextRelease(ctx);
733 if (pBitmap1 != pBitmap) { 732 if (pBitmap1 != pBitmap) {
734 delete pBitmap1; 733 delete pBitmap1;
735 } 734 }
736 RestoreState(FALSE); 735 RestoreState(FALSE);
737 return TRUE; 736 return TRUE;
738 } 737 }
739 FX_BOOL CFX_QuartzDeviceDriver::CG_DrawGlypRun( 738 FX_BOOL CFX_QuartzDeviceDriver::CG_DrawGlypRun(int nChars,
740 int nChars, 739 const FXTEXT_CHARPOS* pCharPos,
741 const FXTEXT_CHARPOS* pCharPos, 740 CFX_Font* pFont,
742 CFX_Font* pFont, 741 CFX_FontCache* pCache,
743 CFX_FontCache* pCache, 742 const CFX_Matrix* pGlyphMatrix,
744 const CFX_AffineMatrix* pGlyphMatrix, 743 const CFX_Matrix* pObject2Device,
745 const CFX_AffineMatrix* pObject2Device, 744 FX_FLOAT font_size,
746 FX_FLOAT font_size, 745 FX_DWORD argb,
747 FX_DWORD argb, 746 int alpha_flag,
748 int alpha_flag, 747 void* pIccTransform) {
749 void* pIccTransform) {
750 if (nChars == 0) { 748 if (nChars == 0) {
751 return TRUE; 749 return TRUE;
752 } 750 }
753 CQuartz2D& quartz2d = 751 CQuartz2D& quartz2d =
754 ((CApplePlatform*)CFX_GEModule::Get()->GetPlatformData())->_quartz2d; 752 ((CApplePlatform*)CFX_GEModule::Get()->GetPlatformData())->_quartz2d;
755 if (!pFont->GetPlatformFont()) { 753 if (!pFont->GetPlatformFont()) {
756 if (pFont->GetPsName() == CFX_WideString::FromLocal("DFHeiStd-W5")) { 754 if (pFont->GetPsName() == CFX_WideString::FromLocal("DFHeiStd-W5")) {
757 return FALSE; 755 return FALSE;
758 } 756 }
759 pFont->SetPlatformFont( 757 pFont->SetPlatformFont(
760 quartz2d.CreateFont(pFont->GetFontData(), pFont->GetSize())); 758 quartz2d.CreateFont(pFont->GetFontData(), pFont->GetSize()));
761 if (!pFont->GetPlatformFont()) { 759 if (!pFont->GetPlatformFont()) {
762 return FALSE; 760 return FALSE;
763 } 761 }
764 } 762 }
765 CFX_FixedBufGrow<FX_WORD, 32> glyph_indices(nChars); 763 CFX_FixedBufGrow<FX_WORD, 32> glyph_indices(nChars);
766 CFX_FixedBufGrow<CGPoint, 32> glyph_positions(nChars); 764 CFX_FixedBufGrow<CGPoint, 32> glyph_positions(nChars);
767 for (int i = 0; i < nChars; i++) { 765 for (int i = 0; i < nChars; i++) {
768 glyph_indices[i] = pCharPos[i].m_ExtGID; 766 glyph_indices[i] = pCharPos[i].m_ExtGID;
769 glyph_positions[i].x = pCharPos[i].m_OriginX; 767 glyph_positions[i].x = pCharPos[i].m_OriginX;
770 glyph_positions[i].y = pCharPos[i].m_OriginY; 768 glyph_positions[i].y = pCharPos[i].m_OriginY;
771 } 769 }
772 CFX_AffineMatrix text_matrix; 770 CFX_Matrix text_matrix;
773 if (pObject2Device) { 771 if (pObject2Device) {
774 text_matrix.Concat(*pObject2Device); 772 text_matrix.Concat(*pObject2Device);
775 } 773 }
776 CGAffineTransform matrix_cg = 774 CGAffineTransform matrix_cg =
777 CGAffineTransformMake(text_matrix.a, text_matrix.b, text_matrix.c, 775 CGAffineTransformMake(text_matrix.a, text_matrix.b, text_matrix.c,
778 text_matrix.d, text_matrix.e, text_matrix.f); 776 text_matrix.d, text_matrix.e, text_matrix.f);
779 matrix_cg = CGAffineTransformConcat(matrix_cg, _foxitDevice2User); 777 matrix_cg = CGAffineTransformConcat(matrix_cg, _foxitDevice2User);
780 CGContextSetTextMatrix(_context, matrix_cg); 778 CGContextSetTextMatrix(_context, matrix_cg);
781 CGContextSetFont(_context, (CGFontRef)pFont->GetPlatformFont()); 779 CGContextSetFont(_context, (CGFontRef)pFont->GetPlatformFont());
782 CGContextSetFontSize(_context, FXSYS_fabs(font_size)); 780 CGContextSetFontSize(_context, FXSYS_fabs(font_size));
(...skipping 13 matching lines...) Expand all
796 glyph_matrix = CGAffineTransformInvert(glyph_matrix); 794 glyph_matrix = CGAffineTransformInvert(glyph_matrix);
797 } 795 }
798 CGContextConcatCTM(_context, glyph_matrix); 796 CGContextConcatCTM(_context, glyph_matrix);
799 CGContextTranslateCTM(_context, -origin.x, -origin.y); 797 CGContextTranslateCTM(_context, -origin.x, -origin.y);
800 } 798 }
801 CGContextShowGlyphsAtPositions(_context, (CGGlyph*)glyph_indices, 799 CGContextShowGlyphsAtPositions(_context, (CGGlyph*)glyph_indices,
802 glyph_positions, nChars); 800 glyph_positions, nChars);
803 RestoreState(FALSE); 801 RestoreState(FALSE);
804 return TRUE; 802 return TRUE;
805 } 803 }
806 FX_BOOL CFX_QuartzDeviceDriver::DrawDeviceText( 804 FX_BOOL CFX_QuartzDeviceDriver::DrawDeviceText(int nChars,
807 int nChars, 805 const FXTEXT_CHARPOS* pCharPos,
808 const FXTEXT_CHARPOS* pCharPos, 806 CFX_Font* pFont,
809 CFX_Font* pFont, 807 CFX_FontCache* pCache,
810 CFX_FontCache* pCache, 808 const CFX_Matrix* pObject2Device,
811 const CFX_AffineMatrix* pObject2Device, 809 FX_FLOAT font_size,
812 FX_FLOAT font_size, 810 FX_DWORD color,
813 FX_DWORD color, 811 int alpha_flag,
814 int alpha_flag, 812 void* pIccTransform) {
815 void* pIccTransform) {
816 if (NULL == pFont || NULL == _context) { 813 if (NULL == pFont || NULL == _context) {
817 return FALSE; 814 return FALSE;
818 } 815 }
819 FX_BOOL bBold = pFont->IsBold(); 816 FX_BOOL bBold = pFont->IsBold();
820 if (!bBold && pFont->GetSubstFont() && 817 if (!bBold && pFont->GetSubstFont() &&
821 pFont->GetSubstFont()->m_Weight >= 500 && 818 pFont->GetSubstFont()->m_Weight >= 500 &&
822 pFont->GetSubstFont()->m_Weight <= 600) { 819 pFont->GetSubstFont()->m_Weight <= 600) {
823 return FALSE; 820 return FALSE;
824 } 821 }
825 SaveState(); 822 SaveState();
826 CGContextSetTextDrawingMode(_context, kCGTextFillClip); 823 CGContextSetTextDrawingMode(_context, kCGTextFillClip);
827 FX_BOOL ret = FALSE; 824 FX_BOOL ret = FALSE;
828 int32_t i = 0; 825 int32_t i = 0;
829 while (i < nChars) { 826 while (i < nChars) {
830 if (pCharPos[i].m_bGlyphAdjust || font_size < 0) { 827 if (pCharPos[i].m_bGlyphAdjust || font_size < 0) {
831 if (i > 0) { 828 if (i > 0) {
832 ret = CG_DrawGlypRun(i, pCharPos, pFont, pCache, NULL, pObject2Device, 829 ret = CG_DrawGlypRun(i, pCharPos, pFont, pCache, NULL, pObject2Device,
833 font_size, color, alpha_flag, pIccTransform); 830 font_size, color, alpha_flag, pIccTransform);
834 if (!ret) { 831 if (!ret) {
835 RestoreState(FALSE); 832 RestoreState(FALSE);
836 return ret; 833 return ret;
837 } 834 }
838 } 835 }
839 const FXTEXT_CHARPOS* char_pos = pCharPos + i; 836 const FXTEXT_CHARPOS* char_pos = pCharPos + i;
840 CFX_AffineMatrix glphy_matrix; 837 CFX_Matrix glphy_matrix;
841 if (font_size < 0) { 838 if (font_size < 0) {
842 glphy_matrix.Concat(-1, 0, 0, -1, 0, 0); 839 glphy_matrix.Concat(-1, 0, 0, -1, 0, 0);
843 } 840 }
844 if (char_pos->m_bGlyphAdjust) { 841 if (char_pos->m_bGlyphAdjust) {
845 glphy_matrix.Concat( 842 glphy_matrix.Concat(
846 char_pos->m_AdjustMatrix[0], char_pos->m_AdjustMatrix[1], 843 char_pos->m_AdjustMatrix[0], char_pos->m_AdjustMatrix[1],
847 char_pos->m_AdjustMatrix[2], char_pos->m_AdjustMatrix[3], 0, 0); 844 char_pos->m_AdjustMatrix[2], char_pos->m_AdjustMatrix[3], 0, 0);
848 } 845 }
849 ret = CG_DrawGlypRun(1, char_pos, pFont, pCache, &glphy_matrix, 846 ret = CG_DrawGlypRun(1, char_pos, pFont, pCache, &glphy_matrix,
850 pObject2Device, font_size, color, alpha_flag, 847 pObject2Device, font_size, color, alpha_flag,
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
1042 } 1039 }
1043 CFX_DIBitmap* pBitmap = new CFX_DIBitmap; 1040 CFX_DIBitmap* pBitmap = new CFX_DIBitmap;
1044 if (!pBitmap->Create(width, height, format)) { 1041 if (!pBitmap->Create(width, height, format)) {
1045 delete pBitmap; 1042 delete pBitmap;
1046 return FALSE; 1043 return FALSE;
1047 } 1044 }
1048 m_bOwnedBitmap = TRUE; 1045 m_bOwnedBitmap = TRUE;
1049 return Attach(pBitmap); 1046 return Attach(pBitmap);
1050 } 1047 }
1051 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ 1048 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
OLDNEW
« no previous file with comments | « core/src/fxge/apple/fx_apple_platform.cpp ('k') | core/src/fxge/dib/dib_int.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698