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

Unified Diff: core/fpdfdoc/cpdf_defaultappearance.cpp

Issue 2190983002: Splitting fpdfdoc/doc_* part III. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@fpdf_doc_IV
Patch Set: Rebase to master Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: core/fpdfdoc/cpdf_defaultappearance.cpp
diff --git a/core/fpdfdoc/cpdf_defaultappearance.cpp b/core/fpdfdoc/cpdf_defaultappearance.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..f4f0cfb1575c9bfd11828893d49e45068b86adba
--- /dev/null
+++ b/core/fpdfdoc/cpdf_defaultappearance.cpp
@@ -0,0 +1,207 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "core/fpdfdoc/include/cpdf_defaultappearance.h"
+
+#include "core/fpdfapi/fpdf_parser/include/cpdf_simple_parser.h"
+#include "core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h"
+#include "core/fpdfdoc/include/cpdf_formcontrol.h"
+
+FX_BOOL CPDF_DefaultAppearance::HasFont() {
+ if (m_csDA.IsEmpty())
+ return FALSE;
+
+ CPDF_SimpleParser syntax(m_csDA.AsStringC());
+ return syntax.FindTagParamFromStart("Tf", 2);
+}
+
+CFX_ByteString CPDF_DefaultAppearance::GetFontString() {
+ CFX_ByteString csFont;
+ if (m_csDA.IsEmpty())
+ return csFont;
+
+ CPDF_SimpleParser syntax(m_csDA.AsStringC());
+ if (syntax.FindTagParamFromStart("Tf", 2)) {
+ csFont += syntax.GetWord();
+ csFont += " ";
+ csFont += syntax.GetWord();
+ csFont += " ";
+ csFont += syntax.GetWord();
+ }
+ return csFont;
+}
+
+void CPDF_DefaultAppearance::GetFont(CFX_ByteString& csFontNameTag,
+ FX_FLOAT& fFontSize) {
+ csFontNameTag = "";
+ fFontSize = 0;
+ if (m_csDA.IsEmpty())
+ return;
+
+ CPDF_SimpleParser syntax(m_csDA.AsStringC());
+ if (syntax.FindTagParamFromStart("Tf", 2)) {
+ csFontNameTag = CFX_ByteString(syntax.GetWord());
+ csFontNameTag.Delete(0, 1);
+ fFontSize = FX_atof(syntax.GetWord());
+ }
+ csFontNameTag = PDF_NameDecode(csFontNameTag);
+}
+
+FX_BOOL CPDF_DefaultAppearance::HasColor(FX_BOOL bStrokingOperation) {
+ if (m_csDA.IsEmpty())
+ return FALSE;
+
+ CPDF_SimpleParser syntax(m_csDA.AsStringC());
+ if (syntax.FindTagParamFromStart(bStrokingOperation ? "G" : "g", 1))
+ return TRUE;
+ if (syntax.FindTagParamFromStart(bStrokingOperation ? "RG" : "rg", 3))
+ return TRUE;
+ return syntax.FindTagParamFromStart(bStrokingOperation ? "K" : "k", 4);
+}
+
+CFX_ByteString CPDF_DefaultAppearance::GetColorString(
+ FX_BOOL bStrokingOperation) {
+ CFX_ByteString csColor;
+ if (m_csDA.IsEmpty())
+ return csColor;
+
+ CPDF_SimpleParser syntax(m_csDA.AsStringC());
+ if (syntax.FindTagParamFromStart(bStrokingOperation ? "G" : "g", 1)) {
+ csColor += syntax.GetWord();
+ csColor += " ";
+ csColor += syntax.GetWord();
+ return csColor;
+ }
+ if (syntax.FindTagParamFromStart(bStrokingOperation ? "RG" : "rg", 3)) {
+ csColor += syntax.GetWord();
+ csColor += " ";
+ csColor += syntax.GetWord();
+ csColor += " ";
+ csColor += syntax.GetWord();
+ csColor += " ";
+ csColor += syntax.GetWord();
+ return csColor;
+ }
+ if (syntax.FindTagParamFromStart(bStrokingOperation ? "K" : "k", 4)) {
+ csColor += syntax.GetWord();
+ csColor += " ";
+ csColor += syntax.GetWord();
+ csColor += " ";
+ csColor += syntax.GetWord();
+ csColor += " ";
+ csColor += syntax.GetWord();
+ csColor += " ";
+ csColor += syntax.GetWord();
+ }
+ return csColor;
+}
+
+void CPDF_DefaultAppearance::GetColor(int& iColorType,
+ FX_FLOAT fc[4],
+ FX_BOOL bStrokingOperation) {
+ iColorType = COLORTYPE_TRANSPARENT;
+ for (int c = 0; c < 4; c++)
+ fc[c] = 0;
+
+ if (m_csDA.IsEmpty())
+ return;
+
+ CPDF_SimpleParser syntax(m_csDA.AsStringC());
+ if (syntax.FindTagParamFromStart(bStrokingOperation ? "G" : "g", 1)) {
+ iColorType = COLORTYPE_GRAY;
+ fc[0] = FX_atof(syntax.GetWord());
+ return;
+ }
+ if (syntax.FindTagParamFromStart(bStrokingOperation ? "RG" : "rg", 3)) {
+ iColorType = COLORTYPE_RGB;
+ fc[0] = FX_atof(syntax.GetWord());
+ fc[1] = FX_atof(syntax.GetWord());
+ fc[2] = FX_atof(syntax.GetWord());
+ return;
+ }
+ if (syntax.FindTagParamFromStart(bStrokingOperation ? "K" : "k", 4)) {
+ iColorType = COLORTYPE_CMYK;
+ fc[0] = FX_atof(syntax.GetWord());
+ fc[1] = FX_atof(syntax.GetWord());
+ fc[2] = FX_atof(syntax.GetWord());
+ fc[3] = FX_atof(syntax.GetWord());
+ }
+}
+void CPDF_DefaultAppearance::GetColor(FX_ARGB& color,
Lei Zhang 2016/07/28 22:15:06 missed a new line here
dsinclair 2016/08/02 18:12:32 Done.
+ int& iColorType,
+ FX_BOOL bStrokingOperation) {
+ color = 0;
+ iColorType = COLORTYPE_TRANSPARENT;
+ if (m_csDA.IsEmpty())
+ return;
+
+ CPDF_SimpleParser syntax(m_csDA.AsStringC());
+ if (syntax.FindTagParamFromStart(bStrokingOperation ? "G" : "g", 1)) {
+ iColorType = COLORTYPE_GRAY;
+ FX_FLOAT g = FX_atof(syntax.GetWord()) * 255 + 0.5f;
+ color = ArgbEncode(255, (int)g, (int)g, (int)g);
+ return;
+ }
+ if (syntax.FindTagParamFromStart(bStrokingOperation ? "RG" : "rg", 3)) {
+ iColorType = COLORTYPE_RGB;
+ FX_FLOAT r = FX_atof(syntax.GetWord()) * 255 + 0.5f;
+ FX_FLOAT g = FX_atof(syntax.GetWord()) * 255 + 0.5f;
+ FX_FLOAT b = FX_atof(syntax.GetWord()) * 255 + 0.5f;
+ color = ArgbEncode(255, (int)r, (int)g, (int)b);
+ return;
+ }
+ if (syntax.FindTagParamFromStart(bStrokingOperation ? "K" : "k", 4)) {
+ iColorType = COLORTYPE_CMYK;
+ FX_FLOAT c = FX_atof(syntax.GetWord());
+ FX_FLOAT m = FX_atof(syntax.GetWord());
+ FX_FLOAT y = FX_atof(syntax.GetWord());
+ FX_FLOAT k = FX_atof(syntax.GetWord());
+ FX_FLOAT r = 1.0f - std::min(1.0f, c + k);
+ FX_FLOAT g = 1.0f - std::min(1.0f, m + k);
+ FX_FLOAT b = 1.0f - std::min(1.0f, y + k);
+ color = ArgbEncode(255, (int)(r * 255 + 0.5f), (int)(g * 255 + 0.5f),
+ (int)(b * 255 + 0.5f));
+ }
+}
+
+FX_BOOL CPDF_DefaultAppearance::HasTextMatrix() {
+ if (m_csDA.IsEmpty())
+ return FALSE;
+
+ CPDF_SimpleParser syntax(m_csDA.AsStringC());
+ return syntax.FindTagParamFromStart("Tm", 6);
+}
+
+CFX_ByteString CPDF_DefaultAppearance::GetTextMatrixString() {
+ CFX_ByteString csTM;
+ if (m_csDA.IsEmpty())
+ return csTM;
+
+ CPDF_SimpleParser syntax(m_csDA.AsStringC());
+ if (syntax.FindTagParamFromStart("Tm", 6)) {
+ for (int i = 0; i < 6; i++) {
+ csTM += syntax.GetWord();
+ csTM += " ";
+ }
+ csTM += syntax.GetWord();
+ }
+ return csTM;
+}
+
+CFX_Matrix CPDF_DefaultAppearance::GetTextMatrix() {
+ CFX_Matrix tm;
+ if (m_csDA.IsEmpty())
+ return tm;
+
+ CPDF_SimpleParser syntax(m_csDA.AsStringC());
+ if (syntax.FindTagParamFromStart("Tm", 6)) {
+ FX_FLOAT f[6];
+ for (int i = 0; i < 6; i++)
+ f[i] = FX_atof(syntax.GetWord());
+ tm.Set(f[0], f[1], f[2], f[3], f[4], f[5]);
+ }
+ return tm;
+}

Powered by Google App Engine
This is Rietveld 408576698