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

Side by Side Diff: core/fpdfapi/fpdf_render/fpdf_render_text.cpp

Issue 1973913002: Clean up CFX_ImageTransformer. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: address comments Created 4 years, 7 months 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/fpdfapi/fpdf_render/fpdf_render_image.cpp ('k') | core/fxge/dib/fx_dib_main.cpp » ('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/fpdfapi/fpdf_render/render_int.h" 7 #include "core/fpdfapi/fpdf_render/render_int.h"
8 8
9 #include "core/fpdfapi/fpdf_font/cpdf_cidfont.h" 9 #include "core/fpdfapi/fpdf_font/cpdf_cidfont.h"
10 #include "core/fpdfapi/fpdf_font/cpdf_type3char.h" 10 #include "core/fpdfapi/fpdf_font/cpdf_type3char.h"
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 } 142 }
143 } else { 143 } else {
144 if (_IsScanLine8bpp(pBuf + line * pitch, width)) { 144 if (_IsScanLine8bpp(pBuf + line * pitch, width)) {
145 return line; 145 return line;
146 } 146 }
147 } 147 }
148 line += line_step; 148 line += line_step;
149 } 149 }
150 return -1; 150 return -1;
151 } 151 }
152
152 CFX_GlyphBitmap* CPDF_Type3Cache::RenderGlyph(CPDF_Type3Glyphs* pSize, 153 CFX_GlyphBitmap* CPDF_Type3Cache::RenderGlyph(CPDF_Type3Glyphs* pSize,
153 uint32_t charcode, 154 uint32_t charcode,
154 const CFX_Matrix* pMatrix, 155 const CFX_Matrix* pMatrix,
155 FX_FLOAT retinaScaleX, 156 FX_FLOAT retinaScaleX,
156 FX_FLOAT retinaScaleY) { 157 FX_FLOAT retinaScaleY) {
157 const CPDF_Type3Char* pChar = m_pFont->LoadChar(charcode); 158 const CPDF_Type3Char* pChar = m_pFont->LoadChar(charcode);
158 if (!pChar || !pChar->m_pBitmap) 159 if (!pChar || !pChar->m_pBitmap)
159 return nullptr; 160 return nullptr;
160 161
161 CFX_DIBitmap* pBitmap = pChar->m_pBitmap; 162 CFX_DIBitmap* pBitmap = pChar->m_pBitmap.get();
162 CFX_Matrix image_matrix, text_matrix; 163 CFX_Matrix image_matrix, text_matrix;
163 image_matrix = pChar->m_ImageMatrix; 164 image_matrix = pChar->m_ImageMatrix;
164 text_matrix.Set(pMatrix->a, pMatrix->b, pMatrix->c, pMatrix->d, 0, 0); 165 text_matrix.Set(pMatrix->a, pMatrix->b, pMatrix->c, pMatrix->d, 0, 0);
165 image_matrix.Concat(text_matrix); 166 image_matrix.Concat(text_matrix);
166 CFX_DIBitmap* pResBitmap = NULL; 167 std::unique_ptr<CFX_DIBitmap> pResBitmap;
167 int left = 0; 168 int left = 0;
168 int top = 0; 169 int top = 0;
169 if (FXSYS_fabs(image_matrix.b) < FXSYS_fabs(image_matrix.a) / 100 && 170 if (FXSYS_fabs(image_matrix.b) < FXSYS_fabs(image_matrix.a) / 100 &&
170 FXSYS_fabs(image_matrix.c) < FXSYS_fabs(image_matrix.d) / 100) { 171 FXSYS_fabs(image_matrix.c) < FXSYS_fabs(image_matrix.d) / 100) {
171 int top_line = _DetectFirstLastScan(pBitmap, TRUE); 172 int top_line = _DetectFirstLastScan(pBitmap, TRUE);
172 int bottom_line = _DetectFirstLastScan(pBitmap, FALSE); 173 int bottom_line = _DetectFirstLastScan(pBitmap, FALSE);
173 if (top_line == 0 && bottom_line == pBitmap->GetHeight() - 1) { 174 if (top_line == 0 && bottom_line == pBitmap->GetHeight() - 1) {
174 FX_FLOAT top_y = image_matrix.d + image_matrix.f; 175 FX_FLOAT top_y = image_matrix.d + image_matrix.f;
175 FX_FLOAT bottom_y = image_matrix.f; 176 FX_FLOAT bottom_y = image_matrix.f;
176 FX_BOOL bFlipped = top_y > bottom_y; 177 FX_BOOL bFlipped = top_y > bottom_y;
177 if (bFlipped) { 178 if (bFlipped) {
178 FX_FLOAT temp = top_y; 179 FX_FLOAT temp = top_y;
179 top_y = bottom_y; 180 top_y = bottom_y;
180 bottom_y = temp; 181 bottom_y = temp;
181 } 182 }
182 pSize->AdjustBlue(top_y, bottom_y, top_line, bottom_line); 183 pSize->AdjustBlue(top_y, bottom_y, top_line, bottom_line);
183 pResBitmap = pBitmap->StretchTo( 184 pResBitmap.reset(pBitmap->StretchTo(
184 (int)(FXSYS_round(image_matrix.a) * retinaScaleX), 185 (int)(FXSYS_round(image_matrix.a) * retinaScaleX),
185 (int)((bFlipped ? top_line - bottom_line : bottom_line - top_line) * 186 (int)((bFlipped ? top_line - bottom_line : bottom_line - top_line) *
186 retinaScaleY)); 187 retinaScaleY)));
187 top = top_line; 188 top = top_line;
188 if (image_matrix.a < 0) { 189 if (image_matrix.a < 0) {
189 image_matrix.Scale(retinaScaleX, retinaScaleY); 190 image_matrix.Scale(retinaScaleX, retinaScaleY);
190 left = FXSYS_round(image_matrix.e + image_matrix.a); 191 left = FXSYS_round(image_matrix.e + image_matrix.a);
191 } else { 192 } else {
192 left = FXSYS_round(image_matrix.e); 193 left = FXSYS_round(image_matrix.e);
193 } 194 }
194 } 195 }
195 } 196 }
196 if (!pResBitmap) { 197 if (!pResBitmap) {
197 image_matrix.Scale(retinaScaleX, retinaScaleY); 198 image_matrix.Scale(retinaScaleX, retinaScaleY);
198 pResBitmap = pBitmap->TransformTo(&image_matrix, left, top); 199 pResBitmap.reset(pBitmap->TransformTo(&image_matrix, left, top));
199 } 200 }
200 if (!pResBitmap) { 201 if (!pResBitmap)
201 return NULL; 202 return nullptr;
202 } 203
203 CFX_GlyphBitmap* pGlyph = new CFX_GlyphBitmap; 204 CFX_GlyphBitmap* pGlyph = new CFX_GlyphBitmap;
204 pGlyph->m_Left = left; 205 pGlyph->m_Left = left;
205 pGlyph->m_Top = -top; 206 pGlyph->m_Top = -top;
206 pGlyph->m_Bitmap.TakeOver(pResBitmap); 207 pGlyph->m_Bitmap.TakeOver(pResBitmap.get());
207 delete pResBitmap;
208 return pGlyph; 208 return pGlyph;
209 } 209 }
210 210
211 FX_BOOL CPDF_RenderStatus::ProcessText(const CPDF_TextObject* textobj, 211 FX_BOOL CPDF_RenderStatus::ProcessText(const CPDF_TextObject* textobj,
212 const CFX_Matrix* pObj2Device, 212 const CFX_Matrix* pObj2Device,
213 CFX_PathData* pClippingPath) { 213 CFX_PathData* pClippingPath) {
214 if (textobj->m_nChars == 0) { 214 if (textobj->m_nChars == 0) {
215 return TRUE; 215 return TRUE;
216 } 216 }
217 int text_render_mode = textobj->m_TextState.GetObject()->m_TextMode; 217 int text_render_mode = textobj->m_TextState.GetObject()->m_TextMode;
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 } 416 }
417 if (fill_alpha == 255) { 417 if (fill_alpha == 255) {
418 CPDF_RenderStatus status; 418 CPDF_RenderStatus status;
419 status.Initialize(m_pContext, m_pDevice, NULL, NULL, this, pStates, 419 status.Initialize(m_pContext, m_pDevice, NULL, NULL, this, pStates,
420 &Options, pType3Char->m_pForm->m_Transparency, 420 &Options, pType3Char->m_pForm->m_Transparency,
421 m_bDropObjects, pFormResource, FALSE, pType3Char, 421 m_bDropObjects, pFormResource, FALSE, pType3Char,
422 fill_argb); 422 fill_argb);
423 status.m_Type3FontCache.Append(m_Type3FontCache); 423 status.m_Type3FontCache.Append(m_Type3FontCache);
424 status.m_Type3FontCache.Add(pType3Font); 424 status.m_Type3FontCache.Add(pType3Font);
425 m_pDevice->SaveState(); 425 m_pDevice->SaveState();
426 status.RenderObjectList(pType3Char->m_pForm, &matrix); 426 status.RenderObjectList(pType3Char->m_pForm.get(), &matrix);
427 m_pDevice->RestoreState(); 427 m_pDevice->RestoreState();
428 } else { 428 } else {
429 CFX_FloatRect rect_f = pType3Char->m_pForm->CalcBoundingBox(); 429 CFX_FloatRect rect_f = pType3Char->m_pForm->CalcBoundingBox();
430 rect_f.Transform(&matrix); 430 rect_f.Transform(&matrix);
431 FX_RECT rect = rect_f.GetOutterRect(); 431 FX_RECT rect = rect_f.GetOutterRect();
432 CFX_FxgeDevice bitmap_device; 432 CFX_FxgeDevice bitmap_device;
433 if (!bitmap_device.Create((int)(rect.Width() * sa), 433 if (!bitmap_device.Create((int)(rect.Width() * sa),
434 (int)(rect.Height() * sd), FXDIB_Argb)) { 434 (int)(rect.Height() * sd), FXDIB_Argb)) {
435 return TRUE; 435 return TRUE;
436 } 436 }
437 bitmap_device.GetBitmap()->Clear(0); 437 bitmap_device.GetBitmap()->Clear(0);
438 CPDF_RenderStatus status; 438 CPDF_RenderStatus status;
439 status.Initialize(m_pContext, &bitmap_device, NULL, NULL, this, pStates, 439 status.Initialize(m_pContext, &bitmap_device, NULL, NULL, this, pStates,
440 &Options, pType3Char->m_pForm->m_Transparency, 440 &Options, pType3Char->m_pForm->m_Transparency,
441 m_bDropObjects, pFormResource, FALSE, pType3Char, 441 m_bDropObjects, pFormResource, FALSE, pType3Char,
442 fill_argb); 442 fill_argb);
443 status.m_Type3FontCache.Append(m_Type3FontCache); 443 status.m_Type3FontCache.Append(m_Type3FontCache);
444 status.m_Type3FontCache.Add(pType3Font); 444 status.m_Type3FontCache.Add(pType3Font);
445 matrix.TranslateI(-rect.left, -rect.top); 445 matrix.TranslateI(-rect.left, -rect.top);
446 matrix.Scale(sa, sd); 446 matrix.Scale(sa, sd);
447 status.RenderObjectList(pType3Char->m_pForm, &matrix); 447 status.RenderObjectList(pType3Char->m_pForm.get(), &matrix);
448 m_pDevice->SetDIBits(bitmap_device.GetBitmap(), rect.left, rect.top); 448 m_pDevice->SetDIBits(bitmap_device.GetBitmap(), rect.left, rect.top);
449 } 449 }
450 delete pStates; 450 delete pStates;
451 } else if (pType3Char->m_pBitmap) { 451 } else if (pType3Char->m_pBitmap) {
452 if (device_class == FXDC_DISPLAY) { 452 if (device_class == FXDC_DISPLAY) {
453 CPDF_Type3Cache* pCache = GetCachedType3(pType3Font); 453 CPDF_Type3Cache* pCache = GetCachedType3(pType3Font);
454 refTypeCache.m_dwCount++; 454 refTypeCache.m_dwCount++;
455 CFX_GlyphBitmap* pBitmap = pCache->LoadGlyph(charcode, &matrix, sa, sd); 455 CFX_GlyphBitmap* pBitmap = pCache->LoadGlyph(charcode, &matrix, sa, sd);
456 if (!pBitmap) { 456 if (!pBitmap) {
457 continue; 457 continue;
458 } 458 }
459 int origin_x = FXSYS_round(matrix.e); 459 int origin_x = FXSYS_round(matrix.e);
460 int origin_y = FXSYS_round(matrix.f); 460 int origin_y = FXSYS_round(matrix.f);
461 if (pGlyphAndPos) { 461 if (pGlyphAndPos) {
462 pGlyphAndPos[iChar].m_pGlyph = pBitmap; 462 pGlyphAndPos[iChar].m_pGlyph = pBitmap;
463 pGlyphAndPos[iChar].m_OriginX = origin_x; 463 pGlyphAndPos[iChar].m_OriginX = origin_x;
464 pGlyphAndPos[iChar].m_OriginY = origin_y; 464 pGlyphAndPos[iChar].m_OriginY = origin_y;
465 } else { 465 } else {
466 m_pDevice->SetBitMask(&pBitmap->m_Bitmap, origin_x + pBitmap->m_Left, 466 m_pDevice->SetBitMask(&pBitmap->m_Bitmap, origin_x + pBitmap->m_Left,
467 origin_y - pBitmap->m_Top, fill_argb); 467 origin_y - pBitmap->m_Top, fill_argb);
468 } 468 }
469 } else { 469 } else {
470 CFX_Matrix image_matrix = pType3Char->m_ImageMatrix; 470 CFX_Matrix image_matrix = pType3Char->m_ImageMatrix;
471 image_matrix.Concat(matrix); 471 image_matrix.Concat(matrix);
472 CPDF_ImageRenderer renderer; 472 CPDF_ImageRenderer renderer;
473 if (renderer.Start(this, pType3Char->m_pBitmap, fill_argb, 255, 473 if (renderer.Start(this, pType3Char->m_pBitmap.get(), fill_argb, 255,
474 &image_matrix, 0, FALSE)) { 474 &image_matrix, 0, FALSE)) {
475 renderer.Continue(NULL); 475 renderer.Continue(nullptr);
476 } 476 }
477 if (!renderer.m_Result) { 477 if (!renderer.m_Result)
478 return FALSE; 478 return FALSE;
479 }
480 } 479 }
481 } 480 }
482 } 481 }
483 if (pGlyphAndPos) { 482 if (pGlyphAndPos) {
484 FX_RECT rect = 483 FX_RECT rect =
485 FXGE_GetGlyphsBBox(pGlyphAndPos, textobj->m_nChars, 0, sa, sd); 484 FXGE_GetGlyphsBBox(pGlyphAndPos, textobj->m_nChars, 0, sa, sd);
486 CFX_DIBitmap bitmap; 485 CFX_DIBitmap bitmap;
487 if (!bitmap.Create((int)(rect.Width() * sa), (int)(rect.Height() * sd), 486 if (!bitmap.Create((int)(rect.Width() * sa), (int)(rect.Height() * sd),
488 FXDIB_8bppMask)) { 487 FXDIB_8bppMask)) {
489 FX_Free(pGlyphAndPos); 488 FX_Free(pGlyphAndPos);
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
778 matrix.Concat(font_size, 0, 0, font_size, charpos.m_OriginX, 777 matrix.Concat(font_size, 0, 0, font_size, charpos.m_OriginX,
779 charpos.m_OriginY); 778 charpos.m_OriginY);
780 path.m_Path.New()->Append(pPath, &matrix); 779 path.m_Path.New()->Append(pPath, &matrix);
781 path.m_Matrix = *pTextMatrix; 780 path.m_Matrix = *pTextMatrix;
782 path.m_bStroke = bStroke; 781 path.m_bStroke = bStroke;
783 path.m_FillType = bFill ? FXFILL_WINDING : 0; 782 path.m_FillType = bFill ? FXFILL_WINDING : 0;
784 path.CalcBoundingBox(); 783 path.CalcBoundingBox();
785 ProcessPath(&path, pObj2Device); 784 ProcessPath(&path, pObj2Device);
786 } 785 }
787 } 786 }
OLDNEW
« no previous file with comments | « core/fpdfapi/fpdf_render/fpdf_render_image.cpp ('k') | core/fxge/dib/fx_dib_main.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698