diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-09-18 14:34:04 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-10-04 11:15:27 +0000 |
commit | e6430e577f105ad8813c92e75c54660c4985026e (patch) | |
tree | 88115e5d1fb471fea807111924dcccbeadbf9e4f /chromium/third_party/pdfium | |
parent | 53d399fe6415a96ea6986ec0d402a9c07da72453 (diff) | |
download | qtwebengine-chromium-e6430e577f105ad8813c92e75c54660c4985026e.tar.gz |
BASELINE: Update Chromium to 61.0.3163.99
Change-Id: I8452f34574d88ca2b27af9bd56fc9ff3f16b1367
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'chromium/third_party/pdfium')
918 files changed, 25207 insertions, 33029 deletions
diff --git a/chromium/third_party/pdfium/AUTHORS b/chromium/third_party/pdfium/AUTHORS index 7499c1094c6..13347edb7a5 100644 --- a/chromium/third_party/pdfium/AUTHORS +++ b/chromium/third_party/pdfium/AUTHORS @@ -32,6 +32,7 @@ Nico Weber <thakis@chromium.org> Peter Kasting <pkasting@chromium.org> Raymes Khoury <raymes@chromium.org> Reid Kleckner <rnk@chromium.org> +Ryan Wiley <wileyrr@gmail.com> Robert Sesek <rsesek@chromium.org> Sam Clegg <sbc@chromium.org> Thomas Sepez <tsepez@chromium.org> diff --git a/chromium/third_party/pdfium/BUILD.gn b/chromium/third_party/pdfium/BUILD.gn index 5802752af99..80a258ea45c 100644 --- a/chromium/third_party/pdfium/BUILD.gn +++ b/chromium/third_party/pdfium/BUILD.gn @@ -86,6 +86,7 @@ config("pdfium_core_config") { if (is_win) { cflags += [ "/wd4267", + "/wd4324", "/wd4577", ] } @@ -134,6 +135,8 @@ static_library("pdfium") { "fpdfsdk/fpdf_structtree.cpp", "fpdfsdk/fpdf_sysfontinfo.cpp", "fpdfsdk/fpdf_transformpage.cpp", + "fpdfsdk/fpdfannot.cpp", + "fpdfsdk/fpdfattachment.cpp", "fpdfsdk/fpdfdoc.cpp", "fpdfsdk/fpdfeditimg.cpp", "fpdfsdk/fpdfeditpage.cpp", @@ -153,6 +156,8 @@ static_library("pdfium") { "fpdfsdk/pdfsdk_fieldaction.cpp", "fpdfsdk/pdfsdk_fieldaction.h", "public/cpp/fpdf_deleters.h", + "public/fpdf_annot.h", + "public/fpdf_attachment.h", "public/fpdf_dataavail.h", "public/fpdf_doc.h", "public/fpdf_edit.h", @@ -257,6 +262,19 @@ static_library("test_support") { configs += [ ":pdfium_core_config" ] } +static_library("image_diff") { + testonly = true + sources = [ + "testing/image_diff/image_diff_png.cpp", + "testing/image_diff/image_diff_png.h", + ] + configs += [ ":pdfium_core_config" ] + deps = [] + if (!pdf_enable_xfa) { + deps += [ "third_party:fx_lpng" ] + } +} + # Targets below this are only visible within this file (and to the # top-level gn_visibility target used to help gn_all build everything). visibility = [ @@ -445,14 +463,30 @@ static_library("fpdfapi") { "core/fpdfapi/edit/cpdf_flateencoder.h", "core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp", "core/fpdfapi/edit/cpdf_pagecontentgenerator.h", + "core/fpdfapi/font/cfx_cttgsubtable.cpp", + "core/fpdfapi/font/cfx_cttgsubtable.h", + "core/fpdfapi/font/cfx_stockfontarray.cpp", + "core/fpdfapi/font/cfx_stockfontarray.h", + "core/fpdfapi/font/cpdf_cid2unicodemap.cpp", + "core/fpdfapi/font/cpdf_cid2unicodemap.h", "core/fpdfapi/font/cpdf_cidfont.cpp", "core/fpdfapi/font/cpdf_cidfont.h", + "core/fpdfapi/font/cpdf_cmap.cpp", + "core/fpdfapi/font/cpdf_cmap.h", + "core/fpdfapi/font/cpdf_cmapmanager.cpp", + "core/fpdfapi/font/cpdf_cmapmanager.h", + "core/fpdfapi/font/cpdf_cmapparser.cpp", + "core/fpdfapi/font/cpdf_cmapparser.h", "core/fpdfapi/font/cpdf_font.cpp", "core/fpdfapi/font/cpdf_font.h", "core/fpdfapi/font/cpdf_fontencoding.cpp", "core/fpdfapi/font/cpdf_fontencoding.h", + "core/fpdfapi/font/cpdf_fontglobals.cpp", + "core/fpdfapi/font/cpdf_fontglobals.h", "core/fpdfapi/font/cpdf_simplefont.cpp", "core/fpdfapi/font/cpdf_simplefont.h", + "core/fpdfapi/font/cpdf_tounicodemap.cpp", + "core/fpdfapi/font/cpdf_tounicodemap.h", "core/fpdfapi/font/cpdf_truetypefont.cpp", "core/fpdfapi/font/cpdf_truetypefont.h", "core/fpdfapi/font/cpdf_type1font.cpp", @@ -461,11 +495,6 @@ static_library("fpdfapi") { "core/fpdfapi/font/cpdf_type3char.h", "core/fpdfapi/font/cpdf_type3font.cpp", "core/fpdfapi/font/cpdf_type3font.h", - "core/fpdfapi/font/font_int.h", - "core/fpdfapi/font/fpdf_font.cpp", - "core/fpdfapi/font/fpdf_font_cid.cpp", - "core/fpdfapi/font/ttgsubtable.cpp", - "core/fpdfapi/font/ttgsubtable.h", "core/fpdfapi/page/cpdf_allstates.cpp", "core/fpdfapi/page/cpdf_allstates.h", "core/fpdfapi/page/cpdf_clippath.cpp", @@ -690,8 +719,6 @@ static_library("fxcodec") { "core/fxcodec/jbig2/JBig2_GrdProc.h", "core/fxcodec/jbig2/JBig2_GrrdProc.cpp", "core/fxcodec/jbig2/JBig2_GrrdProc.h", - "core/fxcodec/jbig2/JBig2_GsidProc.cpp", - "core/fxcodec/jbig2/JBig2_GsidProc.h", "core/fxcodec/jbig2/JBig2_HtrdProc.cpp", "core/fxcodec/jbig2/JBig2_HtrdProc.h", "core/fxcodec/jbig2/JBig2_HuffmanDecoder.cpp", @@ -860,6 +887,7 @@ static_library("fxcrt") { "core/fxcrt/fx_arabic.h", "core/fxcrt/ifx_chariter.h", "core/fxcrt/ifx_locale.h", + "core/fxcrt/xml/cfx_saxcontext.cpp", "core/fxcrt/xml/cfx_saxcontext.h", "core/fxcrt/xml/cfx_saxreader.cpp", "core/fxcrt/xml/cfx_saxreader.h", @@ -902,19 +930,39 @@ static_library("fxge") { "core/fxge/android/cfx_androidfontinfo.cpp", "core/fxge/android/cfx_androidfontinfo.h", "core/fxge/android/fx_android_imp.cpp", + "core/fxge/cfx_cliprgn.cpp", + "core/fxge/cfx_cliprgn.h", + "core/fxge/cfx_color.cpp", + "core/fxge/cfx_color.h", "core/fxge/cfx_defaultrenderdevice.h", + "core/fxge/cfx_facecache.cpp", "core/fxge/cfx_facecache.h", + "core/fxge/cfx_folderfontinfo.cpp", + "core/fxge/cfx_folderfontinfo.h", + "core/fxge/cfx_font.cpp", + "core/fxge/cfx_fontcache.cpp", "core/fxge/cfx_fontcache.h", + "core/fxge/cfx_fontmapper.cpp", "core/fxge/cfx_fontmapper.h", + "core/fxge/cfx_fontmgr.cpp", "core/fxge/cfx_fontmgr.h", + "core/fxge/cfx_gemodule.cpp", "core/fxge/cfx_gemodule.h", + "core/fxge/cfx_graphstate.cpp", "core/fxge/cfx_graphstate.h", + "core/fxge/cfx_graphstatedata.cpp", "core/fxge/cfx_graphstatedata.h", + "core/fxge/cfx_pathdata.cpp", "core/fxge/cfx_pathdata.h", + "core/fxge/cfx_renderdevice.cpp", "core/fxge/cfx_renderdevice.h", + "core/fxge/cfx_substfont.cpp", "core/fxge/cfx_substfont.h", + "core/fxge/cfx_unicodeencoding.cpp", "core/fxge/cfx_unicodeencoding.h", "core/fxge/cfx_windowsrenderdevice.h", + "core/fxge/cttfontdesc.cpp", + "core/fxge/cttfontdesc.h", "core/fxge/dib/cfx_bitmapcomposer.cpp", "core/fxge/dib/cfx_bitmapcomposer.h", "core/fxge/dib/cfx_bitmapstorer.cpp", @@ -960,28 +1008,10 @@ static_library("fxge") { "core/fxge/fx_dib.h", "core/fxge/fx_font.h", "core/fxge/fx_freetype.h", - "core/fxge/ge/cfx_cliprgn.cpp", - "core/fxge/ge/cfx_cliprgn.h", - "core/fxge/ge/cfx_facecache.cpp", - "core/fxge/ge/cfx_folderfontinfo.cpp", - "core/fxge/ge/cfx_folderfontinfo.h", - "core/fxge/ge/cfx_font.cpp", - "core/fxge/ge/cfx_fontcache.cpp", - "core/fxge/ge/cfx_fontmapper.cpp", - "core/fxge/ge/cfx_fontmgr.cpp", - "core/fxge/ge/cfx_gemodule.cpp", - "core/fxge/ge/cfx_graphstate.cpp", - "core/fxge/ge/cfx_graphstatedata.cpp", - "core/fxge/ge/cfx_pathdata.cpp", - "core/fxge/ge/cfx_renderdevice.cpp", - "core/fxge/ge/cfx_substfont.cpp", - "core/fxge/ge/cfx_unicodeencoding.cpp", - "core/fxge/ge/cttfontdesc.cpp", - "core/fxge/ge/cttfontdesc.h", - "core/fxge/ge/fx_ge_fontmap.cpp", - "core/fxge/ge/fx_ge_linux.cpp", - "core/fxge/ge/fx_ge_text.cpp", - "core/fxge/ge/fx_text_int.h", + "core/fxge/fx_ge_fontmap.cpp", + "core/fxge/fx_ge_linux.cpp", + "core/fxge/fx_ge_text.cpp", + "core/fxge/fx_text_int.h", "core/fxge/ifx_renderdevicedriver.cpp", "core/fxge/ifx_renderdevicedriver.h", "core/fxge/ifx_systemfontinfo.h", @@ -1001,8 +1031,8 @@ static_library("fxge") { if (pdf_enable_xfa) { sources += [ + "core/fxge/cfx_unicodeencodingex.cpp", "core/fxge/cfx_unicodeencodingex.h", - "core/fxge/ge/cfx_unicodeencodingex.cpp", ] } @@ -1064,32 +1094,34 @@ static_library("fxedit") { static_library("pdfwindow") { sources = [ - "fpdfsdk/pdfwindow/PWL_Button.cpp", - "fpdfsdk/pdfwindow/PWL_Button.h", - "fpdfsdk/pdfwindow/PWL_Caret.cpp", - "fpdfsdk/pdfwindow/PWL_Caret.h", - "fpdfsdk/pdfwindow/PWL_ComboBox.cpp", - "fpdfsdk/pdfwindow/PWL_ComboBox.h", - "fpdfsdk/pdfwindow/PWL_Edit.cpp", - "fpdfsdk/pdfwindow/PWL_Edit.h", - "fpdfsdk/pdfwindow/PWL_EditCtrl.cpp", - "fpdfsdk/pdfwindow/PWL_EditCtrl.h", - "fpdfsdk/pdfwindow/PWL_FontMap.cpp", - "fpdfsdk/pdfwindow/PWL_FontMap.h", - "fpdfsdk/pdfwindow/PWL_Icon.cpp", - "fpdfsdk/pdfwindow/PWL_Icon.h", - "fpdfsdk/pdfwindow/PWL_ListBox.cpp", - "fpdfsdk/pdfwindow/PWL_ListBox.h", - "fpdfsdk/pdfwindow/PWL_ScrollBar.cpp", - "fpdfsdk/pdfwindow/PWL_ScrollBar.h", - "fpdfsdk/pdfwindow/PWL_SpecialButton.cpp", - "fpdfsdk/pdfwindow/PWL_SpecialButton.h", - "fpdfsdk/pdfwindow/PWL_Utils.cpp", - "fpdfsdk/pdfwindow/PWL_Utils.h", - "fpdfsdk/pdfwindow/PWL_Wnd.cpp", - "fpdfsdk/pdfwindow/PWL_Wnd.h", - "fpdfsdk/pdfwindow/cpwl_color.cpp", - "fpdfsdk/pdfwindow/cpwl_color.h", + "fpdfsdk/pdfwindow/cpwl_appstream.cpp", + "fpdfsdk/pdfwindow/cpwl_appstream.h", + "fpdfsdk/pdfwindow/cpwl_button.cpp", + "fpdfsdk/pdfwindow/cpwl_button.h", + "fpdfsdk/pdfwindow/cpwl_caret.cpp", + "fpdfsdk/pdfwindow/cpwl_caret.h", + "fpdfsdk/pdfwindow/cpwl_combo_box.cpp", + "fpdfsdk/pdfwindow/cpwl_combo_box.h", + "fpdfsdk/pdfwindow/cpwl_edit.cpp", + "fpdfsdk/pdfwindow/cpwl_edit.h", + "fpdfsdk/pdfwindow/cpwl_edit_ctrl.cpp", + "fpdfsdk/pdfwindow/cpwl_edit_ctrl.h", + "fpdfsdk/pdfwindow/cpwl_font_map.cpp", + "fpdfsdk/pdfwindow/cpwl_font_map.h", + "fpdfsdk/pdfwindow/cpwl_icon.cpp", + "fpdfsdk/pdfwindow/cpwl_icon.h", + "fpdfsdk/pdfwindow/cpwl_list_box.cpp", + "fpdfsdk/pdfwindow/cpwl_list_box.h", + "fpdfsdk/pdfwindow/cpwl_scroll_bar.cpp", + "fpdfsdk/pdfwindow/cpwl_scroll_bar.h", + "fpdfsdk/pdfwindow/cpwl_special_button.cpp", + "fpdfsdk/pdfwindow/cpwl_special_button.h", + "fpdfsdk/pdfwindow/cpwl_timer.cpp", + "fpdfsdk/pdfwindow/cpwl_timer.h", + "fpdfsdk/pdfwindow/cpwl_timer_handler.cpp", + "fpdfsdk/pdfwindow/cpwl_timer_handler.h", + "fpdfsdk/pdfwindow/cpwl_wnd.cpp", + "fpdfsdk/pdfwindow/cpwl_wnd.h", ] configs += [ ":pdfium_core_config" ] deps = [ @@ -1164,6 +1196,8 @@ static_library("formfiller") { sources = [ "fpdfsdk/formfiller/cba_fontmap.cpp", "fpdfsdk/formfiller/cba_fontmap.h", + "fpdfsdk/formfiller/cffl_button.cpp", + "fpdfsdk/formfiller/cffl_button.h", "fpdfsdk/formfiller/cffl_checkbox.cpp", "fpdfsdk/formfiller/cffl_checkbox.h", "fpdfsdk/formfiller/cffl_combobox.cpp", @@ -1318,7 +1352,6 @@ if (pdf_enable_xfa) { "fxbarcode/datamatrix/BC_HighLevelEncoder.h", "fxbarcode/datamatrix/BC_SymbolInfo.cpp", "fxbarcode/datamatrix/BC_SymbolInfo.h", - "fxbarcode/datamatrix/BC_SymbolShapeHint.h", "fxbarcode/datamatrix/BC_TextEncoder.cpp", "fxbarcode/datamatrix/BC_TextEncoder.h", "fxbarcode/datamatrix/BC_X12Encoder.cpp", @@ -1420,6 +1453,8 @@ if (pdf_enable_xfa) { "xfa/fde/css/cfde_cssdeclaration.h", "xfa/fde/css/cfde_cssenumvalue.cpp", "xfa/fde/css/cfde_cssenumvalue.h", + "xfa/fde/css/cfde_cssexttextbuf.cpp", + "xfa/fde/css/cfde_cssexttextbuf.h", "xfa/fde/css/cfde_cssnumbervalue.cpp", "xfa/fde/css/cfde_cssnumbervalue.h", "xfa/fde/css/cfde_csspropertyholder.cpp", @@ -1593,6 +1628,52 @@ if (pdf_enable_xfa) { "xfa/fwl/theme/cfwl_widgettp.h", "xfa/fxfa/app/cxfa_csstagprovider.cpp", "xfa/fxfa/app/cxfa_csstagprovider.h", + "xfa/fxfa/app/cxfa_ffarc.cpp", + "xfa/fxfa/app/cxfa_ffarc.h", + "xfa/fxfa/app/cxfa_ffbarcode.cpp", + "xfa/fxfa/app/cxfa_ffbarcode.h", + "xfa/fxfa/app/cxfa_ffcheckbutton.cpp", + "xfa/fxfa/app/cxfa_ffcheckbutton.h", + "xfa/fxfa/app/cxfa_ffcombobox.cpp", + "xfa/fxfa/app/cxfa_ffcombobox.h", + "xfa/fxfa/app/cxfa_ffdatetimeedit.cpp", + "xfa/fxfa/app/cxfa_ffdatetimeedit.h", + "xfa/fxfa/app/cxfa_ffdraw.cpp", + "xfa/fxfa/app/cxfa_ffdraw.h", + "xfa/fxfa/app/cxfa_ffexclgroup.cpp", + "xfa/fxfa/app/cxfa_ffexclgroup.h", + "xfa/fxfa/app/cxfa_fffield.cpp", + "xfa/fxfa/app/cxfa_fffield.h", + "xfa/fxfa/app/cxfa_ffimage.cpp", + "xfa/fxfa/app/cxfa_ffimage.h", + "xfa/fxfa/app/cxfa_ffimageedit.cpp", + "xfa/fxfa/app/cxfa_ffimageedit.h", + "xfa/fxfa/app/cxfa_ffline.cpp", + "xfa/fxfa/app/cxfa_ffline.h", + "xfa/fxfa/app/cxfa_fflistbox.cpp", + "xfa/fxfa/app/cxfa_fflistbox.h", + "xfa/fxfa/app/cxfa_ffnotify.cpp", + "xfa/fxfa/app/cxfa_ffnotify.h", + "xfa/fxfa/app/cxfa_ffnumericedit.cpp", + "xfa/fxfa/app/cxfa_ffnumericedit.h", + "xfa/fxfa/app/cxfa_ffpasswordedit.cpp", + "xfa/fxfa/app/cxfa_ffpasswordedit.h", + "xfa/fxfa/app/cxfa_ffpushbutton.cpp", + "xfa/fxfa/app/cxfa_ffpushbutton.h", + "xfa/fxfa/app/cxfa_ffrectangle.cpp", + "xfa/fxfa/app/cxfa_ffrectangle.h", + "xfa/fxfa/app/cxfa_ffsignature.cpp", + "xfa/fxfa/app/cxfa_ffsignature.h", + "xfa/fxfa/app/cxfa_ffsubform.cpp", + "xfa/fxfa/app/cxfa_ffsubform.h", + "xfa/fxfa/app/cxfa_fftext.cpp", + "xfa/fxfa/app/cxfa_fftext.h", + "xfa/fxfa/app/cxfa_fftextedit.cpp", + "xfa/fxfa/app/cxfa_fftextedit.h", + "xfa/fxfa/app/cxfa_fwladapterwidgetmgr.cpp", + "xfa/fxfa/app/cxfa_fwladapterwidgetmgr.h", + "xfa/fxfa/app/cxfa_fwltheme.cpp", + "xfa/fxfa/app/cxfa_fwltheme.h", "xfa/fxfa/app/cxfa_linkuserdata.cpp", "xfa/fxfa/app/cxfa_linkuserdata.h", "xfa/fxfa/app/cxfa_loadercontext.cpp", @@ -1605,48 +1686,14 @@ if (pdf_enable_xfa) { "xfa/fxfa/app/cxfa_textparsecontext.h", "xfa/fxfa/app/cxfa_textparser.cpp", "xfa/fxfa/app/cxfa_textparser.h", + "xfa/fxfa/app/cxfa_textpiece.cpp", + "xfa/fxfa/app/cxfa_textpiece.h", + "xfa/fxfa/app/cxfa_textprovider.cpp", + "xfa/fxfa/app/cxfa_textprovider.h", "xfa/fxfa/app/cxfa_texttabstopscontext.cpp", "xfa/fxfa/app/cxfa_texttabstopscontext.h", "xfa/fxfa/app/cxfa_textuserdata.cpp", "xfa/fxfa/app/cxfa_textuserdata.h", - "xfa/fxfa/app/xfa_ffbarcode.cpp", - "xfa/fxfa/app/xfa_ffbarcode.h", - "xfa/fxfa/app/xfa_ffcheckbutton.cpp", - "xfa/fxfa/app/xfa_ffcheckbutton.h", - "xfa/fxfa/app/xfa_ffchoicelist.cpp", - "xfa/fxfa/app/xfa_ffchoicelist.h", - "xfa/fxfa/app/xfa_ffdraw.cpp", - "xfa/fxfa/app/xfa_ffdraw.h", - "xfa/fxfa/app/xfa_ffexclgroup.cpp", - "xfa/fxfa/app/xfa_ffexclgroup.h", - "xfa/fxfa/app/xfa_fffield.cpp", - "xfa/fxfa/app/xfa_fffield.h", - "xfa/fxfa/app/xfa_ffimage.cpp", - "xfa/fxfa/app/xfa_ffimage.h", - "xfa/fxfa/app/xfa_ffimageedit.cpp", - "xfa/fxfa/app/xfa_ffimageedit.h", - "xfa/fxfa/app/xfa_ffnotify.cpp", - "xfa/fxfa/app/xfa_ffnotify.h", - "xfa/fxfa/app/xfa_ffpath.cpp", - "xfa/fxfa/app/xfa_ffpath.h", - "xfa/fxfa/app/xfa_ffpushbutton.cpp", - "xfa/fxfa/app/xfa_ffpushbutton.h", - "xfa/fxfa/app/xfa_ffsignature.cpp", - "xfa/fxfa/app/xfa_ffsignature.h", - "xfa/fxfa/app/xfa_ffsubform.cpp", - "xfa/fxfa/app/xfa_ffsubform.h", - "xfa/fxfa/app/xfa_fftext.cpp", - "xfa/fxfa/app/xfa_fftext.h", - "xfa/fxfa/app/xfa_fftextedit.cpp", - "xfa/fxfa/app/xfa_fftextedit.h", - "xfa/fxfa/app/xfa_ffwidgetacc.cpp", - "xfa/fxfa/app/xfa_ffwidgetacc.h", - "xfa/fxfa/app/xfa_fwladapter.cpp", - "xfa/fxfa/app/xfa_fwladapter.h", - "xfa/fxfa/app/xfa_fwltheme.cpp", - "xfa/fxfa/app/xfa_fwltheme.h", - "xfa/fxfa/app/xfa_textpiece.cpp", - "xfa/fxfa/app/xfa_textpiece.h", "xfa/fxfa/cxfa_deffontmgr.cpp", "xfa/fxfa/cxfa_deffontmgr.h", "xfa/fxfa/cxfa_eventparam.cpp", @@ -1827,16 +1874,16 @@ if (pdf_enable_xfa) { "xfa/fxfa/parser/xfa_resolvenode_rs.h", "xfa/fxfa/parser/xfa_utils.cpp", "xfa/fxfa/parser/xfa_utils.h", - "xfa/fxgraphics/cfx_color.cpp", - "xfa/fxgraphics/cfx_color.h", - "xfa/fxgraphics/cfx_graphics.cpp", - "xfa/fxgraphics/cfx_graphics.h", - "xfa/fxgraphics/cfx_path.cpp", - "xfa/fxgraphics/cfx_path.h", - "xfa/fxgraphics/cfx_pattern.cpp", - "xfa/fxgraphics/cfx_pattern.h", - "xfa/fxgraphics/cfx_shading.cpp", - "xfa/fxgraphics/cfx_shading.h", + "xfa/fxgraphics/cxfa_color.cpp", + "xfa/fxgraphics/cxfa_color.h", + "xfa/fxgraphics/cxfa_graphics.cpp", + "xfa/fxgraphics/cxfa_graphics.h", + "xfa/fxgraphics/cxfa_path.cpp", + "xfa/fxgraphics/cxfa_path.h", + "xfa/fxgraphics/cxfa_pattern.cpp", + "xfa/fxgraphics/cxfa_pattern.h", + "xfa/fxgraphics/cxfa_shading.cpp", + "xfa/fxgraphics/cxfa_shading.h", ] include_dirs = [ "." ] deps = [ @@ -1855,8 +1902,8 @@ test("pdfium_unittests") { sources = [ "core/fdrm/crypto/fx_crypt_unittest.cpp", "core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp", - "core/fpdfapi/font/fpdf_font_cid_unittest.cpp", - "core/fpdfapi/font/fpdf_font_unittest.cpp", + "core/fpdfapi/font/cpdf_cmapparser_unittest.cpp", + "core/fpdfapi/font/cpdf_tounicodemap_unittest.cpp", "core/fpdfapi/page/cpdf_devicecs_unittest.cpp", "core/fpdfapi/page/cpdf_streamcontentparser_unittest.cpp", "core/fpdfapi/page/cpdf_streamparser_unittest.cpp", @@ -1870,6 +1917,7 @@ test("pdfium_unittests") { "core/fpdfdoc/cpdf_dest_unittest.cpp", "core/fpdfdoc/cpdf_filespec_unittest.cpp", "core/fpdfdoc/cpdf_formfield_unittest.cpp", + "core/fpdfdoc/cpdf_nametree_unittest.cpp", "core/fpdftext/cpdf_linkextract_unittest.cpp", "core/fxcodec/codec/fx_codec_a85_unittest.cpp", "core/fxcodec/codec/fx_codec_jpx_unittest.cpp", @@ -1915,10 +1963,11 @@ test("pdfium_unittests") { "xfa/fde/css/cfde_cssdeclaration_unittest.cpp", "xfa/fde/css/cfde_cssstylesheet_unittest.cpp", "xfa/fde/css/cfde_cssvaluelistparser_unittest.cpp", + "xfa/fgas/crt/cfgas_formatstring_unittest.cpp", "xfa/fgas/layout/cfx_rtfbreak_unittest.cpp", "xfa/fwl/cfx_barcode_unittest.cpp", + "xfa/fxfa/app/cxfa_ffbarcode_unittest.cpp", "xfa/fxfa/app/cxfa_textparser_unittest.cpp", - "xfa/fxfa/app/xfa_ffbarcode_unittest.cpp", "xfa/fxfa/cxfa_ffapp_unittest.cpp", "xfa/fxfa/fm2js/cxfa_fmlexer_unittest.cpp", "xfa/fxfa/fm2js/cxfa_fmparse_unittest.cpp", @@ -1931,7 +1980,10 @@ test("pdfium_unittests") { deps += [ "//skia" ] } if (pdf_enable_v8) { - sources += [ "fpdfsdk/javascript/public_methods_unittest.cpp" ] + sources += [ + "fpdfsdk/javascript/public_methods_unittest.cpp", + "fpdfsdk/javascript/util_unittest.cpp", + ] include_dirs += [ "//v8", "//v8/include", @@ -1952,10 +2004,12 @@ test("pdfium_embeddertests") { "core/fpdfapi/render/fpdf_render_loadimage_embeddertest.cpp", "core/fpdfapi/render/fpdf_render_pattern_embeddertest.cpp", "core/fxcodec/codec/fx_codec_embeddertest.cpp", - "core/fxge/ge/fx_ge_text_embeddertest.cpp", + "core/fxge/fx_ge_text_embeddertest.cpp", "fpdfsdk/fpdf_dataavail_embeddertest.cpp", "fpdfsdk/fpdf_flatten_embeddertest.cpp", "fpdfsdk/fpdf_structtree_embeddertest.cpp", + "fpdfsdk/fpdfannot_embeddertest.cpp", + "fpdfsdk/fpdfattachment_embeddertest.cpp", "fpdfsdk/fpdfdoc_embeddertest.cpp", "fpdfsdk/fpdfedit_embeddertest.cpp", "fpdfsdk/fpdfext_embeddertest.cpp", @@ -1967,6 +2021,8 @@ test("pdfium_embeddertests") { "fpdfsdk/fpdfview_c_api_test.h", "fpdfsdk/fpdfview_embeddertest.cpp", "fpdfsdk/fsdk_baseform_embeddertest.cpp", + "fpdfsdk/pdfwindow/cpwl_combo_box_embeddertest.cpp", + "fpdfsdk/pdfwindow/cpwl_edit_embeddertest.cpp", "testing/embedder_test.cpp", "testing/embedder_test.h", "testing/embedder_test_mock_delegate.h", @@ -2012,6 +2068,23 @@ if (pdf_is_standalone) { "//samples", ] } + + executable("pdfium_diff") { + testonly = true + sources = [ + "testing/image_diff/image_diff.cpp", + ] + deps = [ + ":image_diff", + ":pdfium", + "//build/config:exe_and_shlib_deps", + "//build/win:default_exe_manifest", + ] + configs -= [ "//build/config/compiler:chromium_code" ] + configs += [ "//build/config/compiler:no_chromium_code" ] + configs += [ ":pdfium_core_config" ] + } + group("fuzzers") { testonly = true deps = [ @@ -2029,6 +2102,7 @@ group("pdfium_all") { if (pdf_is_standalone) { deps += [ ":fuzzers", + ":pdfium_diff", ":samples", ] } diff --git a/chromium/third_party/pdfium/DEPS b/chromium/third_party/pdfium/DEPS index dc3835aefbc..0ad0f785883 100644 --- a/chromium/third_party/pdfium/DEPS +++ b/chromium/third_party/pdfium/DEPS @@ -10,7 +10,7 @@ vars = { 'catapult_revision': '86352b966b0245d6883e5f7df27687856978b6d7', 'clang_revision': 'ae881aab392c247eca831e079d1d45e1c200cce7', 'cygwin_revision': 'c89e446b273697fadf3a10ff1007a97c0b7de6df', - 'freetype_revision': 'a12a34451a99cbbcad55d466940fd445171927fd', + 'freetype_revision': '38bdf22bfe68432aebdd33c198a0bd11b4ebb96f', 'gen_library_loader_revision': '916d4acd8b2cde67a390737dfba90b3c37de23a1', 'gmock_revision': '29763965ab52f24565299976b936d1265cb6a271', 'gtest_revision': '8245545b6dc9c4703e6496d1efd19e975ad2b038', @@ -19,11 +19,11 @@ vars = { 'jinja2_revision': 'd34383206fa42d52faa10bb9931d6d538f3a57e0', 'jpeg_turbo_revision': '7260e4d8b8e1e40b17f03fafdf1cd83296900f76', 'markupsafe_revision': '8f45f5cfa0009d2a70589bcda0349b8cb2b72783', - 'pdfium_tests_revision': '5379e0a6580443318c8192cdfc78a76e880ca3f6', - 'skia_revision': '90e3cd78991ef337dbd0023efb30ece864694308', + 'pdfium_tests_revision': 'ab561f0075518d699636b884b0db46293cd76261', + 'skia_revision': 'bb581ce30f55360fd3a12e7f5aa1fe324b16d085', 'tools_memory_revision': '427f10475e1a8d72424c29d00bf689122b738e5d', 'trace_event_revision': '06294c8a4a6f744ef284cd63cfe54dbf61eea290', - 'v8_revision': '07b2253a044bffa43697c6a43aaccb68c7e82af4', + 'v8_revision': '539f7ab310f8865090c494b0251c45e7c52ae5f5', 'yasm_binary_revision': '52f9b3f4b0aa06da24ef8b123058bb61ee468881', 'yasm_source_revision': '7da28c6c7c6a1387217352ce02b31754deb54d2a', 'zlib_revision': 'eed2732a73838fd581cb25819ab1c4f478d6b38f', @@ -92,6 +92,11 @@ deps = { Var('chromium_git') + "/chromium/src/tools/generate_library_loader@" + Var('gen_library_loader_revision'), + # TODO(GYP): Remove this when no tools rely on GYP anymore. + "tools/gyp": + Var('chromium_git') + '/external/gyp.git@' + + 'eb296f67da078ec01f5e3a9ea9cdc6d26d680161', + "tools/memory": Var('chromium_git') + "/chromium/src/tools/memory@" + Var('tools_memory_revision'), @@ -114,11 +119,6 @@ deps_os = { Var('chromium_git') + '/chromium/deps/yasm/binaries.git' + '@' + Var('yasm_binary_revision'), - # TODO(GYP): Remove this when no tools rely on GYP anymore. - "tools/gyp": - Var('chromium_git') + '/external/gyp.git@' + - 'c61b0b35c8396bfd59efc6cfc11401d912b0f510', - "v8/third_party/cygwin": Var('chromium_git') + "/chromium/deps/cygwin@" + Var('cygwin_revision'), }, @@ -219,6 +219,15 @@ hooks = [ ], }, { + # Downloads the current stable linux sysroot to build/linux/ if needed. + # This sysroot updates at about the same rate that the chrome build deps + # change. + 'name': 'sysroot', + 'pattern': '.', + 'action': ['python', 'pdfium/build/linux/sysroot_scripts/install-sysroot.py', + '--running-as-hook'], + }, + { # Update the Windows toolchain if necessary. 'name': 'win_toolchain', 'pattern': '.', diff --git a/chromium/third_party/pdfium/PRESUBMIT.py b/chromium/third_party/pdfium/PRESUBMIT.py index 26d559a33fb..a7db1230d4c 100644 --- a/chromium/third_party/pdfium/PRESUBMIT.py +++ b/chromium/third_party/pdfium/PRESUBMIT.py @@ -267,7 +267,7 @@ def _CheckTestDuplicates(input_api, output_api): end_len = 4 else: continue - path = f.LocalPath()[:-end_len]; + path = f.LocalPath()[:-end_len] if path in tests_added: results.append(output_api.PresubmitError( 'Remove %s to prevent shadowing %s' % (path + '.pdf', @@ -276,6 +276,21 @@ def _CheckTestDuplicates(input_api, output_api): tests_added.append(path) return results +def _CheckPNGFormat(input_api, output_api): + """Checks that .png files have a format that will be considered valid by our + test runners. If a file ends with .png, then it must be of the form + NAME_expected(_(win|mac|linux))?.pdf.#.png""" + expected_pattern = input_api.re.compile( + r'.+_expected(_(win|mac|linux))?\.pdf\.\d+.png') + results = [] + for f in input_api.AffectedFiles(include_deletes=False): + if not f.LocalPath().endswith('.png'): + continue + if expected_pattern.match(f.LocalPath()): + continue + results.append(output_api.PresubmitError( + 'PNG file %s does not have the correct format' % f.LocalPath())) + return results def CheckChangeOnUpload(input_api, output_api): results = [] @@ -285,5 +300,6 @@ def CheckChangeOnUpload(input_api, output_api): input_api, output_api, None, LINT_FILTERS) results += _CheckIncludeOrder(input_api, output_api) results += _CheckTestDuplicates(input_api, output_api) + results += _CheckPNGFormat(input_api, output_api) return results diff --git a/chromium/third_party/pdfium/README.md b/chromium/third_party/pdfium/README.md index 5d7f47fea5d..ca443950a99 100644 --- a/chromium/third_party/pdfium/README.md +++ b/chromium/third_party/pdfium/README.md @@ -94,7 +94,6 @@ pdf_is_standalone = true # Set for a non-embedded build. is_component_build = false # Disable component build (must be false) clang_use_chrome_plugins = false # Currently must be false. -use_sysroot = false # Currently must be false on Linux, but entirely omitted on windows. ``` Note, you must set `pdf_is_standalone = true` if you want the sample @@ -133,6 +132,11 @@ differences on the various platforms. These tests are reliable on the bots. If you see failures, it can be a good idea to run the tests on the tip-of-tree checkout to see if the same failures appear. +## Code Coverage + +Code coverage reports for PDFium can be generated in Linux development +environments. Details can be found [here](/docs/code-coverage.md). + ## Waterfall The current health of the source tree can be found at @@ -163,7 +167,7 @@ For contributing code, we will follow as much as possible. The main exceptions are: 1. Code has to conform to the existing style and not Chromium/Google style. -2. PDFium uses a different tool for code reviews, and credentials for +2. PDFium uses a different tool for code reviews, and credentials for the tool need to be generated before uploading a CL. diff --git a/chromium/third_party/pdfium/core/fpdfapi/cmaps/CNS1/cmaps_cns1.cpp b/chromium/third_party/pdfium/core/fpdfapi/cmaps/CNS1/cmaps_cns1.cpp index a1bbefc1ab8..dc8a21776d4 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/cmaps/CNS1/cmaps_cns1.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/cmaps/CNS1/cmaps_cns1.cpp @@ -8,7 +8,7 @@ #include "core/fpdfapi/cmaps/cmap_int.h" #include "core/fpdfapi/cpdf_modulemgr.h" -#include "core/fpdfapi/font/font_int.h" +#include "core/fpdfapi/font/cpdf_fontglobals.h" #include "core/fpdfapi/page/cpdf_pagemodule.h" #include "core/fxcrt/fx_basic.h" diff --git a/chromium/third_party/pdfium/core/fpdfapi/cmaps/GB1/cmaps_gb1.cpp b/chromium/third_party/pdfium/core/fpdfapi/cmaps/GB1/cmaps_gb1.cpp index 9d15271e7e1..1591da1eca4 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/cmaps/GB1/cmaps_gb1.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/cmaps/GB1/cmaps_gb1.cpp @@ -8,7 +8,7 @@ #include "core/fpdfapi/cmaps/cmap_int.h" #include "core/fpdfapi/cpdf_modulemgr.h" -#include "core/fpdfapi/font/font_int.h" +#include "core/fpdfapi/font/cpdf_fontglobals.h" #include "core/fpdfapi/page/cpdf_pagemodule.h" #include "core/fxcrt/fx_basic.h" diff --git a/chromium/third_party/pdfium/core/fpdfapi/cmaps/Japan1/cmaps_japan1.cpp b/chromium/third_party/pdfium/core/fpdfapi/cmaps/Japan1/cmaps_japan1.cpp index bdf65595ad4..8fd4fcb7c41 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/cmaps/Japan1/cmaps_japan1.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/cmaps/Japan1/cmaps_japan1.cpp @@ -8,7 +8,7 @@ #include "core/fpdfapi/cmaps/cmap_int.h" #include "core/fpdfapi/cpdf_modulemgr.h" -#include "core/fpdfapi/font/font_int.h" +#include "core/fpdfapi/font/cpdf_fontglobals.h" #include "core/fpdfapi/page/cpdf_pagemodule.h" #include "core/fxcrt/fx_basic.h" diff --git a/chromium/third_party/pdfium/core/fpdfapi/cmaps/Korea1/cmaps_korea1.cpp b/chromium/third_party/pdfium/core/fpdfapi/cmaps/Korea1/cmaps_korea1.cpp index 5e88b3ba17f..8e9784e5de6 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/cmaps/Korea1/cmaps_korea1.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/cmaps/Korea1/cmaps_korea1.cpp @@ -8,7 +8,7 @@ #include "core/fpdfapi/cmaps/cmap_int.h" #include "core/fpdfapi/cpdf_modulemgr.h" -#include "core/fpdfapi/font/font_int.h" +#include "core/fpdfapi/font/cpdf_fontglobals.h" #include "core/fpdfapi/page/cpdf_pagemodule.h" #include "core/fxcrt/fx_basic.h" diff --git a/chromium/third_party/pdfium/core/fpdfapi/cmaps/fpdf_cmaps.cpp b/chromium/third_party/pdfium/core/fpdfapi/cmaps/fpdf_cmaps.cpp index cb2f09fb3cb..80ebbdef703 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/cmaps/fpdf_cmaps.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/cmaps/fpdf_cmaps.cpp @@ -7,7 +7,7 @@ #include "core/fpdfapi/cmaps/cmap_int.h" #include "core/fpdfapi/cpdf_modulemgr.h" -#include "core/fpdfapi/font/font_int.h" +#include "core/fpdfapi/font/cpdf_fontglobals.h" #include "core/fpdfapi/page/cpdf_pagemodule.h" extern "C" { @@ -61,7 +61,7 @@ void FPDFAPI_FindEmbeddedCMap(const CFX_ByteString& bsName, CPDF_FontGlobals* pFontGlobals = CPDF_ModuleMgr::Get()->GetPageModule()->GetFontGlobals(); const FXCMAP_CMap* pCMaps = - pFontGlobals->m_EmbeddedCharsets[charset].m_pMapList; + pFontGlobals->m_EmbeddedCharsets[charset].m_pMapList.Get(); for (uint32_t i = 0; i < pFontGlobals->m_EmbeddedCharsets[charset].m_Count; i++) { if (bsName == pCMaps[i].m_Name) { diff --git a/chromium/third_party/pdfium/core/fpdfapi/cpdf_pagerendercontext.h b/chromium/third_party/pdfium/core/fpdfapi/cpdf_pagerendercontext.h index 27244e7fc3a..5cbcdb77593 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/cpdf_pagerendercontext.h +++ b/chromium/third_party/pdfium/core/fpdfapi/cpdf_pagerendercontext.h @@ -21,11 +21,12 @@ class CPDF_PageRenderContext { CPDF_PageRenderContext(); ~CPDF_PageRenderContext(); + // Specific destruction order required. std::unique_ptr<CPDF_AnnotList> m_pAnnots; + std::unique_ptr<CPDF_RenderOptions> m_pOptions; std::unique_ptr<CFX_RenderDevice> m_pDevice; std::unique_ptr<CPDF_RenderContext> m_pContext; std::unique_ptr<CPDF_ProgressiveRenderer> m_pRenderer; - std::unique_ptr<CPDF_RenderOptions> m_pOptions; }; #endif // CORE_FPDFAPI_CPDF_PAGERENDERCONTEXT_H_ diff --git a/chromium/third_party/pdfium/core/fpdfapi/edit/cpdf_creator.cpp b/chromium/third_party/pdfium/core/fpdfapi/edit/cpdf_creator.cpp index 858d56cbaf4..ceffa5077f3 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/edit/cpdf_creator.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/edit/cpdf_creator.cpp @@ -323,9 +323,9 @@ bool CPDF_Creator::WriteOldIndirectObject(uint32_t objnum) { m_ObjectOffsets[objnum] = m_Archive->CurrentOffset(); bool bExistInMap = !!m_pDocument->GetIndirectObject(objnum); - const uint8_t object_type = m_pParser->GetObjectType(objnum); + const CPDF_Parser::ObjectType object_type = m_pParser->GetObjectType(objnum); if (m_pParser->IsVersionUpdated() || m_bSecurityChanged || bExistInMap || - (object_type == 2 && m_pEncryptDict)) { + (object_type == CPDF_Parser::ObjectType::kCompressed && m_pEncryptDict)) { CPDF_Object* pObj = m_pDocument->GetOrParseIndirectObject(objnum); if (!pObj) { m_ObjectOffsets.erase(objnum); @@ -341,7 +341,7 @@ bool CPDF_Creator::WriteOldIndirectObject(uint32_t objnum) { m_pParser->GetIndirectBinary(objnum, pBuffer, size); if (!pBuffer) return true; - if (object_type == 2) { + if (object_type == CPDF_Parser::ObjectType::kCompressed) { if (!m_Archive->WriteDWord(objnum) || !m_Archive->WriteString(" 0 obj ") || !m_Archive->WriteBlock(pBuffer, size) || @@ -412,7 +412,7 @@ void CPDF_Creator::InitNewObjNumOffsets() { continue; } if (m_pParser && m_pParser->IsValidObjectNumber(objnum) && - m_pParser->GetObjectType(objnum)) { + m_pParser->GetObjectType(objnum) != CPDF_Parser::ObjectType::kFree) { continue; } m_NewObjNumArray.insert(std::lower_bound(m_NewObjNumArray.begin(), diff --git a/chromium/third_party/pdfium/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp b/chromium/third_party/pdfium/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp index fe65e5916cc..18bcbf909dd 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp @@ -17,6 +17,7 @@ #include "core/fpdfapi/page/cpdf_path.h" #include "core/fpdfapi/page/cpdf_pathobject.h" #include "core/fpdfapi/page/cpdf_textobject.h" +#include "core/fpdfapi/parser/cpdf_array.h" #include "core/fpdfapi/parser/cpdf_dictionary.h" #include "core/fpdfapi/parser/cpdf_document.h" #include "core/fpdfapi/parser/cpdf_name.h" @@ -27,7 +28,7 @@ namespace { -CFX_ByteTextBuf& operator<<(CFX_ByteTextBuf& ar, const CFX_Matrix& matrix) { +std::ostream& operator<<(std::ostream& ar, const CFX_Matrix& matrix) { ar << matrix.a << " " << matrix.b << " " << matrix.c << " " << matrix.d << " " << matrix.e << " " << matrix.f; return ar; @@ -48,9 +49,10 @@ bool GetColor(const CPDF_Color* pColor, float* rgb) { } // namespace -CPDF_PageContentGenerator::CPDF_PageContentGenerator(CPDF_Page* pPage) - : m_pPage(pPage), m_pDocument(m_pPage->m_pDocument.Get()) { - for (const auto& pObj : *pPage->GetPageObjectList()) { +CPDF_PageContentGenerator::CPDF_PageContentGenerator( + CPDF_PageObjectHolder* pObjHolder) + : m_pObjHolder(pObjHolder), m_pDocument(pObjHolder->m_pDocument.Get()) { + for (const auto& pObj : *pObjHolder->GetPageObjectList()) { if (pObj) m_pageObjects.emplace_back(pObj.get()); } @@ -59,23 +61,62 @@ CPDF_PageContentGenerator::CPDF_PageContentGenerator(CPDF_Page* pPage) CPDF_PageContentGenerator::~CPDF_PageContentGenerator() {} void CPDF_PageContentGenerator::GenerateContent() { - CFX_ByteTextBuf buf; - for (auto& pPageObj : m_pageObjects) { - if (CPDF_ImageObject* pImageObject = pPageObj->AsImage()) - ProcessImage(&buf, pImageObject); - else if (CPDF_PathObject* pPathObj = pPageObj->AsPath()) - ProcessPath(&buf, pPathObj); - else if (CPDF_TextObject* pTextObj = pPageObj->AsText()) - ProcessText(&buf, pTextObj); - } - CPDF_Dictionary* pPageDict = m_pPage->m_pFormDict.Get(); - CPDF_Object* pContent = - pPageDict ? pPageDict->GetDirectObjectFor("Contents") : nullptr; - if (pContent) - pPageDict->RemoveFor("Contents"); + ASSERT(m_pObjHolder->IsPage()); + + CPDF_Document* pDoc = m_pDocument.Get(); + std::ostringstream buf; + + // Set the default graphic state values + buf << "q\n"; + if (!m_pObjHolder->GetLastCTM().IsIdentity()) + buf << m_pObjHolder->GetLastCTM().GetInverse() << " cm\n"; + ProcessDefaultGraphics(&buf); + + // Process the page objects + if (!ProcessPageObjects(&buf)) + return; + + // Return graphics to original state + buf << "Q\n"; - CPDF_Stream* pStream = m_pDocument->NewIndirect<CPDF_Stream>(); - pStream->SetData(buf.GetBuffer(), buf.GetLength()); + // Add buffer to a stream in page's 'Contents' + CPDF_Dictionary* pPageDict = m_pObjHolder->m_pFormDict.Get(); + CPDF_Object* pContent = + pPageDict ? pPageDict->GetObjectFor("Contents") : nullptr; + CPDF_Stream* pStream = pDoc->NewIndirect<CPDF_Stream>(); + pStream->SetData(&buf); + if (pContent) { + CPDF_Array* pArray = ToArray(pContent); + if (pArray) { + pArray->AddNew<CPDF_Reference>(pDoc, pStream->GetObjNum()); + return; + } + CPDF_Reference* pReference = ToReference(pContent); + if (!pReference) { + pPageDict->SetNewFor<CPDF_Reference>("Contents", m_pDocument.Get(), + pStream->GetObjNum()); + return; + } + CPDF_Object* pDirectObj = pReference->GetDirect(); + if (!pDirectObj) { + pPageDict->SetNewFor<CPDF_Reference>("Contents", m_pDocument.Get(), + pStream->GetObjNum()); + return; + } + CPDF_Array* pObjArray = pDirectObj->AsArray(); + if (pObjArray) { + pObjArray->AddNew<CPDF_Reference>(pDoc, pStream->GetObjNum()); + return; + } + if (pDirectObj->IsStream()) { + CPDF_Array* pContentArray = pDoc->NewIndirect<CPDF_Array>(); + pContentArray->AddNew<CPDF_Reference>(pDoc, pDirectObj->GetObjNum()); + pContentArray->AddNew<CPDF_Reference>(pDoc, pStream->GetObjNum()); + pPageDict->SetNewFor<CPDF_Reference>("Contents", pDoc, + pContentArray->GetObjNum()); + return; + } + } pPageDict->SetNewFor<CPDF_Reference>("Contents", m_pDocument.Get(), pStream->GetObjNum()); } @@ -84,14 +125,15 @@ CFX_ByteString CPDF_PageContentGenerator::RealizeResource( uint32_t dwResourceObjNum, const CFX_ByteString& bsType) { ASSERT(dwResourceObjNum); - if (!m_pPage->m_pResources) { - m_pPage->m_pResources = m_pDocument->NewIndirect<CPDF_Dictionary>(); - m_pPage->m_pFormDict->SetNewFor<CPDF_Reference>( - "Resources", m_pDocument.Get(), m_pPage->m_pResources->GetObjNum()); + if (!m_pObjHolder->m_pResources) { + m_pObjHolder->m_pResources = m_pDocument->NewIndirect<CPDF_Dictionary>(); + m_pObjHolder->m_pFormDict->SetNewFor<CPDF_Reference>( + "Resources", m_pDocument.Get(), + m_pObjHolder->m_pResources->GetObjNum()); } - CPDF_Dictionary* pResList = m_pPage->m_pResources->GetDictFor(bsType); + CPDF_Dictionary* pResList = m_pObjHolder->m_pResources->GetDictFor(bsType); if (!pResList) - pResList = m_pPage->m_pResources->SetNewFor<CPDF_Dictionary>(bsType); + pResList = m_pObjHolder->m_pResources->SetNewFor<CPDF_Dictionary>(bsType); CFX_ByteString name; int idnum = 1; @@ -107,7 +149,25 @@ CFX_ByteString CPDF_PageContentGenerator::RealizeResource( return name; } -void CPDF_PageContentGenerator::ProcessImage(CFX_ByteTextBuf* buf, +bool CPDF_PageContentGenerator::ProcessPageObjects(std::ostringstream* buf) { + bool bDirty = false; + for (auto& pPageObj : m_pageObjects) { + if (m_pObjHolder->IsPage() && !pPageObj->IsDirty()) + continue; + + bDirty = true; + if (CPDF_ImageObject* pImageObject = pPageObj->AsImage()) + ProcessImage(buf, pImageObject); + else if (CPDF_PathObject* pPathObj = pPageObj->AsPath()) + ProcessPath(buf, pPathObj); + else if (CPDF_TextObject* pTextObj = pPageObj->AsText()) + ProcessText(buf, pTextObj); + pPageObj->SetDirty(false); + } + return bDirty; +} + +void CPDF_PageContentGenerator::ProcessImage(std::ostringstream* buf, CPDF_ImageObject* pImageObj) { if ((pImageObj->matrix().a == 0 && pImageObj->matrix().b == 0) || (pImageObj->matrix().c == 0 && pImageObj->matrix().d == 0)) { @@ -146,9 +206,12 @@ void CPDF_PageContentGenerator::ProcessImage(CFX_ByteTextBuf* buf, // Path painting operators: "S", "n", "B", "f", "B*", "f*", depending on // the filling mode and whether we want stroking the path or not. // "Q" restores the graphics state imposed by the ProcessGraphics method. -void CPDF_PageContentGenerator::ProcessPath(CFX_ByteTextBuf* buf, +void CPDF_PageContentGenerator::ProcessPath(std::ostringstream* buf, CPDF_PathObject* pPathObj) { ProcessGraphics(buf, pPathObj); + + *buf << pPathObj->m_Matrix << " cm "; + auto& pPoints = pPathObj->m_Path.GetPoints(); if (pPathObj->m_Path.IsRect()) { CFX_PointF diff = pPoints[2].m_Point - pPoints[0].m_Point; @@ -199,7 +262,7 @@ void CPDF_PageContentGenerator::ProcessPath(CFX_ByteTextBuf* buf, // "w" sets the stroke line width. // "ca" sets the fill alpha, "CA" sets the stroke alpha. // "q" saves the graphics state, so that the settings can later be reversed -void CPDF_PageContentGenerator::ProcessGraphics(CFX_ByteTextBuf* buf, +void CPDF_PageContentGenerator::ProcessGraphics(std::ostringstream* buf, CPDF_PageObject* pPageObj) { *buf << "q "; float fillColor[3]; @@ -215,34 +278,79 @@ void CPDF_PageContentGenerator::ProcessGraphics(CFX_ByteTextBuf* buf, float lineWidth = pPageObj->m_GraphState.GetLineWidth(); if (lineWidth != 1.0f) *buf << lineWidth << " w "; + CFX_GraphStateData::LineCap lineCap = pPageObj->m_GraphState.GetLineCap(); + if (lineCap != CFX_GraphStateData::LineCapButt) + *buf << static_cast<int>(lineCap) << " J "; + CFX_GraphStateData::LineJoin lineJoin = pPageObj->m_GraphState.GetLineJoin(); + if (lineJoin != CFX_GraphStateData::LineJoinMiter) + *buf << static_cast<int>(lineJoin) << " j "; GraphicsData graphD; graphD.fillAlpha = pPageObj->m_GeneralState.GetFillAlpha(); graphD.strokeAlpha = pPageObj->m_GeneralState.GetStrokeAlpha(); - if (graphD.fillAlpha == 1.0f && graphD.strokeAlpha == 1.0f) + graphD.blendType = pPageObj->m_GeneralState.GetBlendType(); + if (graphD.fillAlpha == 1.0f && graphD.strokeAlpha == 1.0f && + (graphD.blendType == FXDIB_BLEND_UNSUPPORTED || + graphD.blendType == FXDIB_BLEND_NORMAL)) { return; + } CFX_ByteString name; - auto it = m_pPage->m_GraphicsMap.find(graphD); - if (it != m_pPage->m_GraphicsMap.end()) { + auto it = m_pObjHolder->m_GraphicsMap.find(graphD); + if (it != m_pObjHolder->m_GraphicsMap.end()) { name = it->second; } else { auto gsDict = pdfium::MakeUnique<CPDF_Dictionary>(); - gsDict->SetNewFor<CPDF_Number>("ca", graphD.fillAlpha); - gsDict->SetNewFor<CPDF_Number>("CA", graphD.strokeAlpha); + if (graphD.fillAlpha != 1.0f) + gsDict->SetNewFor<CPDF_Number>("ca", graphD.fillAlpha); + + if (graphD.strokeAlpha != 1.0f) + gsDict->SetNewFor<CPDF_Number>("CA", graphD.strokeAlpha); + + if (graphD.blendType != FXDIB_BLEND_UNSUPPORTED && + graphD.blendType != FXDIB_BLEND_NORMAL) { + gsDict->SetNewFor<CPDF_Name>("BM", + pPageObj->m_GeneralState.GetBlendMode()); + } CPDF_Object* pDict = m_pDocument->AddIndirectObject(std::move(gsDict)); uint32_t dwObjNum = pDict->GetObjNum(); name = RealizeResource(dwObjNum, "ExtGState"); - m_pPage->m_GraphicsMap[graphD] = name; + m_pObjHolder->m_GraphicsMap[graphD] = name; } *buf << "/" << PDF_NameEncode(name) << " gs "; } +void CPDF_PageContentGenerator::ProcessDefaultGraphics( + std::ostringstream* buf) { + *buf << "0 0 0 RG 0 0 0 rg 1 w " + << static_cast<int>(CFX_GraphStateData::LineCapButt) << " J " + << static_cast<int>(CFX_GraphStateData::LineJoinMiter) << " j\n"; + GraphicsData defaultGraphics; + defaultGraphics.fillAlpha = 1.0f; + defaultGraphics.strokeAlpha = 1.0f; + defaultGraphics.blendType = FXDIB_BLEND_NORMAL; + auto it = m_pObjHolder->m_GraphicsMap.find(defaultGraphics); + CFX_ByteString name; + if (it != m_pObjHolder->m_GraphicsMap.end()) { + name = it->second; + } else { + auto gsDict = pdfium::MakeUnique<CPDF_Dictionary>(); + gsDict->SetNewFor<CPDF_Number>("ca", defaultGraphics.fillAlpha); + gsDict->SetNewFor<CPDF_Number>("CA", defaultGraphics.strokeAlpha); + gsDict->SetNewFor<CPDF_Name>("BM", "Normal"); + CPDF_Object* pDict = m_pDocument->AddIndirectObject(std::move(gsDict)); + uint32_t dwObjNum = pDict->GetObjNum(); + name = RealizeResource(dwObjNum, "ExtGState"); + m_pObjHolder->m_GraphicsMap[defaultGraphics] = name; + } + *buf << "/" << PDF_NameEncode(name).c_str() << " gs "; +} + // This method adds text to the buffer, BT begins the text object, ET ends it. // Tm sets the text matrix (allows positioning and transforming text). // Tf sets the font name (from Font in Resources) and font size. // Tj sets the actual text, <####...> is used when specifying charcodes. -void CPDF_PageContentGenerator::ProcessText(CFX_ByteTextBuf* buf, +void CPDF_PageContentGenerator::ProcessText(std::ostringstream* buf, CPDF_TextObject* pTextObj) { *buf << "BT " << pTextObj->GetTextMatrix() << " Tm "; CPDF_Font* pFont = pTextObj->GetFont(); @@ -258,9 +366,9 @@ void CPDF_PageContentGenerator::ProcessText(CFX_ByteTextBuf* buf, else return; fontD.baseFont = pFont->GetBaseFont(); - auto it = m_pPage->m_FontsMap.find(fontD); + auto it = m_pObjHolder->m_FontsMap.find(fontD); CFX_ByteString dictName; - if (it != m_pPage->m_FontsMap.end()) { + if (it != m_pObjHolder->m_FontsMap.end()) { dictName = it->second; } else { uint32_t dwObjNum = pFont->GetFontDict()->GetObjNum(); @@ -274,7 +382,7 @@ void CPDF_PageContentGenerator::ProcessText(CFX_ByteTextBuf* buf, dwObjNum = pDict->GetObjNum(); } dictName = RealizeResource(dwObjNum, "Font"); - m_pPage->m_FontsMap[fontD] = dictName; + m_pObjHolder->m_FontsMap[fontD] = dictName; } *buf << "/" << PDF_NameEncode(dictName) << " " << pTextObj->GetFontSize() << " Tf "; @@ -283,5 +391,7 @@ void CPDF_PageContentGenerator::ProcessText(CFX_ByteTextBuf* buf, if (charcode != CPDF_Font::kInvalidCharCode) pFont->AppendChar(&text, charcode); } - *buf << PDF_EncodeString(text, true) << " Tj ET\n"; + ProcessGraphics(buf, pTextObj); + *buf << PDF_EncodeString(text, true) << " Tj ET"; + *buf << " Q\n"; } diff --git a/chromium/third_party/pdfium/core/fpdfapi/edit/cpdf_pagecontentgenerator.h b/chromium/third_party/pdfium/core/fpdfapi/edit/cpdf_pagecontentgenerator.h index 6c54d3130ed..5295d8747bb 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/edit/cpdf_pagecontentgenerator.h +++ b/chromium/third_party/pdfium/core/fpdfapi/edit/cpdf_pagecontentgenerator.h @@ -7,6 +7,7 @@ #ifndef CORE_FPDFAPI_EDIT_CPDF_PAGECONTENTGENERATOR_H_ #define CORE_FPDFAPI_EDIT_CPDF_PAGECONTENTGENERATOR_H_ +#include <sstream> #include <vector> #include "core/fxcrt/cfx_unowned_ptr.h" @@ -15,29 +16,31 @@ class CPDF_Document; class CPDF_ImageObject; -class CPDF_Page; class CPDF_PageObject; +class CPDF_PageObjectHolder; class CPDF_PathObject; class CPDF_TextObject; class CPDF_PageContentGenerator { public: - explicit CPDF_PageContentGenerator(CPDF_Page* pPage); + explicit CPDF_PageContentGenerator(CPDF_PageObjectHolder* pObjHolder); ~CPDF_PageContentGenerator(); void GenerateContent(); + bool ProcessPageObjects(std::ostringstream* buf); private: friend class CPDF_PageContentGeneratorTest; - void ProcessPath(CFX_ByteTextBuf* buf, CPDF_PathObject* pPathObj); - void ProcessImage(CFX_ByteTextBuf* buf, CPDF_ImageObject* pImageObj); - void ProcessGraphics(CFX_ByteTextBuf* buf, CPDF_PageObject* pPageObj); - void ProcessText(CFX_ByteTextBuf* buf, CPDF_TextObject* pTextObj); + void ProcessPath(std::ostringstream* buf, CPDF_PathObject* pPathObj); + void ProcessImage(std::ostringstream* buf, CPDF_ImageObject* pImageObj); + void ProcessGraphics(std::ostringstream* buf, CPDF_PageObject* pPageObj); + void ProcessDefaultGraphics(std::ostringstream* buf); + void ProcessText(std::ostringstream* buf, CPDF_TextObject* pTextObj); CFX_ByteString RealizeResource(uint32_t dwResourceObjNum, const CFX_ByteString& bsType); - CFX_UnownedPtr<CPDF_Page> const m_pPage; + CFX_UnownedPtr<CPDF_PageObjectHolder> const m_pObjHolder; CFX_UnownedPtr<CPDF_Document> const m_pDocument; std::vector<CFX_UnownedPtr<CPDF_PageObject>> m_pageObjects; }; diff --git a/chromium/third_party/pdfium/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp b/chromium/third_party/pdfium/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp index 1f2d216ed51..62b10c91499 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp @@ -4,8 +4,12 @@ #include "core/fpdfapi/edit/cpdf_pagecontentgenerator.h" +#include <memory> +#include <utility> + #include "core/fpdfapi/cpdf_modulemgr.h" #include "core/fpdfapi/font/cpdf_font.h" +#include "core/fpdfapi/page/cpdf_form.h" #include "core/fpdfapi/page/cpdf_page.h" #include "core/fpdfapi/page/cpdf_pathobject.h" #include "core/fpdfapi/page/cpdf_textobject.h" @@ -26,7 +30,7 @@ class CPDF_PageContentGeneratorTest : public testing::Test { } void TestProcessPath(CPDF_PageContentGenerator* pGen, - CFX_ByteTextBuf* buf, + std::ostringstream* buf, CPDF_PathObject* pPathObj) { pGen->ProcessPath(buf, pPathObj); } @@ -34,11 +38,11 @@ class CPDF_PageContentGeneratorTest : public testing::Test { CPDF_Dictionary* TestGetResource(CPDF_PageContentGenerator* pGen, const CFX_ByteString& type, const CFX_ByteString& name) { - return pGen->m_pPage->m_pResources->GetDictFor(type)->GetDictFor(name); + return pGen->m_pObjHolder->m_pResources->GetDictFor(type)->GetDictFor(name); } void TestProcessText(CPDF_PageContentGenerator* pGen, - CFX_ByteTextBuf* buf, + std::ostringstream* buf, CPDF_TextObject* pTextObj) { pGen->ProcessText(buf, pTextObj); } @@ -52,9 +56,9 @@ TEST_F(CPDF_PageContentGeneratorTest, ProcessRect) { auto pTestPage = pdfium::MakeUnique<CPDF_Page>(nullptr, nullptr, false); CPDF_PageContentGenerator generator(pTestPage.get()); - CFX_ByteTextBuf buf; + std::ostringstream buf; TestProcessPath(&generator, &buf, pPathObj.get()); - EXPECT_EQ("q 10 5 3 25 re B* Q\n", buf.MakeString()); + EXPECT_EQ("q 1 0 0 1 0 0 cm 10 5 3 25 re B* Q\n", CFX_ByteString(buf)); pPathObj = pdfium::MakeUnique<CPDF_PathObject>(); pPathObj->m_Path.AppendPoint(CFX_PointF(0, 0), FXPT_TYPE::MoveTo, false); @@ -64,10 +68,10 @@ TEST_F(CPDF_PageContentGeneratorTest, ProcessRect) { pPathObj->m_Path.AppendPoint(CFX_PointF(0, 3.78f), FXPT_TYPE::LineTo, true); pPathObj->m_FillType = 0; pPathObj->m_bStroke = false; - buf.Clear(); + buf.str(""); TestProcessPath(&generator, &buf, pPathObj.get()); - EXPECT_EQ("q 0 0 5.2 3.78 re n Q\n", buf.MakeString()); + EXPECT_EQ("q 1 0 0 1 0 0 cm 0 0 5.2 3.78 re n Q\n", CFX_ByteString(buf)); } TEST_F(CPDF_PageContentGeneratorTest, ProcessPath) { @@ -96,12 +100,12 @@ TEST_F(CPDF_PageContentGeneratorTest, ProcessPath) { auto pTestPage = pdfium::MakeUnique<CPDF_Page>(nullptr, nullptr, false); CPDF_PageContentGenerator generator(pTestPage.get()); - CFX_ByteTextBuf buf; + std::ostringstream buf; TestProcessPath(&generator, &buf, pPathObj.get()); EXPECT_EQ( - "q 3.102 4.67 m 5.45 0.29 l 4.24 3.15 4.65 2.98 3.456 0.24 c 10.6 11.15 " - "l 11 12.5 l 11.46 12.67 11.84 12.96 12 13.64 c h f Q\n", - buf.MakeString()); + "q 1 0 0 1 0 0 cm 3.102 4.67 m 5.45 0.29 l 4.24 3.15 4.65 2.98 3.456 0.24" + " c 10.6 11.15 l 11 12.5 l 11.46 12.67 11.84 12.96 12 13.64 c h f Q\n", + CFX_ByteString(buf)); } TEST_F(CPDF_PageContentGeneratorTest, ProcessGraphics) { @@ -126,29 +130,31 @@ TEST_F(CPDF_PageContentGeneratorTest, ProcessGraphics) { CPDF_Dictionary* pPageDict = pDoc->CreateNewPage(0); auto pTestPage = pdfium::MakeUnique<CPDF_Page>(pDoc.get(), pPageDict, false); CPDF_PageContentGenerator generator(pTestPage.get()); - CFX_ByteTextBuf buf; + std::ostringstream buf; TestProcessPath(&generator, &buf, pPathObj.get()); - CFX_ByteString pathString = buf.MakeString(); + CFX_ByteString pathString(buf); // Color RGB values used are integers divided by 255. EXPECT_EQ("q 0.501961 0.701961 0.34902 rg 1 0.901961 0 RG /", pathString.Left(48)); - EXPECT_EQ(" gs 1 2 m 3 4 l 5 6 l h B Q\n", pathString.Right(28)); - ASSERT_TRUE(pathString.GetLength() > 76); + EXPECT_EQ(" gs 1 0 0 1 0 0 cm 1 2 m 3 4 l 5 6 l h B Q\n", + pathString.Right(43)); + ASSERT_TRUE(pathString.GetLength() > 91); CPDF_Dictionary* externalGS = TestGetResource( - &generator, "ExtGState", pathString.Mid(48, pathString.GetLength() - 76)); + &generator, "ExtGState", pathString.Mid(48, pathString.GetLength() - 91)); ASSERT_TRUE(externalGS); EXPECT_EQ(0.5f, externalGS->GetNumberFor("ca")); EXPECT_EQ(0.8f, externalGS->GetNumberFor("CA")); // Same path, now with a stroke. pPathObj->m_GraphState.SetLineWidth(10.5f); - buf.Clear(); + buf.str(""); TestProcessPath(&generator, &buf, pPathObj.get()); - CFX_ByteString pathString2 = buf.MakeString(); + CFX_ByteString pathString2(buf); EXPECT_EQ("q 0.501961 0.701961 0.34902 rg 1 0.901961 0 RG 10.5 w /", pathString2.Left(55)); - EXPECT_EQ(" gs 1 2 m 3 4 l 5 6 l h B Q\n", pathString2.Right(28)); + EXPECT_EQ(" gs 1 0 0 1 0 0 cm 1 2 m 3 4 l 5 6 l h B Q\n", + pathString2.Right(43)); // Compare with the previous (should use same dictionary for gs) EXPECT_EQ(pathString.GetLength() + 7, pathString2.GetLength()); @@ -167,16 +173,46 @@ TEST_F(CPDF_PageContentGeneratorTest, ProcessStandardText) { CPDF_Font* pFont = CPDF_Font::GetStockFont(pDoc.get(), "Times-Roman"); pTextObj->m_TextState.SetFont(pFont); pTextObj->m_TextState.SetFontSize(10.0f); + float rgb[3] = {0.5f, 0.7f, 0.35f}; + CPDF_ColorSpace* pCS = CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB); + pTextObj->m_ColorState.SetFillColor(pCS, rgb, 3); + + float rgb2[3] = {1, 0.9f, 0}; + pTextObj->m_ColorState.SetStrokeColor(pCS, rgb2, 3); + pTextObj->m_GeneralState.SetFillAlpha(0.5f); + pTextObj->m_GeneralState.SetStrokeAlpha(0.8f); pTextObj->Transform(CFX_Matrix(1, 0, 0, 1, 100, 100)); pTextObj->SetText("Hello World"); - CFX_ByteTextBuf buf; + std::ostringstream buf; TestProcessText(&generator, &buf, pTextObj.get()); - CFX_ByteString textString = buf.MakeString(); - EXPECT_LT(61, textString.GetLength()); - EXPECT_EQ("BT 1 0 0 1 100 100 Tm /", textString.Left(23)); - EXPECT_EQ(" 10 Tf <48656C6C6F20576F726C64> Tj ET\n", textString.Right(38)); + CFX_ByteString textString(buf); + int firstResourceAt = textString.Find('/') + 1; + int secondResourceAt = textString.ReverseFind('/') + 1; + CFX_ByteString firstString = textString.Left(firstResourceAt); + CFX_ByteString midString = + textString.Mid(firstResourceAt, secondResourceAt - firstResourceAt); + CFX_ByteString lastString = + textString.Right(textString.GetLength() - secondResourceAt); + CFX_ByteString compareString1 = "BT 1 0 0 1 100 100 Tm /"; + // Color RGB values used are integers divided by 255. + CFX_ByteString compareString2 = + " 10 Tf q 0.501961 0.701961 0.34902 rg 1 0.901961 0 RG /"; + CFX_ByteString compareString3 = " gs <48656C6C6F20576F726C64> Tj ET Q\n"; + EXPECT_LT(compareString1.GetLength() + compareString2.GetLength() + + compareString3.GetLength(), + textString.GetLength()); + EXPECT_EQ(compareString1, firstString.Left(compareString1.GetLength())); + EXPECT_EQ(compareString2, midString.Right(compareString2.GetLength())); + EXPECT_EQ(compareString3, lastString.Right(compareString3.GetLength())); + CPDF_Dictionary* externalGS = TestGetResource( + &generator, "ExtGState", + lastString.Left(lastString.GetLength() - compareString3.GetLength())); + ASSERT_TRUE(externalGS); + EXPECT_EQ(0.5f, externalGS->GetNumberFor("ca")); + EXPECT_EQ(0.8f, externalGS->GetNumberFor("CA")); CPDF_Dictionary* fontDict = TestGetResource( - &generator, "Font", textString.Mid(23, textString.GetLength() - 61)); + &generator, "Font", + midString.Left(midString.GetLength() - compareString2.GetLength())); ASSERT_TRUE(fontDict); EXPECT_EQ("Font", fontDict->GetStringFor("Type")); EXPECT_EQ("Type1", fontDict->GetStringFor("Subtype")); @@ -191,7 +227,7 @@ TEST_F(CPDF_PageContentGeneratorTest, ProcessText) { auto pTestPage = pdfium::MakeUnique<CPDF_Page>(pDoc.get(), pPageDict, false); CPDF_PageContentGenerator generator(pTestPage.get()); - CFX_ByteTextBuf buf; + std::ostringstream buf; { // Set the text object font and text auto pTextObj = pdfium::MakeUnique<CPDF_TextObject>(); @@ -215,13 +251,23 @@ TEST_F(CPDF_PageContentGeneratorTest, ProcessText) { TestProcessText(&generator, &buf, pTextObj.get()); } - CFX_ByteString textString = buf.MakeString(); - EXPECT_LT(63, textString.GetLength()); - EXPECT_EQ("BT 1 0 0 1 0 0 Tm /", textString.Left(19)); - EXPECT_EQ(" 15.5 Tf <4920616D20696E646972656374> Tj ET\n", - textString.Right(44)); + CFX_ByteString textString(buf); + int firstResourceAt = textString.Find('/') + 1; + CFX_ByteString firstString = textString.Left(firstResourceAt); + CFX_ByteString lastString = + textString.Right(textString.GetLength() - firstResourceAt); + CFX_ByteString compareString1 = "BT 1 0 0 1 0 0 Tm /"; + CFX_ByteString compareString2 = + " 15.5 Tf q <4920616D20696E646972656374> Tj ET Q\n"; + EXPECT_LT(compareString1.GetLength() + compareString2.GetLength(), + textString.GetLength()); + EXPECT_EQ(compareString1, textString.Left(compareString1.GetLength())); + EXPECT_EQ(compareString2, textString.Right(compareString2.GetLength())); CPDF_Dictionary* fontDict = TestGetResource( - &generator, "Font", textString.Mid(19, textString.GetLength() - 63)); + &generator, "Font", + textString.Mid(compareString1.GetLength(), + textString.GetLength() - compareString1.GetLength() - + compareString2.GetLength())); ASSERT_TRUE(fontDict); EXPECT_TRUE(fontDict->GetObjNum()); EXPECT_EQ("Font", fontDict->GetStringFor("Type")); @@ -233,3 +279,47 @@ TEST_F(CPDF_PageContentGeneratorTest, ProcessText) { EXPECT_EQ("FontDescriptor", fontDesc->GetStringFor("Type")); EXPECT_EQ("Helvetica", fontDesc->GetStringFor("FontName")); } + +TEST_F(CPDF_PageContentGeneratorTest, ProcessEmptyForm) { + auto pDoc = pdfium::MakeUnique<CPDF_Document>(nullptr); + pDoc->CreateNewDoc(); + auto pDict = pdfium::MakeUnique<CPDF_Dictionary>(); + auto pStream = pdfium::MakeUnique<CPDF_Stream>(nullptr, 0, std::move(pDict)); + + // Create an empty form. + auto pTestForm = + pdfium::MakeUnique<CPDF_Form>(pDoc.get(), nullptr, pStream.get()); + pTestForm->ParseContent(nullptr, nullptr, nullptr); + ASSERT_TRUE(pTestForm->IsParsed()); + + // The generated stream for the empty form should be an empty string. + CPDF_PageContentGenerator generator(pTestForm.get()); + std::ostringstream buf; + generator.ProcessPageObjects(&buf); + EXPECT_EQ("", CFX_ByteString(buf)); +} + +TEST_F(CPDF_PageContentGeneratorTest, ProcessFormWithPath) { + auto pDoc = pdfium::MakeUnique<CPDF_Document>(nullptr); + pDoc->CreateNewDoc(); + auto pDict = pdfium::MakeUnique<CPDF_Dictionary>(); + const char content[] = + "q 1 0 0 1 0 0 cm 3.102 4.67 m 5.45 0.29 l 4.24 3.15 4.65 2.98 3.456 " + "0.24 c 3.102 4.67 l h f Q\n"; + size_t buf_len = FX_ArraySize(content); + std::unique_ptr<uint8_t, FxFreeDeleter> buf(FX_Alloc(uint8_t, buf_len)); + memcpy(buf.get(), content, buf_len); + auto pStream = pdfium::MakeUnique<CPDF_Stream>(std::move(buf), buf_len, + std::move(pDict)); + + // Create a form with a non-empty stream. + auto pTestForm = + pdfium::MakeUnique<CPDF_Form>(pDoc.get(), nullptr, pStream.get()); + pTestForm->ParseContent(nullptr, nullptr, nullptr); + ASSERT_TRUE(pTestForm->IsParsed()); + + CPDF_PageContentGenerator generator(pTestForm.get()); + std::ostringstream process_buf; + generator.ProcessPageObjects(&process_buf); + EXPECT_EQ(content, CFX_ByteString(process_buf)); +} diff --git a/chromium/third_party/pdfium/core/fpdfapi/font/ttgsubtable.cpp b/chromium/third_party/pdfium/core/fpdfapi/font/cfx_cttgsubtable.cpp index b8d6946657d..902957a4366 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/font/ttgsubtable.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/font/cfx_cttgsubtable.cpp @@ -4,7 +4,7 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "core/fpdfapi/font/ttgsubtable.h" +#include "core/fpdfapi/font/cfx_cttgsubtable.h" #include <utility> diff --git a/chromium/third_party/pdfium/core/fpdfapi/font/ttgsubtable.h b/chromium/third_party/pdfium/core/fpdfapi/font/cfx_cttgsubtable.h index c3bff439575..aac3f86c077 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/font/ttgsubtable.h +++ b/chromium/third_party/pdfium/core/fpdfapi/font/cfx_cttgsubtable.h @@ -4,8 +4,8 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef CORE_FPDFAPI_FONT_TTGSUBTABLE_H_ -#define CORE_FPDFAPI_FONT_TTGSUBTABLE_H_ +#ifndef CORE_FPDFAPI_FONT_CFX_CTTGSUBTABLE_H_ +#define CORE_FPDFAPI_FONT_CFX_CTTGSUBTABLE_H_ #include <stdint.h> @@ -295,4 +295,4 @@ class CFX_CTTGSUBTable { TLookupList LookupList; }; -#endif // CORE_FPDFAPI_FONT_TTGSUBTABLE_H_ +#endif // CORE_FPDFAPI_FONT_CFX_CTTGSUBTABLE_H_ diff --git a/chromium/third_party/pdfium/core/fpdfapi/font/cfx_stockfontarray.cpp b/chromium/third_party/pdfium/core/fpdfapi/font/cfx_stockfontarray.cpp new file mode 100644 index 00000000000..0808471c82b --- /dev/null +++ b/chromium/third_party/pdfium/core/fpdfapi/font/cfx_stockfontarray.cpp @@ -0,0 +1,35 @@ +// Copyright 2017 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/fpdfapi/font/cfx_stockfontarray.h" + +#include <memory> +#include <utility> + +#include "core/fxcrt/fx_memory.h" + +CFX_StockFontArray::CFX_StockFontArray() {} + +CFX_StockFontArray::~CFX_StockFontArray() { + for (size_t i = 0; i < FX_ArraySize(m_StockFonts); ++i) { + if (m_StockFonts[i]) + delete m_StockFonts[i]->GetFontDict(); + } +} + +CPDF_Font* CFX_StockFontArray::GetFont(uint32_t index) const { + if (index >= FX_ArraySize(m_StockFonts)) + return nullptr; + return m_StockFonts[index].get(); +} + +CPDF_Font* CFX_StockFontArray::SetFont(uint32_t index, + std::unique_ptr<CPDF_Font> pFont) { + CPDF_Font* result = pFont.get(); + if (index < FX_ArraySize(m_StockFonts)) + m_StockFonts[index] = std::move(pFont); + return result; +} diff --git a/chromium/third_party/pdfium/core/fpdfapi/font/cfx_stockfontarray.h b/chromium/third_party/pdfium/core/fpdfapi/font/cfx_stockfontarray.h new file mode 100644 index 00000000000..50a13c167fa --- /dev/null +++ b/chromium/third_party/pdfium/core/fpdfapi/font/cfx_stockfontarray.h @@ -0,0 +1,27 @@ +// Copyright 2017 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 + +#ifndef CORE_FPDFAPI_FONT_CFX_STOCKFONTARRAY_H_ +#define CORE_FPDFAPI_FONT_CFX_STOCKFONTARRAY_H_ + +#include <memory> + +#include "core/fpdfapi/font/cpdf_font.h" + +class CFX_StockFontArray { + public: + CFX_StockFontArray(); + ~CFX_StockFontArray(); + + // Takes ownership of |pFont|, returns unowned pointer to it. + CPDF_Font* SetFont(uint32_t index, std::unique_ptr<CPDF_Font> pFont); + CPDF_Font* GetFont(uint32_t index) const; + + private: + std::unique_ptr<CPDF_Font> m_StockFonts[14]; +}; + +#endif // CORE_FPDFAPI_FONT_CFX_STOCKFONTARRAY_H_ diff --git a/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_cid2unicodemap.cpp b/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_cid2unicodemap.cpp new file mode 100644 index 00000000000..cb378aa9d66 --- /dev/null +++ b/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_cid2unicodemap.cpp @@ -0,0 +1,42 @@ +// Copyright 2017 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/fpdfapi/font/cpdf_cid2unicodemap.h" + +#include "core/fpdfapi/cpdf_modulemgr.h" +#include "core/fpdfapi/font/cpdf_cmapmanager.h" +#include "core/fpdfapi/page/cpdf_pagemodule.h" + +CPDF_CID2UnicodeMap::CPDF_CID2UnicodeMap() { + m_EmbeddedCount = 0; +} + +CPDF_CID2UnicodeMap::~CPDF_CID2UnicodeMap() {} + +bool CPDF_CID2UnicodeMap::IsLoaded() { + return m_EmbeddedCount != 0; +} + +wchar_t CPDF_CID2UnicodeMap::UnicodeFromCID(uint16_t CID) { + if (m_Charset == CIDSET_UNICODE) { + return CID; + } + if (CID < m_EmbeddedCount) { + return m_pEmbeddedMap[CID]; + } + return 0; +} + +void CPDF_CID2UnicodeMap::Load(CPDF_CMapManager* pMgr, + CIDSet charset, + bool bPromptCJK) { + m_Charset = charset; + + CPDF_FontGlobals* pFontGlobals = + CPDF_ModuleMgr::Get()->GetPageModule()->GetFontGlobals(); + m_pEmbeddedMap = pFontGlobals->m_EmbeddedToUnicodes[charset].m_pMap; + m_EmbeddedCount = pFontGlobals->m_EmbeddedToUnicodes[charset].m_Count; +} diff --git a/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_cid2unicodemap.h b/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_cid2unicodemap.h new file mode 100644 index 00000000000..2c3fe5b7aac --- /dev/null +++ b/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_cid2unicodemap.h @@ -0,0 +1,29 @@ +// Copyright 2017 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 + +#ifndef CORE_FPDFAPI_FONT_CPDF_CID2UNICODEMAP_H_ +#define CORE_FPDFAPI_FONT_CPDF_CID2UNICODEMAP_H_ + +#include "core/fpdfapi/font/cpdf_cidfont.h" + +class CPDF_CMapManager; + +class CPDF_CID2UnicodeMap { + public: + CPDF_CID2UnicodeMap(); + ~CPDF_CID2UnicodeMap(); + + bool IsLoaded(); + void Load(CPDF_CMapManager* pMgr, CIDSet charset, bool bPromptCJK); + wchar_t UnicodeFromCID(uint16_t CID); + + private: + CIDSet m_Charset; + const uint16_t* m_pEmbeddedMap; + uint32_t m_EmbeddedCount; +}; + +#endif // CORE_FPDFAPI_FONT_CPDF_CID2UNICODEMAP_H_ diff --git a/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_cidfont.cpp b/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_cidfont.cpp index c41f8046f74..8cb59de7392 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_cidfont.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_cidfont.cpp @@ -12,9 +12,11 @@ #include "core/fpdfapi/cmaps/cmap_int.h" #include "core/fpdfapi/cpdf_modulemgr.h" +#include "core/fpdfapi/font/cfx_cttgsubtable.h" +#include "core/fpdfapi/font/cpdf_cid2unicodemap.h" +#include "core/fpdfapi/font/cpdf_cmap.h" +#include "core/fpdfapi/font/cpdf_cmapparser.h" #include "core/fpdfapi/font/cpdf_fontencoding.h" -#include "core/fpdfapi/font/font_int.h" -#include "core/fpdfapi/font/ttgsubtable.h" #include "core/fpdfapi/page/cpdf_pagemodule.h" #include "core/fpdfapi/parser/cpdf_array.h" #include "core/fpdfapi/parser/cpdf_dictionary.h" @@ -377,8 +379,8 @@ bool CPDF_CIDFont::Load() { if (m_Charset == CIDSET_UNKNOWN) { CPDF_Dictionary* pCIDInfo = pCIDFontDict->GetDictFor("CIDSystemInfo"); if (pCIDInfo) { - m_Charset = - CharsetFromOrdering(pCIDInfo->GetStringFor("Ordering").AsStringC()); + m_Charset = CPDF_CMapParser::CharsetFromOrdering( + pCIDInfo->GetStringFor("Ordering").AsStringC()); } } if (m_Charset != CIDSET_UNKNOWN) { diff --git a/chromium/third_party/pdfium/core/fpdfapi/font/fpdf_font_cid.cpp b/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_cmap.cpp index dd37551b2d7..55f5ccc5c5f 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/font/fpdf_font_cid.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_cmap.cpp @@ -1,31 +1,22 @@ -// Copyright 2014 PDFium Authors. All rights reserved. +// Copyright 2017 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/fpdfapi/font/font_int.h" +#include "core/fpdfapi/font/cpdf_cmap.h" #include <memory> #include <utility> #include <vector> #include "core/fpdfapi/cmaps/cmap_int.h" -#include "core/fpdfapi/cpdf_modulemgr.h" -#include "core/fpdfapi/font/ttgsubtable.h" -#include "core/fpdfapi/page/cpdf_pagemodule.h" -#include "core/fpdfapi/parser/cpdf_array.h" -#include "core/fpdfapi/parser/cpdf_dictionary.h" +#include "core/fpdfapi/font/cpdf_cmapmanager.h" +#include "core/fpdfapi/font/cpdf_cmapparser.h" #include "core/fpdfapi/parser/cpdf_simple_parser.h" -#include "core/fxcrt/fx_extension.h" -#include "core/fxge/fx_freetype.h" -#include "third_party/base/logging.h" -#include "third_party/base/stl_util.h" namespace { -const char* const g_CharsetNames[CIDSET_NUM_SETS] = {nullptr, "GB1", "CNS1", - "Japan1", "Korea1", "UCS"}; struct ByteRange { uint8_t m_First; uint8_t m_Last; // Inclusive. @@ -190,20 +181,6 @@ const PredefinedCMap g_PredefinedCMaps[] = { {"UniKS-UTF16", CIDSET_KOREA1, CIDCODING_UTF16, CPDF_CMap::TwoBytes, 0, {}}, }; -CIDSet CIDSetFromSizeT(size_t index) { - if (index >= CIDSET_NUM_SETS) { - NOTREACHED(); - return CIDSET_UNKNOWN; - } - return static_cast<CIDSet>(index); -} - -CFX_ByteStringC CMap_GetString(const CFX_ByteStringC& word) { - if (word.GetLength() <= 2) - return CFX_ByteStringC(); - return CFX_ByteStringC(&word[1], word.GetLength() - 2); -} - int CheckFourByteCodeRange(uint8_t* codes, int size, const std::vector<CPDF_CMap::CodeRange>& ranges) { @@ -268,206 +245,6 @@ int GetFourByteCharSizeImpl(uint32_t charcode, } // namespace -CPDF_CMapManager::CPDF_CMapManager() {} - -CPDF_CMapManager::~CPDF_CMapManager() {} - -CFX_RetainPtr<CPDF_CMap> CPDF_CMapManager::GetPredefinedCMap( - const CFX_ByteString& name, - bool bPromptCJK) { - auto it = m_CMaps.find(name); - if (it != m_CMaps.end()) - return it->second; - - CFX_RetainPtr<CPDF_CMap> pCMap = LoadPredefinedCMap(name, bPromptCJK); - if (!name.IsEmpty()) - m_CMaps[name] = pCMap; - - return pCMap; -} - -CFX_RetainPtr<CPDF_CMap> CPDF_CMapManager::LoadPredefinedCMap( - const CFX_ByteString& name, - bool bPromptCJK) { - const char* pname = name.c_str(); - if (*pname == '/') - pname++; - - auto pCMap = pdfium::MakeRetain<CPDF_CMap>(); - pCMap->LoadPredefined(this, pname, bPromptCJK); - return pCMap; -} - -CPDF_CID2UnicodeMap* CPDF_CMapManager::GetCID2UnicodeMap(CIDSet charset, - bool bPromptCJK) { - if (!m_CID2UnicodeMaps[charset]) - m_CID2UnicodeMaps[charset] = LoadCID2UnicodeMap(charset, bPromptCJK); - - return m_CID2UnicodeMaps[charset].get(); -} - -std::unique_ptr<CPDF_CID2UnicodeMap> CPDF_CMapManager::LoadCID2UnicodeMap( - CIDSet charset, - bool bPromptCJK) { - auto pMap = pdfium::MakeUnique<CPDF_CID2UnicodeMap>(); - pMap->Load(this, charset, bPromptCJK); - return pMap; -} - -CPDF_CMapParser::CPDF_CMapParser(CPDF_CMap* pCMap) - : m_pCMap(pCMap), m_Status(0), m_CodeSeq(0) {} - -CPDF_CMapParser::~CPDF_CMapParser() {} - -void CPDF_CMapParser::ParseWord(const CFX_ByteStringC& word) { - if (word.IsEmpty()) { - return; - } - if (word == "begincidchar") { - m_Status = 1; - m_CodeSeq = 0; - } else if (word == "begincidrange") { - m_Status = 2; - m_CodeSeq = 0; - } else if (word == "endcidrange" || word == "endcidchar") { - m_Status = 0; - } else if (word == "/WMode") { - m_Status = 6; - } else if (word == "/Registry") { - m_Status = 3; - } else if (word == "/Ordering") { - m_Status = 4; - } else if (word == "/Supplement") { - m_Status = 5; - } else if (word == "begincodespacerange") { - m_Status = 7; - m_CodeSeq = 0; - } else if (word == "usecmap") { - } else if (m_Status == 1 || m_Status == 2) { - m_CodePoints[m_CodeSeq] = CMap_GetCode(word); - m_CodeSeq++; - uint32_t StartCode, EndCode; - uint16_t StartCID; - if (m_Status == 1) { - if (m_CodeSeq < 2) { - return; - } - EndCode = StartCode = m_CodePoints[0]; - StartCID = (uint16_t)m_CodePoints[1]; - } else { - if (m_CodeSeq < 3) { - return; - } - StartCode = m_CodePoints[0]; - EndCode = m_CodePoints[1]; - StartCID = (uint16_t)m_CodePoints[2]; - } - if (EndCode < 0x10000) { - for (uint32_t code = StartCode; code <= EndCode; code++) { - m_pCMap->m_DirectCharcodeToCIDTable[code] = - static_cast<uint16_t>(StartCID + code - StartCode); - } - } else { - m_AdditionalCharcodeToCIDMappings.push_back( - {StartCode, EndCode, StartCID}); - } - m_CodeSeq = 0; - } else if (m_Status == 3) { - m_Status = 0; - } else if (m_Status == 4) { - m_pCMap->m_Charset = CharsetFromOrdering(CMap_GetString(word)); - m_Status = 0; - } else if (m_Status == 5) { - m_Status = 0; - } else if (m_Status == 6) { - m_pCMap->m_bVertical = CMap_GetCode(word) != 0; - m_Status = 0; - } else if (m_Status == 7) { - if (word == "endcodespacerange") { - uint32_t nSegs = pdfium::CollectionSize<uint32_t>(m_CodeRanges); - if (nSegs > 1) { - m_pCMap->m_CodingScheme = CPDF_CMap::MixedFourBytes; - m_pCMap->m_MixedFourByteLeadingRanges = m_CodeRanges; - } else if (nSegs == 1) { - m_pCMap->m_CodingScheme = (m_CodeRanges[0].m_CharSize == 2) - ? CPDF_CMap::TwoBytes - : CPDF_CMap::OneByte; - } - m_Status = 0; - } else { - if (word.GetLength() == 0 || word.GetAt(0) != '<') { - return; - } - if (m_CodeSeq % 2) { - CPDF_CMap::CodeRange range; - if (CMap_GetCodeRange(range, m_LastWord.AsStringC(), word)) - m_CodeRanges.push_back(range); - } - m_CodeSeq++; - } - } - m_LastWord = word; -} - -// Static. -uint32_t CPDF_CMapParser::CMap_GetCode(const CFX_ByteStringC& word) { - pdfium::base::CheckedNumeric<uint32_t> num = 0; - if (word.GetAt(0) == '<') { - for (int i = 1; i < word.GetLength() && std::isxdigit(word.GetAt(i)); ++i) { - num = num * 16 + FXSYS_HexCharToInt(word.GetAt(i)); - if (!num.IsValid()) - return 0; - } - return num.ValueOrDie(); - } - - for (int i = 0; i < word.GetLength() && std::isdigit(word.GetAt(i)); ++i) { - num = - num * 10 + FXSYS_DecimalCharToInt(static_cast<wchar_t>(word.GetAt(i))); - if (!num.IsValid()) - return 0; - } - return num.ValueOrDie(); -} - -// Static. -bool CPDF_CMapParser::CMap_GetCodeRange(CPDF_CMap::CodeRange& range, - const CFX_ByteStringC& first, - const CFX_ByteStringC& second) { - if (first.GetLength() == 0 || first.GetAt(0) != '<') - return false; - - int i; - for (i = 1; i < first.GetLength(); ++i) { - if (first.GetAt(i) == '>') { - break; - } - } - range.m_CharSize = (i - 1) / 2; - if (range.m_CharSize > 4) - return false; - - for (i = 0; i < range.m_CharSize; ++i) { - uint8_t digit1 = first.GetAt(i * 2 + 1); - uint8_t digit2 = first.GetAt(i * 2 + 2); - range.m_Lower[i] = - FXSYS_HexCharToInt(digit1) * 16 + FXSYS_HexCharToInt(digit2); - } - - uint32_t size = second.GetLength(); - for (i = 0; i < range.m_CharSize; ++i) { - uint8_t digit1 = ((uint32_t)i * 2 + 1 < size) - ? second.GetAt((FX_STRSIZE)i * 2 + 1) - : '0'; - uint8_t digit2 = ((uint32_t)i * 2 + 2 < size) - ? second.GetAt((FX_STRSIZE)i * 2 + 2) - : '0'; - range.m_Upper[i] = - FXSYS_HexCharToInt(digit1) * 16 + FXSYS_HexCharToInt(digit2); - } - return true; -} - CPDF_CMap::CPDF_CMap() : m_bLoaded(false), m_bVertical(false), @@ -709,42 +486,3 @@ int CPDF_CMap::AppendChar(char* str, uint32_t charcode) const { } return 0; } - -CPDF_CID2UnicodeMap::CPDF_CID2UnicodeMap() { - m_EmbeddedCount = 0; -} - -CPDF_CID2UnicodeMap::~CPDF_CID2UnicodeMap() {} - -bool CPDF_CID2UnicodeMap::IsLoaded() { - return m_EmbeddedCount != 0; -} - -wchar_t CPDF_CID2UnicodeMap::UnicodeFromCID(uint16_t CID) { - if (m_Charset == CIDSET_UNICODE) { - return CID; - } - if (CID < m_EmbeddedCount) { - return m_pEmbeddedMap[CID]; - } - return 0; -} - -void CPDF_CID2UnicodeMap::Load(CPDF_CMapManager* pMgr, - CIDSet charset, - bool bPromptCJK) { - m_Charset = charset; - - CPDF_FontGlobals* pFontGlobals = - CPDF_ModuleMgr::Get()->GetPageModule()->GetFontGlobals(); - m_pEmbeddedMap = pFontGlobals->m_EmbeddedToUnicodes[charset].m_pMap; - m_EmbeddedCount = pFontGlobals->m_EmbeddedToUnicodes[charset].m_Count; -} - -CIDSet CharsetFromOrdering(const CFX_ByteStringC& ordering) { - for (size_t charset = 1; charset < FX_ArraySize(g_CharsetNames); ++charset) { - if (ordering == g_CharsetNames[charset]) - return CIDSetFromSizeT(charset); - } - return CIDSET_UNKNOWN; -} diff --git a/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_cmap.h b/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_cmap.h new file mode 100644 index 00000000000..ab495efbfc3 --- /dev/null +++ b/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_cmap.h @@ -0,0 +1,87 @@ +// Copyright 2017 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 + +#ifndef CORE_FPDFAPI_FONT_CPDF_CMAP_H_ +#define CORE_FPDFAPI_FONT_CPDF_CMAP_H_ + +#include <vector> + +#include "core/fpdfapi/font/cpdf_cidfont.h" +#include "core/fxcrt/cfx_retain_ptr.h" +#include "core/fxcrt/fx_basic.h" + +class CPDF_CMapManager; +struct FXCMAP_CMap; + +enum CIDCoding : uint8_t { + CIDCODING_UNKNOWN = 0, + CIDCODING_GB, + CIDCODING_BIG5, + CIDCODING_JIS, + CIDCODING_KOREA, + CIDCODING_UCS2, + CIDCODING_CID, + CIDCODING_UTF16, +}; + +class CPDF_CMap : public CFX_Retainable { + public: + enum CodingScheme : uint8_t { + OneByte, + TwoBytes, + MixedTwoBytes, + MixedFourBytes + }; + + struct CodeRange { + int m_CharSize; + uint8_t m_Lower[4]; + uint8_t m_Upper[4]; + }; + + struct CIDRange { + uint32_t m_StartCode; + uint32_t m_EndCode; + uint16_t m_StartCID; + }; + + template <typename T, typename... Args> + friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args); + + void LoadPredefined(CPDF_CMapManager* pMgr, + const CFX_ByteString& name, + bool bPromptCJK); + void LoadEmbedded(const uint8_t* pData, uint32_t dwSize); + + bool IsLoaded() const { return m_bLoaded; } + bool IsVertWriting() const { return m_bVertical; } + uint16_t CIDFromCharCode(uint32_t charcode) const; + int GetCharSize(uint32_t charcode) const; + uint32_t GetNextChar(const char* pString, int nStrLen, int& offset) const; + int CountChar(const char* pString, int size) const; + int AppendChar(char* str, uint32_t charcode) const; + + private: + friend class CPDF_CMapParser; + friend class CPDF_CIDFont; + + CPDF_CMap(); + ~CPDF_CMap() override; + + CFX_ByteString m_PredefinedCMap; + bool m_bLoaded; + bool m_bVertical; + CIDSet m_Charset; + CodingScheme m_CodingScheme; + int m_Coding; + std::vector<bool> m_MixedTwoByteLeadingBytes; + std::vector<CodeRange> m_MixedFourByteLeadingRanges; + std::vector<uint16_t> m_DirectCharcodeToCIDTable; + std::vector<CIDRange> m_AdditionalCharcodeToCIDMappings; + const FXCMAP_CMap* m_pEmbedMap; +}; + +#endif // CORE_FPDFAPI_FONT_CPDF_CMAP_H_ diff --git a/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_cmapmanager.cpp b/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_cmapmanager.cpp new file mode 100644 index 00000000000..040af5556a6 --- /dev/null +++ b/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_cmapmanager.cpp @@ -0,0 +1,59 @@ +// Copyright 2017 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/fpdfapi/font/cpdf_cmapmanager.h" + +#include <utility> + +#include "core/fpdfapi/font/cpdf_cid2unicodemap.h" +#include "core/fpdfapi/font/cpdf_cmap.h" +#include "third_party/base/stl_util.h" + +CPDF_CMapManager::CPDF_CMapManager() {} + +CPDF_CMapManager::~CPDF_CMapManager() {} + +CFX_RetainPtr<CPDF_CMap> CPDF_CMapManager::GetPredefinedCMap( + const CFX_ByteString& name, + bool bPromptCJK) { + auto it = m_CMaps.find(name); + if (it != m_CMaps.end()) + return it->second; + + CFX_RetainPtr<CPDF_CMap> pCMap = LoadPredefinedCMap(name, bPromptCJK); + if (!name.IsEmpty()) + m_CMaps[name] = pCMap; + + return pCMap; +} + +CFX_RetainPtr<CPDF_CMap> CPDF_CMapManager::LoadPredefinedCMap( + const CFX_ByteString& name, + bool bPromptCJK) { + const char* pname = name.c_str(); + if (*pname == '/') + pname++; + + auto pCMap = pdfium::MakeRetain<CPDF_CMap>(); + pCMap->LoadPredefined(this, pname, bPromptCJK); + return pCMap; +} + +CPDF_CID2UnicodeMap* CPDF_CMapManager::GetCID2UnicodeMap(CIDSet charset, + bool bPromptCJK) { + if (!m_CID2UnicodeMaps[charset]) + m_CID2UnicodeMaps[charset] = LoadCID2UnicodeMap(charset, bPromptCJK); + + return m_CID2UnicodeMaps[charset].get(); +} + +std::unique_ptr<CPDF_CID2UnicodeMap> CPDF_CMapManager::LoadCID2UnicodeMap( + CIDSet charset, + bool bPromptCJK) { + auto pMap = pdfium::MakeUnique<CPDF_CID2UnicodeMap>(); + pMap->Load(this, charset, bPromptCJK); + return pMap; +} diff --git a/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_cmapmanager.h b/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_cmapmanager.h new file mode 100644 index 00000000000..1bc1c6f8393 --- /dev/null +++ b/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_cmapmanager.h @@ -0,0 +1,36 @@ +// Copyright 2017 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 + +#ifndef CORE_FPDFAPI_FONT_CPDF_CMAPMANAGER_H_ +#define CORE_FPDFAPI_FONT_CPDF_CMAPMANAGER_H_ + +#include <map> +#include <memory> + +#include "core/fpdfapi/font/cpdf_cidfont.h" +#include "core/fxcrt/cfx_bytestring.h" +#include "core/fxcrt/cfx_retain_ptr.h" + +class CPDF_CMapManager { + public: + CPDF_CMapManager(); + ~CPDF_CMapManager(); + + CFX_RetainPtr<CPDF_CMap> GetPredefinedCMap(const CFX_ByteString& name, + bool bPromptCJK); + CPDF_CID2UnicodeMap* GetCID2UnicodeMap(CIDSet charset, bool bPromptCJK); + + private: + CFX_RetainPtr<CPDF_CMap> LoadPredefinedCMap(const CFX_ByteString& name, + bool bPromptCJK); + std::unique_ptr<CPDF_CID2UnicodeMap> LoadCID2UnicodeMap(CIDSet charset, + bool bPromptCJK); + + std::map<CFX_ByteString, CFX_RetainPtr<CPDF_CMap>> m_CMaps; + std::unique_ptr<CPDF_CID2UnicodeMap> m_CID2UnicodeMaps[6]; +}; + +#endif // CORE_FPDFAPI_FONT_CPDF_CMAPMANAGER_H_ diff --git a/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_cmapparser.cpp b/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_cmapparser.cpp new file mode 100644 index 00000000000..0f9bca6018d --- /dev/null +++ b/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_cmapparser.cpp @@ -0,0 +1,204 @@ +// Copyright 2014 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/fpdfapi/font/cpdf_cmapparser.h" + +#include <vector> + +#include "core/fpdfapi/cmaps/cmap_int.h" +#include "core/fpdfapi/cpdf_modulemgr.h" +#include "core/fpdfapi/page/cpdf_pagemodule.h" +#include "core/fpdfapi/parser/cpdf_array.h" +#include "core/fpdfapi/parser/cpdf_dictionary.h" +#include "core/fpdfapi/parser/cpdf_simple_parser.h" +#include "core/fxcrt/fx_extension.h" +#include "core/fxge/fx_freetype.h" +#include "third_party/base/logging.h" +#include "third_party/base/stl_util.h" + +namespace { + +const char* const g_CharsetNames[CIDSET_NUM_SETS] = {nullptr, "GB1", "CNS1", + "Japan1", "Korea1", "UCS"}; + +CIDSet CIDSetFromSizeT(size_t index) { + if (index >= CIDSET_NUM_SETS) { + NOTREACHED(); + return CIDSET_UNKNOWN; + } + return static_cast<CIDSet>(index); +} + +CFX_ByteStringC CMap_GetString(const CFX_ByteStringC& word) { + if (word.GetLength() <= 2) + return CFX_ByteStringC(); + return CFX_ByteStringC(&word[1], word.GetLength() - 2); +} + +} // namespace + +CPDF_CMapParser::CPDF_CMapParser(CPDF_CMap* pCMap) + : m_pCMap(pCMap), m_Status(0), m_CodeSeq(0) {} + +CPDF_CMapParser::~CPDF_CMapParser() {} + +void CPDF_CMapParser::ParseWord(const CFX_ByteStringC& word) { + if (word.IsEmpty()) { + return; + } + if (word == "begincidchar") { + m_Status = 1; + m_CodeSeq = 0; + } else if (word == "begincidrange") { + m_Status = 2; + m_CodeSeq = 0; + } else if (word == "endcidrange" || word == "endcidchar") { + m_Status = 0; + } else if (word == "/WMode") { + m_Status = 6; + } else if (word == "/Registry") { + m_Status = 3; + } else if (word == "/Ordering") { + m_Status = 4; + } else if (word == "/Supplement") { + m_Status = 5; + } else if (word == "begincodespacerange") { + m_Status = 7; + m_CodeSeq = 0; + } else if (word == "usecmap") { + } else if (m_Status == 1 || m_Status == 2) { + m_CodePoints[m_CodeSeq] = CMap_GetCode(word); + m_CodeSeq++; + uint32_t StartCode, EndCode; + uint16_t StartCID; + if (m_Status == 1) { + if (m_CodeSeq < 2) { + return; + } + EndCode = StartCode = m_CodePoints[0]; + StartCID = (uint16_t)m_CodePoints[1]; + } else { + if (m_CodeSeq < 3) { + return; + } + StartCode = m_CodePoints[0]; + EndCode = m_CodePoints[1]; + StartCID = (uint16_t)m_CodePoints[2]; + } + if (EndCode < 0x10000) { + for (uint32_t code = StartCode; code <= EndCode; code++) { + m_pCMap->m_DirectCharcodeToCIDTable[code] = + static_cast<uint16_t>(StartCID + code - StartCode); + } + } else { + m_AdditionalCharcodeToCIDMappings.push_back( + {StartCode, EndCode, StartCID}); + } + m_CodeSeq = 0; + } else if (m_Status == 3) { + m_Status = 0; + } else if (m_Status == 4) { + m_pCMap->m_Charset = CharsetFromOrdering(CMap_GetString(word)); + m_Status = 0; + } else if (m_Status == 5) { + m_Status = 0; + } else if (m_Status == 6) { + m_pCMap->m_bVertical = CMap_GetCode(word) != 0; + m_Status = 0; + } else if (m_Status == 7) { + if (word == "endcodespacerange") { + uint32_t nSegs = pdfium::CollectionSize<uint32_t>(m_CodeRanges); + if (nSegs > 1) { + m_pCMap->m_CodingScheme = CPDF_CMap::MixedFourBytes; + m_pCMap->m_MixedFourByteLeadingRanges = m_CodeRanges; + } else if (nSegs == 1) { + m_pCMap->m_CodingScheme = (m_CodeRanges[0].m_CharSize == 2) + ? CPDF_CMap::TwoBytes + : CPDF_CMap::OneByte; + } + m_Status = 0; + } else { + if (word.GetLength() == 0 || word.GetAt(0) != '<') { + return; + } + if (m_CodeSeq % 2) { + CPDF_CMap::CodeRange range; + if (CMap_GetCodeRange(range, m_LastWord.AsStringC(), word)) + m_CodeRanges.push_back(range); + } + m_CodeSeq++; + } + } + m_LastWord = word; +} + +// Static. +uint32_t CPDF_CMapParser::CMap_GetCode(const CFX_ByteStringC& word) { + pdfium::base::CheckedNumeric<uint32_t> num = 0; + if (word.GetAt(0) == '<') { + for (int i = 1; i < word.GetLength() && std::isxdigit(word.GetAt(i)); ++i) { + num = num * 16 + FXSYS_HexCharToInt(word.GetAt(i)); + if (!num.IsValid()) + return 0; + } + return num.ValueOrDie(); + } + + for (int i = 0; i < word.GetLength() && std::isdigit(word.GetAt(i)); ++i) { + num = + num * 10 + FXSYS_DecimalCharToInt(static_cast<wchar_t>(word.GetAt(i))); + if (!num.IsValid()) + return 0; + } + return num.ValueOrDie(); +} + +// Static. +bool CPDF_CMapParser::CMap_GetCodeRange(CPDF_CMap::CodeRange& range, + const CFX_ByteStringC& first, + const CFX_ByteStringC& second) { + if (first.GetLength() == 0 || first.GetAt(0) != '<') + return false; + + int i; + for (i = 1; i < first.GetLength(); ++i) { + if (first.GetAt(i) == '>') { + break; + } + } + range.m_CharSize = (i - 1) / 2; + if (range.m_CharSize > 4) + return false; + + for (i = 0; i < range.m_CharSize; ++i) { + uint8_t digit1 = first.GetAt(i * 2 + 1); + uint8_t digit2 = first.GetAt(i * 2 + 2); + range.m_Lower[i] = + FXSYS_HexCharToInt(digit1) * 16 + FXSYS_HexCharToInt(digit2); + } + + uint32_t size = second.GetLength(); + for (i = 0; i < range.m_CharSize; ++i) { + uint8_t digit1 = ((uint32_t)i * 2 + 1 < size) + ? second.GetAt((FX_STRSIZE)i * 2 + 1) + : '0'; + uint8_t digit2 = ((uint32_t)i * 2 + 2 < size) + ? second.GetAt((FX_STRSIZE)i * 2 + 2) + : '0'; + range.m_Upper[i] = + FXSYS_HexCharToInt(digit1) * 16 + FXSYS_HexCharToInt(digit2); + } + return true; +} + +// static +CIDSet CPDF_CMapParser::CharsetFromOrdering(const CFX_ByteStringC& ordering) { + for (size_t charset = 1; charset < FX_ArraySize(g_CharsetNames); ++charset) { + if (ordering == g_CharsetNames[charset]) + return CIDSetFromSizeT(charset); + } + return CIDSET_UNKNOWN; +} diff --git a/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_cmapparser.h b/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_cmapparser.h new file mode 100644 index 00000000000..184ef750430 --- /dev/null +++ b/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_cmapparser.h @@ -0,0 +1,52 @@ +// Copyright 2017 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 + +#ifndef CORE_FPDFAPI_FONT_CPDF_CMAPPARSER_H_ +#define CORE_FPDFAPI_FONT_CPDF_CMAPPARSER_H_ + +#include <map> +#include <utility> +#include <vector> + +#include "core/fpdfapi/font/cpdf_cidfont.h" +#include "core/fpdfapi/font/cpdf_cmap.h" +#include "core/fxcrt/cfx_unowned_ptr.h" +#include "core/fxcrt/fx_basic.h" + +class CPDF_CMapParser { + public: + explicit CPDF_CMapParser(CPDF_CMap* pMap); + ~CPDF_CMapParser(); + + void ParseWord(const CFX_ByteStringC& str); + bool HasAdditionalMappings() const { + return !m_AdditionalCharcodeToCIDMappings.empty(); + } + std::vector<CPDF_CMap::CIDRange> TakeAdditionalMappings() { + return std::move(m_AdditionalCharcodeToCIDMappings); + } + + static CIDSet CharsetFromOrdering(const CFX_ByteStringC& ordering); + + private: + friend class cpdf_cmapparser_CMap_GetCode_Test; + friend class cpdf_cmapparser_CMap_GetCodeRange_Test; + + static uint32_t CMap_GetCode(const CFX_ByteStringC& word); + static bool CMap_GetCodeRange(CPDF_CMap::CodeRange& range, + const CFX_ByteStringC& first, + const CFX_ByteStringC& second); + + CFX_UnownedPtr<CPDF_CMap> const m_pCMap; + int m_Status; + int m_CodeSeq; + uint32_t m_CodePoints[4]; + std::vector<CPDF_CMap::CodeRange> m_CodeRanges; + std::vector<CPDF_CMap::CIDRange> m_AdditionalCharcodeToCIDMappings; + CFX_ByteString m_LastWord; +}; + +#endif // CORE_FPDFAPI_FONT_CPDF_CMAPPARSER_H_ diff --git a/chromium/third_party/pdfium/core/fpdfapi/font/fpdf_font_cid_unittest.cpp b/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_cmapparser_unittest.cpp index 813a3a9d9b1..0d55aa274df 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/font/fpdf_font_cid_unittest.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_cmapparser_unittest.cpp @@ -2,7 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "core/fpdfapi/font/font_int.h" +#include "core/fpdfapi/font/cpdf_cmapparser.h" + #include "testing/gtest/include/gtest/gtest.h" namespace { @@ -17,7 +18,7 @@ bool uint_ranges_equal(uint8_t* a, uint8_t* b, size_t count) { } // namespace -TEST(fpdf_font_cid, CMap_GetCode) { +TEST(cpdf_cmapparser, CMap_GetCode) { EXPECT_EQ(0u, CPDF_CMapParser::CMap_GetCode("")); EXPECT_EQ(0u, CPDF_CMapParser::CMap_GetCode("<")); EXPECT_EQ(194u, CPDF_CMapParser::CMap_GetCode("<c2")); @@ -35,7 +36,7 @@ TEST(fpdf_font_cid, CMap_GetCode) { EXPECT_EQ(0u, CPDF_CMapParser::CMap_GetCode("<100000000")); } -TEST(fpdf_font_cid, CMap_GetCodeRange) { +TEST(cpdf_cmapparser, CMap_GetCodeRange) { CPDF_CMap::CodeRange range; // Must start with a < diff --git a/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_font.cpp b/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_font.cpp index 1a7fb60b0bc..82f9be3361a 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_font.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_font.cpp @@ -6,6 +6,7 @@ #include "core/fpdfapi/font/cpdf_font.h" +#include <limits> #include <memory> #include <utility> #include <vector> @@ -15,7 +16,6 @@ #include "core/fpdfapi/font/cpdf_truetypefont.h" #include "core/fpdfapi/font/cpdf_type1font.h" #include "core/fpdfapi/font/cpdf_type3font.h" -#include "core/fpdfapi/font/font_int.h" #include "core/fpdfapi/page/cpdf_docpagedata.h" #include "core/fpdfapi/page/cpdf_pagemodule.h" #include "core/fpdfapi/parser/cpdf_array.h" @@ -160,6 +160,10 @@ uint32_t CPDF_Font::CharCodeFromUnicode(wchar_t unicode) const { return m_pToUnicodeMap ? m_pToUnicodeMap->ReverseLookup(unicode) : 0; } +bool CPDF_Font::HasFontWidths() const { + return true; +} + void CPDF_Font::LoadFontDescriptor(CPDF_Dictionary* pFontDesc) { m_Flags = pFontDesc->GetIntegerFor("Flags", FXFONT_NONSYMBOLIC); int ItalicAngle = 0; @@ -477,3 +481,30 @@ CFX_Font* CPDF_Font::GetFontFallback(int position) { return nullptr; return m_FontFallbacks[position].get(); } + +// static +int CPDF_Font::TT2PDF(int m, FXFT_Face face) { + int upm = FXFT_Get_Face_UnitsPerEM(face); + if (upm == 0) + return m; + + return static_cast<int>( + pdfium::clamp((m * 1000.0 + upm / 2) / upm, + static_cast<double>(std::numeric_limits<int>::min()), + static_cast<double>(std::numeric_limits<int>::max()))); +} + +// static +bool CPDF_Font::FT_UseTTCharmap(FXFT_Face face, + int platform_id, + int encoding_id) { + auto** pCharMap = FXFT_Get_Face_Charmaps(face); + for (int i = 0; i < FXFT_Get_Face_CharmapCount(face); i++) { + if (FXFT_Get_Charmap_PlatformID(pCharMap[i]) == platform_id && + FXFT_Get_Charmap_EncodingID(pCharMap[i]) == encoding_id) { + FXFT_Set_Charmap(face, pCharMap[i]); + return true; + } + } + return false; +} diff --git a/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_font.h b/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_font.h index c8e65e26a53..f70542223c5 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_font.h +++ b/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_font.h @@ -10,6 +10,7 @@ #include <memory> #include <vector> +#include "core/fpdfapi/font/cpdf_tounicodemap.h" #include "core/fpdfapi/parser/cpdf_stream_acc.h" #include "core/fxcrt/cfx_unowned_ptr.h" #include "core/fxcrt/fx_string.h" @@ -60,6 +61,7 @@ class CPDF_Font { virtual int GlyphFromCharCodeExt(uint32_t charcode); virtual CFX_WideString UnicodeFromCharCode(uint32_t charcode) const; virtual uint32_t CharCodeFromUnicode(wchar_t Unicode) const; + virtual bool HasFontWidths() const; const CFX_ByteString& GetBaseFont() const { return m_BaseFont; } CFX_SubstFont* GetSubstFont() const { return m_Font.GetSubstFont(); } @@ -87,6 +89,9 @@ class CPDF_Font { protected: CPDF_Font(); + static int TT2PDF(int m, FXFT_Face face); + static bool FT_UseTTCharmap(FXFT_Face face, int platform_id, int encoding_id); + virtual bool Load() = 0; void LoadUnicodeMap() const; // logically const only. diff --git a/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_fontglobals.cpp b/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_fontglobals.cpp new file mode 100644 index 00000000000..ddf87b1c09b --- /dev/null +++ b/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_fontglobals.cpp @@ -0,0 +1,39 @@ +// Copyright 2017 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/fpdfapi/font/cpdf_fontglobals.h" + +#include <utility> + +#include "core/fpdfapi/parser/cpdf_document.h" +#include "third_party/base/ptr_util.h" +#include "third_party/base/stl_util.h" + +CPDF_FontGlobals::CPDF_FontGlobals() { + memset(m_EmbeddedCharsets, 0, sizeof(m_EmbeddedCharsets)); + memset(m_EmbeddedToUnicodes, 0, sizeof(m_EmbeddedToUnicodes)); +} + +CPDF_FontGlobals::~CPDF_FontGlobals() {} + +CPDF_Font* CPDF_FontGlobals::Find(CPDF_Document* pDoc, uint32_t index) { + auto it = m_StockMap.find(pDoc); + if (it == m_StockMap.end()) + return nullptr; + return it->second ? it->second->GetFont(index) : nullptr; +} + +CPDF_Font* CPDF_FontGlobals::Set(CPDF_Document* pDoc, + uint32_t index, + std::unique_ptr<CPDF_Font> pFont) { + if (!pdfium::ContainsKey(m_StockMap, pDoc)) + m_StockMap[pDoc] = pdfium::MakeUnique<CFX_StockFontArray>(); + return m_StockMap[pDoc]->SetFont(index, std::move(pFont)); +} + +void CPDF_FontGlobals::Clear(CPDF_Document* pDoc) { + m_StockMap.erase(pDoc); +} diff --git a/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_fontglobals.h b/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_fontglobals.h new file mode 100644 index 00000000000..b930aa2905e --- /dev/null +++ b/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_fontglobals.h @@ -0,0 +1,45 @@ +// Copyright 2017 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 + +#ifndef CORE_FPDFAPI_FONT_CPDF_FONTGLOBALS_H_ +#define CORE_FPDFAPI_FONT_CPDF_FONTGLOBALS_H_ + +#include <map> +#include <memory> + +#include "core/fpdfapi/cmaps/cmap_int.h" +#include "core/fpdfapi/font/cfx_stockfontarray.h" +#include "core/fpdfapi/font/cpdf_cmapmanager.h" +#include "core/fxcrt/fx_basic.h" + +class CPDF_FontGlobals { + public: + CPDF_FontGlobals(); + ~CPDF_FontGlobals(); + + void Clear(CPDF_Document* pDoc); + CPDF_Font* Find(CPDF_Document* pDoc, uint32_t index); + + // Takes ownership of |pFont|, returns unowned pointer to it. + CPDF_Font* Set(CPDF_Document* key, + uint32_t index, + std::unique_ptr<CPDF_Font> pFont); + + CPDF_CMapManager m_CMapManager; + struct { + CFX_UnownedPtr<const FXCMAP_CMap> m_pMapList; + uint32_t m_Count; + } m_EmbeddedCharsets[CIDSET_NUM_SETS]; + struct { + const uint16_t* m_pMap; + uint32_t m_Count; + } m_EmbeddedToUnicodes[CIDSET_NUM_SETS]; + + private: + std::map<CPDF_Document*, std::unique_ptr<CFX_StockFontArray>> m_StockMap; +}; + +#endif // CORE_FPDFAPI_FONT_CPDF_FONTGLOBALS_H_ diff --git a/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_simplefont.cpp b/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_simplefont.cpp index cb8f00a98a6..a6c3ba0547f 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_simplefont.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_simplefont.cpp @@ -6,7 +6,6 @@ #include "core/fpdfapi/font/cpdf_simplefont.h" -#include "core/fpdfapi/font/font_int.h" #include "core/fpdfapi/parser/cpdf_array.h" #include "core/fpdfapi/parser/cpdf_dictionary.h" #include "core/fxge/fx_freetype.h" @@ -213,3 +212,7 @@ uint32_t CPDF_SimpleFont::CharCodeFromUnicode(wchar_t unicode) const { return ret; return m_Encoding.CharCodeFromUnicode(unicode); } + +bool CPDF_SimpleFont::HasFontWidths() const { + return !m_bUseFontWidth; +} diff --git a/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_simplefont.h b/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_simplefont.h index 3e414fa788c..6a22f46966c 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_simplefont.h +++ b/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_simplefont.h @@ -29,6 +29,8 @@ class CPDF_SimpleFont : public CPDF_Font { CPDF_FontEncoding* GetEncoding() { return &m_Encoding; } + bool HasFontWidths() const override; + protected: virtual void LoadGlyphMap() = 0; diff --git a/chromium/third_party/pdfium/core/fpdfapi/font/fpdf_font.cpp b/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_tounicodemap.cpp index ebdad49da76..8989f0be37c 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/font/fpdf_font.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_tounicodemap.cpp @@ -1,99 +1,18 @@ -// Copyright 2014 PDFium Authors. All rights reserved. +// Copyright 2017 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/fpdfapi/font/font_int.h" - -#include <memory> -#include <utility> +#include "core/fpdfapi/font/cpdf_tounicodemap.h" #include "core/fpdfapi/cpdf_modulemgr.h" -#include "core/fpdfapi/page/cpdf_form.h" +#include "core/fpdfapi/font/cpdf_cid2unicodemap.h" #include "core/fpdfapi/page/cpdf_pagemodule.h" -#include "core/fpdfapi/parser/cpdf_array.h" -#include "core/fpdfapi/parser/cpdf_dictionary.h" -#include "core/fpdfapi/parser/cpdf_document.h" -#include "core/fpdfapi/parser/cpdf_name.h" -#include "core/fpdfapi/parser/cpdf_number.h" #include "core/fpdfapi/parser/cpdf_simple_parser.h" -#include "core/fpdfapi/parser/cpdf_stream_acc.h" #include "core/fxcrt/fx_extension.h" #include "core/fxcrt/fx_safe_types.h" -#include "core/fxge/fx_freetype.h" #include "third_party/base/numerics/safe_conversions.h" -#include "third_party/base/ptr_util.h" -#include "third_party/base/stl_util.h" - -int TT2PDF(int m, FXFT_Face face) { - int upm = FXFT_Get_Face_UnitsPerEM(face); - if (upm == 0) - return m; - return pdfium::base::checked_cast<int>( - (static_cast<double>(m) * 1000 + upm / 2) / upm); -} - -bool FT_UseTTCharmap(FXFT_Face face, int platform_id, int encoding_id) { - auto** pCharMap = FXFT_Get_Face_Charmaps(face); - for (int i = 0; i < FXFT_Get_Face_CharmapCount(face); i++) { - if (FXFT_Get_Charmap_PlatformID(pCharMap[i]) == platform_id && - FXFT_Get_Charmap_EncodingID(pCharMap[i]) == encoding_id) { - FXFT_Set_Charmap(face, pCharMap[i]); - return true; - } - } - return false; -} - -CFX_StockFontArray::CFX_StockFontArray() {} - -CFX_StockFontArray::~CFX_StockFontArray() { - for (size_t i = 0; i < FX_ArraySize(m_StockFonts); ++i) { - if (m_StockFonts[i]) - delete m_StockFonts[i]->GetFontDict(); - } -} - -CPDF_Font* CFX_StockFontArray::GetFont(uint32_t index) const { - if (index >= FX_ArraySize(m_StockFonts)) - return nullptr; - return m_StockFonts[index].get(); -} - -CPDF_Font* CFX_StockFontArray::SetFont(uint32_t index, - std::unique_ptr<CPDF_Font> pFont) { - CPDF_Font* result = pFont.get(); - if (index < FX_ArraySize(m_StockFonts)) - m_StockFonts[index] = std::move(pFont); - return result; -} - -CPDF_FontGlobals::CPDF_FontGlobals() { - memset(m_EmbeddedCharsets, 0, sizeof(m_EmbeddedCharsets)); - memset(m_EmbeddedToUnicodes, 0, sizeof(m_EmbeddedToUnicodes)); -} - -CPDF_FontGlobals::~CPDF_FontGlobals() {} - -CPDF_Font* CPDF_FontGlobals::Find(CPDF_Document* pDoc, uint32_t index) { - auto it = m_StockMap.find(pDoc); - if (it == m_StockMap.end()) - return nullptr; - return it->second ? it->second->GetFont(index) : nullptr; -} - -CPDF_Font* CPDF_FontGlobals::Set(CPDF_Document* pDoc, - uint32_t index, - std::unique_ptr<CPDF_Font> pFont) { - if (!pdfium::ContainsKey(m_StockMap, pDoc)) - m_StockMap[pDoc] = pdfium::MakeUnique<CFX_StockFontArray>(); - return m_StockMap[pDoc]->SetFont(index, std::move(pFont)); -} - -void CPDF_FontGlobals::Clear(CPDF_Document* pDoc) { - m_StockMap.erase(pDoc); -} CFX_WideString CPDF_ToUnicodeMap::Lookup(uint32_t charcode) const { auto it = m_Map.find(charcode); diff --git a/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_tounicodemap.h b/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_tounicodemap.h new file mode 100644 index 00000000000..83db6e3030e --- /dev/null +++ b/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_tounicodemap.h @@ -0,0 +1,42 @@ +// Copyright 2017 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 + +#ifndef CORE_FPDFAPI_FONT_CPDF_TOUNICODEMAP_H_ +#define CORE_FPDFAPI_FONT_CPDF_TOUNICODEMAP_H_ + +#include <map> + +#include "core/fpdfapi/parser/cpdf_stream.h" +#include "core/fxcrt/cfx_unowned_ptr.h" +#include "core/fxcrt/fx_basic.h" + +class CPDF_CID2UnicodeMap; + +class CPDF_ToUnicodeMap { + public: + CPDF_ToUnicodeMap(); + ~CPDF_ToUnicodeMap(); + + void Load(CPDF_Stream* pStream); + + CFX_WideString Lookup(uint32_t charcode) const; + uint32_t ReverseLookup(wchar_t unicode) const; + + private: + friend class cpdf_tounicodemap_StringToCode_Test; + friend class cpdf_tounicodemap_StringToWideString_Test; + + static uint32_t StringToCode(const CFX_ByteStringC& str); + static CFX_WideString StringToWideString(const CFX_ByteStringC& str); + + uint32_t GetUnicode(); + + std::map<uint32_t, uint32_t> m_Map; + CFX_UnownedPtr<CPDF_CID2UnicodeMap> m_pBaseMap; + CFX_WideTextBuf m_MultiCharBuf; +}; + +#endif // CORE_FPDFAPI_FONT_CPDF_TOUNICODEMAP_H_ diff --git a/chromium/third_party/pdfium/core/fpdfapi/font/fpdf_font_unittest.cpp b/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_tounicodemap_unittest.cpp index 977ae8a3bb0..299f4d9b1eb 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/font/fpdf_font_unittest.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_tounicodemap_unittest.cpp @@ -2,10 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "core/fpdfapi/font/font_int.h" +#include "core/fpdfapi/font/cpdf_tounicodemap.h" + #include "testing/gtest/include/gtest/gtest.h" -TEST(fpdf_font, StringToCode) { +TEST(cpdf_tounicodemap, StringToCode) { EXPECT_EQ(0u, CPDF_ToUnicodeMap::StringToCode("")); EXPECT_EQ(194u, CPDF_ToUnicodeMap::StringToCode("<c2")); EXPECT_EQ(162u, CPDF_ToUnicodeMap::StringToCode("<A2")); @@ -14,7 +15,7 @@ TEST(fpdf_font, StringToCode) { EXPECT_EQ(128u, CPDF_ToUnicodeMap::StringToCode("128")); } -TEST(fpdf_font, StringToWideString) { +TEST(cpdf_tounicodemap, StringToWideString) { EXPECT_EQ(L"", CPDF_ToUnicodeMap::StringToWideString("")); EXPECT_EQ(L"", CPDF_ToUnicodeMap::StringToWideString("1234")); diff --git a/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_truetypefont.cpp b/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_truetypefont.cpp index 7f4512da053..5fde64693a6 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_truetypefont.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_truetypefont.cpp @@ -6,7 +6,6 @@ #include "core/fpdfapi/font/cpdf_truetypefont.h" -#include "core/fpdfapi/font/font_int.h" #include "core/fpdfapi/parser/cpdf_dictionary.h" #include "core/fxge/fx_font.h" diff --git a/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_type1font.cpp b/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_type1font.cpp index ac0aed4050b..a7ac264fe06 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_type1font.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/font/cpdf_type1font.cpp @@ -6,7 +6,6 @@ #include "core/fpdfapi/font/cpdf_type1font.h" -#include "core/fpdfapi/font/font_int.h" #include "core/fpdfapi/parser/cpdf_dictionary.h" #include "core/fxge/cfx_gemodule.h" #include "core/fxge/fx_freetype.h" diff --git a/chromium/third_party/pdfium/core/fpdfapi/font/font_int.h b/chromium/third_party/pdfium/core/fpdfapi/font/font_int.h deleted file mode 100644 index ebd08e258a3..00000000000 --- a/chromium/third_party/pdfium/core/fpdfapi/font/font_int.h +++ /dev/null @@ -1,228 +0,0 @@ -// Copyright 2014 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 - -#ifndef CORE_FPDFAPI_FONT_FONT_INT_H_ -#define CORE_FPDFAPI_FONT_FONT_INT_H_ - -#include <map> -#include <memory> -#include <utility> -#include <vector> - -#include "core/fpdfapi/font/cpdf_cidfont.h" -#include "core/fxcrt/cfx_retain_ptr.h" -#include "core/fxcrt/fx_basic.h" - -class CPDF_CID2UnicodeMap; -class CPDF_CMapManager; -class CPDF_Font; -class CPDF_Stream; -struct FXCMAP_CMap; - -using FXFT_Library = void*; - -int TT2PDF(int m, FXFT_Face face); -bool FT_UseTTCharmap(FXFT_Face face, int platform_id, int encoding_id); -CIDSet CharsetFromOrdering(const CFX_ByteStringC& ordering); - -class CFX_StockFontArray { - public: - CFX_StockFontArray(); - ~CFX_StockFontArray(); - - // Takes ownership of |pFont|, returns unowned pointer to it. - CPDF_Font* SetFont(uint32_t index, std::unique_ptr<CPDF_Font> pFont); - CPDF_Font* GetFont(uint32_t index) const; - - private: - std::unique_ptr<CPDF_Font> m_StockFonts[14]; -}; - -enum CIDCoding : uint8_t { - CIDCODING_UNKNOWN = 0, - CIDCODING_GB, - CIDCODING_BIG5, - CIDCODING_JIS, - CIDCODING_KOREA, - CIDCODING_UCS2, - CIDCODING_CID, - CIDCODING_UTF16, -}; - -class CPDF_CMap : public CFX_Retainable { - public: - enum CodingScheme : uint8_t { - OneByte, - TwoBytes, - MixedTwoBytes, - MixedFourBytes - }; - - struct CodeRange { - int m_CharSize; - uint8_t m_Lower[4]; - uint8_t m_Upper[4]; - }; - - struct CIDRange { - uint32_t m_StartCode; - uint32_t m_EndCode; - uint16_t m_StartCID; - }; - - template <typename T, typename... Args> - friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args); - - void LoadPredefined(CPDF_CMapManager* pMgr, - const CFX_ByteString& name, - bool bPromptCJK); - void LoadEmbedded(const uint8_t* pData, uint32_t dwSize); - - bool IsLoaded() const { return m_bLoaded; } - bool IsVertWriting() const { return m_bVertical; } - uint16_t CIDFromCharCode(uint32_t charcode) const; - int GetCharSize(uint32_t charcode) const; - uint32_t GetNextChar(const char* pString, int nStrLen, int& offset) const; - int CountChar(const char* pString, int size) const; - int AppendChar(char* str, uint32_t charcode) const; - - private: - friend class CPDF_CMapParser; - friend class CPDF_CIDFont; - - CPDF_CMap(); - ~CPDF_CMap() override; - - CFX_ByteString m_PredefinedCMap; - bool m_bLoaded; - bool m_bVertical; - CIDSet m_Charset; - CodingScheme m_CodingScheme; - int m_Coding; - std::vector<bool> m_MixedTwoByteLeadingBytes; - std::vector<CodeRange> m_MixedFourByteLeadingRanges; - std::vector<uint16_t> m_DirectCharcodeToCIDTable; - std::vector<CIDRange> m_AdditionalCharcodeToCIDMappings; - const FXCMAP_CMap* m_pEmbedMap; -}; - -class CPDF_CMapManager { - public: - CPDF_CMapManager(); - ~CPDF_CMapManager(); - - CFX_RetainPtr<CPDF_CMap> GetPredefinedCMap(const CFX_ByteString& name, - bool bPromptCJK); - CPDF_CID2UnicodeMap* GetCID2UnicodeMap(CIDSet charset, bool bPromptCJK); - - private: - CFX_RetainPtr<CPDF_CMap> LoadPredefinedCMap(const CFX_ByteString& name, - bool bPromptCJK); - std::unique_ptr<CPDF_CID2UnicodeMap> LoadCID2UnicodeMap(CIDSet charset, - bool bPromptCJK); - - std::map<CFX_ByteString, CFX_RetainPtr<CPDF_CMap>> m_CMaps; - std::unique_ptr<CPDF_CID2UnicodeMap> m_CID2UnicodeMaps[6]; -}; - -class CPDF_CMapParser { - public: - explicit CPDF_CMapParser(CPDF_CMap* pMap); - ~CPDF_CMapParser(); - - void ParseWord(const CFX_ByteStringC& str); - bool HasAdditionalMappings() const { - return !m_AdditionalCharcodeToCIDMappings.empty(); - } - std::vector<CPDF_CMap::CIDRange> TakeAdditionalMappings() { - return std::move(m_AdditionalCharcodeToCIDMappings); - } - - private: - friend class fpdf_font_cid_CMap_GetCode_Test; - friend class fpdf_font_cid_CMap_GetCodeRange_Test; - - static uint32_t CMap_GetCode(const CFX_ByteStringC& word); - static bool CMap_GetCodeRange(CPDF_CMap::CodeRange& range, - const CFX_ByteStringC& first, - const CFX_ByteStringC& second); - - CFX_UnownedPtr<CPDF_CMap> const m_pCMap; - int m_Status; - int m_CodeSeq; - uint32_t m_CodePoints[4]; - std::vector<CPDF_CMap::CodeRange> m_CodeRanges; - std::vector<CPDF_CMap::CIDRange> m_AdditionalCharcodeToCIDMappings; - CFX_ByteString m_LastWord; -}; - -class CPDF_CID2UnicodeMap { - public: - CPDF_CID2UnicodeMap(); - ~CPDF_CID2UnicodeMap(); - - bool IsLoaded(); - void Load(CPDF_CMapManager* pMgr, CIDSet charset, bool bPromptCJK); - wchar_t UnicodeFromCID(uint16_t CID); - - private: - CIDSet m_Charset; - const uint16_t* m_pEmbeddedMap; - uint32_t m_EmbeddedCount; -}; - -class CPDF_ToUnicodeMap { - public: - CPDF_ToUnicodeMap(); - ~CPDF_ToUnicodeMap(); - - void Load(CPDF_Stream* pStream); - - CFX_WideString Lookup(uint32_t charcode) const; - uint32_t ReverseLookup(wchar_t unicode) const; - - private: - friend class fpdf_font_StringToCode_Test; - friend class fpdf_font_StringToWideString_Test; - - static uint32_t StringToCode(const CFX_ByteStringC& str); - static CFX_WideString StringToWideString(const CFX_ByteStringC& str); - - uint32_t GetUnicode(); - - std::map<uint32_t, uint32_t> m_Map; - CPDF_CID2UnicodeMap* m_pBaseMap; - CFX_WideTextBuf m_MultiCharBuf; -}; - -class CPDF_FontGlobals { - public: - CPDF_FontGlobals(); - ~CPDF_FontGlobals(); - - void Clear(CPDF_Document* pDoc); - CPDF_Font* Find(CPDF_Document* pDoc, uint32_t index); - - // Takes ownership of |pFont|, returns unowned pointer to it. - CPDF_Font* Set(CPDF_Document* key, - uint32_t index, - std::unique_ptr<CPDF_Font> pFont); - - CPDF_CMapManager m_CMapManager; - struct { - const FXCMAP_CMap* m_pMapList; - uint32_t m_Count; - } m_EmbeddedCharsets[CIDSET_NUM_SETS]; - struct { - const uint16_t* m_pMap; - uint32_t m_Count; - } m_EmbeddedToUnicodes[CIDSET_NUM_SETS]; - - private: - std::map<CPDF_Document*, std::unique_ptr<CFX_StockFontArray>> m_StockMap; -}; - -#endif // CORE_FPDFAPI_FONT_FONT_INT_H_ diff --git a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_color.cpp b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_color.cpp index e6665c83ac8..747e6844ecd 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_color.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_color.cpp @@ -160,6 +160,6 @@ CPDF_Pattern* CPDF_Color::GetPattern() const { if (!m_pBuffer || m_pCS->GetFamily() != PDFCS_PATTERN) return nullptr; - PatternValue* pvalue = (PatternValue*)m_pBuffer; + PatternValue* pvalue = reinterpret_cast<PatternValue*>(m_pBuffer); return pvalue->m_pPattern; } diff --git a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_colorspace.cpp b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_colorspace.cpp index 345180f368e..eef6b40a442 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_colorspace.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_colorspace.cpp @@ -76,7 +76,6 @@ class CPDF_CalGray : public CPDF_ColorSpace { // CPDF_ColorSpace: bool v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) override; bool GetRGB(float* pBuf, float* R, float* G, float* B) const override; - bool SetRGB(float* pBuf, float R, float G, float B) const override; void TranslateImageLine(uint8_t* pDestBuf, const uint8_t* pSrcBuf, int pixels, @@ -98,7 +97,6 @@ class CPDF_CalRGB : public CPDF_ColorSpace { bool v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) override; bool GetRGB(float* pBuf, float* R, float* G, float* B) const override; - bool SetRGB(float* pBuf, float R, float G, float B) const override; void TranslateImageLine(uint8_t* pDestBuf, const uint8_t* pSrcBuf, @@ -148,11 +146,6 @@ class CPDF_ICCBasedCS : public CPDF_ColorSpace { // CPDF_ColorSpace: bool v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) override; bool GetRGB(float* pBuf, float* R, float* G, float* B) const override; - bool v_GetCMYK(float* pBuf, - float* c, - float* m, - float* y, - float* k) const override; void EnableStdConversion(bool bEnabled) override; void TranslateImageLine(uint8_t* pDestBuf, const uint8_t* pSrcBuf, @@ -185,12 +178,11 @@ class CPDF_IndexedCS : public CPDF_ColorSpace { bool v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) override; bool GetRGB(float* pBuf, float* R, float* G, float* B) const override; - CPDF_ColorSpace* GetBaseCS() const override; void EnableStdConversion(bool bEnabled) override; CPDF_ColorSpace* m_pBaseCS; - CPDF_CountedColorSpace* m_pCountedBaseCS; + CFX_UnownedPtr<CPDF_CountedColorSpace> m_pCountedBaseCS; int m_nBaseComponents; int m_MaxIndex; CFX_ByteString m_Table; @@ -469,54 +461,6 @@ float* CPDF_ColorSpace::CreateBuf() { return (float*)pBuf; } -bool CPDF_ColorSpace::sRGB() const { - if (m_Family == PDFCS_DEVICERGB) - return true; - - if (m_Family != PDFCS_ICCBASED) - return false; - - const CPDF_ICCBasedCS* pCS = static_cast<const CPDF_ICCBasedCS*>(this); - return pCS->IsSRGB(); -} - -bool CPDF_ColorSpace::SetRGB(float* pBuf, float R, float G, float B) const { - return false; -} - -bool CPDF_ColorSpace::GetCMYK(float* pBuf, - float* c, - float* m, - float* y, - float* k) const { - if (v_GetCMYK(pBuf, c, m, y, k)) - return true; - - float R; - float G; - float B; - if (!GetRGB(pBuf, &R, &G, &B)) - return false; - - sRGB_to_AdobeCMYK(R, G, B, *c, *m, *y, *k); - return true; -} - -bool CPDF_ColorSpace::SetCMYK(float* pBuf, - float c, - float m, - float y, - float k) const { - if (v_SetCMYK(pBuf, c, m, y, k)) - return true; - - float R; - float G; - float B; - AdobeCMYK_to_sRGB(c, m, y, k, R, G, B); - return SetRGB(pBuf, R, G, B); -} - void CPDF_ColorSpace::GetDefaultColor(float* buf) const { if (!buf || m_Family == PDFCS_PATTERN) return; @@ -562,10 +506,6 @@ void CPDF_ColorSpace::TranslateImageLine(uint8_t* dest_buf, } } -CPDF_ColorSpace* CPDF_ColorSpace::GetBaseCS() const { - return nullptr; -} - void CPDF_ColorSpace::EnableStdConversion(bool bEnabled) { if (bEnabled) m_dwStdConversion++; @@ -588,22 +528,6 @@ bool CPDF_ColorSpace::v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) { return true; } -bool CPDF_ColorSpace::v_GetCMYK(float* pBuf, - float* c, - float* m, - float* y, - float* k) const { - return false; -} - -bool CPDF_ColorSpace::v_SetCMYK(float* pBuf, - float c, - float m, - float y, - float k) const { - return false; -} - CPDF_CalGray::CPDF_CalGray(CPDF_Document* pDoc) : CPDF_ColorSpace(pDoc, PDFCS_CALGRAY, 1) {} @@ -634,14 +558,6 @@ bool CPDF_CalGray::GetRGB(float* pBuf, float* R, float* G, float* B) const { return true; } -bool CPDF_CalGray::SetRGB(float* pBuf, float R, float G, float B) const { - if (R == G && R == B) { - *pBuf = R; - return true; - } - return false; -} - void CPDF_CalGray::TranslateImageLine(uint8_t* pDestBuf, const uint8_t* pSrcBuf, int pixels, @@ -719,13 +635,6 @@ bool CPDF_CalRGB::GetRGB(float* pBuf, float* R, float* G, float* B) const { return true; } -bool CPDF_CalRGB::SetRGB(float* pBuf, float R, float G, float B) const { - pBuf[0] = R; - pBuf[1] = G; - pBuf[2] = B; - return true; -} - void CPDF_CalRGB::TranslateImageLine(uint8_t* pDestBuf, const uint8_t* pSrcBuf, int pixels, @@ -930,21 +839,6 @@ bool CPDF_ICCBasedCS::GetRGB(float* pBuf, float* R, float* G, float* B) const { return true; } -bool CPDF_ICCBasedCS::v_GetCMYK(float* pBuf, - float* c, - float* m, - float* y, - float* k) const { - if (m_nComponents != 4) - return false; - - *c = pBuf[0]; - *m = pBuf[1]; - *y = pBuf[2]; - *k = pBuf[3]; - return true; -} - void CPDF_ICCBasedCS::EnableStdConversion(bool bEnabled) { CPDF_ColorSpace::EnableStdConversion(bEnabled); if (m_pAlterCS) @@ -1124,10 +1018,6 @@ bool CPDF_IndexedCS::GetRGB(float* pBuf, float* R, float* G, float* B) const { return m_pBaseCS->GetRGB(comps, R, G, B); } -CPDF_ColorSpace* CPDF_IndexedCS::GetBaseCS() const { - return m_pBaseCS; -} - void CPDF_IndexedCS::EnableStdConversion(bool bEnabled) { CPDF_ColorSpace::EnableStdConversion(bEnabled); if (m_pBaseCS) diff --git a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_colorspace.h b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_colorspace.h index c8c2abf0da6..a518689dedc 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_colorspace.h +++ b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_colorspace.h @@ -57,12 +57,7 @@ class CPDF_ColorSpace { float* min, float* max) const; - bool sRGB() const; virtual bool GetRGB(float* pBuf, float* R, float* G, float* B) const = 0; - virtual bool SetRGB(float* pBuf, float R, float G, float B) const; - - bool GetCMYK(float* pBuf, float* c, float* m, float* y, float* k) const; - bool SetCMYK(float* pBuf, float c, float m, float y, float k) const; virtual void TranslateImageLine(uint8_t* dest_buf, const uint8_t* src_buf, @@ -70,7 +65,6 @@ class CPDF_ColorSpace { int image_width, int image_height, bool bTransMask) const; - virtual CPDF_ColorSpace* GetBaseCS() const; virtual void EnableStdConversion(bool bEnabled); CPDF_Array* GetArray() const { return m_pArray.Get(); } @@ -81,12 +75,6 @@ class CPDF_ColorSpace { virtual ~CPDF_ColorSpace(); virtual bool v_Load(CPDF_Document* pDoc, CPDF_Array* pArray); - virtual bool v_GetCMYK(float* pBuf, - float* c, - float* m, - float* y, - float* k) const; - virtual bool v_SetCMYK(float* pBuf, float c, float m, float y, float k) const; CFX_UnownedPtr<CPDF_Document> const m_pDocument; int m_Family; diff --git a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_contentparser.h b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_contentparser.h index 58a977301f0..982a6243467 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_contentparser.h +++ b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_contentparser.h @@ -29,6 +29,9 @@ class CPDF_ContentParser { ~CPDF_ContentParser(); ParseStatus GetStatus() const { return m_Status; } + const CPDF_AllStates* GetCurStates() const { + return m_pParser ? m_pParser->GetCurStates() : nullptr; + } void Start(CPDF_Page* pPage); void Start(CPDF_Form* pForm, CPDF_AllStates* pGraphicStates, diff --git a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_devicecs.cpp b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_devicecs.cpp index d410b1fb4ae..b07e620604f 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_devicecs.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_devicecs.cpp @@ -95,9 +95,9 @@ bool CPDF_DeviceCS::GetRGB(float* pBuf, float* R, float* G, float* B) const { *G = 1.0f - std::min(1.0f, pBuf[1] + k); *B = 1.0f - std::min(1.0f, pBuf[2] + k); } else { - AdobeCMYK_to_sRGB(NormalizeChannel(pBuf[0]), NormalizeChannel(pBuf[1]), - NormalizeChannel(pBuf[2]), NormalizeChannel(pBuf[3]), - *R, *G, *B); + std::tie(*R, *G, *B) = AdobeCMYK_to_sRGB( + NormalizeChannel(pBuf[0]), NormalizeChannel(pBuf[1]), + NormalizeChannel(pBuf[2]), NormalizeChannel(pBuf[3])); } return true; default: @@ -106,65 +106,6 @@ bool CPDF_DeviceCS::GetRGB(float* pBuf, float* R, float* G, float* B) const { } } -bool CPDF_DeviceCS::v_GetCMYK(float* pBuf, - float* c, - float* m, - float* y, - float* k) const { - if (m_Family != PDFCS_DEVICECMYK) - return false; - - *c = pBuf[0]; - *m = pBuf[1]; - *y = pBuf[2]; - *k = pBuf[3]; - return true; -} - -bool CPDF_DeviceCS::SetRGB(float* pBuf, float R, float G, float B) const { - switch (m_Family) { - case PDFCS_DEVICEGRAY: - if (R != G || R != B) - return false; - *pBuf = R; - return true; - case PDFCS_DEVICERGB: - pBuf[0] = R; - pBuf[1] = G; - pBuf[2] = B; - return true; - case PDFCS_DEVICECMYK: - sRGB_to_AdobeCMYK(R, G, B, pBuf[0], pBuf[1], pBuf[2], pBuf[3]); - return true; - default: - NOTREACHED(); - return false; - } -} - -bool CPDF_DeviceCS::v_SetCMYK(float* pBuf, - float c, - float m, - float y, - float k) const { - switch (m_Family) { - case PDFCS_DEVICEGRAY: - return false; - case PDFCS_DEVICERGB: - AdobeCMYK_to_sRGB(c, m, y, k, pBuf[0], pBuf[1], pBuf[2]); - return true; - case PDFCS_DEVICECMYK: - pBuf[0] = c; - pBuf[1] = m; - pBuf[2] = y; - pBuf[3] = k; - return true; - default: - NOTREACHED(); - return false; - } -} - void CPDF_DeviceCS::TranslateImageLine(uint8_t* pDestBuf, const uint8_t* pSrcBuf, int pixels, @@ -200,8 +141,9 @@ void CPDF_DeviceCS::TranslateImageLine(uint8_t* pDestBuf, pDestBuf[1] = 255 - std::min(255, pSrcBuf[1] + k); pDestBuf[0] = 255 - std::min(255, pSrcBuf[2] + k); } else { - AdobeCMYK_to_sRGB1(pSrcBuf[0], pSrcBuf[1], pSrcBuf[2], pSrcBuf[3], - pDestBuf[2], pDestBuf[1], pDestBuf[0]); + std::tie(pDestBuf[2], pDestBuf[1], pDestBuf[0]) = + AdobeCMYK_to_sRGB1(pSrcBuf[0], pSrcBuf[1], pSrcBuf[2], + pSrcBuf[3]); } pSrcBuf += 4; pDestBuf += 3; diff --git a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_devicecs.h b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_devicecs.h index 177f240fbc7..d472476b8ba 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_devicecs.h +++ b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_devicecs.h @@ -16,17 +16,6 @@ class CPDF_DeviceCS : public CPDF_ColorSpace { // CPDF_ColorSpace: bool GetRGB(float* pBuf, float* R, float* G, float* B) const override; - bool SetRGB(float* pBuf, float R, float G, float B) const override; - bool v_GetCMYK(float* pBuf, - float* c, - float* m, - float* y, - float* k) const override; - bool v_SetCMYK(float* pBuf, - float c, - float m, - float y, - float k) const override; void TranslateImageLine(uint8_t* pDestBuf, const uint8_t* pSrcBuf, int pixels, diff --git a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_docpagedata.cpp b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_docpagedata.cpp index d8b89b318b4..71143d0b6c7 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_docpagedata.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_docpagedata.cpp @@ -14,7 +14,6 @@ #include "core/fdrm/crypto/fx_crypt.h" #include "core/fpdfapi/cpdf_modulemgr.h" #include "core/fpdfapi/font/cpdf_type1font.h" -#include "core/fpdfapi/font/font_int.h" #include "core/fpdfapi/page/cpdf_iccprofile.h" #include "core/fpdfapi/page/cpdf_image.h" #include "core/fpdfapi/page/cpdf_pagemodule.h" @@ -53,11 +52,26 @@ CPDF_DocPageData::~CPDF_DocPageData() { void CPDF_DocPageData::Clear(bool bForceRelease) { m_bForceClear = bForceRelease; + // This is needed because if |bForceRelease| is true we will destroy any + // pattern we see regardless of the ref-count. The tiling pattern owns a + // Form object which owns a ShadingObject. The ShadingObject has an unowned + // pointer to a ShadingPattern. The ShadingPattern is owned by the + // DocPageData. So, we loop through and clear any tiling patterns before we + // do the same for any shading patterns, otherwise we may free the + // ShadingPattern before the ShadingObject and trigger an unowned pointer + // probe warning. for (auto& it : m_PatternMap) { CPDF_CountedPattern* ptData = it.second; - if (!ptData->get()) + if (!ptData->get() || !ptData->get()->AsTilingPattern()) continue; + if (bForceRelease || ptData->use_count() < 2) + ptData->clear(); + } + for (auto& it : m_PatternMap) { + CPDF_CountedPattern* ptData = it.second; + if (!ptData->get()) + continue; if (bForceRelease || ptData->use_count() < 2) ptData->clear(); } @@ -66,7 +80,6 @@ void CPDF_DocPageData::Clear(bool bForceRelease) { CPDF_CountedFont* fontData = it.second; if (!fontData->get()) continue; - if (bForceRelease || fontData->use_count() < 2) { fontData->clear(); } @@ -76,7 +89,6 @@ void CPDF_DocPageData::Clear(bool bForceRelease) { CPDF_CountedColorSpace* csData = it.second; if (!csData->get()) continue; - if (bForceRelease || csData->use_count() < 2) { csData->get()->Release(); csData->reset(nullptr); diff --git a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_generalstate.cpp b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_generalstate.cpp index e07a3ca13d1..540707447e5 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_generalstate.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_generalstate.cpp @@ -78,6 +78,43 @@ CPDF_GeneralState::~CPDF_GeneralState() {} void CPDF_GeneralState::SetRenderIntent(const CFX_ByteString& ri) { m_Ref.GetPrivateCopy()->m_RenderIntent = RI_StringToId(ri); } +CFX_ByteString CPDF_GeneralState::GetBlendMode() const { + switch (GetBlendType()) { + case FXDIB_BLEND_NORMAL: + return CFX_ByteString("Normal"); + case FXDIB_BLEND_MULTIPLY: + return CFX_ByteString("Multiply"); + case FXDIB_BLEND_SCREEN: + return CFX_ByteString("Screen"); + case FXDIB_BLEND_OVERLAY: + return CFX_ByteString("Overlay"); + case FXDIB_BLEND_DARKEN: + return CFX_ByteString("Darken"); + case FXDIB_BLEND_LIGHTEN: + return CFX_ByteString("Lighten"); + case FXDIB_BLEND_COLORDODGE: + return CFX_ByteString("ColorDodge"); + case FXDIB_BLEND_COLORBURN: + return CFX_ByteString("ColorBurn"); + case FXDIB_BLEND_HARDLIGHT: + return CFX_ByteString("HardLight"); + case FXDIB_BLEND_SOFTLIGHT: + return CFX_ByteString("SoftLight"); + case FXDIB_BLEND_DIFFERENCE: + return CFX_ByteString("Difference"); + case FXDIB_BLEND_EXCLUSION: + return CFX_ByteString("Exclusion"); + case FXDIB_BLEND_HUE: + return CFX_ByteString("Hue"); + case FXDIB_BLEND_SATURATION: + return CFX_ByteString("Saturation"); + case FXDIB_BLEND_COLOR: + return CFX_ByteString("Color"); + case FXDIB_BLEND_LUMINOSITY: + return CFX_ByteString("Luminosity"); + } + return CFX_ByteString("Normal"); +} int CPDF_GeneralState::GetBlendType() const { const StateData* pData = m_Ref.GetObject(); diff --git a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_generalstate.h b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_generalstate.h index 4ec08ca9c5e..356841690b3 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_generalstate.h +++ b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_generalstate.h @@ -27,6 +27,7 @@ class CPDF_GeneralState { void SetRenderIntent(const CFX_ByteString& ri); + CFX_ByteString GetBlendMode() const; int GetBlendType() const; void SetBlendType(int type); diff --git a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_iccprofile.cpp b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_iccprofile.cpp index afb505a7e64..0fa4be4b5af 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_iccprofile.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_iccprofile.cpp @@ -8,7 +8,6 @@ #include "core/fpdfapi/cpdf_modulemgr.h" #include "core/fpdfapi/parser/cpdf_stream.h" -#include "core/fxcodec/codec/ccodec_iccmodule.h" namespace { @@ -29,12 +28,9 @@ CPDF_IccProfile::CPDF_IccProfile(CPDF_Stream* pStream, uint32_t nSrcComps = 0; auto* pIccModule = CPDF_ModuleMgr::Get()->GetIccModule(); - m_pTransform = pIccModule->CreateTransform_sRGB(pData, dwSize, nSrcComps); - if (m_pTransform) + m_Transform = pIccModule->CreateTransform_sRGB(pData, dwSize, &nSrcComps); + if (m_Transform) m_nSrcComponents = nSrcComps; } -CPDF_IccProfile::~CPDF_IccProfile() { - if (m_pTransform) - CPDF_ModuleMgr::Get()->GetIccModule()->DestroyTransform(m_pTransform); -} +CPDF_IccProfile::~CPDF_IccProfile() {} diff --git a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_iccprofile.h b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_iccprofile.h index a0cf744b9c7..156fb595dc0 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_iccprofile.h +++ b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_iccprofile.h @@ -7,6 +7,9 @@ #ifndef CORE_FPDFAPI_PAGE_CPDF_ICCPROFILE_H_ #define CORE_FPDFAPI_PAGE_CPDF_ICCPROFILE_H_ +#include <memory> + +#include "core/fxcodec/codec/ccodec_iccmodule.h" #include "core/fxcrt/cfx_retain_ptr.h" #include "core/fxcrt/cfx_unowned_ptr.h" @@ -20,8 +23,8 @@ class CPDF_IccProfile : public CFX_Retainable { CPDF_Stream* GetStream() const { return m_pStream.Get(); } bool IsValid() const { return IsSRGB() || IsSupported(); } bool IsSRGB() const { return m_bsRGB; } - bool IsSupported() const { return !!m_pTransform; } - void* transform() { return m_pTransform; } + bool IsSupported() const { return !!m_Transform; } + CLcmsCmm* transform() { return m_Transform.get(); } uint32_t GetComponents() const { return m_nSrcComponents; } private: @@ -30,7 +33,7 @@ class CPDF_IccProfile : public CFX_Retainable { const bool m_bsRGB; CFX_UnownedPtr<CPDF_Stream> const m_pStream; - void* m_pTransform = nullptr; + std::unique_ptr<CLcmsCmm> m_Transform; uint32_t m_nSrcComponents = 0; }; diff --git a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_imageobject.cpp b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_imageobject.cpp index 8732c009540..a74ac4802ce 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_imageobject.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_imageobject.cpp @@ -25,6 +25,7 @@ CPDF_PageObject::Type CPDF_ImageObject::GetType() const { void CPDF_ImageObject::Transform(const CFX_Matrix& matrix) { m_Matrix.Concat(matrix); CalcBoundingBox(); + SetDirty(true); } bool CPDF_ImageObject::IsImage() const { diff --git a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_meshstream.cpp b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_meshstream.cpp index 7a6228a25bd..8588734d951 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_meshstream.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_meshstream.cpp @@ -242,19 +242,22 @@ bool CPDF_MeshStream::ReadVertex(const CFX_Matrix& pObject2Bitmap, return true; } -bool CPDF_MeshStream::ReadVertexRow(const CFX_Matrix& pObject2Bitmap, - int count, - CPDF_MeshVertex* vertex) { - for (int i = 0; i < count; i++) { +std::vector<CPDF_MeshVertex> CPDF_MeshStream::ReadVertexRow( + const CFX_Matrix& pObject2Bitmap, + int count) { + std::vector<CPDF_MeshVertex> vertices; + for (int i = 0; i < count; ++i) { if (m_BitStream.IsEOF() || !CanReadCoords()) - return false; + return std::vector<CPDF_MeshVertex>(); - vertex[i].position = pObject2Bitmap.Transform(ReadCoords()); + vertices.push_back(CPDF_MeshVertex()); + CPDF_MeshVertex& vertex = vertices.back(); + vertex.position = pObject2Bitmap.Transform(ReadCoords()); if (!CanReadColor()) - return false; + return std::vector<CPDF_MeshVertex>(); - std::tie(vertex[i].r, vertex[i].g, vertex[i].b) = ReadColor(); + std::tie(vertex.r, vertex.g, vertex.b) = ReadColor(); m_BitStream.ByteAlign(); } - return true; + return vertices; } diff --git a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_meshstream.h b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_meshstream.h index af636a964d7..60c47790a47 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_meshstream.h +++ b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_meshstream.h @@ -54,9 +54,8 @@ class CPDF_MeshStream { bool ReadVertex(const CFX_Matrix& pObject2Bitmap, CPDF_MeshVertex* vertex, uint32_t* flag); - bool ReadVertexRow(const CFX_Matrix& pObject2Bitmap, - int count, - CPDF_MeshVertex* vertex); + std::vector<CPDF_MeshVertex> ReadVertexRow(const CFX_Matrix& pObject2Bitmap, + int count); CFX_BitStream* BitStream() { return &m_BitStream; } uint32_t ComponentBits() const { return m_nComponentBits; } diff --git a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_page.cpp b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_page.cpp index 2f0c83556ca..dfbd342f132 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_page.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_page.cpp @@ -31,32 +31,24 @@ CPDF_Page::CPDF_Page(CPDF_Document* pDocument, if (!pPageDict) return; - CPDF_Object* pageAttr = GetPageAttr("Resources"); - m_pResources = pageAttr ? pageAttr->GetDict() : nullptr; + CPDF_Object* pPageAttr = GetPageAttr("Resources"); + m_pResources = pPageAttr ? pPageAttr->GetDict() : nullptr; m_pPageResources = m_pResources; - int rotate = GetPageRotation(); - CPDF_Array* pMediaBox = ToArray(GetPageAttr("MediaBox")); - CFX_FloatRect mediabox; - if (pMediaBox) { - mediabox = pMediaBox->GetRect(); - mediabox.Normalize(); - } + CFX_FloatRect mediabox = GetBox("MediaBox"); if (mediabox.IsEmpty()) mediabox = CFX_FloatRect(0, 0, 612, 792); - CPDF_Array* pCropBox = ToArray(GetPageAttr("CropBox")); - if (pCropBox) { - m_BBox = pCropBox->GetRect(); - m_BBox.Normalize(); - } + m_BBox = GetBox("CropBox"); if (m_BBox.IsEmpty()) m_BBox = mediabox; else m_BBox.Intersect(mediabox); - m_PageWidth = m_BBox.right - m_BBox.left; - m_PageHeight = m_BBox.top - m_BBox.bottom; + m_PageWidth = m_BBox.Width(); + m_PageHeight = m_BBox.Height(); + + int rotate = GetPageRotation(); if (rotate % 2) std::swap(m_PageWidth, m_PageHeight); @@ -82,6 +74,10 @@ CPDF_Page::CPDF_Page(CPDF_Document* pDocument, CPDF_Page::~CPDF_Page() {} +bool CPDF_Page::IsPage() const { + return true; +} + void CPDF_Page::StartParse() { if (m_ParseState == CONTENT_PARSED || m_ParseState == CONTENT_PARSING) return; @@ -116,6 +112,16 @@ CPDF_Object* CPDF_Page::GetPageAttr(const CFX_ByteString& name) const { return nullptr; } +CFX_FloatRect CPDF_Page::GetBox(const CFX_ByteString& name) const { + CFX_FloatRect box; + CPDF_Array* pBox = ToArray(GetPageAttr(name)); + if (pBox) { + box = pBox->GetRect(); + box.Normalize(); + } + return box; +} + CFX_Matrix CPDF_Page::GetDisplayMatrix(int xPos, int yPos, int xSize, @@ -181,7 +187,9 @@ int CPDF_Page::GetPageRotation() const { bool GraphicsData::operator<(const GraphicsData& other) const { if (fillAlpha != other.fillAlpha) return fillAlpha < other.fillAlpha; - return strokeAlpha < other.strokeAlpha; + if (strokeAlpha != other.strokeAlpha) + return strokeAlpha < other.strokeAlpha; + return blendType < other.blendType; } bool FontData::operator<(const FontData& other) const { diff --git a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_page.h b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_page.h index b0dfa26124c..82df60ce9f5 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_page.h +++ b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_page.h @@ -7,7 +7,6 @@ #ifndef CORE_FPDFAPI_PAGE_CPDF_PAGE_H_ #define CORE_FPDFAPI_PAGE_CPDF_PAGE_H_ -#include <map> #include <memory> #include "core/fpdfapi/page/cpdf_pageobjectholder.h" @@ -21,20 +20,6 @@ class CPDF_Object; class CPDF_PageRenderCache; class CPDF_PageRenderContext; -// These structs are used to keep track of resources that have already been -// generated in the page. -struct GraphicsData { - float fillAlpha; - float strokeAlpha; - bool operator<(const GraphicsData& other) const; -}; - -struct FontData { - CFX_ByteString baseFont; - CFX_ByteString type; - bool operator<(const FontData& other) const; -}; - class CPDF_Page : public CPDF_PageObjectHolder { public: class View {}; // Caller implements as desired, empty here due to layering. @@ -44,6 +29,9 @@ class CPDF_Page : public CPDF_PageObjectHolder { bool bPageCache); ~CPDF_Page() override; + // CPDF_PageObjectHolder + bool IsPage() const override; + void ParseContent(); CFX_Matrix GetDisplayMatrix(int xPos, @@ -57,7 +45,6 @@ class CPDF_Page : public CPDF_PageObjectHolder { CFX_FloatRect GetPageBBox() const { return m_BBox; } const CFX_Matrix& GetPageMatrix() const { return m_PageMatrix; } int GetPageRotation() const; - CPDF_Object* GetPageAttr(const CFX_ByteString& name) const; CPDF_PageRenderCache* GetRenderCache() const { return m_pPageRender.get(); } CPDF_PageRenderContext* GetRenderContext() const { @@ -68,12 +55,12 @@ class CPDF_Page : public CPDF_PageObjectHolder { View* GetView() const { return m_pView; } void SetView(View* pView) { m_pView = pView; } - std::map<GraphicsData, CFX_ByteString> m_GraphicsMap; - std::map<FontData, CFX_ByteString> m_FontsMap; - - protected: + private: void StartParse(); + CPDF_Object* GetPageAttr(const CFX_ByteString& name) const; + CFX_FloatRect GetBox(const CFX_ByteString& name) const; + float m_PageWidth; float m_PageHeight; CFX_Matrix m_PageMatrix; diff --git a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_pagemodule.h b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_pagemodule.h index 49d2769f88b..720ee854643 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_pagemodule.h +++ b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_pagemodule.h @@ -7,7 +7,7 @@ #ifndef CORE_FPDFAPI_PAGE_CPDF_PAGEMODULE_H_ #define CORE_FPDFAPI_PAGE_CPDF_PAGEMODULE_H_ -#include "core/fpdfapi/font/font_int.h" +#include "core/fpdfapi/font/cpdf_fontglobals.h" #include "core/fpdfapi/page/cpdf_colorspace.h" #include "core/fpdfapi/page/cpdf_devicecs.h" #include "core/fpdfapi/page/cpdf_patterncs.h" diff --git a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_pageobject.cpp b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_pageobject.cpp index 09a98eee7d9..79d9bbc5409 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_pageobject.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_pageobject.cpp @@ -6,7 +6,7 @@ #include "core/fpdfapi/page/cpdf_pageobject.h" -CPDF_PageObject::CPDF_PageObject() {} +CPDF_PageObject::CPDF_PageObject() : m_bDirty(false) {} CPDF_PageObject::~CPDF_PageObject() {} @@ -76,18 +76,21 @@ void CPDF_PageObject::CopyData(const CPDF_PageObject* pSrc) { m_Right = pSrc->m_Right; m_Top = pSrc->m_Top; m_Bottom = pSrc->m_Bottom; + m_bDirty = true; } void CPDF_PageObject::TransformClipPath(CFX_Matrix& matrix) { if (!m_ClipPath.HasRef()) return; m_ClipPath.Transform(matrix); + SetDirty(true); } void CPDF_PageObject::TransformGeneralState(CFX_Matrix& matrix) { if (!m_GeneralState.HasRef()) return; m_GeneralState.GetMutableMatrix()->Concat(matrix); + SetDirty(true); } FX_RECT CPDF_PageObject::GetBBox(const CFX_Matrix* pMatrix) const { diff --git a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_pageobject.h b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_pageobject.h index 668621ff512..d23cd971f80 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_pageobject.h +++ b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_pageobject.h @@ -49,6 +49,8 @@ class CPDF_PageObject : public CPDF_GraphicStates { virtual CPDF_FormObject* AsForm(); virtual const CPDF_FormObject* AsForm() const; + void SetDirty(bool value) { m_bDirty = value; } + bool IsDirty() const { return m_bDirty; } void TransformClipPath(CFX_Matrix& matrix); void TransformGeneralState(CFX_Matrix& matrix); @@ -69,6 +71,8 @@ class CPDF_PageObject : public CPDF_GraphicStates { private: CPDF_PageObject(const CPDF_PageObject& src) = delete; void operator=(const CPDF_PageObject& src) = delete; + + bool m_bDirty; }; #endif // CORE_FPDFAPI_PAGE_CPDF_PAGEOBJECT_H_ diff --git a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_pageobjectholder.cpp b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_pageobjectholder.cpp index 53dfd75d5d7..138cb0d2041 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_pageobjectholder.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_pageobjectholder.cpp @@ -8,6 +8,7 @@ #include <algorithm> +#include "core/fpdfapi/page/cpdf_allstates.h" #include "core/fpdfapi/page/cpdf_contentparser.h" #include "core/fpdfapi/page/cpdf_pageobject.h" #include "core/fpdfapi/parser/cpdf_dictionary.h" @@ -25,6 +26,10 @@ CPDF_PageObjectHolder::CPDF_PageObjectHolder(CPDF_Document* pDoc, CPDF_PageObjectHolder::~CPDF_PageObjectHolder() {} +bool CPDF_PageObjectHolder::IsPage() const { + return false; +} + void CPDF_PageObjectHolder::ContinueParse(IFX_Pause* pPause) { if (!m_pParser) return; @@ -34,6 +39,8 @@ void CPDF_PageObjectHolder::ContinueParse(IFX_Pause* pPause) { return; m_ParseState = CONTENT_PARSED; + if (m_pParser->GetCurStates()) + m_LastCTM = m_pParser->GetCurStates()->m_CTM; m_pParser.reset(); } @@ -48,7 +55,7 @@ void CPDF_PageObjectHolder::Transform(const CFX_Matrix& matrix) { CFX_FloatRect CPDF_PageObjectHolder::CalcBoundingBox() const { if (m_PageObjectList.empty()) - return CFX_FloatRect(0, 0, 0, 0); + return CFX_FloatRect(); float left = 1000000.0f; float right = -1000000.0f; diff --git a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_pageobjectholder.h b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_pageobjectholder.h index c95ae505205..87ebbc84605 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_pageobjectholder.h +++ b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_pageobjectholder.h @@ -7,6 +7,7 @@ #ifndef CORE_FPDFAPI_PAGE_CPDF_PAGEOBJECTHOLDER_H_ #define CORE_FPDFAPI_PAGE_CPDF_PAGEOBJECTHOLDER_H_ +#include <map> #include <memory> #include <vector> @@ -25,11 +26,28 @@ class CPDF_ContentParser; #define PDFTRANS_ISOLATED 0x0200 #define PDFTRANS_KNOCKOUT 0x0400 +// These structs are used to keep track of resources that have already been +// generated in the page object holder. +struct GraphicsData { + float fillAlpha; + float strokeAlpha; + int blendType; + bool operator<(const GraphicsData& other) const; +}; + +struct FontData { + CFX_ByteString baseFont; + CFX_ByteString type; + bool operator<(const FontData& other) const; +}; + class CPDF_PageObjectHolder { public: CPDF_PageObjectHolder(CPDF_Document* pDoc, CPDF_Dictionary* pFormDict); virtual ~CPDF_PageObjectHolder(); + virtual bool IsPage() const; + void ContinueParse(IFX_Pause* pPause); bool IsParsed() const { return m_ParseState == CONTENT_PARSED; } @@ -37,6 +55,7 @@ class CPDF_PageObjectHolder { const CPDF_PageObjectList* GetPageObjectList() const { return &m_PageObjectList; } + const CFX_Matrix& GetLastCTM() const { return m_LastCTM; } bool BackgroundAlphaNeeded() const { return m_bBackgroundAlphaNeeded; } void SetBackgroundAlphaNeeded(bool needed) { @@ -56,6 +75,8 @@ class CPDF_PageObjectHolder { CFX_UnownedPtr<CPDF_Document> m_pDocument; CFX_UnownedPtr<CPDF_Dictionary> m_pPageResources; CFX_UnownedPtr<CPDF_Dictionary> m_pResources; + std::map<GraphicsData, CFX_ByteString> m_GraphicsMap; + std::map<FontData, CFX_ByteString> m_FontsMap; CFX_FloatRect m_BBox; int m_Transparency; @@ -69,6 +90,7 @@ class CPDF_PageObjectHolder { ParseState m_ParseState; std::unique_ptr<CPDF_ContentParser> m_pParser; CPDF_PageObjectList m_PageObjectList; + CFX_Matrix m_LastCTM; }; #endif // CORE_FPDFAPI_PAGE_CPDF_PAGEOBJECTHOLDER_H_ diff --git a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_pathobject.cpp b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_pathobject.cpp index c4d55bc20f2..b54ad6e151c 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_pathobject.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_pathobject.cpp @@ -17,6 +17,7 @@ CPDF_PageObject::Type CPDF_PathObject::GetType() const { void CPDF_PathObject::Transform(const CFX_Matrix& matrix) { m_Matrix.Concat(matrix); CalcBoundingBox(); + SetDirty(true); } bool CPDF_PathObject::IsPath() const { diff --git a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_patterncs.cpp b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_patterncs.cpp index 4951f61d543..46b975ab67e 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_patterncs.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_patterncs.cpp @@ -56,7 +56,3 @@ bool CPDF_PatternCS::GetRGB(float* pBuf, float* R, float* G, float* B) const { *B = 0.75f; return false; } - -CPDF_ColorSpace* CPDF_PatternCS::GetBaseCS() const { - return m_pBaseCS; -} diff --git a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_patterncs.h b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_patterncs.h index d28fff19c96..ff5ad827ccf 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_patterncs.h +++ b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_patterncs.h @@ -19,7 +19,6 @@ class CPDF_PatternCS : public CPDF_ColorSpace { // CPDF_ColorSpace: bool v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) override; bool GetRGB(float* pBuf, float* R, float* G, float* B) const override; - CPDF_ColorSpace* GetBaseCS() const override; private: CPDF_ColorSpace* m_pBaseCS; diff --git a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_shadingobject.cpp b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_shadingobject.cpp index 5454380caee..8a61161f171 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_shadingobject.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_shadingobject.cpp @@ -6,7 +6,6 @@ #include "core/fpdfapi/page/cpdf_shadingobject.h" -#include "core/fpdfapi/page/cpdf_docpagedata.h" #include "core/fpdfapi/page/cpdf_shadingpattern.h" #include "core/fpdfapi/parser/cpdf_document.h" diff --git a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_shadingobject.h b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_shadingobject.h index ffd622379eb..9db67128247 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_shadingobject.h +++ b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_shadingobject.h @@ -8,6 +8,7 @@ #define CORE_FPDFAPI_PAGE_CPDF_SHADINGOBJECT_H_ #include "core/fpdfapi/page/cpdf_pageobject.h" +#include "core/fxcrt/cfx_unowned_ptr.h" #include "core/fxcrt/fx_coordinates.h" class CPDF_ShadingPattern; @@ -26,7 +27,7 @@ class CPDF_ShadingObject : public CPDF_PageObject { void CalcBoundingBox(); - CPDF_ShadingPattern* m_pShading; + CFX_UnownedPtr<CPDF_ShadingPattern> m_pShading; CFX_Matrix m_Matrix; }; diff --git a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_shadingpattern.cpp b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_shadingpattern.cpp index c21f51cb770..542c4051c5f 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_shadingpattern.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_shadingpattern.cpp @@ -45,11 +45,13 @@ CPDF_ShadingPattern::CPDF_ShadingPattern(CPDF_Document* pDoc, } CPDF_ShadingPattern::~CPDF_ShadingPattern() { - CPDF_ColorSpace* pCS = m_pCountedCS ? m_pCountedCS->get() : nullptr; - if (pCS) { + CPDF_ColorSpace* pCountedCS = m_pCountedCS ? m_pCountedCS->get() : nullptr; + if (pCountedCS) { auto* pPageData = document()->GetPageData(); - if (pPageData) - pPageData->ReleaseColorSpace(pCS->GetArray()); + if (pPageData) { + m_pCS.Release(); // Give up unowned reference first. + pPageData->ReleaseColorSpace(pCountedCS->GetArray()); + } } } diff --git a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_shadingpattern.h b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_shadingpattern.h index 068d772bc3f..24ad4c200e9 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_shadingpattern.h +++ b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_shadingpattern.h @@ -55,7 +55,7 @@ class CPDF_ShadingPattern : public CPDF_Pattern { ShadingType GetShadingType() const { return m_ShadingType; } bool IsShadingObject() const { return m_bShadingObj; } CPDF_Object* GetShadingObject() const { return m_pShadingObj.Get(); } - CPDF_ColorSpace* GetCS() const { return m_pCS; } + CPDF_ColorSpace* GetCS() const { return m_pCS.Get(); } const std::vector<std::unique_ptr<CPDF_Function>>& GetFuncs() const { return m_pFunctions; } @@ -67,9 +67,9 @@ class CPDF_ShadingPattern : public CPDF_Pattern { // Still keep |m_pCS| as some CPDF_ColorSpace (name object) are not managed // as counted objects. Refer to CPDF_DocPageData::GetColorSpace. - CPDF_ColorSpace* m_pCS; + CFX_UnownedPtr<CPDF_ColorSpace> m_pCS; - CPDF_CountedColorSpace* m_pCountedCS; + CFX_UnownedPtr<CPDF_CountedColorSpace> m_pCountedCS; std::vector<std::unique_ptr<CPDF_Function>> m_pFunctions; }; diff --git a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_streamcontentparser.cpp b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_streamcontentparser.cpp index 151b0e644ec..e00dbc54fdf 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_streamcontentparser.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_streamcontentparser.cpp @@ -75,11 +75,11 @@ CFX_FloatRect GetShadingBBox(CPDF_ShadingPattern* pShading, CPDF_Stream* pStream = ToStream(pShading->GetShadingObject()); CPDF_ColorSpace* pCS = pShading->GetCS(); if (!pStream || !pCS) - return CFX_FloatRect(0, 0, 0, 0); + return CFX_FloatRect(); CPDF_MeshStream stream(type, pShading->GetFuncs(), pStream, pCS); if (!stream.Load()) - return CFX_FloatRect(0, 0, 0, 0); + return CFX_FloatRect(); CFX_FloatRect rect; bool bStarted = false; diff --git a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_streamparser.cpp b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_streamparser.cpp index e8116cf980b..964d600b3d6 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_streamparser.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_streamparser.cpp @@ -8,7 +8,9 @@ #include <limits.h> +#include <algorithm> #include <memory> +#include <sstream> #include <utility> #include "core/fpdfapi/cpdf_modulemgr.h" @@ -34,8 +36,8 @@ const uint32_t kMaxWordBuffer = 256; const FX_STRSIZE kMaxStringLength = 32767; uint32_t DecodeAllScanlines(std::unique_ptr<CCodec_ScanlineDecoder> pDecoder, - uint8_t*& dest_buf, - uint32_t& dest_size) { + uint8_t** dest_buf, + uint32_t* dest_size) { if (!pDecoder) return FX_INVALID_OFFSET; int ncomps = pDecoder->CountComps(); @@ -46,26 +48,29 @@ uint32_t DecodeAllScanlines(std::unique_ptr<CCodec_ScanlineDecoder> pDecoder, if (height == 0 || pitch > (1 << 30) / height) return FX_INVALID_OFFSET; - dest_buf = FX_Alloc2D(uint8_t, pitch, height); - dest_size = pitch * height; // Safe since checked alloc returned. - for (int row = 0; row < height; row++) { + *dest_buf = FX_Alloc2D(uint8_t, pitch, height); + *dest_size = pitch * height; // Safe since checked alloc returned. + for (int row = 0; row < height; ++row) { const uint8_t* pLine = pDecoder->GetScanline(row); if (!pLine) break; - memcpy(dest_buf + row * pitch, pLine, pitch); + memcpy(*dest_buf + row * pitch, pLine, pitch); } return pDecoder->GetSrcOffset(); } -uint32_t PDF_DecodeInlineStream(const uint8_t* src_buf, - uint32_t limit, - int width, - int height, - const CFX_ByteString& decoder, - CPDF_Dictionary* pParam, - uint8_t*& dest_buf, - uint32_t& dest_size) { +} // namespace + +// Static +uint32_t CPDF_StreamParser::DecodeInlineStream(const uint8_t* src_buf, + uint32_t limit, + int width, + int height, + const CFX_ByteString& decoder, + CPDF_Dictionary* pParam, + uint8_t** dest_buf, + uint32_t* dest_size) { if (decoder == "CCITTFaxDecode" || decoder == "CCF") { std::unique_ptr<CCodec_ScanlineDecoder> pDecoder = FPDFAPI_CreateFaxDecoder(src_buf, limit, width, height, pParam); @@ -76,7 +81,7 @@ uint32_t PDF_DecodeInlineStream(const uint8_t* src_buf, if (decoder == "ASCIIHexDecode" || decoder == "AHx") return HexDecode(src_buf, limit, dest_buf, dest_size); if (decoder == "FlateDecode" || decoder == "Fl") { - return FPDFAPI_FlateOrLZWDecode(false, src_buf, limit, pParam, dest_size, + return FPDFAPI_FlateOrLZWDecode(false, src_buf, limit, pParam, *dest_size, dest_buf, dest_size); } if (decoder == "LZWDecode" || decoder == "LZW") { @@ -92,27 +97,19 @@ uint32_t PDF_DecodeInlineStream(const uint8_t* src_buf, } if (decoder == "RunLengthDecode" || decoder == "RL") return RunLengthDecode(src_buf, limit, dest_buf, dest_size); - dest_size = 0; - dest_buf = 0; + *dest_size = 0; + *dest_buf = 0; return 0xFFFFFFFF; } -} // namespace - CPDF_StreamParser::CPDF_StreamParser(const uint8_t* pData, uint32_t dwSize) - : m_pBuf(pData), - m_Size(dwSize), - m_Pos(0), - m_pPool(nullptr) {} + : m_pBuf(pData), m_Size(dwSize), m_Pos(0), m_pPool(nullptr) {} CPDF_StreamParser::CPDF_StreamParser( const uint8_t* pData, uint32_t dwSize, const CFX_WeakPtr<CFX_ByteStringPool>& pPool) - : m_pBuf(pData), - m_Size(dwSize), - m_Pos(0), - m_pPool(pPool) {} + : m_pBuf(pData), m_Size(dwSize), m_Pos(0), m_pPool(pPool) {} CPDF_StreamParser::~CPDF_StreamParser() {} @@ -191,8 +188,8 @@ std::unique_ptr<CPDF_Stream> CPDF_StreamParser::ReadInlineStream( uint8_t* pIgnore = nullptr; uint32_t dwDestSize = OrigSize; dwStreamSize = - PDF_DecodeInlineStream(m_pBuf + m_Pos, m_Size - m_Pos, width, height, - Decoder, pParam, pIgnore, dwDestSize); + DecodeInlineStream(m_pBuf + m_Pos, m_Size - m_Pos, width, height, + Decoder, pParam, &pIgnore, &dwDestSize); FX_Free(pIgnore); if (static_cast<int>(dwStreamSize) < 0) return nullptr; @@ -220,7 +217,7 @@ std::unique_ptr<CPDF_Stream> CPDF_StreamParser::ReadInlineStream( memcpy(pData.get(), m_pBuf + m_Pos, dwStreamSize); m_Pos += dwStreamSize; } - pDict->SetNewFor<CPDF_Number>("Length", (int)dwStreamSize); + pDict->SetNewFor<CPDF_Number>("Length", static_cast<int>(dwStreamSize)); return pdfium::MakeUnique<CPDF_Stream>(std::move(pData), dwStreamSize, std::move(pDict)); } @@ -473,7 +470,7 @@ CFX_ByteString CPDF_StreamParser::ReadString() { return CFX_ByteString(); uint8_t ch = m_pBuf[m_Pos++]; - CFX_ByteTextBuf buf; + std::ostringstream buf; int parlevel = 0; int status = 0; int iEscCode = 0; @@ -482,20 +479,19 @@ CFX_ByteString CPDF_StreamParser::ReadString() { case 0: if (ch == ')') { if (parlevel == 0) { - if (buf.GetLength() > kMaxStringLength) { - return CFX_ByteString(buf.GetBuffer(), kMaxStringLength); - } - return buf.MakeString(); + return CFX_ByteString( + buf.str().c_str(), + std::min(static_cast<int>(buf.tellp()), kMaxStringLength)); } parlevel--; - buf.AppendChar(')'); + buf << ')'; } else if (ch == '(') { parlevel++; - buf.AppendChar('('); + buf << '('; } else if (ch == '\\') { status = 1; } else { - buf.AppendChar((char)ch); + buf << static_cast<char>(ch); } break; case 1: @@ -505,21 +501,21 @@ CFX_ByteString CPDF_StreamParser::ReadString() { break; } if (ch == 'n') { - buf.AppendChar('\n'); + buf << '\n'; } else if (ch == 'r') { - buf.AppendChar('\r'); + buf << '\r'; } else if (ch == 't') { - buf.AppendChar('\t'); + buf << '\t'; } else if (ch == 'b') { - buf.AppendChar('\b'); + buf << '\b'; } else if (ch == 'f') { - buf.AppendChar('\f'); + buf << '\f'; } else if (ch == '\r') { status = 4; break; } else if (ch == '\n') { } else { - buf.AppendChar(ch); + buf << static_cast<char>(ch); } status = 0; break; @@ -529,7 +525,7 @@ CFX_ByteString CPDF_StreamParser::ReadString() { iEscCode * 8 + FXSYS_DecimalCharToInt(static_cast<char>(ch)); status = 3; } else { - buf.AppendChar(iEscCode); + buf << static_cast<char>(iEscCode); status = 0; continue; } @@ -538,19 +534,18 @@ CFX_ByteString CPDF_StreamParser::ReadString() { if (ch >= '0' && ch <= '7') { iEscCode = iEscCode * 8 + FXSYS_DecimalCharToInt(static_cast<char>(ch)); - buf.AppendChar(iEscCode); + buf << static_cast<char>(iEscCode); status = 0; } else { - buf.AppendChar(iEscCode); + buf << static_cast<char>(iEscCode); status = 0; continue; } break; case 4: status = 0; - if (ch != '\n') { + if (ch != '\n') continue; - } break; } if (!PositionIsInBounds()) @@ -561,17 +556,16 @@ CFX_ByteString CPDF_StreamParser::ReadString() { if (PositionIsInBounds()) ++m_Pos; - if (buf.GetLength() > kMaxStringLength) { - return CFX_ByteString(buf.GetBuffer(), kMaxStringLength); - } - return buf.MakeString(); + return CFX_ByteString( + buf.str().c_str(), + std::min(static_cast<int>(buf.tellp()), kMaxStringLength)); } CFX_ByteString CPDF_StreamParser::ReadHexString() { if (!PositionIsInBounds()) return CFX_ByteString(); - CFX_ByteTextBuf buf; + std::ostringstream buf; bool bFirst = true; int code = 0; while (PositionIsInBounds()) { @@ -588,17 +582,16 @@ CFX_ByteString CPDF_StreamParser::ReadHexString() { code = val * 16; } else { code += val; - buf.AppendByte((uint8_t)code); + buf << static_cast<uint8_t>(code); } bFirst = !bFirst; } if (!bFirst) - buf.AppendChar((char)code); - - if (buf.GetLength() > kMaxStringLength) - return CFX_ByteString(buf.GetBuffer(), kMaxStringLength); + buf << static_cast<char>(code); - return buf.MakeString(); + return CFX_ByteString( + buf.str().c_str(), + std::min(static_cast<int>(buf.tellp()), kMaxStringLength)); } bool CPDF_StreamParser::PositionIsInBounds() const { diff --git a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_streamparser.h b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_streamparser.h index fdc418c634b..9f9a8eaf12a 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_streamparser.h +++ b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_streamparser.h @@ -21,6 +21,15 @@ class CPDF_StreamParser { public: enum SyntaxType { EndOfData, Number, Keyword, Name, Others }; + static uint32_t DecodeInlineStream(const uint8_t* src_buf, + uint32_t limit, + int width, + int height, + const CFX_ByteString& decoder, + CPDF_Dictionary* pParam, + uint8_t** dest_buf, + uint32_t* dest_size); + CPDF_StreamParser(const uint8_t* pData, uint32_t dwSize); CPDF_StreamParser(const uint8_t* pData, uint32_t dwSize, diff --git a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_textobject.cpp b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_textobject.cpp index b8f3f610734..7a70101789e 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_textobject.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/page/cpdf_textobject.cpp @@ -115,6 +115,7 @@ void CPDF_TextObject::Transform(const CFX_Matrix& matrix) { pTextMatrix[3] = text_matrix.d; m_Pos = CFX_PointF(text_matrix.e, text_matrix.f); CalcPositionData(0); + SetDirty(true); } bool CPDF_TextObject::IsText() const { @@ -164,6 +165,7 @@ void CPDF_TextObject::SetSegments(const CFX_ByteString* pStrs, void CPDF_TextObject::SetText(const CFX_ByteString& str) { SetSegments(&str, nullptr, 1); RecalcPositionData(); + SetDirty(true); } float CPDF_TextObject::GetCharWidth(uint32_t charcode) const { diff --git a/chromium/third_party/pdfium/core/fpdfapi/parser/cfdf_document.h b/chromium/third_party/pdfium/core/fpdfapi/parser/cfdf_document.h index f83adc1a308..9a138775446 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/parser/cfdf_document.h +++ b/chromium/third_party/pdfium/core/fpdfapi/parser/cfdf_document.h @@ -11,6 +11,7 @@ #include "core/fpdfapi/parser/cpdf_indirect_object_holder.h" #include "core/fpdfapi/parser/cpdf_object.h" +#include "core/fxcrt/cfx_unowned_ptr.h" #include "core/fxcrt/fx_basic.h" class CPDF_Dictionary; @@ -27,12 +28,12 @@ class CFDF_Document : public CPDF_IndirectObjectHolder { ~CFDF_Document() override; bool WriteBuf(CFX_ByteTextBuf& buf) const; - CPDF_Dictionary* GetRoot() const { return m_pRootDict; } + CPDF_Dictionary* GetRoot() const { return m_pRootDict.Get(); } protected: void ParseStream(const CFX_RetainPtr<IFX_SeekableReadStream>& pFile); - CPDF_Dictionary* m_pRootDict; + CFX_UnownedPtr<CPDF_Dictionary> m_pRootDict; CFX_RetainPtr<IFX_SeekableReadStream> m_pFile; }; diff --git a/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_array.cpp b/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_array.cpp index 4caad10631e..1f2740ea9c6 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_array.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_array.cpp @@ -105,6 +105,12 @@ CFX_ByteString CPDF_Array::GetStringAt(size_t i) const { return m_Objects[i]->GetString(); } +CFX_WideString CPDF_Array::GetUnicodeTextAt(size_t i) const { + if (i >= m_Objects.size()) + return CFX_WideString(); + return m_Objects[i]->GetUnicodeText(); +} + int CPDF_Array::GetIntegerAt(size_t i) const { if (i >= m_Objects.size()) return 0; @@ -136,14 +142,20 @@ CPDF_Array* CPDF_Array::GetArrayAt(size_t i) const { return ToArray(GetDirectObjectAt(i)); } -void CPDF_Array::RemoveAt(size_t i, size_t nCount) { - if (i >= m_Objects.size()) - return; +void CPDF_Array::RemoveAt(size_t i) { + if (i < m_Objects.size()) + m_Objects.erase(m_Objects.begin() + i); +} + +void CPDF_Array::Clear() { + m_Objects.clear(); +} - if (nCount <= 0 || nCount > m_Objects.size() - i) +void CPDF_Array::Truncate(size_t nNewSize) { + if (nNewSize >= m_Objects.size()) return; - m_Objects.erase(m_Objects.begin() + i, m_Objects.begin() + i + nCount); + m_Objects.resize(nNewSize); } void CPDF_Array::ConvertToIndirectObjectAt(size_t i, diff --git a/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_array.h b/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_array.h index aff65d14548..2590971d80d 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_array.h +++ b/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_array.h @@ -41,6 +41,7 @@ class CPDF_Array : public CPDF_Object { CPDF_Object* GetObjectAt(size_t index) const; CPDF_Object* GetDirectObjectAt(size_t index) const; CFX_ByteString GetStringAt(size_t index) const; + CFX_WideString GetUnicodeTextAt(size_t index) const; int GetIntegerAt(size_t index) const; float GetNumberAt(size_t index) const; CPDF_Dictionary* GetDictAt(size_t index) const; @@ -99,7 +100,9 @@ class CPDF_Array : public CPDF_Object { index, pdfium::MakeUnique<T>(m_pPool, std::forward<Args>(args)...))); } - void RemoveAt(size_t index, size_t nCount = 1); + void RemoveAt(size_t index); + void Clear(); + void Truncate(size_t nNewSize); void ConvertToIndirectObjectAt(size_t index, CPDF_IndirectObjectHolder* pDoc); const_iterator begin() const { return m_Objects.begin(); } diff --git a/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_array_unittest.cpp b/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_array_unittest.cpp index 1e92b32716c..006e5fad335 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_array_unittest.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_array_unittest.cpp @@ -14,52 +14,85 @@ TEST(cpdf_array, RemoveAt) { { - int elems[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + const int elems[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; auto arr = pdfium::MakeUnique<CPDF_Array>(); for (size_t i = 0; i < FX_ArraySize(elems); ++i) arr->AddNew<CPDF_Number>(elems[i]); - arr->RemoveAt(3, 3); - int expected[] = {1, 2, 3, 7, 8, 9, 10}; - EXPECT_EQ(FX_ArraySize(expected), arr->GetCount()); + for (size_t i = 0; i < 3; ++i) + arr->RemoveAt(3); + const int expected[] = {1, 2, 3, 7, 8, 9, 10}; + ASSERT_EQ(FX_ArraySize(expected), arr->GetCount()); for (size_t i = 0; i < FX_ArraySize(expected); ++i) EXPECT_EQ(expected[i], arr->GetIntegerAt(i)); - arr->RemoveAt(4, 2); - int expected2[] = {1, 2, 3, 7, 10}; - EXPECT_EQ(FX_ArraySize(expected2), arr->GetCount()); + arr->RemoveAt(4); + arr->RemoveAt(4); + const int expected2[] = {1, 2, 3, 7, 10}; + ASSERT_EQ(FX_ArraySize(expected2), arr->GetCount()); for (size_t i = 0; i < FX_ArraySize(expected2); ++i) EXPECT_EQ(expected2[i], arr->GetIntegerAt(i)); } { - // When the range is out of bound, RemoveAt has no effect. - int elems[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + // When the range is out of bound, RemoveAt() has no effect. + const int elems[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; auto arr = pdfium::MakeUnique<CPDF_Array>(); for (size_t i = 0; i < FX_ArraySize(elems); ++i) arr->AddNew<CPDF_Number>(elems[i]); - arr->RemoveAt(8, 5); + arr->RemoveAt(11); EXPECT_EQ(FX_ArraySize(elems), arr->GetCount()); + } +} + +TEST(cpdf_array, Clear) { + const int elems[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + auto arr = pdfium::MakeUnique<CPDF_Array>(); + EXPECT_EQ(0U, arr->GetCount()); + for (size_t i = 0; i < FX_ArraySize(elems); ++i) + arr->AddNew<CPDF_Number>(elems[i]); + EXPECT_EQ(FX_ArraySize(elems), arr->GetCount()); + arr->Clear(); + EXPECT_EQ(0U, arr->GetCount()); +} + +TEST(cpdf_array, Truncate) { + { + const int elems[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + auto arr = pdfium::MakeUnique<CPDF_Array>(); for (size_t i = 0; i < FX_ArraySize(elems); ++i) - EXPECT_EQ(elems[i], arr->GetIntegerAt(i)); - arr->RemoveAt(0, 12); - EXPECT_EQ(FX_ArraySize(elems), arr->GetCount()); - arr->RemoveAt(11, 1); + arr->AddNew<CPDF_Number>(elems[i]); + arr->Truncate(4); + const int expected[] = {1, 2, 3, 4}; + ASSERT_EQ(FX_ArraySize(expected), arr->GetCount()); + for (size_t i = 0; i < FX_ArraySize(expected); ++i) + EXPECT_EQ(expected[i], arr->GetIntegerAt(i)); + arr->Truncate(0); + EXPECT_EQ(0U, arr->GetCount()); + } + { + // When the range is out of bound, Truncate() has no effect. + // It does not try to grow the array. + const int elems[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + auto arr = pdfium::MakeUnique<CPDF_Array>(); + for (size_t i = 0; i < FX_ArraySize(elems); ++i) + arr->AddNew<CPDF_Number>(elems[i]); + arr->Truncate(11); EXPECT_EQ(FX_ArraySize(elems), arr->GetCount()); } } TEST(cpdf_array, InsertAt) { { - int elems[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + const int elems[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; auto arr = pdfium::MakeUnique<CPDF_Array>(); for (size_t i = 0; i < FX_ArraySize(elems); ++i) arr->InsertNewAt<CPDF_Number>(i, elems[i]); - EXPECT_EQ(FX_ArraySize(elems), arr->GetCount()); + ASSERT_EQ(FX_ArraySize(elems), arr->GetCount()); for (size_t i = 0; i < FX_ArraySize(elems); ++i) EXPECT_EQ(elems[i], arr->GetIntegerAt(i)); arr->InsertNewAt<CPDF_Number>(3, 33); arr->InsertNewAt<CPDF_Number>(6, 55); arr->InsertNewAt<CPDF_Number>(12, 12); - int expected[] = {1, 2, 3, 33, 4, 5, 55, 6, 7, 8, 9, 10, 12}; - EXPECT_EQ(FX_ArraySize(expected), arr->GetCount()); + const int expected[] = {1, 2, 3, 33, 4, 5, 55, 6, 7, 8, 9, 10, 12}; + ASSERT_EQ(FX_ArraySize(expected), arr->GetCount()); for (size_t i = 0; i < FX_ArraySize(expected); ++i) EXPECT_EQ(expected[i], arr->GetIntegerAt(i)); } @@ -67,12 +100,12 @@ TEST(cpdf_array, InsertAt) { // When the position to insert is beyond the upper bound, // an element is inserted at that position while other unfilled // positions have nullptr. - int elems[] = {1, 2}; + const int elems[] = {1, 2}; auto arr = pdfium::MakeUnique<CPDF_Array>(); for (size_t i = 0; i < FX_ArraySize(elems); ++i) arr->InsertNewAt<CPDF_Number>(i, elems[i]); arr->InsertNewAt<CPDF_Number>(10, 10); - EXPECT_EQ(11u, arr->GetCount()); + ASSERT_EQ(11u, arr->GetCount()); for (size_t i = 0; i < FX_ArraySize(elems); ++i) EXPECT_EQ(elems[i], arr->GetIntegerAt(i)); for (size_t i = FX_ArraySize(elems); i < 10; ++i) @@ -84,12 +117,12 @@ TEST(cpdf_array, InsertAt) { TEST(cpdf_array, Clone) { { // Basic case. - int elems[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + const int elems[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; auto arr = pdfium::MakeUnique<CPDF_Array>(); for (size_t i = 0; i < FX_ArraySize(elems); ++i) arr->InsertNewAt<CPDF_Number>(i, elems[i]); std::unique_ptr<CPDF_Array> arr2 = ToArray(arr->Clone()); - EXPECT_EQ(arr->GetCount(), arr2->GetCount()); + ASSERT_EQ(arr->GetCount(), arr2->GetCount()); for (size_t i = 0; i < FX_ArraySize(elems); ++i) { // Clone() always create new objects. EXPECT_NE(arr->GetObjectAt(i), arr2->GetObjectAt(i)); @@ -100,7 +133,7 @@ TEST(cpdf_array, Clone) { // Clone() with and without dereferencing reference objects. static const size_t kNumOfRows = 3; static const size_t kNumOfRowElems = 5; - int elems[kNumOfRows][kNumOfRowElems] = { + const int elems[kNumOfRows][kNumOfRowElems] = { {1, 2, 3, 4, 5}, {10, 9, 8, 7, 6}, {11, 12, 13, 14, 15}}; auto arr = pdfium::MakeUnique<CPDF_Array>(); // Indirect references to indirect objects. @@ -121,10 +154,10 @@ TEST(cpdf_array, Clone) { // Not dereferencing reference objects means just creating new references // instead of new copies of direct objects. std::unique_ptr<CPDF_Array> arr1 = ToArray(arr->Clone()); - EXPECT_EQ(arr->GetCount(), arr1->GetCount()); + ASSERT_EQ(arr->GetCount(), arr1->GetCount()); // Dereferencing reference objects creates new copies of direct objects. std::unique_ptr<CPDF_Array> arr2 = ToArray(arr->CloneDirectObject()); - EXPECT_EQ(arr->GetCount(), arr2->GetCount()); + ASSERT_EQ(arr->GetCount(), arr2->GetCount()); for (size_t i = 0; i < kNumOfRows; ++i) { CPDF_Array* arr_elem = arr->GetObjectAt(i)->AsArray(); CPDF_Array* arr1_elem = arr1->GetObjectAt(i)->AsArray(); @@ -173,4 +206,5 @@ TEST(cpdf_array, Iterator) { size_t index = 0; for (const auto& it : *arr) EXPECT_EQ(elems[index++], it->AsNumber()->GetInteger()); + EXPECT_EQ(FX_ArraySize(elems), index); } diff --git a/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_data_avail.cpp b/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_data_avail.cpp index b4da8934298..6f12260eae1 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_data_avail.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_data_avail.cpp @@ -94,11 +94,12 @@ uint32_t CPDF_DataAvail::GetObjectSize(uint32_t objnum, FX_FILESIZE& offset) { if (!pParser || !pParser->IsValidObjectNumber(objnum)) return 0; - if (pParser->GetObjectType(objnum) == 2) + if (pParser->GetObjectType(objnum) == CPDF_Parser::ObjectType::kCompressed) objnum = pParser->GetObjectPositionOrZero(objnum); - if (pParser->GetObjectType(objnum) != 1 && - pParser->GetObjectType(objnum) != 255) { + if (pParser->GetObjectType(objnum) != + CPDF_Parser::ObjectType::kNotCompressed && + pParser->GetObjectType(objnum) != CPDF_Parser::ObjectType::kNull) { return 0; } diff --git a/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_data_avail.h b/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_data_avail.h index 8edf062590c..f47c859697a 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_data_avail.h +++ b/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_data_avail.h @@ -13,6 +13,7 @@ #include "core/fpdfapi/parser/cpdf_parser.h" #include "core/fpdfapi/parser/cpdf_syntax_parser.h" +#include "core/fxcrt/cfx_unowned_ptr.h" #include "core/fxcrt/fx_basic.h" class CPDF_Dictionary; @@ -204,7 +205,7 @@ class CPDF_DataAvail final { uint32_t m_dwRootObjNum; uint32_t m_dwInfoObjNum; std::unique_ptr<CPDF_LinearizedHeader> m_pLinearized; - CPDF_Object* m_pTrailer; + CFX_UnownedPtr<CPDF_Object> m_pTrailer; bool m_bDocAvail; FX_FILESIZE m_dwHeaderOffset; FX_FILESIZE m_dwLastXRefOffset; diff --git a/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_document.cpp b/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_document.cpp index 1fdd59e6155..9bfb16b97e5 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_document.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_document.cpp @@ -374,6 +374,10 @@ void CPDF_Document::LoadDocInternal() { if (!m_pRootDict) return; + LoadDocumentInfo(); +} + +void CPDF_Document::LoadDocumentInfo() { CPDF_Object* pInfoObj = GetOrParseIndirectObject(m_pParser->GetInfoObjNum()); if (pInfoObj) m_pInfoDict = pInfoObj->GetDict(); diff --git a/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_document.h b/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_document.h index 493c1edb32c..e6107e1040d 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_document.h +++ b/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_document.h @@ -87,6 +87,7 @@ class CPDF_Document : public CPDF_IndirectObjectHolder { void LoadDoc(); void LoadLinearizedDoc(const CPDF_LinearizedHeader* pLinearizationParams); void LoadPages(); + void LoadDocumentInfo(); void CreateNewDoc(); CPDF_Dictionary* CreateNewPage(int iPage); diff --git a/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_object_unittest.cpp b/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_object_unittest.cpp index 1923992d7a4..24a989665f6 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_object_unittest.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_object_unittest.cpp @@ -82,7 +82,7 @@ class PDFObjectsTest : public testing::Test { // All direct objects. CPDF_Object* objs[] = {boolean_false_obj, boolean_true_obj, number_int_obj, number_float_obj, str_reg_obj, str_spec_obj, - name_obj, m_ArrayObj, m_DictObj, + name_obj, m_ArrayObj.Get(), m_DictObj.Get(), stream_obj, null_obj}; m_DirectObjTypes = { CPDF_Object::BOOLEAN, CPDF_Object::BOOLEAN, CPDF_Object::NUMBER, @@ -179,9 +179,9 @@ class PDFObjectsTest : public testing::Test { std::vector<std::unique_ptr<CPDF_Object>> m_DirectObjs; std::vector<int> m_DirectObjTypes; std::vector<std::unique_ptr<CPDF_Object>> m_RefObjs; - CPDF_Dictionary* m_DictObj; - CPDF_Dictionary* m_StreamDictObj; - CPDF_Array* m_ArrayObj; + CFX_UnownedPtr<CPDF_Dictionary> m_DictObj; + CFX_UnownedPtr<CPDF_Dictionary> m_StreamDictObj; + CFX_UnownedPtr<CPDF_Array> m_ArrayObj; std::vector<CPDF_Object*> m_IndirectObjs; }; @@ -244,23 +244,29 @@ TEST_F(PDFObjectsTest, GetInteger) { TEST_F(PDFObjectsTest, GetDict) { const CPDF_Dictionary* const direct_obj_results[] = { - nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, - nullptr, nullptr, m_DictObj, m_StreamDictObj, nullptr}; + nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, m_DictObj.Get(), m_StreamDictObj.Get(), + nullptr}; // Check for direct objects. for (size_t i = 0; i < m_DirectObjs.size(); ++i) EXPECT_EQ(direct_obj_results[i], m_DirectObjs[i]->GetDict()); // Check indirect references. - const CPDF_Dictionary* const indirect_obj_results[] = { - nullptr, nullptr, nullptr, nullptr, nullptr, m_DictObj, m_StreamDictObj}; + const CPDF_Dictionary* const indirect_obj_results[] = {nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + m_DictObj.Get(), + m_StreamDictObj.Get()}; for (size_t i = 0; i < m_RefObjs.size(); ++i) EXPECT_TRUE(Equal(indirect_obj_results[i], m_RefObjs[i]->GetDict())); } TEST_F(PDFObjectsTest, GetArray) { const CPDF_Array* const direct_obj_results[] = { - nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, - nullptr, m_ArrayObj, nullptr, nullptr, nullptr}; + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, m_ArrayObj.Get(), nullptr, nullptr, nullptr}; // Check for direct objects. for (size_t i = 0; i < m_DirectObjs.size(); ++i) EXPECT_EQ(direct_obj_results[i], m_DirectObjs[i]->AsArray()); diff --git a/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_parser.cpp b/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_parser.cpp index bf8bc7b542e..0f4da6e28f8 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_parser.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_parser.cpp @@ -49,21 +49,34 @@ int32_t GetStreamFirst(const CFX_RetainPtr<CPDF_StreamAcc>& pObjStream) { return pObjStream->GetDict()->GetIntegerFor("First"); } +CPDF_Parser::ObjectType GetObjectTypeFromCrossRefStreamType( + int cross_ref_stream_type) { + switch (cross_ref_stream_type) { + case 0: + return CPDF_Parser::ObjectType::kFree; + case 1: + return CPDF_Parser::ObjectType::kNotCompressed; + case 2: + return CPDF_Parser::ObjectType::kCompressed; + default: + return CPDF_Parser::ObjectType::kNull; + } +} + } // namespace CPDF_Parser::CPDF_Parser() - : m_bHasParsed(false), + : m_pSyntax(pdfium::MakeUnique<CPDF_SyntaxParser>()), + m_bHasParsed(false), m_bXRefStream(false), m_bVersionUpdated(false), m_FileVersion(0), m_pEncryptDict(nullptr), - m_dwXrefStartObjNum(0) { - m_pSyntax = pdfium::MakeUnique<CPDF_SyntaxParser>(); -} + m_TrailerPos(CPDF_Parser::kInvalidPos), + m_dwXrefStartObjNum(0) {} CPDF_Parser::~CPDF_Parser() { ReleaseEncryptHandler(); - SetEncryptDictionary(nullptr); } uint32_t CPDF_Parser::GetLastObjNum() const { @@ -79,10 +92,10 @@ FX_FILESIZE CPDF_Parser::GetObjectPositionOrZero(uint32_t objnum) const { return it != m_ObjectInfo.end() ? it->second.pos : 0; } -uint8_t CPDF_Parser::GetObjectType(uint32_t objnum) const { +CPDF_Parser::ObjectType CPDF_Parser::GetObjectType(uint32_t objnum) const { ASSERT(IsValidObjectNumber(objnum)); auto it = m_ObjectInfo.find(objnum); - return it != m_ObjectInfo.end() ? it->second.type : 0; + return it != m_ObjectInfo.end() ? it->second.type : ObjectType::kFree; } uint16_t CPDF_Parser::GetObjectGenNum(uint32_t objnum) const { @@ -92,8 +105,16 @@ uint16_t CPDF_Parser::GetObjectGenNum(uint32_t objnum) const { } bool CPDF_Parser::IsObjectFreeOrNull(uint32_t objnum) const { - uint8_t type = GetObjectType(objnum); - return type == 0 || type == 255; + switch (GetObjectType(objnum)) { + case ObjectType::kFree: + case ObjectType::kNull: + return true; + case ObjectType::kNotCompressed: + case ObjectType::kCompressed: + return false; + } + ASSERT(false); // NOTREACHED(); + return false; } void CPDF_Parser::SetEncryptDictionary(CPDF_Dictionary* pDict) { @@ -220,14 +241,13 @@ CPDF_Parser::Error CPDF_Parser::StartParse( } return SUCCESS; } + CPDF_Parser::Error CPDF_Parser::SetEncryptHandler() { ReleaseEncryptHandler(); - SetEncryptDictionary(nullptr); - - if (!m_pTrailer) + if (!GetTrailer()) return FORMAT_ERROR; - CPDF_Object* pEncryptObj = m_pTrailer->GetObjectFor("Encrypt"); + CPDF_Object* pEncryptObj = GetTrailer()->GetObjectFor("Encrypt"); if (pEncryptObj) { if (CPDF_Dictionary* pEncryptDict = pEncryptObj->AsDictionary()) { SetEncryptDictionary(pEncryptDict); @@ -260,16 +280,17 @@ CPDF_Parser::Error CPDF_Parser::SetEncryptHandler() { void CPDF_Parser::ReleaseEncryptHandler() { m_pSyntax->m_pCryptoHandler.Reset(); m_pSecurityHandler.reset(); + SetEncryptDictionary(nullptr); } FX_FILESIZE CPDF_Parser::GetObjectOffset(uint32_t objnum) const { if (!IsValidObjectNumber(objnum)) return 0; - if (GetObjectType(objnum) == 1) + if (GetObjectType(objnum) == ObjectType::kNotCompressed) return GetObjectPositionOrZero(objnum); - if (GetObjectType(objnum) == 2) { + if (GetObjectType(objnum) == ObjectType::kCompressed) { FX_FILESIZE pos = GetObjectPositionOrZero(objnum); return GetObjectPositionOrZero(pos); } @@ -306,11 +327,13 @@ bool CPDF_Parser::LoadAllCrossRefV4(FX_FILESIZE xrefpos) { if (!LoadCrossRefV4(xrefpos, 0, true)) return false; - m_pTrailer = LoadTrailerV4(); - if (!m_pTrailer) + std::unique_ptr<CPDF_Dictionary> trailer = LoadTrailerV4(); + if (!trailer) return false; - int32_t xrefsize = GetDirectInteger(m_pTrailer.get(), "Size"); + m_Trailers.push_back(std::move(trailer)); + m_TrailerPos = m_Trailers.size() - 1; + int32_t xrefsize = GetDirectInteger(GetTrailer(), "Size"); if (xrefsize > 0 && xrefsize <= kMaxXRefSize) ShrinkObjectMap(xrefsize); @@ -319,12 +342,12 @@ bool CPDF_Parser::LoadAllCrossRefV4(FX_FILESIZE xrefpos) { std::set<FX_FILESIZE> seen_xrefpos; CrossRefList.push_back(xrefpos); - XRefStreamList.push_back(GetDirectInteger(m_pTrailer.get(), "XRefStm")); + XRefStreamList.push_back(GetDirectInteger(GetTrailer(), "XRefStm")); seen_xrefpos.insert(xrefpos); - // When |m_pTrailer| doesn't have Prev entry or Prev entry value is not + // When the trailer doesn't have Prev entry or Prev entry value is not // numerical, GetDirectInteger() returns 0. Loading will end. - xrefpos = GetDirectInteger(m_pTrailer.get(), "Prev"); + xrefpos = GetDirectInteger(GetTrailer(), "Prev"); while (xrefpos) { // Check for circular references. if (pdfium::ContainsKey(seen_xrefpos, xrefpos)) @@ -362,11 +385,13 @@ bool CPDF_Parser::LoadLinearizedAllCrossRefV4(FX_FILESIZE xrefpos, if (!LoadLinearizedCrossRefV4(xrefpos, dwObjCount)) return false; - m_pTrailer = LoadTrailerV4(); - if (!m_pTrailer) + std::unique_ptr<CPDF_Dictionary> trailer = LoadTrailerV4(); + if (!trailer) return false; - int32_t xrefsize = GetDirectInteger(m_pTrailer.get(), "Size"); + m_Trailers.push_back(std::move(trailer)); + m_TrailerPos = m_Trailers.size() - 1; + int32_t xrefsize = GetDirectInteger(GetTrailer(), "Size"); if (xrefsize == 0) return false; @@ -375,10 +400,10 @@ bool CPDF_Parser::LoadLinearizedAllCrossRefV4(FX_FILESIZE xrefpos, std::set<FX_FILESIZE> seen_xrefpos; CrossRefList.push_back(xrefpos); - XRefStreamList.push_back(GetDirectInteger(m_pTrailer.get(), "XRefStm")); + XRefStreamList.push_back(GetDirectInteger(GetTrailer(), "XRefStm")); seen_xrefpos.insert(xrefpos); - xrefpos = GetDirectInteger(m_pTrailer.get(), "Prev"); + xrefpos = GetDirectInteger(GetTrailer(), "Prev"); while (xrefpos) { // Check for circular references. if (pdfium::ContainsKey(seen_xrefpos, xrefpos)) @@ -441,7 +466,7 @@ bool CPDF_Parser::LoadLinearizedCrossRefV4(FX_FILESIZE pos, char* pEntry = &buf[i * recordsize]; if (pEntry[17] == 'f') { m_ObjectInfo[objnum].pos = 0; - m_ObjectInfo[objnum].type = 0; + m_ObjectInfo[objnum].type = ObjectType::kFree; } else { int32_t offset = FXSYS_atoi(pEntry); if (offset == 0) { @@ -460,7 +485,7 @@ bool CPDF_Parser::LoadLinearizedCrossRefV4(FX_FILESIZE pos, if (m_ObjectInfo[objnum].pos < m_pSyntax->m_FileLen) m_SortedOffset.insert(m_ObjectInfo[objnum].pos); - m_ObjectInfo[objnum].type = 1; + m_ObjectInfo[objnum].type = ObjectType::kNotCompressed; } } } @@ -516,7 +541,7 @@ bool CPDF_Parser::LoadCrossRefV4(FX_FILESIZE pos, char* pEntry = &buf[i * recordsize]; if (pEntry[17] == 'f') { m_ObjectInfo[objnum].pos = 0; - m_ObjectInfo[objnum].type = 0; + m_ObjectInfo[objnum].type = ObjectType::kFree; } else { FX_FILESIZE offset = (FX_FILESIZE)FXSYS_atoi64(pEntry); if (offset == 0) { @@ -535,7 +560,7 @@ bool CPDF_Parser::LoadCrossRefV4(FX_FILESIZE pos, if (m_ObjectInfo[objnum].pos < m_pSyntax->m_FileLen) m_SortedOffset.insert(m_ObjectInfo[objnum].pos); - m_ObjectInfo[objnum].type = 1; + m_ObjectInfo[objnum].type = ObjectType::kNotCompressed; } } } @@ -567,7 +592,8 @@ bool CPDF_Parser::LoadAllCrossRefV5(FX_FILESIZE xrefpos) { bool CPDF_Parser::RebuildCrossRef() { m_ObjectInfo.clear(); m_SortedOffset.clear(); - m_pTrailer.reset(); + m_Trailers.clear(); + m_TrailerPos = CPDF_Parser::kInvalidPos; ParserState state = ParserState::kDefault; int32_t inside_index = 0; @@ -728,7 +754,8 @@ bool CPDF_Parser::RebuildCrossRef() { CPDF_Object* pRoot = pDict->GetObjectFor("Root"); if (pRoot && pRoot->GetDict() && pRoot->GetDict()->GetObjectFor("Pages")) { - m_pTrailer = ToDictionary(pDict->Clone()); + m_Trailers.push_back(ToDictionary(pDict->Clone())); + m_TrailerPos = m_Trailers.size() - 1; } } } @@ -761,7 +788,7 @@ bool CPDF_Parser::RebuildCrossRef() { } } else { m_ObjectInfo[objnum].pos = obj_pos; - m_ObjectInfo[objnum].type = 1; + m_ObjectInfo[objnum].type = ObjectType::kNotCompressed; m_ObjectInfo[objnum].gennum = gennum; } } @@ -784,7 +811,7 @@ bool CPDF_Parser::RebuildCrossRef() { CPDF_Stream* pStream = pObj->AsStream(); if (CPDF_Dictionary* pTrailer = pStream ? pStream->GetDict() : pObj->AsDictionary()) { - if (m_pTrailer) { + if (GetTrailer()) { CPDF_Object* pRoot = pTrailer->GetObjectFor("Root"); CPDF_Reference* pRef = ToReference(pRoot); if (!pRoot || @@ -798,19 +825,19 @@ bool CPDF_Parser::RebuildCrossRef() { uint32_t dwObjNum = pElement ? pElement->GetObjNum() : 0; if (dwObjNum) { - m_pTrailer->SetNewFor<CPDF_Reference>( + GetTrailer()->SetNewFor<CPDF_Reference>( key, m_pDocument.Get(), dwObjNum); } else { - m_pTrailer->SetFor(key, pElement->Clone()); + GetTrailer()->SetFor(key, pElement->Clone()); } } } } else { - if (pObj->IsStream()) { - m_pTrailer = ToDictionary(pTrailer->Clone()); - } else { - m_pTrailer = ToDictionary(std::move(pObj)); - } + if (pObj->IsStream()) + m_Trailers.push_back(ToDictionary(pTrailer->Clone())); + else + m_Trailers.push_back(ToDictionary(std::move(pObj))); + m_TrailerPos = m_Trailers.size() - 1; FX_FILESIZE dwSavePos = m_pSyntax->GetPos(); CFX_ByteString strWord = m_pSyntax->GetKeyword(); @@ -914,7 +941,7 @@ bool CPDF_Parser::RebuildCrossRef() { last_trailer = m_pSyntax->m_FileLen; m_SortedOffset.insert(last_trailer - m_pSyntax->m_HeaderOffset); - return m_pTrailer && !m_ObjectInfo.empty(); + return GetTrailer() && !m_ObjectInfo.empty(); } bool CPDF_Parser::LoadCrossRefV5(FX_FILESIZE* pos, bool bMainXRef) { @@ -950,10 +977,11 @@ bool CPDF_Parser::LoadCrossRefV5(FX_FILESIZE* pos, bool bMainXRef) { std::unique_ptr<CPDF_Dictionary> pNewTrailer = ToDictionary(pDict->Clone()); if (bMainXRef) { - m_pTrailer = std::move(pNewTrailer); + m_Trailers.push_back(std::move(pNewTrailer)); + m_TrailerPos = m_Trailers.size() - 1; ShrinkObjectMap(size); for (auto& it : m_ObjectInfo) - it.second.type = 0; + it.second.type = ObjectType::kFree; } else { m_Trailers.push_back(std::move(pNewTrailer)); } @@ -1021,12 +1049,15 @@ bool CPDF_Parser::LoadCrossRefV5(FX_FILESIZE* pos, bool bMainXRef) { continue; for (uint32_t j = 0; j < count; j++) { - int32_t type = 1; + ObjectType type = ObjectType::kNotCompressed; const uint8_t* entrystart = segstart + j * totalWidth; - if (WidthArray[0]) - type = GetVarInt(entrystart, WidthArray[0]); + if (WidthArray[0]) { + const int cross_ref_stream_obj_type = + GetVarInt(entrystart, WidthArray[0]); + type = GetObjectTypeFromCrossRefStreamType(cross_ref_stream_obj_type); + } - if (GetObjectType(startnum + j) == 255) { + if (GetObjectType(startnum + j) == ObjectType::kNull) { FX_FILESIZE offset = GetVarInt(entrystart + WidthArray[0], WidthArray[1]); m_ObjectInfo[startnum + j].pos = offset; @@ -1034,22 +1065,22 @@ bool CPDF_Parser::LoadCrossRefV5(FX_FILESIZE* pos, bool bMainXRef) { continue; } - if (GetObjectType(startnum + j)) + if (GetObjectType(startnum + j) != ObjectType::kFree) continue; m_ObjectInfo[startnum + j].type = type; - if (type == 0) { + if (type == ObjectType::kFree) { m_ObjectInfo[startnum + j].pos = 0; } else { FX_FILESIZE offset = GetVarInt(entrystart + WidthArray[0], WidthArray[1]); m_ObjectInfo[startnum + j].pos = offset; - if (type == 1) { + if (type == ObjectType::kNotCompressed) { m_SortedOffset.insert(offset); } else { if (offset < 0 || !IsValidObjectNumber(offset)) return false; - m_ObjectInfo[offset].type = 255; + m_ObjectInfo[offset].type = ObjectType::kNull; } } } @@ -1059,10 +1090,10 @@ bool CPDF_Parser::LoadCrossRefV5(FX_FILESIZE* pos, bool bMainXRef) { } CPDF_Array* CPDF_Parser::GetIDArray() { - if (!m_pTrailer) + if (!GetTrailer()) return nullptr; - CPDF_Object* pID = m_pTrailer->GetObjectFor("ID"); + CPDF_Object* pID = GetTrailer()->GetObjectFor("ID"); if (!pID) return nullptr; @@ -1073,20 +1104,31 @@ CPDF_Array* CPDF_Parser::GetIDArray() { std::unique_ptr<CPDF_Object> pNewObj = ParseIndirectObject(nullptr, pRef->GetRefObjNum()); pID = pNewObj.get(); - m_pTrailer->SetFor("ID", std::move(pNewObj)); + GetTrailer()->SetFor("ID", std::move(pNewObj)); return ToArray(pID); } uint32_t CPDF_Parser::GetRootObjNum() { CPDF_Reference* pRef = - ToReference(m_pTrailer ? m_pTrailer->GetObjectFor("Root") : nullptr); + ToReference(GetTrailer() ? GetTrailer()->GetObjectFor("Root") : nullptr); return pRef ? pRef->GetRefObjNum() : 0; } uint32_t CPDF_Parser::GetInfoObjNum() { CPDF_Reference* pRef = - ToReference(m_pTrailer ? m_pTrailer->GetObjectFor("Info") : nullptr); - return pRef ? pRef->GetRefObjNum() : 0; + ToReference(GetTrailer() ? GetTrailer()->GetObjectFor("Info") : nullptr); + if (pRef) + return pRef->GetRefObjNum(); + + // Search trailers array from latest to earliest revision, as we want the + // most recent Info object number. + // See PDF 1.7 spec, section 3.4.5 - Incremental Updates. + for (auto it = m_Trailers.rbegin(); it != m_Trailers.rend(); ++it) { + pRef = ToReference(it->get()->GetObjectFor("Info")); + if (pRef) + return pRef->GetRefObjNum(); + } + return 0; } std::unique_ptr<CPDF_Object> CPDF_Parser::ParseIndirectObject( @@ -1100,13 +1142,14 @@ std::unique_ptr<CPDF_Object> CPDF_Parser::ParseIndirectObject( return nullptr; pdfium::ScopedSetInsertion<uint32_t> local_insert(&m_ParsingObjNums, objnum); - if (GetObjectType(objnum) == 1 || GetObjectType(objnum) == 255) { + if (GetObjectType(objnum) == ObjectType::kNotCompressed || + GetObjectType(objnum) == ObjectType::kNull) { FX_FILESIZE pos = m_ObjectInfo[objnum].pos; if (pos <= 0) return nullptr; return ParseIndirectObjectAt(pObjList, pos, objnum); } - if (GetObjectType(objnum) != 2) + if (GetObjectType(objnum) != ObjectType::kCompressed) return nullptr; CFX_RetainPtr<CPDF_StreamAcc> pObjStream = @@ -1161,10 +1204,11 @@ FX_FILESIZE CPDF_Parser::GetObjectSize(uint32_t objnum) const { if (!IsValidObjectNumber(objnum)) return 0; - if (GetObjectType(objnum) == 2) + if (GetObjectType(objnum) == ObjectType::kCompressed) objnum = GetObjectPositionOrZero(objnum); - if (GetObjectType(objnum) != 1 && GetObjectType(objnum) != 255) + if (GetObjectType(objnum) != ObjectType::kNotCompressed && + GetObjectType(objnum) != ObjectType::kNull) return 0; FX_FILESIZE offset = GetObjectPositionOrZero(objnum); @@ -1186,7 +1230,7 @@ void CPDF_Parser::GetIndirectBinary(uint32_t objnum, if (!IsValidObjectNumber(objnum)) return; - if (GetObjectType(objnum) == 2) { + if (GetObjectType(objnum) == ObjectType::kCompressed) { CFX_RetainPtr<CPDF_StreamAcc> pObjStream = GetObjectStream(m_ObjectInfo[objnum].pos); if (!pObjStream) @@ -1221,7 +1265,7 @@ void CPDF_Parser::GetIndirectBinary(uint32_t objnum, return; } - if (GetObjectType(objnum) != 1) + if (GetObjectType(objnum) != ObjectType::kNotCompressed) return; FX_FILESIZE pos = m_ObjectInfo[objnum].pos; @@ -1476,11 +1520,13 @@ CPDF_Parser::Error CPDF_Parser::StartLinearizedParse( } if (bLoadV4) { - m_pTrailer = LoadTrailerV4(); - if (!m_pTrailer) + std::unique_ptr<CPDF_Dictionary> trailer = LoadTrailerV4(); + if (!trailer) return SUCCESS; - int32_t xrefsize = GetDirectInteger(m_pTrailer.get(), "Size"); + m_Trailers.push_back(std::move(trailer)); + m_TrailerPos = m_Trailers.size() - 1; + int32_t xrefsize = GetDirectInteger(GetTrailer(), "Size"); if (xrefsize > 0) ShrinkObjectMap(xrefsize); } @@ -1547,7 +1593,6 @@ bool CPDF_Parser::LoadLinearizedAllCrossRefV5(FX_FILESIZE xrefpos) { CPDF_Parser::Error CPDF_Parser::LoadLinearizedMainXRefTable() { uint32_t dwSaveMetadataObjnum = m_pSyntax->m_MetadataObjnum; m_pSyntax->m_MetadataObjnum = 0; - m_pTrailer.reset(); m_pSyntax->SetPos(m_LastXRefOffset - m_pSyntax->m_HeaderOffset); uint8_t ch = 0; diff --git a/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_parser.h b/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_parser.h index 8f55ddb3256..3acdbbfa6f1 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_parser.h +++ b/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_parser.h @@ -7,6 +7,7 @@ #ifndef CORE_FPDFAPI_PARSER_CPDF_PARSER_H_ #define CORE_FPDFAPI_PARSER_CPDF_PARSER_H_ +#include <limits> #include <map> #include <memory> #include <set> @@ -37,10 +38,19 @@ class CPDF_Parser { HANDLER_ERROR }; + enum class ObjectType : uint8_t { + kFree = 0x00, + kNotCompressed = 0x01, + kCompressed = 0x02, + kNull = 0xFF, + }; + // A limit on the maximum object number in the xref table. Theoretical limits // are higher, but this may be large enough in practice. static const uint32_t kMaxObjectNumber = 1048576; + static const size_t kInvalidPos = std::numeric_limits<size_t>::max(); + CPDF_Parser(); ~CPDF_Parser(); @@ -51,7 +61,10 @@ class CPDF_Parser { void SetPassword(const char* password) { m_Password = password; } CFX_ByteString GetPassword() { return m_Password; } - CPDF_Dictionary* GetTrailer() const { return m_pTrailer.get(); } + CPDF_Dictionary* GetTrailer() const { + return m_TrailerPos == kInvalidPos ? nullptr + : m_Trailers[m_TrailerPos].get(); + } FX_FILESIZE GetLastXRefOffset() const { return m_LastXRefOffset; } uint32_t GetPermissions() const; @@ -68,7 +81,7 @@ class CPDF_Parser { uint32_t GetLastObjNum() const; bool IsValidObjectNumber(uint32_t objnum) const; FX_FILESIZE GetObjectPositionOrZero(uint32_t objnum) const; - uint8_t GetObjectType(uint32_t objnum) const; + ObjectType GetObjectType(uint32_t objnum) const; uint16_t GetObjectGenNum(uint32_t objnum) const; bool IsVersionUpdated() const { return m_bVersionUpdated; } bool IsObjectFreeOrNull(uint32_t objnum) const; @@ -97,10 +110,10 @@ class CPDF_Parser { protected: struct ObjectInfo { - ObjectInfo() : pos(0), type(0), gennum(0) {} + ObjectInfo() : pos(0), type(ObjectType::kFree), gennum(0) {} FX_FILESIZE pos; - uint8_t type; + ObjectType type; uint16_t gennum; }; @@ -161,8 +174,8 @@ class CPDF_Parser { std::unique_ptr<CPDF_SecurityHandler> m_pSecurityHandler; CFX_ByteString m_Password; std::set<FX_FILESIZE> m_SortedOffset; - std::unique_ptr<CPDF_Dictionary> m_pTrailer; std::vector<std::unique_ptr<CPDF_Dictionary>> m_Trailers; + size_t m_TrailerPos; std::unique_ptr<CPDF_LinearizedHeader> m_pLinearized; uint32_t m_dwXrefStartObjNum; diff --git a/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_parser_unittest.cpp b/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_parser_unittest.cpp index f988f8248b3..25c22c701b2 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_parser_unittest.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_parser_unittest.cpp @@ -118,7 +118,13 @@ TEST(cpdf_parser, LoadCrossRefV4) { ASSERT_TRUE(parser.LoadCrossRefV4(0, 0, false)); const FX_FILESIZE offsets[] = {0, 17, 81, 0, 331, 409}; - const uint8_t types[] = {0, 1, 1, 0, 1, 1}; + const CPDF_Parser::ObjectType types[] = { + CPDF_Parser::ObjectType::kFree, + CPDF_Parser::ObjectType::kNotCompressed, + CPDF_Parser::ObjectType::kNotCompressed, + CPDF_Parser::ObjectType::kFree, + CPDF_Parser::ObjectType::kNotCompressed, + CPDF_Parser::ObjectType::kNotCompressed}; for (size_t i = 0; i < FX_ArraySize(offsets); ++i) { EXPECT_EQ(offsets[i], parser.m_ObjectInfo[i].pos); EXPECT_EQ(types[i], parser.m_ObjectInfo[i].type); @@ -144,7 +150,20 @@ TEST(cpdf_parser, LoadCrossRefV4) { ASSERT_TRUE(parser.LoadCrossRefV4(0, 0, false)); const FX_FILESIZE offsets[] = {0, 0, 0, 25325, 0, 0, 0, 0, 25518, 25635, 0, 0, 25777}; - const uint8_t types[] = {0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1}; + const CPDF_Parser::ObjectType types[] = { + CPDF_Parser::ObjectType::kFree, + CPDF_Parser::ObjectType::kFree, + CPDF_Parser::ObjectType::kFree, + CPDF_Parser::ObjectType::kNotCompressed, + CPDF_Parser::ObjectType::kFree, + CPDF_Parser::ObjectType::kFree, + CPDF_Parser::ObjectType::kFree, + CPDF_Parser::ObjectType::kFree, + CPDF_Parser::ObjectType::kNotCompressed, + CPDF_Parser::ObjectType::kNotCompressed, + CPDF_Parser::ObjectType::kFree, + CPDF_Parser::ObjectType::kFree, + CPDF_Parser::ObjectType::kNotCompressed}; for (size_t i = 0; i < FX_ArraySize(offsets); ++i) { EXPECT_EQ(offsets[i], parser.m_ObjectInfo[i].pos); EXPECT_EQ(types[i], parser.m_ObjectInfo[i].type); @@ -170,7 +189,20 @@ TEST(cpdf_parser, LoadCrossRefV4) { ASSERT_TRUE(parser.LoadCrossRefV4(0, 0, false)); const FX_FILESIZE offsets[] = {0, 0, 0, 25325, 0, 0, 0, 0, 0, 25635, 0, 0, 25777}; - const uint8_t types[] = {0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1}; + const CPDF_Parser::ObjectType types[] = { + CPDF_Parser::ObjectType::kFree, + CPDF_Parser::ObjectType::kFree, + CPDF_Parser::ObjectType::kFree, + CPDF_Parser::ObjectType::kNotCompressed, + CPDF_Parser::ObjectType::kFree, + CPDF_Parser::ObjectType::kFree, + CPDF_Parser::ObjectType::kFree, + CPDF_Parser::ObjectType::kFree, + CPDF_Parser::ObjectType::kFree, + CPDF_Parser::ObjectType::kNotCompressed, + CPDF_Parser::ObjectType::kFree, + CPDF_Parser::ObjectType::kFree, + CPDF_Parser::ObjectType::kNotCompressed}; for (size_t i = 0; i < FX_ArraySize(offsets); ++i) { EXPECT_EQ(offsets[i], parser.m_ObjectInfo[i].pos); EXPECT_EQ(types[i], parser.m_ObjectInfo[i].type); @@ -194,7 +226,14 @@ TEST(cpdf_parser, LoadCrossRefV4) { ASSERT_TRUE(parser.LoadCrossRefV4(0, 0, false)); const FX_FILESIZE offsets[] = {0, 23, 0, 0, 0, 45, 179}; - const uint8_t types[] = {0, 1, 0, 0, 0, 1, 1}; + const CPDF_Parser::ObjectType types[] = { + CPDF_Parser::ObjectType::kFree, + CPDF_Parser::ObjectType::kNotCompressed, + CPDF_Parser::ObjectType::kFree, + CPDF_Parser::ObjectType::kFree, + CPDF_Parser::ObjectType::kFree, + CPDF_Parser::ObjectType::kNotCompressed, + CPDF_Parser::ObjectType::kNotCompressed}; for (size_t i = 0; i < FX_ArraySize(offsets); ++i) { EXPECT_EQ(offsets[i], parser.m_ObjectInfo[i].pos); EXPECT_EQ(types[i], parser.m_ObjectInfo[i].type); diff --git a/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_security_handler_embeddertest.cpp b/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_security_handler_embeddertest.cpp index c6c6217e2c7..5df3348834c 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_security_handler_embeddertest.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_security_handler_embeddertest.cpp @@ -2,6 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include <string> + +#include "core/fxcrt/fx_system.h" +#include "public/fpdf_edit.h" +#include "public/fpdf_save.h" +#include "public/fpdfview.h" #include "testing/embedder_test.h" #include "testing/gtest/include/gtest/gtest.h" @@ -35,6 +41,48 @@ TEST_F(CPDFSecurityHandlerEmbeddertest, OwnerPassword) { EXPECT_EQ(0xFFFFFFFC, FPDF_GetDocPermissions(document())); } +TEST_F(CPDFSecurityHandlerEmbeddertest, PasswordAfterGenerateSave) { +#if _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ + const char md5[] = "e4a3701ca5b2a759e06455aa8d97d46e"; +#elif _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ + const char md5[] = "6951b6c9891dfe0332a5b1983e484400"; +#else + const char md5[] = "50985f3440d3f66c3b599ab138214015"; +#endif // _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ + { + ASSERT_TRUE(OpenDocument("encrypted.pdf", "5678", true)); + FPDF_PAGE page = LoadPage(0); + ASSERT_TRUE(page); + FPDF_PAGEOBJECT red_rect = FPDFPageObj_CreateNewRect(10, 10, 20, 20); + ASSERT_TRUE(red_rect); + EXPECT_TRUE(FPDFPath_SetFillColor(red_rect, 255, 0, 0, 255)); + EXPECT_TRUE(FPDFPath_SetDrawMode(red_rect, FPDF_FILLMODE_ALTERNATE, 0)); + FPDFPage_InsertObject(page, red_rect); + FPDF_BITMAP page_bitmap = RenderPage(page); + CompareBitmap(page_bitmap, 612, 792, md5); + FPDFBitmap_Destroy(page_bitmap); + EXPECT_TRUE(FPDFPage_GenerateContent(page)); + EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); + UnloadPage(page); + } + std::string new_file = GetString(); + FPDF_FILEACCESS file_access; + memset(&file_access, 0, sizeof(file_access)); + file_access.m_FileLen = new_file.size(); + file_access.m_GetBlock = GetBlockFromString; + file_access.m_Param = &new_file; + EXPECT_FALSE(FPDF_LoadCustomDocument(&file_access, nullptr)); + struct { + const char* password; + const unsigned long permissions; + } tests[] = {{"1234", 0xFFFFF2C0}, {"5678", 0xFFFFFFFC}}; + for (const auto& test : tests) { + TestSaved(612, 792, md5, test.password); + EXPECT_EQ(test.permissions, FPDF_GetDocPermissions(m_SavedDocument)); + CloseSaved(); + } +} + TEST_F(CPDFSecurityHandlerEmbeddertest, NoPasswordVersion5) { ASSERT_FALSE(OpenDocument("bug_644.pdf")); } diff --git a/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_simple_parser_unittest.cpp b/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_simple_parser_unittest.cpp index 5f56b948cd4..f1c84853dc9 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_simple_parser_unittest.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_simple_parser_unittest.cpp @@ -54,7 +54,7 @@ TEST(SimpleParserTest, GetWord) { CFX_ByteStringC word = parser.GetWord(); EXPECT_EQ(std::string(reinterpret_cast<const char*>(data.expected), data.expected_size), - std::string(word.c_str(), word.GetLength())) + std::string(word.unterminated_c_str(), word.GetLength())) << " for case " << i; } } diff --git a/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_stream.cpp b/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_stream.cpp index 69a87e6d2ed..ec12ac50807 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_stream.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_stream.cpp @@ -110,6 +110,11 @@ void CPDF_Stream::SetData(const uint8_t* pData, uint32_t size) { m_pDict->RemoveFor("DecodeParms"); } +void CPDF_Stream::SetData(std::ostringstream* stream) { + SetData(reinterpret_cast<const uint8_t*>(stream->str().c_str()), + stream->tellp()); +} + bool CPDF_Stream::ReadRawData(FX_FILESIZE offset, uint8_t* buf, uint32_t size) const { diff --git a/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_stream.h b/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_stream.h index 82cc01aef3d..d58f608f720 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_stream.h +++ b/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_stream.h @@ -9,6 +9,7 @@ #include <memory> #include <set> +#include <sstream> #include "core/fpdfapi/parser/cpdf_dictionary.h" #include "core/fpdfapi/parser/cpdf_object.h" @@ -38,8 +39,9 @@ class CPDF_Stream : public CPDF_Object { uint32_t GetRawSize() const { return m_dwSize; } uint8_t* GetRawData() const { return m_pDataBuf.get(); } - // Does not takes onwership of |pData|, copies into internally-owned buffer. + // Does not takes ownership of |pData|, copies into internally-owned buffer. void SetData(const uint8_t* pData, uint32_t size); + void SetData(std::ostringstream* stream); void InitStream(const uint8_t* pData, uint32_t size, diff --git a/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_stream_acc.cpp b/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_stream_acc.cpp index fe333e4d2bc..ccc3fdae534 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_stream_acc.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_stream_acc.cpp @@ -42,9 +42,9 @@ void CPDF_StreamAcc::LoadAllData(bool bRawAccess, if (!m_pStream->HasFilter() || bRawAccess) { m_pData = pSrcData; m_dwSize = dwSrcSize; - } else if (!PDF_DataDecode(pSrcData, dwSrcSize, m_pStream->GetDict(), m_pData, - m_dwSize, &m_ImageDecoder, m_pImageParam, - estimated_size, bImageAcc)) { + } else if (!PDF_DataDecode(pSrcData, dwSrcSize, m_pStream->GetDict(), + estimated_size, bImageAcc, &m_pData, &m_dwSize, + &m_ImageDecoder, &m_pImageParam)) { m_pData = pSrcData; m_dwSize = dwSrcSize; } diff --git a/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_syntax_parser.cpp b/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_syntax_parser.cpp index ab03e623ac7..ce5a83579db 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_syntax_parser.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/parser/cpdf_syntax_parser.cpp @@ -7,6 +7,7 @@ #include "core/fpdfapi/parser/cpdf_syntax_parser.h" #include <algorithm> +#include <sstream> #include <utility> #include <vector> @@ -204,7 +205,7 @@ CFX_ByteString CPDF_SyntaxParser::ReadString() { if (!GetNextChar(ch)) return CFX_ByteString(); - CFX_ByteTextBuf buf; + std::ostringstream buf; int32_t parlevel = 0; ReadStatus status = ReadStatus::Normal; int32_t iEscCode = 0; @@ -213,7 +214,7 @@ CFX_ByteString CPDF_SyntaxParser::ReadString() { case ReadStatus::Normal: if (ch == ')') { if (parlevel == 0) - return buf.MakeString(); + return CFX_ByteString(buf); parlevel--; } else if (ch == '(') { parlevel++; @@ -221,7 +222,7 @@ CFX_ByteString CPDF_SyntaxParser::ReadString() { if (ch == '\\') status = ReadStatus::Backslash; else - buf.AppendChar(ch); + buf << static_cast<char>(ch); break; case ReadStatus::Backslash: if (ch >= '0' && ch <= '7') { @@ -231,20 +232,20 @@ CFX_ByteString CPDF_SyntaxParser::ReadString() { } if (ch == 'n') { - buf.AppendChar('\n'); + buf << '\n'; } else if (ch == 'r') { - buf.AppendChar('\r'); + buf << '\r'; } else if (ch == 't') { - buf.AppendChar('\t'); + buf << '\t'; } else if (ch == 'b') { - buf.AppendChar('\b'); + buf << '\b'; } else if (ch == 'f') { - buf.AppendChar('\f'); + buf << '\f'; } else if (ch == '\r') { status = ReadStatus::CarriageReturn; break; } else if (ch != '\n') { - buf.AppendChar(ch); + buf << static_cast<char>(ch); } status = ReadStatus::Normal; break; @@ -254,7 +255,7 @@ CFX_ByteString CPDF_SyntaxParser::ReadString() { iEscCode * 8 + FXSYS_DecimalCharToInt(static_cast<wchar_t>(ch)); status = ReadStatus::FinishOctal; } else { - buf.AppendChar(iEscCode); + buf << static_cast<char>(iEscCode); status = ReadStatus::Normal; continue; } @@ -264,9 +265,9 @@ CFX_ByteString CPDF_SyntaxParser::ReadString() { if (ch >= '0' && ch <= '7') { iEscCode = iEscCode * 8 + FXSYS_DecimalCharToInt(static_cast<wchar_t>(ch)); - buf.AppendChar(iEscCode); + buf << static_cast<char>(iEscCode); } else { - buf.AppendChar(iEscCode); + buf << static_cast<char>(iEscCode); continue; } break; @@ -282,7 +283,7 @@ CFX_ByteString CPDF_SyntaxParser::ReadString() { } GetNextChar(ch); - return buf.MakeString(); + return CFX_ByteString(buf); } CFX_ByteString CPDF_SyntaxParser::ReadHexString() { @@ -290,7 +291,7 @@ CFX_ByteString CPDF_SyntaxParser::ReadHexString() { if (!GetNextChar(ch)) return CFX_ByteString(); - CFX_ByteTextBuf buf; + std::ostringstream buf; bool bFirst = true; uint8_t code = 0; while (1) { @@ -303,7 +304,7 @@ CFX_ByteString CPDF_SyntaxParser::ReadHexString() { code = val * 16; } else { code += val; - buf.AppendByte(code); + buf << static_cast<char>(code); } bFirst = !bFirst; } @@ -312,9 +313,9 @@ CFX_ByteString CPDF_SyntaxParser::ReadHexString() { break; } if (!bFirst) - buf.AppendByte(code); + buf << static_cast<char>(code); - return buf.MakeString(); + return CFX_ByteString(buf); } void CPDF_SyntaxParser::ToNextLine() { @@ -386,10 +387,10 @@ std::unique_ptr<CPDF_Object> CPDF_SyntaxParser::GetObject( if (bIsNumber) { CFX_ByteString nextword2 = GetNextWord(nullptr); if (nextword2 == "R") { - uint32_t objnum = FXSYS_atoui(word.c_str()); - if (objnum == CPDF_Object::kInvalidObjNum) + uint32_t refnum = FXSYS_atoui(word.c_str()); + if (refnum == CPDF_Object::kInvalidObjNum) return nullptr; - return pdfium::MakeUnique<CPDF_Reference>(pObjList, objnum); + return pdfium::MakeUnique<CPDF_Reference>(pObjList, refnum); } } m_Pos = SavedPos; @@ -507,10 +508,10 @@ std::unique_ptr<CPDF_Object> CPDF_SyntaxParser::GetObjectForStrict( if (bIsNumber) { CFX_ByteString nextword2 = GetNextWord(nullptr); if (nextword2 == "R") { - uint32_t objnum = FXSYS_atoui(word.c_str()); - if (objnum == CPDF_Object::kInvalidObjNum) + uint32_t refnum = FXSYS_atoui(word.c_str()); + if (refnum == CPDF_Object::kInvalidObjNum) return nullptr; - return pdfium::MakeUnique<CPDF_Reference>(pObjList, objnum); + return pdfium::MakeUnique<CPDF_Reference>(pObjList, refnum); } } m_Pos = SavedPos; diff --git a/chromium/third_party/pdfium/core/fpdfapi/parser/fpdf_parser_decode.cpp b/chromium/third_party/pdfium/core/fpdfapi/parser/fpdf_parser_decode.cpp index 561b6627bcf..ddd6b1462da 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/parser/fpdf_parser_decode.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/parser/fpdf_parser_decode.cpp @@ -9,6 +9,7 @@ #include <limits.h> #include <algorithm> +#include <sstream> #include <utility> #include <vector> @@ -18,6 +19,7 @@ #include "core/fpdfapi/parser/fpdf_parser_utility.h" #include "core/fxcodec/fx_codec.h" #include "core/fxcrt/fx_extension.h" +#include "third_party/base/numerics/safe_math.h" #include "third_party/base/stl_util.h" namespace { @@ -28,15 +30,13 @@ bool CheckFlateDecodeParams(int Colors, int BitsPerComponent, int Columns) { if (Colors < 0 || BitsPerComponent < 0 || Columns < 0) return false; - int check = Columns; - if (check > 0 && Colors > INT_MAX / check) - return false; - + pdfium::base::CheckedNumeric<int> check = Columns; check *= Colors; - if (check > 0 && BitsPerComponent > INT_MAX / check) + check *= BitsPerComponent; + if (!check.IsValid()) return false; - return check * BitsPerComponent <= INT_MAX - 7; + return check.ValueOrDie() <= INT_MAX - 7; } } // namespace @@ -74,10 +74,10 @@ const uint16_t PDFDocEncoding[256] = { uint32_t A85Decode(const uint8_t* src_buf, uint32_t src_size, - uint8_t*& dest_buf, - uint32_t& dest_size) { - dest_size = 0; - dest_buf = nullptr; + uint8_t** dest_buf, + uint32_t* dest_size) { + *dest_size = 0; + *dest_buf = nullptr; if (src_size == 0) return 0; @@ -104,26 +104,27 @@ uint32_t A85Decode(const uint8_t* src_buf, if (zcount > (UINT_MAX - space_for_non_zeroes) / 4) return 0xFFFFFFFF; - dest_buf = FX_Alloc(uint8_t, zcount * 4 + space_for_non_zeroes); + *dest_buf = FX_Alloc(uint8_t, zcount * 4 + space_for_non_zeroes); size_t state = 0; uint32_t res = 0; - pos = dest_size = 0; + pos = 0; while (pos < src_size) { uint8_t ch = src_buf[pos++]; if (PDFCharIsLineEnding(ch) || ch == ' ' || ch == '\t') continue; if (ch == 'z') { - memset(dest_buf + dest_size, 0, 4); + memset(*dest_buf + *dest_size, 0, 4); state = 0; res = 0; - dest_size += 4; + *dest_size += 4; } else if (ch >= '!' && ch <= 'u') { res = res * 85 + ch - 33; state++; if (state == 5) { - for (size_t i = 0; i < 4; i++) { - dest_buf[dest_size++] = (uint8_t)(res >> (3 - i) * 8); + for (size_t i = 0; i < 4; ++i) { + (*dest_buf)[(*dest_size)++] = + static_cast<uint8_t>(res >> (3 - i) * 8); } state = 0; res = 0; @@ -135,34 +136,34 @@ uint32_t A85Decode(const uint8_t* src_buf, } // Handle partial group. if (state) { - for (size_t i = state; i < 5; i++) + for (size_t i = state; i < 5; ++i) res = res * 85 + 84; - for (size_t i = 0; i < state - 1; i++) - dest_buf[dest_size++] = (uint8_t)(res >> (3 - i) * 8); + for (size_t i = 0; i < state - 1; ++i) + (*dest_buf)[(*dest_size)++] = static_cast<uint8_t>(res >> (3 - i) * 8); } if (pos < src_size && src_buf[pos] == '>') - pos++; + ++pos; return pos; } uint32_t HexDecode(const uint8_t* src_buf, uint32_t src_size, - uint8_t*& dest_buf, - uint32_t& dest_size) { - dest_size = 0; + uint8_t** dest_buf, + uint32_t* dest_size) { + *dest_size = 0; if (src_size == 0) { - dest_buf = nullptr; + *dest_buf = nullptr; return 0; } uint32_t i = 0; // Find the end of data. while (i < src_size && src_buf[i] != '>') - i++; + ++i; - dest_buf = FX_Alloc(uint8_t, i / 2 + 1); + *dest_buf = FX_Alloc(uint8_t, i / 2 + 1); bool bFirst = true; - for (i = 0; i < src_size; i++) { + for (i = 0; i < src_size; ++i) { uint8_t ch = src_buf[i]; if (PDFCharIsLineEnding(ch) || ch == ' ' || ch == '\t') continue; @@ -176,44 +177,43 @@ uint32_t HexDecode(const uint8_t* src_buf, int digit = FXSYS_HexCharToInt(ch); if (bFirst) - dest_buf[dest_size] = digit * 16; + (*dest_buf)[*dest_size] = digit * 16; else - dest_buf[dest_size++] += digit; - + (*dest_buf)[(*dest_size)++] += digit; bFirst = !bFirst; } if (!bFirst) - dest_size++; + ++(*dest_size); return i; } uint32_t RunLengthDecode(const uint8_t* src_buf, uint32_t src_size, - uint8_t*& dest_buf, - uint32_t& dest_size) { + uint8_t** dest_buf, + uint32_t* dest_size) { uint32_t i = 0; - dest_size = 0; + *dest_size = 0; while (i < src_size) { if (src_buf[i] == 128) break; - uint32_t old = dest_size; + uint32_t old = *dest_size; if (src_buf[i] < 128) { - dest_size += src_buf[i] + 1; - if (dest_size < old) + *dest_size += src_buf[i] + 1; + if (*dest_size < old) return FX_INVALID_OFFSET; i += src_buf[i] + 2; } else { - dest_size += 257 - src_buf[i]; - if (dest_size < old) + *dest_size += 257 - src_buf[i]; + if (*dest_size < old) return FX_INVALID_OFFSET; i += 2; } } - if (dest_size >= kMaxStreamSize) + if (*dest_size >= kMaxStreamSize) return FX_INVALID_OFFSET; - dest_buf = FX_Alloc(uint8_t, dest_size); + *dest_buf = FX_Alloc(uint8_t, *dest_size); i = 0; int dest_count = 0; while (i < src_size) { @@ -226,22 +226,20 @@ uint32_t RunLengthDecode(const uint8_t* src_buf, if (buf_left < copy_len) { uint32_t delta = copy_len - buf_left; copy_len = buf_left; - memset(dest_buf + dest_count + copy_len, '\0', delta); + memset(*dest_buf + dest_count + copy_len, '\0', delta); } - memcpy(dest_buf + dest_count, src_buf + i + 1, copy_len); + memcpy(*dest_buf + dest_count, src_buf + i + 1, copy_len); dest_count += src_buf[i] + 1; i += src_buf[i] + 2; } else { int fill = 0; - if (i < src_size - 1) { + if (i < src_size - 1) fill = src_buf[i + 1]; - } - memset(dest_buf + dest_count, fill, 257 - src_buf[i]); + memset(*dest_buf + dest_count, fill, 257 - src_buf[i]); dest_count += 257 - src_buf[i]; i += 2; } } - return std::min(i + 1, src_size); } @@ -264,9 +262,8 @@ std::unique_ptr<CCodec_ScanlineDecoder> FPDFAPI_CreateFaxDecoder( BlackIs1 = !!pParams->GetIntegerFor("BlackIs1"); Columns = pParams->GetIntegerFor("Columns", 1728); Rows = pParams->GetIntegerFor("Rows"); - if (Rows > USHRT_MAX) { + if (Rows > USHRT_MAX) Rows = 0; - } } return CPDF_ModuleMgr::Get()->GetFaxModule()->CreateDecoder( src_buf, src_size, width, height, K, EndOfLine, ByteAlign, BlackIs1, @@ -282,7 +279,9 @@ std::unique_ptr<CCodec_ScanlineDecoder> FPDFAPI_CreateFlateDecoder( int bpc, const CPDF_Dictionary* pParams) { int predictor = 0; - int Colors = 0, BitsPerComponent = 0, Columns = 0; + int Colors = 0; + int BitsPerComponent = 0; + int Columns = 0; if (pParams) { predictor = pParams->GetIntegerFor("Predictor"); Colors = pParams->GetIntegerFor("Colors", 1); @@ -301,8 +300,8 @@ uint32_t FPDFAPI_FlateOrLZWDecode(bool bLZW, uint32_t src_size, CPDF_Dictionary* pParams, uint32_t estimated_size, - uint8_t*& dest_buf, - uint32_t& dest_size) { + uint8_t** dest_buf, + uint32_t* dest_size) { int predictor = 0; int Colors = 0; int BitsPerComponent = 0; @@ -325,12 +324,12 @@ uint32_t FPDFAPI_FlateOrLZWDecode(bool bLZW, bool PDF_DataDecode(const uint8_t* src_buf, uint32_t src_size, const CPDF_Dictionary* pDict, - uint8_t*& dest_buf, - uint32_t& dest_size, - CFX_ByteString* ImageEncoding, - CPDF_Dictionary*& pImageParms, uint32_t last_estimated_size, - bool bImageAcc) { + bool bImageAcc, + uint8_t** dest_buf, + uint32_t* dest_size, + CFX_ByteString* ImageEncoding, + CPDF_Dictionary** pImageParms) { CPDF_Object* pDecoder = pDict ? pDict->GetDirectObjectFor("Filter") : nullptr; if (!pDecoder || (!pDecoder->IsArray() && !pDecoder->IsName())) return false; @@ -341,7 +340,7 @@ bool PDF_DataDecode(const uint8_t* src_buf, std::vector<std::pair<CFX_ByteString, CPDF_Object*>> DecoderArray; if (CPDF_Array* pDecoders = pDecoder->AsArray()) { CPDF_Array* pParamsArray = ToArray(pParams); - for (size_t i = 0; i < pDecoders->GetCount(); i++) { + for (size_t i = 0; i < pDecoders->GetCount(); ++i) { DecoderArray.push_back( {pDecoders->GetStringAt(i), pParamsArray ? pParamsArray->GetDictAt(i) : nullptr}); @@ -353,7 +352,7 @@ bool PDF_DataDecode(const uint8_t* src_buf, uint8_t* last_buf = const_cast<uint8_t*>(src_buf); uint32_t last_size = src_size; int nSize = pdfium::CollectionSize<int>(DecoderArray); - for (int i = 0; i < nSize; i++) { + for (int i = 0; i < nSize; ++i) { int estimated_size = i == nSize - 1 ? last_estimated_size : 0; CFX_ByteString decoder = DecoderArray[i].first; CPDF_Dictionary* pParam = ToDictionary(DecoderArray[i].second); @@ -363,49 +362,47 @@ bool PDF_DataDecode(const uint8_t* src_buf, if (decoder == "FlateDecode" || decoder == "Fl") { if (bImageAcc && i == nSize - 1) { *ImageEncoding = "FlateDecode"; - dest_buf = last_buf; - dest_size = last_size; - pImageParms = pParam; + *dest_buf = last_buf; + *dest_size = last_size; + *pImageParms = pParam; return true; } offset = FPDFAPI_FlateOrLZWDecode(false, last_buf, last_size, pParam, - estimated_size, new_buf, new_size); + estimated_size, &new_buf, &new_size); } else if (decoder == "LZWDecode" || decoder == "LZW") { offset = FPDFAPI_FlateOrLZWDecode(true, last_buf, last_size, pParam, - estimated_size, new_buf, new_size); + estimated_size, &new_buf, &new_size); } else if (decoder == "ASCII85Decode" || decoder == "A85") { - offset = A85Decode(last_buf, last_size, new_buf, new_size); + offset = A85Decode(last_buf, last_size, &new_buf, &new_size); } else if (decoder == "ASCIIHexDecode" || decoder == "AHx") { - offset = HexDecode(last_buf, last_size, new_buf, new_size); + offset = HexDecode(last_buf, last_size, &new_buf, &new_size); } else if (decoder == "RunLengthDecode" || decoder == "RL") { if (bImageAcc && i == nSize - 1) { *ImageEncoding = "RunLengthDecode"; - dest_buf = last_buf; - dest_size = last_size; - pImageParms = pParam; + *dest_buf = last_buf; + *dest_size = last_size; + *pImageParms = pParam; return true; } - offset = RunLengthDecode(last_buf, last_size, new_buf, new_size); + offset = RunLengthDecode(last_buf, last_size, &new_buf, &new_size); } else if (decoder == "Crypt") { continue; } else { // If we get here, assume it's an image decoder. - if (decoder == "DCT") { + if (decoder == "DCT") decoder = "DCTDecode"; - } else if (decoder == "CCF") { + else if (decoder == "CCF") decoder = "CCITTFaxDecode"; - } *ImageEncoding = decoder; - pImageParms = pParam; - dest_buf = last_buf; - dest_size = last_size; + *pImageParms = pParam; + *dest_buf = last_buf; + *dest_size = last_size; if (CPDF_Array* pDecoders = pDecoder->AsArray()) - pDecoders->RemoveAt(i + 1, pDecoders->GetCount() - i - 1); + pDecoders->Truncate(i + 1); return true; } - if (last_buf != src_buf) { + if (last_buf != src_buf) FX_Free(last_buf); - } if (offset == -1) { FX_Free(new_buf); return false; @@ -414,9 +411,9 @@ bool PDF_DataDecode(const uint8_t* src_buf, last_size = new_size; } *ImageEncoding = ""; - pImageParms = nullptr; - dest_buf = last_buf; - dest_size = last_size; + *pImageParms = nullptr; + *dest_buf = last_buf; + *dest_size = last_size; return true; } @@ -426,12 +423,11 @@ CFX_WideString PDF_DecodeText(const uint8_t* src_data, uint32_t src_len) { (src_data[0] == 0xff && src_data[1] == 0xfe))) { bool bBE = src_data[0] == 0xfe; uint32_t max_chars = (src_len - 2) / 2; - if (!max_chars) { + if (!max_chars) return result; - } - if (src_data[0] == 0xff) { + + if (src_data[0] == 0xff) bBE = !src_data[2]; - } wchar_t* dest_buf = result.GetBuffer(max_chars); const uint8_t* uni_str = src_data + 2; int dest_pos = 0; @@ -454,7 +450,7 @@ CFX_WideString PDF_DecodeText(const uint8_t* src_data, uint32_t src_len) { result.ReleaseBuffer(dest_pos); } else { wchar_t* dest_buf = result.GetBuffer(src_len); - for (uint32_t i = 0; i < src_len; i++) + for (uint32_t i = 0; i < src_len; ++i) dest_buf[i] = PDFDocEncoding[src_data[i]]; result.ReleaseBuffer(src_len); } @@ -462,31 +458,32 @@ CFX_WideString PDF_DecodeText(const uint8_t* src_data, uint32_t src_len) { } CFX_WideString PDF_DecodeText(const CFX_ByteString& bstr) { - return PDF_DecodeText((const uint8_t*)bstr.c_str(), bstr.GetLength()); + return PDF_DecodeText(reinterpret_cast<const uint8_t*>(bstr.c_str()), + bstr.GetLength()); } CFX_ByteString PDF_EncodeText(const wchar_t* pString, int len) { - if (len == -1) { + if (len == -1) len = FXSYS_wcslen(pString); - } + CFX_ByteString result; char* dest_buf1 = result.GetBuffer(len); int i; - for (i = 0; i < len; i++) { + for (i = 0; i < len; ++i) { int code; - for (code = 0; code < 256; code++) - if (PDFDocEncoding[code] == pString[i]) { + for (code = 0; code < 256; ++code) { + if (PDFDocEncoding[code] == pString[i]) break; - } - if (code == 256) { - break; } + + if (code == 256) + break; + dest_buf1[i] = code; } result.ReleaseBuffer(i); - if (i == len) { + if (i == len) return result; - } if (len > INT_MAX / 2 - 1) { result.ReleaseBuffer(0); @@ -495,13 +492,13 @@ CFX_ByteString PDF_EncodeText(const wchar_t* pString, int len) { int encLen = len * 2 + 2; - uint8_t* dest_buf2 = (uint8_t*)result.GetBuffer(encLen); + uint8_t* dest_buf2 = reinterpret_cast<uint8_t*>(result.GetBuffer(encLen)); dest_buf2[0] = 0xfe; dest_buf2[1] = 0xff; dest_buf2 += 2; - for (int j = 0; j < len; j++) { + for (int j = 0; j < len; ++j) { *dest_buf2++ = pString[j] >> 8; - *dest_buf2++ = (uint8_t)pString[j]; + *dest_buf2++ = static_cast<uint8_t>(pString[j]); } result.ReleaseBuffer(encLen); return result; @@ -512,21 +509,21 @@ CFX_ByteString PDF_EncodeText(const CFX_WideString& str) { } CFX_ByteString PDF_EncodeString(const CFX_ByteString& src, bool bHex) { - CFX_ByteTextBuf result; + std::ostringstream result; int srclen = src.GetLength(); if (bHex) { - result.AppendChar('<'); - for (int i = 0; i < srclen; i++) { + result << '<'; + for (int i = 0; i < srclen; ++i) { char buf[2]; FXSYS_IntToTwoHexChars(src[i], buf); - result.AppendChar(buf[0]); - result.AppendChar(buf[1]); + result << buf[0]; + result << buf[1]; } - result.AppendChar('>'); - return result.MakeString(); + result << '>'; + return CFX_ByteString(result); } - result.AppendChar('('); - for (int i = 0; i < srclen; i++) { + result << '('; + for (int i = 0; i < srclen; ++i) { uint8_t ch = src[i]; if (ch == 0x0a) { result << "\\n"; @@ -537,11 +534,11 @@ CFX_ByteString PDF_EncodeString(const CFX_ByteString& src, bool bHex) { continue; } if (ch == ')' || ch == '\\' || ch == '(') - result.AppendChar('\\'); - result.AppendChar(ch); + result << '\\'; + result << static_cast<char>(ch); } - result.AppendChar(')'); - return result.MakeString(); + result << ')'; + return CFX_ByteString(result); } bool FlateEncode(const uint8_t* src_buf, @@ -564,8 +561,8 @@ bool PngEncode(const uint8_t* src_buf, uint32_t FlateDecode(const uint8_t* src_buf, uint32_t src_size, - uint8_t*& dest_buf, - uint32_t& dest_size) { + uint8_t** dest_buf, + uint32_t* dest_size) { CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); return pEncoders->GetFlateModule()->FlateOrLZWDecode( false, src_buf, src_size, false, 0, 0, 0, 0, 0, dest_buf, dest_size); diff --git a/chromium/third_party/pdfium/core/fpdfapi/parser/fpdf_parser_decode.h b/chromium/third_party/pdfium/core/fpdfapi/parser/fpdf_parser_decode.h index 955a8cfb329..4d2c6732e02 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/parser/fpdf_parser_decode.h +++ b/chromium/third_party/pdfium/core/fpdfapi/parser/fpdf_parser_decode.h @@ -20,10 +20,10 @@ extern const uint16_t PDFDocEncoding[256]; CFX_ByteString PDF_NameDecode(const CFX_ByteStringC& orig); CFX_ByteString PDF_NameDecode(const CFX_ByteString& orig); CFX_ByteString PDF_NameEncode(const CFX_ByteString& orig); -CFX_ByteString PDF_EncodeString(const CFX_ByteString& src, bool bHex = false); +CFX_ByteString PDF_EncodeString(const CFX_ByteString& src, bool bHex); CFX_WideString PDF_DecodeText(const uint8_t* pData, uint32_t size); CFX_WideString PDF_DecodeText(const CFX_ByteString& bstr); -CFX_ByteString PDF_EncodeText(const wchar_t* pString, int len = -1); +CFX_ByteString PDF_EncodeText(const wchar_t* pString, int len); CFX_ByteString PDF_EncodeText(const CFX_WideString& str); bool FlateEncode(const uint8_t* src_buf, @@ -41,12 +41,13 @@ bool PngEncode(const uint8_t* src_buf, uint32_t FlateDecode(const uint8_t* src_buf, uint32_t src_size, - uint8_t*& dest_buf, - uint32_t& dest_size); + uint8_t** dest_buf, + uint32_t* dest_size); + uint32_t RunLengthDecode(const uint8_t* src_buf, uint32_t src_size, - uint8_t*& dest_buf, - uint32_t& dest_size); + uint8_t** dest_buf, + uint32_t* dest_size); std::unique_ptr<CCodec_ScanlineDecoder> FPDFAPI_CreateFaxDecoder( const uint8_t* src_buf, @@ -64,32 +65,32 @@ std::unique_ptr<CCodec_ScanlineDecoder> FPDFAPI_CreateFlateDecoder( int bpc, const CPDF_Dictionary* pParams); -// Public for testing. uint32_t A85Decode(const uint8_t* src_buf, uint32_t src_size, - uint8_t*& dest_buf, - uint32_t& dest_size); -// Public for testing. + uint8_t** dest_buf, + uint32_t* dest_size); + uint32_t HexDecode(const uint8_t* src_buf, uint32_t src_size, - uint8_t*& dest_buf, - uint32_t& dest_size); -// Public for testing. + uint8_t** dest_buf, + uint32_t* dest_size); + uint32_t FPDFAPI_FlateOrLZWDecode(bool bLZW, const uint8_t* src_buf, uint32_t src_size, CPDF_Dictionary* pParams, uint32_t estimated_size, - uint8_t*& dest_buf, - uint32_t& dest_size); + uint8_t** dest_buf, + uint32_t* dest_size); + bool PDF_DataDecode(const uint8_t* src_buf, uint32_t src_size, const CPDF_Dictionary* pDict, - uint8_t*& dest_buf, - uint32_t& dest_size, - CFX_ByteString* ImageEncoding, - CPDF_Dictionary*& pImageParms, uint32_t estimated_size, - bool bImageAcc); + bool bImageAcc, + uint8_t** dest_buf, + uint32_t* dest_size, + CFX_ByteString* ImageEncoding, + CPDF_Dictionary** pImageParms); #endif // CORE_FPDFAPI_PARSER_FPDF_PARSER_DECODE_H_ diff --git a/chromium/third_party/pdfium/core/fpdfapi/parser/fpdf_parser_decode_embeddertest.cpp b/chromium/third_party/pdfium/core/fpdfapi/parser/fpdf_parser_decode_embeddertest.cpp index 136d7c9f2ff..799da49bdcd 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/parser/fpdf_parser_decode_embeddertest.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/parser/fpdf_parser_decode_embeddertest.cpp @@ -9,7 +9,6 @@ #include "core/fxcrt/fx_basic.h" #include "testing/embedder_test.h" -#include "testing/fx_string_testhelpers.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/test_support.h" @@ -76,7 +75,7 @@ TEST_F(FPDFParserDecodeEmbeddertest, FlateDecode) { unsigned char* result = nullptr; unsigned int result_size; EXPECT_EQ(data.processed_size, - FlateDecode(data.input, data.input_size, result, result_size)) + FlateDecode(data.input, data.input_size, &result, &result_size)) << " for case " << i; ASSERT_TRUE(result); EXPECT_EQ(std::string((const char*)data.expected, data.expected_size), @@ -117,9 +116,9 @@ TEST_F(FPDFParserDecodeEmbeddertest, Bug_455199) { #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ const char kExpectedMd5sum[] = "b90475ca64d1348c3bf5e2b77ad9187a"; #elif _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ - const char kExpectedMd5sum[] = "5db84ceda153acc4420c2062b182191b"; + const char kExpectedMd5sum[] = "9a2637b73fd5265309bfddd9c69476cd"; #else - const char kExpectedMd5sum[] = "f24438fe53948941200fd43da37908bc"; + const char kExpectedMd5sum[] = "f7e129d97c58e91adeace32a4327b925"; #endif CompareBitmap(bitmap, 200, 200, kExpectedMd5sum); FPDFBitmap_Destroy(bitmap); diff --git a/chromium/third_party/pdfium/core/fpdfapi/parser/fpdf_parser_decode_unittest.cpp b/chromium/third_party/pdfium/core/fpdfapi/parser/fpdf_parser_decode_unittest.cpp index f8c9863c324..c8e0c7a0e16 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/parser/fpdf_parser_decode_unittest.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/parser/fpdf_parser_decode_unittest.cpp @@ -31,7 +31,7 @@ TEST(fpdf_parser_decode, A85Decode) { uint8_t* result = nullptr; uint32_t result_size = 0; EXPECT_EQ(ptr->processed_size, - A85Decode(ptr->input, ptr->input_size, result, result_size)) + A85Decode(ptr->input, ptr->input_size, &result, &result_size)) << "for case " << i; ASSERT_EQ(ptr->expected_size, result_size); for (size_t j = 0; j < result_size; ++j) { @@ -66,7 +66,7 @@ TEST(fpdf_parser_decode, HexDecode) { uint8_t* result = nullptr; uint32_t result_size = 0; EXPECT_EQ(ptr->processed_size, - HexDecode(ptr->input, ptr->input_size, result, result_size)) + HexDecode(ptr->input, ptr->input_size, &result, &result_size)) << "for case " << i; ASSERT_EQ(ptr->expected_size, result_size); for (size_t j = 0; j < result_size; ++j) { diff --git a/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_charposlist.cpp b/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_charposlist.cpp index d4c6b3b5f94..a87fc3334e4 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_charposlist.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_charposlist.cpp @@ -37,20 +37,24 @@ void CPDF_CharPosList::Load(const std::vector<uint32_t>& charCodes, FXTEXT_CHARPOS& charpos = m_pCharPos[m_nChars++]; if (pCIDFont) charpos.m_bFontStyle = true; - + CFX_WideString unicode = pFont->UnicodeFromCharCode(CharCode); + charpos.m_Unicode = !unicode.IsEmpty() ? unicode.GetAt(0) : CharCode; charpos.m_GlyphIndex = pFont->GlyphFromCharCode(CharCode, &bVert); uint32_t GlyphID = charpos.m_GlyphIndex; #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ charpos.m_ExtGID = pFont->GlyphFromCharCodeExt(CharCode); GlyphID = charpos.m_ExtGID; #endif + CFX_Font* pCurrentFont; if (GlyphID != static_cast<uint32_t>(-1)) { charpos.m_FallbackFontPosition = -1; + pCurrentFont = pFont->GetFont(); } else { charpos.m_FallbackFontPosition = pFont->FallbackFontFromCharcode(CharCode); charpos.m_GlyphIndex = pFont->FallbackGlyphFromCharcode( charpos.m_FallbackFontPosition, CharCode); + pCurrentFont = pFont->GetFontFallback(charpos.m_FallbackFontPosition); #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ charpos.m_ExtGID = charpos.m_GlyphIndex; #endif @@ -63,6 +67,29 @@ void CPDF_CharPosList::Load(const std::vector<uint32_t>& charCodes, charpos.m_Origin = CFX_PointF(iChar ? charPos[iChar - 1] : 0, 0); charpos.m_bGlyphAdjust = false; + + float scalingFactor = 1.0f; + if (!pFont->IsEmbedded() && pFont->HasFontWidths() && !bVertWriting && + !(pCurrentFont->GetSubstFont()->m_SubstFlags & FXFONT_SUBST_MM)) { + int pdfGlyphWidth = pFont->GetCharWidthF(CharCode); + int ftGlyphWidth = + pCurrentFont ? pCurrentFont->GetGlyphWidth(charpos.m_GlyphIndex) : 0; + if (ftGlyphWidth && pdfGlyphWidth > ftGlyphWidth + 1) { + // Move the initial x position by half of the excess (transformed to + // text space coordinates). + charpos.m_Origin.x += + (pdfGlyphWidth - ftGlyphWidth) * FontSize / 2000.0f; + } else if (pdfGlyphWidth && ftGlyphWidth && + pdfGlyphWidth < ftGlyphWidth) { + scalingFactor = static_cast<float>(pdfGlyphWidth) / ftGlyphWidth; + ASSERT(scalingFactor >= 0.0f); + charpos.m_AdjustMatrix[0] = scalingFactor; + charpos.m_AdjustMatrix[1] = 0.0f; + charpos.m_AdjustMatrix[2] = 0.0f; + charpos.m_AdjustMatrix[3] = 1.0f; + charpos.m_bGlyphAdjust = true; + } + } if (!pCIDFont) continue; @@ -79,9 +106,11 @@ void CPDF_CharPosList::Load(const std::vector<uint32_t>& charCodes, const uint8_t* pTransform = pCIDFont->GetCIDTransform(CID); if (pTransform && !bVert) { - charpos.m_AdjustMatrix[0] = pCIDFont->CIDTransformToFloat(pTransform[0]); + charpos.m_AdjustMatrix[0] = + pCIDFont->CIDTransformToFloat(pTransform[0]) * scalingFactor; + charpos.m_AdjustMatrix[1] = + pCIDFont->CIDTransformToFloat(pTransform[1]) * scalingFactor; charpos.m_AdjustMatrix[2] = pCIDFont->CIDTransformToFloat(pTransform[2]); - charpos.m_AdjustMatrix[1] = pCIDFont->CIDTransformToFloat(pTransform[1]); charpos.m_AdjustMatrix[3] = pCIDFont->CIDTransformToFloat(pTransform[3]); charpos.m_Origin.x += pCIDFont->CIDTransformToFloat(pTransform[4]) * FontSize; diff --git a/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_imageloader.cpp b/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_imageloader.cpp index 53b6009c156..b09b919baaf 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_imageloader.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_imageloader.cpp @@ -36,8 +36,8 @@ bool CPDF_ImageLoader::Start(const CPDF_ImageObject* pImage, GroupFamily, bLoadMask, pRenderStatus); } else { ret = m_pImageObject->GetImage()->StartLoadDIBSource( - pRenderStatus->m_pFormResource, pRenderStatus->m_pPageResource, bStdCS, - GroupFamily, bLoadMask); + pRenderStatus->m_pFormResource.Get(), + pRenderStatus->m_pPageResource.Get(), bStdCS, GroupFamily, bLoadMask); } if (!ret) HandleFailure(); diff --git a/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_imageloader.h b/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_imageloader.h index f17f29cce5e..47dd2f9812f 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_imageloader.h +++ b/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_imageloader.h @@ -9,6 +9,7 @@ #include <memory> +#include "core/fxcrt/cfx_unowned_ptr.h" #include "core/fxcrt/fx_basic.h" #include "core/fxge/fx_dib.h" @@ -37,8 +38,8 @@ class CPDF_ImageLoader { private: void HandleFailure(); - CPDF_PageRenderCache* m_pCache; - CPDF_ImageObject* m_pImageObject; + CFX_UnownedPtr<CPDF_PageRenderCache> m_pCache; + CFX_UnownedPtr<CPDF_ImageObject> m_pImageObject; }; #endif // CORE_FPDFAPI_RENDER_CPDF_IMAGELOADER_H_ diff --git a/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_imagerenderer.cpp b/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_imagerenderer.cpp index ff4ed9c7d90..e6280772c82 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_imagerenderer.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_imagerenderer.cpp @@ -76,7 +76,7 @@ bool CPDF_ImageRenderer::StartRenderDIBSource() { CPDF_GeneralState& state = m_pImageObject->m_GeneralState; m_BitmapAlpha = FXSYS_round(255 * state.GetFillAlpha()); m_pDIBSource = m_Loader.m_pBitmap; - if (m_pRenderStatus->m_Options.m_ColorMode == RENDER_COLOR_ALPHA && + if (m_pRenderStatus->m_Options.m_ColorMode == CPDF_RenderOptions::kAlpha && !m_Loader.m_pMask) { return StartBitmapAlpha(); } @@ -103,10 +103,10 @@ bool CPDF_ImageRenderer::StartRenderDIBSource() { m_bPatternColor = true; } m_FillArgb = m_pRenderStatus->GetFillArgb(m_pImageObject.Get()); - } else if (m_pRenderStatus->m_Options.m_ColorMode == RENDER_COLOR_GRAY) { + } else if (m_pRenderStatus->m_Options.m_ColorMode == + CPDF_RenderOptions::kGray) { m_pClone = m_pDIBSource->Clone(nullptr); - m_pClone->ConvertColorScale(m_pRenderStatus->m_Options.m_BackColor, - m_pRenderStatus->m_Options.m_ForeColor); + m_pClone->ConvertColorScale(0xffffff, 0); m_pDIBSource = m_pClone; } m_Flags = 0; @@ -225,8 +225,8 @@ void CPDF_ImageRenderer::CalculateDrawImage( CFX_Matrix* pNewMatrix, const FX_RECT& rect) const { CPDF_RenderStatus bitmap_render; - bitmap_render.Initialize(m_pRenderStatus->m_pContext, pBitmapDevice2, nullptr, - nullptr, nullptr, nullptr, nullptr, 0, + bitmap_render.Initialize(m_pRenderStatus->m_pContext.Get(), pBitmapDevice2, + nullptr, nullptr, nullptr, nullptr, nullptr, 0, m_pRenderStatus->m_bDropObjects, nullptr, true); CPDF_ImageRenderer image_render; if (image_render.Start(&bitmap_render, pDIBSource, 0xffffffff, 255, @@ -276,7 +276,7 @@ bool CPDF_ImageRenderer::DrawPatternImage(const CFX_Matrix* pObj2Device) { bitmap_device1.GetBitmap()->Clear(0xffffff); CPDF_RenderStatus bitmap_render; - bitmap_render.Initialize(m_pRenderStatus->m_pContext, &bitmap_device1, + bitmap_render.Initialize(m_pRenderStatus->m_pContext.Get(), &bitmap_device1, nullptr, nullptr, nullptr, nullptr, &m_pRenderStatus->m_Options, 0, m_pRenderStatus->m_bDropObjects, nullptr, true); @@ -329,7 +329,7 @@ bool CPDF_ImageRenderer::DrawMaskedImage() { bitmap_device1.GetBitmap()->Clear(0xffffff); #endif CPDF_RenderStatus bitmap_render; - bitmap_render.Initialize(m_pRenderStatus->m_pContext, &bitmap_device1, + bitmap_render.Initialize(m_pRenderStatus->m_pContext.Get(), &bitmap_device1, nullptr, nullptr, nullptr, nullptr, nullptr, 0, m_pRenderStatus->m_bDropObjects, nullptr, true); CPDF_ImageRenderer image_render; @@ -418,7 +418,6 @@ bool CPDF_ImageRenderer::StartDIBSource() { m_Status = 2; m_pTransformer = pdfium::MakeUnique<CFX_ImageTransformer>( m_pDIBSource, &m_ImageMatrix, m_Flags, &clip_box); - m_pTransformer->Start(); return true; } if (m_ImageMatrix.a < 0) diff --git a/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_imagerenderer.h b/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_imagerenderer.h index bf73098cde5..46159284b21 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_imagerenderer.h +++ b/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_imagerenderer.h @@ -10,6 +10,7 @@ #include <memory> #include "core/fpdfapi/render/cpdf_imageloader.h" +#include "core/fxcrt/cfx_unowned_ptr.h" #include "core/fxcrt/fx_coordinates.h" #include "core/fxge/dib/cfx_imagerenderer.h" @@ -72,7 +73,7 @@ class CPDF_ImageRenderer { CFX_RetainPtr<CFX_DIBitmap> m_pClone; int m_BitmapAlpha; bool m_bPatternColor; - CPDF_Pattern* m_pPattern; + CFX_UnownedPtr<CPDF_Pattern> m_pPattern; FX_ARGB m_FillArgb; uint32_t m_Flags; std::unique_ptr<CFX_ImageTransformer> m_pTransformer; diff --git a/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_pagerendercache.cpp b/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_pagerendercache.cpp index a997e34906a..455b7f5ddb2 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_pagerendercache.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_pagerendercache.cpp @@ -95,8 +95,8 @@ bool CPDF_PageRenderCache::StartGetCachedBitmap( new CPDF_ImageCacheEntry(m_pPage->m_pDocument.Get(), pImage); } int ret = m_pCurImageCacheEntry->StartGetCachedBitmap( - pRenderStatus->m_pFormResource, m_pPage->m_pPageResources.Get(), bStdCS, - GroupFamily, bLoadMask, pRenderStatus); + pRenderStatus->m_pFormResource.Get(), m_pPage->m_pPageResources.Get(), + bStdCS, GroupFamily, bLoadMask, pRenderStatus); if (ret == 2) return true; diff --git a/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_progressiverenderer.cpp b/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_progressiverenderer.cpp index 4505db68742..4ddc5283426 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_progressiverenderer.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_progressiverenderer.cpp @@ -28,8 +28,10 @@ CPDF_ProgressiveRenderer::CPDF_ProgressiveRenderer( m_pCurrentLayer(nullptr) {} CPDF_ProgressiveRenderer::~CPDF_ProgressiveRenderer() { - if (m_pRenderStatus) + if (m_pRenderStatus) { + m_pRenderStatus.reset(); // Release first. m_pDevice->RestoreState(false); + } } void CPDF_ProgressiveRenderer::Start(IFX_Pause* pPause) { @@ -58,9 +60,7 @@ void CPDF_ProgressiveRenderer::Continue(IFX_Pause* pPause) { nullptr); m_pDevice->SaveState(); m_ClipRect = CFX_FloatRect(m_pDevice->GetClipBox()); - CFX_Matrix device2object; - device2object.SetReverse(m_pCurrentLayer->m_Matrix); - device2object.TransformRect(m_ClipRect); + m_pCurrentLayer->m_Matrix.GetInverse().TransformRect(m_ClipRect); } CPDF_PageObjectList::iterator iter; CPDF_PageObjectList::iterator iterEnd = diff --git a/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_progressiverenderer.h b/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_progressiverenderer.h index cadbd2d0897..5e5b69e7333 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_progressiverenderer.h +++ b/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_progressiverenderer.h @@ -26,7 +26,7 @@ class CPDF_ProgressiveRenderer { // static_asserts to make sure the two sets of values match. enum Status { Ready, // FPDF_RENDER_READER - ToBeContinued, // FPDF_RENDER_TOBECOUNTINUED + ToBeContinued, // FPDF_RENDER_TOBECONTINUED Done, // FPDF_RENDER_DONE Failed // FPDF_RENDER_FAILED }; diff --git a/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_rendercontext.cpp b/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_rendercontext.cpp index 2cd59cac188..dec513276d3 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_rendercontext.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_rendercontext.cpp @@ -72,12 +72,12 @@ void CPDF_RenderContext::Render(CFX_RenderDevice* pDevice, status.Initialize(this, pDevice, pLastMatrix, pStopObj, nullptr, nullptr, pOptions, layer.m_pObjectHolder->m_Transparency, false, nullptr); - status.RenderObjectList(layer.m_pObjectHolder, &FinalMatrix); + status.RenderObjectList(layer.m_pObjectHolder.Get(), &FinalMatrix); } else { status.Initialize(this, pDevice, nullptr, pStopObj, nullptr, nullptr, pOptions, layer.m_pObjectHolder->m_Transparency, false, nullptr); - status.RenderObjectList(layer.m_pObjectHolder, &layer.m_Matrix); + status.RenderObjectList(layer.m_pObjectHolder.Get(), &layer.m_Matrix); } if (status.m_Options.m_Flags & RENDER_LIMITEDIMAGECACHE) m_pPageCache->CacheOptimization(status.m_Options.m_dwLimitCacheSize); @@ -85,3 +85,9 @@ void CPDF_RenderContext::Render(CFX_RenderDevice* pDevice, break; } } + +CPDF_RenderContext::Layer::Layer() {} + +CPDF_RenderContext::Layer::Layer(const Layer& that) = default; + +CPDF_RenderContext::Layer::~Layer() {} diff --git a/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_rendercontext.h b/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_rendercontext.h index 4980d37ed63..220ff2b775f 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_rendercontext.h +++ b/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_rendercontext.h @@ -9,6 +9,7 @@ #include <vector> +#include "core/fxcrt/cfx_unowned_ptr.h" #include "core/fxcrt/fx_basic.h" #include "core/fxcrt/fx_coordinates.h" @@ -27,7 +28,11 @@ class CPDF_RenderContext { public: class Layer { public: - CPDF_PageObjectHolder* m_pObjectHolder; + Layer(); + Layer(const Layer& that); + ~Layer(); + + CFX_UnownedPtr<CPDF_PageObjectHolder> m_pObjectHolder; CFX_Matrix m_Matrix; }; diff --git a/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_renderoptions.cpp b/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_renderoptions.cpp index 70a4cf9615f..7916243cba5 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_renderoptions.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_renderoptions.cpp @@ -7,33 +7,24 @@ #include "core/fpdfapi/render/cpdf_renderoptions.h" CPDF_RenderOptions::CPDF_RenderOptions() - : m_ColorMode(RENDER_COLOR_NORMAL), + : m_ColorMode(kNormal), m_Flags(RENDER_CLEARTYPE), - m_Interpolation(0), - m_AddFlags(0), m_dwLimitCacheSize(1024 * 1024 * 100), - m_HalftoneLimit(-1), m_bDrawAnnots(false) {} CPDF_RenderOptions::CPDF_RenderOptions(const CPDF_RenderOptions& rhs) : m_ColorMode(rhs.m_ColorMode), - m_BackColor(rhs.m_BackColor), - m_ForeColor(rhs.m_ForeColor), m_Flags(rhs.m_Flags), - m_Interpolation(rhs.m_Interpolation), - m_AddFlags(rhs.m_AddFlags), m_dwLimitCacheSize(rhs.m_dwLimitCacheSize), - m_HalftoneLimit(rhs.m_HalftoneLimit), m_bDrawAnnots(rhs.m_bDrawAnnots), m_pOCContext(rhs.m_pOCContext) {} CPDF_RenderOptions::~CPDF_RenderOptions() {} FX_ARGB CPDF_RenderOptions::TranslateColor(FX_ARGB argb) const { - if (m_ColorMode == RENDER_COLOR_NORMAL) + if (m_ColorMode == kNormal) return argb; - - if (m_ColorMode == RENDER_COLOR_ALPHA) + if (m_ColorMode == kAlpha) return argb; int a; @@ -42,25 +33,5 @@ FX_ARGB CPDF_RenderOptions::TranslateColor(FX_ARGB argb) const { int b; std::tie(a, r, g, b) = ArgbDecode(argb); int gray = FXRGB2GRAY(r, g, b); - if (m_ColorMode == RENDER_COLOR_TWOCOLOR) { - int color = (r - gray) * (r - gray) + (g - gray) * (g - gray) + - (b - gray) * (b - gray); - if (gray < 35 && color < 20) - return ArgbEncode(a, m_ForeColor); - - if (gray > 221 && color < 20) - return ArgbEncode(a, m_BackColor); - - return argb; - } - int fr = FXSYS_GetRValue(m_ForeColor); - int fg = FXSYS_GetGValue(m_ForeColor); - int fb = FXSYS_GetBValue(m_ForeColor); - int br = FXSYS_GetRValue(m_BackColor); - int bg = FXSYS_GetGValue(m_BackColor); - int bb = FXSYS_GetBValue(m_BackColor); - r = (br - fr) * gray / 255 + fr; - g = (bg - fg) * gray / 255 + fg; - b = (bb - fb) * gray / 255 + fb; - return ArgbEncode(a, r, g, b); + return ArgbEncode(a, gray, gray, gray); } diff --git a/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_renderoptions.h b/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_renderoptions.h index ee26ccbb072..aa48b4e5dcf 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_renderoptions.h +++ b/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_renderoptions.h @@ -12,10 +12,6 @@ #include "core/fxcrt/fx_system.h" #include "core/fxge/fx_dib.h" -#define RENDER_COLOR_NORMAL 0 -#define RENDER_COLOR_GRAY 1 -#define RENDER_COLOR_TWOCOLOR 2 -#define RENDER_COLOR_ALPHA 3 #define RENDER_CLEARTYPE 0x00000001 #define RENDER_PRINTGRAPHICTEXT 0x00000002 #define RENDER_FORCE_DOWNSAMPLE 0x00000004 @@ -36,20 +32,17 @@ class CPDF_RenderOptions { public: + enum Type { kNormal = 0, kGray, kAlpha }; + CPDF_RenderOptions(); CPDF_RenderOptions(const CPDF_RenderOptions& rhs); ~CPDF_RenderOptions(); FX_ARGB TranslateColor(FX_ARGB argb) const; - int m_ColorMode; - FX_COLORREF m_BackColor; - FX_COLORREF m_ForeColor; + Type m_ColorMode; uint32_t m_Flags; - int m_Interpolation; - uint32_t m_AddFlags; uint32_t m_dwLimitCacheSize; - int m_HalftoneLimit; bool m_bDrawAnnots; CFX_RetainPtr<CPDF_OCContext> m_pOCContext; }; diff --git a/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_renderstatus.cpp b/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_renderstatus.cpp index 7c17ff56b40..e033f260939 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_renderstatus.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_renderstatus.cpp @@ -133,8 +133,6 @@ void DrawAxialShading(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, float x_span = end_x - start_x; float y_span = end_y - start_y; float axis_len_square = (x_span * x_span) + (y_span * y_span); - CFX_Matrix matrix; - matrix.SetReverse(*pObject2Bitmap); uint32_t total_results = std::max(CountOutputs(funcs), pCS->CountComponents()); CFX_FixedBufGrow<float, 16> result_array(total_results); @@ -160,6 +158,7 @@ void DrawAxialShading(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, FXSYS_round(G * 255), FXSYS_round(B * 255))); } int pitch = pBitmap->GetPitch(); + CFX_Matrix matrix = pObject2Bitmap->GetInverse(); for (int row = 0; row < height; row++) { uint32_t* dib_buf = (uint32_t*)(pBitmap->GetBuffer() + row * pitch); for (int column = 0; column < width; column++) { @@ -202,8 +201,6 @@ void DrawRadialShading(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, float end_x = pCoords->GetNumberAt(3); float end_y = pCoords->GetNumberAt(4); float end_r = pCoords->GetNumberAt(5); - CFX_Matrix matrix; - matrix.SetReverse(*pObject2Bitmap); float t_min = 0; float t_max = 1.0f; CPDF_Array* pArray = pDict->GetArrayFor("Domain"); @@ -256,6 +253,7 @@ void DrawRadialShading(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, bDecreasing = true; } } + CFX_Matrix matrix = pObject2Bitmap->GetInverse(); for (int row = 0; row < height; row++) { uint32_t* dib_buf = (uint32_t*)(pBitmap->GetBuffer() + row * pitch); for (int column = 0; column < width; column++) { @@ -334,12 +332,8 @@ void DrawFuncShading(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, ymax = pDomain->GetNumberAt(3); } CFX_Matrix mtDomain2Target = pDict->GetMatrixFor("Matrix"); - CFX_Matrix matrix; - matrix.SetReverse(*pObject2Bitmap); - - CFX_Matrix reverse_matrix; - reverse_matrix.SetReverse(mtDomain2Target); - matrix.Concat(reverse_matrix); + CFX_Matrix matrix = pObject2Bitmap->GetInverse(); + matrix.Concat(mtDomain2Target.GetInverse()); int width = pBitmap->GetWidth(); int height = pBitmap->GetHeight(); int pitch = pBitmap->GetPitch(); @@ -533,25 +527,24 @@ void DrawLatticeGouraudShading( if (!stream.Load()) return; - std::unique_ptr<CPDF_MeshVertex, FxFreeDeleter> vertex( - FX_Alloc2D(CPDF_MeshVertex, row_verts, 2)); - if (!stream.ReadVertexRow(*pObject2Bitmap, row_verts, vertex.get())) + std::vector<CPDF_MeshVertex> vertices[2]; + vertices[0] = stream.ReadVertexRow(*pObject2Bitmap, row_verts); + if (vertices[0].empty()) return; int last_index = 0; while (1) { - CPDF_MeshVertex* last_row = vertex.get() + last_index * row_verts; - CPDF_MeshVertex* this_row = vertex.get() + (1 - last_index) * row_verts; - if (!stream.ReadVertexRow(*pObject2Bitmap, row_verts, this_row)) + vertices[1 - last_index] = stream.ReadVertexRow(*pObject2Bitmap, row_verts); + if (vertices[1 - last_index].empty()) return; CPDF_MeshVertex triangle[3]; - for (int i = 1; i < row_verts; i++) { - triangle[0] = last_row[i]; - triangle[1] = this_row[i - 1]; - triangle[2] = last_row[i - 1]; + for (int i = 1; i < row_verts; ++i) { + triangle[0] = vertices[last_index][i]; + triangle[1] = vertices[1 - last_index][i - 1]; + triangle[2] = vertices[last_index][i - 1]; DrawGouraud(pBitmap, alpha, triangle); - triangle[2] = this_row[i]; + triangle[2] = vertices[1 - last_index][i]; DrawGouraud(pBitmap, alpha, triangle); } last_index = 1 - last_index; @@ -943,7 +936,7 @@ CFX_RetainPtr<CFX_DIBitmap> DrawPatternBitmap(CPDF_Document* pDoc, mtPattern2Bitmap.Concat(mtAdjust); CPDF_RenderOptions options; if (!pPattern->colored()) - options.m_ColorMode = RENDER_COLOR_ALPHA; + options.m_ColorMode = CPDF_RenderOptions::kAlpha; flags |= RENDER_FORCE_HALFTONE; options.m_Flags = flags; @@ -1056,9 +1049,7 @@ void CPDF_RenderStatus::RenderObjectList( DebugVerifyDeviceIsPreMultiplied(); #endif CFX_FloatRect clip_rect(m_pDevice->GetClipBox()); - CFX_Matrix device2object; - device2object.SetReverse(*pObj2Device); - device2object.TransformRect(clip_rect); + pObj2Device->GetInverse().TransformRect(clip_rect); for (const auto& pCurObj : *pObjectHolder->GetPageObjectList()) { if (pCurObj.get() == m_pStopObj) { @@ -1235,7 +1226,8 @@ void CPDF_RenderStatus::DrawObjWithBackground(CPDF_PageObject* pObj, res = 0; } CPDF_ScaledRenderBuffer buffer; - if (!buffer.Initialize(m_pContext, m_pDevice, rect, pObj, &m_Options, res)) { + if (!buffer.Initialize(m_pContext.Get(), m_pDevice, rect, pObj, &m_Options, + res)) { return; } CFX_Matrix matrix = *pObj2Device; @@ -1249,8 +1241,8 @@ void CPDF_RenderStatus::DrawObjWithBackground(CPDF_PageObject* pObj, } } CPDF_RenderStatus status; - status.Initialize(m_pContext, buffer.GetDevice(), buffer.GetMatrix(), nullptr, - nullptr, nullptr, &m_Options, m_Transparency, + status.Initialize(m_pContext.Get(), buffer.GetDevice(), buffer.GetMatrix(), + nullptr, nullptr, nullptr, &m_Options, m_Transparency, m_bDropObjects, pFormResource); status.RenderSingleObject(pObj, &matrix); buffer.OutputToDevice(); @@ -1273,9 +1265,9 @@ bool CPDF_RenderStatus::ProcessForm(const CPDF_FormObject* pFormObj, pResources = pFormObj->m_pForm->m_pFormDict->GetDictFor("Resources"); } CPDF_RenderStatus status; - status.Initialize(m_pContext, m_pDevice, nullptr, m_pStopObj, this, pFormObj, - &m_Options, m_Transparency, m_bDropObjects, pResources, - false); + status.Initialize(m_pContext.Get(), m_pDevice, nullptr, m_pStopObj, this, + pFormObj, &m_Options, m_Transparency, m_bDropObjects, + pResources, false); status.m_curBlend = m_curBlend; { CFX_RenderDevice::StateRestorer restorer(m_pDevice); @@ -1605,9 +1597,9 @@ bool CPDF_RenderStatus::ProcessTransparency(CPDF_PageObject* pPageObj, } } CPDF_RenderStatus bitmap_render; - bitmap_render.Initialize(m_pContext, &bitmap_device, nullptr, m_pStopObj, - nullptr, nullptr, &m_Options, 0, m_bDropObjects, - pFormResource, true); + bitmap_render.Initialize(m_pContext.Get(), &bitmap_device, nullptr, + m_pStopObj, nullptr, nullptr, &m_Options, 0, + m_bDropObjects, pFormResource, true); bitmap_render.ProcessObjectNoClip(pPageObj, &new_matrix); #if defined _SKIA_SUPPORT_PATHS_ bitmap_device.Flush(); @@ -1871,7 +1863,7 @@ bool CPDF_RenderStatus::ProcessType3Text(CPDF_TextObject* textobj, matrix.e += iChar ? textobj->m_CharPos[iChar - 1] : 0; matrix.Concat(text_matrix); matrix.Concat(*pObj2Device); - if (!pType3Char->LoadBitmap(m_pContext)) { + if (!pType3Char->LoadBitmap(m_pContext.Get())) { if (!glyphs.empty()) { for (int i = 0; i < iChar; i++) { const FXTEXT_GLYPHPOS& glyph = glyphs[i]; @@ -1897,7 +1889,7 @@ bool CPDF_RenderStatus::ProcessType3Text(CPDF_TextObject* textobj, } if (fill_alpha == 255) { CPDF_RenderStatus status; - status.Initialize(m_pContext, m_pDevice, nullptr, nullptr, this, + status.Initialize(m_pContext.Get(), m_pDevice, nullptr, nullptr, this, pStates.get(), &Options, pType3Char->m_pForm->m_Transparency, m_bDropObjects, pFormResource, false, pType3Char, fill_argb); @@ -1919,8 +1911,8 @@ bool CPDF_RenderStatus::ProcessType3Text(CPDF_TextObject* textobj, } bitmap_device.GetBitmap()->Clear(0); CPDF_RenderStatus status; - status.Initialize(m_pContext, &bitmap_device, nullptr, nullptr, this, - pStates.get(), &Options, + status.Initialize(m_pContext.Get(), &bitmap_device, nullptr, nullptr, + this, pStates.get(), &Options, pType3Char->m_pForm->m_Transparency, m_bDropObjects, pFormResource, false, pType3Char, fill_argb); status.m_Type3FontCache = m_Type3FontCache; @@ -2093,7 +2085,7 @@ void CPDF_RenderStatus::DrawShading(CPDF_ShadingPattern* pPattern, return; } CPDF_DeviceBuffer buffer; - buffer.Initialize(m_pContext, m_pDevice, &clip_rect, m_pCurObj, 150); + buffer.Initialize(m_pContext.Get(), m_pDevice, &clip_rect, m_pCurObj, 150); CFX_Matrix FinalMatrix = *pMatrix; FinalMatrix.Concat(*buffer.GetMatrix()); CFX_RetainPtr<CFX_DIBitmap> pBitmap = buffer.GetBitmap(); @@ -2145,8 +2137,8 @@ void CPDF_RenderStatus::DrawShading(CPDF_ShadingPattern* pPattern, if (bAlphaMode) pBitmap->LoadChannel(FXDIB_Red, pBitmap, FXDIB_Alpha); - if (m_Options.m_ColorMode == RENDER_COLOR_GRAY) - pBitmap->ConvertColorScale(m_Options.m_ForeColor, m_Options.m_BackColor); + if (m_Options.m_ColorMode == CPDF_RenderOptions::kGray) + pBitmap->ConvertColorScale(0, 0xffffff); buffer.OutputToDevice(); } @@ -2177,7 +2169,7 @@ void CPDF_RenderStatus::DrawShadingPattern(CPDF_ShadingPattern* pattern, FXSYS_round(255 * (bStroke ? pPageObj->m_GeneralState.GetStrokeAlpha() : pPageObj->m_GeneralState.GetFillAlpha())); DrawShading(pattern, &matrix, rect, alpha, - m_Options.m_ColorMode == RENDER_COLOR_ALPHA); + m_Options.m_ColorMode == CPDF_RenderOptions::kAlpha); } void CPDF_RenderStatus::ProcessShading(const CPDF_ShadingObject* pShadingObj, @@ -2190,9 +2182,9 @@ void CPDF_RenderStatus::ProcessShading(const CPDF_ShadingObject* pShadingObj, CFX_Matrix matrix = pShadingObj->m_Matrix; matrix.Concat(*pObj2Device); - DrawShading(pShadingObj->m_pShading, &matrix, rect, + DrawShading(pShadingObj->m_pShading.Get(), &matrix, rect, FXSYS_round(255 * pShadingObj->m_GeneralState.GetFillAlpha()), - m_Options.m_ColorMode == RENDER_COLOR_ALPHA); + m_Options.m_ColorMode == CPDF_RenderOptions::kAlpha); } void CPDF_RenderStatus::DrawTilingPattern(CPDF_TilingPattern* pPattern, @@ -2242,11 +2234,8 @@ void CPDF_RenderStatus::DrawTilingPattern(CPDF_TilingPattern* pPattern, if (height == 0) height = 1; - CFX_Matrix mtDevice2Pattern; - mtDevice2Pattern.SetReverse(mtPattern2Device); - CFX_FloatRect clip_box_p(clip_box); - mtDevice2Pattern.TransformRect(clip_box_p); + mtPattern2Device.GetInverse().TransformRect(clip_box_p); int min_col = (int)ceil((clip_box_p.left - pPattern->bbox().right) / pPattern->x_step()); @@ -2276,7 +2265,7 @@ void CPDF_RenderStatus::DrawTilingPattern(CPDF_TilingPattern* pPattern, original.y - mtPattern2Device.f); CFX_RenderDevice::StateRestorer restorer2(m_pDevice); CPDF_RenderStatus status; - status.Initialize(m_pContext, m_pDevice, nullptr, nullptr, this, + status.Initialize(m_pContext.Get(), m_pDevice, nullptr, nullptr, this, pStates.get(), &m_Options, pPattern->form()->m_Transparency, m_bDropObjects, pFormResource); @@ -2320,9 +2309,8 @@ void CPDF_RenderStatus::DrawTilingPattern(CPDF_TilingPattern* pPattern, if (!pPatternBitmap) return; - if (m_Options.m_ColorMode == RENDER_COLOR_GRAY) { - pPatternBitmap->ConvertColorScale(m_Options.m_ForeColor, - m_Options.m_BackColor); + if (m_Options.m_ColorMode == CPDF_RenderOptions::kGray) { + pPatternBitmap->ConvertColorScale(0, 0xffffff); } FX_ARGB fill_argb = GetFillArgb(pPageObj); int clip_width = clip_box.right - clip_box.left; @@ -2626,9 +2614,10 @@ CFX_RetainPtr<CFX_DIBitmap> CPDF_RenderStatus::LoadSMask( pFormResource = form.m_pFormDict->GetDictFor("Resources"); } CPDF_RenderOptions options; - options.m_ColorMode = bLuminosity ? RENDER_COLOR_NORMAL : RENDER_COLOR_ALPHA; + options.m_ColorMode = + bLuminosity ? CPDF_RenderOptions::kNormal : CPDF_RenderOptions::kAlpha; CPDF_RenderStatus status; - status.Initialize(m_pContext, &bitmap_device, nullptr, nullptr, nullptr, + status.Initialize(m_pContext.Get(), &bitmap_device, nullptr, nullptr, nullptr, nullptr, &options, 0, m_bDropObjects, pFormResource, true, nullptr, 0, color_space_family, bLuminosity); status.RenderObjectList(&form, &matrix); diff --git a/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_renderstatus.h b/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_renderstatus.h index ab5ddd9f0dc..47fbac8a7c8 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_renderstatus.h +++ b/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_renderstatus.h @@ -13,6 +13,7 @@ #include "core/fpdfapi/page/cpdf_clippath.h" #include "core/fpdfapi/page/cpdf_graphicstates.h" #include "core/fpdfapi/render/cpdf_renderoptions.h" +#include "core/fxcrt/cfx_unowned_ptr.h" #include "core/fxge/cfx_renderdevice.h" class CFX_PathData; @@ -61,15 +62,15 @@ class CPDF_RenderStatus { bool ContinueSingleObject(CPDF_PageObject* pObj, const CFX_Matrix* pObj2Device, IFX_Pause* pPause); - CPDF_RenderContext* GetContext() { return m_pContext; } + CPDF_RenderContext* GetContext() const { return m_pContext.Get(); } #if defined _SKIA_SUPPORT_ void DebugVerifyDeviceIsPreMultiplied() const; #endif CPDF_RenderOptions m_Options; - CPDF_Dictionary* m_pFormResource; - CPDF_Dictionary* m_pPageResource; + CFX_UnownedPtr<CPDF_Dictionary> m_pFormResource; + CFX_UnownedPtr<CPDF_Dictionary> m_pPageResource; std::vector<CPDF_Type3Font*> m_Type3FontCache; private: @@ -157,7 +158,7 @@ class CPDF_RenderStatus { static const int kRenderMaxRecursionDepth = 64; static int s_CurrentRecursionDepth; - CPDF_RenderContext* m_pContext; + CFX_UnownedPtr<CPDF_RenderContext> m_pContext; bool m_bStopped; CFX_RenderDevice* m_pDevice; CFX_Matrix m_DeviceMatrix; @@ -172,7 +173,7 @@ class CPDF_RenderStatus { bool m_bStdCS; uint32_t m_GroupFamily; bool m_bLoadMask; - CPDF_Type3Char* m_pType3Char; + CFX_UnownedPtr<CPDF_Type3Char> m_pType3Char; FX_ARGB m_T3FillColor; int m_curBlend; }; diff --git a/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_scaledrenderbuffer.cpp b/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_scaledrenderbuffer.cpp index 74d506c05c8..17e33af3b1d 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_scaledrenderbuffer.cpp +++ b/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_scaledrenderbuffer.cpp @@ -67,8 +67,8 @@ bool CPDF_ScaledRenderBuffer::Initialize(CPDF_RenderContext* pContext, } m_Matrix.Scale(0.5f, 0.5f); } - m_pContext->GetBackground(m_pBitmapDevice->GetBitmap(), m_pObject, pOptions, - &m_Matrix); + m_pContext->GetBackground(m_pBitmapDevice->GetBitmap(), m_pObject.Get(), + pOptions, &m_Matrix); return true; } diff --git a/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_scaledrenderbuffer.h b/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_scaledrenderbuffer.h index 92fabefbee4..47ab5ad39f4 100644 --- a/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_scaledrenderbuffer.h +++ b/chromium/third_party/pdfium/core/fpdfapi/render/cpdf_scaledrenderbuffer.h @@ -9,6 +9,7 @@ #include <memory> +#include "core/fxcrt/cfx_unowned_ptr.h" #include "core/fxcrt/fx_coordinates.h" #include "core/fxge/cfx_defaultrenderdevice.h" @@ -28,17 +29,18 @@ class CPDF_ScaledRenderBuffer { const CPDF_PageObject* pObj, const CPDF_RenderOptions* pOptions, int max_dpi); - CFX_RenderDevice* GetDevice() { - return m_pBitmapDevice ? m_pBitmapDevice.get() : m_pDevice; + + CFX_RenderDevice* GetDevice() const { + return m_pBitmapDevice ? m_pBitmapDevice.get() : m_pDevice.Get(); } CFX_Matrix* GetMatrix() { return &m_Matrix; } void OutputToDevice(); private: - CFX_RenderDevice* m_pDevice; - CPDF_RenderContext* m_pContext; + CFX_UnownedPtr<CFX_RenderDevice> m_pDevice; + CFX_UnownedPtr<CPDF_RenderContext> m_pContext; FX_RECT m_Rect; - const CPDF_PageObject* m_pObject; + CFX_UnownedPtr<const CPDF_PageObject> m_pObject; std::unique_ptr<CFX_DefaultRenderDevice> m_pBitmapDevice; CFX_Matrix m_Matrix; }; diff --git a/chromium/third_party/pdfium/core/fpdfdoc/cpdf_action.cpp b/chromium/third_party/pdfium/core/fpdfdoc/cpdf_action.cpp index b40fdcd2259..2357580548b 100644 --- a/chromium/third_party/pdfium/core/fpdfdoc/cpdf_action.cpp +++ b/chromium/third_party/pdfium/core/fpdfdoc/cpdf_action.cpp @@ -42,7 +42,7 @@ CPDF_Dest CPDF_Action::GetDest(CPDF_Document* pDoc) const { return CPDF_Dest(); if (pDest->IsString() || pDest->IsName()) { CPDF_NameTree name_tree(pDoc, "Dests"); - return CPDF_Dest(name_tree.LookupNamedDest(pDoc, pDest->GetString())); + return CPDF_Dest(name_tree.LookupNamedDest(pDoc, pDest->GetUnicodeText())); } if (CPDF_Array* pArray = pDest->AsArray()) return CPDF_Dest(pArray); @@ -73,21 +73,16 @@ CFX_WideString CPDF_Action::GetFilePath() const { } CPDF_Object* pFile = m_pDict->GetDirectObjectFor("F"); - CFX_WideString path; - if (!pFile) { - if (type == "Launch") { - CPDF_Dictionary* pWinDict = m_pDict->GetDictFor("Win"); - if (pWinDict) { - return CFX_WideString::FromLocal( - pWinDict->GetStringFor("F").AsStringC()); - } + if (pFile) + return CPDF_FileSpec(pFile).GetFileName(); + + if (type == "Launch") { + CPDF_Dictionary* pWinDict = m_pDict->GetDictFor("Win"); + if (pWinDict) { + return CFX_WideString::FromLocal(pWinDict->GetStringFor("F").AsStringC()); } - return path; } - - CPDF_FileSpec filespec(pFile); - filespec.GetFileName(&path); - return path; + return CFX_WideString(); } CFX_ByteString CPDF_Action::GetURI(CPDF_Document* pDoc) const { diff --git a/chromium/third_party/pdfium/core/fpdfdoc/cpdf_annot.cpp b/chromium/third_party/pdfium/core/fpdfdoc/cpdf_annot.cpp index eab6cd0145e..e43a7353b65 100644 --- a/chromium/third_party/pdfium/core/fpdfdoc/cpdf_annot.cpp +++ b/chromium/third_party/pdfium/core/fpdfdoc/cpdf_annot.cpp @@ -34,9 +34,10 @@ bool IsTextMarkupAnnotation(CPDF_Annot::Subtype type) { } bool ShouldGenerateAPForAnnotation(CPDF_Dictionary* pAnnotDict) { - // If AP dictionary exists, we use the appearance defined in the - // existing AP dictionary. - if (pAnnotDict->KeyExist("AP")) + // If AP dictionary exists and defines an appearance for normal mode, we use + // the appearance defined in the existing AP dictionary. + CPDF_Dictionary* pAP = pAnnotDict->GetDictFor("AP"); + if (pAP && pAP->GetDictFor("N")) return false; return !CPDF_Annot::IsAnnotationHidden(pAnnotDict); @@ -157,7 +158,7 @@ uint32_t CPDF_Annot::GetFlags() const { return m_pAnnotDict->GetIntegerFor("F"); } -CPDF_Stream* FPDFDOC_GetAnnotAP(CPDF_Dictionary* pAnnotDict, +CPDF_Stream* FPDFDOC_GetAnnotAP(const CPDF_Dictionary* pAnnotDict, CPDF_Annot::AppearanceMode mode) { CPDF_Dictionary* pAP = pAnnotDict->GetDictFor("AP"); if (!pAP) { diff --git a/chromium/third_party/pdfium/core/fpdfdoc/cpdf_annot.h b/chromium/third_party/pdfium/core/fpdfdoc/cpdf_annot.h index 85a205345e0..081cef7a356 100644 --- a/chromium/third_party/pdfium/core/fpdfdoc/cpdf_annot.h +++ b/chromium/third_party/pdfium/core/fpdfdoc/cpdf_annot.h @@ -124,7 +124,7 @@ class CPDF_Annot { CPDF_Annot* m_pPopupAnnot = nullptr; }; -CPDF_Stream* FPDFDOC_GetAnnotAP(CPDF_Dictionary* pAnnotDict, +CPDF_Stream* FPDFDOC_GetAnnotAP(const CPDF_Dictionary* pAnnotDict, CPDF_Annot::AppearanceMode mode); #endif // CORE_FPDFDOC_CPDF_ANNOT_H_ diff --git a/chromium/third_party/pdfium/core/fpdfdoc/cpdf_annotlist.cpp b/chromium/third_party/pdfium/core/fpdfdoc/cpdf_annotlist.cpp index 1427c856164..1f94779c15e 100644 --- a/chromium/third_party/pdfium/core/fpdfdoc/cpdf_annotlist.cpp +++ b/chromium/third_party/pdfium/core/fpdfdoc/cpdf_annotlist.cpp @@ -86,7 +86,7 @@ CPDF_AnnotList::CPDF_AnnotList(CPDF_Page* pPage) pAnnots->ConvertToIndirectObjectAt(i, m_pDocument); m_AnnotList.push_back(pdfium::MakeUnique<CPDF_Annot>(pDict, m_pDocument)); if (bRegenerateAP && subtype == "Widget" && - CPDF_InterForm::IsUpdateAPEnabled()) { + CPDF_InterForm::IsUpdateAPEnabled() && !pDict->GetDictFor("AP")) { FPDF_GenerateAP(m_pDocument, pDict); } } diff --git a/chromium/third_party/pdfium/core/fpdfdoc/cpdf_bookmark.cpp b/chromium/third_party/pdfium/core/fpdfdoc/cpdf_bookmark.cpp index 29303f1d325..e84001f8468 100644 --- a/chromium/third_party/pdfium/core/fpdfdoc/cpdf_bookmark.cpp +++ b/chromium/third_party/pdfium/core/fpdfdoc/cpdf_bookmark.cpp @@ -70,7 +70,8 @@ CPDF_Dest CPDF_Bookmark::GetDest(CPDF_Document* pDocument) const { return CPDF_Dest(); if (pDest->IsString() || pDest->IsName()) { CPDF_NameTree name_tree(pDocument, "Dests"); - return CPDF_Dest(name_tree.LookupNamedDest(pDocument, pDest->GetString())); + return CPDF_Dest( + name_tree.LookupNamedDest(pDocument, pDest->GetUnicodeText())); } if (CPDF_Array* pArray = pDest->AsArray()) return CPDF_Dest(pArray); diff --git a/chromium/third_party/pdfium/core/fpdfdoc/cpdf_docjsactions.cpp b/chromium/third_party/pdfium/core/fpdfdoc/cpdf_docjsactions.cpp index 59dbccce85f..669ed7055c8 100644 --- a/chromium/third_party/pdfium/core/fpdfdoc/cpdf_docjsactions.cpp +++ b/chromium/third_party/pdfium/core/fpdfdoc/cpdf_docjsactions.cpp @@ -20,7 +20,7 @@ int CPDF_DocJSActions::CountJSActions() const { CPDF_Action CPDF_DocJSActions::GetJSActionAndName( int index, - CFX_ByteString* csName) const { + CFX_WideString* csName) const { ASSERT(m_pDocument); CPDF_NameTree name_tree(m_pDocument.Get(), "JavaScript"); CPDF_Object* pAction = name_tree.LookupValueAndName(index, csName); @@ -28,7 +28,7 @@ CPDF_Action CPDF_DocJSActions::GetJSActionAndName( : CPDF_Action(); } -CPDF_Action CPDF_DocJSActions::GetJSAction(const CFX_ByteString& csName) const { +CPDF_Action CPDF_DocJSActions::GetJSAction(const CFX_WideString& csName) const { ASSERT(m_pDocument); CPDF_NameTree name_tree(m_pDocument.Get(), "JavaScript"); CPDF_Object* pAction = name_tree.LookupValue(csName); @@ -36,7 +36,7 @@ CPDF_Action CPDF_DocJSActions::GetJSAction(const CFX_ByteString& csName) const { : CPDF_Action(); } -int CPDF_DocJSActions::FindJSAction(const CFX_ByteString& csName) const { +int CPDF_DocJSActions::FindJSAction(const CFX_WideString& csName) const { ASSERT(m_pDocument); CPDF_NameTree name_tree(m_pDocument.Get(), "JavaScript"); return name_tree.GetIndex(csName); diff --git a/chromium/third_party/pdfium/core/fpdfdoc/cpdf_docjsactions.h b/chromium/third_party/pdfium/core/fpdfdoc/cpdf_docjsactions.h index 328b8869f61..73c0a1ef1c8 100644 --- a/chromium/third_party/pdfium/core/fpdfdoc/cpdf_docjsactions.h +++ b/chromium/third_party/pdfium/core/fpdfdoc/cpdf_docjsactions.h @@ -19,9 +19,9 @@ class CPDF_DocJSActions { ~CPDF_DocJSActions(); int CountJSActions() const; - CPDF_Action GetJSActionAndName(int index, CFX_ByteString* csName) const; - CPDF_Action GetJSAction(const CFX_ByteString& csName) const; - int FindJSAction(const CFX_ByteString& csName) const; + CPDF_Action GetJSActionAndName(int index, CFX_WideString* csName) const; + CPDF_Action GetJSAction(const CFX_WideString& csName) const; + int FindJSAction(const CFX_WideString& csName) const; CPDF_Document* GetDocument() const { return m_pDocument.Get(); } private: diff --git a/chromium/third_party/pdfium/core/fpdfdoc/cpdf_filespec.cpp b/chromium/third_party/pdfium/core/fpdfdoc/cpdf_filespec.cpp index 59915eaa057..5ef6f466c56 100644 --- a/chromium/third_party/pdfium/core/fpdfdoc/cpdf_filespec.cpp +++ b/chromium/third_party/pdfium/core/fpdfdoc/cpdf_filespec.cpp @@ -6,9 +6,12 @@ #include "core/fpdfdoc/cpdf_filespec.h" +#include <vector> + #include "core/fpdfapi/parser/cpdf_dictionary.h" #include "core/fpdfapi/parser/cpdf_name.h" #include "core/fpdfapi/parser/cpdf_object.h" +#include "core/fpdfapi/parser/cpdf_stream.h" #include "core/fpdfapi/parser/cpdf_string.h" #include "core/fpdfapi/parser/fpdf_parser_decode.h" #include "core/fxcrt/fx_system.h" @@ -50,6 +53,12 @@ CFX_WideString ChangeSlashToPDF(const wchar_t* str) { } // namespace +CPDF_FileSpec::CPDF_FileSpec(CPDF_Object* pObj) : m_pObj(pObj) { + ASSERT(m_pObj); +} + +CPDF_FileSpec::~CPDF_FileSpec() {} + CFX_WideString CPDF_FileSpec::DecodeFileName(const CFX_WideString& filepath) { if (filepath.GetLength() <= 1) return CFX_WideString(); @@ -80,41 +89,69 @@ CFX_WideString CPDF_FileSpec::DecodeFileName(const CFX_WideString& filepath) { #endif } -bool CPDF_FileSpec::GetFileName(CFX_WideString* csFileName) const { +CFX_WideString CPDF_FileSpec::GetFileName() const { + CFX_WideString csFileName; if (CPDF_Dictionary* pDict = m_pObj->AsDictionary()) { - *csFileName = pDict->GetUnicodeTextFor("UF"); - if (csFileName->IsEmpty()) { - *csFileName = + csFileName = pDict->GetUnicodeTextFor("UF"); + if (csFileName.IsEmpty()) { + csFileName = CFX_WideString::FromLocal(pDict->GetStringFor("F").AsStringC()); } if (pDict->GetStringFor("FS") == "URL") - return true; - if (csFileName->IsEmpty()) { - if (pDict->KeyExist("DOS")) { - *csFileName = - CFX_WideString::FromLocal(pDict->GetStringFor("DOS").AsStringC()); - } else if (pDict->KeyExist("Mac")) { - *csFileName = - CFX_WideString::FromLocal(pDict->GetStringFor("Mac").AsStringC()); - } else if (pDict->KeyExist("Unix")) { - *csFileName = - CFX_WideString::FromLocal(pDict->GetStringFor("Unix").AsStringC()); - } else { - return false; + return csFileName; + + if (csFileName.IsEmpty()) { + constexpr const char* keys[] = {"DOS", "Mac", "Unix"}; + for (const auto* key : keys) { + if (pDict->KeyExist(key)) { + csFileName = + CFX_WideString::FromLocal(pDict->GetStringFor(key).AsStringC()); + break; + } } } } else if (m_pObj->IsString()) { - *csFileName = CFX_WideString::FromLocal(m_pObj->GetString().AsStringC()); - } else { - return false; + csFileName = CFX_WideString::FromLocal(m_pObj->GetString().AsStringC()); } - *csFileName = DecodeFileName(*csFileName); - return true; + return DecodeFileName(csFileName); } -CPDF_FileSpec::CPDF_FileSpec(CPDF_Object* pObj) : m_pObj(pObj) {} +CPDF_Stream* CPDF_FileSpec::GetFileStream() const { + CPDF_Dictionary* pDict = m_pObj->AsDictionary(); + if (!pDict) + return nullptr; + + // Get the embedded files dictionary. + CPDF_Dictionary* pFiles = pDict->GetDictFor("EF"); + if (!pFiles) + return nullptr; + + // Get the file stream of the highest precedence with its file specification + // string available. Follows the same precedence order as GetFileName(). + constexpr const char* keys[] = {"UF", "F", "DOS", "Mac", "Unix"}; + size_t end = pDict->GetStringFor("FS") == "URL" ? 2 : FX_ArraySize(keys); + for (size_t i = 0; i < end; ++i) { + const CFX_ByteString& key = keys[i]; + if (!pDict->GetUnicodeTextFor(key).IsEmpty()) { + CPDF_Stream* pStream = pFiles->GetStreamFor(key); + if (pStream) + return pStream; + } + } + return nullptr; +} -CPDF_FileSpec::~CPDF_FileSpec() {} +CPDF_Dictionary* CPDF_FileSpec::GetParamsDict() const { + CPDF_Stream* pStream = GetFileStream(); + if (!pStream) + return nullptr; + + CPDF_Dictionary* pDict = pStream->GetDict(); + if (!pDict) + return nullptr; + + return pDict->GetDictFor("Params"); +} CFX_WideString CPDF_FileSpec::EncodeFileName(const CFX_WideString& filepath) { if (filepath.GetLength() <= 1) @@ -146,9 +183,6 @@ CFX_WideString CPDF_FileSpec::EncodeFileName(const CFX_WideString& filepath) { } void CPDF_FileSpec::SetFileName(const CFX_WideString& wsFileName) { - if (!m_pObj) - return; - CFX_WideString wsStr = EncodeFileName(wsFileName); if (m_pObj->IsString()) { m_pObj->SetString(CFX_ByteString::FromUnicode(wsStr)); diff --git a/chromium/third_party/pdfium/core/fpdfdoc/cpdf_filespec.h b/chromium/third_party/pdfium/core/fpdfdoc/cpdf_filespec.h index 04baf2e63f9..8640b2e4c67 100644 --- a/chromium/third_party/pdfium/core/fpdfdoc/cpdf_filespec.h +++ b/chromium/third_party/pdfium/core/fpdfdoc/cpdf_filespec.h @@ -12,7 +12,9 @@ #include "core/fxcrt/cfx_weak_ptr.h" #include "core/fxcrt/fx_string.h" +class CPDF_Dictionary; class CPDF_Object; +class CPDF_Stream; class CPDF_FileSpec { public: @@ -26,7 +28,9 @@ class CPDF_FileSpec { static CFX_WideString DecodeFileName(const CFX_WideString& filepath); CPDF_Object* GetObj() const { return m_pObj.Get(); } - bool GetFileName(CFX_WideString* wsFileName) const; + CFX_WideString GetFileName() const; + CPDF_Stream* GetFileStream() const; + CPDF_Dictionary* GetParamsDict() const; // Set this file spec to refer to a file name (not a url). void SetFileName(const CFX_WideString& wsFileName); diff --git a/chromium/third_party/pdfium/core/fpdfdoc/cpdf_filespec_unittest.cpp b/chromium/third_party/pdfium/core/fpdfdoc/cpdf_filespec_unittest.cpp index e237aa5b6bb..8d151c9dd80 100644 --- a/chromium/third_party/pdfium/core/fpdfdoc/cpdf_filespec_unittest.cpp +++ b/chromium/third_party/pdfium/core/fpdfdoc/cpdf_filespec_unittest.cpp @@ -3,10 +3,13 @@ // found in the LICENSE file. #include <memory> +#include <utility> #include <vector> #include "core/fpdfapi/parser/cpdf_dictionary.h" #include "core/fpdfapi/parser/cpdf_name.h" +#include "core/fpdfapi/parser/cpdf_number.h" +#include "core/fpdfapi/parser/cpdf_stream.h" #include "core/fpdfapi/parser/cpdf_string.h" #include "core/fpdfdoc/cpdf_filespec.h" #include "testing/gtest/include/gtest/gtest.h" @@ -45,11 +48,11 @@ TEST(cpdf_filespec, EncodeDecodeFileName) { #endif }; for (const auto& data : test_data) { - CFX_WideString encoded_str = CPDF_FileSpec::EncodeFileName(data.input); - EXPECT_TRUE(encoded_str == data.expected); + EXPECT_STREQ(data.expected, + CPDF_FileSpec::EncodeFileName(data.input).c_str()); // DecodeFileName is the reverse procedure of EncodeFileName. - CFX_WideString decoded_str = CPDF_FileSpec::DecodeFileName(data.expected); - EXPECT_TRUE(decoded_str == data.input); + EXPECT_STREQ(data.input, + CPDF_FileSpec::DecodeFileName(data.expected).c_str()); } } @@ -70,9 +73,7 @@ TEST(cpdf_filespec, GetFileName) { }; auto str_obj = pdfium::MakeUnique<CPDF_String>(nullptr, test_data.input); CPDF_FileSpec file_spec(str_obj.get()); - CFX_WideString file_name; - EXPECT_TRUE(file_spec.GetFileName(&file_name)); - EXPECT_TRUE(file_name == test_data.expected); + EXPECT_STREQ(test_data.expected, file_spec.GetFileName().c_str()); } { // Dictionary object. @@ -101,25 +102,22 @@ TEST(cpdf_filespec, GetFileName) { const char* const keywords[5] = {"Unix", "Mac", "DOS", "F", "UF"}; auto dict_obj = pdfium::MakeUnique<CPDF_Dictionary>(); CPDF_FileSpec file_spec(dict_obj.get()); - CFX_WideString file_name; + EXPECT_TRUE(file_spec.GetFileName().IsEmpty()); for (int i = 0; i < 5; ++i) { dict_obj->SetNewFor<CPDF_String>(keywords[i], test_data[i].input); - EXPECT_TRUE(file_spec.GetFileName(&file_name)); - EXPECT_TRUE(file_name == test_data[i].expected); + EXPECT_STREQ(test_data[i].expected, file_spec.GetFileName().c_str()); } // With all the former fields and 'FS' field suggests 'URL' type. dict_obj->SetNewFor<CPDF_String>("FS", "URL", false); - EXPECT_TRUE(file_spec.GetFileName(&file_name)); // Url string is not decoded. - EXPECT_TRUE(file_name == test_data[4].input); + EXPECT_STREQ(test_data[4].input, file_spec.GetFileName().c_str()); } { // Invalid object. auto name_obj = pdfium::MakeUnique<CPDF_Name>(nullptr, "test.pdf"); CPDF_FileSpec file_spec(name_obj.get()); - CFX_WideString file_name; - EXPECT_FALSE(file_spec.GetFileName(&file_name)); + EXPECT_TRUE(file_spec.GetFileName().IsEmpty()); } } @@ -141,23 +139,112 @@ TEST(cpdf_filespec, SetFileName) { CPDF_FileSpec file_spec1(str_obj.get()); file_spec1.SetFileName(test_data.input); // Check internal object value. - CFX_ByteString str = CFX_ByteString::FromUnicode(test_data.expected); - EXPECT_TRUE(str == str_obj->GetString()); + EXPECT_STREQ(test_data.expected, str_obj->GetUnicodeText().c_str()); // Check we can get the file name back. - CFX_WideString file_name; - EXPECT_TRUE(file_spec1.GetFileName(&file_name)); - EXPECT_TRUE(file_name == test_data.input); + EXPECT_STREQ(test_data.input, file_spec1.GetFileName().c_str()); // Dictionary object. auto dict_obj = pdfium::MakeUnique<CPDF_Dictionary>(); CPDF_FileSpec file_spec2(dict_obj.get()); file_spec2.SetFileName(test_data.input); // Check internal object value. - file_name = dict_obj->GetUnicodeTextFor("F"); - EXPECT_TRUE(file_name == test_data.expected); - file_name = dict_obj->GetUnicodeTextFor("UF"); - EXPECT_TRUE(file_name == test_data.expected); + EXPECT_STREQ(test_data.expected, dict_obj->GetUnicodeTextFor("F").c_str()); + EXPECT_STREQ(test_data.expected, dict_obj->GetUnicodeTextFor("UF").c_str()); // Check we can get the file name back. - EXPECT_TRUE(file_spec2.GetFileName(&file_name)); - EXPECT_TRUE(file_name == test_data.input); + EXPECT_STREQ(test_data.input, file_spec2.GetFileName().c_str()); +} + +TEST(cpdf_filespec, GetFileStream) { + { + // Invalid object. + auto name_obj = pdfium::MakeUnique<CPDF_Name>(nullptr, "test.pdf"); + CPDF_FileSpec file_spec(name_obj.get()); + EXPECT_FALSE(file_spec.GetFileStream()); + } + { + // Dictionary object missing its embedded files dictionary. + auto dict_obj = pdfium::MakeUnique<CPDF_Dictionary>(); + CPDF_FileSpec file_spec(dict_obj.get()); + EXPECT_FALSE(file_spec.GetFileStream()); + } + { + // Dictionary object with an empty embedded files dictionary. + auto dict_obj = pdfium::MakeUnique<CPDF_Dictionary>(); + dict_obj->SetNewFor<CPDF_Dictionary>("EF"); + CPDF_FileSpec file_spec(dict_obj.get()); + EXPECT_FALSE(file_spec.GetFileStream()); + } + { + // Dictionary object with a non-empty embedded files dictionary. + auto dict_obj = pdfium::MakeUnique<CPDF_Dictionary>(); + dict_obj->SetNewFor<CPDF_Dictionary>("EF"); + CPDF_FileSpec file_spec(dict_obj.get()); + + const char* const keys[5] = {"Unix", "Mac", "DOS", "F", "UF"}; + const wchar_t file_name[] = L"test.pdf"; + const char* const stream[5] = {"test1", "test2", "test3", "test4", "test5"}; + CPDF_Dictionary* file_dict = + file_spec.GetObj()->AsDictionary()->GetDictFor("EF"); + + // Keys in reverse order of precedence to retrieve the file content stream. + for (size_t i = 0; i < FX_ArraySize(keys); ++i) { + // Set the file name. + dict_obj->SetNewFor<CPDF_String>(keys[i], file_name); + + // Set the file stream. + auto pDict = pdfium::MakeUnique<CPDF_Dictionary>(); + size_t buf_len = strlen(stream[i]) + 1; + std::unique_ptr<uint8_t, FxFreeDeleter> buf(FX_Alloc(uint8_t, buf_len)); + memcpy(buf.get(), stream[i], buf_len); + file_dict->SetNewFor<CPDF_Stream>(keys[i], std::move(buf), buf_len, + std::move(pDict)); + + // Check that the file content stream is as expected. + EXPECT_STREQ( + stream[i], + file_spec.GetFileStream()->GetUnicodeText().UTF8Encode().c_str()); + + if (i == 2) { + dict_obj->SetNewFor<CPDF_String>("FS", "URL", false); + EXPECT_FALSE(file_spec.GetFileStream()); + } + } + } +} + +TEST(cpdf_filespec, GetParamsDict) { + { + // Invalid object. + auto name_obj = pdfium::MakeUnique<CPDF_Name>(nullptr, "test.pdf"); + CPDF_FileSpec file_spec(name_obj.get()); + EXPECT_FALSE(file_spec.GetParamsDict()); + } + { + // Dictionary object. + auto dict_obj = pdfium::MakeUnique<CPDF_Dictionary>(); + dict_obj->SetNewFor<CPDF_Dictionary>("EF"); + dict_obj->SetNewFor<CPDF_String>("UF", L"test.pdf"); + CPDF_FileSpec file_spec(dict_obj.get()); + EXPECT_FALSE(file_spec.GetParamsDict()); + + // Add a file stream to the embedded files dictionary. + CPDF_Dictionary* file_dict = + file_spec.GetObj()->AsDictionary()->GetDictFor("EF"); + auto pDict = pdfium::MakeUnique<CPDF_Dictionary>(); + std::unique_ptr<uint8_t, FxFreeDeleter> buf(FX_Alloc(uint8_t, 6)); + memcpy(buf.get(), "hello", 6); + file_dict->SetNewFor<CPDF_Stream>("UF", std::move(buf), 6, + std::move(pDict)); + + // Add a params dictionary to the file stream. + CPDF_Stream* stream = file_dict->GetStreamFor("UF"); + CPDF_Dictionary* stream_dict = stream->GetDict(); + stream_dict->SetNewFor<CPDF_Dictionary>("Params"); + EXPECT_TRUE(file_spec.GetParamsDict()); + + // Add a parameter to the params dictionary. + CPDF_Dictionary* params_dict = stream_dict->GetDictFor("Params"); + params_dict->SetNewFor<CPDF_Number>("Size", 6); + EXPECT_EQ(6, file_spec.GetParamsDict()->GetIntegerFor("Size")); + } } diff --git a/chromium/third_party/pdfium/core/fpdfdoc/cpdf_formfield.cpp b/chromium/third_party/pdfium/core/fpdfdoc/cpdf_formfield.cpp index 97ea0524363..acb46a5beb4 100644 --- a/chromium/third_party/pdfium/core/fpdfdoc/cpdf_formfield.cpp +++ b/chromium/third_party/pdfium/core/fpdfdoc/cpdf_formfield.cpp @@ -662,8 +662,7 @@ int CPDF_FormField::InsertOption(CFX_WideString csOptLabel, if (bNotify && !NotifyListOrComboBoxBeforeChange(csOptLabel)) return -1; - CFX_ByteString csStr = - PDF_EncodeText(csOptLabel.c_str(), csOptLabel.GetLength()); + CFX_ByteString csStr = PDF_EncodeText(csOptLabel); CPDF_Array* pOpt = ToArray(FPDF_GetFieldAttr(m_pDict.Get(), "Opt")); if (!pOpt) pOpt = m_pDict->SetNewFor<CPDF_Array>("Opt"); @@ -899,7 +898,7 @@ bool CPDF_FormField::ClearSelectedOptions(bool bNotify) { } void CPDF_FormField::LoadDA() { - CPDF_Dictionary* pFormDict = m_pForm->m_pFormDict; + CPDF_Dictionary* pFormDict = m_pForm->m_pFormDict.Get(); if (!pFormDict) return; diff --git a/chromium/third_party/pdfium/core/fpdfdoc/cpdf_formfield.h b/chromium/third_party/pdfium/core/fpdfdoc/cpdf_formfield.h index f2038e41bdc..f5c4c6964bc 100644 --- a/chromium/third_party/pdfium/core/fpdfdoc/cpdf_formfield.h +++ b/chromium/third_party/pdfium/core/fpdfdoc/cpdf_formfield.h @@ -134,7 +134,7 @@ class CPDF_FormField { #endif // PDF_ENABLE_XFA float GetFontSize() const { return m_FontSize; } - CPDF_Font* GetFont() const { return m_pFont; } + CPDF_Font* GetFont() const { return m_pFont.Get(); } const CPDF_Dictionary* GetDict() const { return m_pDict.Get(); } const CPDF_InterForm* GetForm() const { return m_pForm.Get(); } @@ -176,7 +176,7 @@ class CPDF_FormField { // Owned by InterForm parent. std::vector<CFX_UnownedPtr<CPDF_FormControl>> m_ControlList; float m_FontSize; - CPDF_Font* m_pFont; + CFX_UnownedPtr<CPDF_Font> m_pFont; }; #endif // CORE_FPDFDOC_CPDF_FORMFIELD_H_ diff --git a/chromium/third_party/pdfium/core/fpdfdoc/cpdf_interform.cpp b/chromium/third_party/pdfium/core/fpdfdoc/cpdf_interform.cpp index de99a5de0fe..9c3730ad705 100644 --- a/chromium/third_party/pdfium/core/fpdfdoc/cpdf_interform.cpp +++ b/chromium/third_party/pdfium/core/fpdfdoc/cpdf_interform.cpp @@ -961,7 +961,7 @@ int CPDF_InterForm::FindFieldInCalculationOrder(const CPDF_FormField* pField) { } CPDF_Font* CPDF_InterForm::GetFormFont(CFX_ByteString csNameTag) const { - return GetFont(m_pFormDict, m_pDocument.Get(), csNameTag); + return GetFont(m_pFormDict.Get(), m_pDocument.Get(), csNameTag); } CPDF_DefaultAppearance CPDF_InterForm::GetDefaultAppearance() const { diff --git a/chromium/third_party/pdfium/core/fpdfdoc/cpdf_interform.h b/chromium/third_party/pdfium/core/fpdfdoc/cpdf_interform.h index 0a9b3e0e4aa..9dc0532939c 100644 --- a/chromium/third_party/pdfium/core/fpdfdoc/cpdf_interform.h +++ b/chromium/third_party/pdfium/core/fpdfdoc/cpdf_interform.h @@ -13,6 +13,7 @@ #include "core/fpdfapi/parser/fpdf_parser_decode.h" #include "core/fpdfdoc/cpdf_defaultappearance.h" +#include "core/fxcrt/cfx_unowned_ptr.h" #include "core/fxcrt/fx_string.h" #include "core/fxcrt/fx_system.h" @@ -109,12 +110,12 @@ class CPDF_InterForm { static bool s_bUpdateAP; CFX_UnownedPtr<CPDF_Document> const m_pDocument; - CPDF_Dictionary* m_pFormDict; + CFX_UnownedPtr<CPDF_Dictionary> m_pFormDict; std::map<const CPDF_Dictionary*, std::unique_ptr<CPDF_FormControl>> m_ControlMap; std::unique_ptr<CFieldTree> m_pFieldTree; CFX_ByteString m_bsEncoding; - IPDF_FormNotify* m_pFormNotify; + CFX_UnownedPtr<IPDF_FormNotify> m_pFormNotify; }; #endif // CORE_FPDFDOC_CPDF_INTERFORM_H_ diff --git a/chromium/third_party/pdfium/core/fpdfdoc/cpdf_link.cpp b/chromium/third_party/pdfium/core/fpdfdoc/cpdf_link.cpp index 20ec486df28..f7aec4087e8 100644 --- a/chromium/third_party/pdfium/core/fpdfdoc/cpdf_link.cpp +++ b/chromium/third_party/pdfium/core/fpdfdoc/cpdf_link.cpp @@ -9,6 +9,14 @@ #include "core/fpdfapi/parser/cpdf_array.h" #include "core/fpdfdoc/cpdf_nametree.h" +CPDF_Link::CPDF_Link() {} + +CPDF_Link::CPDF_Link(CPDF_Dictionary* pDict) : m_pDict(pDict) {} + +CPDF_Link::CPDF_Link(const CPDF_Link& that) = default; + +CPDF_Link::~CPDF_Link() {} + CFX_FloatRect CPDF_Link::GetRect() { return m_pDict->GetRectFor("Rect"); } @@ -20,7 +28,7 @@ CPDF_Dest CPDF_Link::GetDest(CPDF_Document* pDoc) { if (pDest->IsString() || pDest->IsName()) { CPDF_NameTree name_tree(pDoc, "Dests"); - return CPDF_Dest(name_tree.LookupNamedDest(pDoc, pDest->GetString())); + return CPDF_Dest(name_tree.LookupNamedDest(pDoc, pDest->GetUnicodeText())); } if (CPDF_Array* pArray = pDest->AsArray()) return CPDF_Dest(pArray); diff --git a/chromium/third_party/pdfium/core/fpdfdoc/cpdf_link.h b/chromium/third_party/pdfium/core/fpdfdoc/cpdf_link.h index 162630d6ac2..82f50fe0047 100644 --- a/chromium/third_party/pdfium/core/fpdfdoc/cpdf_link.h +++ b/chromium/third_party/pdfium/core/fpdfdoc/cpdf_link.h @@ -9,23 +9,25 @@ #include "core/fpdfdoc/cpdf_action.h" #include "core/fpdfdoc/cpdf_dest.h" +#include "core/fxcrt/cfx_unowned_ptr.h" #include "core/fxcrt/fx_coordinates.h" class CPDF_Dictionary; class CPDF_Link { public: - CPDF_Link() : m_pDict(nullptr) {} - explicit CPDF_Link(CPDF_Dictionary* pDict) : m_pDict(pDict) {} - - CPDF_Dictionary* GetDict() const { return m_pDict; } + CPDF_Link(); + explicit CPDF_Link(CPDF_Dictionary* pDict); + CPDF_Link(const CPDF_Link& that); + ~CPDF_Link(); + CPDF_Dictionary* GetDict() const { return m_pDict.Get(); } CFX_FloatRect GetRect(); CPDF_Dest GetDest(CPDF_Document* pDoc); CPDF_Action GetAction(); private: - CPDF_Dictionary* m_pDict; + CFX_UnownedPtr<CPDF_Dictionary> m_pDict; }; #endif // CORE_FPDFDOC_CPDF_LINK_H_ diff --git a/chromium/third_party/pdfium/core/fpdfdoc/cpdf_nametree.cpp b/chromium/third_party/pdfium/core/fpdfdoc/cpdf_nametree.cpp index b3808bddba7..04cb1b9e406 100644 --- a/chromium/third_party/pdfium/core/fpdfdoc/cpdf_nametree.cpp +++ b/chromium/third_party/pdfium/core/fpdfdoc/cpdf_nametree.cpp @@ -9,13 +9,14 @@ #include "core/fpdfapi/parser/cpdf_array.h" #include "core/fpdfapi/parser/cpdf_dictionary.h" #include "core/fpdfapi/parser/cpdf_document.h" +#include "core/fpdfapi/parser/fpdf_parser_decode.h" namespace { const int nMaxRecursion = 32; CPDF_Object* SearchNameNode(CPDF_Dictionary* pNode, - const CFX_ByteString& csName, + const CFX_WideString& csName, size_t& nIndex, CPDF_Array** ppFind, int nLevel = 0) { @@ -24,15 +25,14 @@ CPDF_Object* SearchNameNode(CPDF_Dictionary* pNode, CPDF_Array* pLimits = pNode->GetArrayFor("Limits"); if (pLimits) { - CFX_ByteString csLeft = pLimits->GetStringAt(0); - CFX_ByteString csRight = pLimits->GetStringAt(1); - if (csLeft.Compare(csRight.AsStringC()) > 0) { - CFX_ByteString csTmp = csRight; + CFX_WideString csLeft = pLimits->GetUnicodeTextAt(0); + CFX_WideString csRight = pLimits->GetUnicodeTextAt(1); + if (csLeft.Compare(csRight) > 0) { + CFX_WideString csTmp = csRight; csRight = csLeft; csLeft = csTmp; } - if (csName.Compare(csLeft.AsStringC()) < 0 || - csName.Compare(csRight.AsStringC()) > 0) { + if (csName.Compare(csLeft) < 0 || csName.Compare(csRight) > 0) { return nullptr; } } @@ -41,8 +41,8 @@ CPDF_Object* SearchNameNode(CPDF_Dictionary* pNode, if (pNames) { size_t dwCount = pNames->GetCount() / 2; for (size_t i = 0; i < dwCount; i++) { - CFX_ByteString csValue = pNames->GetStringAt(i * 2); - int32_t iCompare = csValue.Compare(csName.AsStringC()); + CFX_WideString csValue = pNames->GetUnicodeTextAt(i * 2); + int32_t iCompare = csValue.Compare(csName); if (iCompare <= 0) { if (ppFind) *ppFind = pNames; @@ -78,7 +78,7 @@ CPDF_Object* SearchNameNode(CPDF_Dictionary* pNode, CPDF_Object* SearchNameNode(CPDF_Dictionary* pNode, size_t nIndex, size_t& nCurIndex, - CFX_ByteString* csName, + CFX_WideString* csName, CPDF_Array** ppFind, int nLevel = 0) { if (nLevel > nMaxRecursion) @@ -93,7 +93,7 @@ CPDF_Object* SearchNameNode(CPDF_Dictionary* pNode, } if (ppFind) *ppFind = pNames; - *csName = pNames->GetStringAt((nIndex - nCurIndex) * 2); + *csName = pNames->GetUnicodeTextAt((nIndex - nCurIndex) * 2); return pNames->GetDirectObjectAt((nIndex - nCurIndex) * 2 + 1); } CPDF_Array* pKids = pNode->GetArrayFor("Kids"); @@ -158,7 +158,7 @@ size_t CPDF_NameTree::GetCount() const { return m_pRoot ? ::CountNames(m_pRoot.Get()) : 0; } -int CPDF_NameTree::GetIndex(const CFX_ByteString& csName) const { +int CPDF_NameTree::GetIndex(const CFX_WideString& csName) const { if (!m_pRoot) return -1; @@ -169,8 +169,8 @@ int CPDF_NameTree::GetIndex(const CFX_ByteString& csName) const { } CPDF_Object* CPDF_NameTree::LookupValueAndName(int nIndex, - CFX_ByteString* csName) const { - *csName = CFX_ByteString(); + CFX_WideString* csName) const { + *csName = CFX_WideString(); if (!m_pRoot) return nullptr; @@ -178,7 +178,7 @@ CPDF_Object* CPDF_NameTree::LookupValueAndName(int nIndex, return SearchNameNode(m_pRoot.Get(), nIndex, nCurIndex, csName, nullptr); } -CPDF_Object* CPDF_NameTree::LookupValue(const CFX_ByteString& csName) const { +CPDF_Object* CPDF_NameTree::LookupValue(const CFX_WideString& csName) const { if (!m_pRoot) return nullptr; @@ -187,13 +187,13 @@ CPDF_Object* CPDF_NameTree::LookupValue(const CFX_ByteString& csName) const { } CPDF_Array* CPDF_NameTree::LookupNamedDest(CPDF_Document* pDoc, - const CFX_ByteString& sName) { + const CFX_WideString& sName) { CPDF_Object* pValue = LookupValue(sName); if (!pValue) { CPDF_Dictionary* pDests = pDoc->GetRoot()->GetDictFor("Dests"); if (!pDests) return nullptr; - pValue = pDests->GetDirectObjectFor(sName); + pValue = pDests->GetDirectObjectFor(PDF_EncodeText(sName)); } if (!pValue) return nullptr; diff --git a/chromium/third_party/pdfium/core/fpdfdoc/cpdf_nametree.h b/chromium/third_party/pdfium/core/fpdfdoc/cpdf_nametree.h index 69000f32b22..a56f511783e 100644 --- a/chromium/third_party/pdfium/core/fpdfdoc/cpdf_nametree.h +++ b/chromium/third_party/pdfium/core/fpdfdoc/cpdf_nametree.h @@ -21,11 +21,11 @@ class CPDF_NameTree { CPDF_NameTree(CPDF_Document* pDoc, const CFX_ByteString& category); ~CPDF_NameTree(); - CPDF_Object* LookupValueAndName(int nIndex, CFX_ByteString* csName) const; - CPDF_Object* LookupValue(const CFX_ByteString& csName) const; - CPDF_Array* LookupNamedDest(CPDF_Document* pDoc, const CFX_ByteString& sName); + CPDF_Object* LookupValueAndName(int nIndex, CFX_WideString* csName) const; + CPDF_Object* LookupValue(const CFX_WideString& csName) const; + CPDF_Array* LookupNamedDest(CPDF_Document* pDoc, const CFX_WideString& sName); - int GetIndex(const CFX_ByteString& csName) const; + int GetIndex(const CFX_WideString& csName) const; size_t GetCount() const; CPDF_Dictionary* GetRoot() const { return m_pRoot.Get(); } diff --git a/chromium/third_party/pdfium/core/fpdfdoc/cpdf_nametree_unittest.cpp b/chromium/third_party/pdfium/core/fpdfdoc/cpdf_nametree_unittest.cpp new file mode 100644 index 00000000000..28af9e078df --- /dev/null +++ b/chromium/third_party/pdfium/core/fpdfdoc/cpdf_nametree_unittest.cpp @@ -0,0 +1,35 @@ +// Copyright 2017 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. + +#include "core/fpdfdoc/cpdf_nametree.h" +#include "core/fpdfapi/parser/cpdf_array.h" +#include "core/fpdfapi/parser/cpdf_dictionary.h" +#include "core/fpdfapi/parser/cpdf_number.h" +#include "core/fpdfapi/parser/cpdf_string.h" +#include "testing/gtest/include/gtest/gtest.h" + +TEST(cpdf_nametree, GetUnicodeNameWithBOM) { + // Set up the root dictionary with a Names array. + auto pRootDict = pdfium::MakeUnique<CPDF_Dictionary>(); + CPDF_Array* pNames = pRootDict->SetNewFor<CPDF_Array>("Names"); + + // Add the key "1" (with BOM) and value 100 into the array. + std::ostringstream buf; + buf << static_cast<unsigned char>(254) << static_cast<unsigned char>(255) + << static_cast<unsigned char>(0) << static_cast<unsigned char>(49); + pNames->AddNew<CPDF_String>(CFX_ByteString(buf), true); + pNames->AddNew<CPDF_Number>(100); + + // Check that the key is as expected. + CPDF_NameTree nameTree(pRootDict.get()); + CFX_WideString storedName; + nameTree.LookupValueAndName(0, &storedName); + EXPECT_STREQ(L"1", storedName.c_str()); + + // Check that the correct value object can be obtained by looking up "1". + CFX_WideString matchName = L"1"; + CPDF_Object* pObj = nameTree.LookupValue(matchName); + ASSERT_TRUE(pObj->IsNumber()); + EXPECT_EQ(100, pObj->AsNumber()->GetInteger()); +} diff --git a/chromium/third_party/pdfium/core/fpdfdoc/cpdf_occontext.cpp b/chromium/third_party/pdfium/core/fpdfdoc/cpdf_occontext.cpp index 66950c94067..7e746e0028d 100644 --- a/chromium/third_party/pdfium/core/fpdfdoc/cpdf_occontext.cpp +++ b/chromium/third_party/pdfium/core/fpdfdoc/cpdf_occontext.cpp @@ -254,18 +254,25 @@ bool CPDF_OCContext::LoadOCMDState(const CPDF_Dictionary* pOCMDDict) { return true; bool bState = (csP == "AllOn" || csP == "AllOff"); + // At least one entry of OCGs needs to be a valid dictionary for it to be + // considered present. See "OCGs" in table 4.49 in the PDF 1.7 spec. + bool bValidEntrySeen = false; for (size_t i = 0; i < pArray->GetCount(); i++) { bool bItem = true; CPDF_Dictionary* pItemDict = pArray->GetDictAt(i); - if (pItemDict) - bItem = GetOCGVisible(pItemDict); + if (!pItemDict) + continue; + + bValidEntrySeen = true; + bItem = GetOCGVisible(pItemDict); if ((csP == "AnyOn" && bItem) || (csP == "AnyOff" && !bItem)) return true; if ((csP == "AllOn" && !bItem) || (csP == "AllOff" && bItem)) return false; } - return bState; + + return !bValidEntrySeen || bState; } bool CPDF_OCContext::CheckOCGVisible(const CPDF_Dictionary* pOCGDict) { diff --git a/chromium/third_party/pdfium/core/fpdfdoc/cpdf_pagelabel.cpp b/chromium/third_party/pdfium/core/fpdfdoc/cpdf_pagelabel.cpp index 3892abad5ed..41cbb8974e3 100644 --- a/chromium/third_party/pdfium/core/fpdfdoc/cpdf_pagelabel.cpp +++ b/chromium/third_party/pdfium/core/fpdfdoc/cpdf_pagelabel.cpp @@ -142,5 +142,7 @@ int32_t CPDF_PageLabel::GetPageByLabel(const CFX_ByteStringC& bsLabel) const { } int32_t CPDF_PageLabel::GetPageByLabel(const CFX_WideStringC& wsLabel) const { - return GetPageByLabel(PDF_EncodeText(wsLabel.c_str()).AsStringC()); + // TODO(tsepez): check usage of c_str() below. + return GetPageByLabel( + PDF_EncodeText(wsLabel.unterminated_c_str()).AsStringC()); } diff --git a/chromium/third_party/pdfium/core/fpdfdoc/cpvt_generateap.cpp b/chromium/third_party/pdfium/core/fpdfdoc/cpvt_generateap.cpp index bcd3aa1d00a..eb874b33524 100644 --- a/chromium/third_party/pdfium/core/fpdfdoc/cpvt_generateap.cpp +++ b/chromium/third_party/pdfium/core/fpdfdoc/cpvt_generateap.cpp @@ -8,6 +8,7 @@ #include <algorithm> #include <memory> +#include <sstream> #include <utility> #include "core/fpdfapi/font/cpdf_font.h" @@ -151,7 +152,7 @@ bool GenerateWidgetAP(CPDF_Document* pDoc, if (CPDF_Array* pArray = pMKDict->GetArrayFor("BG")) crBG = CPVT_Color::ParseColor(*pArray); } - CFX_ByteTextBuf sAppStream; + std::ostringstream sAppStream; CFX_ByteString sBG = CPVT_GenerateAP::GenerateColorAP(crBG, PaintOperation::FILL); if (sBG.GetLength() > 0) { @@ -351,7 +352,7 @@ bool GenerateWidgetAP(CPDF_Document* pDoc, CPDF_Array* pSels = ToArray(FPDF_GetFieldAttr(pAnnotDict, "I")); CPDF_Object* pTi = FPDF_GetFieldAttr(pAnnotDict, "TI"); int32_t nTop = pTi ? pTi->GetInteger() : 0; - CFX_ByteTextBuf sBody; + std::ostringstream sBody; if (pOpts) { float fy = rcBody.top; for (size_t i = nTop, sz = pOpts->GetCount(); i < sz; i++) { @@ -417,16 +418,16 @@ bool GenerateWidgetAP(CPDF_Document* pDoc, } } } - if (sBody.GetSize() > 0) { + if (sBody.tellp() > 0) { sAppStream << "/Tx BMC\nq\n" << rcBody.left << " " << rcBody.bottom << " " << rcBody.Width() << " " << rcBody.Height() << " re\nW\nn\n" - << sBody.AsStringC() << "Q\nEMC\n"; + << sBody.str() << "Q\nEMC\n"; } } break; } if (pNormalStream) { - pNormalStream->SetData(sAppStream.GetBuffer(), sAppStream.GetSize()); + pNormalStream->SetData(&sAppStream); pStreamDict = pNormalStream->GetDict(); if (pStreamDict) { pStreamDict->SetMatrixFor("Matrix", matrix); @@ -498,14 +499,14 @@ CFX_ByteString GetDashPatternString(const CPDF_Dictionary& pAnnotDict) { // Support maximum of ten elements in the dash array. size_t pDashArrayCount = std::min<size_t>(pDashArray->GetCount(), 10); - CFX_ByteTextBuf sDashStream; + std::ostringstream sDashStream; sDashStream << "["; for (size_t i = 0; i < pDashArrayCount; ++i) sDashStream << pDashArray->GetNumberAt(i) << " "; sDashStream << "] 0 d\n"; - return sDashStream.MakeString(); + return CFX_ByteString(sDashStream); } CFX_ByteString GetPopupContentsString(CPDF_Document* pDoc, @@ -535,34 +536,13 @@ CFX_ByteString GetPopupContentsString(CPDF_Document* pDoc, if (sContent.IsEmpty()) return CFX_ByteString(); - CFX_ByteTextBuf sAppStream; + std::ostringstream sAppStream; sAppStream << "BT\n" << CPVT_GenerateAP::GenerateColorAP( CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), PaintOperation::FILL) << sContent << "ET\n" << "Q\n"; - return sAppStream.MakeString(); -} - -std::unique_ptr<CPDF_Dictionary> GenerateExtGStateDict( - const CPDF_Dictionary& pAnnotDict, - const CFX_ByteString& sExtGSDictName, - const CFX_ByteString& sBlendMode) { - auto pGSDict = - pdfium::MakeUnique<CPDF_Dictionary>(pAnnotDict.GetByteStringPool()); - pGSDict->SetNewFor<CPDF_String>("Type", "ExtGState", false); - - float fOpacity = - pAnnotDict.KeyExist("CA") ? pAnnotDict.GetNumberFor("CA") : 1; - pGSDict->SetNewFor<CPDF_Number>("CA", fOpacity); - pGSDict->SetNewFor<CPDF_Number>("ca", fOpacity); - pGSDict->SetNewFor<CPDF_Boolean>("AIS", false); - pGSDict->SetNewFor<CPDF_String>("BM", sBlendMode, false); - - auto pExtGStateDict = - pdfium::MakeUnique<CPDF_Dictionary>(pAnnotDict.GetByteStringPool()); - pExtGStateDict->SetFor(sExtGSDictName, std::move(pGSDict)); - return pExtGStateDict; + return CFX_ByteString(sAppStream); } std::unique_ptr<CPDF_Dictionary> GenerateResourceFontDict( @@ -581,42 +561,6 @@ std::unique_ptr<CPDF_Dictionary> GenerateResourceFontDict( return pResourceFontDict; } -std::unique_ptr<CPDF_Dictionary> GenerateResourceDict( - CPDF_Document* pDoc, - std::unique_ptr<CPDF_Dictionary> pExtGStateDict, - std::unique_ptr<CPDF_Dictionary> pResourceFontDict) { - auto pResourceDict = - pdfium::MakeUnique<CPDF_Dictionary>(pDoc->GetByteStringPool()); - if (pExtGStateDict) - pResourceDict->SetFor("ExtGState", std::move(pExtGStateDict)); - if (pResourceFontDict) - pResourceDict->SetFor("Font", std::move(pResourceFontDict)); - return pResourceDict; -} - -void GenerateAndSetAPDict(CPDF_Document* pDoc, - CPDF_Dictionary* pAnnotDict, - const CFX_ByteTextBuf& sAppStream, - std::unique_ptr<CPDF_Dictionary> pResourceDict, - bool bIsTextMarkupAnnotation) { - CPDF_Stream* pNormalStream = pDoc->NewIndirect<CPDF_Stream>(); - pNormalStream->SetData(sAppStream.GetBuffer(), sAppStream.GetSize()); - - CPDF_Dictionary* pAPDict = pAnnotDict->SetNewFor<CPDF_Dictionary>("AP"); - pAPDict->SetNewFor<CPDF_Reference>("N", pDoc, pNormalStream->GetObjNum()); - - CPDF_Dictionary* pStreamDict = pNormalStream->GetDict(); - pStreamDict->SetNewFor<CPDF_Number>("FormType", 1); - pStreamDict->SetNewFor<CPDF_String>("Subtype", "Form", false); - pStreamDict->SetMatrixFor("Matrix", CFX_Matrix()); - - CFX_FloatRect rect = bIsTextMarkupAnnotation - ? CPDF_Annot::RectFromQuadPoints(pAnnotDict) - : pAnnotDict->GetRectFor("Rect"); - pStreamDict->SetRectFor("BBox", rect); - pStreamDict->SetFor("Resources", std::move(pResourceDict)); -} - CFX_ByteString GetPaintOperatorString(bool bIsStrokeRect, bool bIsFillRect) { if (bIsStrokeRect) return bIsFillRect ? "b" : "s"; @@ -624,7 +568,7 @@ CFX_ByteString GetPaintOperatorString(bool bIsStrokeRect, bool bIsFillRect) { } CFX_ByteString GenerateTextSymbolAP(const CFX_FloatRect& rect) { - CFX_ByteTextBuf sAppStream; + std::ostringstream sAppStream; sAppStream << CPVT_GenerateAP::GenerateColorAP( CPVT_Color(CPVT_Color::kRGB, 1, 1, 0), PaintOperation::FILL); sAppStream << CPVT_GenerateAP::GenerateColorAP( @@ -670,7 +614,7 @@ CFX_ByteString GenerateTextSymbolAP(const CFX_FloatRect& rect) { } sAppStream << "B*\n"; - return sAppStream.MakeString(); + return CFX_ByteString(sAppStream); } } // namespace @@ -731,7 +675,7 @@ bool CPVT_GenerateAP::GenerateTextFieldAP(CPDF_Document* pDoc, bool CPVT_GenerateAP::GenerateCircleAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict) { - CFX_ByteTextBuf sAppStream; + std::ostringstream sAppStream; CFX_ByteString sExtGSDictName = "GS"; sAppStream << "/" << sExtGSDictName << " gs "; @@ -798,14 +742,14 @@ bool CPVT_GenerateAP::GenerateCircleAP(CPDF_Document* pDoc, GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); auto pResourceDict = GenerateResourceDict(pDoc, std::move(pExtGStateDict), nullptr); - GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, std::move(pResourceDict), + GenerateAndSetAPDict(pDoc, pAnnotDict, &sAppStream, std::move(pResourceDict), false /*IsTextMarkupAnnotation*/); return true; } bool CPVT_GenerateAP::GenerateHighlightAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict) { - CFX_ByteTextBuf sAppStream; + std::ostringstream sAppStream; CFX_ByteString sExtGSDictName = "GS"; sAppStream << "/" << sExtGSDictName << " gs "; @@ -825,7 +769,7 @@ bool CPVT_GenerateAP::GenerateHighlightAP(CPDF_Document* pDoc, GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Multiply"); auto pResourceDict = GenerateResourceDict(pDoc, std::move(pExtGStateDict), nullptr); - GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, std::move(pResourceDict), + GenerateAndSetAPDict(pDoc, pAnnotDict, &sAppStream, std::move(pResourceDict), true /*IsTextMarkupAnnotation*/); return true; @@ -843,7 +787,7 @@ bool CPVT_GenerateAP::GenerateInkAP(CPDF_Document* pDoc, if (!pInkList || pInkList->IsEmpty()) return false; - CFX_ByteTextBuf sAppStream; + std::ostringstream sAppStream; CFX_ByteString sExtGSDictName = "GS"; sAppStream << "/" << sExtGSDictName << " gs "; @@ -880,14 +824,14 @@ bool CPVT_GenerateAP::GenerateInkAP(CPDF_Document* pDoc, GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); auto pResourceDict = GenerateResourceDict(pDoc, std::move(pExtGStateDict), nullptr); - GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, std::move(pResourceDict), + GenerateAndSetAPDict(pDoc, pAnnotDict, &sAppStream, std::move(pResourceDict), false /*IsTextMarkupAnnotation*/); return true; } bool CPVT_GenerateAP::GenerateTextAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict) { - CFX_ByteTextBuf sAppStream; + std::ostringstream sAppStream; CFX_ByteString sExtGSDictName = "GS"; sAppStream << "/" << sExtGSDictName << " gs "; @@ -903,14 +847,14 @@ bool CPVT_GenerateAP::GenerateTextAP(CPDF_Document* pDoc, GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); auto pResourceDict = GenerateResourceDict(pDoc, std::move(pExtGStateDict), nullptr); - GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, std::move(pResourceDict), + GenerateAndSetAPDict(pDoc, pAnnotDict, &sAppStream, std::move(pResourceDict), false /*IsTextMarkupAnnotation*/); return true; } bool CPVT_GenerateAP::GenerateUnderlineAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict) { - CFX_ByteTextBuf sAppStream; + std::ostringstream sAppStream; CFX_ByteString sExtGSDictName = "GS"; sAppStream << "/" << sExtGSDictName << " gs "; @@ -930,14 +874,14 @@ bool CPVT_GenerateAP::GenerateUnderlineAP(CPDF_Document* pDoc, GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); auto pResourceDict = GenerateResourceDict(pDoc, std::move(pExtGStateDict), nullptr); - GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, std::move(pResourceDict), + GenerateAndSetAPDict(pDoc, pAnnotDict, &sAppStream, std::move(pResourceDict), true /*IsTextMarkupAnnotation*/); return true; } bool CPVT_GenerateAP::GeneratePopupAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict) { - CFX_ByteTextBuf sAppStream; + std::ostringstream sAppStream; CFX_ByteString sExtGSDictName = "GS"; sAppStream << "/" << sExtGSDictName << " gs\n"; @@ -968,14 +912,14 @@ bool CPVT_GenerateAP::GeneratePopupAP(CPDF_Document* pDoc, std::move(pExtGStateDict)); sAppStream << GetPopupContentsString(pDoc, *pAnnotDict, pDefFont, sFontName); - GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, std::move(pResourceDict), + GenerateAndSetAPDict(pDoc, pAnnotDict, &sAppStream, std::move(pResourceDict), false /*IsTextMarkupAnnotation*/); return true; } bool CPVT_GenerateAP::GenerateSquareAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict) { - CFX_ByteTextBuf sAppStream; + std::ostringstream sAppStream; CFX_ByteString sExtGSDictName = "GS"; sAppStream << "/" << sExtGSDictName << " gs "; @@ -1016,14 +960,14 @@ bool CPVT_GenerateAP::GenerateSquareAP(CPDF_Document* pDoc, GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); auto pResourceDict = GenerateResourceDict(pDoc, std::move(pExtGStateDict), nullptr); - GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, std::move(pResourceDict), + GenerateAndSetAPDict(pDoc, pAnnotDict, &sAppStream, std::move(pResourceDict), false /*IsTextMarkupAnnotation*/); return true; } bool CPVT_GenerateAP::GenerateSquigglyAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict) { - CFX_ByteTextBuf sAppStream; + std::ostringstream sAppStream; CFX_ByteString sExtGSDictName = "GS"; sAppStream << "/" << sExtGSDictName << " gs "; @@ -1065,14 +1009,14 @@ bool CPVT_GenerateAP::GenerateSquigglyAP(CPDF_Document* pDoc, GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); auto pResourceDict = GenerateResourceDict(pDoc, std::move(pExtGStateDict), nullptr); - GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, std::move(pResourceDict), + GenerateAndSetAPDict(pDoc, pAnnotDict, &sAppStream, std::move(pResourceDict), true /*IsTextMarkupAnnotation*/); return true; } bool CPVT_GenerateAP::GenerateStrikeOutAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict) { - CFX_ByteTextBuf sAppStream; + std::ostringstream sAppStream; CFX_ByteString sExtGSDictName = "GS"; sAppStream << "/" << sExtGSDictName << " gs "; @@ -1092,7 +1036,7 @@ bool CPVT_GenerateAP::GenerateStrikeOutAP(CPDF_Document* pDoc, GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); auto pResourceDict = GenerateResourceDict(pDoc, std::move(pExtGStateDict), nullptr); - GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, std::move(pResourceDict), + GenerateAndSetAPDict(pDoc, pAnnotDict, &sAppStream, std::move(pResourceDict), true /*IsTextMarkupAnnotation*/); return true; } @@ -1104,9 +1048,9 @@ CFX_ByteString CPVT_GenerateAP::GenerateEditAP( const CFX_PointF& ptOffset, bool bContinuous, uint16_t SubWord) { - CFX_ByteTextBuf sEditStream; - CFX_ByteTextBuf sLineStream; - CFX_ByteTextBuf sWords; + std::ostringstream sEditStream; + std::ostringstream sLineStream; + std::ostringstream sWords; CFX_PointF ptOld; CFX_PointF ptNew; int32_t nCurFontIndex = -1; @@ -1117,11 +1061,11 @@ CFX_ByteString CPVT_GenerateAP::GenerateEditAP( CPVT_WordPlace place = pIterator->GetAt(); if (bContinuous) { if (place.LineCmp(oldplace) != 0) { - if (sWords.GetSize() > 0) { - sLineStream << GetWordRenderString(sWords.MakeString()); - sEditStream << sLineStream; - sLineStream.Clear(); - sWords.Clear(); + if (sWords.tellp() > 0) { + sLineStream << GetWordRenderString(CFX_ByteString(sWords)); + sEditStream << sLineStream.str(); + sLineStream.str(""); + sWords.str(""); } CPVT_Word word; if (pIterator->GetWord(word)) { @@ -1142,9 +1086,9 @@ CFX_ByteString CPVT_GenerateAP::GenerateEditAP( CPVT_Word word; if (pIterator->GetWord(word)) { if (word.nFontIndex != nCurFontIndex) { - if (sWords.GetSize() > 0) { - sLineStream << GetWordRenderString(sWords.MakeString()); - sWords.Clear(); + if (sWords.tellp() > 0) { + sLineStream << GetWordRenderString(CFX_ByteString(sWords)); + sWords.str(""); } sLineStream << GetFontSetString(pFontMap, word.nFontIndex, word.fFontSize); @@ -1173,12 +1117,12 @@ CFX_ByteString CPVT_GenerateAP::GenerateEditAP( } } } - if (sWords.GetSize() > 0) { - sLineStream << GetWordRenderString(sWords.MakeString()); - sEditStream << sLineStream; - sWords.Clear(); + if (sWords.tellp() > 0) { + sLineStream << GetWordRenderString(CFX_ByteString(sWords)); + sEditStream << sLineStream.str(); + sWords.str(""); } - return sEditStream.MakeString(); + return CFX_ByteString(sEditStream); } // Static. @@ -1190,7 +1134,7 @@ CFX_ByteString CPVT_GenerateAP::GenerateBorderAP( const CPVT_Color& crRightBottom, BorderStyle nStyle, const CPVT_Dash& dash) { - CFX_ByteTextBuf sAppStream; + std::ostringstream sAppStream; CFX_ByteString sColor; float fLeft = rect.left; float fRight = rect.right; @@ -1286,13 +1230,13 @@ CFX_ByteString CPVT_GenerateAP::GenerateBorderAP( break; } } - return sAppStream.MakeString(); + return CFX_ByteString(sAppStream); } // Static. CFX_ByteString CPVT_GenerateAP::GenerateColorAP(const CPVT_Color& color, PaintOperation nOperation) { - CFX_ByteTextBuf sColorStream; + std::ostringstream sColorStream; switch (color.nColorType) { case CPVT_Color::kRGB: sColorStream << color.fColor1 << " " << color.fColor2 << " " @@ -1314,7 +1258,71 @@ CFX_ByteString CPVT_GenerateAP::GenerateColorAP(const CPVT_Color& color, case CPVT_Color::kTransparent: break; } - return sColorStream.MakeString(); + return CFX_ByteString(sColorStream); +} + +// Static. +std::unique_ptr<CPDF_Dictionary> CPVT_GenerateAP::GenerateExtGStateDict( + const CPDF_Dictionary& pAnnotDict, + const CFX_ByteString& sExtGSDictName, + const CFX_ByteString& sBlendMode) { + auto pGSDict = + pdfium::MakeUnique<CPDF_Dictionary>(pAnnotDict.GetByteStringPool()); + pGSDict->SetNewFor<CPDF_String>("Type", "ExtGState", false); + + float fOpacity = + pAnnotDict.KeyExist("CA") ? pAnnotDict.GetNumberFor("CA") : 1; + pGSDict->SetNewFor<CPDF_Number>("CA", fOpacity); + pGSDict->SetNewFor<CPDF_Number>("ca", fOpacity); + pGSDict->SetNewFor<CPDF_Boolean>("AIS", false); + pGSDict->SetNewFor<CPDF_String>("BM", sBlendMode, false); + + auto pExtGStateDict = + pdfium::MakeUnique<CPDF_Dictionary>(pAnnotDict.GetByteStringPool()); + pExtGStateDict->SetFor(sExtGSDictName, std::move(pGSDict)); + return pExtGStateDict; +} + +// Static. +std::unique_ptr<CPDF_Dictionary> CPVT_GenerateAP::GenerateResourceDict( + CPDF_Document* pDoc, + std::unique_ptr<CPDF_Dictionary> pExtGStateDict, + std::unique_ptr<CPDF_Dictionary> pResourceFontDict) { + auto pResourceDict = + pdfium::MakeUnique<CPDF_Dictionary>(pDoc->GetByteStringPool()); + if (pExtGStateDict) + pResourceDict->SetFor("ExtGState", std::move(pExtGStateDict)); + if (pResourceFontDict) + pResourceDict->SetFor("Font", std::move(pResourceFontDict)); + return pResourceDict; +} + +// Static. +void CPVT_GenerateAP::GenerateAndSetAPDict( + CPDF_Document* pDoc, + CPDF_Dictionary* pAnnotDict, + std::ostringstream* psAppStream, + std::unique_ptr<CPDF_Dictionary> pResourceDict, + bool bIsTextMarkupAnnotation) { + CPDF_Stream* pNormalStream = pDoc->NewIndirect<CPDF_Stream>(); + pNormalStream->SetData(psAppStream); + + CPDF_Dictionary* pAPDict = pAnnotDict->GetDictFor("AP"); + if (!pAPDict) + pAPDict = pAnnotDict->SetNewFor<CPDF_Dictionary>("AP"); + + pAPDict->SetNewFor<CPDF_Reference>("N", pDoc, pNormalStream->GetObjNum()); + + CPDF_Dictionary* pStreamDict = pNormalStream->GetDict(); + pStreamDict->SetNewFor<CPDF_Number>("FormType", 1); + pStreamDict->SetNewFor<CPDF_String>("Subtype", "Form", false); + pStreamDict->SetMatrixFor("Matrix", CFX_Matrix()); + + CFX_FloatRect rect = bIsTextMarkupAnnotation + ? CPDF_Annot::RectFromQuadPoints(pAnnotDict) + : pAnnotDict->GetRectFor("Rect"); + pStreamDict->SetRectFor("BBox", rect); + pStreamDict->SetFor("Resources", std::move(pResourceDict)); } // Static. @@ -1348,7 +1356,7 @@ CFX_ByteString CPVT_GenerateAP::GetPDFWordString(IPVT_FontMap* pFontMap, CFX_ByteString CPVT_GenerateAP::GetWordRenderString( const CFX_ByteString& strWords) { if (strWords.GetLength() > 0) - return PDF_EncodeString(strWords) + " Tj\n"; + return PDF_EncodeString(strWords, false) + " Tj\n"; return ""; } @@ -1356,11 +1364,11 @@ CFX_ByteString CPVT_GenerateAP::GetWordRenderString( CFX_ByteString CPVT_GenerateAP::GetFontSetString(IPVT_FontMap* pFontMap, int32_t nFontIndex, float fFontSize) { - CFX_ByteTextBuf sRet; + std::ostringstream sRet; if (pFontMap) { CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); if (sFontAlias.GetLength() > 0 && fFontSize > 0) sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; } - return sRet.MakeString(); + return CFX_ByteString(sRet); } diff --git a/chromium/third_party/pdfium/core/fpdfdoc/cpvt_generateap.h b/chromium/third_party/pdfium/core/fpdfdoc/cpvt_generateap.h index c5586362556..cee96cda508 100644 --- a/chromium/third_party/pdfium/core/fpdfdoc/cpvt_generateap.h +++ b/chromium/third_party/pdfium/core/fpdfdoc/cpvt_generateap.h @@ -60,6 +60,20 @@ class CPVT_GenerateAP { const CPVT_Dash& dash); static CFX_ByteString GenerateColorAP(const CPVT_Color& color, PaintOperation nOperation); + static std::unique_ptr<CPDF_Dictionary> GenerateExtGStateDict( + const CPDF_Dictionary& pAnnotDict, + const CFX_ByteString& sExtGSDictName, + const CFX_ByteString& sBlendMode); + static std::unique_ptr<CPDF_Dictionary> GenerateResourceDict( + CPDF_Document* pDoc, + std::unique_ptr<CPDF_Dictionary> pExtGStateDict, + std::unique_ptr<CPDF_Dictionary> pResourceFontDict); + static void GenerateAndSetAPDict( + CPDF_Document* pDoc, + CPDF_Dictionary* pAnnotDict, + std::ostringstream* psAppStream, + std::unique_ptr<CPDF_Dictionary> pResourceDict, + bool bIsTextMarkupAnnotation); static CFX_ByteString GetPDFWordString(IPVT_FontMap* pFontMap, int32_t nFontIndex, diff --git a/chromium/third_party/pdfium/core/fpdfdoc/cpvt_wordrange.h b/chromium/third_party/pdfium/core/fpdfdoc/cpvt_wordrange.h index ed06d6f0de6..638f6c17c0f 100644 --- a/chromium/third_party/pdfium/core/fpdfdoc/cpvt_wordrange.h +++ b/chromium/third_party/pdfium/core/fpdfdoc/cpvt_wordrange.h @@ -7,6 +7,7 @@ #ifndef CORE_FPDFDOC_CPVT_WORDRANGE_H_ #define CORE_FPDFDOC_CPVT_WORDRANGE_H_ +#include <algorithm> #include <utility> #include "core/fpdfdoc/cpvt_wordplace.h" @@ -41,6 +42,16 @@ struct CPVT_WordRange { Normalize(); } + CPVT_WordRange Intersect(const CPVT_WordRange& that) const { + if (that.EndPos < BeginPos || that.BeginPos > EndPos || + EndPos < that.BeginPos || BeginPos > that.EndPos) { + return CPVT_WordRange(); + } + + return CPVT_WordRange(std::max(BeginPos, that.BeginPos), + std::min(EndPos, that.EndPos)); + } + inline bool IsEmpty() const { return BeginPos == EndPos; } inline bool operator==(const CPVT_WordRange& wr) const { return wr.BeginPos == BeginPos && wr.EndPos == EndPos; diff --git a/chromium/third_party/pdfium/core/fpdftext/cpdf_linkextract.cpp b/chromium/third_party/pdfium/core/fpdftext/cpdf_linkextract.cpp index 315cff12a01..5179f732c9b 100644 --- a/chromium/third_party/pdfium/core/fpdftext/cpdf_linkextract.cpp +++ b/chromium/third_party/pdfium/core/fpdftext/cpdf_linkextract.cpp @@ -15,12 +15,13 @@ namespace { -// Find the end of a web link starting from offset |start|. -// The purpose of this function is to separate url from the surrounding context -// characters, we do not intend to fully validate the url. -// |str| contains lower case characters only. -FX_STRSIZE FindWebLinkEnding(const CFX_WideString& str, FX_STRSIZE start) { - FX_STRSIZE end = str.GetLength() - 1; +// Find the end of a web link starting from offset |start| and ending at offset +// |end|. The purpose of this function is to separate url from the surrounding +// context characters, we do not intend to fully validate the url. |str| +// contains lower case characters only. +FX_STRSIZE FindWebLinkEnding(const CFX_WideString& str, + FX_STRSIZE start, + FX_STRSIZE end) { if (str.Find(L'/', start) != -1) { // When there is a path and query after '/', most ASCII chars are allowed. // We don't sanitize in this case. @@ -59,6 +60,46 @@ FX_STRSIZE FindWebLinkEnding(const CFX_WideString& str, FX_STRSIZE start) { return end; } +// Remove characters from the end of |str|, delimited by |start| and |end|, up +// to and including |charToFind|. No-op if |charToFind| is not present. Updates +// |end| if characters were removed. +void TrimBackwardsToChar(const CFX_WideString& str, + wchar_t charToFind, + FX_STRSIZE start, + FX_STRSIZE* end) { + for (FX_STRSIZE pos = *end; pos >= start; pos--) { + if (str[pos] == charToFind) { + *end = pos - 1; + break; + } + } +} + +// Finds opening brackets ()[]{}<> and quotes "' before the URL delimited by +// |start| and |end| in |str|. Matches a closing bracket or quote for each +// opening character and, if present, removes everything afterwards. Returns the +// new end position for the string. +FX_STRSIZE TrimExternalBracketsFromWebLink(const CFX_WideString& str, + FX_STRSIZE start, + FX_STRSIZE end) { + for (FX_STRSIZE pos = 0; pos < start; pos++) { + if (str[pos] == '(') { + TrimBackwardsToChar(str, ')', start, &end); + } else if (str[pos] == '[') { + TrimBackwardsToChar(str, ']', start, &end); + } else if (str[pos] == '{') { + TrimBackwardsToChar(str, '}', start, &end); + } else if (str[pos] == '<') { + TrimBackwardsToChar(str, '>', start, &end); + } else if (str[pos] == '"') { + TrimBackwardsToChar(str, '"', start, &end); + } else if (str[pos] == '\'') { + TrimBackwardsToChar(str, '\'', start, &end); + } + } + return end; +} + } // namespace CPDF_LinkExtract::CPDF_LinkExtract(const CPDF_TextPage* pTextPage) @@ -121,9 +162,15 @@ void CPDF_LinkExtract::ParseLink() { } // Check for potential web URLs and email addresses. // Ftp address, file system links, data, blob etc. are not checked. - if (nCount > 5 && - (CheckWebLink(strBeCheck) || CheckMailLink(strBeCheck))) { - m_LinkArray.push_back({start, nCount, strBeCheck}); + if (nCount > 5) { + int32_t nStartOffset; + int32_t nCountOverload; + if (CheckWebLink(&strBeCheck, &nStartOffset, &nCountOverload)) { + m_LinkArray.push_back( + {start + nStartOffset, nCountOverload, strBeCheck}); + } else if (CheckMailLink(&strBeCheck)) { + m_LinkArray.push_back({start, nCount, strBeCheck}); + } } } start = ++pos; @@ -136,13 +183,15 @@ void CPDF_LinkExtract::ParseLink() { } } -bool CPDF_LinkExtract::CheckWebLink(CFX_WideString& strBeCheck) { +bool CPDF_LinkExtract::CheckWebLink(CFX_WideString* strBeCheck, + int32_t* nStart, + int32_t* nCount) { static const wchar_t kHttpScheme[] = L"http"; static const FX_STRSIZE kHttpSchemeLen = FXSYS_len(kHttpScheme); static const wchar_t kWWWAddrStart[] = L"www."; static const FX_STRSIZE kWWWAddrStartLen = FXSYS_len(kWWWAddrStart); - CFX_WideString str = strBeCheck; + CFX_WideString str = *strBeCheck; str.MakeLower(); FX_STRSIZE len = str.GetLength(); @@ -154,9 +203,14 @@ bool CPDF_LinkExtract::CheckWebLink(CFX_WideString& strBeCheck) { if (str[off] == L's') // "https" scheme is accepted. off++; if (str[off] == L':' && str[off + 1] == L'/' && str[off + 2] == L'/') { - FX_STRSIZE end = FindWebLinkEnding(str, off + 3); - if (end > off + 3) { // Non-empty host name. - strBeCheck = strBeCheck.Mid(start, end - start + 1); + off += 3; + FX_STRSIZE end = + TrimExternalBracketsFromWebLink(str, start, str.GetLength() - 1); + end = FindWebLinkEnding(str, off, end); + if (end > off) { // Non-empty host name. + *nStart = start; + *nCount = end - start + 1; + *strBeCheck = strBeCheck->Mid(*nStart, *nCount); return true; } } @@ -166,17 +220,21 @@ bool CPDF_LinkExtract::CheckWebLink(CFX_WideString& strBeCheck) { // When there is no scheme, try to find url starting with "www.". start = str.Find(kWWWAddrStart); if (start != -1 && len > start + kWWWAddrStartLen) { - FX_STRSIZE end = FindWebLinkEnding(str, start); + FX_STRSIZE end = + TrimExternalBracketsFromWebLink(str, start, str.GetLength() - 1); + end = FindWebLinkEnding(str, start, end); if (end > start + kWWWAddrStartLen) { - strBeCheck = L"http://" + strBeCheck.Mid(start, end - start + 1); + *nStart = start; + *nCount = end - start + 1; + *strBeCheck = L"http://" + strBeCheck->Mid(*nStart, *nCount); return true; } } return false; } -bool CPDF_LinkExtract::CheckMailLink(CFX_WideString& str) { - int aPos = str.Find(L'@'); +bool CPDF_LinkExtract::CheckMailLink(CFX_WideString* str) { + int aPos = str->Find(L'@'); // Invalid when no '@'. if (aPos < 1) return false; @@ -184,7 +242,7 @@ bool CPDF_LinkExtract::CheckMailLink(CFX_WideString& str) { // Check the local part. int pPos = aPos; // Used to track the position of '@' or '.'. for (int i = aPos - 1; i >= 0; i--) { - wchar_t ch = str.GetAt(i); + wchar_t ch = str->GetAt(i); if (ch == L'_' || ch == L'-' || FXSYS_iswalnum(ch)) continue; @@ -196,7 +254,7 @@ bool CPDF_LinkExtract::CheckMailLink(CFX_WideString& str) { // End extracting for other invalid chars, '.' at the beginning, or // consecutive '.'. int removed_len = i == pPos - 1 ? i + 2 : i + 1; - str = str.Right(str.GetLength() - removed_len); + *str = str->Right(str->GetLength() - removed_len); break; } // Found a valid '.'. @@ -204,23 +262,23 @@ bool CPDF_LinkExtract::CheckMailLink(CFX_WideString& str) { } // Check the domain name part. - aPos = str.Find(L'@'); + aPos = str->Find(L'@'); if (aPos < 1) return false; - str.TrimRight(L'.'); + str->TrimRight(L'.'); // At least one '.' in domain name, but not at the beginning. // TODO(weili): RFC5322 allows domain names to be a local name without '.'. // Check whether we should remove this check. - int ePos = str.Find(L'.', aPos + 1); + int ePos = str->Find(L'.', aPos + 1); if (ePos == -1 || ePos == aPos + 1) return false; // Validate all other chars in domain name. - int nLen = str.GetLength(); + int nLen = str->GetLength(); pPos = 0; // Used to track the position of '.'. for (int i = aPos + 1; i < nLen; i++) { - wchar_t wch = str.GetAt(i); + wchar_t wch = str->GetAt(i); if (wch == L'-' || FXSYS_iswalnum(wch)) continue; @@ -229,7 +287,7 @@ bool CPDF_LinkExtract::CheckMailLink(CFX_WideString& str) { int host_end = i == pPos + 1 ? i - 2 : i - 1; if (pPos > 0 && host_end - aPos >= 3) { // Trim the ending invalid chars if there is at least one '.' and name. - str = str.Left(host_end + 1); + *str = str->Left(host_end + 1); break; } return false; @@ -237,8 +295,8 @@ bool CPDF_LinkExtract::CheckMailLink(CFX_WideString& str) { pPos = i; } - if (str.Find(L"mailto:") == -1) - str = L"mailto:" + str; + if (str->Find(L"mailto:") == -1) + *str = L"mailto:" + *str; return true; } diff --git a/chromium/third_party/pdfium/core/fpdftext/cpdf_linkextract.h b/chromium/third_party/pdfium/core/fpdftext/cpdf_linkextract.h index 564d5525481..31004577b91 100644 --- a/chromium/third_party/pdfium/core/fpdftext/cpdf_linkextract.h +++ b/chromium/third_party/pdfium/core/fpdftext/cpdf_linkextract.h @@ -28,8 +28,8 @@ class CPDF_LinkExtract { protected: void ParseLink(); - bool CheckWebLink(CFX_WideString& str); - bool CheckMailLink(CFX_WideString& str); + bool CheckWebLink(CFX_WideString* str, int32_t* nStart, int32_t* nCount); + bool CheckMailLink(CFX_WideString* str); private: struct Link { diff --git a/chromium/third_party/pdfium/core/fpdftext/cpdf_linkextract_unittest.cpp b/chromium/third_party/pdfium/core/fpdftext/cpdf_linkextract_unittest.cpp index bd059862fd8..efeb53ebe26 100644 --- a/chromium/third_party/pdfium/core/fpdftext/cpdf_linkextract_unittest.cpp +++ b/chromium/third_party/pdfium/core/fpdftext/cpdf_linkextract_unittest.cpp @@ -31,8 +31,9 @@ TEST(CPDF_LinkExtractTest, CheckMailLink) { L"fan@g..com" // Domain name should not have consecutive '.' }; for (size_t i = 0; i < FX_ArraySize(invalid_strs); ++i) { - CFX_WideString text_str(invalid_strs[i]); - EXPECT_FALSE(extractor.CheckMailLink(text_str)) << text_str.c_str(); + const wchar_t* const input = invalid_strs[i]; + CFX_WideString text_str(input); + EXPECT_FALSE(extractor.CheckMailLink(&text_str)) << input; } // Check cases that can extract valid mail link. @@ -51,10 +52,11 @@ TEST(CPDF_LinkExtractTest, CheckMailLink) { {L"CAP.cap@Gmail.Com", L"CAP.cap@Gmail.Com"}, // Keep the original case. }; for (size_t i = 0; i < FX_ArraySize(valid_strs); ++i) { - CFX_WideString text_str(valid_strs[i][0]); + const wchar_t* const input = valid_strs[i][0]; + CFX_WideString text_str(input); CFX_WideString expected_str(L"mailto:"); expected_str += valid_strs[i][1]; - EXPECT_TRUE(extractor.CheckMailLink(text_str)) << text_str.c_str(); + EXPECT_TRUE(extractor.CheckMailLink(&text_str)) << input; EXPECT_STREQ(expected_str.c_str(), text_str.c_str()); } } @@ -75,64 +77,111 @@ TEST(CPDF_LinkExtractTest, CheckWebLink) { // Web addresses that in correct format that we don't handle. L"abc.example.com", // URL without scheme. }; + const int32_t DEFAULT_VALUE = -42; for (size_t i = 0; i < FX_ArraySize(invalid_cases); ++i) { - CFX_WideString text_str(invalid_cases[i]); - EXPECT_FALSE(extractor.CheckWebLink(text_str)) << text_str.c_str(); + const wchar_t* const input = invalid_cases[i]; + CFX_WideString text_str(input); + int32_t start_offset = DEFAULT_VALUE; + int32_t count = DEFAULT_VALUE; + EXPECT_FALSE(extractor.CheckWebLink(&text_str, &start_offset, &count)) + << input; + EXPECT_EQ(DEFAULT_VALUE, start_offset) << input; + EXPECT_EQ(DEFAULT_VALUE, count) << input; } // Check cases that can extract valid web link. // An array of {input_string, expected_extracted_web_link}. - const wchar_t* const valid_cases[][2] = { - {L"http://www.example.com", L"http://www.example.com"}, // standard URL. - {L"http://www.example.com:88", - L"http://www.example.com:88"}, // URL with port number. - {L"http://test@www.example.com", - L"http://test@www.example.com"}, // URL with username. - {L"http://test:test@example.com", - L"http://test:test@example.com"}, // URL with username and password. - {L"http://example", L"http://example"}, // URL with short domain name. - {L"http////www.server", L"http://www.server"}, // URL starts with "www.". - {L"http:/www.abc.com", L"http://www.abc.com"}, // URL starts with "www.". - {L"www.a.b.c", L"http://www.a.b.c"}, // URL starts with "www.". - {L"https://a.us", L"https://a.us"}, // Secure http URL. - {L"https://www.t.us", L"https://www.t.us"}, // Secure http URL. - {L"www.example-test.com", - L"http://www.example-test.com"}, // '-' in host is ok. - {L"www.example.com,", - L"http://www.example.com"}, // Trim ending invalid chars. - {L"www.example.com;(", - L"http://www.example.com"}, // Trim ending invalid chars. - {L"test:www.abc.com", L"http://www.abc.com"}, // Trim chars before URL. - {L"www.g.com..", L"http://www.g.com.."}, // Leave ending periods. - // Web link can contain IP address too. - {L"http://192.168.0.1", L"http://192.168.0.1"}, // IPv4 address. - {L"http://192.168.0.1:80", - L"http://192.168.0.1:80"}, // IPv4 address with port. - {L"http://[aa::00:bb::00:cc:00]", - L"http://[aa::00:bb::00:cc:00]"}, // IPv6 reference. - {L"http://[aa::00:bb::00:cc:00]:12", - L"http://[aa::00:bb::00:cc:00]:12"}, // IPv6 reference with port. - {L"http://[aa]:12", L"http://[aa]:12"}, // Not validate IP address. - {L"http://[aa]:12abc", L"http://[aa]:12"}, // Trim for IPv6 address. - {L"http://[aa]:", L"http://[aa]"}, // Trim for IPv6 address. + struct ValidCase { + const wchar_t* const input_string; + const wchar_t* const url_extracted; + const int32_t start_offset; + const int32_t count; + }; + const ValidCase valid_cases[] = { + {L"http://www.example.com", L"http://www.example.com", 0, + 22}, // standard URL. + {L"http://www.example.com:88", L"http://www.example.com:88", 0, + 25}, // URL with port number. + {L"http://test@www.example.com", L"http://test@www.example.com", 0, + 27}, // URL with username. + {L"http://test:test@example.com", L"http://test:test@example.com", 0, + 28}, // URL with username and password. + {L"http://example", L"http://example", 0, + 14}, // URL with short domain name. + {L"http////www.server", L"http://www.server", 8, + 10}, // URL starts with "www.". + {L"http:/www.abc.com", L"http://www.abc.com", 6, + 11}, // URL starts with "www.". + {L"www.a.b.c", L"http://www.a.b.c", 0, 9}, // URL starts with "www.". + {L"https://a.us", L"https://a.us", 0, 12}, // Secure http URL. + {L"https://www.t.us", L"https://www.t.us", 0, 16}, // Secure http URL. + {L"www.example-test.com", L"http://www.example-test.com", 0, + 20}, // '-' in host is ok. + {L"www.example.com,", L"http://www.example.com", 0, + 15}, // Trim ending invalid chars. + {L"www.example.com;(", L"http://www.example.com", 0, + 15}, // Trim ending invalid chars. + {L"test:www.abc.com", L"http://www.abc.com", 5, + 11}, // Trim chars before URL. + {L"(http://www.abc.com)", L"http://www.abc.com", 1, + 18}, // Trim external brackets. + {L"0(http://www.abc.com)0", L"http://www.abc.com", 2, + 18}, // Trim chars outside brackets as well. + {L"0(www.abc.com)0", L"http://www.abc.com", 2, + 11}, // Links without http should also have brackets trimmed. + {L"http://www.abc.com)0", L"http://www.abc.com)0", 0, + 20}, // Do not trim brackets that were not opened. + {L"{(<http://www.abc.com>)}", L"http://www.abc.com", 3, + 18}, // Trim chars with multiple levels of brackets. + {L"[http://www.abc.com/z(1)]", L"http://www.abc.com/z(1)", 1, + 23}, // Brackets opened inside the URL should not be trimmed. + {L"(http://www.abc.com/z(1))", L"http://www.abc.com/z(1)", 1, + 23}, // Brackets opened inside the URL should not be trimmed. + {L"\"http://www.abc.com\"", L"http://www.abc.com", 1, + 18}, // External quotes can also be escaped + {L"www.g.com..", L"http://www.g.com..", 0, 11}, // Leave ending periods. + + // Web links can contain IP addresses too. + {L"http://192.168.0.1", L"http://192.168.0.1", 0, 18}, // IPv4 address. + {L"http://192.168.0.1:80", L"http://192.168.0.1:80", 0, + 21}, // IPv4 address with port. + {L"http://[aa::00:bb::00:cc:00]", L"http://[aa::00:bb::00:cc:00]", 0, + 28}, // IPv6 reference. + {L"http://[aa::00:bb::00:cc:00]:12", L"http://[aa::00:bb::00:cc:00]:12", + 0, 31}, // IPv6 reference with port. + {L"http://[aa]:12", L"http://[aa]:12", 0, + 14}, // Not validate IP address. + {L"http://[aa]:12abc", L"http://[aa]:12", 0, + 14}, // Trim for IPv6 address. + {L"http://[aa]:", L"http://[aa]", 0, 11}, // Trim for IPv6 address. + // Path and query parts can be anything. - {L"www.abc.com/#%%^&&*(", L"http://www.abc.com/#%%^&&*("}, - {L"www.a.com/#a=@?q=rr&r=y", L"http://www.a.com/#a=@?q=rr&r=y"}, - {L"http://a.com/1/2/3/4\5\6", L"http://a.com/1/2/3/4\5\6"}, - {L"http://www.example.com/foo;bar", L"http://www.example.com/foo;bar"}, + {L"www.abc.com/#%%^&&*(", L"http://www.abc.com/#%%^&&*(", 0, 20}, + {L"www.a.com/#a=@?q=rr&r=y", L"http://www.a.com/#a=@?q=rr&r=y", 0, 23}, + {L"http://a.com/1/2/3/4\5\6", L"http://a.com/1/2/3/4\5\6", 0, 22}, + {L"http://www.example.com/foo;bar", L"http://www.example.com/foo;bar", 0, + 30}, + // Invalid chars inside host name are ok as we don't validate them. - {L"http://ex[am]ple", L"http://ex[am]ple"}, - {L"http://:example.com", L"http://:example.com"}, - {L"http://((())/path?", L"http://((())/path?"}, - {L"http:////abc.server", L"http:////abc.server"}, + {L"http://ex[am]ple", L"http://ex[am]ple", 0, 16}, + {L"http://:example.com", L"http://:example.com", 0, 19}, + {L"http://((())/path?", L"http://((())/path?", 0, 18}, + {L"http:////abc.server", L"http:////abc.server", 0, 19}, + // Non-ASCII chars are not validated either. - {L"www.测试.net", L"http://www.测试.net"}, - {L"www.测试。net。", L"http://www.测试。net。"}, - {L"www.测试.net;", L"http://www.测试.net;"}, + {L"www.测试.net", L"http://www.测试.net", 0, 10}, + {L"www.测试。net。", L"http://www.测试。net。", 0, 11}, + {L"www.测试.net;", L"http://www.测试.net;", 0, 11}, }; for (size_t i = 0; i < FX_ArraySize(valid_cases); ++i) { - CFX_WideString text_str(valid_cases[i][0]); - EXPECT_TRUE(extractor.CheckWebLink(text_str)) << text_str.c_str(); - EXPECT_STREQ(valid_cases[i][1], text_str.c_str()); + const wchar_t* const input = valid_cases[i].input_string; + CFX_WideString text_str(input); + int32_t start_offset = DEFAULT_VALUE; + int32_t count = DEFAULT_VALUE; + EXPECT_TRUE(extractor.CheckWebLink(&text_str, &start_offset, &count)) + << input; + EXPECT_STREQ(valid_cases[i].url_extracted, text_str.c_str()); + EXPECT_EQ(valid_cases[i].start_offset, start_offset) << input; + EXPECT_EQ(valid_cases[i].count, count) << input; } } diff --git a/chromium/third_party/pdfium/core/fpdftext/cpdf_textpage.cpp b/chromium/third_party/pdfium/core/fpdftext/cpdf_textpage.cpp index 7a493c004d1..b6b3a0dbce5 100644 --- a/chromium/third_party/pdfium/core/fpdftext/cpdf_textpage.cpp +++ b/chromium/third_party/pdfium/core/fpdftext/cpdf_textpage.cpp @@ -108,6 +108,12 @@ float MaskPercentFilled(const std::vector<bool>& mask, } // namespace +PDFTEXT_Obj::PDFTEXT_Obj() {} + +PDFTEXT_Obj::PDFTEXT_Obj(const PDFTEXT_Obj& that) = default; + +PDFTEXT_Obj::~PDFTEXT_Obj() {} + FPDF_CHAR_INFO::FPDF_CHAR_INFO() : m_Unicode(0), m_Charcode(0), @@ -258,10 +264,7 @@ std::vector<CFX_FloatRect> CPDF_TextPage::GetRectArray(int start, CFX_Matrix matrix = info_curchar.m_pTextObj->GetTextMatrix(); matrix.Concat(info_curchar.m_Matrix); - CFX_Matrix matrix_reverse; - matrix_reverse.SetReverse(matrix); - - CFX_PointF origin = matrix_reverse.Transform(info_curchar.m_Origin); + CFX_PointF origin = matrix.GetInverse().Transform(info_curchar.m_Origin); rect.left = info_curchar.m_CharBox.left; rect.right = info_curchar.m_CharBox.right; if (pCurObj->GetFont()->GetTypeDescent()) { @@ -584,7 +587,7 @@ void CPDF_TextPage::ProcessObject() { CFX_Matrix matrix; ProcessTextObject(pObj->AsText(), matrix, pObjList, it); } else if (pObj->IsForm()) { - CFX_Matrix formMatrix(1, 0, 0, 1, 0, 0); + CFX_Matrix formMatrix; ProcessFormObject(pObj->AsForm(), formMatrix); } } @@ -799,7 +802,7 @@ void CPDF_TextPage::ProcessTextObject( } FPDFText_MarkedContent CPDF_TextPage::PreMarkedContent(PDFTEXT_Obj Obj) { - CPDF_TextObject* pTextObj = Obj.m_pTextObj; + CPDF_TextObject* pTextObj = Obj.m_pTextObj.Get(); if (!pTextObj->m_ContentMark.HasRef()) return FPDFText_MarkedContent::Pass; @@ -862,7 +865,7 @@ FPDFText_MarkedContent CPDF_TextPage::PreMarkedContent(PDFTEXT_Obj Obj) { } void CPDF_TextPage::ProcessMarkedContent(PDFTEXT_Obj Obj) { - CPDF_TextObject* pTextObj = Obj.m_pTextObj; + CPDF_TextObject* pTextObj = Obj.m_pTextObj.Get(); if (!pTextObj->m_ContentMark.HasRef()) return; @@ -952,7 +955,7 @@ bool CPDF_TextPage::IsRightToLeft(const CPDF_TextObject* pTextObj, } void CPDF_TextPage::ProcessTextObject(PDFTEXT_Obj Obj) { - CPDF_TextObject* pTextObj = Obj.m_pTextObj; + CPDF_TextObject* pTextObj = Obj.m_pTextObj.Get(); if (fabs(pTextObj->m_Right - pTextObj->m_Left) < 0.01f) return; CFX_Matrix formMatrix = Obj.m_formMatrix; @@ -1300,8 +1303,7 @@ CPDF_TextPage::GenerateCharacter CPDF_TextPage::ProcessInsertObject( CFX_Matrix prev_matrix = m_pPreTextObj->GetTextMatrix(); prev_matrix.Concat(m_perMatrix); - CFX_Matrix prev_reverse; - prev_reverse.SetReverse(prev_matrix); + CFX_Matrix prev_reverse = prev_matrix.GetInverse(); CFX_PointF pos = prev_reverse.Transform(formMatrix.Transform(pObj->GetPos())); if (last_width < this_width) diff --git a/chromium/third_party/pdfium/core/fpdftext/cpdf_textpage.h b/chromium/third_party/pdfium/core/fpdftext/cpdf_textpage.h index a18310667d9..0f507de4aa3 100644 --- a/chromium/third_party/pdfium/core/fpdftext/cpdf_textpage.h +++ b/chromium/third_party/pdfium/core/fpdftext/cpdf_textpage.h @@ -84,7 +84,11 @@ class PAGECHAR_INFO { }; struct PDFTEXT_Obj { - CPDF_TextObject* m_pTextObj; + PDFTEXT_Obj(); + PDFTEXT_Obj(const PDFTEXT_Obj& that); + ~PDFTEXT_Obj(); + + CFX_UnownedPtr<CPDF_TextObject> m_pTextObj; CFX_Matrix m_formMatrix; }; diff --git a/chromium/third_party/pdfium/core/fxcodec/codec/ccodec_bmpmodule.cpp b/chromium/third_party/pdfium/core/fxcodec/codec/ccodec_bmpmodule.cpp index 003f5d3d492..a64e6783e13 100644 --- a/chromium/third_party/pdfium/core/fxcodec/codec/ccodec_bmpmodule.cpp +++ b/chromium/third_party/pdfium/core/fxcodec/codec/ccodec_bmpmodule.cpp @@ -9,123 +9,78 @@ #include "core/fxcodec/codec/codec_int.h" #include "core/fxcodec/fx_codec.h" #include "core/fxcodec/lbmp/fx_bmp.h" +#include "core/fxcrt/cfx_unowned_ptr.h" #include "core/fxge/fx_dib.h" +#include "third_party/base/ptr_util.h" -struct FXBMP_Context { - bmp_decompress_struct_p bmp_ptr; - void* parent_ptr; - - void* (*m_AllocFunc)(unsigned int); - void (*m_FreeFunc)(void*); -}; -extern "C" { -static void* bmp_alloc_func(unsigned int size) { - return FX_Alloc(char, size); -} -static void bmp_free_func(void* p) { - FX_Free(p); -} -}; -static void bmp_error_data(bmp_decompress_struct_p bmp_ptr, - const char* err_msg) { - strncpy((char*)bmp_ptr->err_ptr, err_msg, BMP_MAX_ERROR_SIZE - 1); - longjmp(bmp_ptr->jmpbuf, 1); -} -static void bmp_read_scanline(bmp_decompress_struct_p bmp_ptr, - int32_t row_num, - uint8_t* row_buf) { - FXBMP_Context* p = (FXBMP_Context*)bmp_ptr->context_ptr; - CCodec_BmpModule* pModule = (CCodec_BmpModule*)p->parent_ptr; - pModule->GetDelegate()->BmpReadScanline(row_num, row_buf); -} -static bool bmp_get_data_position(bmp_decompress_struct_p bmp_ptr, - uint32_t rcd_pos) { - FXBMP_Context* p = (FXBMP_Context*)bmp_ptr->context_ptr; - CCodec_BmpModule* pModule = (CCodec_BmpModule*)p->parent_ptr; - return pModule->GetDelegate()->BmpInputImagePositionBuf(rcd_pos); -} - -CCodec_BmpModule::CCodec_BmpModule() { +CBmpContext::CBmpContext(CCodec_BmpModule* pModule, + CCodec_BmpModule::Delegate* pDelegate) + : m_pModule(pModule), m_pDelegate(pDelegate) { memset(m_szLastError, 0, sizeof(m_szLastError)); } -CCodec_BmpModule::~CCodec_BmpModule() {} +CBmpContext::~CBmpContext() {} -FXBMP_Context* CCodec_BmpModule::Start() { - FXBMP_Context* p = FX_Alloc(FXBMP_Context, 1); - if (!p) - return nullptr; +CCodec_BmpModule::CCodec_BmpModule() {} - memset(p, 0, sizeof(FXBMP_Context)); - if (!p) - return nullptr; +CCodec_BmpModule::~CCodec_BmpModule() {} - p->m_AllocFunc = bmp_alloc_func; - p->m_FreeFunc = bmp_free_func; - p->bmp_ptr = nullptr; - p->parent_ptr = this; - p->bmp_ptr = bmp_create_decompress(); - if (!p->bmp_ptr) { - FX_Free(p); - return nullptr; - } - p->bmp_ptr->context_ptr = p; - p->bmp_ptr->err_ptr = m_szLastError; - p->bmp_ptr->bmp_error_fn = bmp_error_data; - p->bmp_ptr->bmp_get_row_fn = bmp_read_scanline; - p->bmp_ptr->bmp_get_data_position_fn = bmp_get_data_position; +std::unique_ptr<CCodec_BmpModule::Context> CCodec_BmpModule::Start( + Delegate* pDelegate) { + auto p = pdfium::MakeUnique<CBmpContext>(this, pDelegate); + p->m_Bmp.context_ptr = p.get(); + p->m_Bmp.err_ptr = p->m_szLastError; return p; } -void CCodec_BmpModule::Finish(FXBMP_Context* ctx) { - if (ctx) { - bmp_destroy_decompress(&ctx->bmp_ptr); - ctx->m_FreeFunc(ctx); - } -} -int32_t CCodec_BmpModule::ReadHeader(FXBMP_Context* ctx, +int32_t CCodec_BmpModule::ReadHeader(Context* pContext, int32_t* width, int32_t* height, bool* tb_flag, int32_t* components, int32_t* pal_num, - uint32_t** pal_pp, + std::vector<uint32_t>* palette, CFX_DIBAttribute* pAttribute) { - if (setjmp(ctx->bmp_ptr->jmpbuf)) { + auto* ctx = static_cast<CBmpContext*>(pContext); + if (setjmp(ctx->m_Bmp.jmpbuf)) return 0; - } - int32_t ret = bmp_read_header(ctx->bmp_ptr); - if (ret != 1) { + + int32_t ret = ctx->m_Bmp.ReadHeader(); + if (ret != 1) return ret; - } - *width = ctx->bmp_ptr->width; - *height = ctx->bmp_ptr->height; - *tb_flag = ctx->bmp_ptr->imgTB_flag; - *components = ctx->bmp_ptr->components; - *pal_num = ctx->bmp_ptr->pal_num; - *pal_pp = ctx->bmp_ptr->pal_ptr; + + *width = ctx->m_Bmp.width; + *height = ctx->m_Bmp.height; + *tb_flag = ctx->m_Bmp.imgTB_flag; + *components = ctx->m_Bmp.components; + *pal_num = ctx->m_Bmp.pal_num; + *palette = ctx->m_Bmp.palette; if (pAttribute) { pAttribute->m_wDPIUnit = FXCODEC_RESUNIT_METER; - pAttribute->m_nXDPI = ctx->bmp_ptr->dpi_x; - pAttribute->m_nYDPI = ctx->bmp_ptr->dpi_y; - pAttribute->m_nBmpCompressType = ctx->bmp_ptr->compress_flag; + pAttribute->m_nXDPI = ctx->m_Bmp.dpi_x; + pAttribute->m_nYDPI = ctx->m_Bmp.dpi_y; + pAttribute->m_nBmpCompressType = ctx->m_Bmp.compress_flag; } return 1; } -int32_t CCodec_BmpModule::LoadImage(FXBMP_Context* ctx) { - if (setjmp(ctx->bmp_ptr->jmpbuf)) +int32_t CCodec_BmpModule::LoadImage(Context* pContext) { + auto* ctx = static_cast<CBmpContext*>(pContext); + if (setjmp(ctx->m_Bmp.jmpbuf)) return 0; - return bmp_decode_image(ctx->bmp_ptr); + + return ctx->m_Bmp.DecodeImage(); } -uint32_t CCodec_BmpModule::GetAvailInput(FXBMP_Context* ctx, +uint32_t CCodec_BmpModule::GetAvailInput(Context* pContext, uint8_t** avail_buf_ptr) { - return bmp_get_avail_input(ctx->bmp_ptr, avail_buf_ptr); + auto* ctx = static_cast<CBmpContext*>(pContext); + return ctx->m_Bmp.GetAvailInput(avail_buf_ptr); } -void CCodec_BmpModule::Input(FXBMP_Context* ctx, +void CCodec_BmpModule::Input(Context* pContext, const uint8_t* src_buf, uint32_t src_size) { - bmp_input_buffer(ctx->bmp_ptr, (uint8_t*)src_buf, src_size); + auto* ctx = static_cast<CBmpContext*>(pContext); + ctx->m_Bmp.SetInputBuffer(const_cast<uint8_t*>(src_buf), src_size); } diff --git a/chromium/third_party/pdfium/core/fxcodec/codec/ccodec_bmpmodule.h b/chromium/third_party/pdfium/core/fxcodec/codec/ccodec_bmpmodule.h index bdf6544251d..e9ad7c30018 100644 --- a/chromium/third_party/pdfium/core/fxcodec/codec/ccodec_bmpmodule.h +++ b/chromium/third_party/pdfium/core/fxcodec/codec/ccodec_bmpmodule.h @@ -7,43 +7,43 @@ #ifndef CORE_FXCODEC_CODEC_CCODEC_BMPMODULE_H_ #define CORE_FXCODEC_CODEC_CCODEC_BMPMODULE_H_ +#include <memory> +#include <vector> + +#include "core/fxcrt/cfx_unowned_ptr.h" #include "core/fxcrt/fx_system.h" class CFX_DIBAttribute; -struct FXBMP_Context; class CCodec_BmpModule { public: + class Context { + public: + virtual ~Context() {} + }; + class Delegate { public: virtual bool BmpInputImagePositionBuf(uint32_t rcd_pos) = 0; - virtual void BmpReadScanline(int32_t row_num, uint8_t* row_buf) = 0; + virtual void BmpReadScanline(uint32_t row_num, + const std::vector<uint8_t>& row_buf) = 0; }; CCodec_BmpModule(); ~CCodec_BmpModule(); - FXBMP_Context* Start(); - void Finish(FXBMP_Context* pContext); - uint32_t GetAvailInput(FXBMP_Context* pContext, uint8_t** avail_buf_ptr); - void Input(FXBMP_Context* pContext, - const uint8_t* src_buf, - uint32_t src_size); - int32_t ReadHeader(FXBMP_Context* pContext, + std::unique_ptr<Context> Start(Delegate* pDelegate); + uint32_t GetAvailInput(Context* pContext, uint8_t** avail_buf_ptr); + void Input(Context* pContext, const uint8_t* src_buf, uint32_t src_size); + int32_t ReadHeader(Context* pContext, int32_t* width, int32_t* height, bool* tb_flag, int32_t* components, int32_t* pal_num, - uint32_t** pal_pp, + std::vector<uint32_t>* palette, CFX_DIBAttribute* pAttribute); - int32_t LoadImage(FXBMP_Context* pContext); - Delegate* GetDelegate() const { return m_pDelegate; } - void SetDelegate(Delegate* pDelegate) { m_pDelegate = pDelegate; } - - protected: - Delegate* m_pDelegate; - char m_szLastError[256]; + int32_t LoadImage(Context* pContext); }; #endif // CORE_FXCODEC_CODEC_CCODEC_BMPMODULE_H_ diff --git a/chromium/third_party/pdfium/core/fxcodec/codec/ccodec_flatemodule.h b/chromium/third_party/pdfium/core/fxcodec/codec/ccodec_flatemodule.h index 5178943ca0c..ae34103f3bd 100644 --- a/chromium/third_party/pdfium/core/fxcodec/codec/ccodec_flatemodule.h +++ b/chromium/third_party/pdfium/core/fxcodec/codec/ccodec_flatemodule.h @@ -34,12 +34,14 @@ class CCodec_FlateModule { int BitsPerComponent, int Columns, uint32_t estimated_size, - uint8_t*& dest_buf, - uint32_t& dest_size); + uint8_t** dest_buf, + uint32_t* dest_size); + bool Encode(const uint8_t* src_buf, uint32_t src_size, uint8_t** dest_buf, uint32_t* dest_size); + bool PngEncode(const uint8_t* src_buf, uint32_t src_size, uint8_t** dest_buf, diff --git a/chromium/third_party/pdfium/core/fxcodec/codec/ccodec_gifmodule.cpp b/chromium/third_party/pdfium/core/fxcodec/codec/ccodec_gifmodule.cpp index 11980ee7a59..757019314da 100644 --- a/chromium/third_party/pdfium/core/fxcodec/codec/ccodec_gifmodule.cpp +++ b/chromium/third_party/pdfium/core/fxcodec/codec/ccodec_gifmodule.cpp @@ -13,23 +13,23 @@ #include "core/fxge/fx_dib.h" #include "third_party/base/ptr_util.h" -CCodec_GifModule::CCodec_GifModule() { - memset(m_szLastError, 0, sizeof(m_szLastError)); -} +CCodec_GifModule::CCodec_GifModule() {} CCodec_GifModule::~CCodec_GifModule() {} -std::unique_ptr<CGifContext> CCodec_GifModule::Start() { - return pdfium::MakeUnique<CGifContext>(this, m_szLastError); +std::unique_ptr<CCodec_GifModule::Context> CCodec_GifModule::Start( + Delegate* pDelegate) { + return pdfium::MakeUnique<CGifContext>(this, pDelegate); } -GifDecodeStatus CCodec_GifModule::ReadHeader(CGifContext* context, +GifDecodeStatus CCodec_GifModule::ReadHeader(Context* pContext, int* width, int* height, int* pal_num, void** pal_pp, int* bg_index, CFX_DIBAttribute* pAttribute) { + auto* context = static_cast<CGifContext*>(pContext); GifDecodeStatus ret = gif_read_header(context); if (ret != GifDecodeStatus::Success) return ret; @@ -43,8 +43,9 @@ GifDecodeStatus CCodec_GifModule::ReadHeader(CGifContext* context, return GifDecodeStatus::Success; } -GifDecodeStatus CCodec_GifModule::LoadFrameInfo(CGifContext* context, +GifDecodeStatus CCodec_GifModule::LoadFrameInfo(Context* pContext, int* frame_num) { + auto* context = static_cast<CGifContext*>(pContext); GifDecodeStatus ret = gif_get_frame(context); if (ret != GifDecodeStatus::Success) return ret; @@ -53,9 +54,10 @@ GifDecodeStatus CCodec_GifModule::LoadFrameInfo(CGifContext* context, return GifDecodeStatus::Success; } -GifDecodeStatus CCodec_GifModule::LoadFrame(CGifContext* context, +GifDecodeStatus CCodec_GifModule::LoadFrame(Context* pContext, int frame_num, CFX_DIBAttribute* pAttribute) { + auto* context = static_cast<CGifContext*>(pContext); GifDecodeStatus ret = gif_load_frame(context, frame_num); if (ret != GifDecodeStatus::Success || !pAttribute) return ret; @@ -76,13 +78,15 @@ GifDecodeStatus CCodec_GifModule::LoadFrame(CGifContext* context, return GifDecodeStatus::Success; } -uint32_t CCodec_GifModule::GetAvailInput(CGifContext* context, +uint32_t CCodec_GifModule::GetAvailInput(Context* pContext, uint8_t** avail_buf_ptr) { + auto* context = static_cast<CGifContext*>(pContext); return gif_get_avail_input(context, avail_buf_ptr); } -void CCodec_GifModule::Input(CGifContext* context, +void CCodec_GifModule::Input(Context* pContext, const uint8_t* src_buf, uint32_t src_size) { + auto* context = static_cast<CGifContext*>(pContext); gif_input_buffer(context, (uint8_t*)src_buf, src_size); } diff --git a/chromium/third_party/pdfium/core/fxcodec/codec/ccodec_gifmodule.h b/chromium/third_party/pdfium/core/fxcodec/codec/ccodec_gifmodule.h index 5f3f45f83f4..fe1c46478db 100644 --- a/chromium/third_party/pdfium/core/fxcodec/codec/ccodec_gifmodule.h +++ b/chromium/third_party/pdfium/core/fxcodec/codec/ccodec_gifmodule.h @@ -17,6 +17,11 @@ class CFX_DIBAttribute; class CCodec_GifModule { public: + class Context { + public: + virtual ~Context() {} + }; + class Delegate { public: virtual void GifRecordCurrentPosition(uint32_t& cur_pos) = 0; @@ -35,31 +40,20 @@ class CCodec_GifModule { CCodec_GifModule(); ~CCodec_GifModule(); - std::unique_ptr<CGifContext> Start(); - uint32_t GetAvailInput(CGifContext* context, - uint8_t** avail_buf_ptr = nullptr); - - void Input(CGifContext* context, const uint8_t* src_buf, uint32_t src_size); - - GifDecodeStatus ReadHeader(CGifContext* context, + std::unique_ptr<Context> Start(Delegate* pDelegate); + uint32_t GetAvailInput(Context* context, uint8_t** avail_buf_ptr = nullptr); + void Input(Context* context, const uint8_t* src_buf, uint32_t src_size); + GifDecodeStatus ReadHeader(Context* context, int* width, int* height, int* pal_num, void** pal_pp, int* bg_index, CFX_DIBAttribute* pAttribute); - - GifDecodeStatus LoadFrameInfo(CGifContext* context, int* frame_num); - GifDecodeStatus LoadFrame(CGifContext* context, + GifDecodeStatus LoadFrameInfo(Context* context, int* frame_num); + GifDecodeStatus LoadFrame(Context* context, int frame_num, CFX_DIBAttribute* pAttribute); - - Delegate* GetDelegate() const { return m_pDelegate; } - void SetDelegate(Delegate* pDelegate) { m_pDelegate = pDelegate; } - - protected: - Delegate* m_pDelegate; - char m_szLastError[256]; }; #endif // CORE_FXCODEC_CODEC_CCODEC_GIFMODULE_H_ diff --git a/chromium/third_party/pdfium/core/fxcodec/codec/ccodec_iccmodule.h b/chromium/third_party/pdfium/core/fxcodec/codec/ccodec_iccmodule.h index 08878acc988..e775475249c 100644 --- a/chromium/third_party/pdfium/core/fxcodec/codec/ccodec_iccmodule.h +++ b/chromium/third_party/pdfium/core/fxcodec/codec/ccodec_iccmodule.h @@ -7,23 +7,41 @@ #ifndef CORE_FXCODEC_CODEC_CCODEC_ICCMODULE_H_ #define CORE_FXCODEC_CODEC_CCODEC_ICCMODULE_H_ +#include <memory> + #include "core/fxcodec/fx_codec_def.h" #include "core/fxcrt/fx_string.h" #include "core/fxcrt/fx_system.h" +#include "third_party/base/ptr_util.h" + +#if defined(USE_SYSTEM_LCMS2) +#include <lcms2.h> +#else +#include "third_party/lcms2-2.6/include/lcms2.h" +#endif + +class CLcmsCmm { + public: + CLcmsCmm(int srcComponents, cmsHTRANSFORM transform, bool isLab); + ~CLcmsCmm(); + + cmsHTRANSFORM m_hTransform; + int m_nSrcComponents; + bool m_bLab; +}; class CCodec_IccModule { public: CCodec_IccModule(); ~CCodec_IccModule(); - void* CreateTransform_sRGB(const uint8_t* pProfileData, - uint32_t dwProfileSize, - uint32_t& nComponents, - int32_t intent = 0, - uint32_t dwSrcFormat = Icc_FORMAT_DEFAULT); - void DestroyTransform(void* pTransform); - void Translate(void* pTransform, const float* pSrcValues, float* pDestValues); - void TranslateScanline(void* pTransform, + std::unique_ptr<CLcmsCmm> CreateTransform_sRGB(const uint8_t* pProfileData, + uint32_t dwProfileSize, + uint32_t* nComponents); + void Translate(CLcmsCmm* pTransform, + const float* pSrcValues, + float* pDestValues); + void TranslateScanline(CLcmsCmm* pTransform, uint8_t* pDest, const uint8_t* pSrc, int pixels); diff --git a/chromium/third_party/pdfium/core/fxcodec/codec/ccodec_jbig2module.h b/chromium/third_party/pdfium/core/fxcodec/codec/ccodec_jbig2module.h index 43abe042f02..b80d78f6053 100644 --- a/chromium/third_party/pdfium/core/fxcodec/codec/ccodec_jbig2module.h +++ b/chromium/third_party/pdfium/core/fxcodec/codec/ccodec_jbig2module.h @@ -29,7 +29,6 @@ class CCodec_Jbig2Context { CFX_RetainPtr<CPDF_StreamAcc> m_pSrcStream; uint8_t* m_dest_buf; uint32_t m_dest_pitch; - IFX_Pause* m_pPause; std::unique_ptr<CJBig2_Context> m_pContext; }; diff --git a/chromium/third_party/pdfium/core/fxcodec/codec/ccodec_jpegmodule.h b/chromium/third_party/pdfium/core/fxcodec/codec/ccodec_jpegmodule.h index 7782b5fad13..a5837177f2a 100644 --- a/chromium/third_party/pdfium/core/fxcodec/codec/ccodec_jpegmodule.h +++ b/chromium/third_party/pdfium/core/fxcodec/codec/ccodec_jpegmodule.h @@ -9,11 +9,11 @@ #include <memory> +#include "core/fxcrt/cfx_retain_ptr.h" #include "core/fxcrt/fx_system.h" class CCodec_ScanlineDecoder; class CFX_DIBSource; -struct FXJPEG_Context; #ifdef PDF_ENABLE_XFA class CFX_DIBAttribute; @@ -21,7 +21,10 @@ class CFX_DIBAttribute; class CCodec_JpegModule { public: - CCodec_JpegModule() {} + class Context { + public: + virtual ~Context() {} + }; std::unique_ptr<CCodec_ScanlineDecoder> CreateDecoder(const uint8_t* src_buf, uint32_t src_size, @@ -36,28 +39,23 @@ class CCodec_JpegModule { int* num_components, int* bits_per_components, bool* color_transform); - FXJPEG_Context* Start(); - void Finish(FXJPEG_Context* pContext); - void Input(FXJPEG_Context* pContext, - const uint8_t* src_buf, - uint32_t src_size); + + std::unique_ptr<Context> Start(); + void Input(Context* pContext, const uint8_t* src_buf, uint32_t src_size); #ifndef PDF_ENABLE_XFA - int ReadHeader(FXJPEG_Context* pContext, - int* width, - int* height, - int* nComps); + int ReadHeader(Context* pContext, int* width, int* height, int* nComps); #else // PDF_ENABLE_XFA - int ReadHeader(FXJPEG_Context* pContext, + int ReadHeader(Context* pContext, int* width, int* height, int* nComps, CFX_DIBAttribute* pAttribute); #endif // PDF_ENABLE_XFA - bool StartScanline(FXJPEG_Context* pContext, int down_scale); - bool ReadScanline(FXJPEG_Context* pContext, uint8_t* dest_buf); - uint32_t GetAvailInput(FXJPEG_Context* pContext, uint8_t** avail_buf_ptr); + bool StartScanline(Context* pContext, int down_scale); + bool ReadScanline(Context* pContext, uint8_t* dest_buf); + uint32_t GetAvailInput(Context* pContext, uint8_t** avail_buf_ptr); #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_DESKTOP_ static bool JpegEncode(const CFX_RetainPtr<CFX_DIBSource>& pSource, diff --git a/chromium/third_party/pdfium/core/fxcodec/codec/ccodec_pngmodule.cpp b/chromium/third_party/pdfium/core/fxcodec/codec/ccodec_pngmodule.cpp index 5529eae5629..8a3de3a1540 100644 --- a/chromium/third_party/pdfium/core/fxcodec/codec/ccodec_pngmodule.cpp +++ b/chromium/third_party/pdfium/core/fxcodec/codec/ccodec_pngmodule.cpp @@ -10,20 +10,42 @@ #include "core/fxcodec/codec/codec_int.h" #include "core/fxcodec/fx_codec.h" +#include "core/fxcrt/cfx_unowned_ptr.h" #include "core/fxge/fx_dib.h" +#include "third_party/base/ptr_util.h" extern "C" { #undef FAR #include "third_party/libpng16/png.h" -} +} // extern "C" + +#define PNG_ERROR_SIZE 256 + +class CPngContext : public CCodec_PngModule::Context { + public: + CPngContext(CCodec_PngModule* pModule, CCodec_PngModule::Delegate* pDelegate); + ~CPngContext() override; + + png_structp m_pPng; + png_infop m_pInfo; + CFX_UnownedPtr<CCodec_PngModule> m_pModule; + CFX_UnownedPtr<CCodec_PngModule::Delegate> m_pDelegate; + void* (*m_AllocFunc)(unsigned int); + void (*m_FreeFunc)(void*); + char m_szLastError[PNG_ERROR_SIZE]; +}; + +extern "C" { static void _png_error_data(png_structp png_ptr, png_const_charp error_msg) { - if (png_get_error_ptr(png_ptr)) { + if (png_get_error_ptr(png_ptr)) strncpy((char*)png_get_error_ptr(png_ptr), error_msg, PNG_ERROR_SIZE - 1); - } + longjmp(png_jmpbuf(png_ptr), 1); } + static void _png_warning_data(png_structp png_ptr, png_const_charp error_msg) {} + static void _png_load_bmp_attribute(png_structp png_ptr, png_infop info_ptr, CFX_DIBAttribute* pAttribute) { @@ -72,61 +94,52 @@ static void _png_load_bmp_attribute(png_structp png_ptr, #endif } } -struct FXPNG_Context { - png_structp png_ptr; - png_infop info_ptr; - void* parent_ptr; - void* (*m_AllocFunc)(unsigned int); - void (*m_FreeFunc)(void*); -}; -extern "C" { static void* _png_alloc_func(unsigned int size) { return FX_Alloc(char, size); } + static void _png_free_func(void* p) { FX_Free(p); } -}; -static void _png_get_header_func(png_structp png_ptr, png_infop info_ptr) { - FXPNG_Context* p = (FXPNG_Context*)png_get_progressive_ptr(png_ptr); - if (!p) - return; - CCodec_PngModule* pModule = (CCodec_PngModule*)p->parent_ptr; - if (!pModule) +static void _png_get_header_func(png_structp png_ptr, png_infop info_ptr) { + auto* pContext = + reinterpret_cast<CPngContext*>(png_get_progressive_ptr(png_ptr)); + if (!pContext) return; - png_uint_32 width = 0, height = 0; - int bpc = 0, color_type = 0, color_type1 = 0, pass = 0; - double gamma = 1.0; + png_uint_32 width = 0; + png_uint_32 height = 0; + int bpc = 0; + int color_type = 0; png_get_IHDR(png_ptr, info_ptr, &width, &height, &bpc, &color_type, nullptr, nullptr, nullptr); - color_type1 = color_type; - if (bpc > 8) { + int color_type1 = color_type; + if (bpc > 8) png_set_strip_16(png_ptr); - } else if (bpc < 8) { + else if (bpc < 8) png_set_expand_gray_1_2_4_to_8(png_ptr); - } + bpc = 8; - if (color_type == PNG_COLOR_TYPE_PALETTE) { + if (color_type == PNG_COLOR_TYPE_PALETTE) png_set_palette_to_rgb(png_ptr); - } - pass = png_set_interlace_handling(png_ptr); - if (!pModule->GetDelegate()->PngReadHeader(width, height, bpc, pass, - &color_type, &gamma)) { - png_error(p->png_ptr, "Read Header Callback Error"); + + int pass = png_set_interlace_handling(png_ptr); + double gamma = 1.0; + if (!pContext->m_pDelegate->PngReadHeader(width, height, bpc, pass, + &color_type, &gamma)) { + png_error(pContext->m_pPng, "Read Header Callback Error"); } int intent; if (png_get_sRGB(png_ptr, info_ptr, &intent)) { png_set_gamma(png_ptr, gamma, 0.45455); } else { double image_gamma; - if (png_get_gAMA(png_ptr, info_ptr, &image_gamma)) { + if (png_get_gAMA(png_ptr, info_ptr, &image_gamma)) png_set_gamma(png_ptr, gamma, image_gamma); - } else { + else png_set_gamma(png_ptr, gamma, 0.45455); - } } switch (color_type) { case PNG_COLOR_TYPE_GRAY: @@ -137,7 +150,7 @@ static void _png_get_header_func(png_structp png_ptr, png_infop info_ptr) { } break; case PNG_COLOR_TYPE_PALETTE: if (color_type1 != PNG_COLOR_TYPE_PALETTE) { - png_error(p->png_ptr, "Not Support Output Palette Now"); + png_error(pContext->m_pPng, "Not Support Output Palette Now"); } case PNG_COLOR_TYPE_RGB: case PNG_COLOR_TYPE_RGB_ALPHA: @@ -147,95 +160,89 @@ static void _png_get_header_func(png_structp png_ptr, png_infop info_ptr) { png_set_bgr(png_ptr); break; } - if (!(color_type & PNG_COLOR_MASK_ALPHA)) { + if (!(color_type & PNG_COLOR_MASK_ALPHA)) png_set_strip_alpha(png_ptr); - } + if (color_type & PNG_COLOR_MASK_ALPHA && !(color_type1 & PNG_COLOR_MASK_ALPHA)) { png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER); } png_read_update_info(png_ptr, info_ptr); } + static void _png_get_end_func(png_structp png_ptr, png_infop info_ptr) {} + static void _png_get_row_func(png_structp png_ptr, png_bytep new_row, png_uint_32 row_num, int pass) { - FXPNG_Context* p = (FXPNG_Context*)png_get_progressive_ptr(png_ptr); - if (!p) + auto* pContext = + reinterpret_cast<CPngContext*>(png_get_progressive_ptr(png_ptr)); + if (!pContext) return; - CCodec_PngModule* pModule = (CCodec_PngModule*)p->parent_ptr; uint8_t* src_buf = nullptr; - if (!pModule->GetDelegate()->PngAskScanlineBuf(row_num, src_buf)) { + if (!pContext->m_pDelegate->PngAskScanlineBuf(row_num, src_buf)) png_error(png_ptr, "Ask Scanline buffer Callback Error"); - } - if (src_buf) { + + if (src_buf) png_progressive_combine_row(png_ptr, src_buf, new_row); - } - pModule->GetDelegate()->PngFillScanlineBufCompleted(pass, row_num); + + pContext->m_pDelegate->PngFillScanlineBufCompleted(pass, row_num); } -CCodec_PngModule::CCodec_PngModule() { +} // extern "C" + +CPngContext::CPngContext(CCodec_PngModule* pModule, + CCodec_PngModule::Delegate* pDelegate) + : m_pPng(nullptr), + m_pInfo(nullptr), + m_pModule(pModule), + m_pDelegate(pDelegate), + m_AllocFunc(_png_alloc_func), + m_FreeFunc(_png_free_func) { memset(m_szLastError, 0, sizeof(m_szLastError)); } -CCodec_PngModule::~CCodec_PngModule() {} - -FXPNG_Context* CCodec_PngModule::Start() { - FXPNG_Context* p = FX_Alloc(FXPNG_Context, 1); - if (!p) - return nullptr; +CPngContext::~CPngContext() { + png_destroy_read_struct(m_pPng ? &m_pPng : nullptr, + m_pInfo ? &m_pInfo : nullptr, nullptr); +} - p->m_AllocFunc = _png_alloc_func; - p->m_FreeFunc = _png_free_func; - p->png_ptr = nullptr; - p->info_ptr = nullptr; - p->parent_ptr = this; - p->png_ptr = +std::unique_ptr<CCodec_PngModule::Context> CCodec_PngModule::Start( + Delegate* pDelegate) { + auto p = pdfium::MakeUnique<CPngContext>(this, pDelegate); + p->m_pPng = png_create_read_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr); - if (!p->png_ptr) { - FX_Free(p); + if (!p->m_pPng) return nullptr; - } - p->info_ptr = png_create_info_struct(p->png_ptr); - if (!p->info_ptr) { - png_destroy_read_struct(&(p->png_ptr), nullptr, nullptr); - FX_Free(p); + + p->m_pInfo = png_create_info_struct(p->m_pPng); + if (!p->m_pInfo) return nullptr; - } - if (setjmp(png_jmpbuf(p->png_ptr))) { - if (p) { - png_destroy_read_struct(&(p->png_ptr), &(p->info_ptr), nullptr); - FX_Free(p); - } + + if (setjmp(png_jmpbuf(p->m_pPng))) return nullptr; - } - png_set_progressive_read_fn(p->png_ptr, p, _png_get_header_func, + + png_set_progressive_read_fn(p->m_pPng, p.get(), _png_get_header_func, _png_get_row_func, _png_get_end_func); - png_set_error_fn(p->png_ptr, m_szLastError, (png_error_ptr)_png_error_data, - (png_error_ptr)_png_warning_data); + png_set_error_fn(p->m_pPng, p->m_szLastError, _png_error_data, + _png_warning_data); return p; } -void CCodec_PngModule::Finish(FXPNG_Context* ctx) { - if (ctx) { - png_destroy_read_struct(&(ctx->png_ptr), &(ctx->info_ptr), nullptr); - ctx->m_FreeFunc(ctx); - } -} - -bool CCodec_PngModule::Input(FXPNG_Context* ctx, +bool CCodec_PngModule::Input(Context* pContext, const uint8_t* src_buf, uint32_t src_size, CFX_DIBAttribute* pAttribute) { - if (setjmp(png_jmpbuf(ctx->png_ptr))) { + auto* ctx = static_cast<CPngContext*>(pContext); + if (setjmp(png_jmpbuf(ctx->m_pPng))) { if (pAttribute && - 0 == strcmp(m_szLastError, "Read Header Callback Error")) { - _png_load_bmp_attribute(ctx->png_ptr, ctx->info_ptr, pAttribute); + strcmp(ctx->m_szLastError, "Read Header Callback Error") == 0) { + _png_load_bmp_attribute(ctx->m_pPng, ctx->m_pInfo, pAttribute); } return false; } - png_process_data(ctx->png_ptr, ctx->info_ptr, (uint8_t*)src_buf, src_size); + png_process_data(ctx->m_pPng, ctx->m_pInfo, (uint8_t*)src_buf, src_size); return true; } diff --git a/chromium/third_party/pdfium/core/fxcodec/codec/ccodec_pngmodule.h b/chromium/third_party/pdfium/core/fxcodec/codec/ccodec_pngmodule.h index f0a08db66c8..121e646a86e 100644 --- a/chromium/third_party/pdfium/core/fxcodec/codec/ccodec_pngmodule.h +++ b/chromium/third_party/pdfium/core/fxcodec/codec/ccodec_pngmodule.h @@ -7,15 +7,19 @@ #ifndef CORE_FXCODEC_CODEC_CCODEC_PNGMODULE_H_ #define CORE_FXCODEC_CODEC_CCODEC_PNGMODULE_H_ +#include <memory> + #include "core/fxcrt/fx_system.h" class CFX_DIBAttribute; -struct FXPNG_Context; - -#define PNG_ERROR_SIZE 256 class CCodec_PngModule { public: + class Context { + public: + virtual ~Context() {} + }; + class Delegate { public: virtual bool PngReadHeader(int width, @@ -28,22 +32,11 @@ class CCodec_PngModule { virtual void PngFillScanlineBufCompleted(int pass, int line) = 0; }; - CCodec_PngModule(); - ~CCodec_PngModule(); - - FXPNG_Context* Start(); - void Finish(FXPNG_Context* pContext); - bool Input(FXPNG_Context* pContext, + std::unique_ptr<Context> Start(Delegate* pDelegate); + bool Input(Context* pContext, const uint8_t* src_buf, uint32_t src_size, CFX_DIBAttribute* pAttribute); - - Delegate* GetDelegate() const { return m_pDelegate; } - void SetDelegate(Delegate* delegate) { m_pDelegate = delegate; } - - protected: - Delegate* m_pDelegate; - char m_szLastError[PNG_ERROR_SIZE]; }; #endif // CORE_FXCODEC_CODEC_CCODEC_PNGMODULE_H_ diff --git a/chromium/third_party/pdfium/core/fxcodec/codec/ccodec_progressivedecoder.h b/chromium/third_party/pdfium/core/fxcodec/codec/ccodec_progressivedecoder.h index 2b343b7e949..4417e478241 100644 --- a/chromium/third_party/pdfium/core/fxcodec/codec/ccodec_progressivedecoder.h +++ b/chromium/third_party/pdfium/core/fxcodec/codec/ccodec_progressivedecoder.h @@ -12,19 +12,18 @@ #include "core/fxcodec/codec/ccodec_bmpmodule.h" #include "core/fxcodec/codec/ccodec_gifmodule.h" +#include "core/fxcodec/codec/ccodec_jpegmodule.h" #include "core/fxcodec/codec/ccodec_pngmodule.h" #include "core/fxcodec/codec/ccodec_tiffmodule.h" #include "core/fxcodec/fx_codec_def.h" -#include "core/fxcodec/lgif/cgifcontext.h" #include "core/fxcrt/cfx_retain_ptr.h" +#include "core/fxcrt/cfx_unowned_ptr.h" #include "core/fxcrt/fx_system.h" #include "core/fxge/fx_dib.h" -class CCodec_JpegModule; class CCodec_ModuleMgr; class CFX_DIBAttribute; class IFX_SeekableReadStream; -struct FXJPEG_Context; class CCodec_ProgressiveDecoder : public CCodec_BmpModule::Delegate, public CCodec_GifModule::Delegate, @@ -126,49 +125,6 @@ class CCodec_ProgressiveDecoder : public CCodec_BmpModule::Delegate, std::vector<uint8_t> m_pWeightTables; }; - CFX_RetainPtr<IFX_SeekableReadStream> m_pFile; - CCodec_ModuleMgr* m_pCodecMgr; - FXJPEG_Context* m_pJpegContext; - FXPNG_Context* m_pPngContext; - std::unique_ptr<CGifContext> m_pGifContext; - FXBMP_Context* m_pBmpContext; - CCodec_TiffContext* m_pTiffContext; - FXCODEC_IMAGE_TYPE m_imagType; - uint32_t m_offSet; - uint8_t* m_pSrcBuf; - uint32_t m_SrcSize; - uint8_t* m_pDecodeBuf; - int m_ScanlineSize; - CFX_RetainPtr<CFX_DIBitmap> m_pDeviceBitmap; - bool m_bInterpol; - CFXCODEC_WeightTable m_WeightHorz; - CFXCODEC_VertTable m_WeightVert; - CFXCODEC_HorzTable m_WeightHorzOO; - int m_SrcWidth; - int m_SrcHeight; - int m_SrcComponents; - int m_SrcBPC; - FX_RECT m_clipBox; - int m_startX; - int m_startY; - int m_sizeX; - int m_sizeY; - int m_TransMethod; - FX_ARGB* m_pSrcPalette; - int m_SrcPaletteNumber; - int m_SrcRow; - FXCodec_Format m_SrcFormat; - int m_SrcPassNumber; - int m_FrameNumber; - int m_FrameCur; - int m_GifBgIndex; - uint8_t* m_pGifPalette; - int32_t m_GifPltNumber; - int m_GifTransIndex; - FX_RECT m_GifFrameRect; - bool m_BmpIsTopBottom; - FXCODEC_STATUS m_status; - // CCodec_PngModule::Delegate bool PngReadHeader(int width, int height, @@ -194,9 +150,10 @@ class CCodec_ProgressiveDecoder : public CCodec_BmpModule::Delegate, // CCodec_BmpModule::Delegate bool BmpInputImagePositionBuf(uint32_t rcd_pos) override; - void BmpReadScanline(int32_t row_num, uint8_t* row_buf) override; + void BmpReadScanline(uint32_t row_num, + const std::vector<uint8_t>& row_buf) override; - protected: + private: bool BmpReadMoreData(CCodec_BmpModule* pBmpModule, FXCODEC_STATUS& err_status); bool GifReadMoreData(CCodec_GifModule* pGifModule, @@ -230,6 +187,49 @@ class CCodec_ProgressiveDecoder : public CCodec_BmpModule::Delegate, void ResampleVertBT(const CFX_RetainPtr<CFX_DIBitmap>& pDeviceBitmap, double scale_y, int des_row); + + CFX_RetainPtr<IFX_SeekableReadStream> m_pFile; + CFX_RetainPtr<CFX_DIBitmap> m_pDeviceBitmap; + CFX_UnownedPtr<CCodec_ModuleMgr> m_pCodecMgr; + std::unique_ptr<CCodec_JpegModule::Context> m_pJpegContext; + std::unique_ptr<CCodec_PngModule::Context> m_pPngContext; + std::unique_ptr<CCodec_GifModule::Context> m_pGifContext; + std::unique_ptr<CCodec_BmpModule::Context> m_pBmpContext; + std::unique_ptr<CCodec_TiffModule::Context> m_pTiffContext; + FXCODEC_IMAGE_TYPE m_imagType; + uint32_t m_offSet; + uint8_t* m_pSrcBuf; + uint32_t m_SrcSize; + uint8_t* m_pDecodeBuf; + int m_ScanlineSize; + bool m_bInterpol; + CFXCODEC_WeightTable m_WeightHorz; + CFXCODEC_VertTable m_WeightVert; + CFXCODEC_HorzTable m_WeightHorzOO; + int m_SrcWidth; + int m_SrcHeight; + int m_SrcComponents; + int m_SrcBPC; + FX_RECT m_clipBox; + int m_startX; + int m_startY; + int m_sizeX; + int m_sizeY; + int m_TransMethod; + FX_ARGB* m_pSrcPalette; + int m_SrcPaletteNumber; + int m_SrcRow; + FXCodec_Format m_SrcFormat; + int m_SrcPassNumber; + int m_FrameNumber; + int m_FrameCur; + int m_GifBgIndex; + uint8_t* m_pGifPalette; + int32_t m_GifPltNumber; + int m_GifTransIndex; + FX_RECT m_GifFrameRect; + bool m_BmpIsTopBottom; + FXCODEC_STATUS m_status; }; #endif // CORE_FXCODEC_CODEC_CCODEC_PROGRESSIVEDECODER_H_ diff --git a/chromium/third_party/pdfium/core/fxcodec/codec/ccodec_tiffmodule.cpp b/chromium/third_party/pdfium/core/fxcodec/codec/ccodec_tiffmodule.cpp index 6ead576ce8b..1f101061b48 100644 --- a/chromium/third_party/pdfium/core/fxcodec/codec/ccodec_tiffmodule.cpp +++ b/chromium/third_party/pdfium/core/fxcodec/codec/ccodec_tiffmodule.cpp @@ -21,10 +21,10 @@ extern "C" { #include "third_party/libtiff/tiffiop.h" } -class CCodec_TiffContext { +class CTiffContext : public CCodec_TiffModule::Context { public: - CCodec_TiffContext(); - ~CCodec_TiffContext(); + CTiffContext(); + ~CTiffContext() override; bool InitDecoder(const CFX_RetainPtr<IFX_SeekableReadStream>& file_ptr); bool LoadFrameInfo(int32_t frame, @@ -101,8 +101,7 @@ TIFFErrorHandler _TIFFerrorHandler = nullptr; namespace { tsize_t tiff_read(thandle_t context, tdata_t buf, tsize_t length) { - CCodec_TiffContext* pTiffContext = - reinterpret_cast<CCodec_TiffContext*>(context); + CTiffContext* pTiffContext = reinterpret_cast<CTiffContext*>(context); FX_SAFE_UINT32 increment = pTiffContext->offset(); increment += length; if (!increment.IsValid()) @@ -125,8 +124,7 @@ tsize_t tiff_write(thandle_t context, tdata_t buf, tsize_t length) { } toff_t tiff_seek(thandle_t context, toff_t offset, int whence) { - CCodec_TiffContext* pTiffContext = - reinterpret_cast<CCodec_TiffContext*>(context); + CTiffContext* pTiffContext = reinterpret_cast<CTiffContext*>(context); FX_SAFE_FILESIZE safe_offset = offset; if (!safe_offset.IsValid()) return static_cast<toff_t>(-1); @@ -163,8 +161,7 @@ int tiff_close(thandle_t context) { } toff_t tiff_get_size(thandle_t context) { - CCodec_TiffContext* pTiffContext = - reinterpret_cast<CCodec_TiffContext*>(context); + CTiffContext* pTiffContext = reinterpret_cast<CTiffContext*>(context); return static_cast<toff_t>(pTiffContext->io_in()->GetSize()); } @@ -221,27 +218,27 @@ void TiffBGRA2RGBA(uint8_t* pBuf, int32_t pixel, int32_t spp) { } // namespace -CCodec_TiffContext::CCodec_TiffContext() +CTiffContext::CTiffContext() : m_io_in(nullptr), m_offset(0), m_tif_ctx(nullptr) {} -CCodec_TiffContext::~CCodec_TiffContext() { +CTiffContext::~CTiffContext() { if (m_tif_ctx) TIFFClose(m_tif_ctx); } -bool CCodec_TiffContext::InitDecoder( +bool CTiffContext::InitDecoder( const CFX_RetainPtr<IFX_SeekableReadStream>& file_ptr) { m_io_in = file_ptr; m_tif_ctx = tiff_open(this, "r"); return !!m_tif_ctx; } -bool CCodec_TiffContext::LoadFrameInfo(int32_t frame, - int32_t* width, - int32_t* height, - int32_t* comps, - int32_t* bpc, - CFX_DIBAttribute* pAttribute) { +bool CTiffContext::LoadFrameInfo(int32_t frame, + int32_t* width, + int32_t* height, + int32_t* comps, + int32_t* bpc, + CFX_DIBAttribute* pAttribute) { if (!TIFFSetDirectory(m_tif_ctx, (uint16)frame)) return false; @@ -293,7 +290,7 @@ bool CCodec_TiffContext::LoadFrameInfo(int32_t frame, return true; } -bool CCodec_TiffContext::IsSupport( +bool CTiffContext::IsSupport( const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap) const { if (TIFFIsTiled(m_tif_ctx)) return false; @@ -324,9 +321,8 @@ bool CCodec_TiffContext::IsSupport( return planarconfig != PLANARCONFIG_SEPARATE; } -void CCodec_TiffContext::SetPalette( - const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap, - uint16_t bps) { +void CTiffContext::SetPalette(const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap, + uint16_t bps) { uint16_t* red_orig = nullptr; uint16_t* green_orig = nullptr; uint16_t* blue_orig = nullptr; @@ -349,12 +345,11 @@ void CCodec_TiffContext::SetPalette( } } -bool CCodec_TiffContext::Decode1bppRGB( - const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap, - int32_t height, - int32_t width, - uint16_t bps, - uint16_t spp) { +bool CTiffContext::Decode1bppRGB(const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap, + int32_t height, + int32_t width, + uint16_t bps, + uint16_t spp) { if (pDIBitmap->GetBPP() != 1 || spp != 1 || bps != 1 || !IsSupport(pDIBitmap)) { return false; @@ -378,12 +373,11 @@ bool CCodec_TiffContext::Decode1bppRGB( return true; } -bool CCodec_TiffContext::Decode8bppRGB( - const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap, - int32_t height, - int32_t width, - uint16_t bps, - uint16_t spp) { +bool CTiffContext::Decode8bppRGB(const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap, + int32_t height, + int32_t width, + uint16_t bps, + uint16_t spp) { if (pDIBitmap->GetBPP() != 8 || spp != 1 || (bps != 4 && bps != 8) || !IsSupport(pDIBitmap)) { return false; @@ -415,12 +409,11 @@ bool CCodec_TiffContext::Decode8bppRGB( return true; } -bool CCodec_TiffContext::Decode24bppRGB( - const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap, - int32_t height, - int32_t width, - uint16_t bps, - uint16_t spp) { +bool CTiffContext::Decode24bppRGB(const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap, + int32_t height, + int32_t width, + uint16_t bps, + uint16_t spp) { if (pDIBitmap->GetBPP() != 24 || !IsSupport(pDIBitmap)) return false; @@ -444,7 +437,7 @@ bool CCodec_TiffContext::Decode24bppRGB( return true; } -bool CCodec_TiffContext::Decode(const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap) { +bool CTiffContext::Decode(const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap) { uint32_t img_wid = pDIBitmap->GetWidth(); uint32_t img_hei = pDIBitmap->GetHeight(); uint32_t width = 0; @@ -485,30 +478,28 @@ bool CCodec_TiffContext::Decode(const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap) { return false; } -CCodec_TiffContext* CCodec_TiffModule::CreateDecoder( +std::unique_ptr<CCodec_TiffModule::Context> CCodec_TiffModule::CreateDecoder( const CFX_RetainPtr<IFX_SeekableReadStream>& file_ptr) { - auto pDecoder = pdfium::MakeUnique<CCodec_TiffContext>(); + auto pDecoder = pdfium::MakeUnique<CTiffContext>(); if (!pDecoder->InitDecoder(file_ptr)) return nullptr; - return pDecoder.release(); + return pDecoder; } -bool CCodec_TiffModule::LoadFrameInfo(CCodec_TiffContext* ctx, +bool CCodec_TiffModule::LoadFrameInfo(Context* pContext, int32_t frame, int32_t* width, int32_t* height, int32_t* comps, int32_t* bpc, CFX_DIBAttribute* pAttribute) { + auto* ctx = static_cast<CTiffContext*>(pContext); return ctx->LoadFrameInfo(frame, width, height, comps, bpc, pAttribute); } -bool CCodec_TiffModule::Decode(CCodec_TiffContext* ctx, +bool CCodec_TiffModule::Decode(Context* pContext, const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap) { + auto* ctx = static_cast<CTiffContext*>(pContext); return ctx->Decode(pDIBitmap); } - -void CCodec_TiffModule::DestroyDecoder(CCodec_TiffContext* ctx) { - delete ctx; -} diff --git a/chromium/third_party/pdfium/core/fxcodec/codec/ccodec_tiffmodule.h b/chromium/third_party/pdfium/core/fxcodec/codec/ccodec_tiffmodule.h index be791e5cc26..73d9c379926 100644 --- a/chromium/third_party/pdfium/core/fxcodec/codec/ccodec_tiffmodule.h +++ b/chromium/third_party/pdfium/core/fxcodec/codec/ccodec_tiffmodule.h @@ -7,27 +7,31 @@ #ifndef CORE_FXCODEC_CODEC_CCODEC_TIFFMODULE_H_ #define CORE_FXCODEC_CODEC_CCODEC_TIFFMODULE_H_ +#include <memory> + #include "core/fxcrt/cfx_retain_ptr.h" #include "core/fxcrt/fx_system.h" #include "core/fxge/dib/cfx_dibitmap.h" -class CCodec_TiffContext; class CFX_DIBAttribute; class CCodec_TiffModule { public: - CCodec_TiffContext* CreateDecoder( + class Context { + public: + virtual ~Context() {} + }; + + std::unique_ptr<Context> CreateDecoder( const CFX_RetainPtr<IFX_SeekableReadStream>& file_ptr); - bool LoadFrameInfo(CCodec_TiffContext* ctx, + bool LoadFrameInfo(Context* ctx, int32_t frame, int32_t* width, int32_t* height, int32_t* comps, int32_t* bpc, CFX_DIBAttribute* pAttribute); - bool Decode(CCodec_TiffContext* ctx, - const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap); - void DestroyDecoder(CCodec_TiffContext* ctx); + bool Decode(Context* ctx, const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap); }; #endif // CORE_FXCODEC_CODEC_CCODEC_TIFFMODULE_H_ diff --git a/chromium/third_party/pdfium/core/fxcodec/codec/fx_codec.cpp b/chromium/third_party/pdfium/core/fxcodec/codec/fx_codec.cpp index e695bc97c68..aeffd9cb459 100644 --- a/chromium/third_party/pdfium/core/fxcodec/codec/fx_codec.cpp +++ b/chromium/third_party/pdfium/core/fxcodec/codec/fx_codec.cpp @@ -9,6 +9,7 @@ #include <algorithm> #include <cmath> #include <memory> +#include <tuple> #include <utility> #include "core/fxcodec/codec/codec_int.h" @@ -17,6 +18,1326 @@ #include "third_party/base/logging.h" #include "third_party/base/ptr_util.h" +namespace { + +const uint8_t g_CMYK[81 * 81 * 3] = { + 255, 255, 255, 225, 226, 228, 199, 200, 202, 173, 174, 178, 147, 149, 152, + 123, 125, 128, 99, 99, 102, 69, 70, 71, 34, 30, 31, 255, 253, 229, + 226, 224, 203, 200, 199, 182, 173, 173, 158, 149, 148, 135, 125, 124, 113, + 99, 99, 90, 70, 69, 63, 33, 29, 24, 255, 251, 204, 228, 223, 182, + 201, 198, 163, 174, 172, 142, 150, 147, 122, 125, 123, 101, 99, 98, 80, + 70, 68, 54, 32, 28, 16, 255, 249, 179, 230, 222, 160, 203, 197, 144, + 174, 170, 124, 150, 145, 105, 125, 122, 88, 99, 97, 69, 70, 68, 46, + 31, 28, 6, 255, 247, 154, 229, 220, 138, 203, 195, 122, 176, 169, 107, + 150, 145, 91, 125, 121, 74, 100, 96, 57, 70, 67, 35, 29, 26, 0, + 255, 246, 128, 231, 217, 114, 205, 194, 101, 176, 167, 88, 150, 144, 75, + 125, 120, 60, 100, 96, 44, 70, 66, 24, 28, 26, 0, 255, 244, 96, + 231, 217, 87, 203, 192, 78, 175, 167, 66, 150, 143, 56, 125, 119, 43, + 100, 95, 29, 69, 66, 7, 26, 26, 0, 255, 243, 51, 232, 215, 51, + 204, 191, 43, 176, 165, 38, 150, 142, 28, 125, 118, 17, 99, 94, 0, + 68, 65, 0, 24, 25, 0, 255, 241, 0, 231, 215, 0, 203, 190, 0, + 176, 164, 0, 150, 141, 0, 126, 117, 0, 99, 93, 0, 68, 65, 0, + 24, 25, 0, 252, 228, 238, 222, 201, 211, 197, 180, 190, 171, 156, 166, + 147, 133, 143, 123, 111, 119, 99, 88, 94, 71, 61, 66, 34, 22, 26, + 254, 226, 213, 224, 201, 191, 199, 179, 171, 172, 155, 148, 147, 133, 128, + 123, 110, 106, 98, 87, 83, 70, 59, 57, 33, 21, 18, 254, 224, 191, + 224, 199, 172, 200, 177, 153, 173, 154, 133, 147, 132, 115, 123, 109, 94, + 98, 86, 74, 70, 59, 49, 32, 21, 9, 255, 222, 168, 227, 198, 150, + 200, 175, 135, 173, 153, 118, 148, 130, 99, 123, 109, 82, 98, 86, 64, + 69, 58, 40, 31, 19, 0, 255, 221, 145, 227, 196, 129, 201, 174, 115, + 173, 151, 99, 148, 129, 85, 124, 108, 69, 98, 85, 52, 69, 58, 30, + 30, 19, 0, 255, 219, 121, 227, 195, 109, 201, 174, 97, 174, 150, 83, + 148, 129, 70, 124, 107, 55, 98, 84, 40, 69, 58, 19, 28, 18, 0, + 255, 218, 92, 229, 194, 82, 202, 173, 75, 174, 150, 63, 149, 128, 51, + 124, 106, 39, 98, 84, 24, 68, 57, 3, 26, 18, 0, 255, 217, 54, + 228, 193, 52, 201, 172, 46, 174, 148, 36, 148, 127, 27, 123, 105, 14, + 98, 83, 0, 68, 56, 0, 25, 18, 0, 255, 216, 0, 229, 192, 2, + 202, 171, 4, 173, 148, 0, 148, 126, 0, 124, 105, 0, 98, 83, 0, + 68, 56, 0, 24, 17, 0, 249, 204, 223, 219, 181, 199, 195, 160, 178, + 170, 140, 156, 146, 119, 134, 123, 99, 112, 98, 77, 88, 70, 52, 61, + 34, 11, 20, 250, 201, 200, 221, 180, 178, 197, 159, 161, 171, 139, 139, + 147, 119, 120, 123, 98, 99, 98, 77, 78, 69, 51, 52, 34, 11, 10, + 252, 201, 180, 223, 179, 162, 197, 159, 144, 170, 138, 125, 146, 117, 107, + 122, 97, 89, 98, 76, 69, 69, 50, 44, 32, 11, 2, 252, 199, 158, + 222, 177, 143, 199, 158, 127, 171, 137, 110, 147, 117, 93, 122, 96, 76, + 97, 75, 58, 69, 50, 36, 32, 10, 0, 253, 198, 137, 223, 177, 123, + 198, 156, 110, 171, 136, 95, 146, 116, 80, 122, 96, 65, 97, 75, 47, + 69, 50, 25, 30, 10, 0, 254, 197, 115, 225, 175, 104, 198, 156, 92, + 172, 135, 79, 147, 115, 66, 123, 95, 52, 98, 74, 37, 69, 49, 15, + 29, 10, 0, 254, 196, 89, 224, 175, 80, 199, 154, 70, 172, 134, 59, + 146, 114, 48, 122, 95, 36, 97, 74, 21, 68, 49, 0, 27, 9, 0, + 255, 195, 57, 225, 173, 52, 198, 154, 44, 172, 133, 36, 147, 113, 26, + 123, 94, 14, 98, 74, 0, 68, 49, 0, 26, 10, 0, 254, 194, 15, + 225, 172, 12, 198, 153, 7, 172, 132, 3, 146, 113, 0, 123, 93, 0, + 98, 73, 0, 68, 49, 0, 26, 9, 0, 246, 178, 209, 218, 159, 186, + 194, 140, 166, 168, 122, 145, 144, 104, 125, 121, 85, 103, 97, 65, 81, + 69, 41, 55, 34, 0, 12, 248, 176, 186, 219, 157, 166, 195, 139, 149, + 168, 121, 130, 144, 103, 111, 121, 85, 91, 97, 65, 71, 69, 41, 46, + 34, 0, 4, 249, 175, 168, 220, 156, 150, 196, 139, 135, 169, 121, 116, + 144, 103, 100, 122, 84, 83, 98, 65, 63, 70, 41, 39, 33, 0, 0, + 249, 175, 148, 220, 155, 133, 196, 138, 119, 169, 120, 103, 145, 101, 87, + 121, 83, 71, 97, 65, 54, 69, 41, 31, 32, 0, 0, 249, 173, 128, + 222, 154, 115, 195, 137, 102, 170, 119, 88, 145, 101, 74, 122, 83, 59, + 97, 64, 43, 68, 40, 20, 30, 0, 0, 250, 172, 108, 221, 154, 98, + 195, 136, 86, 170, 118, 73, 145, 100, 61, 122, 82, 48, 97, 63, 32, + 69, 40, 11, 28, 0, 0, 250, 171, 85, 221, 153, 76, 196, 136, 67, + 170, 117, 56, 145, 99, 44, 121, 82, 33, 97, 63, 17, 68, 40, 0, + 28, 0, 0, 251, 171, 58, 222, 152, 50, 197, 135, 43, 169, 117, 34, + 146, 99, 25, 121, 81, 10, 96, 63, 0, 68, 40, 0, 27, 0, 0, + 250, 170, 26, 222, 151, 19, 196, 134, 13, 169, 116, 4, 145, 99, 0, + 122, 81, 0, 97, 63, 0, 67, 40, 0, 26, 0, 0, 244, 153, 194, + 215, 136, 173, 192, 121, 155, 167, 104, 135, 143, 89, 115, 121, 72, 96, + 97, 54, 75, 70, 31, 49, 34, 0, 6, 245, 153, 173, 216, 136, 155, + 192, 120, 138, 167, 104, 121, 144, 88, 103, 121, 71, 85, 97, 54, 66, + 69, 31, 42, 34, 0, 0, 246, 152, 157, 217, 135, 140, 193, 120, 126, + 167, 103, 109, 143, 88, 92, 121, 72, 76, 97, 54, 58, 69, 31, 35, + 33, 0, 0, 245, 150, 139, 218, 134, 125, 193, 119, 111, 167, 103, 96, + 144, 87, 80, 121, 71, 66, 96, 53, 49, 68, 31, 26, 32, 0, 0, + 246, 151, 122, 218, 133, 108, 194, 118, 96, 168, 102, 81, 144, 86, 69, + 120, 71, 55, 95, 53, 39, 68, 30, 17, 31, 0, 0, 248, 150, 103, + 218, 133, 91, 193, 118, 81, 168, 102, 69, 143, 86, 56, 120, 70, 43, + 96, 53, 28, 68, 31, 6, 29, 0, 0, 247, 149, 81, 218, 132, 72, + 194, 117, 62, 168, 101, 52, 144, 86, 42, 121, 70, 29, 96, 52, 13, + 68, 30, 0, 28, 0, 0, 247, 148, 55, 219, 131, 50, 194, 117, 43, + 167, 101, 32, 144, 85, 22, 120, 69, 8, 96, 52, 0, 67, 30, 0, + 27, 0, 0, 247, 147, 29, 218, 131, 24, 194, 116, 20, 168, 100, 11, + 144, 85, 0, 120, 69, 0, 96, 52, 0, 67, 30, 0, 26, 0, 0, + 242, 130, 179, 214, 114, 160, 190, 101, 143, 166, 87, 125, 143, 72, 107, + 120, 58, 88, 96, 42, 68, 69, 17, 44, 35, 0, 0, 243, 129, 161, + 215, 114, 143, 191, 101, 128, 166, 87, 113, 143, 73, 96, 120, 58, 79, + 96, 41, 60, 69, 18, 37, 33, 0, 0, 243, 129, 146, 216, 114, 130, + 192, 101, 117, 166, 87, 101, 143, 72, 86, 121, 58, 69, 96, 42, 52, + 69, 18, 29, 31, 0, 0, 243, 128, 130, 216, 114, 115, 191, 101, 102, + 165, 86, 88, 142, 72, 75, 120, 58, 60, 95, 42, 43, 68, 19, 21, + 30, 0, 0, 244, 127, 112, 217, 113, 101, 192, 99, 89, 166, 85, 75, + 142, 72, 63, 119, 57, 50, 96, 41, 35, 68, 19, 13, 30, 0, 0, + 244, 127, 96, 216, 112, 86, 191, 99, 75, 166, 86, 64, 143, 72, 52, + 120, 57, 40, 95, 41, 24, 67, 20, 1, 29, 0, 0, 245, 126, 77, + 216, 113, 68, 191, 100, 59, 166, 85, 49, 142, 71, 38, 119, 57, 26, + 95, 41, 10, 67, 20, 0, 28, 0, 0, 244, 126, 55, 216, 112, 48, + 191, 99, 40, 166, 85, 31, 143, 71, 20, 119, 57, 6, 95, 42, 0, + 67, 20, 0, 28, 0, 0, 245, 126, 33, 217, 112, 26, 192, 99, 22, + 166, 84, 11, 142, 70, 0, 119, 57, 0, 95, 41, 0, 66, 20, 0, + 27, 0, 0, 241, 102, 167, 213, 90, 149, 189, 79, 133, 165, 66, 115, + 141, 54, 98, 119, 41, 81, 96, 25, 63, 69, 0, 38, 30, 0, 0, + 241, 102, 149, 213, 90, 133, 189, 79, 119, 165, 66, 103, 142, 55, 88, + 119, 41, 71, 96, 25, 53, 69, 0, 31, 28, 0, 0, 241, 102, 135, + 214, 90, 121, 190, 79, 108, 165, 66, 92, 141, 55, 78, 119, 42, 63, + 96, 26, 46, 69, 0, 24, 28, 0, 0, 241, 101, 120, 214, 90, 107, + 189, 79, 95, 165, 67, 83, 141, 54, 68, 118, 41, 54, 95, 27, 39, + 68, 0, 16, 27, 0, 0, 241, 102, 106, 213, 90, 93, 189, 78, 82, + 164, 67, 70, 141, 55, 58, 118, 42, 45, 94, 27, 29, 67, 2, 6, + 27, 0, 0, 242, 101, 90, 214, 89, 79, 190, 79, 69, 166, 67, 59, + 141, 55, 47, 118, 41, 35, 95, 27, 19, 67, 3, 0, 26, 0, 0, + 242, 102, 72, 213, 89, 63, 191, 79, 56, 164, 67, 45, 141, 55, 34, + 118, 42, 22, 94, 28, 6, 67, 3, 0, 26, 0, 0, 242, 100, 51, + 214, 89, 45, 190, 78, 38, 164, 67, 30, 141, 55, 18, 118, 42, 3, + 95, 28, 0, 66, 4, 0, 26, 0, 0, 243, 100, 33, 214, 90, 27, + 190, 78, 22, 165, 67, 13, 141, 55, 0, 118, 43, 0, 94, 29, 0, + 66, 5, 0, 26, 0, 0, 237, 69, 153, 211, 58, 135, 187, 51, 121, + 163, 41, 105, 141, 28, 90, 118, 15, 73, 96, 0, 56, 68, 0, 33, + 25, 0, 0, 239, 67, 137, 212, 60, 123, 189, 50, 110, 163, 41, 94, + 141, 29, 79, 118, 17, 65, 95, 0, 48, 69, 0, 26, 25, 0, 0, + 240, 69, 124, 211, 60, 111, 188, 50, 98, 163, 42, 85, 141, 31, 72, + 118, 18, 57, 94, 0, 41, 68, 0, 19, 25, 0, 0, 240, 70, 112, + 212, 61, 99, 188, 52, 87, 163, 41, 74, 140, 31, 62, 118, 20, 48, + 94, 2, 32, 68, 0, 11, 24, 0, 0, 239, 70, 98, 212, 62, 86, + 188, 53, 77, 164, 42, 64, 140, 32, 52, 118, 20, 40, 94, 3, 24, + 67, 0, 3, 23, 0, 0, 239, 71, 85, 212, 61, 74, 187, 53, 65, + 163, 44, 54, 140, 34, 43, 118, 22, 30, 95, 3, 14, 67, 0, 0, + 23, 0, 0, 239, 70, 67, 212, 62, 59, 188, 53, 51, 163, 45, 42, + 141, 34, 31, 117, 22, 17, 94, 5, 2, 66, 0, 0, 23, 0, 0, + 239, 71, 50, 213, 62, 43, 188, 54, 37, 164, 45, 28, 139, 34, 16, + 117, 22, 2, 94, 7, 0, 65, 0, 0, 23, 0, 0, 240, 71, 34, + 212, 63, 29, 189, 54, 24, 163, 46, 15, 139, 36, 2, 117, 25, 0, + 94, 8, 0, 66, 0, 0, 23, 0, 0, 237, 0, 140, 209, 0, 124, + 186, 0, 112, 162, 0, 97, 141, 0, 82, 118, 0, 67, 95, 0, 49, + 68, 0, 27, 20, 0, 0, 237, 0, 126, 210, 0, 113, 187, 0, 99, + 163, 0, 86, 139, 0, 72, 118, 0, 58, 95, 0, 42, 67, 0, 20, + 20, 0, 0, 237, 1, 114, 209, 1, 102, 187, 0, 90, 163, 0, 78, + 139, 0, 64, 118, 0, 50, 95, 0, 35, 67, 0, 13, 20, 0, 0, + 236, 16, 102, 209, 7, 91, 186, 0, 80, 162, 0, 68, 139, 0, 56, + 117, 0, 43, 94, 0, 27, 67, 0, 6, 20, 0, 0, 238, 15, 89, + 209, 13, 79, 186, 6, 69, 162, 0, 58, 139, 0, 47, 117, 0, 34, + 93, 0, 20, 66, 0, 2, 20, 0, 0, 237, 20, 78, 210, 12, 68, + 187, 4, 59, 163, 0, 49, 139, 0, 38, 116, 0, 26, 94, 0, 11, + 66, 0, 0, 20, 0, 0, 237, 25, 64, 210, 18, 56, 186, 11, 48, + 162, 4, 39, 138, 0, 27, 117, 0, 14, 93, 0, 0, 66, 0, 0, + 20, 0, 0, 238, 25, 48, 210, 22, 43, 186, 15, 35, 162, 8, 26, + 140, 0, 14, 117, 0, 0, 93, 0, 0, 65, 0, 0, 20, 0, 0, + 238, 28, 35, 210, 21, 30, 187, 15, 24, 162, 8, 16, 139, 1, 2, + 117, 0, 0, 93, 0, 0, 65, 0, 0, 22, 0, 0, 219, 242, 252, + 195, 214, 225, 172, 191, 201, 148, 165, 175, 127, 142, 150, 106, 119, 126, + 84, 95, 101, 58, 66, 72, 24, 27, 32, 222, 239, 226, 196, 213, 202, + 173, 189, 180, 150, 165, 158, 129, 141, 135, 107, 118, 113, 85, 94, 90, + 58, 66, 63, 21, 26, 24, 223, 237, 203, 198, 211, 182, 175, 188, 163, + 152, 164, 141, 129, 140, 121, 107, 117, 101, 85, 93, 80, 58, 64, 54, + 21, 26, 18, 226, 236, 179, 201, 210, 160, 177, 187, 143, 153, 162, 125, + 130, 139, 106, 108, 116, 89, 85, 92, 69, 58, 64, 45, 20, 25, 8, + 227, 234, 153, 201, 208, 139, 178, 185, 124, 154, 161, 107, 131, 138, 91, + 108, 115, 75, 85, 91, 58, 58, 63, 35, 17, 25, 0, 229, 233, 130, + 203, 207, 116, 178, 184, 104, 154, 160, 90, 131, 137, 76, 109, 114, 62, + 85, 90, 46, 58, 63, 25, 16, 24, 0, 230, 231, 100, 202, 205, 90, + 179, 183, 80, 154, 159, 69, 131, 136, 57, 109, 113, 46, 86, 90, 32, + 58, 63, 10, 14, 24, 0, 230, 230, 65, 204, 204, 58, 180, 182, 52, + 155, 157, 44, 132, 135, 35, 110, 113, 24, 86, 89, 9, 57, 62, 0, + 11, 24, 0, 232, 230, 19, 204, 204, 19, 180, 181, 17, 155, 157, 10, + 131, 134, 2, 109, 112, 0, 85, 89, 0, 57, 62, 0, 10, 23, 0, + 218, 216, 236, 194, 192, 211, 172, 171, 188, 149, 149, 164, 128, 127, 141, + 106, 106, 119, 84, 84, 94, 59, 57, 66, 25, 18, 26, 221, 214, 211, + 196, 191, 190, 174, 170, 170, 150, 148, 148, 128, 126, 127, 107, 105, 106, + 85, 83, 84, 59, 56, 58, 23, 17, 18, 222, 213, 190, 197, 189, 170, + 175, 169, 153, 151, 147, 133, 129, 126, 113, 108, 105, 94, 85, 82, 74, + 59, 56, 49, 22, 17, 11, 224, 211, 168, 199, 188, 151, 175, 168, 135, + 152, 146, 117, 129, 124, 99, 107, 103, 82, 84, 82, 64, 59, 55, 41, + 21, 17, 1, 224, 210, 145, 199, 187, 130, 176, 166, 117, 152, 145, 101, + 129, 123, 86, 107, 103, 70, 85, 81, 53, 58, 55, 31, 19, 17, 0, + 227, 208, 123, 200, 186, 110, 177, 165, 98, 153, 143, 84, 130, 122, 70, + 108, 102, 57, 85, 80, 41, 58, 54, 20, 18, 16, 0, 227, 208, 97, + 202, 185, 86, 177, 164, 77, 153, 142, 65, 130, 122, 54, 108, 101, 42, + 85, 80, 27, 58, 54, 7, 16, 16, 0, 228, 206, 66, 202, 184, 58, + 178, 163, 50, 154, 141, 42, 131, 121, 33, 109, 101, 21, 86, 79, 5, + 58, 54, 0, 13, 16, 0, 228, 206, 29, 202, 183, 25, 178, 163, 20, + 154, 141, 15, 131, 121, 5, 108, 100, 0, 85, 79, 0, 58, 53, 0, + 13, 16, 0, 217, 193, 221, 193, 172, 198, 172, 153, 178, 149, 133, 154, + 128, 114, 132, 107, 94, 111, 85, 74, 89, 59, 49, 61, 25, 8, 22, + 219, 191, 198, 195, 171, 178, 173, 153, 159, 149, 132, 139, 128, 113, 119, + 107, 94, 100, 85, 73, 79, 59, 48, 52, 25, 7, 14, 221, 191, 180, + 196, 170, 160, 174, 152, 144, 150, 132, 125, 129, 113, 107, 107, 93, 89, + 85, 73, 69, 59, 48, 45, 23, 7, 4, 222, 189, 159, 197, 169, 142, + 174, 151, 127, 151, 131, 110, 129, 112, 94, 108, 93, 78, 85, 72, 60, + 58, 47, 37, 22, 7, 0, 223, 188, 138, 197, 168, 123, 175, 150, 109, + 151, 130, 95, 130, 111, 81, 108, 92, 65, 85, 72, 49, 59, 47, 27, + 21, 7, 0, 224, 187, 118, 198, 167, 105, 176, 149, 93, 152, 129, 79, + 130, 110, 68, 108, 91, 54, 85, 71, 38, 59, 47, 17, 18, 7, 0, + 224, 187, 93, 199, 166, 83, 176, 148, 73, 152, 128, 62, 129, 109, 51, + 108, 90, 39, 85, 71, 25, 58, 46, 3, 16, 8, 0, 226, 186, 64, + 200, 165, 57, 177, 147, 50, 153, 127, 40, 130, 108, 31, 108, 90, 19, + 85, 70, 3, 58, 46, 0, 16, 8, 0, 227, 185, 35, 200, 165, 30, + 176, 146, 25, 152, 127, 18, 130, 108, 7, 108, 89, 0, 85, 70, 0, + 57, 46, 0, 14, 8, 0, 216, 169, 205, 192, 150, 184, 171, 134, 164, + 149, 116, 144, 128, 99, 124, 107, 81, 103, 85, 63, 81, 60, 39, 55, + 26, 0, 15, 217, 168, 186, 193, 150, 165, 172, 134, 149, 150, 116, 130, + 128, 99, 111, 107, 81, 92, 85, 62, 72, 59, 39, 47, 25, 0, 6, + 219, 168, 168, 194, 149, 150, 173, 133, 135, 150, 116, 117, 128, 98, 99, + 107, 80, 82, 86, 62, 63, 59, 38, 39, 24, 0, 0, 219, 166, 148, + 195, 149, 133, 173, 133, 119, 150, 115, 103, 128, 98, 88, 107, 80, 72, + 85, 61, 54, 59, 38, 32, 23, 0, 0, 220, 166, 129, 196, 148, 116, + 174, 132, 103, 151, 114, 89, 129, 97, 75, 107, 79, 60, 85, 61, 44, + 59, 38, 22, 21, 0, 0, 222, 164, 110, 197, 147, 99, 175, 131, 87, + 151, 113, 75, 129, 96, 63, 107, 79, 49, 85, 61, 33, 58, 38, 12, + 19, 0, 0, 222, 164, 88, 197, 146, 79, 174, 130, 69, 151, 113, 58, + 129, 95, 47, 107, 78, 35, 85, 60, 20, 58, 38, 0, 18, 0, 0, + 223, 164, 63, 198, 145, 55, 175, 129, 48, 151, 112, 39, 129, 95, 29, + 107, 78, 16, 85, 60, 1, 58, 38, 0, 17, 0, 0, 223, 163, 36, + 198, 145, 32, 174, 129, 26, 151, 111, 17, 129, 95, 7, 107, 78, 0, + 84, 60, 0, 57, 37, 0, 15, 0, 0, 215, 147, 192, 191, 130, 172, + 170, 116, 153, 148, 100, 133, 127, 85, 115, 107, 69, 96, 85, 51, 75, + 60, 28, 50, 25, 0, 8, 217, 146, 173, 192, 130, 154, 171, 115, 138, + 149, 100, 121, 128, 84, 103, 107, 68, 85, 85, 51, 66, 60, 28, 42, + 25, 0, 0, 217, 145, 157, 193, 129, 140, 173, 115, 125, 149, 100, 109, + 128, 84, 92, 107, 68, 76, 85, 51, 58, 59, 28, 35, 23, 0, 0, + 218, 145, 140, 193, 129, 125, 172, 114, 110, 149, 99, 96, 128, 83, 81, + 107, 67, 65, 84, 51, 49, 59, 29, 27, 22, 0, 0, 219, 144, 121, + 194, 128, 108, 172, 113, 96, 149, 98, 83, 128, 83, 69, 107, 68, 55, + 85, 50, 40, 59, 28, 18, 20, 0, 0, 220, 143, 104, 195, 128, 93, + 173, 114, 82, 150, 98, 69, 127, 82, 58, 107, 67, 45, 85, 50, 30, + 59, 28, 7, 19, 0, 0, 220, 143, 84, 195, 127, 74, 173, 113, 65, + 149, 97, 55, 128, 82, 44, 106, 67, 32, 84, 50, 16, 58, 28, 0, + 18, 0, 0, 221, 142, 62, 196, 126, 53, 173, 112, 46, 150, 97, 37, + 128, 82, 26, 107, 66, 14, 84, 50, 0, 58, 28, 0, 16, 0, 0, + 222, 142, 38, 196, 126, 34, 174, 112, 27, 150, 96, 17, 128, 82, 6, + 106, 66, 0, 84, 50, 0, 57, 29, 0, 16, 0, 0, 214, 123, 179, + 191, 110, 159, 169, 98, 143, 147, 84, 124, 126, 70, 106, 107, 55, 88, + 85, 39, 69, 60, 15, 45, 23, 0, 2, 216, 123, 161, 192, 110, 144, + 170, 98, 129, 148, 84, 112, 127, 70, 95, 107, 55, 79, 85, 39, 61, + 60, 15, 37, 20, 0, 0, 217, 122, 145, 192, 110, 130, 170, 97, 116, + 149, 84, 101, 127, 70, 85, 106, 55, 70, 85, 39, 53, 59, 16, 30, + 19, 0, 0, 217, 123, 131, 192, 109, 116, 171, 96, 103, 149, 83, 89, + 127, 70, 75, 106, 55, 60, 85, 40, 45, 59, 16, 23, 17, 0, 0, + 217, 122, 114, 193, 109, 101, 172, 96, 91, 149, 82, 77, 128, 69, 64, + 106, 55, 50, 84, 39, 35, 59, 17, 14, 17, 0, 0, 218, 122, 98, + 194, 108, 87, 171, 96, 77, 149, 82, 65, 127, 69, 52, 106, 55, 40, + 84, 40, 25, 59, 18, 3, 15, 0, 0, 219, 122, 80, 193, 108, 70, + 172, 95, 61, 149, 82, 51, 127, 69, 40, 106, 55, 28, 84, 39, 12, + 58, 17, 0, 13, 0, 0, 219, 121, 59, 194, 108, 52, 172, 96, 44, + 149, 82, 35, 127, 68, 24, 106, 55, 11, 84, 40, 0, 57, 18, 0, + 13, 0, 0, 219, 121, 40, 193, 108, 33, 172, 95, 26, 149, 81, 19, + 128, 68, 6, 106, 54, 0, 84, 39, 0, 57, 18, 0, 13, 0, 0, + 213, 99, 165, 189, 87, 148, 169, 76, 132, 147, 64, 115, 126, 52, 98, + 106, 39, 81, 85, 23, 63, 60, 0, 39, 16, 0, 0, 214, 98, 149, + 191, 87, 133, 170, 76, 119, 148, 65, 103, 127, 53, 88, 106, 39, 72, + 85, 24, 55, 60, 0, 32, 15, 0, 0, 215, 99, 136, 191, 87, 121, + 170, 77, 108, 148, 65, 93, 126, 53, 79, 106, 40, 64, 85, 24, 47, + 59, 0, 25, 14, 0, 0, 215, 99, 121, 192, 87, 108, 170, 77, 96, + 148, 65, 82, 126, 53, 69, 106, 40, 55, 85, 25, 39, 59, 0, 18, + 13, 0, 0, 216, 99, 106, 191, 87, 95, 170, 76, 83, 148, 65, 71, + 126, 53, 58, 106, 41, 45, 85, 26, 30, 59, 0, 8, 11, 0, 0, + 216, 98, 91, 192, 88, 82, 170, 77, 71, 148, 65, 60, 127, 53, 48, + 105, 41, 36, 83, 26, 21, 58, 1, 2, 11, 0, 0, 217, 99, 75, + 192, 87, 66, 170, 76, 57, 148, 65, 47, 126, 53, 36, 105, 41, 24, + 83, 26, 8, 57, 2, 0, 9, 0, 0, 217, 98, 57, 192, 87, 49, + 171, 77, 41, 147, 65, 32, 126, 53, 21, 105, 41, 8, 84, 27, 0, + 57, 3, 0, 9, 0, 0, 217, 98, 40, 193, 87, 34, 171, 76, 27, + 148, 65, 19, 126, 53, 6, 105, 41, 0, 83, 27, 0, 57, 4, 0, + 9, 0, 0, 211, 67, 152, 189, 58, 136, 168, 50, 122, 147, 39, 105, + 127, 28, 89, 106, 14, 74, 85, 0, 56, 59, 0, 33, 9, 0, 0, + 213, 68, 138, 190, 59, 123, 169, 51, 109, 148, 40, 95, 126, 30, 80, + 106, 16, 65, 85, 0, 48, 59, 0, 27, 9, 0, 0, 214, 69, 125, + 190, 59, 111, 168, 51, 99, 148, 41, 86, 126, 31, 72, 106, 18, 58, + 85, 0, 41, 59, 0, 20, 7, 0, 0, 215, 70, 112, 190, 61, 100, + 169, 52, 88, 147, 42, 76, 126, 32, 63, 106, 19, 49, 84, 1, 34, + 58, 0, 13, 7, 0, 0, 214, 70, 99, 190, 62, 88, 169, 53, 77, + 147, 43, 65, 125, 32, 53, 106, 20, 40, 84, 3, 26, 58, 0, 4, + 7, 0, 0, 214, 71, 86, 190, 61, 75, 169, 53, 65, 146, 43, 54, + 126, 33, 44, 105, 21, 31, 83, 4, 17, 57, 0, 0, 7, 0, 0, + 215, 71, 71, 191, 62, 62, 169, 53, 53, 147, 44, 44, 126, 34, 33, + 105, 22, 20, 83, 5, 4, 57, 0, 0, 7, 0, 0, 215, 71, 54, + 191, 62, 47, 169, 54, 39, 147, 44, 30, 126, 35, 20, 105, 23, 6, + 83, 6, 0, 56, 0, 0, 5, 0, 0, 215, 71, 41, 191, 63, 34, + 170, 54, 27, 147, 45, 17, 126, 35, 6, 105, 23, 0, 83, 8, 0, + 56, 0, 0, 5, 0, 0, 210, 13, 140, 189, 1, 125, 167, 0, 110, + 146, 0, 96, 126, 0, 81, 106, 0, 67, 85, 0, 51, 59, 0, 28, + 4, 0, 0, 212, 18, 126, 190, 7, 113, 168, 0, 100, 146, 0, 86, + 126, 0, 73, 106, 0, 59, 84, 0, 43, 59, 0, 22, 4, 0, 0, + 212, 21, 115, 190, 13, 103, 168, 3, 91, 146, 0, 78, 125, 0, 65, + 105, 0, 52, 84, 0, 36, 58, 0, 16, 4, 0, 0, 213, 24, 103, + 189, 19, 91, 168, 9, 82, 146, 0, 69, 125, 0, 57, 105, 0, 44, + 84, 0, 29, 58, 0, 7, 4, 0, 0, 213, 27, 92, 188, 21, 81, + 168, 14, 71, 146, 1, 59, 125, 0, 48, 105, 0, 36, 84, 0, 21, + 58, 0, 4, 4, 0, 0, 213, 30, 80, 189, 22, 69, 168, 17, 61, + 146, 5, 50, 125, 0, 39, 104, 0, 27, 83, 0, 12, 57, 0, 0, + 4, 0, 0, 214, 30, 67, 189, 25, 57, 168, 20, 50, 146, 9, 40, + 125, 0, 29, 104, 0, 17, 83, 0, 2, 56, 0, 0, 4, 0, 0, + 214, 32, 53, 189, 27, 44, 169, 20, 38, 146, 13, 28, 124, 2, 17, + 104, 0, 4, 83, 0, 0, 56, 0, 0, 4, 0, 0, 214, 33, 41, + 190, 27, 33, 168, 23, 27, 146, 13, 18, 125, 3, 5, 105, 0, 0, + 83, 0, 0, 56, 0, 0, 4, 0, 0, 185, 229, 250, 164, 204, 223, + 146, 182, 199, 127, 158, 174, 108, 136, 149, 89, 113, 125, 70, 90, 100, + 46, 62, 71, 10, 25, 33, 189, 227, 225, 168, 202, 201, 148, 181, 179, + 129, 157, 156, 109, 135, 134, 90, 113, 113, 70, 89, 90, 46, 62, 62, + 8, 24, 25, 192, 226, 202, 170, 202, 182, 151, 179, 162, 130, 156, 141, + 110, 133, 121, 91, 112, 101, 71, 89, 80, 46, 61, 54, 7, 24, 19, + 194, 224, 179, 173, 200, 160, 153, 178, 144, 132, 155, 125, 112, 133, 107, + 92, 111, 89, 71, 88, 69, 46, 61, 45, 6, 23, 10, 196, 223, 155, + 174, 198, 139, 154, 176, 124, 132, 153, 107, 113, 131, 91, 92, 110, 75, + 72, 87, 58, 47, 60, 37, 4, 23, 0, 198, 221, 131, 175, 197, 117, + 155, 175, 105, 133, 152, 91, 113, 130, 76, 92, 109, 63, 72, 86, 47, + 46, 60, 26, 3, 23, 0, 200, 220, 104, 176, 196, 94, 156, 175, 84, + 134, 151, 72, 113, 129, 59, 93, 108, 47, 72, 85, 33, 46, 59, 13, + 0, 23, 0, 201, 219, 73, 179, 195, 65, 157, 173, 57, 135, 150, 48, + 114, 129, 39, 94, 108, 28, 72, 85, 15, 47, 59, 0, 0, 22, 0, + 203, 219, 42, 178, 195, 37, 157, 173, 32, 135, 150, 26, 114, 128, 16, + 94, 107, 6, 73, 85, 0, 46, 58, 0, 0, 22, 0, 186, 205, 233, + 165, 183, 209, 148, 163, 187, 128, 142, 163, 109, 121, 140, 91, 101, 118, + 71, 80, 94, 48, 54, 66, 12, 15, 27, 189, 204, 211, 169, 182, 189, + 151, 163, 169, 131, 141, 147, 111, 121, 126, 92, 101, 105, 72, 79, 84, + 48, 54, 58, 11, 15, 19, 192, 202, 190, 171, 181, 170, 152, 161, 152, + 131, 141, 133, 112, 120, 113, 93, 100, 94, 72, 79, 74, 48, 53, 50, + 10, 15, 11, 195, 201, 169, 172, 179, 151, 153, 160, 135, 132, 139, 117, + 113, 119, 100, 93, 99, 82, 72, 78, 64, 48, 53, 41, 9, 14, 3, + 195, 200, 146, 174, 179, 131, 154, 159, 117, 133, 138, 101, 113, 118, 86, + 93, 98, 70, 73, 77, 53, 48, 52, 32, 8, 15, 0, 198, 199, 125, + 175, 177, 111, 155, 158, 100, 133, 137, 85, 113, 117, 71, 93, 97, 57, + 72, 77, 42, 47, 52, 22, 5, 14, 0, 199, 198, 101, 176, 177, 89, + 155, 157, 79, 134, 136, 68, 113, 116, 56, 94, 97, 44, 73, 76, 30, + 47, 52, 10, 2, 15, 0, 200, 197, 72, 178, 176, 63, 157, 156, 56, + 135, 136, 46, 114, 116, 37, 94, 96, 26, 73, 76, 11, 47, 51, 0, + 0, 14, 0, 201, 197, 45, 177, 175, 38, 156, 155, 31, 135, 135, 25, + 114, 115, 17, 94, 96, 5, 73, 75, 0, 46, 51, 0, 0, 14, 0, + 187, 183, 218, 167, 165, 197, 149, 147, 176, 129, 127, 153, 111, 109, 132, + 92, 90, 111, 73, 70, 89, 49, 46, 62, 15, 4, 22, 190, 183, 197, + 170, 164, 177, 151, 146, 159, 130, 127, 139, 112, 109, 119, 93, 90, 99, + 72, 70, 78, 49, 45, 53, 14, 4, 15, 192, 182, 179, 171, 163, 161, + 153, 145, 144, 132, 126, 125, 113, 108, 107, 93, 89, 88, 73, 70, 69, + 49, 45, 45, 13, 5, 6, 195, 181, 159, 172, 162, 142, 152, 145, 127, + 132, 125, 111, 113, 107, 94, 93, 88, 77, 73, 69, 59, 48, 45, 37, + 11, 5, 0, 195, 180, 139, 173, 161, 124, 153, 143, 110, 133, 125, 96, + 113, 106, 81, 94, 88, 66, 73, 68, 49, 49, 44, 28, 9, 6, 0, + 196, 179, 118, 174, 160, 106, 154, 142, 94, 133, 124, 81, 113, 105, 68, + 94, 87, 54, 73, 68, 39, 48, 44, 18, 5, 5, 0, 197, 178, 96, + 176, 159, 86, 155, 141, 75, 134, 123, 64, 114, 105, 53, 94, 87, 40, + 73, 68, 26, 48, 44, 5, 2, 6, 0, 199, 178, 70, 176, 158, 62, + 156, 141, 54, 134, 122, 44, 114, 104, 35, 94, 86, 23, 73, 67, 8, + 47, 44, 0, 2, 6, 0, 199, 177, 45, 178, 158, 40, 156, 140, 32, + 135, 122, 26, 114, 104, 16, 94, 86, 4, 73, 67, 0, 47, 44, 0, + 0, 7, 0, 188, 161, 204, 168, 144, 183, 149, 129, 164, 130, 112, 144, + 112, 95, 123, 93, 78, 103, 74, 60, 81, 50, 36, 56, 16, 0, 16, + 190, 160, 185, 170, 144, 165, 151, 128, 148, 132, 111, 130, 112, 95, 110, + 93, 78, 92, 74, 59, 72, 50, 36, 48, 16, 0, 8, 192, 160, 167, + 171, 143, 150, 153, 128, 134, 132, 111, 117, 112, 94, 100, 94, 77, 82, + 74, 59, 63, 50, 36, 40, 14, 0, 0, 193, 159, 149, 172, 143, 134, + 153, 127, 119, 133, 110, 103, 113, 94, 87, 93, 77, 72, 73, 59, 54, + 50, 36, 32, 12, 0, 0, 195, 159, 131, 173, 142, 117, 153, 127, 104, + 132, 110, 90, 113, 93, 76, 93, 76, 61, 74, 59, 45, 49, 36, 23, + 9, 0, 0, 196, 158, 113, 174, 141, 101, 155, 126, 89, 133, 109, 76, + 113, 93, 64, 94, 76, 51, 74, 58, 35, 49, 36, 14, 6, 0, 0, + 197, 157, 92, 174, 141, 80, 154, 125, 71, 134, 108, 60, 114, 92, 50, + 94, 75, 37, 73, 58, 22, 48, 36, 1, 5, 0, 0, 197, 157, 68, + 175, 140, 59, 155, 124, 51, 134, 108, 41, 113, 91, 32, 94, 75, 21, + 73, 57, 5, 48, 35, 0, 5, 0, 0, 198, 156, 46, 176, 140, 40, + 155, 124, 32, 134, 107, 24, 114, 91, 14, 94, 75, 2, 73, 57, 0, + 48, 36, 0, 3, 0, 0, 189, 140, 191, 168, 126, 172, 150, 112, 154, + 131, 97, 134, 112, 82, 115, 94, 66, 96, 74, 49, 75, 51, 25, 50, + 12, 0, 10, 191, 139, 173, 170, 125, 154, 152, 111, 138, 132, 96, 121, + 113, 81, 103, 94, 66, 85, 74, 48, 66, 50, 26, 42, 12, 0, 1, + 192, 139, 157, 171, 125, 140, 152, 111, 125, 132, 96, 109, 113, 81, 92, + 94, 65, 76, 74, 48, 58, 50, 26, 35, 9, 0, 0, 193, 139, 140, + 172, 124, 125, 153, 110, 112, 133, 95, 96, 113, 80, 82, 94, 65, 66, + 74, 49, 50, 50, 26, 28, 7, 0, 0, 194, 138, 123, 172, 123, 109, + 153, 110, 97, 133, 95, 84, 113, 80, 70, 94, 65, 56, 74, 48, 40, + 50, 26, 20, 6, 0, 0, 194, 138, 105, 173, 123, 94, 153, 109, 83, + 133, 94, 70, 112, 79, 59, 94, 64, 46, 74, 48, 31, 50, 26, 9, + 4, 0, 0, 196, 138, 87, 174, 122, 77, 153, 109, 67, 133, 93, 56, + 113, 79, 46, 94, 64, 34, 73, 48, 18, 49, 27, 0, 4, 0, 0, + 196, 137, 65, 174, 122, 57, 154, 108, 49, 133, 93, 39, 113, 79, 29, + 94, 64, 18, 74, 48, 3, 49, 27, 0, 2, 0, 0, 197, 137, 47, + 175, 122, 40, 155, 108, 32, 133, 93, 23, 114, 79, 14, 94, 64, 1, + 73, 48, 0, 48, 27, 0, 2, 0, 0, 189, 119, 177, 168, 106, 159, + 150, 94, 142, 131, 81, 124, 113, 67, 107, 94, 53, 89, 74, 37, 69, + 51, 11, 45, 6, 0, 3, 191, 119, 161, 170, 106, 144, 152, 94, 129, + 132, 81, 112, 113, 67, 96, 94, 53, 79, 74, 37, 61, 51, 13, 38, + 6, 0, 0, 192, 119, 146, 170, 106, 131, 152, 94, 117, 132, 80, 101, + 112, 67, 85, 94, 53, 70, 74, 37, 53, 50, 14, 31, 4, 0, 0, + 192, 119, 131, 171, 106, 117, 153, 94, 105, 132, 80, 89, 113, 67, 75, + 94, 54, 61, 74, 38, 45, 51, 14, 23, 3, 0, 0, 193, 118, 114, + 171, 106, 102, 153, 93, 90, 132, 80, 78, 113, 67, 65, 94, 53, 52, + 74, 37, 36, 50, 15, 16, 1, 0, 0, 194, 118, 99, 172, 105, 89, + 153, 93, 78, 132, 80, 66, 113, 67, 54, 94, 53, 42, 74, 38, 27, + 50, 16, 5, 1, 0, 0, 194, 118, 82, 173, 105, 72, 153, 93, 63, + 132, 79, 53, 113, 67, 42, 94, 53, 30, 74, 38, 15, 49, 16, 0, + 0, 0, 0, 195, 117, 63, 173, 105, 55, 154, 93, 47, 133, 79, 37, + 113, 66, 27, 94, 53, 15, 73, 38, 0, 48, 16, 0, 0, 0, 0, + 195, 117, 46, 173, 104, 39, 154, 92, 32, 133, 79, 22, 113, 66, 13, + 94, 53, 0, 73, 38, 0, 48, 17, 0, 0, 0, 0, 189, 96, 166, + 168, 85, 147, 150, 74, 132, 131, 62, 115, 113, 51, 99, 94, 38, 82, + 74, 21, 63, 51, 0, 40, 1, 0, 0, 190, 96, 150, 170, 85, 133, + 152, 75, 119, 132, 63, 104, 113, 51, 88, 94, 38, 72, 75, 22, 55, + 51, 0, 33, 1, 0, 0, 192, 96, 137, 170, 85, 121, 152, 74, 108, + 132, 64, 94, 113, 52, 79, 94, 39, 64, 74, 23, 48, 50, 0, 26, + 0, 0, 0, 192, 96, 122, 171, 86, 109, 152, 75, 96, 132, 63, 83, + 113, 52, 69, 94, 39, 56, 74, 24, 41, 50, 0, 19, 0, 0, 0, + 193, 96, 107, 171, 85, 96, 152, 75, 84, 132, 64, 72, 113, 52, 60, + 94, 39, 47, 74, 24, 32, 50, 1, 10, 0, 0, 0, 193, 96, 93, + 172, 85, 82, 152, 75, 72, 133, 63, 61, 113, 51, 49, 94, 39, 37, + 73, 25, 23, 49, 2, 2, 0, 0, 0, 194, 96, 78, 172, 85, 68, + 152, 75, 59, 132, 63, 49, 113, 52, 39, 94, 40, 26, 73, 25, 11, + 48, 3, 0, 0, 0, 0, 194, 96, 60, 173, 85, 52, 153, 75, 44, + 132, 64, 35, 112, 52, 25, 94, 40, 12, 73, 26, 0, 48, 4, 0, + 0, 0, 0, 195, 96, 46, 173, 85, 38, 154, 74, 31, 133, 63, 22, + 113, 52, 11, 93, 40, 0, 73, 26, 0, 47, 5, 0, 0, 0, 0, + 188, 67, 153, 168, 58, 137, 151, 49, 122, 131, 39, 106, 113, 28, 90, + 94, 13, 75, 75, 0, 57, 51, 0, 35, 0, 0, 0, 190, 68, 138, + 170, 59, 123, 152, 50, 110, 132, 41, 96, 113, 29, 80, 94, 16, 66, + 75, 0, 49, 50, 0, 27, 0, 0, 0, 191, 69, 126, 170, 59, 112, + 151, 52, 100, 132, 42, 86, 113, 30, 73, 95, 17, 58, 75, 0, 42, + 50, 0, 21, 0, 0, 0, 192, 70, 113, 170, 61, 100, 151, 52, 89, + 132, 42, 77, 113, 31, 64, 94, 19, 50, 74, 1, 35, 50, 0, 14, + 0, 0, 0, 192, 70, 100, 170, 62, 89, 151, 53, 77, 131, 43, 66, + 112, 32, 54, 94, 20, 42, 74, 2, 27, 49, 0, 5, 0, 0, 0, + 192, 71, 87, 171, 61, 77, 152, 53, 67, 131, 44, 57, 112, 33, 45, + 94, 21, 33, 74, 4, 19, 49, 0, 1, 0, 0, 0, 193, 71, 74, + 171, 62, 64, 152, 53, 55, 132, 44, 45, 113, 34, 34, 94, 22, 23, + 73, 5, 7, 48, 0, 0, 0, 0, 0, 193, 70, 58, 172, 62, 50, + 152, 54, 42, 132, 44, 32, 112, 35, 22, 93, 23, 10, 73, 6, 0, + 47, 0, 0, 0, 0, 0, 193, 70, 45, 172, 62, 38, 153, 54, 31, + 132, 44, 21, 112, 35, 9, 94, 23, 0, 73, 7, 0, 47, 0, 0, + 0, 0, 0, 189, 26, 141, 169, 15, 126, 150, 2, 112, 131, 0, 97, + 113, 0, 82, 94, 0, 67, 75, 0, 51, 50, 0, 29, 0, 0, 0, + 190, 28, 128, 170, 18, 114, 151, 8, 101, 132, 0, 88, 113, 0, 74, + 94, 0, 60, 75, 0, 44, 50, 0, 23, 0, 0, 0, 191, 30, 117, + 170, 23, 104, 152, 11, 92, 132, 1, 79, 113, 0, 67, 95, 0, 53, + 75, 0, 37, 50, 0, 17, 0, 0, 0, 191, 33, 105, 170, 26, 93, + 151, 18, 83, 132, 6, 70, 112, 0, 58, 94, 0, 45, 75, 0, 30, + 49, 0, 8, 0, 0, 0, 191, 34, 93, 170, 27, 82, 151, 20, 72, + 131, 8, 61, 112, 0, 49, 94, 0, 38, 74, 0, 23, 49, 0, 4, + 0, 0, 0, 191, 36, 82, 170, 29, 71, 151, 22, 63, 131, 11, 52, + 112, 0, 41, 93, 0, 29, 74, 0, 14, 48, 0, 1, 0, 0, 0, + 191, 38, 69, 170, 31, 60, 151, 24, 51, 131, 14, 41, 112, 1, 31, + 93, 0, 19, 73, 0, 3, 48, 0, 0, 0, 0, 0, 192, 37, 56, + 171, 31, 47, 152, 25, 40, 131, 17, 30, 112, 4, 19, 93, 0, 7, + 73, 0, 0, 47, 0, 0, 0, 0, 0, 192, 38, 45, 171, 33, 36, + 152, 26, 30, 131, 18, 21, 111, 7, 9, 93, 0, 0, 73, 0, 0, + 47, 0, 0, 0, 0, 0, 149, 218, 248, 133, 194, 222, 119, 173, 198, + 102, 151, 173, 86, 130, 148, 70, 108, 125, 53, 85, 100, 32, 59, 71, + 0, 22, 33, 154, 216, 223, 137, 193, 200, 122, 172, 178, 106, 150, 156, + 89, 128, 133, 73, 107, 112, 54, 85, 89, 31, 59, 63, 0, 22, 26, + 159, 215, 202, 141, 192, 181, 126, 171, 161, 108, 149, 141, 90, 128, 121, + 74, 107, 100, 55, 85, 80, 32, 58, 55, 0, 22, 19, 161, 213, 179, + 144, 190, 160, 126, 170, 143, 109, 148, 125, 92, 127, 107, 74, 106, 89, + 56, 84, 69, 32, 58, 46, 0, 21, 11, 163, 211, 156, 144, 189, 139, + 129, 168, 125, 110, 147, 108, 93, 126, 92, 75, 105, 76, 57, 83, 58, + 33, 58, 37, 0, 21, 1, 167, 211, 133, 147, 188, 120, 130, 167, 105, + 110, 145, 92, 93, 125, 78, 76, 104, 64, 58, 83, 48, 33, 57, 27, + 0, 21, 0, 169, 210, 108, 149, 187, 96, 131, 166, 86, 112, 144, 74, + 94, 124, 62, 77, 103, 49, 58, 82, 35, 33, 57, 15, 0, 21, 0, + 170, 209, 80, 151, 186, 71, 133, 165, 62, 114, 143, 52, 95, 123, 42, + 77, 103, 32, 58, 81, 18, 33, 56, 0, 0, 21, 0, 173, 208, 55, + 152, 186, 49, 134, 165, 41, 114, 143, 34, 95, 122, 25, 77, 102, 14, + 58, 81, 0, 33, 56, 0, 0, 21, 0, 154, 195, 232, 137, 174, 207, + 122, 156, 185, 105, 136, 163, 89, 116, 140, 73, 97, 117, 56, 76, 94, + 35, 51, 66, 0, 13, 28, 158, 194, 209, 141, 174, 187, 125, 155, 167, + 109, 135, 146, 91, 116, 125, 75, 96, 105, 57, 75, 83, 35, 50, 57, + 0, 12, 21, 161, 193, 189, 144, 173, 169, 128, 154, 151, 110, 134, 132, + 93, 115, 113, 77, 95, 94, 58, 75, 74, 35, 50, 50, 0, 12, 13, + 164, 192, 168, 145, 171, 151, 129, 153, 134, 111, 133, 117, 94, 114, 100, + 76, 95, 82, 58, 75, 64, 36, 50, 42, 0, 12, 5, 165, 191, 147, + 147, 170, 131, 130, 152, 117, 113, 132, 102, 95, 113, 86, 77, 94, 71, + 58, 74, 54, 35, 50, 33, 0, 13, 0, 167, 189, 126, 148, 169, 113, + 132, 151, 100, 113, 131, 86, 96, 112, 73, 77, 93, 59, 59, 73, 43, + 35, 49, 23, 0, 12, 0, 170, 189, 104, 150, 168, 91, 133, 150, 81, + 114, 130, 69, 96, 111, 57, 78, 92, 46, 59, 73, 31, 35, 49, 11, + 0, 13, 0, 171, 188, 78, 152, 168, 68, 134, 149, 60, 115, 130, 50, + 96, 111, 41, 78, 92, 29, 60, 73, 15, 35, 49, 0, 0, 12, 0, + 173, 187, 55, 153, 167, 47, 134, 149, 39, 115, 129, 33, 97, 110, 24, + 79, 92, 13, 60, 72, 0, 35, 48, 0, 0, 12, 0, 157, 175, 217, + 139, 157, 196, 125, 141, 175, 109, 122, 153, 92, 104, 132, 76, 86, 110, + 59, 67, 88, 37, 43, 61, 1, 1, 23, 161, 174, 196, 144, 156, 176, + 127, 140, 158, 110, 121, 137, 94, 104, 118, 77, 85, 98, 59, 67, 78, + 37, 43, 53, 0, 2, 16, 163, 174, 178, 146, 156, 160, 130, 139, 143, + 112, 121, 124, 95, 103, 106, 78, 85, 88, 60, 66, 69, 37, 42, 46, + 0, 2, 7, 166, 173, 159, 147, 154, 142, 130, 138, 127, 113, 120, 111, + 96, 103, 95, 78, 84, 77, 60, 66, 59, 37, 43, 37, 0, 2, 0, + 166, 172, 139, 148, 154, 125, 131, 137, 112, 113, 120, 96, 96, 102, 81, + 78, 84, 66, 60, 65, 50, 37, 42, 29, 0, 3, 0, 167, 171, 120, + 149, 153, 107, 133, 137, 95, 114, 118, 81, 97, 101, 69, 79, 84, 56, + 60, 65, 40, 37, 42, 19, 0, 3, 0, 170, 170, 99, 151, 152, 87, + 134, 136, 77, 115, 118, 66, 97, 101, 55, 79, 83, 42, 61, 65, 28, + 37, 42, 7, 0, 3, 0, 172, 170, 75, 152, 151, 65, 134, 135, 57, + 115, 117, 48, 97, 100, 38, 79, 83, 27, 61, 64, 12, 36, 42, 0, + 0, 3, 0, 172, 169, 55, 154, 151, 46, 135, 134, 40, 116, 116, 32, + 97, 99, 21, 80, 82, 10, 61, 64, 0, 36, 41, 0, 0, 3, 0, + 160, 154, 203, 143, 139, 182, 127, 124, 164, 111, 107, 143, 95, 91, 122, + 78, 75, 103, 60, 57, 81, 39, 33, 56, 1, 0, 18, 163, 154, 184, + 146, 138, 165, 130, 123, 148, 113, 107, 129, 96, 90, 110, 79, 74, 92, + 61, 56, 72, 39, 34, 48, 2, 0, 9, 165, 154, 167, 147, 137, 149, + 131, 122, 134, 114, 106, 117, 96, 90, 100, 79, 74, 82, 61, 56, 64, + 39, 33, 40, 2, 0, 1, 166, 153, 150, 149, 137, 133, 132, 122, 119, + 114, 106, 104, 97, 90, 88, 79, 74, 72, 61, 56, 55, 39, 34, 33, + 0, 0, 0, 168, 152, 132, 149, 136, 117, 132, 121, 104, 114, 105, 90, + 97, 89, 76, 79, 73, 62, 61, 56, 46, 38, 34, 25, 0, 0, 0, + 169, 151, 114, 150, 135, 101, 133, 121, 90, 114, 104, 77, 97, 89, 65, + 80, 73, 51, 61, 56, 36, 38, 34, 16, 0, 0, 0, 170, 150, 94, + 151, 135, 83, 134, 120, 73, 115, 104, 62, 98, 88, 51, 80, 72, 39, + 61, 56, 24, 38, 34, 3, 0, 0, 0, 172, 150, 72, 153, 134, 63, + 135, 119, 55, 115, 103, 45, 98, 88, 36, 80, 72, 24, 61, 55, 9, + 38, 34, 0, 0, 0, 0, 172, 150, 54, 153, 134, 47, 135, 119, 38, + 116, 103, 30, 98, 87, 21, 80, 72, 8, 62, 55, 0, 37, 34, 0, + 0, 0, 0, 162, 134, 190, 145, 120, 171, 129, 108, 153, 113, 93, 134, + 97, 78, 115, 80, 63, 96, 62, 46, 75, 41, 23, 51, 0, 0, 11, + 165, 134, 173, 147, 120, 154, 131, 107, 138, 114, 92, 120, 97, 78, 103, + 80, 63, 85, 62, 46, 66, 40, 23, 43, 0, 0, 2, 166, 134, 157, + 148, 120, 140, 132, 106, 125, 114, 92, 109, 97, 77, 93, 81, 63, 77, + 62, 46, 58, 40, 24, 36, 0, 0, 0, 168, 133, 140, 149, 119, 125, + 132, 106, 112, 115, 92, 97, 98, 77, 82, 81, 62, 67, 62, 46, 50, + 40, 24, 29, 0, 0, 0, 168, 133, 123, 150, 119, 110, 133, 106, 97, + 115, 91, 84, 98, 77, 70, 81, 62, 57, 62, 46, 41, 40, 24, 20, + 0, 0, 0, 169, 132, 107, 150, 118, 94, 133, 105, 84, 115, 91, 72, + 98, 76, 60, 80, 62, 47, 62, 46, 32, 39, 25, 11, 0, 0, 0, + 171, 132, 89, 152, 118, 79, 135, 105, 69, 115, 90, 58, 98, 76, 47, + 80, 62, 36, 62, 46, 21, 39, 25, 0, 0, 0, 0, 171, 132, 69, + 153, 117, 60, 135, 104, 52, 116, 90, 42, 98, 76, 33, 81, 61, 21, + 62, 46, 6, 38, 25, 0, 0, 0, 0, 172, 132, 54, 153, 118, 45, + 135, 104, 38, 116, 90, 28, 98, 76, 18, 81, 61, 6, 62, 46, 0, + 38, 25, 0, 0, 0, 0, 164, 115, 177, 146, 103, 159, 130, 91, 143, + 114, 78, 125, 97, 65, 107, 81, 51, 89, 63, 34, 69, 41, 9, 46, + 0, 0, 4, 166, 115, 161, 148, 103, 144, 132, 91, 129, 115, 78, 112, + 98, 65, 96, 81, 51, 79, 63, 35, 61, 41, 11, 38, 0, 0, 0, + 167, 115, 146, 150, 102, 131, 132, 91, 117, 115, 78, 101, 98, 65, 86, + 81, 51, 71, 63, 35, 54, 41, 12, 32, 0, 0, 0, 168, 114, 132, + 150, 103, 118, 133, 91, 105, 116, 78, 91, 98, 64, 76, 82, 51, 61, + 63, 36, 46, 41, 13, 24, 0, 0, 0, 169, 114, 116, 150, 102, 103, + 134, 90, 91, 116, 78, 79, 98, 65, 66, 81, 51, 53, 63, 36, 37, + 40, 14, 17, 0, 0, 0, 169, 114, 101, 151, 101, 89, 134, 90, 79, + 116, 77, 67, 98, 64, 56, 81, 51, 44, 63, 36, 29, 40, 15, 7, + 0, 0, 0, 170, 114, 85, 152, 101, 75, 135, 90, 65, 116, 77, 54, + 98, 64, 44, 81, 51, 32, 63, 36, 17, 39, 15, 0, 0, 0, 0, + 172, 113, 66, 152, 101, 58, 135, 89, 49, 116, 77, 40, 99, 64, 30, + 81, 51, 18, 62, 36, 3, 38, 16, 0, 0, 0, 0, 171, 113, 51, + 153, 101, 44, 136, 89, 36, 116, 77, 28, 99, 64, 18, 81, 51, 5, + 62, 36, 0, 38, 16, 0, 0, 0, 0, 165, 94, 166, 147, 82, 147, + 132, 72, 132, 115, 61, 115, 98, 49, 99, 82, 36, 82, 64, 19, 64, + 42, 0, 41, 0, 0, 0, 167, 93, 150, 150, 83, 134, 133, 73, 120, + 116, 62, 104, 99, 49, 88, 82, 36, 72, 64, 20, 55, 41, 0, 33, + 0, 0, 0, 169, 93, 137, 150, 83, 122, 134, 73, 109, 116, 61, 94, + 99, 50, 80, 82, 37, 65, 64, 21, 49, 41, 0, 27, 0, 0, 0, + 169, 94, 123, 150, 83, 110, 133, 73, 97, 116, 61, 83, 99, 50, 70, + 82, 38, 57, 63, 23, 42, 41, 0, 20, 0, 0, 0, 169, 94, 109, + 150, 84, 97, 134, 73, 85, 116, 62, 73, 99, 51, 61, 81, 38, 48, + 63, 23, 33, 41, 1, 11, 0, 0, 0, 170, 94, 96, 150, 83, 84, + 134, 73, 74, 116, 61, 62, 99, 50, 51, 82, 38, 39, 64, 23, 24, + 40, 3, 4, 0, 0, 0, 171, 93, 79, 152, 82, 70, 135, 73, 61, + 116, 62, 51, 98, 51, 40, 81, 38, 28, 63, 24, 14, 39, 4, 0, + 0, 0, 0, 171, 94, 64, 152, 83, 55, 135, 73, 47, 116, 62, 37, + 98, 50, 27, 81, 38, 15, 63, 24, 1, 39, 4, 0, 0, 0, 0, + 172, 93, 51, 153, 82, 42, 135, 73, 35, 117, 62, 26, 99, 51, 16, + 81, 39, 3, 63, 25, 0, 38, 5, 0, 0, 0, 0, 166, 68, 153, + 148, 59, 137, 133, 49, 121, 115, 39, 106, 99, 28, 91, 82, 13, 75, + 65, 0, 58, 42, 0, 36, 0, 0, 0, 168, 68, 139, 150, 59, 124, + 134, 50, 110, 116, 40, 96, 99, 30, 81, 82, 16, 66, 64, 0, 50, + 41, 0, 29, 0, 0, 0, 169, 69, 126, 150, 59, 113, 134, 51, 101, + 117, 42, 87, 100, 30, 73, 82, 17, 59, 65, 0, 43, 41, 0, 23, + 0, 0, 0, 169, 70, 115, 150, 61, 102, 134, 52, 89, 116, 42, 77, + 99, 32, 65, 82, 19, 52, 64, 0, 36, 41, 0, 15, 0, 0, 0, + 169, 70, 101, 150, 61, 90, 134, 52, 79, 116, 43, 68, 99, 32, 55, + 82, 21, 43, 64, 2, 28, 41, 0, 6, 0, 0, 0, 170, 70, 89, + 151, 62, 79, 134, 53, 69, 116, 44, 58, 99, 33, 46, 81, 21, 34, + 64, 3, 20, 41, 0, 2, 0, 0, 0, 170, 71, 76, 152, 62, 66, + 134, 53, 57, 116, 43, 46, 99, 33, 36, 82, 22, 24, 64, 5, 10, + 40, 0, 0, 0, 0, 0, 171, 70, 61, 152, 62, 52, 135, 53, 44, + 116, 44, 35, 99, 34, 24, 82, 22, 12, 63, 6, 0, 39, 0, 0, + 0, 0, 0, 171, 71, 49, 153, 62, 41, 135, 54, 33, 117, 45, 25, + 98, 34, 13, 81, 23, 0, 63, 7, 0, 39, 0, 0, 0, 0, 0, + 167, 33, 142, 149, 24, 127, 134, 10, 113, 116, 0, 97, 100, 0, 83, + 83, 0, 68, 65, 0, 52, 40, 0, 30, 0, 0, 0, 169, 33, 129, + 150, 26, 115, 134, 17, 102, 116, 3, 89, 100, 0, 75, 83, 0, 60, + 65, 0, 45, 40, 0, 24, 0, 0, 0, 169, 36, 118, 151, 27, 104, + 134, 19, 93, 116, 7, 80, 100, 0, 67, 83, 0, 54, 65, 0, 38, + 41, 0, 17, 0, 0, 0, 169, 39, 107, 150, 30, 94, 134, 22, 84, + 116, 11, 71, 99, 0, 59, 83, 0, 46, 64, 0, 31, 40, 0, 9, + 0, 0, 0, 169, 39, 95, 151, 31, 83, 134, 24, 73, 116, 15, 62, + 100, 1, 51, 83, 0, 38, 64, 0, 24, 40, 0, 5, 0, 0, 0, + 169, 41, 83, 151, 33, 73, 134, 26, 64, 117, 17, 54, 99, 4, 42, + 82, 0, 30, 64, 0, 16, 40, 0, 1, 0, 0, 0, 170, 42, 71, + 152, 34, 62, 134, 28, 53, 117, 19, 44, 99, 6, 33, 82, 0, 21, + 63, 0, 4, 39, 0, 0, 0, 0, 0, 171, 42, 59, 152, 35, 50, + 134, 29, 42, 117, 21, 32, 99, 9, 22, 82, 0, 9, 63, 0, 0, + 38, 0, 0, 0, 0, 0, 172, 42, 48, 152, 36, 40, 135, 29, 32, + 117, 21, 23, 99, 10, 12, 82, 0, 0, 63, 0, 0, 38, 0, 0, + 0, 0, 0, 107, 207, 246, 96, 185, 220, 86, 165, 196, 73, 144, 171, + 60, 123, 147, 46, 103, 125, 32, 82, 100, 9, 56, 71, 0, 20, 33, + 115, 206, 221, 104, 184, 198, 92, 164, 178, 78, 143, 154, 64, 123, 133, + 51, 102, 111, 34, 81, 89, 10, 56, 63, 0, 20, 27, 122, 204, 200, + 108, 183, 180, 95, 163, 161, 82, 142, 140, 68, 122, 120, 54, 102, 101, + 36, 81, 79, 11, 56, 55, 0, 20, 20, 125, 203, 179, 111, 181, 160, + 97, 162, 143, 85, 141, 124, 70, 121, 107, 55, 101, 89, 38, 80, 69, + 14, 55, 46, 0, 19, 10, 128, 202, 156, 113, 180, 140, 102, 161, 125, + 87, 140, 108, 71, 120, 92, 56, 100, 76, 39, 79, 59, 14, 55, 38, + 0, 20, 3, 132, 200, 135, 117, 179, 121, 103, 159, 106, 88, 139, 93, + 73, 119, 79, 57, 100, 65, 41, 79, 49, 15, 54, 28, 0, 19, 0, + 134, 200, 111, 119, 178, 98, 105, 158, 87, 89, 138, 76, 74, 118, 64, + 58, 99, 51, 41, 78, 37, 16, 54, 17, 0, 19, 0, 137, 199, 85, + 122, 177, 75, 108, 158, 66, 91, 137, 56, 75, 118, 46, 59, 98, 35, + 42, 78, 22, 16, 54, 3, 0, 19, 0, 140, 198, 62, 125, 177, 55, + 109, 158, 47, 92, 137, 40, 76, 117, 32, 59, 98, 21, 42, 78, 6, + 16, 54, 0, 0, 18, 0, 118, 186, 231, 106, 167, 206, 93, 149, 184, + 81, 130, 161, 67, 111, 139, 54, 92, 117, 39, 72, 93, 17, 48, 66, + 0, 10, 29, 123, 185, 207, 110, 166, 186, 98, 148, 167, 85, 129, 145, + 71, 111, 125, 56, 92, 104, 40, 72, 83, 18, 48, 57, 0, 10, 22, + 128, 184, 188, 113, 165, 168, 102, 147, 151, 88, 128, 131, 73, 110, 113, + 58, 91, 94, 42, 71, 74, 19, 48, 50, 0, 9, 15, 131, 183, 168, + 116, 164, 151, 104, 146, 134, 89, 127, 117, 73, 109, 100, 58, 90, 83, + 42, 71, 65, 20, 48, 42, 0, 9, 5, 134, 182, 148, 120, 163, 131, + 105, 145, 118, 90, 126, 102, 75, 108, 86, 59, 90, 72, 43, 71, 55, + 19, 47, 34, 0, 9, 0, 136, 181, 128, 122, 162, 115, 107, 144, 102, + 92, 125, 87, 76, 107, 74, 61, 89, 60, 44, 70, 45, 20, 47, 24, + 0, 8, 0, 139, 180, 106, 124, 161, 95, 109, 144, 83, 93, 124, 71, + 77, 107, 60, 61, 89, 47, 44, 70, 33, 20, 47, 13, 0, 8, 0, + 142, 179, 82, 125, 160, 72, 111, 143, 63, 94, 124, 54, 77, 106, 44, + 61, 88, 32, 44, 69, 18, 20, 46, 0, 0, 8, 0, 143, 179, 62, + 127, 160, 54, 111, 142, 47, 94, 124, 39, 78, 106, 29, 62, 88, 18, + 45, 69, 3, 20, 46, 0, 0, 8, 0, 124, 167, 216, 112, 150, 194, + 99, 134, 174, 87, 117, 153, 73, 100, 131, 58, 82, 110, 43, 64, 88, + 23, 40, 61, 0, 0, 24, 129, 166, 195, 116, 150, 175, 103, 134, 158, + 89, 116, 137, 75, 99, 118, 60, 82, 98, 44, 63, 78, 23, 40, 53, + 0, 0, 17, 132, 166, 177, 119, 149, 160, 106, 133, 143, 90, 115, 124, + 76, 99, 107, 61, 81, 88, 45, 63, 69, 24, 40, 46, 0, 0, 9, + 136, 166, 159, 121, 148, 143, 107, 132, 126, 92, 115, 111, 77, 98, 94, + 62, 81, 78, 46, 63, 60, 23, 40, 38, 0, 0, 0, 138, 164, 140, + 122, 147, 125, 108, 131, 111, 93, 114, 97, 79, 98, 82, 63, 80, 67, + 46, 62, 50, 24, 40, 29, 0, 0, 0, 139, 163, 122, 124, 146, 109, + 110, 131, 96, 94, 114, 83, 79, 97, 70, 63, 81, 57, 46, 62, 41, + 24, 40, 21, 0, 0, 0, 141, 163, 101, 126, 145, 90, 111, 130, 79, + 95, 113, 68, 79, 96, 56, 63, 80, 44, 47, 62, 30, 23, 40, 10, + 0, 0, 0, 144, 162, 79, 127, 145, 70, 112, 129, 60, 95, 112, 51, + 79, 96, 41, 64, 79, 30, 47, 61, 15, 23, 40, 0, 0, 0, 0, + 145, 162, 60, 129, 145, 52, 113, 129, 46, 96, 112, 37, 79, 95, 27, + 64, 79, 16, 47, 61, 1, 23, 39, 0, 0, 0, 0, 131, 147, 202, + 117, 133, 181, 105, 119, 162, 91, 103, 142, 77, 87, 122, 62, 71, 102, + 47, 54, 81, 26, 31, 56, 0, 0, 18, 135, 147, 183, 120, 132, 164, + 107, 118, 147, 93, 102, 128, 78, 87, 110, 63, 71, 92, 47, 54, 72, + 26, 31, 48, 0, 0, 10, 138, 147, 166, 123, 131, 149, 108, 118, 133, + 94, 102, 116, 79, 86, 100, 64, 71, 82, 48, 54, 64, 27, 31, 41, + 0, 0, 2, 139, 146, 149, 124, 131, 134, 111, 117, 119, 94, 101, 103, + 79, 86, 88, 64, 70, 72, 48, 53, 55, 27, 31, 33, 0, 0, 0, + 141, 146, 132, 125, 131, 117, 111, 117, 104, 95, 101, 91, 80, 86, 77, + 65, 70, 62, 48, 53, 46, 26, 31, 25, 0, 0, 0, 143, 145, 115, + 126, 130, 101, 112, 116, 90, 96, 100, 78, 80, 85, 65, 65, 70, 52, + 49, 53, 37, 27, 32, 17, 0, 0, 0, 144, 144, 96, 128, 129, 85, + 112, 115, 75, 97, 100, 64, 81, 85, 52, 65, 69, 40, 49, 53, 26, + 26, 31, 5, 0, 0, 0, 146, 144, 76, 129, 129, 67, 114, 115, 58, + 97, 99, 48, 82, 84, 38, 66, 69, 27, 49, 53, 12, 26, 32, 0, + 0, 0, 0, 146, 144, 59, 130, 128, 51, 114, 114, 43, 98, 99, 35, + 82, 84, 25, 66, 69, 13, 49, 53, 0, 26, 32, 0, 0, 0, 0, + 135, 129, 189, 122, 115, 170, 107, 103, 152, 94, 89, 133, 79, 74, 114, + 64, 60, 95, 49, 43, 75, 29, 20, 51, 0, 0, 12, 138, 129, 171, + 124, 115, 153, 110, 103, 138, 95, 89, 120, 81, 74, 103, 66, 60, 86, + 50, 44, 67, 28, 21, 43, 0, 0, 3, 140, 129, 156, 125, 115, 140, + 111, 103, 125, 96, 89, 109, 81, 74, 93, 67, 60, 76, 50, 44, 59, + 29, 22, 36, 0, 0, 0, 142, 128, 140, 127, 115, 125, 112, 102, 112, + 97, 88, 97, 82, 74, 83, 67, 60, 67, 50, 44, 51, 29, 22, 29, + 0, 0, 0, 142, 128, 124, 127, 114, 111, 113, 102, 98, 98, 88, 85, + 82, 74, 71, 66, 60, 58, 50, 44, 42, 29, 22, 21, 0, 0, 0, + 144, 127, 108, 128, 114, 96, 113, 101, 85, 98, 87, 73, 82, 74, 61, + 67, 60, 48, 50, 44, 33, 28, 23, 12, 0, 0, 0, 145, 127, 91, + 129, 114, 81, 115, 101, 71, 98, 87, 60, 82, 73, 48, 67, 59, 37, + 50, 44, 22, 29, 23, 1, 0, 0, 0, 147, 127, 73, 130, 113, 63, + 115, 101, 55, 98, 87, 45, 83, 73, 35, 67, 59, 24, 50, 44, 10, + 28, 24, 0, 0, 0, 0, 147, 127, 58, 131, 113, 49, 115, 100, 42, + 99, 86, 33, 83, 73, 23, 67, 59, 10, 50, 44, 0, 27, 24, 0, + 0, 0, 0, 138, 110, 177, 124, 99, 159, 110, 88, 142, 96, 75, 125, + 82, 62, 107, 66, 48, 89, 51, 33, 70, 30, 8, 46, 0, 0, 5, + 142, 111, 160, 127, 99, 144, 113, 88, 130, 98, 75, 112, 82, 62, 96, + 68, 49, 80, 51, 33, 61, 30, 10, 39, 0, 0, 0, 143, 111, 146, + 128, 99, 131, 114, 88, 118, 98, 75, 101, 83, 62, 86, 68, 49, 71, + 52, 33, 54, 30, 11, 32, 0, 0, 0, 144, 111, 132, 128, 99, 118, + 113, 88, 106, 99, 75, 91, 83, 62, 77, 68, 49, 62, 52, 34, 46, + 30, 12, 25, 0, 0, 0, 144, 111, 117, 129, 98, 104, 114, 87, 92, + 99, 75, 80, 83, 62, 67, 68, 49, 53, 51, 34, 38, 30, 13, 18, + 0, 0, 0, 145, 111, 103, 130, 98, 91, 114, 87, 80, 99, 75, 68, + 83, 63, 57, 68, 50, 45, 51, 34, 30, 30, 14, 8, 0, 0, 0, + 146, 110, 87, 131, 98, 76, 115, 87, 67, 99, 75, 56, 83, 62, 45, + 68, 49, 33, 52, 35, 19, 30, 15, 2, 0, 0, 0, 148, 110, 70, + 131, 98, 60, 116, 86, 52, 99, 74, 43, 84, 62, 33, 69, 49, 21, + 52, 35, 6, 29, 15, 0, 0, 0, 0, 148, 110, 56, 132, 97, 48, + 117, 87, 40, 100, 75, 31, 84, 62, 22, 68, 49, 9, 51, 35, 0, + 28, 15, 0, 0, 0, 0, 142, 91, 166, 126, 80, 148, 113, 71, 132, + 98, 59, 115, 83, 47, 99, 69, 34, 82, 53, 17, 64, 32, 0, 41, + 0, 0, 0, 143, 91, 150, 128, 81, 135, 114, 71, 120, 99, 60, 104, + 85, 48, 89, 69, 35, 73, 53, 19, 56, 32, 0, 34, 0, 0, 0, + 145, 91, 137, 129, 81, 122, 115, 71, 109, 100, 60, 94, 85, 48, 81, + 69, 35, 65, 53, 19, 49, 32, 0, 28, 0, 0, 0, 146, 92, 124, + 130, 81, 110, 115, 71, 98, 100, 60, 84, 85, 49, 71, 69, 36, 57, + 53, 21, 42, 32, 0, 21, 0, 0, 0, 147, 91, 110, 130, 81, 97, + 115, 71, 86, 100, 60, 74, 84, 49, 62, 69, 36, 48, 53, 22, 34, + 32, 0, 13, 0, 0, 0, 147, 92, 97, 130, 81, 85, 116, 72, 76, + 100, 60, 63, 85, 49, 52, 69, 37, 40, 53, 22, 26, 31, 1, 5, + 0, 0, 0, 148, 92, 82, 131, 81, 71, 116, 71, 62, 100, 60, 53, + 84, 49, 42, 69, 37, 30, 52, 23, 16, 31, 2, 0, 0, 0, 0, + 148, 91, 67, 132, 81, 57, 117, 71, 49, 100, 60, 39, 84, 49, 30, + 69, 37, 18, 52, 23, 2, 30, 2, 0, 0, 0, 0, 149, 91, 54, + 132, 81, 46, 118, 71, 39, 101, 60, 29, 85, 49, 19, 69, 37, 6, + 52, 23, 0, 29, 3, 0, 0, 0, 0, 143, 68, 153, 128, 59, 137, + 115, 49, 122, 99, 39, 107, 85, 28, 91, 70, 13, 75, 54, 0, 58, + 32, 0, 36, 0, 0, 0, 146, 68, 140, 131, 59, 125, 116, 51, 111, + 100, 40, 97, 85, 29, 82, 70, 15, 67, 54, 0, 50, 32, 0, 29, + 0, 0, 0, 147, 68, 127, 131, 59, 114, 117, 51, 102, 101, 41, 88, + 86, 30, 74, 70, 17, 60, 54, 0, 44, 32, 0, 23, 0, 0, 0, + 147, 70, 115, 131, 60, 103, 116, 52, 91, 100, 42, 78, 85, 32, 65, + 70, 19, 53, 54, 1, 38, 32, 0, 17, 0, 0, 0, 147, 70, 103, + 131, 61, 91, 117, 53, 81, 101, 43, 69, 86, 32, 57, 70, 20, 44, + 54, 2, 30, 32, 0, 7, 0, 0, 0, 148, 70, 91, 132, 61, 80, + 117, 52, 70, 101, 43, 59, 85, 33, 48, 70, 21, 36, 53, 4, 22, + 32, 0, 3, 0, 0, 0, 148, 70, 78, 132, 62, 68, 117, 53, 58, + 101, 43, 48, 85, 34, 38, 70, 22, 26, 53, 6, 12, 31, 0, 0, + 0, 0, 0, 149, 71, 64, 132, 62, 54, 118, 54, 46, 101, 44, 37, + 85, 34, 27, 69, 23, 15, 53, 7, 1, 30, 0, 0, 0, 0, 0, + 150, 70, 53, 134, 61, 44, 118, 54, 36, 101, 44, 28, 85, 35, 17, + 69, 23, 4, 52, 8, 0, 30, 0, 0, 0, 0, 0, 145, 38, 143, + 130, 29, 128, 117, 18, 114, 101, 3, 98, 87, 0, 84, 72, 0, 69, + 54, 0, 53, 30, 0, 31, 0, 0, 0, 147, 38, 130, 132, 30, 116, + 117, 22, 103, 101, 8, 89, 87, 0, 76, 72, 0, 62, 54, 0, 46, + 30, 0, 24, 0, 0, 0, 148, 40, 119, 132, 31, 105, 117, 23, 94, + 101, 13, 81, 87, 0, 68, 71, 0, 55, 54, 0, 39, 30, 0, 18, + 0, 0, 0, 148, 42, 108, 132, 34, 96, 117, 25, 85, 102, 15, 73, + 86, 2, 60, 71, 0, 47, 54, 0, 33, 30, 0, 11, 0, 0, 0, + 148, 43, 96, 133, 35, 85, 117, 28, 75, 102, 18, 64, 87, 5, 52, + 71, 0, 40, 54, 0, 25, 30, 0, 5, 0, 0, 0, 149, 44, 85, + 132, 36, 75, 118, 29, 66, 101, 20, 55, 86, 8, 44, 70, 0, 32, + 53, 0, 18, 29, 0, 2, 0, 0, 0, 149, 45, 74, 133, 37, 64, + 118, 31, 55, 102, 21, 45, 85, 10, 34, 70, 0, 22, 53, 0, 6, + 28, 0, 0, 0, 0, 0, 150, 46, 61, 133, 39, 52, 118, 31, 44, + 102, 23, 34, 85, 12, 24, 70, 0, 12, 52, 0, 0, 28, 0, 0, + 0, 0, 0, 150, 46, 51, 133, 40, 42, 119, 32, 35, 102, 24, 25, + 85, 13, 14, 70, 0, 1, 52, 0, 0, 27, 0, 0, 0, 0, 0, + 53, 198, 244, 49, 177, 218, 41, 158, 195, 32, 138, 171, 22, 118, 147, + 11, 98, 124, 0, 78, 100, 0, 54, 71, 0, 18, 34, 69, 196, 220, + 64, 175, 196, 54, 157, 176, 45, 137, 154, 32, 117, 133, 19, 98, 111, + 0, 78, 89, 0, 53, 63, 0, 17, 27, 80, 195, 198, 69, 175, 179, + 60, 156, 159, 50, 136, 139, 38, 116, 120, 25, 98, 101, 4, 77, 80, + 0, 53, 55, 0, 17, 21, 84, 193, 177, 75, 173, 159, 64, 155, 142, + 55, 135, 124, 41, 116, 107, 27, 97, 89, 9, 76, 70, 0, 53, 47, + 0, 17, 11, 89, 193, 157, 79, 172, 140, 70, 154, 125, 57, 134, 109, + 44, 115, 92, 32, 96, 76, 13, 76, 59, 0, 52, 39, 0, 16, 4, + 94, 191, 135, 85, 171, 121, 72, 152, 108, 60, 133, 94, 47, 114, 80, + 32, 95, 65, 15, 76, 49, 0, 52, 29, 0, 16, 0, 98, 190, 113, + 87, 170, 100, 76, 152, 89, 62, 132, 77, 49, 113, 65, 35, 95, 52, + 18, 75, 37, 0, 52, 18, 0, 15, 0, 103, 190, 89, 90, 169, 80, + 78, 151, 70, 64, 132, 60, 51, 113, 49, 37, 94, 38, 20, 75, 25, + 0, 52, 5, 0, 15, 0, 106, 189, 69, 93, 169, 61, 80, 151, 53, + 66, 131, 45, 52, 113, 36, 37, 94, 25, 19, 74, 11, 0, 51, 0, + 0, 15, 0, 76, 178, 229, 68, 159, 205, 61, 142, 183, 50, 124, 160, + 40, 106, 138, 28, 88, 116, 12, 69, 93, 0, 45, 66, 0, 5, 29, + 86, 177, 207, 78, 158, 184, 67, 142, 166, 56, 123, 145, 45, 106, 125, + 31, 88, 105, 16, 69, 83, 0, 45, 58, 0, 6, 22, 93, 176, 187, + 81, 158, 168, 71, 141, 150, 61, 123, 131, 47, 105, 113, 35, 87, 94, + 20, 68, 74, 0, 45, 51, 0, 5, 16, 98, 175, 168, 84, 157, 150, + 75, 140, 134, 63, 122, 117, 50, 104, 100, 37, 87, 83, 21, 68, 65, + 0, 45, 42, 0, 4, 7, 100, 174, 149, 89, 155, 132, 76, 139, 117, + 65, 121, 102, 53, 104, 87, 39, 86, 72, 23, 67, 55, 0, 45, 34, + 0, 3, 0, 103, 173, 130, 92, 155, 115, 80, 138, 102, 68, 120, 88, + 53, 103, 75, 40, 86, 61, 24, 67, 45, 0, 45, 25, 0, 3, 0, + 107, 172, 108, 95, 154, 96, 82, 137, 85, 70, 119, 73, 55, 102, 61, + 42, 85, 49, 25, 67, 34, 0, 45, 14, 0, 3, 0, 110, 172, 86, + 97, 153, 76, 85, 137, 67, 70, 119, 57, 56, 102, 46, 42, 84, 35, + 26, 66, 21, 0, 44, 1, 0, 3, 0, 112, 171, 67, 98, 153, 59, + 86, 137, 52, 71, 119, 44, 58, 102, 34, 44, 85, 22, 27, 66, 7, + 0, 44, 0, 0, 3, 0, 90, 160, 215, 81, 144, 193, 70, 129, 173, + 61, 112, 151, 49, 95, 131, 37, 79, 109, 22, 61, 87, 0, 38, 61, + 0, 0, 25, 96, 160, 194, 86, 143, 174, 75, 128, 157, 65, 112, 137, + 53, 95, 117, 40, 78, 98, 25, 60, 78, 0, 38, 53, 0, 0, 17, + 100, 159, 177, 89, 143, 159, 79, 128, 143, 67, 111, 124, 55, 95, 107, + 42, 78, 89, 27, 60, 70, 2, 38, 46, 0, 0, 9, 104, 158, 159, + 92, 142, 143, 81, 127, 127, 69, 110, 110, 56, 94, 94, 43, 78, 78, + 28, 60, 60, 2, 38, 38, 0, 0, 1, 107, 157, 140, 94, 141, 125, + 82, 126, 112, 71, 110, 97, 59, 94, 82, 45, 77, 67, 29, 59, 51, + 4, 37, 30, 0, 0, 0, 110, 156, 122, 97, 140, 109, 85, 125, 97, + 72, 109, 83, 58, 93, 71, 45, 77, 57, 29, 60, 42, 5, 38, 22, + 0, 0, 0, 111, 156, 103, 99, 139, 91, 87, 125, 81, 73, 108, 69, + 60, 92, 58, 46, 77, 45, 30, 59, 31, 5, 38, 12, 0, 0, 0, + 115, 156, 82, 101, 140, 73, 88, 124, 63, 74, 108, 53, 60, 92, 44, + 46, 76, 32, 31, 59, 18, 6, 37, 0, 0, 0, 0, 116, 155, 65, + 102, 139, 58, 89, 124, 49, 75, 108, 41, 61, 92, 32, 48, 76, 21, + 31, 59, 6, 5, 37, 0, 0, 0, 0, 100, 141, 201, 88, 127, 181, + 79, 114, 162, 69, 99, 142, 57, 83, 122, 44, 68, 102, 30, 51, 81, + 7, 28, 56, 0, 0, 19, 105, 141, 182, 94, 127, 163, 83, 114, 146, + 71, 98, 128, 59, 83, 110, 46, 68, 91, 31, 51, 72, 10, 28, 48, + 0, 0, 11, 108, 141, 166, 96, 127, 149, 85, 113, 133, 73, 98, 116, + 60, 83, 99, 46, 68, 82, 32, 51, 64, 11, 29, 41, 0, 0, 2, + 111, 141, 149, 98, 126, 134, 88, 112, 119, 74, 97, 103, 61, 83, 88, + 48, 67, 72, 33, 51, 56, 11, 29, 34, 0, 0, 0, 112, 140, 132, + 100, 125, 118, 89, 112, 105, 75, 97, 91, 62, 82, 77, 49, 68, 62, + 33, 51, 47, 12, 29, 26, 0, 0, 0, 115, 140, 116, 102, 125, 103, + 90, 111, 91, 76, 96, 78, 62, 82, 65, 49, 67, 52, 34, 51, 38, + 13, 29, 18, 0, 0, 0, 117, 139, 97, 103, 124, 87, 91, 111, 77, + 78, 96, 65, 63, 81, 54, 49, 67, 41, 34, 51, 27, 12, 29, 7, + 0, 0, 0, 119, 138, 78, 105, 124, 69, 92, 110, 60, 78, 95, 50, + 65, 81, 40, 50, 67, 29, 34, 51, 15, 13, 30, 0, 0, 0, 0, + 120, 138, 64, 106, 124, 54, 93, 110, 47, 78, 95, 38, 65, 81, 29, + 50, 66, 17, 34, 50, 2, 13, 29, 0, 0, 0, 0, 107, 124, 189, + 96, 111, 169, 85, 99, 152, 73, 85, 132, 61, 71, 114, 48, 57, 95, + 34, 41, 75, 14, 18, 51, 0, 0, 13, 111, 124, 171, 100, 111, 153, + 88, 99, 137, 75, 85, 120, 63, 72, 103, 50, 58, 85, 36, 41, 66, + 15, 19, 43, 0, 0, 4, 113, 124, 156, 101, 111, 139, 90, 99, 125, + 77, 85, 109, 64, 71, 93, 51, 57, 77, 36, 42, 59, 17, 20, 37, + 0, 0, 0, 115, 124, 140, 103, 111, 125, 90, 99, 112, 78, 85, 97, + 64, 71, 82, 52, 57, 67, 36, 42, 50, 16, 20, 30, 0, 0, 0, + 117, 123, 125, 104, 110, 111, 92, 98, 99, 79, 85, 86, 65, 71, 72, + 51, 58, 59, 37, 42, 43, 17, 21, 22, 0, 0, 0, 118, 123, 110, + 105, 110, 97, 93, 98, 86, 78, 84, 74, 66, 71, 62, 52, 57, 49, + 37, 42, 34, 17, 22, 14, 0, 0, 0, 120, 123, 93, 106, 109, 82, + 94, 97, 72, 80, 84, 61, 66, 71, 50, 52, 57, 38, 37, 42, 24, + 17, 22, 2, 0, 0, 0, 121, 122, 75, 108, 109, 66, 95, 97, 58, + 80, 84, 48, 66, 71, 37, 52, 57, 26, 37, 42, 12, 16, 22, 0, + 0, 0, 0, 122, 123, 62, 108, 109, 52, 95, 97, 45, 81, 84, 36, + 67, 70, 26, 52, 57, 14, 37, 42, 0, 15, 22, 0, 0, 0, 0, + 113, 107, 177, 102, 96, 159, 89, 85, 141, 78, 72, 124, 65, 60, 107, + 52, 46, 89, 37, 30, 70, 18, 5, 46, 0, 0, 6, 116, 107, 160, + 104, 96, 144, 92, 85, 129, 80, 72, 112, 67, 60, 96, 53, 47, 80, + 38, 31, 62, 19, 7, 39, 0, 0, 0, 118, 107, 147, 105, 96, 131, + 93, 85, 118, 80, 72, 101, 67, 60, 87, 54, 47, 71, 39, 31, 54, + 19, 8, 32, 0, 0, 0, 119, 107, 132, 106, 96, 118, 94, 85, 106, + 81, 73, 91, 67, 60, 77, 54, 47, 63, 39, 32, 47, 20, 9, 25, + 0, 0, 0, 119, 107, 118, 106, 95, 105, 94, 85, 93, 81, 72, 80, + 68, 60, 68, 54, 47, 54, 39, 32, 39, 20, 11, 18, 0, 0, 0, + 121, 107, 104, 107, 96, 92, 95, 84, 80, 81, 72, 69, 68, 61, 58, + 54, 48, 46, 39, 33, 31, 20, 12, 9, 0, 0, 0, 123, 107, 88, + 108, 95, 77, 96, 84, 68, 82, 72, 57, 68, 60, 46, 54, 47, 35, + 39, 33, 20, 19, 13, 2, 0, 0, 0, 123, 106, 72, 110, 95, 63, + 96, 84, 54, 82, 72, 45, 69, 60, 35, 55, 48, 23, 39, 33, 9, + 18, 14, 0, 0, 0, 0, 125, 106, 60, 110, 94, 50, 98, 84, 42, + 83, 72, 34, 69, 60, 25, 55, 48, 12, 39, 33, 0, 17, 13, 0, + 0, 0, 0, 118, 89, 165, 105, 79, 148, 93, 69, 132, 81, 57, 115, + 68, 45, 99, 55, 32, 82, 41, 15, 64, 21, 0, 41, 0, 0, 0, + 120, 89, 150, 107, 79, 135, 96, 69, 121, 82, 58, 105, 70, 46, 89, + 56, 34, 73, 41, 17, 56, 21, 0, 34, 0, 0, 0, 121, 89, 137, + 108, 79, 123, 96, 69, 109, 82, 58, 95, 70, 47, 81, 56, 34, 66, + 41, 18, 49, 21, 0, 28, 0, 0, 0, 122, 90, 124, 109, 79, 110, + 96, 69, 99, 83, 58, 85, 70, 47, 72, 56, 35, 58, 41, 19, 42, + 21, 0, 22, 0, 0, 0, 123, 90, 111, 110, 79, 98, 97, 69, 87, + 83, 59, 75, 70, 47, 63, 56, 35, 50, 41, 20, 35, 21, 0, 14, + 0, 0, 0, 123, 90, 98, 110, 79, 87, 97, 70, 76, 84, 58, 64, + 70, 48, 53, 56, 36, 41, 40, 21, 26, 21, 0, 5, 0, 0, 0, + 125, 89, 84, 111, 79, 73, 97, 69, 64, 84, 59, 54, 70, 48, 43, + 56, 36, 31, 40, 22, 17, 20, 1, 1, 0, 0, 0, 125, 89, 69, + 112, 79, 60, 98, 70, 51, 84, 59, 42, 70, 48, 32, 56, 36, 20, + 41, 22, 5, 19, 2, 0, 0, 0, 0, 126, 89, 57, 112, 79, 49, + 99, 70, 41, 84, 59, 32, 70, 48, 22, 56, 36, 10, 40, 22, 0, + 18, 2, 0, 0, 0, 0, 121, 67, 154, 108, 58, 138, 97, 50, 124, + 84, 39, 107, 71, 28, 92, 58, 12, 76, 43, 0, 59, 20, 0, 37, + 0, 0, 0, 124, 68, 140, 111, 59, 126, 98, 50, 112, 84, 40, 98, + 71, 29, 83, 58, 15, 67, 42, 0, 51, 20, 0, 30, 0, 0, 0, + 124, 68, 129, 111, 59, 114, 99, 51, 102, 86, 41, 88, 71, 30, 75, + 58, 17, 60, 42, 0, 45, 20, 0, 24, 0, 0, 0, 125, 70, 116, + 111, 60, 103, 99, 51, 92, 85, 41, 79, 71, 31, 66, 58, 19, 53, + 42, 3, 38, 20, 0, 17, 0, 0, 0, 125, 70, 104, 111, 61, 93, + 99, 52, 81, 85, 43, 69, 72, 32, 58, 58, 20, 45, 42, 4, 31, + 20, 0, 8, 0, 0, 0, 126, 70, 92, 111, 61, 81, 99, 52, 71, + 85, 42, 60, 71, 33, 49, 57, 21, 37, 42, 6, 23, 20, 0, 3, + 0, 0, 0, 126, 70, 79, 112, 61, 70, 99, 53, 60, 85, 43, 50, + 71, 33, 39, 57, 22, 28, 41, 7, 13, 19, 0, 0, 0, 0, 0, + 127, 71, 66, 113, 62, 56, 100, 53, 48, 86, 44, 39, 71, 34, 29, + 57, 23, 18, 41, 8, 2, 18, 0, 0, 0, 0, 0, 128, 70, 55, + 114, 62, 46, 100, 54, 39, 86, 44, 30, 71, 34, 20, 57, 23, 7, + 41, 9, 0, 18, 0, 0, 0, 0, 0, 124, 41, 145, 111, 32, 128, + 99, 23, 114, 86, 10, 100, 73, 0, 85, 60, 0, 71, 43, 0, 54, + 17, 0, 32, 0, 0, 0, 126, 42, 131, 113, 33, 117, 100, 25, 104, + 86, 14, 90, 73, 0, 77, 60, 0, 63, 44, 0, 47, 18, 0, 25, + 0, 0, 0, 127, 43, 120, 113, 34, 106, 101, 26, 95, 86, 17, 82, + 73, 2, 69, 59, 0, 56, 43, 0, 41, 18, 0, 19, 0, 0, 0, + 127, 45, 109, 113, 37, 97, 101, 28, 85, 86, 19, 74, 73, 5, 61, + 59, 0, 48, 43, 0, 34, 19, 0, 11, 0, 0, 0, 127, 46, 98, + 114, 38, 86, 100, 30, 76, 87, 21, 65, 73, 9, 54, 59, 0, 41, + 43, 0, 26, 18, 0, 5, 0, 0, 0, 127, 47, 87, 113, 39, 76, + 101, 31, 67, 86, 22, 56, 72, 11, 45, 59, 0, 33, 43, 0, 19, + 18, 0, 2, 0, 0, 0, 128, 48, 75, 114, 39, 65, 101, 33, 56, + 86, 23, 46, 72, 12, 36, 58, 0, 24, 42, 0, 9, 17, 0, 0, + 0, 0, 0, 129, 48, 63, 114, 41, 54, 102, 33, 46, 87, 24, 36, + 72, 14, 26, 58, 1, 14, 42, 0, 2, 16, 0, 0, 0, 0, 0, + 128, 48, 53, 114, 41, 44, 102, 34, 37, 87, 25, 27, 72, 15, 17, + 58, 1, 3, 41, 0, 0, 15, 0, 0, 0, 0, 0, 0, 189, 242, + 0, 169, 217, 0, 151, 194, 0, 132, 170, 0, 113, 147, 0, 94, 123, + 0, 74, 99, 0, 51, 71, 0, 15, 34, 1, 187, 219, 1, 167, 195, + 0, 150, 175, 0, 131, 153, 0, 113, 132, 0, 94, 111, 0, 74, 89, + 0, 50, 63, 0, 13, 28, 1, 186, 198, 1, 167, 178, 0, 149, 158, + 0, 130, 139, 0, 111, 119, 0, 93, 100, 0, 74, 80, 0, 50, 55, + 0, 13, 22, 1, 185, 176, 1, 165, 159, 1, 148, 142, 0, 129, 123, + 0, 111, 106, 0, 93, 89, 0, 73, 70, 0, 50, 47, 0, 13, 13, + 1, 184, 157, 1, 164, 141, 1, 147, 125, 0, 128, 110, 0, 110, 93, + 0, 92, 77, 0, 73, 60, 0, 50, 39, 0, 12, 5, 25, 182, 137, + 25, 163, 122, 17, 146, 109, 0, 128, 96, 0, 110, 81, 0, 92, 66, + 0, 73, 51, 0, 50, 30, 0, 10, 0, 42, 181, 114, 35, 163, 102, + 30, 145, 91, 14, 127, 80, 0, 109, 67, 0, 91, 53, 0, 72, 39, + 0, 50, 19, 0, 10, 0, 52, 181, 92, 43, 162, 83, 32, 145, 73, + 19, 126, 63, 0, 108, 52, 0, 90, 40, 0, 72, 27, 0, 50, 7, + 0, 10, 0, 57, 181, 74, 48, 162, 66, 37, 144, 57, 24, 126, 49, + 7, 108, 40, 0, 90, 29, 0, 72, 15, 0, 49, 0, 0, 10, 0, + 1, 170, 227, 1, 152, 203, 0, 136, 182, 0, 119, 159, 0, 101, 137, + 0, 84, 115, 0, 65, 92, 0, 43, 66, 0, 1, 29, 1, 169, 206, + 1, 151, 184, 1, 136, 165, 0, 118, 144, 0, 102, 125, 0, 84, 105, + 0, 65, 83, 0, 43, 58, 0, 0, 22, 29, 168, 186, 21, 151, 167, + 14, 135, 150, 4, 118, 131, 0, 101, 112, 0, 83, 94, 0, 65, 75, + 0, 43, 51, 0, 0, 16, 41, 167, 167, 33, 150, 150, 31, 134, 134, + 19, 117, 117, 4, 100, 100, 0, 83, 83, 0, 65, 65, 0, 42, 43, + 0, 0, 8, 48, 167, 149, 41, 149, 133, 33, 133, 118, 25, 116, 103, + 13, 99, 88, 0, 83, 73, 0, 65, 56, 0, 42, 35, 0, 0, 0, + 58, 165, 130, 49, 148, 115, 42, 132, 103, 31, 115, 89, 18, 99, 75, + 0, 82, 61, 0, 64, 46, 0, 42, 26, 0, 0, 0, 62, 164, 110, + 55, 147, 97, 45, 132, 87, 35, 115, 75, 22, 98, 63, 5, 82, 50, + 0, 64, 36, 0, 42, 16, 0, 0, 0, 69, 164, 89, 60, 147, 78, + 50, 131, 70, 37, 114, 59, 26, 98, 49, 10, 81, 37, 0, 64, 24, + 0, 42, 4, 0, 0, 0, 71, 164, 71, 63, 147, 63, 53, 131, 55, + 40, 114, 47, 28, 98, 38, 13, 81, 26, 0, 64, 12, 0, 42, 0, + 0, 0, 0, 28, 153, 214, 24, 138, 193, 23, 123, 171, 16, 107, 150, + 0, 91, 130, 0, 75, 109, 0, 58, 87, 0, 35, 61, 0, 0, 25, + 48, 153, 194, 41, 138, 174, 34, 123, 156, 27, 107, 136, 16, 91, 117, + 1, 75, 98, 0, 57, 78, 0, 35, 53, 0, 0, 17, 55, 153, 177, + 47, 137, 158, 42, 122, 142, 33, 107, 124, 22, 91, 106, 6, 75, 88, + 0, 57, 70, 0, 35, 46, 0, 0, 9, 61, 152, 158, 53, 136, 143, + 45, 122, 127, 36, 106, 111, 24, 90, 94, 10, 74, 78, 0, 57, 61, + 0, 35, 39, 0, 0, 2, 67, 151, 141, 59, 135, 126, 49, 121, 112, + 39, 105, 98, 29, 90, 83, 14, 74, 68, 0, 57, 52, 0, 35, 31, + 0, 0, 0, 71, 150, 123, 62, 135, 110, 54, 120, 98, 42, 105, 84, + 31, 89, 71, 16, 74, 58, 0, 57, 43, 0, 35, 22, 0, 0, 0, + 74, 150, 105, 64, 134, 92, 55, 120, 83, 45, 104, 71, 34, 89, 59, + 20, 73, 47, 0, 57, 32, 0, 35, 13, 0, 0, 0, 78, 149, 84, + 69, 134, 75, 59, 120, 66, 47, 103, 56, 34, 88, 46, 22, 73, 34, + 1, 57, 20, 0, 35, 1, 0, 0, 0, 80, 149, 69, 70, 133, 61, + 60, 119, 53, 49, 103, 44, 36, 88, 35, 23, 73, 24, 2, 56, 10, + 0, 35, 0, 0, 0, 0, 58, 136, 200, 50, 122, 180, 45, 109, 162, + 38, 94, 141, 27, 80, 121, 15, 65, 102, 0, 48, 81, 0, 26, 56, + 0, 0, 19, 66, 136, 182, 59, 122, 163, 52, 109, 146, 42, 94, 128, + 32, 80, 109, 20, 65, 91, 2, 48, 72, 0, 26, 49, 0, 0, 11, + 70, 136, 165, 62, 122, 149, 55, 108, 133, 46, 94, 116, 35, 80, 99, + 21, 65, 82, 4, 49, 64, 0, 26, 41, 0, 0, 3, 76, 135, 149, + 66, 121, 133, 58, 108, 119, 48, 94, 103, 36, 79, 88, 23, 65, 73, + 7, 49, 56, 0, 27, 34, 0, 0, 0, 78, 135, 133, 69, 120, 118, + 60, 107, 106, 50, 93, 92, 39, 79, 77, 26, 65, 63, 8, 49, 47, + 0, 27, 26, 0, 0, 0, 82, 134, 117, 71, 120, 104, 62, 107, 92, + 51, 93, 79, 39, 78, 66, 27, 64, 53, 10, 48, 39, 0, 27, 18, + 0, 0, 0, 84, 134, 99, 73, 119, 87, 64, 106, 77, 53, 92, 66, + 42, 78, 55, 28, 64, 42, 11, 48, 29, 0, 28, 9, 0, 0, 0, + 87, 133, 81, 76, 119, 72, 66, 106, 62, 55, 92, 52, 43, 78, 42, + 29, 64, 31, 12, 48, 17, 0, 28, 0, 0, 0, 0, 88, 134, 67, + 77, 119, 58, 68, 106, 51, 56, 92, 42, 44, 78, 32, 30, 64, 20, + 12, 48, 6, 0, 28, 0, 0, 0, 0, 73, 120, 189, 64, 107, 168, + 57, 96, 151, 47, 82, 133, 38, 69, 114, 26, 55, 95, 11, 39, 75, + 0, 16, 51, 0, 0, 14, 78, 120, 171, 69, 107, 153, 62, 95, 137, + 51, 82, 119, 40, 69, 102, 29, 55, 85, 15, 39, 66, 0, 17, 44, + 0, 0, 4, 81, 120, 156, 71, 107, 140, 64, 95, 125, 53, 82, 109, + 42, 69, 93, 31, 55, 77, 16, 39, 59, 0, 18, 37, 0, 0, 0, + 85, 120, 141, 74, 107, 126, 65, 95, 112, 54, 82, 97, 43, 69, 82, + 32, 55, 67, 17, 39, 51, 0, 19, 30, 0, 0, 0, 86, 119, 126, + 76, 106, 112, 66, 95, 100, 56, 81, 85, 45, 69, 72, 33, 55, 59, + 18, 40, 43, 0, 19, 22, 0, 0, 0, 89, 119, 110, 78, 106, 98, + 69, 94, 87, 56, 81, 75, 46, 68, 62, 33, 55, 49, 18, 40, 35, + 0, 20, 15, 0, 0, 0, 89, 119, 95, 80, 106, 83, 70, 94, 73, + 58, 81, 63, 46, 68, 51, 34, 55, 39, 19, 40, 25, 0, 20, 4, + 0, 0, 0, 92, 118, 78, 82, 106, 68, 70, 93, 59, 59, 81, 49, + 47, 68, 39, 34, 55, 28, 19, 40, 14, 0, 20, 0, 0, 0, 0, + 93, 118, 65, 82, 105, 55, 72, 93, 48, 60, 81, 39, 47, 68, 29, + 34, 55, 18, 20, 40, 2, 0, 20, 0, 0, 0, 0, 83, 104, 177, + 74, 93, 159, 65, 82, 142, 56, 70, 124, 45, 57, 106, 33, 44, 89, + 20, 28, 70, 1, 4, 46, 0, 0, 8, 86, 104, 161, 78, 93, 145, + 68, 82, 128, 58, 70, 112, 48, 58, 96, 35, 45, 80, 21, 29, 62, + 1, 6, 40, 0, 0, 0, 89, 104, 147, 79, 93, 131, 69, 82, 118, + 59, 70, 102, 47, 58, 87, 36, 45, 72, 23, 29, 55, 3, 7, 33, + 0, 0, 0, 90, 104, 132, 80, 93, 119, 71, 82, 106, 60, 70, 91, + 48, 58, 77, 37, 45, 62, 23, 30, 47, 4, 7, 26, 0, 0, 0, + 92, 104, 118, 82, 93, 105, 72, 82, 93, 61, 69, 80, 50, 58, 68, + 37, 45, 55, 23, 30, 39, 4, 8, 18, 0, 0, 0, 94, 104, 105, + 82, 92, 93, 72, 82, 82, 61, 70, 70, 50, 58, 58, 38, 46, 46, + 23, 31, 31, 6, 10, 11, 0, 0, 0, 95, 104, 90, 84, 92, 79, + 74, 82, 70, 62, 70, 58, 50, 58, 48, 37, 46, 36, 23, 31, 22, + 4, 11, 3, 0, 0, 0, 96, 103, 74, 85, 92, 65, 75, 81, 56, + 63, 70, 47, 50, 58, 37, 38, 46, 25, 24, 31, 11, 3, 11, 0, + 0, 0, 0, 97, 103, 62, 86, 92, 53, 76, 81, 45, 63, 69, 36, + 51, 58, 27, 38, 46, 15, 23, 31, 0, 3, 11, 0, 0, 0, 0, + 90, 87, 165, 81, 77, 148, 72, 67, 132, 62, 55, 116, 50, 44, 99, + 39, 31, 82, 25, 14, 64, 1, 0, 42, 0, 0, 1, 93, 87, 150, + 83, 77, 135, 74, 67, 121, 63, 56, 105, 52, 45, 90, 40, 32, 74, + 25, 16, 57, 3, 0, 35, 0, 0, 0, 95, 87, 138, 85, 77, 123, + 75, 67, 109, 63, 57, 95, 53, 45, 81, 41, 33, 66, 26, 17, 50, + 4, 0, 28, 0, 0, 0, 95, 88, 124, 85, 77, 111, 75, 67, 99, + 63, 57, 86, 53, 45, 72, 41, 33, 58, 26, 18, 43, 5, 1, 22, + 0, 0, 0, 97, 88, 112, 87, 77, 100, 76, 68, 88, 64, 57, 76, + 53, 46, 63, 41, 34, 50, 26, 19, 35, 5, 2, 14, 0, 0, 0, + 99, 87, 99, 87, 78, 88, 76, 68, 77, 65, 57, 65, 53, 46, 54, + 41, 35, 42, 27, 20, 27, 6, 2, 5, 0, 0, 0, 100, 87, 85, + 88, 77, 75, 77, 68, 65, 65, 57, 54, 53, 46, 44, 41, 35, 32, + 27, 21, 19, 5, 3, 2, 0, 0, 0, 100, 88, 71, 89, 77, 61, + 78, 68, 53, 66, 57, 44, 53, 47, 33, 41, 35, 22, 27, 21, 7, + 5, 3, 0, 0, 0, 0, 101, 87, 60, 90, 77, 52, 79, 68, 44, + 66, 58, 34, 53, 47, 25, 41, 35, 13, 26, 22, 0, 5, 3, 0, + 0, 0, 0, 97, 67, 155, 86, 58, 138, 77, 50, 125, 66, 39, 108, + 55, 28, 92, 43, 12, 76, 29, 0, 59, 2, 0, 37, 0, 0, 0, + 99, 67, 141, 88, 59, 127, 78, 50, 113, 68, 40, 98, 56, 29, 83, + 44, 15, 68, 29, 0, 52, 3, 0, 30, 0, 0, 0, 100, 68, 129, + 89, 59, 115, 80, 51, 103, 68, 41, 89, 56, 30, 75, 44, 16, 61, + 30, 0, 45, 4, 0, 24, 0, 0, 0, 100, 69, 118, 90, 60, 104, + 80, 51, 92, 67, 41, 79, 56, 31, 66, 44, 18, 53, 29, 2, 38, + 4, 0, 18, 0, 0, 0, 101, 69, 104, 90, 61, 93, 79, 51, 82, + 67, 42, 70, 56, 32, 59, 44, 20, 46, 29, 4, 31, 6, 0, 9, + 0, 0, 0, 102, 69, 93, 90, 61, 83, 80, 52, 72, 68, 42, 61, + 56, 33, 50, 43, 20, 38, 29, 5, 23, 7, 0, 4, 0, 0, 0, + 102, 70, 80, 91, 61, 71, 80, 52, 61, 68, 43, 51, 56, 32, 40, + 44, 21, 29, 30, 6, 14, 7, 0, 0, 0, 0, 0, 103, 70, 68, + 92, 61, 58, 81, 53, 50, 69, 43, 41, 56, 34, 31, 43, 22, 19, + 29, 7, 3, 7, 0, 0, 0, 0, 0, 104, 70, 57, 92, 61, 48, + 82, 53, 40, 69, 43, 32, 56, 34, 22, 43, 23, 10, 29, 8, 0, + 6, 0, 0, 0, 0, 0, 101, 45, 145, 91, 35, 129, 80, 26, 116, + 69, 15, 101, 59, 0, 86, 46, 0, 71, 31, 0, 55, 0, 0, 33, + 0, 0, 0, 104, 44, 132, 92, 36, 118, 82, 28, 105, 71, 17, 91, + 58, 3, 77, 46, 0, 63, 31, 0, 48, 2, 0, 26, 0, 0, 0, + 104, 46, 121, 93, 37, 107, 82, 30, 96, 70, 20, 83, 58, 6, 70, + 46, 0, 57, 32, 0, 41, 4, 0, 20, 0, 0, 0, 104, 48, 110, + 93, 40, 98, 82, 31, 87, 70, 22, 74, 59, 9, 62, 45, 0, 49, + 31, 0, 35, 6, 0, 13, 0, 0, 0, 104, 48, 99, 92, 41, 88, + 82, 32, 77, 70, 23, 65, 58, 11, 54, 46, 0, 42, 32, 0, 27, + 7, 0, 5, 0, 0, 0, 105, 50, 88, 93, 41, 77, 82, 34, 68, + 71, 24, 57, 58, 13, 46, 45, 1, 35, 31, 0, 21, 7, 0, 2, + 0, 0, 0, 105, 50, 76, 94, 41, 66, 83, 34, 57, 71, 25, 47, + 58, 15, 37, 45, 2, 25, 32, 0, 11, 7, 0, 0, 0, 0, 0, + 106, 50, 64, 94, 42, 55, 83, 35, 47, 71, 26, 38, 58, 16, 27, + 45, 4, 17, 31, 0, 4, 7, 0, 0, 0, 0, 0, 106, 51, 54, + 95, 42, 45, 83, 35, 38, 71, 27, 30, 58, 16, 19, 45, 5, 7, + 30, 0, 0, 6, 0, 0, 0, 0, 0, 0, 181, 240, 0, 162, 216, + 0, 144, 193, 0, 126, 168, 0, 109, 146, 0, 91, 123, 0, 71, 98, + 0, 48, 71, 0, 9, 34, 0, 179, 218, 0, 161, 195, 0, 144, 174, + 0, 126, 153, 0, 108, 132, 0, 90, 110, 0, 71, 88, 0, 48, 63, + 0, 8, 29, 0, 178, 197, 0, 159, 177, 0, 143, 159, 0, 125, 139, + 0, 107, 119, 0, 90, 99, 0, 71, 79, 0, 48, 55, 0, 8, 22, + 0, 177, 177, 0, 158, 158, 0, 142, 141, 0, 124, 123, 0, 107, 106, + 0, 89, 88, 0, 71, 70, 0, 48, 47, 0, 8, 14, 0, 176, 157, + 0, 158, 141, 0, 141, 126, 0, 123, 109, 0, 106, 93, 0, 89, 78, + 0, 70, 60, 0, 47, 39, 0, 7, 5, 0, 175, 138, 0, 157, 123, + 0, 141, 110, 0, 123, 96, 0, 105, 81, 0, 88, 67, 0, 70, 51, + 0, 48, 30, 0, 6, 0, 0, 173, 115, 0, 155, 104, 0, 140, 92, + 0, 122, 80, 0, 105, 67, 0, 88, 55, 0, 69, 40, 0, 47, 20, + 0, 6, 0, 0, 173, 94, 0, 155, 85, 0, 139, 75, 0, 121, 64, + 0, 104, 53, 0, 88, 42, 0, 70, 28, 0, 47, 9, 0, 6, 0, + 0, 173, 76, 0, 155, 70, 0, 138, 61, 0, 122, 53, 0, 104, 44, + 0, 87, 32, 0, 69, 18, 0, 47, 0, 0, 6, 0, 0, 164, 226, + 0, 147, 203, 0, 131, 181, 0, 114, 158, 0, 97, 136, 0, 80, 115, + 0, 63, 92, 0, 40, 65, 0, 0, 30, 0, 162, 205, 0, 145, 184, + 0, 130, 164, 0, 114, 143, 0, 97, 124, 0, 81, 104, 0, 63, 83, + 0, 40, 58, 0, 0, 23, 0, 162, 187, 0, 145, 167, 0, 130, 150, + 0, 113, 131, 0, 96, 112, 0, 80, 93, 0, 62, 74, 0, 40, 50, + 0, 0, 16, 0, 160, 167, 0, 144, 150, 0, 129, 134, 0, 112, 116, + 0, 96, 100, 0, 80, 82, 0, 62, 65, 0, 40, 43, 0, 0, 7, + 0, 160, 148, 0, 143, 133, 0, 128, 118, 0, 111, 103, 0, 96, 88, + 0, 80, 73, 0, 62, 56, 0, 40, 35, 0, 0, 0, 0, 158, 130, + 0, 142, 117, 0, 127, 104, 0, 111, 89, 0, 95, 76, 0, 79, 62, + 0, 62, 46, 0, 40, 26, 0, 0, 0, 0, 158, 111, 0, 141, 99, + 0, 127, 88, 0, 111, 76, 0, 95, 63, 0, 79, 51, 0, 62, 37, + 0, 40, 18, 0, 0, 0, 0, 158, 91, 0, 141, 81, 0, 126, 72, + 0, 110, 62, 0, 94, 50, 0, 79, 39, 0, 62, 25, 0, 40, 5, + 0, 0, 0, 0, 157, 74, 0, 141, 66, 0, 126, 59, 0, 110, 49, + 0, 94, 40, 0, 78, 29, 0, 61, 15, 0, 40, 0, 0, 0, 0, + 0, 148, 214, 0, 133, 192, 0, 119, 171, 0, 103, 150, 0, 87, 129, + 0, 72, 108, 0, 55, 86, 0, 32, 61, 0, 0, 25, 0, 147, 193, + 0, 132, 173, 0, 118, 155, 0, 103, 136, 0, 87, 116, 0, 72, 98, + 0, 55, 78, 0, 32, 53, 0, 0, 17, 0, 147, 176, 0, 132, 158, + 0, 118, 142, 0, 102, 124, 0, 87, 106, 0, 72, 88, 0, 55, 69, + 0, 33, 46, 0, 0, 9, 0, 146, 159, 0, 131, 142, 0, 117, 127, + 0, 102, 111, 0, 87, 95, 0, 71, 79, 0, 55, 61, 0, 33, 39, + 0, 0, 2, 0, 145, 140, 0, 130, 126, 0, 117, 112, 0, 101, 98, + 0, 86, 83, 0, 71, 68, 0, 55, 52, 0, 33, 31, 0, 0, 0, + 0, 144, 124, 0, 130, 111, 0, 116, 99, 0, 101, 84, 0, 86, 72, + 0, 71, 59, 0, 55, 43, 0, 33, 23, 0, 0, 0, 0, 144, 106, + 0, 129, 94, 0, 115, 83, 0, 101, 72, 0, 85, 60, 0, 71, 48, + 0, 55, 34, 0, 33, 14, 0, 0, 0, 3, 143, 86, 0, 129, 77, + 0, 115, 68, 0, 100, 58, 0, 85, 48, 0, 70, 36, 0, 54, 22, + 0, 33, 3, 0, 0, 0, 18, 143, 72, 13, 128, 63, 0, 115, 57, + 0, 100, 47, 0, 85, 37, 0, 70, 26, 0, 54, 13, 0, 33, 0, + 0, 0, 0, 0, 132, 200, 0, 118, 179, 0, 105, 161, 0, 91, 140, + 0, 76, 121, 0, 62, 101, 0, 46, 81, 0, 24, 56, 0, 0, 19, + 0, 131, 182, 0, 118, 163, 0, 105, 146, 0, 91, 128, 0, 77, 110, + 0, 62, 91, 0, 46, 72, 0, 25, 48, 0, 0, 11, 0, 131, 165, + 0, 117, 149, 0, 104, 133, 0, 91, 116, 0, 77, 99, 0, 62, 82, + 0, 46, 64, 0, 25, 41, 0, 0, 4, 0, 131, 149, 0, 116, 134, + 0, 104, 119, 0, 91, 104, 0, 77, 89, 0, 62, 73, 0, 46, 56, + 0, 25, 34, 0, 0, 0, 10, 130, 133, 2, 116, 119, 0, 104, 106, + 0, 90, 91, 0, 76, 78, 0, 62, 64, 0, 46, 48, 0, 26, 27, + 0, 0, 0, 23, 130, 118, 20, 116, 104, 13, 103, 93, 3, 89, 79, + 0, 76, 67, 0, 62, 54, 0, 46, 39, 0, 26, 19, 0, 0, 0, + 33, 129, 101, 27, 115, 89, 19, 103, 79, 9, 89, 67, 0, 75, 56, + 0, 61, 43, 0, 46, 29, 0, 26, 10, 0, 0, 0, 41, 128, 83, + 35, 115, 73, 27, 102, 64, 15, 89, 55, 0, 76, 45, 0, 62, 33, + 0, 46, 18, 0, 26, 0, 0, 0, 0, 43, 129, 69, 38, 115, 61, + 30, 102, 54, 17, 89, 45, 2, 75, 34, 0, 61, 23, 0, 46, 9, + 0, 26, 0, 0, 0, 0, 1, 116, 188, 1, 104, 168, 0, 92, 151, + 0, 79, 132, 0, 66, 113, 0, 52, 94, 0, 36, 75, 0, 14, 52, + 0, 0, 14, 17, 116, 171, 16, 104, 153, 14, 92, 137, 8, 79, 119, + 0, 67, 102, 0, 53, 85, 0, 37, 67, 0, 16, 44, 0, 0, 4, + 31, 116, 155, 27, 104, 140, 21, 92, 125, 13, 79, 109, 3, 66, 93, + 0, 53, 77, 0, 37, 59, 0, 16, 38, 0, 0, 0, 37, 115, 141, + 30, 103, 126, 26, 92, 112, 16, 79, 98, 5, 66, 83, 0, 53, 67, + 0, 38, 51, 0, 17, 31, 0, 0, 0, 41, 115, 126, 37, 103, 112, + 31, 92, 100, 22, 79, 86, 10, 66, 72, 0, 53, 59, 0, 38, 44, + 0, 17, 23, 0, 0, 0, 48, 115, 111, 41, 102, 99, 34, 91, 88, + 24, 78, 76, 14, 66, 63, 0, 53, 50, 0, 38, 36, 0, 18, 15, + 0, 0, 0, 51, 115, 95, 46, 102, 85, 37, 91, 74, 26, 78, 63, + 16, 66, 52, 0, 53, 40, 0, 38, 26, 0, 18, 5, 0, 0, 0, + 55, 114, 80, 47, 102, 69, 40, 90, 60, 30, 78, 51, 19, 66, 41, + 3, 53, 29, 0, 38, 15, 0, 17, 0, 0, 0, 0, 56, 114, 66, + 50, 102, 58, 40, 91, 50, 32, 78, 41, 18, 66, 32, 4, 53, 21, + 0, 38, 5, 0, 17, 0, 0, 0, 0, 39, 102, 178, 37, 90, 159, + 30, 79, 142, 21, 68, 124, 14, 55, 106, 0, 42, 89, 0, 26, 70, + 0, 4, 46, 0, 0, 8, 48, 102, 161, 42, 90, 145, 35, 79, 128, + 26, 68, 112, 19, 55, 96, 3, 43, 79, 0, 27, 62, 0, 6, 40, + 0, 0, 0, 50, 102, 147, 44, 90, 132, 37, 79, 118, 30, 68, 102, + 20, 56, 87, 7, 43, 72, 0, 28, 55, 0, 6, 34, 0, 0, 0, + 53, 101, 133, 47, 90, 118, 41, 79, 106, 32, 68, 91, 21, 56, 78, + 9, 43, 63, 0, 28, 47, 0, 6, 26, 0, 0, 0, 57, 101, 119, + 50, 89, 106, 42, 79, 94, 34, 67, 81, 24, 56, 68, 9, 44, 55, + 0, 29, 40, 0, 6, 19, 0, 0, 0, 60, 100, 105, 50, 90, 94, + 45, 80, 83, 36, 68, 71, 24, 56, 59, 11, 44, 46, 0, 29, 32, + 0, 7, 12, 0, 0, 0, 63, 101, 91, 55, 90, 80, 46, 79, 70, + 37, 68, 59, 26, 56, 49, 12, 44, 37, 1, 29, 23, 0, 7, 3, + 0, 0, 0, 64, 101, 75, 56, 89, 67, 48, 79, 57, 37, 68, 48, + 27, 56, 37, 15, 44, 26, 0, 29, 12, 0, 7, 0, 0, 0, 0, + 66, 101, 64, 58, 89, 55, 49, 79, 47, 39, 68, 38, 27, 56, 29, + 14, 44, 18, 1, 30, 2, 0, 7, 0, 0, 0, 0, 57, 86, 165, + 51, 75, 148, 45, 65, 133, 38, 54, 116, 28, 43, 100, 16, 29, 83, + 0, 13, 64, 0, 0, 42, 0, 0, 3, 60, 86, 151, 55, 75, 135, + 47, 66, 121, 39, 55, 105, 30, 44, 90, 18, 31, 74, 3, 16, 57, + 0, 1, 35, 0, 0, 0, 62, 86, 139, 56, 75, 123, 49, 66, 110, + 40, 55, 95, 30, 44, 81, 19, 31, 66, 4, 17, 51, 0, 1, 29, + 0, 0, 0, 65, 86, 125, 56, 76, 112, 49, 66, 99, 39, 55, 86, + 31, 44, 72, 19, 32, 59, 5, 18, 44, 0, 1, 23, 0, 0, 0, + 67, 86, 113, 58, 75, 100, 51, 66, 88, 41, 56, 77, 31, 45, 64, + 20, 32, 51, 6, 18, 35, 0, 1, 14, 0, 0, 0, 69, 86, 99, + 61, 76, 88, 52, 66, 78, 43, 56, 66, 32, 45, 55, 20, 33, 42, + 7, 19, 27, 0, 1, 6, 0, 0, 0, 69, 86, 86, 61, 76, 75, + 53, 67, 66, 43, 56, 55, 33, 45, 45, 21, 34, 34, 8, 20, 20, + 0, 2, 2, 0, 0, 0, 71, 86, 72, 63, 75, 62, 54, 66, 55, + 45, 56, 45, 33, 45, 35, 22, 34, 23, 7, 20, 8, 0, 2, 0, + 0, 0, 0, 71, 86, 62, 64, 75, 53, 55, 66, 46, 45, 56, 36, + 33, 46, 27, 22, 34, 15, 8, 20, 0, 0, 2, 0, 0, 0, 0, + 69, 67, 156, 61, 58, 140, 53, 50, 125, 45, 39, 108, 35, 28, 93, + 25, 12, 77, 12, 0, 59, 0, 0, 37, 0, 0, 0, 71, 68, 142, + 63, 59, 126, 56, 50, 114, 47, 40, 98, 37, 28, 84, 26, 15, 68, + 12, 0, 53, 0, 0, 30, 0, 0, 0, 72, 68, 130, 63, 59, 116, + 56, 50, 104, 47, 40, 90, 38, 30, 75, 27, 16, 61, 13, 0, 46, + 0, 0, 24, 0, 0, 0, 73, 69, 118, 65, 59, 105, 57, 51, 92, + 47, 41, 80, 37, 30, 67, 26, 18, 53, 14, 1, 39, 0, 0, 18, + 0, 0, 0, 74, 69, 106, 65, 60, 93, 57, 51, 82, 48, 41, 70, + 38, 31, 59, 26, 19, 46, 13, 2, 32, 0, 0, 10, 0, 0, 0, + 76, 69, 95, 66, 61, 84, 58, 52, 73, 48, 42, 61, 37, 32, 50, + 26, 20, 38, 14, 4, 24, 0, 0, 4, 0, 0, 0, 76, 69, 81, + 68, 60, 72, 58, 52, 62, 48, 42, 51, 38, 32, 41, 27, 21, 30, + 14, 4, 16, 0, 0, 1, 0, 0, 0, 76, 69, 68, 68, 61, 60, + 60, 52, 51, 49, 43, 41, 38, 33, 32, 27, 21, 20, 14, 5, 5, + 0, 0, 0, 0, 0, 0, 78, 70, 59, 69, 61, 50, 60, 52, 42, + 49, 43, 34, 39, 33, 24, 27, 22, 13, 14, 7, 1, 0, 0, 0, + 0, 0, 0, 75, 46, 146, 68, 38, 131, 60, 30, 117, 50, 19, 102, + 41, 4, 87, 29, 0, 72, 13, 0, 55, 0, 0, 33, 0, 0, 0, + 78, 47, 132, 70, 39, 119, 61, 30, 105, 53, 20, 92, 42, 5, 78, + 30, 0, 64, 13, 0, 49, 0, 0, 27, 0, 0, 0, 79, 48, 122, + 70, 40, 108, 62, 32, 96, 52, 22, 84, 42, 9, 71, 30, 0, 58, + 14, 0, 42, 0, 0, 20, 0, 0, 0, 79, 50, 111, 70, 42, 99, + 62, 33, 88, 52, 23, 74, 41, 11, 63, 29, 0, 50, 14, 0, 36, + 0, 0, 14, 0, 0, 0, 80, 50, 99, 70, 42, 89, 61, 34, 78, + 52, 25, 67, 41, 14, 55, 30, 0, 42, 15, 0, 28, 0, 0, 6, + 0, 0, 0, 81, 51, 89, 71, 43, 78, 62, 35, 69, 52, 25, 58, + 42, 15, 47, 30, 3, 36, 15, 0, 22, 0, 0, 3, 0, 0, 0, + 81, 51, 77, 71, 44, 68, 63, 36, 59, 53, 26, 49, 41, 16, 38, + 31, 4, 27, 16, 0, 12, 0, 0, 0, 0, 0, 0, 81, 52, 65, + 72, 43, 56, 63, 36, 48, 53, 27, 39, 41, 17, 29, 30, 4, 18, + 14, 0, 3, 0, 0, 0, 0, 0, 0, 81, 52, 55, 73, 44, 47, + 64, 36, 39, 53, 28, 32, 42, 18, 21, 31, 6, 9, 14, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 174, 239, 0, 156, 214, 0, 139, 192, + 0, 121, 168, 0, 105, 145, 0, 87, 123, 0, 68, 98, 0, 46, 70, + 0, 3, 35, 0, 172, 217, 0, 155, 194, 0, 139, 173, 0, 121, 152, + 0, 104, 130, 0, 87, 110, 0, 69, 88, 0, 46, 63, 0, 4, 28, + 0, 171, 197, 0, 153, 175, 0, 138, 158, 0, 121, 139, 0, 103, 118, + 0, 86, 100, 0, 68, 79, 0, 46, 55, 0, 4, 22, 0, 170, 177, + 0, 152, 158, 0, 136, 141, 0, 119, 124, 0, 103, 106, 0, 86, 88, + 0, 68, 70, 0, 45, 47, 0, 3, 14, 0, 169, 157, 0, 152, 141, + 0, 136, 126, 0, 119, 109, 0, 102, 94, 0, 86, 78, 0, 68, 60, + 0, 46, 39, 0, 3, 5, 0, 167, 138, 0, 150, 124, 0, 135, 111, + 0, 118, 97, 0, 102, 82, 0, 85, 68, 0, 68, 52, 0, 46, 31, + 0, 3, 0, 0, 167, 118, 0, 150, 104, 0, 135, 94, 0, 118, 81, + 0, 101, 69, 0, 84, 56, 0, 67, 41, 0, 45, 21, 0, 3, 0, + 0, 166, 97, 0, 149, 87, 0, 134, 77, 0, 117, 67, 0, 101, 56, + 0, 85, 44, 0, 67, 30, 0, 45, 10, 0, 3, 0, 0, 165, 79, + 0, 149, 73, 0, 133, 64, 0, 117, 56, 0, 101, 46, 0, 85, 34, + 0, 68, 21, 0, 46, 1, 0, 3, 0, 0, 158, 225, 0, 141, 201, + 0, 126, 180, 0, 109, 158, 0, 94, 136, 0, 78, 114, 0, 60, 91, + 0, 38, 66, 0, 0, 30, 0, 156, 203, 0, 140, 183, 0, 125, 164, + 0, 109, 143, 0, 94, 124, 0, 78, 104, 0, 61, 83, 0, 38, 57, + 0, 0, 23, 0, 156, 186, 0, 140, 166, 0, 125, 150, 0, 109, 130, + 0, 93, 111, 0, 77, 93, 0, 60, 74, 0, 38, 50, 0, 0, 17, + 0, 155, 167, 0, 138, 149, 0, 124, 134, 0, 109, 117, 0, 93, 100, + 0, 76, 83, 0, 60, 65, 0, 38, 43, 0, 0, 9, 0, 153, 147, + 0, 138, 134, 0, 124, 120, 0, 107, 103, 0, 92, 88, 0, 77, 73, + 0, 60, 56, 0, 38, 35, 0, 0, 0, 0, 153, 131, 0, 137, 118, + 0, 122, 105, 0, 107, 90, 0, 91, 76, 0, 76, 63, 0, 60, 47, + 0, 39, 28, 0, 0, 0, 0, 153, 111, 0, 136, 100, 0, 123, 90, + 0, 107, 77, 0, 92, 65, 0, 76, 52, 0, 60, 37, 0, 38, 18, + 0, 0, 0, 0, 152, 93, 0, 136, 82, 0, 122, 74, 0, 106, 63, + 0, 91, 52, 0, 76, 40, 0, 59, 26, 0, 38, 6, 0, 0, 0, + 0, 151, 78, 0, 136, 69, 0, 121, 61, 0, 106, 52, 0, 91, 43, + 0, 76, 32, 0, 59, 17, 0, 38, 0, 0, 0, 0, 0, 143, 213, + 0, 128, 191, 0, 115, 171, 0, 100, 149, 0, 84, 128, 0, 69, 108, + 0, 52, 86, 0, 30, 61, 0, 0, 25, 0, 142, 193, 0, 127, 173, + 0, 114, 154, 0, 99, 134, 0, 84, 116, 0, 69, 98, 0, 52, 77, + 0, 31, 53, 0, 0, 18, 0, 141, 176, 0, 127, 158, 0, 114, 141, + 0, 98, 122, 0, 84, 105, 0, 69, 88, 0, 53, 69, 0, 31, 46, + 0, 0, 9, 0, 141, 159, 0, 126, 142, 0, 113, 127, 0, 98, 110, + 0, 83, 95, 0, 69, 78, 0, 53, 60, 0, 32, 39, 0, 0, 2, + 0, 140, 140, 0, 126, 126, 0, 112, 112, 0, 98, 98, 0, 83, 83, + 0, 68, 69, 0, 52, 52, 0, 31, 31, 0, 0, 0, 0, 140, 124, + 0, 125, 112, 0, 112, 100, 0, 97, 86, 0, 83, 72, 0, 68, 59, + 0, 52, 44, 0, 31, 23, 0, 0, 0, 0, 139, 106, 0, 125, 96, + 0, 111, 85, 0, 97, 72, 0, 83, 62, 0, 68, 49, 0, 52, 35, + 0, 31, 15, 0, 0, 0, 0, 138, 88, 0, 124, 79, 0, 111, 70, + 0, 96, 59, 0, 82, 48, 0, 68, 38, 0, 52, 24, 0, 31, 4, + 0, 0, 0, 0, 139, 76, 0, 124, 66, 0, 111, 58, 0, 96, 50, + 0, 82, 40, 0, 68, 29, 0, 52, 15, 0, 31, 0, 0, 0, 0, + 0, 129, 200, 0, 114, 179, 0, 102, 160, 0, 87, 139, 0, 74, 120, + 0, 60, 101, 0, 44, 81, 0, 22, 56, 0, 0, 19, 0, 127, 181, + 0, 114, 163, 0, 102, 146, 0, 88, 127, 0, 74, 109, 0, 60, 91, + 0, 44, 72, 0, 23, 48, 0, 0, 11, 0, 127, 166, 0, 113, 148, + 0, 101, 133, 0, 87, 115, 0, 74, 99, 0, 60, 82, 0, 44, 64, + 0, 23, 42, 0, 0, 4, 0, 127, 150, 0, 113, 134, 0, 101, 119, + 0, 87, 104, 0, 74, 89, 0, 60, 73, 0, 44, 56, 0, 23, 35, + 0, 0, 0, 0, 125, 134, 0, 112, 118, 0, 100, 106, 0, 87, 92, + 0, 73, 78, 0, 60, 64, 0, 44, 48, 0, 23, 27, 0, 0, 0, + 0, 125, 118, 0, 112, 105, 0, 100, 94, 0, 86, 80, 0, 73, 68, + 0, 60, 54, 0, 44, 39, 0, 23, 20, 0, 0, 0, 0, 125, 101, + 0, 111, 90, 0, 99, 80, 0, 86, 69, 0, 73, 58, 0, 59, 45, + 0, 44, 30, 0, 23, 11, 0, 0, 0, 0, 124, 85, 0, 111, 75, + 0, 99, 66, 0, 86, 56, 0, 73, 45, 0, 59, 34, 0, 44, 20, + 0, 23, 1, 0, 0, 0, 0, 125, 72, 0, 111, 62, 0, 99, 56, + 0, 86, 46, 0, 73, 36, 0, 60, 26, 0, 44, 12, 0, 23, 0, + 0, 0, 0, 0, 114, 188, 0, 101, 167, 0, 89, 150, 0, 77, 131, + 0, 64, 113, 0, 50, 95, 0, 34, 75, 0, 12, 52, 0, 0, 14, + 0, 113, 170, 0, 101, 153, 0, 89, 137, 0, 77, 120, 0, 64, 102, + 0, 50, 85, 0, 35, 67, 0, 12, 44, 0, 0, 4, 0, 113, 156, + 0, 100, 139, 0, 89, 125, 0, 77, 109, 0, 64, 92, 0, 51, 77, + 0, 35, 60, 0, 12, 38, 0, 0, 0, 0, 112, 141, 0, 100, 126, + 0, 89, 113, 0, 77, 98, 0, 64, 83, 0, 51, 68, 0, 35, 51, + 0, 12, 30, 0, 0, 0, 0, 112, 127, 0, 100, 112, 0, 89, 100, + 0, 76, 87, 0, 64, 74, 0, 51, 59, 0, 35, 44, 0, 13, 24, + 0, 0, 0, 0, 112, 111, 0, 100, 100, 0, 88, 88, 0, 76, 76, + 0, 64, 64, 0, 51, 52, 0, 36, 37, 0, 13, 17, 0, 0, 0, + 0, 111, 96, 0, 99, 85, 0, 88, 76, 0, 76, 64, 0, 64, 53, + 0, 51, 41, 0, 36, 27, 0, 13, 6, 0, 0, 0, 0, 111, 81, + 0, 99, 71, 0, 88, 62, 0, 76, 52, 0, 64, 43, 0, 51, 31, + 0, 36, 17, 0, 13, 0, 0, 0, 0, 0, 111, 69, 0, 99, 60, + 0, 88, 52, 0, 75, 43, 0, 63, 34, 0, 51, 21, 0, 36, 7, + 0, 13, 0, 0, 0, 0, 0, 99, 177, 0, 88, 158, 0, 77, 141, + 0, 66, 123, 0, 53, 106, 0, 40, 89, 0, 25, 71, 0, 5, 47, + 0, 0, 8, 0, 99, 160, 0, 88, 144, 0, 77, 129, 0, 66, 112, + 0, 54, 97, 0, 41, 80, 0, 26, 62, 0, 5, 40, 0, 0, 0, + 0, 99, 147, 0, 87, 132, 0, 78, 117, 0, 66, 102, 0, 54, 87, + 0, 42, 72, 0, 26, 55, 0, 5, 34, 0, 0, 0, 0, 99, 134, + 0, 88, 119, 0, 77, 107, 0, 66, 92, 0, 54, 78, 0, 42, 64, + 0, 27, 48, 0, 5, 27, 0, 0, 0, 0, 99, 120, 0, 87, 107, + 0, 78, 94, 0, 66, 81, 0, 54, 68, 0, 42, 55, 0, 27, 40, + 0, 6, 20, 0, 0, 0, 0, 98, 105, 0, 87, 94, 0, 77, 84, + 0, 65, 71, 0, 55, 59, 0, 42, 47, 0, 28, 33, 0, 6, 12, + 0, 0, 0, 0, 98, 93, 0, 87, 81, 0, 77, 72, 0, 66, 61, + 0, 54, 49, 0, 42, 37, 0, 28, 24, 0, 6, 4, 0, 0, 0, + 0, 98, 77, 0, 87, 68, 0, 77, 59, 0, 65, 49, 0, 54, 39, + 0, 42, 27, 0, 29, 14, 0, 6, 0, 0, 0, 0, 1, 98, 65, + 7, 87, 56, 0, 77, 49, 0, 66, 41, 0, 54, 30, 0, 42, 19, + 0, 29, 3, 0, 6, 0, 0, 0, 0, 0, 84, 166, 0, 74, 149, + 0, 64, 134, 0, 53, 117, 0, 41, 100, 0, 28, 83, 0, 11, 64, + 0, 0, 42, 0, 0, 3, 0, 84, 151, 0, 74, 135, 0, 64, 121, + 0, 53, 105, 0, 42, 90, 0, 30, 75, 0, 14, 58, 0, 0, 36, + 0, 0, 0, 0, 84, 138, 0, 74, 124, 1, 64, 110, 0, 54, 95, + 0, 43, 81, 0, 30, 67, 0, 15, 51, 0, 1, 29, 0, 0, 0, + 14, 84, 126, 12, 74, 112, 2, 65, 99, 0, 54, 85, 0, 44, 73, + 0, 31, 59, 0, 16, 44, 0, 1, 23, 0, 0, 0, 16, 84, 113, + 13, 74, 100, 6, 65, 89, 0, 54, 77, 0, 44, 65, 0, 31, 51, + 0, 17, 36, 0, 1, 16, 0, 0, 0, 24, 84, 100, 18, 74, 88, + 13, 65, 78, 2, 55, 68, 0, 44, 55, 0, 32, 43, 0, 18, 28, + 0, 1, 6, 0, 0, 0, 26, 84, 87, 24, 74, 76, 17, 65, 67, + 7, 54, 57, 0, 44, 46, 0, 32, 35, 0, 19, 21, 0, 2, 3, + 0, 0, 0, 30, 84, 74, 28, 74, 64, 20, 65, 55, 12, 55, 46, + 0, 44, 35, 0, 32, 24, 0, 18, 9, 0, 1, 0, 0, 0, 0, + 32, 84, 63, 28, 74, 54, 21, 65, 47, 13, 54, 38, 0, 44, 28, + 0, 32, 16, 0, 18, 1, 0, 1, 0, 0, 0, 0, 30, 67, 155, + 20, 58, 139, 20, 49, 126, 12, 39, 110, 0, 27, 94, 0, 13, 77, + 0, 0, 60, 0, 0, 37, 0, 0, 0, 35, 67, 142, 30, 58, 126, + 23, 50, 114, 16, 40, 99, 7, 29, 85, 0, 15, 69, 0, 0, 52, + 0, 0, 30, 0, 0, 0, 35, 68, 131, 30, 59, 116, 27, 50, 104, + 18, 40, 90, 9, 29, 76, 0, 17, 62, 0, 2, 46, 0, 0, 24, + 0, 0, 0, 37, 69, 119, 33, 59, 106, 27, 51, 94, 21, 41, 80, + 9, 30, 67, 0, 18, 54, 0, 3, 39, 0, 0, 18, 0, 0, 0, + 40, 69, 107, 36, 59, 94, 28, 51, 84, 18, 41, 72, 10, 31, 60, + 0, 19, 47, 0, 4, 32, 0, 0, 10, 0, 0, 0, 42, 69, 95, + 36, 59, 84, 29, 51, 74, 19, 41, 63, 10, 31, 52, 0, 20, 39, + 0, 4, 25, 0, 0, 4, 0, 0, 0, 43, 69, 83, 38, 60, 73, + 32, 51, 62, 23, 42, 53, 11, 31, 42, 0, 20, 31, 0, 5, 17, + 0, 0, 1, 0, 0, 0, 45, 69, 70, 39, 60, 60, 33, 51, 52, + 24, 42, 43, 13, 32, 33, 0, 21, 21, 0, 5, 6, 0, 0, 0, + 0, 0, 0, 47, 69, 59, 41, 60, 51, 34, 51, 43, 24, 42, 35, + 12, 33, 26, 1, 22, 14, 0, 5, 1, 0, 0, 0, 0, 0, 0, + 46, 48, 146, 42, 40, 131, 36, 32, 118, 27, 22, 103, 17, 6, 88, + 5, 0, 73, 0, 0, 55, 0, 0, 33, 0, 0, 0, 48, 48, 133, + 44, 40, 119, 37, 32, 107, 28, 22, 93, 20, 8, 79, 7, 0, 65, + 0, 0, 49, 0, 0, 27, 0, 0, 0, 48, 50, 123, 44, 41, 109, + 37, 33, 97, 30, 23, 83, 21, 11, 71, 8, 0, 58, 0, 0, 42, + 0, 0, 21, 0, 0, 0, 49, 51, 111, 45, 42, 99, 38, 34, 87, + 29, 25, 75, 20, 13, 63, 8, 0, 51, 0, 0, 36, 0, 0, 14, + 0, 0, 0, 52, 52, 100, 44, 43, 89, 38, 35, 79, 29, 26, 68, + 19, 15, 56, 10, 1, 43, 0, 0, 28, 0, 0, 6, 0, 0, 0, + 52, 52, 90, 47, 44, 79, 39, 36, 70, 30, 27, 59, 20, 16, 47, + 9, 2, 36, 0, 0, 22, 0, 0, 2, 0, 0, 0, 52, 53, 78, + 46, 44, 68, 39, 37, 60, 32, 27, 49, 22, 17, 39, 10, 3, 28, + 0, 0, 12, 0, 0, 0, 0, 0, 0, 53, 53, 66, 47, 44, 57, + 40, 36, 48, 32, 27, 39, 22, 18, 30, 9, 4, 18, 0, 0, 3, + 0, 0, 0, 0, 0, 0, 54, 53, 57, 48, 45, 49, 41, 37, 41, + 33, 28, 32, 22, 19, 23, 11, 6, 10, 1, 0, 0, 0, 0, 0, + 0, 0, 0, +}; + +} // namespace + CCodec_ModuleMgr::CCodec_ModuleMgr() : m_pBasicModule(pdfium::MakeUnique<CCodec_BasicModule>()), m_pFaxModule(pdfium::MakeUnique<CCodec_FaxModule>()), @@ -460,3 +1781,90 @@ CCodec_BasicModule::CreateRunLengthDecoder(const uint8_t* src_buf, return std::move(pDecoder); } + +std::tuple<uint8_t, uint8_t, uint8_t> AdobeCMYK_to_sRGB1(uint8_t c, + uint8_t m, + uint8_t y, + uint8_t k) { + int fix_c = c << 8; + int fix_m = m << 8; + int fix_y = y << 8; + int fix_k = k << 8; + int c_index = (fix_c + 4096) >> 13; + int m_index = (fix_m + 4096) >> 13; + int y_index = (fix_y + 4096) >> 13; + int k_index = (fix_k + 4096) >> 13; + int pos = (c_index * 9 * 9 * 9 + m_index * 9 * 9 + y_index * 9 + k_index) * 3; + int fix_r = g_CMYK[pos] << 8; + int fix_g = g_CMYK[pos + 1] << 8; + int fix_b = g_CMYK[pos + 2] << 8; + int c1_index = fix_c >> 13; + if (c1_index == c_index) + c1_index = c1_index == 8 ? c1_index - 1 : c1_index + 1; + int m1_index = fix_m >> 13; + if (m1_index == m_index) + m1_index = m1_index == 8 ? m1_index - 1 : m1_index + 1; + int y1_index = fix_y >> 13; + if (y1_index == y_index) + y1_index = y1_index == 8 ? y1_index - 1 : y1_index + 1; + int k1_index = fix_k >> 13; + if (k1_index == k_index) + k1_index = k1_index == 8 ? k1_index - 1 : k1_index + 1; + int c1_pos = pos + (c1_index - c_index) * 9 * 9 * 9 * 3; + int m1_pos = pos + (m1_index - m_index) * 9 * 9 * 3; + int y1_pos = pos + (y1_index - y_index) * 9 * 3; + int k1_pos = pos + (k1_index - k_index) * 3; + int c_rate = (fix_c - (c_index << 13)) * (c_index - c1_index); + fix_r += (g_CMYK[pos] - g_CMYK[c1_pos]) * c_rate / 32; + fix_g += (g_CMYK[pos + 1] - g_CMYK[c1_pos + 1]) * c_rate / 32; + fix_b += (g_CMYK[pos + 2] - g_CMYK[c1_pos + 2]) * c_rate / 32; + int m_rate = (fix_m - (m_index << 13)) * (m_index - m1_index); + fix_r += (g_CMYK[pos] - g_CMYK[m1_pos]) * m_rate / 32; + fix_g += (g_CMYK[pos + 1] - g_CMYK[m1_pos + 1]) * m_rate / 32; + fix_b += (g_CMYK[pos + 2] - g_CMYK[m1_pos + 2]) * m_rate / 32; + int y_rate = (fix_y - (y_index << 13)) * (y_index - y1_index); + fix_r += (g_CMYK[pos] - g_CMYK[y1_pos]) * y_rate / 32; + fix_g += (g_CMYK[pos + 1] - g_CMYK[y1_pos + 1]) * y_rate / 32; + fix_b += (g_CMYK[pos + 2] - g_CMYK[y1_pos + 2]) * y_rate / 32; + int k_rate = (fix_k - (k_index << 13)) * (k_index - k1_index); + fix_r += (g_CMYK[pos] - g_CMYK[k1_pos]) * k_rate / 32; + fix_g += (g_CMYK[pos + 1] - g_CMYK[k1_pos + 1]) * k_rate / 32; + fix_b += (g_CMYK[pos + 2] - g_CMYK[k1_pos + 2]) * k_rate / 32; + fix_r = std::max(fix_r, 0); + fix_g = std::max(fix_g, 0); + fix_b = std::max(fix_b, 0); + return std::make_tuple(fix_r >> 8, fix_g >> 8, fix_b >> 8); +} + +std::tuple<float, float, float> AdobeCMYK_to_sRGB(float c, + float m, + float y, + float k) { + // Convert to uint8_t with round-to-nearest. Avoid using FXSYS_round because + // it is incredibly expensive with VC++ (tested on VC++ 2015) because round() + // is very expensive. + // The 'magic' value of 0.49999997f, the float that precedes 0.5f, was chosen + // because it gives identical results to FXSYS_round(). Using the constant + // 0.5f gives different results (1 instead of 0) for one value, 0.0019607842. + // That value is close to the cusp but zero is the correct answer, and + // getting the same answer as before is desirable. + // All floats from 0.0 to 1.0 were tested and now give the same results. + const float rounding_offset = 0.49999997f; + uint8_t c1 = int(c * 255.f + rounding_offset); + uint8_t m1 = int(m * 255.f + rounding_offset); + uint8_t y1 = int(y * 255.f + rounding_offset); + uint8_t k1 = int(k * 255.f + rounding_offset); + + ASSERT(c1 == FXSYS_round(c * 255)); + ASSERT(m1 == FXSYS_round(m * 255)); + ASSERT(y1 == FXSYS_round(y * 255)); + ASSERT(k1 == FXSYS_round(k * 255)); + + uint8_t r; + uint8_t g; + uint8_t b; + std::tie(r, g, b) = AdobeCMYK_to_sRGB1(c1, m1, y1, k1); + // Multiply by a constant rather than dividing because division is much + // more expensive. + return std::make_tuple(r * (1.0f / 255), g * (1.0f / 255), b * (1.0f / 255)); +} diff --git a/chromium/third_party/pdfium/core/fxcodec/codec/fx_codec_a85_unittest.cpp b/chromium/third_party/pdfium/core/fxcodec/codec/fx_codec_a85_unittest.cpp index 78f9bd8fcca..5e40548bf22 100644 --- a/chromium/third_party/pdfium/core/fxcodec/codec/fx_codec_a85_unittest.cpp +++ b/chromium/third_party/pdfium/core/fxcodec/codec/fx_codec_a85_unittest.cpp @@ -8,7 +8,6 @@ #include "core/fxcodec/codec/ccodec_basicmodule.h" #include "core/fxcodec/fx_codec.h" -#include "testing/fx_string_testhelpers.h" #include "testing/gtest/include/gtest/gtest.h" TEST(fxcodec, A85TestBadInputs) { diff --git a/chromium/third_party/pdfium/core/fxcodec/codec/fx_codec_flate.cpp b/chromium/third_party/pdfium/core/fxcodec/codec/fx_codec_flate.cpp index 5af3e99c2e2..02be295ce61 100644 --- a/chromium/third_party/pdfium/core/fxcodec/codec/fx_codec_flate.cpp +++ b/chromium/third_party/pdfium/core/fxcodec/codec/fx_codec_flate.cpp @@ -766,48 +766,44 @@ uint32_t CCodec_FlateModule::FlateOrLZWDecode(bool bLZW, int BitsPerComponent, int Columns, uint32_t estimated_size, - uint8_t*& dest_buf, - uint32_t& dest_size) { - dest_buf = nullptr; + uint8_t** dest_buf, + uint32_t* dest_size) { + *dest_buf = nullptr; uint32_t offset = 0; int predictor_type = 0; if (predictor) { - if (predictor >= 10) { + if (predictor >= 10) predictor_type = 2; - } else if (predictor == 2) { + else if (predictor == 2) predictor_type = 1; - } } if (bLZW) { - { - auto decoder = pdfium::MakeUnique<CLZWDecoder>(); - dest_size = 0xFFFFFFFF; - offset = src_size; - int err = - decoder->Decode(nullptr, dest_size, src_buf, offset, bEarlyChange); - if (err || dest_size == 0 || dest_size + 1 < dest_size) { - return FX_INVALID_OFFSET; - } - } - { - auto decoder = pdfium::MakeUnique<CLZWDecoder>(); - dest_buf = FX_Alloc(uint8_t, dest_size + 1); - dest_buf[dest_size] = '\0'; - decoder->Decode(dest_buf, dest_size, src_buf, offset, bEarlyChange); - } + auto decoder = pdfium::MakeUnique<CLZWDecoder>(); + *dest_size = 0xFFFFFFFF; + offset = src_size; + int err = + decoder->Decode(nullptr, *dest_size, src_buf, offset, bEarlyChange); + if (err || *dest_size == 0 || *dest_size + 1 < *dest_size) + return FX_INVALID_OFFSET; + + decoder = pdfium::MakeUnique<CLZWDecoder>(); + *dest_buf = FX_Alloc(uint8_t, *dest_size + 1); + (*dest_buf)[*dest_size] = '\0'; + decoder->Decode(*dest_buf, *dest_size, src_buf, offset, bEarlyChange); } else { - FlateUncompress(src_buf, src_size, estimated_size, dest_buf, dest_size, + FlateUncompress(src_buf, src_size, estimated_size, *dest_buf, *dest_size, offset); } - if (predictor_type == 0) { + if (predictor_type == 0) return offset; - } + bool ret = true; if (predictor_type == 2) { - ret = PNG_Predictor(dest_buf, dest_size, Colors, BitsPerComponent, Columns); - } else if (predictor_type == 1) { ret = - TIFF_Predictor(dest_buf, dest_size, Colors, BitsPerComponent, Columns); + PNG_Predictor(*dest_buf, *dest_size, Colors, BitsPerComponent, Columns); + } else if (predictor_type == 1) { + ret = TIFF_Predictor(*dest_buf, *dest_size, Colors, BitsPerComponent, + Columns); } return ret ? offset : FX_INVALID_OFFSET; } diff --git a/chromium/third_party/pdfium/core/fxcodec/codec/fx_codec_icc.cpp b/chromium/third_party/pdfium/core/fxcodec/codec/fx_codec_icc.cpp index ee562f0e92b..00ddf651158 100644 --- a/chromium/third_party/pdfium/core/fxcodec/codec/fx_codec_icc.cpp +++ b/chromium/third_party/pdfium/core/fxcodec/codec/fx_codec_icc.cpp @@ -4,6 +4,8 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com +#include <memory> + #include "core/fxcodec/codec/codec_int.h" #include "core/fxcodec/fx_codec.h" @@ -13,70 +15,51 @@ #include "third_party/lcms2-2.6/include/lcms2.h" #endif -struct CLcmsCmm { - cmsHTRANSFORM m_hTransform; - int m_nSrcComponents; - int m_nDstComponents; - bool m_bLab; -}; -bool CheckComponents(cmsColorSpaceSignature cs, int nComponents, bool bDst) { - if (nComponents <= 0 || nComponents > 15) { - return false; - } +namespace { + +bool Check3Components(cmsColorSpaceSignature cs, bool bDst) { switch (cs) { - case cmsSigLabData: - if (nComponents < 3) { - return false; - } - break; case cmsSigGrayData: - if (bDst && nComponents != 1) { - return false; - } - if (!bDst && nComponents > 2) { - return false; - } - break; - case cmsSigRgbData: - if (bDst && nComponents != 3) { - return false; - } - break; + return false; case cmsSigCmykData: - if (bDst && nComponents != 4) { + if (bDst) return false; - } break; + case cmsSigLabData: + case cmsSigRgbData: default: - if (nComponents != 3) { - return false; - } break; } return true; } -void* IccLib_CreateTransform(const unsigned char* pSrcProfileData, - uint32_t dwSrcProfileSize, - uint32_t& nSrcComponents, - const unsigned char* pDstProfileData, - uint32_t dwDstProfileSize, - int32_t nDstComponents, - int intent, - uint32_t dwSrcFormat = Icc_FORMAT_DEFAULT, - uint32_t dwDstFormat = Icc_FORMAT_DEFAULT) { - nSrcComponents = 0; +} // namespace + +CLcmsCmm::CLcmsCmm(int srcComponents, cmsHTRANSFORM hTransform, bool isLab) + : m_hTransform(hTransform), + m_nSrcComponents(srcComponents), + m_bLab(isLab) {} + +CLcmsCmm::~CLcmsCmm() { + cmsDeleteTransform(m_hTransform); +} + +CCodec_IccModule::CCodec_IccModule() : m_nComponents(0) {} + +CCodec_IccModule::~CCodec_IccModule() {} + +std::unique_ptr<CLcmsCmm> CCodec_IccModule::CreateTransform_sRGB( + const unsigned char* pSrcProfileData, + uint32_t dwSrcProfileSize, + uint32_t* nSrcComponents) { + *nSrcComponents = 0; cmsHPROFILE srcProfile = cmsOpenProfileFromMem(pSrcProfileData, dwSrcProfileSize); if (!srcProfile) return nullptr; cmsHPROFILE dstProfile; - if (!pDstProfileData && dwDstProfileSize == 0 && nDstComponents == 3) { - dstProfile = cmsCreate_sRGBProfile(); - } else { - dstProfile = cmsOpenProfileFromMem(pDstProfileData, dwDstProfileSize); - } + dstProfile = cmsCreate_sRGBProfile(); if (!dstProfile) { cmsCloseProfile(srcProfile); return nullptr; @@ -85,9 +68,9 @@ void* IccLib_CreateTransform(const unsigned char* pSrcProfileData, bool bLab = false; cmsColorSpaceSignature srcCS = cmsGetColorSpace(srcProfile); - nSrcComponents = cmsChannelsOf(srcCS); + *nSrcComponents = cmsChannelsOf(srcCS); // According to PDF spec, number of components must be 1, 3, or 4. - if (nSrcComponents != 1 && nSrcComponents != 3 && nSrcComponents != 4) { + if (*nSrcComponents != 1 && *nSrcComponents != 3 && *nSrcComponents != 4) { cmsCloseProfile(srcProfile); cmsCloseProfile(dstProfile); return nullptr; @@ -95,23 +78,24 @@ void* IccLib_CreateTransform(const unsigned char* pSrcProfileData, if (srcCS == cmsSigLabData) { srcFormat = - COLORSPACE_SH(PT_Lab) | CHANNELS_SH(nSrcComponents) | BYTES_SH(0); + COLORSPACE_SH(PT_Lab) | CHANNELS_SH(*nSrcComponents) | BYTES_SH(0); bLab = true; } else { srcFormat = - COLORSPACE_SH(PT_ANY) | CHANNELS_SH(nSrcComponents) | BYTES_SH(1); - if (srcCS == cmsSigRgbData && T_DOSWAP(dwSrcFormat)) { + COLORSPACE_SH(PT_ANY) | CHANNELS_SH(*nSrcComponents) | BYTES_SH(1); + if (srcCS == cmsSigRgbData && T_DOSWAP(Icc_FORMAT_DEFAULT)) { srcFormat |= DOSWAP_SH(1); } } cmsColorSpaceSignature dstCS = cmsGetColorSpace(dstProfile); - if (!CheckComponents(dstCS, nDstComponents, true)) { + if (!Check3Components(dstCS, true)) { cmsCloseProfile(srcProfile); cmsCloseProfile(dstProfile); return nullptr; } cmsHTRANSFORM hTransform = nullptr; + int intent = 0; switch (dstCS) { case cmsSigGrayData: hTransform = cmsCreateTransform(srcProfile, srcFormat, dstProfile, @@ -124,7 +108,7 @@ void* IccLib_CreateTransform(const unsigned char* pSrcProfileData, case cmsSigCmykData: hTransform = cmsCreateTransform( srcProfile, srcFormat, dstProfile, - T_DOSWAP(dwDstFormat) ? TYPE_KYMC_8 : TYPE_CMYK_8, intent, 0); + T_DOSWAP(Icc_FORMAT_DEFAULT) ? TYPE_KYMC_8 : TYPE_CMYK_8, intent, 0); break; default: break; @@ -134,1544 +118,44 @@ void* IccLib_CreateTransform(const unsigned char* pSrcProfileData, cmsCloseProfile(dstProfile); return nullptr; } - CLcmsCmm* pCmm = new CLcmsCmm; - pCmm->m_nSrcComponents = nSrcComponents; - pCmm->m_nDstComponents = nDstComponents; - pCmm->m_hTransform = hTransform; - pCmm->m_bLab = bLab; + auto pCmm = pdfium::MakeUnique<CLcmsCmm>(*nSrcComponents, hTransform, bLab); cmsCloseProfile(srcProfile); cmsCloseProfile(dstProfile); return pCmm; } -void* IccLib_CreateTransform_sRGB(const unsigned char* pProfileData, - uint32_t dwProfileSize, - uint32_t& nComponents, - int32_t intent, - uint32_t dwSrcFormat) { - return IccLib_CreateTransform(pProfileData, dwProfileSize, nComponents, - nullptr, 0, 3, intent, dwSrcFormat); -} -void IccLib_DestroyTransform(void* pTransform) { - if (!pTransform) { - return; - } - cmsDeleteTransform(((CLcmsCmm*)pTransform)->m_hTransform); - delete (CLcmsCmm*)pTransform; -} -void IccLib_Translate(void* pTransform, - uint32_t nSrcComponents, - const float* pSrcValues, - float* pDestValues) { +void CCodec_IccModule::Translate(CLcmsCmm* pTransform, + const float* pSrcValues, + float* pDestValues) { if (!pTransform) return; - CLcmsCmm* p = (CLcmsCmm*)pTransform; + uint32_t nSrcComponents = m_nComponents; uint8_t output[4]; - if (p->m_bLab) { + if (pTransform->m_bLab) { CFX_FixedBufGrow<double, 16> inputs(nSrcComponents); double* input = inputs; - for (uint32_t i = 0; i < nSrcComponents; i++) + for (uint32_t i = 0; i < nSrcComponents; ++i) input[i] = pSrcValues[i]; - cmsDoTransform(p->m_hTransform, input, output, 1); + cmsDoTransform(pTransform->m_hTransform, input, output, 1); } else { CFX_FixedBufGrow<uint8_t, 16> inputs(nSrcComponents); uint8_t* input = inputs; - for (uint32_t i = 0; i < nSrcComponents; i++) { - if (pSrcValues[i] > 1.0f) - input[i] = 255; - else if (pSrcValues[i] < 0) - input[i] = 0; - else - input[i] = static_cast<int>(pSrcValues[i] * 255.0f); + for (uint32_t i = 0; i < nSrcComponents; ++i) { + input[i] = + pdfium::clamp(static_cast<int>(pSrcValues[i] * 255.0f), 0, 255); } - cmsDoTransform(p->m_hTransform, input, output, 1); - } - switch (p->m_nDstComponents) { - case 1: - pDestValues[0] = output[0] / 255.0f; - break; - case 3: - pDestValues[0] = output[2] / 255.0f; - pDestValues[1] = output[1] / 255.0f; - pDestValues[2] = output[0] / 255.0f; - break; - case 4: - pDestValues[0] = output[0] / 255.0f; - pDestValues[1] = output[1] / 255.0f; - pDestValues[2] = output[2] / 255.0f; - pDestValues[3] = output[3] / 255.0f; - break; + cmsDoTransform(pTransform->m_hTransform, input, output, 1); } + pDestValues[0] = output[2] / 255.0f; + pDestValues[1] = output[1] / 255.0f; + pDestValues[2] = output[0] / 255.0f; } -void IccLib_TranslateImage(void* pTransform, - unsigned char* pDest, - const unsigned char* pSrc, - int32_t pixels) { - if (!pTransform) - return; - cmsDoTransform(((CLcmsCmm*)pTransform)->m_hTransform, pSrc, pDest, pixels); -} - -CCodec_IccModule::CCodec_IccModule() : m_nComponents(0) {} - -CCodec_IccModule::~CCodec_IccModule() { -} -void* CCodec_IccModule::CreateTransform_sRGB(const uint8_t* pProfileData, - uint32_t dwProfileSize, - uint32_t& nComponents, - int32_t intent, - uint32_t dwSrcFormat) { - return IccLib_CreateTransform_sRGB(pProfileData, dwProfileSize, nComponents, - intent, dwSrcFormat); -} - -void CCodec_IccModule::DestroyTransform(void* pTransform) { - IccLib_DestroyTransform(pTransform); -} - -void CCodec_IccModule::Translate(void* pTransform, - const float* pSrcValues, - float* pDestValues) { - IccLib_Translate(pTransform, m_nComponents, pSrcValues, pDestValues); -} - -void CCodec_IccModule::TranslateScanline(void* pTransform, - uint8_t* pDest, - const uint8_t* pSrc, +void CCodec_IccModule::TranslateScanline(CLcmsCmm* pTransform, + unsigned char* pDest, + const unsigned char* pSrc, int32_t pixels) { - IccLib_TranslateImage(pTransform, pDest, pSrc, pixels); -} - -const uint8_t g_CMYKSamples[81 * 81 * 3] = { - 255, 255, 255, 225, 226, 228, 199, 200, 202, 173, 174, 178, 147, 149, 152, - 123, 125, 128, 99, 99, 102, 69, 70, 71, 34, 30, 31, 255, 253, 229, - 226, 224, 203, 200, 199, 182, 173, 173, 158, 149, 148, 135, 125, 124, 113, - 99, 99, 90, 70, 69, 63, 33, 29, 24, 255, 251, 204, 228, 223, 182, - 201, 198, 163, 174, 172, 142, 150, 147, 122, 125, 123, 101, 99, 98, 80, - 70, 68, 54, 32, 28, 16, 255, 249, 179, 230, 222, 160, 203, 197, 144, - 174, 170, 124, 150, 145, 105, 125, 122, 88, 99, 97, 69, 70, 68, 46, - 31, 28, 6, 255, 247, 154, 229, 220, 138, 203, 195, 122, 176, 169, 107, - 150, 145, 91, 125, 121, 74, 100, 96, 57, 70, 67, 35, 29, 26, 0, - 255, 246, 128, 231, 217, 114, 205, 194, 101, 176, 167, 88, 150, 144, 75, - 125, 120, 60, 100, 96, 44, 70, 66, 24, 28, 26, 0, 255, 244, 96, - 231, 217, 87, 203, 192, 78, 175, 167, 66, 150, 143, 56, 125, 119, 43, - 100, 95, 29, 69, 66, 7, 26, 26, 0, 255, 243, 51, 232, 215, 51, - 204, 191, 43, 176, 165, 38, 150, 142, 28, 125, 118, 17, 99, 94, 0, - 68, 65, 0, 24, 25, 0, 255, 241, 0, 231, 215, 0, 203, 190, 0, - 176, 164, 0, 150, 141, 0, 126, 117, 0, 99, 93, 0, 68, 65, 0, - 24, 25, 0, 252, 228, 238, 222, 201, 211, 197, 180, 190, 171, 156, 166, - 147, 133, 143, 123, 111, 119, 99, 88, 94, 71, 61, 66, 34, 22, 26, - 254, 226, 213, 224, 201, 191, 199, 179, 171, 172, 155, 148, 147, 133, 128, - 123, 110, 106, 98, 87, 83, 70, 59, 57, 33, 21, 18, 254, 224, 191, - 224, 199, 172, 200, 177, 153, 173, 154, 133, 147, 132, 115, 123, 109, 94, - 98, 86, 74, 70, 59, 49, 32, 21, 9, 255, 222, 168, 227, 198, 150, - 200, 175, 135, 173, 153, 118, 148, 130, 99, 123, 109, 82, 98, 86, 64, - 69, 58, 40, 31, 19, 0, 255, 221, 145, 227, 196, 129, 201, 174, 115, - 173, 151, 99, 148, 129, 85, 124, 108, 69, 98, 85, 52, 69, 58, 30, - 30, 19, 0, 255, 219, 121, 227, 195, 109, 201, 174, 97, 174, 150, 83, - 148, 129, 70, 124, 107, 55, 98, 84, 40, 69, 58, 19, 28, 18, 0, - 255, 218, 92, 229, 194, 82, 202, 173, 75, 174, 150, 63, 149, 128, 51, - 124, 106, 39, 98, 84, 24, 68, 57, 3, 26, 18, 0, 255, 217, 54, - 228, 193, 52, 201, 172, 46, 174, 148, 36, 148, 127, 27, 123, 105, 14, - 98, 83, 0, 68, 56, 0, 25, 18, 0, 255, 216, 0, 229, 192, 2, - 202, 171, 4, 173, 148, 0, 148, 126, 0, 124, 105, 0, 98, 83, 0, - 68, 56, 0, 24, 17, 0, 249, 204, 223, 219, 181, 199, 195, 160, 178, - 170, 140, 156, 146, 119, 134, 123, 99, 112, 98, 77, 88, 70, 52, 61, - 34, 11, 20, 250, 201, 200, 221, 180, 178, 197, 159, 161, 171, 139, 139, - 147, 119, 120, 123, 98, 99, 98, 77, 78, 69, 51, 52, 34, 11, 10, - 252, 201, 180, 223, 179, 162, 197, 159, 144, 170, 138, 125, 146, 117, 107, - 122, 97, 89, 98, 76, 69, 69, 50, 44, 32, 11, 2, 252, 199, 158, - 222, 177, 143, 199, 158, 127, 171, 137, 110, 147, 117, 93, 122, 96, 76, - 97, 75, 58, 69, 50, 36, 32, 10, 0, 253, 198, 137, 223, 177, 123, - 198, 156, 110, 171, 136, 95, 146, 116, 80, 122, 96, 65, 97, 75, 47, - 69, 50, 25, 30, 10, 0, 254, 197, 115, 225, 175, 104, 198, 156, 92, - 172, 135, 79, 147, 115, 66, 123, 95, 52, 98, 74, 37, 69, 49, 15, - 29, 10, 0, 254, 196, 89, 224, 175, 80, 199, 154, 70, 172, 134, 59, - 146, 114, 48, 122, 95, 36, 97, 74, 21, 68, 49, 0, 27, 9, 0, - 255, 195, 57, 225, 173, 52, 198, 154, 44, 172, 133, 36, 147, 113, 26, - 123, 94, 14, 98, 74, 0, 68, 49, 0, 26, 10, 0, 254, 194, 15, - 225, 172, 12, 198, 153, 7, 172, 132, 3, 146, 113, 0, 123, 93, 0, - 98, 73, 0, 68, 49, 0, 26, 9, 0, 246, 178, 209, 218, 159, 186, - 194, 140, 166, 168, 122, 145, 144, 104, 125, 121, 85, 103, 97, 65, 81, - 69, 41, 55, 34, 0, 12, 248, 176, 186, 219, 157, 166, 195, 139, 149, - 168, 121, 130, 144, 103, 111, 121, 85, 91, 97, 65, 71, 69, 41, 46, - 34, 0, 4, 249, 175, 168, 220, 156, 150, 196, 139, 135, 169, 121, 116, - 144, 103, 100, 122, 84, 83, 98, 65, 63, 70, 41, 39, 33, 0, 0, - 249, 175, 148, 220, 155, 133, 196, 138, 119, 169, 120, 103, 145, 101, 87, - 121, 83, 71, 97, 65, 54, 69, 41, 31, 32, 0, 0, 249, 173, 128, - 222, 154, 115, 195, 137, 102, 170, 119, 88, 145, 101, 74, 122, 83, 59, - 97, 64, 43, 68, 40, 20, 30, 0, 0, 250, 172, 108, 221, 154, 98, - 195, 136, 86, 170, 118, 73, 145, 100, 61, 122, 82, 48, 97, 63, 32, - 69, 40, 11, 28, 0, 0, 250, 171, 85, 221, 153, 76, 196, 136, 67, - 170, 117, 56, 145, 99, 44, 121, 82, 33, 97, 63, 17, 68, 40, 0, - 28, 0, 0, 251, 171, 58, 222, 152, 50, 197, 135, 43, 169, 117, 34, - 146, 99, 25, 121, 81, 10, 96, 63, 0, 68, 40, 0, 27, 0, 0, - 250, 170, 26, 222, 151, 19, 196, 134, 13, 169, 116, 4, 145, 99, 0, - 122, 81, 0, 97, 63, 0, 67, 40, 0, 26, 0, 0, 244, 153, 194, - 215, 136, 173, 192, 121, 155, 167, 104, 135, 143, 89, 115, 121, 72, 96, - 97, 54, 75, 70, 31, 49, 34, 0, 6, 245, 153, 173, 216, 136, 155, - 192, 120, 138, 167, 104, 121, 144, 88, 103, 121, 71, 85, 97, 54, 66, - 69, 31, 42, 34, 0, 0, 246, 152, 157, 217, 135, 140, 193, 120, 126, - 167, 103, 109, 143, 88, 92, 121, 72, 76, 97, 54, 58, 69, 31, 35, - 33, 0, 0, 245, 150, 139, 218, 134, 125, 193, 119, 111, 167, 103, 96, - 144, 87, 80, 121, 71, 66, 96, 53, 49, 68, 31, 26, 32, 0, 0, - 246, 151, 122, 218, 133, 108, 194, 118, 96, 168, 102, 81, 144, 86, 69, - 120, 71, 55, 95, 53, 39, 68, 30, 17, 31, 0, 0, 248, 150, 103, - 218, 133, 91, 193, 118, 81, 168, 102, 69, 143, 86, 56, 120, 70, 43, - 96, 53, 28, 68, 31, 6, 29, 0, 0, 247, 149, 81, 218, 132, 72, - 194, 117, 62, 168, 101, 52, 144, 86, 42, 121, 70, 29, 96, 52, 13, - 68, 30, 0, 28, 0, 0, 247, 148, 55, 219, 131, 50, 194, 117, 43, - 167, 101, 32, 144, 85, 22, 120, 69, 8, 96, 52, 0, 67, 30, 0, - 27, 0, 0, 247, 147, 29, 218, 131, 24, 194, 116, 20, 168, 100, 11, - 144, 85, 0, 120, 69, 0, 96, 52, 0, 67, 30, 0, 26, 0, 0, - 242, 130, 179, 214, 114, 160, 190, 101, 143, 166, 87, 125, 143, 72, 107, - 120, 58, 88, 96, 42, 68, 69, 17, 44, 35, 0, 0, 243, 129, 161, - 215, 114, 143, 191, 101, 128, 166, 87, 113, 143, 73, 96, 120, 58, 79, - 96, 41, 60, 69, 18, 37, 33, 0, 0, 243, 129, 146, 216, 114, 130, - 192, 101, 117, 166, 87, 101, 143, 72, 86, 121, 58, 69, 96, 42, 52, - 69, 18, 29, 31, 0, 0, 243, 128, 130, 216, 114, 115, 191, 101, 102, - 165, 86, 88, 142, 72, 75, 120, 58, 60, 95, 42, 43, 68, 19, 21, - 30, 0, 0, 244, 127, 112, 217, 113, 101, 192, 99, 89, 166, 85, 75, - 142, 72, 63, 119, 57, 50, 96, 41, 35, 68, 19, 13, 30, 0, 0, - 244, 127, 96, 216, 112, 86, 191, 99, 75, 166, 86, 64, 143, 72, 52, - 120, 57, 40, 95, 41, 24, 67, 20, 1, 29, 0, 0, 245, 126, 77, - 216, 113, 68, 191, 100, 59, 166, 85, 49, 142, 71, 38, 119, 57, 26, - 95, 41, 10, 67, 20, 0, 28, 0, 0, 244, 126, 55, 216, 112, 48, - 191, 99, 40, 166, 85, 31, 143, 71, 20, 119, 57, 6, 95, 42, 0, - 67, 20, 0, 28, 0, 0, 245, 126, 33, 217, 112, 26, 192, 99, 22, - 166, 84, 11, 142, 70, 0, 119, 57, 0, 95, 41, 0, 66, 20, 0, - 27, 0, 0, 241, 102, 167, 213, 90, 149, 189, 79, 133, 165, 66, 115, - 141, 54, 98, 119, 41, 81, 96, 25, 63, 69, 0, 38, 30, 0, 0, - 241, 102, 149, 213, 90, 133, 189, 79, 119, 165, 66, 103, 142, 55, 88, - 119, 41, 71, 96, 25, 53, 69, 0, 31, 28, 0, 0, 241, 102, 135, - 214, 90, 121, 190, 79, 108, 165, 66, 92, 141, 55, 78, 119, 42, 63, - 96, 26, 46, 69, 0, 24, 28, 0, 0, 241, 101, 120, 214, 90, 107, - 189, 79, 95, 165, 67, 83, 141, 54, 68, 118, 41, 54, 95, 27, 39, - 68, 0, 16, 27, 0, 0, 241, 102, 106, 213, 90, 93, 189, 78, 82, - 164, 67, 70, 141, 55, 58, 118, 42, 45, 94, 27, 29, 67, 2, 6, - 27, 0, 0, 242, 101, 90, 214, 89, 79, 190, 79, 69, 166, 67, 59, - 141, 55, 47, 118, 41, 35, 95, 27, 19, 67, 3, 0, 26, 0, 0, - 242, 102, 72, 213, 89, 63, 191, 79, 56, 164, 67, 45, 141, 55, 34, - 118, 42, 22, 94, 28, 6, 67, 3, 0, 26, 0, 0, 242, 100, 51, - 214, 89, 45, 190, 78, 38, 164, 67, 30, 141, 55, 18, 118, 42, 3, - 95, 28, 0, 66, 4, 0, 26, 0, 0, 243, 100, 33, 214, 90, 27, - 190, 78, 22, 165, 67, 13, 141, 55, 0, 118, 43, 0, 94, 29, 0, - 66, 5, 0, 26, 0, 0, 237, 69, 153, 211, 58, 135, 187, 51, 121, - 163, 41, 105, 141, 28, 90, 118, 15, 73, 96, 0, 56, 68, 0, 33, - 25, 0, 0, 239, 67, 137, 212, 60, 123, 189, 50, 110, 163, 41, 94, - 141, 29, 79, 118, 17, 65, 95, 0, 48, 69, 0, 26, 25, 0, 0, - 240, 69, 124, 211, 60, 111, 188, 50, 98, 163, 42, 85, 141, 31, 72, - 118, 18, 57, 94, 0, 41, 68, 0, 19, 25, 0, 0, 240, 70, 112, - 212, 61, 99, 188, 52, 87, 163, 41, 74, 140, 31, 62, 118, 20, 48, - 94, 2, 32, 68, 0, 11, 24, 0, 0, 239, 70, 98, 212, 62, 86, - 188, 53, 77, 164, 42, 64, 140, 32, 52, 118, 20, 40, 94, 3, 24, - 67, 0, 3, 23, 0, 0, 239, 71, 85, 212, 61, 74, 187, 53, 65, - 163, 44, 54, 140, 34, 43, 118, 22, 30, 95, 3, 14, 67, 0, 0, - 23, 0, 0, 239, 70, 67, 212, 62, 59, 188, 53, 51, 163, 45, 42, - 141, 34, 31, 117, 22, 17, 94, 5, 2, 66, 0, 0, 23, 0, 0, - 239, 71, 50, 213, 62, 43, 188, 54, 37, 164, 45, 28, 139, 34, 16, - 117, 22, 2, 94, 7, 0, 65, 0, 0, 23, 0, 0, 240, 71, 34, - 212, 63, 29, 189, 54, 24, 163, 46, 15, 139, 36, 2, 117, 25, 0, - 94, 8, 0, 66, 0, 0, 23, 0, 0, 237, 0, 140, 209, 0, 124, - 186, 0, 112, 162, 0, 97, 141, 0, 82, 118, 0, 67, 95, 0, 49, - 68, 0, 27, 20, 0, 0, 237, 0, 126, 210, 0, 113, 187, 0, 99, - 163, 0, 86, 139, 0, 72, 118, 0, 58, 95, 0, 42, 67, 0, 20, - 20, 0, 0, 237, 1, 114, 209, 1, 102, 187, 0, 90, 163, 0, 78, - 139, 0, 64, 118, 0, 50, 95, 0, 35, 67, 0, 13, 20, 0, 0, - 236, 16, 102, 209, 7, 91, 186, 0, 80, 162, 0, 68, 139, 0, 56, - 117, 0, 43, 94, 0, 27, 67, 0, 6, 20, 0, 0, 238, 15, 89, - 209, 13, 79, 186, 6, 69, 162, 0, 58, 139, 0, 47, 117, 0, 34, - 93, 0, 20, 66, 0, 2, 20, 0, 0, 237, 20, 78, 210, 12, 68, - 187, 4, 59, 163, 0, 49, 139, 0, 38, 116, 0, 26, 94, 0, 11, - 66, 0, 0, 20, 0, 0, 237, 25, 64, 210, 18, 56, 186, 11, 48, - 162, 4, 39, 138, 0, 27, 117, 0, 14, 93, 0, 0, 66, 0, 0, - 20, 0, 0, 238, 25, 48, 210, 22, 43, 186, 15, 35, 162, 8, 26, - 140, 0, 14, 117, 0, 0, 93, 0, 0, 65, 0, 0, 20, 0, 0, - 238, 28, 35, 210, 21, 30, 187, 15, 24, 162, 8, 16, 139, 1, 2, - 117, 0, 0, 93, 0, 0, 65, 0, 0, 22, 0, 0, 219, 242, 252, - 195, 214, 225, 172, 191, 201, 148, 165, 175, 127, 142, 150, 106, 119, 126, - 84, 95, 101, 58, 66, 72, 24, 27, 32, 222, 239, 226, 196, 213, 202, - 173, 189, 180, 150, 165, 158, 129, 141, 135, 107, 118, 113, 85, 94, 90, - 58, 66, 63, 21, 26, 24, 223, 237, 203, 198, 211, 182, 175, 188, 163, - 152, 164, 141, 129, 140, 121, 107, 117, 101, 85, 93, 80, 58, 64, 54, - 21, 26, 18, 226, 236, 179, 201, 210, 160, 177, 187, 143, 153, 162, 125, - 130, 139, 106, 108, 116, 89, 85, 92, 69, 58, 64, 45, 20, 25, 8, - 227, 234, 153, 201, 208, 139, 178, 185, 124, 154, 161, 107, 131, 138, 91, - 108, 115, 75, 85, 91, 58, 58, 63, 35, 17, 25, 0, 229, 233, 130, - 203, 207, 116, 178, 184, 104, 154, 160, 90, 131, 137, 76, 109, 114, 62, - 85, 90, 46, 58, 63, 25, 16, 24, 0, 230, 231, 100, 202, 205, 90, - 179, 183, 80, 154, 159, 69, 131, 136, 57, 109, 113, 46, 86, 90, 32, - 58, 63, 10, 14, 24, 0, 230, 230, 65, 204, 204, 58, 180, 182, 52, - 155, 157, 44, 132, 135, 35, 110, 113, 24, 86, 89, 9, 57, 62, 0, - 11, 24, 0, 232, 230, 19, 204, 204, 19, 180, 181, 17, 155, 157, 10, - 131, 134, 2, 109, 112, 0, 85, 89, 0, 57, 62, 0, 10, 23, 0, - 218, 216, 236, 194, 192, 211, 172, 171, 188, 149, 149, 164, 128, 127, 141, - 106, 106, 119, 84, 84, 94, 59, 57, 66, 25, 18, 26, 221, 214, 211, - 196, 191, 190, 174, 170, 170, 150, 148, 148, 128, 126, 127, 107, 105, 106, - 85, 83, 84, 59, 56, 58, 23, 17, 18, 222, 213, 190, 197, 189, 170, - 175, 169, 153, 151, 147, 133, 129, 126, 113, 108, 105, 94, 85, 82, 74, - 59, 56, 49, 22, 17, 11, 224, 211, 168, 199, 188, 151, 175, 168, 135, - 152, 146, 117, 129, 124, 99, 107, 103, 82, 84, 82, 64, 59, 55, 41, - 21, 17, 1, 224, 210, 145, 199, 187, 130, 176, 166, 117, 152, 145, 101, - 129, 123, 86, 107, 103, 70, 85, 81, 53, 58, 55, 31, 19, 17, 0, - 227, 208, 123, 200, 186, 110, 177, 165, 98, 153, 143, 84, 130, 122, 70, - 108, 102, 57, 85, 80, 41, 58, 54, 20, 18, 16, 0, 227, 208, 97, - 202, 185, 86, 177, 164, 77, 153, 142, 65, 130, 122, 54, 108, 101, 42, - 85, 80, 27, 58, 54, 7, 16, 16, 0, 228, 206, 66, 202, 184, 58, - 178, 163, 50, 154, 141, 42, 131, 121, 33, 109, 101, 21, 86, 79, 5, - 58, 54, 0, 13, 16, 0, 228, 206, 29, 202, 183, 25, 178, 163, 20, - 154, 141, 15, 131, 121, 5, 108, 100, 0, 85, 79, 0, 58, 53, 0, - 13, 16, 0, 217, 193, 221, 193, 172, 198, 172, 153, 178, 149, 133, 154, - 128, 114, 132, 107, 94, 111, 85, 74, 89, 59, 49, 61, 25, 8, 22, - 219, 191, 198, 195, 171, 178, 173, 153, 159, 149, 132, 139, 128, 113, 119, - 107, 94, 100, 85, 73, 79, 59, 48, 52, 25, 7, 14, 221, 191, 180, - 196, 170, 160, 174, 152, 144, 150, 132, 125, 129, 113, 107, 107, 93, 89, - 85, 73, 69, 59, 48, 45, 23, 7, 4, 222, 189, 159, 197, 169, 142, - 174, 151, 127, 151, 131, 110, 129, 112, 94, 108, 93, 78, 85, 72, 60, - 58, 47, 37, 22, 7, 0, 223, 188, 138, 197, 168, 123, 175, 150, 109, - 151, 130, 95, 130, 111, 81, 108, 92, 65, 85, 72, 49, 59, 47, 27, - 21, 7, 0, 224, 187, 118, 198, 167, 105, 176, 149, 93, 152, 129, 79, - 130, 110, 68, 108, 91, 54, 85, 71, 38, 59, 47, 17, 18, 7, 0, - 224, 187, 93, 199, 166, 83, 176, 148, 73, 152, 128, 62, 129, 109, 51, - 108, 90, 39, 85, 71, 25, 58, 46, 3, 16, 8, 0, 226, 186, 64, - 200, 165, 57, 177, 147, 50, 153, 127, 40, 130, 108, 31, 108, 90, 19, - 85, 70, 3, 58, 46, 0, 16, 8, 0, 227, 185, 35, 200, 165, 30, - 176, 146, 25, 152, 127, 18, 130, 108, 7, 108, 89, 0, 85, 70, 0, - 57, 46, 0, 14, 8, 0, 216, 169, 205, 192, 150, 184, 171, 134, 164, - 149, 116, 144, 128, 99, 124, 107, 81, 103, 85, 63, 81, 60, 39, 55, - 26, 0, 15, 217, 168, 186, 193, 150, 165, 172, 134, 149, 150, 116, 130, - 128, 99, 111, 107, 81, 92, 85, 62, 72, 59, 39, 47, 25, 0, 6, - 219, 168, 168, 194, 149, 150, 173, 133, 135, 150, 116, 117, 128, 98, 99, - 107, 80, 82, 86, 62, 63, 59, 38, 39, 24, 0, 0, 219, 166, 148, - 195, 149, 133, 173, 133, 119, 150, 115, 103, 128, 98, 88, 107, 80, 72, - 85, 61, 54, 59, 38, 32, 23, 0, 0, 220, 166, 129, 196, 148, 116, - 174, 132, 103, 151, 114, 89, 129, 97, 75, 107, 79, 60, 85, 61, 44, - 59, 38, 22, 21, 0, 0, 222, 164, 110, 197, 147, 99, 175, 131, 87, - 151, 113, 75, 129, 96, 63, 107, 79, 49, 85, 61, 33, 58, 38, 12, - 19, 0, 0, 222, 164, 88, 197, 146, 79, 174, 130, 69, 151, 113, 58, - 129, 95, 47, 107, 78, 35, 85, 60, 20, 58, 38, 0, 18, 0, 0, - 223, 164, 63, 198, 145, 55, 175, 129, 48, 151, 112, 39, 129, 95, 29, - 107, 78, 16, 85, 60, 1, 58, 38, 0, 17, 0, 0, 223, 163, 36, - 198, 145, 32, 174, 129, 26, 151, 111, 17, 129, 95, 7, 107, 78, 0, - 84, 60, 0, 57, 37, 0, 15, 0, 0, 215, 147, 192, 191, 130, 172, - 170, 116, 153, 148, 100, 133, 127, 85, 115, 107, 69, 96, 85, 51, 75, - 60, 28, 50, 25, 0, 8, 217, 146, 173, 192, 130, 154, 171, 115, 138, - 149, 100, 121, 128, 84, 103, 107, 68, 85, 85, 51, 66, 60, 28, 42, - 25, 0, 0, 217, 145, 157, 193, 129, 140, 173, 115, 125, 149, 100, 109, - 128, 84, 92, 107, 68, 76, 85, 51, 58, 59, 28, 35, 23, 0, 0, - 218, 145, 140, 193, 129, 125, 172, 114, 110, 149, 99, 96, 128, 83, 81, - 107, 67, 65, 84, 51, 49, 59, 29, 27, 22, 0, 0, 219, 144, 121, - 194, 128, 108, 172, 113, 96, 149, 98, 83, 128, 83, 69, 107, 68, 55, - 85, 50, 40, 59, 28, 18, 20, 0, 0, 220, 143, 104, 195, 128, 93, - 173, 114, 82, 150, 98, 69, 127, 82, 58, 107, 67, 45, 85, 50, 30, - 59, 28, 7, 19, 0, 0, 220, 143, 84, 195, 127, 74, 173, 113, 65, - 149, 97, 55, 128, 82, 44, 106, 67, 32, 84, 50, 16, 58, 28, 0, - 18, 0, 0, 221, 142, 62, 196, 126, 53, 173, 112, 46, 150, 97, 37, - 128, 82, 26, 107, 66, 14, 84, 50, 0, 58, 28, 0, 16, 0, 0, - 222, 142, 38, 196, 126, 34, 174, 112, 27, 150, 96, 17, 128, 82, 6, - 106, 66, 0, 84, 50, 0, 57, 29, 0, 16, 0, 0, 214, 123, 179, - 191, 110, 159, 169, 98, 143, 147, 84, 124, 126, 70, 106, 107, 55, 88, - 85, 39, 69, 60, 15, 45, 23, 0, 2, 216, 123, 161, 192, 110, 144, - 170, 98, 129, 148, 84, 112, 127, 70, 95, 107, 55, 79, 85, 39, 61, - 60, 15, 37, 20, 0, 0, 217, 122, 145, 192, 110, 130, 170, 97, 116, - 149, 84, 101, 127, 70, 85, 106, 55, 70, 85, 39, 53, 59, 16, 30, - 19, 0, 0, 217, 123, 131, 192, 109, 116, 171, 96, 103, 149, 83, 89, - 127, 70, 75, 106, 55, 60, 85, 40, 45, 59, 16, 23, 17, 0, 0, - 217, 122, 114, 193, 109, 101, 172, 96, 91, 149, 82, 77, 128, 69, 64, - 106, 55, 50, 84, 39, 35, 59, 17, 14, 17, 0, 0, 218, 122, 98, - 194, 108, 87, 171, 96, 77, 149, 82, 65, 127, 69, 52, 106, 55, 40, - 84, 40, 25, 59, 18, 3, 15, 0, 0, 219, 122, 80, 193, 108, 70, - 172, 95, 61, 149, 82, 51, 127, 69, 40, 106, 55, 28, 84, 39, 12, - 58, 17, 0, 13, 0, 0, 219, 121, 59, 194, 108, 52, 172, 96, 44, - 149, 82, 35, 127, 68, 24, 106, 55, 11, 84, 40, 0, 57, 18, 0, - 13, 0, 0, 219, 121, 40, 193, 108, 33, 172, 95, 26, 149, 81, 19, - 128, 68, 6, 106, 54, 0, 84, 39, 0, 57, 18, 0, 13, 0, 0, - 213, 99, 165, 189, 87, 148, 169, 76, 132, 147, 64, 115, 126, 52, 98, - 106, 39, 81, 85, 23, 63, 60, 0, 39, 16, 0, 0, 214, 98, 149, - 191, 87, 133, 170, 76, 119, 148, 65, 103, 127, 53, 88, 106, 39, 72, - 85, 24, 55, 60, 0, 32, 15, 0, 0, 215, 99, 136, 191, 87, 121, - 170, 77, 108, 148, 65, 93, 126, 53, 79, 106, 40, 64, 85, 24, 47, - 59, 0, 25, 14, 0, 0, 215, 99, 121, 192, 87, 108, 170, 77, 96, - 148, 65, 82, 126, 53, 69, 106, 40, 55, 85, 25, 39, 59, 0, 18, - 13, 0, 0, 216, 99, 106, 191, 87, 95, 170, 76, 83, 148, 65, 71, - 126, 53, 58, 106, 41, 45, 85, 26, 30, 59, 0, 8, 11, 0, 0, - 216, 98, 91, 192, 88, 82, 170, 77, 71, 148, 65, 60, 127, 53, 48, - 105, 41, 36, 83, 26, 21, 58, 1, 2, 11, 0, 0, 217, 99, 75, - 192, 87, 66, 170, 76, 57, 148, 65, 47, 126, 53, 36, 105, 41, 24, - 83, 26, 8, 57, 2, 0, 9, 0, 0, 217, 98, 57, 192, 87, 49, - 171, 77, 41, 147, 65, 32, 126, 53, 21, 105, 41, 8, 84, 27, 0, - 57, 3, 0, 9, 0, 0, 217, 98, 40, 193, 87, 34, 171, 76, 27, - 148, 65, 19, 126, 53, 6, 105, 41, 0, 83, 27, 0, 57, 4, 0, - 9, 0, 0, 211, 67, 152, 189, 58, 136, 168, 50, 122, 147, 39, 105, - 127, 28, 89, 106, 14, 74, 85, 0, 56, 59, 0, 33, 9, 0, 0, - 213, 68, 138, 190, 59, 123, 169, 51, 109, 148, 40, 95, 126, 30, 80, - 106, 16, 65, 85, 0, 48, 59, 0, 27, 9, 0, 0, 214, 69, 125, - 190, 59, 111, 168, 51, 99, 148, 41, 86, 126, 31, 72, 106, 18, 58, - 85, 0, 41, 59, 0, 20, 7, 0, 0, 215, 70, 112, 190, 61, 100, - 169, 52, 88, 147, 42, 76, 126, 32, 63, 106, 19, 49, 84, 1, 34, - 58, 0, 13, 7, 0, 0, 214, 70, 99, 190, 62, 88, 169, 53, 77, - 147, 43, 65, 125, 32, 53, 106, 20, 40, 84, 3, 26, 58, 0, 4, - 7, 0, 0, 214, 71, 86, 190, 61, 75, 169, 53, 65, 146, 43, 54, - 126, 33, 44, 105, 21, 31, 83, 4, 17, 57, 0, 0, 7, 0, 0, - 215, 71, 71, 191, 62, 62, 169, 53, 53, 147, 44, 44, 126, 34, 33, - 105, 22, 20, 83, 5, 4, 57, 0, 0, 7, 0, 0, 215, 71, 54, - 191, 62, 47, 169, 54, 39, 147, 44, 30, 126, 35, 20, 105, 23, 6, - 83, 6, 0, 56, 0, 0, 5, 0, 0, 215, 71, 41, 191, 63, 34, - 170, 54, 27, 147, 45, 17, 126, 35, 6, 105, 23, 0, 83, 8, 0, - 56, 0, 0, 5, 0, 0, 210, 13, 140, 189, 1, 125, 167, 0, 110, - 146, 0, 96, 126, 0, 81, 106, 0, 67, 85, 0, 51, 59, 0, 28, - 4, 0, 0, 212, 18, 126, 190, 7, 113, 168, 0, 100, 146, 0, 86, - 126, 0, 73, 106, 0, 59, 84, 0, 43, 59, 0, 22, 4, 0, 0, - 212, 21, 115, 190, 13, 103, 168, 3, 91, 146, 0, 78, 125, 0, 65, - 105, 0, 52, 84, 0, 36, 58, 0, 16, 4, 0, 0, 213, 24, 103, - 189, 19, 91, 168, 9, 82, 146, 0, 69, 125, 0, 57, 105, 0, 44, - 84, 0, 29, 58, 0, 7, 4, 0, 0, 213, 27, 92, 188, 21, 81, - 168, 14, 71, 146, 1, 59, 125, 0, 48, 105, 0, 36, 84, 0, 21, - 58, 0, 4, 4, 0, 0, 213, 30, 80, 189, 22, 69, 168, 17, 61, - 146, 5, 50, 125, 0, 39, 104, 0, 27, 83, 0, 12, 57, 0, 0, - 4, 0, 0, 214, 30, 67, 189, 25, 57, 168, 20, 50, 146, 9, 40, - 125, 0, 29, 104, 0, 17, 83, 0, 2, 56, 0, 0, 4, 0, 0, - 214, 32, 53, 189, 27, 44, 169, 20, 38, 146, 13, 28, 124, 2, 17, - 104, 0, 4, 83, 0, 0, 56, 0, 0, 4, 0, 0, 214, 33, 41, - 190, 27, 33, 168, 23, 27, 146, 13, 18, 125, 3, 5, 105, 0, 0, - 83, 0, 0, 56, 0, 0, 4, 0, 0, 185, 229, 250, 164, 204, 223, - 146, 182, 199, 127, 158, 174, 108, 136, 149, 89, 113, 125, 70, 90, 100, - 46, 62, 71, 10, 25, 33, 189, 227, 225, 168, 202, 201, 148, 181, 179, - 129, 157, 156, 109, 135, 134, 90, 113, 113, 70, 89, 90, 46, 62, 62, - 8, 24, 25, 192, 226, 202, 170, 202, 182, 151, 179, 162, 130, 156, 141, - 110, 133, 121, 91, 112, 101, 71, 89, 80, 46, 61, 54, 7, 24, 19, - 194, 224, 179, 173, 200, 160, 153, 178, 144, 132, 155, 125, 112, 133, 107, - 92, 111, 89, 71, 88, 69, 46, 61, 45, 6, 23, 10, 196, 223, 155, - 174, 198, 139, 154, 176, 124, 132, 153, 107, 113, 131, 91, 92, 110, 75, - 72, 87, 58, 47, 60, 37, 4, 23, 0, 198, 221, 131, 175, 197, 117, - 155, 175, 105, 133, 152, 91, 113, 130, 76, 92, 109, 63, 72, 86, 47, - 46, 60, 26, 3, 23, 0, 200, 220, 104, 176, 196, 94, 156, 175, 84, - 134, 151, 72, 113, 129, 59, 93, 108, 47, 72, 85, 33, 46, 59, 13, - 0, 23, 0, 201, 219, 73, 179, 195, 65, 157, 173, 57, 135, 150, 48, - 114, 129, 39, 94, 108, 28, 72, 85, 15, 47, 59, 0, 0, 22, 0, - 203, 219, 42, 178, 195, 37, 157, 173, 32, 135, 150, 26, 114, 128, 16, - 94, 107, 6, 73, 85, 0, 46, 58, 0, 0, 22, 0, 186, 205, 233, - 165, 183, 209, 148, 163, 187, 128, 142, 163, 109, 121, 140, 91, 101, 118, - 71, 80, 94, 48, 54, 66, 12, 15, 27, 189, 204, 211, 169, 182, 189, - 151, 163, 169, 131, 141, 147, 111, 121, 126, 92, 101, 105, 72, 79, 84, - 48, 54, 58, 11, 15, 19, 192, 202, 190, 171, 181, 170, 152, 161, 152, - 131, 141, 133, 112, 120, 113, 93, 100, 94, 72, 79, 74, 48, 53, 50, - 10, 15, 11, 195, 201, 169, 172, 179, 151, 153, 160, 135, 132, 139, 117, - 113, 119, 100, 93, 99, 82, 72, 78, 64, 48, 53, 41, 9, 14, 3, - 195, 200, 146, 174, 179, 131, 154, 159, 117, 133, 138, 101, 113, 118, 86, - 93, 98, 70, 73, 77, 53, 48, 52, 32, 8, 15, 0, 198, 199, 125, - 175, 177, 111, 155, 158, 100, 133, 137, 85, 113, 117, 71, 93, 97, 57, - 72, 77, 42, 47, 52, 22, 5, 14, 0, 199, 198, 101, 176, 177, 89, - 155, 157, 79, 134, 136, 68, 113, 116, 56, 94, 97, 44, 73, 76, 30, - 47, 52, 10, 2, 15, 0, 200, 197, 72, 178, 176, 63, 157, 156, 56, - 135, 136, 46, 114, 116, 37, 94, 96, 26, 73, 76, 11, 47, 51, 0, - 0, 14, 0, 201, 197, 45, 177, 175, 38, 156, 155, 31, 135, 135, 25, - 114, 115, 17, 94, 96, 5, 73, 75, 0, 46, 51, 0, 0, 14, 0, - 187, 183, 218, 167, 165, 197, 149, 147, 176, 129, 127, 153, 111, 109, 132, - 92, 90, 111, 73, 70, 89, 49, 46, 62, 15, 4, 22, 190, 183, 197, - 170, 164, 177, 151, 146, 159, 130, 127, 139, 112, 109, 119, 93, 90, 99, - 72, 70, 78, 49, 45, 53, 14, 4, 15, 192, 182, 179, 171, 163, 161, - 153, 145, 144, 132, 126, 125, 113, 108, 107, 93, 89, 88, 73, 70, 69, - 49, 45, 45, 13, 5, 6, 195, 181, 159, 172, 162, 142, 152, 145, 127, - 132, 125, 111, 113, 107, 94, 93, 88, 77, 73, 69, 59, 48, 45, 37, - 11, 5, 0, 195, 180, 139, 173, 161, 124, 153, 143, 110, 133, 125, 96, - 113, 106, 81, 94, 88, 66, 73, 68, 49, 49, 44, 28, 9, 6, 0, - 196, 179, 118, 174, 160, 106, 154, 142, 94, 133, 124, 81, 113, 105, 68, - 94, 87, 54, 73, 68, 39, 48, 44, 18, 5, 5, 0, 197, 178, 96, - 176, 159, 86, 155, 141, 75, 134, 123, 64, 114, 105, 53, 94, 87, 40, - 73, 68, 26, 48, 44, 5, 2, 6, 0, 199, 178, 70, 176, 158, 62, - 156, 141, 54, 134, 122, 44, 114, 104, 35, 94, 86, 23, 73, 67, 8, - 47, 44, 0, 2, 6, 0, 199, 177, 45, 178, 158, 40, 156, 140, 32, - 135, 122, 26, 114, 104, 16, 94, 86, 4, 73, 67, 0, 47, 44, 0, - 0, 7, 0, 188, 161, 204, 168, 144, 183, 149, 129, 164, 130, 112, 144, - 112, 95, 123, 93, 78, 103, 74, 60, 81, 50, 36, 56, 16, 0, 16, - 190, 160, 185, 170, 144, 165, 151, 128, 148, 132, 111, 130, 112, 95, 110, - 93, 78, 92, 74, 59, 72, 50, 36, 48, 16, 0, 8, 192, 160, 167, - 171, 143, 150, 153, 128, 134, 132, 111, 117, 112, 94, 100, 94, 77, 82, - 74, 59, 63, 50, 36, 40, 14, 0, 0, 193, 159, 149, 172, 143, 134, - 153, 127, 119, 133, 110, 103, 113, 94, 87, 93, 77, 72, 73, 59, 54, - 50, 36, 32, 12, 0, 0, 195, 159, 131, 173, 142, 117, 153, 127, 104, - 132, 110, 90, 113, 93, 76, 93, 76, 61, 74, 59, 45, 49, 36, 23, - 9, 0, 0, 196, 158, 113, 174, 141, 101, 155, 126, 89, 133, 109, 76, - 113, 93, 64, 94, 76, 51, 74, 58, 35, 49, 36, 14, 6, 0, 0, - 197, 157, 92, 174, 141, 80, 154, 125, 71, 134, 108, 60, 114, 92, 50, - 94, 75, 37, 73, 58, 22, 48, 36, 1, 5, 0, 0, 197, 157, 68, - 175, 140, 59, 155, 124, 51, 134, 108, 41, 113, 91, 32, 94, 75, 21, - 73, 57, 5, 48, 35, 0, 5, 0, 0, 198, 156, 46, 176, 140, 40, - 155, 124, 32, 134, 107, 24, 114, 91, 14, 94, 75, 2, 73, 57, 0, - 48, 36, 0, 3, 0, 0, 189, 140, 191, 168, 126, 172, 150, 112, 154, - 131, 97, 134, 112, 82, 115, 94, 66, 96, 74, 49, 75, 51, 25, 50, - 12, 0, 10, 191, 139, 173, 170, 125, 154, 152, 111, 138, 132, 96, 121, - 113, 81, 103, 94, 66, 85, 74, 48, 66, 50, 26, 42, 12, 0, 1, - 192, 139, 157, 171, 125, 140, 152, 111, 125, 132, 96, 109, 113, 81, 92, - 94, 65, 76, 74, 48, 58, 50, 26, 35, 9, 0, 0, 193, 139, 140, - 172, 124, 125, 153, 110, 112, 133, 95, 96, 113, 80, 82, 94, 65, 66, - 74, 49, 50, 50, 26, 28, 7, 0, 0, 194, 138, 123, 172, 123, 109, - 153, 110, 97, 133, 95, 84, 113, 80, 70, 94, 65, 56, 74, 48, 40, - 50, 26, 20, 6, 0, 0, 194, 138, 105, 173, 123, 94, 153, 109, 83, - 133, 94, 70, 112, 79, 59, 94, 64, 46, 74, 48, 31, 50, 26, 9, - 4, 0, 0, 196, 138, 87, 174, 122, 77, 153, 109, 67, 133, 93, 56, - 113, 79, 46, 94, 64, 34, 73, 48, 18, 49, 27, 0, 4, 0, 0, - 196, 137, 65, 174, 122, 57, 154, 108, 49, 133, 93, 39, 113, 79, 29, - 94, 64, 18, 74, 48, 3, 49, 27, 0, 2, 0, 0, 197, 137, 47, - 175, 122, 40, 155, 108, 32, 133, 93, 23, 114, 79, 14, 94, 64, 1, - 73, 48, 0, 48, 27, 0, 2, 0, 0, 189, 119, 177, 168, 106, 159, - 150, 94, 142, 131, 81, 124, 113, 67, 107, 94, 53, 89, 74, 37, 69, - 51, 11, 45, 6, 0, 3, 191, 119, 161, 170, 106, 144, 152, 94, 129, - 132, 81, 112, 113, 67, 96, 94, 53, 79, 74, 37, 61, 51, 13, 38, - 6, 0, 0, 192, 119, 146, 170, 106, 131, 152, 94, 117, 132, 80, 101, - 112, 67, 85, 94, 53, 70, 74, 37, 53, 50, 14, 31, 4, 0, 0, - 192, 119, 131, 171, 106, 117, 153, 94, 105, 132, 80, 89, 113, 67, 75, - 94, 54, 61, 74, 38, 45, 51, 14, 23, 3, 0, 0, 193, 118, 114, - 171, 106, 102, 153, 93, 90, 132, 80, 78, 113, 67, 65, 94, 53, 52, - 74, 37, 36, 50, 15, 16, 1, 0, 0, 194, 118, 99, 172, 105, 89, - 153, 93, 78, 132, 80, 66, 113, 67, 54, 94, 53, 42, 74, 38, 27, - 50, 16, 5, 1, 0, 0, 194, 118, 82, 173, 105, 72, 153, 93, 63, - 132, 79, 53, 113, 67, 42, 94, 53, 30, 74, 38, 15, 49, 16, 0, - 0, 0, 0, 195, 117, 63, 173, 105, 55, 154, 93, 47, 133, 79, 37, - 113, 66, 27, 94, 53, 15, 73, 38, 0, 48, 16, 0, 0, 0, 0, - 195, 117, 46, 173, 104, 39, 154, 92, 32, 133, 79, 22, 113, 66, 13, - 94, 53, 0, 73, 38, 0, 48, 17, 0, 0, 0, 0, 189, 96, 166, - 168, 85, 147, 150, 74, 132, 131, 62, 115, 113, 51, 99, 94, 38, 82, - 74, 21, 63, 51, 0, 40, 1, 0, 0, 190, 96, 150, 170, 85, 133, - 152, 75, 119, 132, 63, 104, 113, 51, 88, 94, 38, 72, 75, 22, 55, - 51, 0, 33, 1, 0, 0, 192, 96, 137, 170, 85, 121, 152, 74, 108, - 132, 64, 94, 113, 52, 79, 94, 39, 64, 74, 23, 48, 50, 0, 26, - 0, 0, 0, 192, 96, 122, 171, 86, 109, 152, 75, 96, 132, 63, 83, - 113, 52, 69, 94, 39, 56, 74, 24, 41, 50, 0, 19, 0, 0, 0, - 193, 96, 107, 171, 85, 96, 152, 75, 84, 132, 64, 72, 113, 52, 60, - 94, 39, 47, 74, 24, 32, 50, 1, 10, 0, 0, 0, 193, 96, 93, - 172, 85, 82, 152, 75, 72, 133, 63, 61, 113, 51, 49, 94, 39, 37, - 73, 25, 23, 49, 2, 2, 0, 0, 0, 194, 96, 78, 172, 85, 68, - 152, 75, 59, 132, 63, 49, 113, 52, 39, 94, 40, 26, 73, 25, 11, - 48, 3, 0, 0, 0, 0, 194, 96, 60, 173, 85, 52, 153, 75, 44, - 132, 64, 35, 112, 52, 25, 94, 40, 12, 73, 26, 0, 48, 4, 0, - 0, 0, 0, 195, 96, 46, 173, 85, 38, 154, 74, 31, 133, 63, 22, - 113, 52, 11, 93, 40, 0, 73, 26, 0, 47, 5, 0, 0, 0, 0, - 188, 67, 153, 168, 58, 137, 151, 49, 122, 131, 39, 106, 113, 28, 90, - 94, 13, 75, 75, 0, 57, 51, 0, 35, 0, 0, 0, 190, 68, 138, - 170, 59, 123, 152, 50, 110, 132, 41, 96, 113, 29, 80, 94, 16, 66, - 75, 0, 49, 50, 0, 27, 0, 0, 0, 191, 69, 126, 170, 59, 112, - 151, 52, 100, 132, 42, 86, 113, 30, 73, 95, 17, 58, 75, 0, 42, - 50, 0, 21, 0, 0, 0, 192, 70, 113, 170, 61, 100, 151, 52, 89, - 132, 42, 77, 113, 31, 64, 94, 19, 50, 74, 1, 35, 50, 0, 14, - 0, 0, 0, 192, 70, 100, 170, 62, 89, 151, 53, 77, 131, 43, 66, - 112, 32, 54, 94, 20, 42, 74, 2, 27, 49, 0, 5, 0, 0, 0, - 192, 71, 87, 171, 61, 77, 152, 53, 67, 131, 44, 57, 112, 33, 45, - 94, 21, 33, 74, 4, 19, 49, 0, 1, 0, 0, 0, 193, 71, 74, - 171, 62, 64, 152, 53, 55, 132, 44, 45, 113, 34, 34, 94, 22, 23, - 73, 5, 7, 48, 0, 0, 0, 0, 0, 193, 70, 58, 172, 62, 50, - 152, 54, 42, 132, 44, 32, 112, 35, 22, 93, 23, 10, 73, 6, 0, - 47, 0, 0, 0, 0, 0, 193, 70, 45, 172, 62, 38, 153, 54, 31, - 132, 44, 21, 112, 35, 9, 94, 23, 0, 73, 7, 0, 47, 0, 0, - 0, 0, 0, 189, 26, 141, 169, 15, 126, 150, 2, 112, 131, 0, 97, - 113, 0, 82, 94, 0, 67, 75, 0, 51, 50, 0, 29, 0, 0, 0, - 190, 28, 128, 170, 18, 114, 151, 8, 101, 132, 0, 88, 113, 0, 74, - 94, 0, 60, 75, 0, 44, 50, 0, 23, 0, 0, 0, 191, 30, 117, - 170, 23, 104, 152, 11, 92, 132, 1, 79, 113, 0, 67, 95, 0, 53, - 75, 0, 37, 50, 0, 17, 0, 0, 0, 191, 33, 105, 170, 26, 93, - 151, 18, 83, 132, 6, 70, 112, 0, 58, 94, 0, 45, 75, 0, 30, - 49, 0, 8, 0, 0, 0, 191, 34, 93, 170, 27, 82, 151, 20, 72, - 131, 8, 61, 112, 0, 49, 94, 0, 38, 74, 0, 23, 49, 0, 4, - 0, 0, 0, 191, 36, 82, 170, 29, 71, 151, 22, 63, 131, 11, 52, - 112, 0, 41, 93, 0, 29, 74, 0, 14, 48, 0, 1, 0, 0, 0, - 191, 38, 69, 170, 31, 60, 151, 24, 51, 131, 14, 41, 112, 1, 31, - 93, 0, 19, 73, 0, 3, 48, 0, 0, 0, 0, 0, 192, 37, 56, - 171, 31, 47, 152, 25, 40, 131, 17, 30, 112, 4, 19, 93, 0, 7, - 73, 0, 0, 47, 0, 0, 0, 0, 0, 192, 38, 45, 171, 33, 36, - 152, 26, 30, 131, 18, 21, 111, 7, 9, 93, 0, 0, 73, 0, 0, - 47, 0, 0, 0, 0, 0, 149, 218, 248, 133, 194, 222, 119, 173, 198, - 102, 151, 173, 86, 130, 148, 70, 108, 125, 53, 85, 100, 32, 59, 71, - 0, 22, 33, 154, 216, 223, 137, 193, 200, 122, 172, 178, 106, 150, 156, - 89, 128, 133, 73, 107, 112, 54, 85, 89, 31, 59, 63, 0, 22, 26, - 159, 215, 202, 141, 192, 181, 126, 171, 161, 108, 149, 141, 90, 128, 121, - 74, 107, 100, 55, 85, 80, 32, 58, 55, 0, 22, 19, 161, 213, 179, - 144, 190, 160, 126, 170, 143, 109, 148, 125, 92, 127, 107, 74, 106, 89, - 56, 84, 69, 32, 58, 46, 0, 21, 11, 163, 211, 156, 144, 189, 139, - 129, 168, 125, 110, 147, 108, 93, 126, 92, 75, 105, 76, 57, 83, 58, - 33, 58, 37, 0, 21, 1, 167, 211, 133, 147, 188, 120, 130, 167, 105, - 110, 145, 92, 93, 125, 78, 76, 104, 64, 58, 83, 48, 33, 57, 27, - 0, 21, 0, 169, 210, 108, 149, 187, 96, 131, 166, 86, 112, 144, 74, - 94, 124, 62, 77, 103, 49, 58, 82, 35, 33, 57, 15, 0, 21, 0, - 170, 209, 80, 151, 186, 71, 133, 165, 62, 114, 143, 52, 95, 123, 42, - 77, 103, 32, 58, 81, 18, 33, 56, 0, 0, 21, 0, 173, 208, 55, - 152, 186, 49, 134, 165, 41, 114, 143, 34, 95, 122, 25, 77, 102, 14, - 58, 81, 0, 33, 56, 0, 0, 21, 0, 154, 195, 232, 137, 174, 207, - 122, 156, 185, 105, 136, 163, 89, 116, 140, 73, 97, 117, 56, 76, 94, - 35, 51, 66, 0, 13, 28, 158, 194, 209, 141, 174, 187, 125, 155, 167, - 109, 135, 146, 91, 116, 125, 75, 96, 105, 57, 75, 83, 35, 50, 57, - 0, 12, 21, 161, 193, 189, 144, 173, 169, 128, 154, 151, 110, 134, 132, - 93, 115, 113, 77, 95, 94, 58, 75, 74, 35, 50, 50, 0, 12, 13, - 164, 192, 168, 145, 171, 151, 129, 153, 134, 111, 133, 117, 94, 114, 100, - 76, 95, 82, 58, 75, 64, 36, 50, 42, 0, 12, 5, 165, 191, 147, - 147, 170, 131, 130, 152, 117, 113, 132, 102, 95, 113, 86, 77, 94, 71, - 58, 74, 54, 35, 50, 33, 0, 13, 0, 167, 189, 126, 148, 169, 113, - 132, 151, 100, 113, 131, 86, 96, 112, 73, 77, 93, 59, 59, 73, 43, - 35, 49, 23, 0, 12, 0, 170, 189, 104, 150, 168, 91, 133, 150, 81, - 114, 130, 69, 96, 111, 57, 78, 92, 46, 59, 73, 31, 35, 49, 11, - 0, 13, 0, 171, 188, 78, 152, 168, 68, 134, 149, 60, 115, 130, 50, - 96, 111, 41, 78, 92, 29, 60, 73, 15, 35, 49, 0, 0, 12, 0, - 173, 187, 55, 153, 167, 47, 134, 149, 39, 115, 129, 33, 97, 110, 24, - 79, 92, 13, 60, 72, 0, 35, 48, 0, 0, 12, 0, 157, 175, 217, - 139, 157, 196, 125, 141, 175, 109, 122, 153, 92, 104, 132, 76, 86, 110, - 59, 67, 88, 37, 43, 61, 1, 1, 23, 161, 174, 196, 144, 156, 176, - 127, 140, 158, 110, 121, 137, 94, 104, 118, 77, 85, 98, 59, 67, 78, - 37, 43, 53, 0, 2, 16, 163, 174, 178, 146, 156, 160, 130, 139, 143, - 112, 121, 124, 95, 103, 106, 78, 85, 88, 60, 66, 69, 37, 42, 46, - 0, 2, 7, 166, 173, 159, 147, 154, 142, 130, 138, 127, 113, 120, 111, - 96, 103, 95, 78, 84, 77, 60, 66, 59, 37, 43, 37, 0, 2, 0, - 166, 172, 139, 148, 154, 125, 131, 137, 112, 113, 120, 96, 96, 102, 81, - 78, 84, 66, 60, 65, 50, 37, 42, 29, 0, 3, 0, 167, 171, 120, - 149, 153, 107, 133, 137, 95, 114, 118, 81, 97, 101, 69, 79, 84, 56, - 60, 65, 40, 37, 42, 19, 0, 3, 0, 170, 170, 99, 151, 152, 87, - 134, 136, 77, 115, 118, 66, 97, 101, 55, 79, 83, 42, 61, 65, 28, - 37, 42, 7, 0, 3, 0, 172, 170, 75, 152, 151, 65, 134, 135, 57, - 115, 117, 48, 97, 100, 38, 79, 83, 27, 61, 64, 12, 36, 42, 0, - 0, 3, 0, 172, 169, 55, 154, 151, 46, 135, 134, 40, 116, 116, 32, - 97, 99, 21, 80, 82, 10, 61, 64, 0, 36, 41, 0, 0, 3, 0, - 160, 154, 203, 143, 139, 182, 127, 124, 164, 111, 107, 143, 95, 91, 122, - 78, 75, 103, 60, 57, 81, 39, 33, 56, 1, 0, 18, 163, 154, 184, - 146, 138, 165, 130, 123, 148, 113, 107, 129, 96, 90, 110, 79, 74, 92, - 61, 56, 72, 39, 34, 48, 2, 0, 9, 165, 154, 167, 147, 137, 149, - 131, 122, 134, 114, 106, 117, 96, 90, 100, 79, 74, 82, 61, 56, 64, - 39, 33, 40, 2, 0, 1, 166, 153, 150, 149, 137, 133, 132, 122, 119, - 114, 106, 104, 97, 90, 88, 79, 74, 72, 61, 56, 55, 39, 34, 33, - 0, 0, 0, 168, 152, 132, 149, 136, 117, 132, 121, 104, 114, 105, 90, - 97, 89, 76, 79, 73, 62, 61, 56, 46, 38, 34, 25, 0, 0, 0, - 169, 151, 114, 150, 135, 101, 133, 121, 90, 114, 104, 77, 97, 89, 65, - 80, 73, 51, 61, 56, 36, 38, 34, 16, 0, 0, 0, 170, 150, 94, - 151, 135, 83, 134, 120, 73, 115, 104, 62, 98, 88, 51, 80, 72, 39, - 61, 56, 24, 38, 34, 3, 0, 0, 0, 172, 150, 72, 153, 134, 63, - 135, 119, 55, 115, 103, 45, 98, 88, 36, 80, 72, 24, 61, 55, 9, - 38, 34, 0, 0, 0, 0, 172, 150, 54, 153, 134, 47, 135, 119, 38, - 116, 103, 30, 98, 87, 21, 80, 72, 8, 62, 55, 0, 37, 34, 0, - 0, 0, 0, 162, 134, 190, 145, 120, 171, 129, 108, 153, 113, 93, 134, - 97, 78, 115, 80, 63, 96, 62, 46, 75, 41, 23, 51, 0, 0, 11, - 165, 134, 173, 147, 120, 154, 131, 107, 138, 114, 92, 120, 97, 78, 103, - 80, 63, 85, 62, 46, 66, 40, 23, 43, 0, 0, 2, 166, 134, 157, - 148, 120, 140, 132, 106, 125, 114, 92, 109, 97, 77, 93, 81, 63, 77, - 62, 46, 58, 40, 24, 36, 0, 0, 0, 168, 133, 140, 149, 119, 125, - 132, 106, 112, 115, 92, 97, 98, 77, 82, 81, 62, 67, 62, 46, 50, - 40, 24, 29, 0, 0, 0, 168, 133, 123, 150, 119, 110, 133, 106, 97, - 115, 91, 84, 98, 77, 70, 81, 62, 57, 62, 46, 41, 40, 24, 20, - 0, 0, 0, 169, 132, 107, 150, 118, 94, 133, 105, 84, 115, 91, 72, - 98, 76, 60, 80, 62, 47, 62, 46, 32, 39, 25, 11, 0, 0, 0, - 171, 132, 89, 152, 118, 79, 135, 105, 69, 115, 90, 58, 98, 76, 47, - 80, 62, 36, 62, 46, 21, 39, 25, 0, 0, 0, 0, 171, 132, 69, - 153, 117, 60, 135, 104, 52, 116, 90, 42, 98, 76, 33, 81, 61, 21, - 62, 46, 6, 38, 25, 0, 0, 0, 0, 172, 132, 54, 153, 118, 45, - 135, 104, 38, 116, 90, 28, 98, 76, 18, 81, 61, 6, 62, 46, 0, - 38, 25, 0, 0, 0, 0, 164, 115, 177, 146, 103, 159, 130, 91, 143, - 114, 78, 125, 97, 65, 107, 81, 51, 89, 63, 34, 69, 41, 9, 46, - 0, 0, 4, 166, 115, 161, 148, 103, 144, 132, 91, 129, 115, 78, 112, - 98, 65, 96, 81, 51, 79, 63, 35, 61, 41, 11, 38, 0, 0, 0, - 167, 115, 146, 150, 102, 131, 132, 91, 117, 115, 78, 101, 98, 65, 86, - 81, 51, 71, 63, 35, 54, 41, 12, 32, 0, 0, 0, 168, 114, 132, - 150, 103, 118, 133, 91, 105, 116, 78, 91, 98, 64, 76, 82, 51, 61, - 63, 36, 46, 41, 13, 24, 0, 0, 0, 169, 114, 116, 150, 102, 103, - 134, 90, 91, 116, 78, 79, 98, 65, 66, 81, 51, 53, 63, 36, 37, - 40, 14, 17, 0, 0, 0, 169, 114, 101, 151, 101, 89, 134, 90, 79, - 116, 77, 67, 98, 64, 56, 81, 51, 44, 63, 36, 29, 40, 15, 7, - 0, 0, 0, 170, 114, 85, 152, 101, 75, 135, 90, 65, 116, 77, 54, - 98, 64, 44, 81, 51, 32, 63, 36, 17, 39, 15, 0, 0, 0, 0, - 172, 113, 66, 152, 101, 58, 135, 89, 49, 116, 77, 40, 99, 64, 30, - 81, 51, 18, 62, 36, 3, 38, 16, 0, 0, 0, 0, 171, 113, 51, - 153, 101, 44, 136, 89, 36, 116, 77, 28, 99, 64, 18, 81, 51, 5, - 62, 36, 0, 38, 16, 0, 0, 0, 0, 165, 94, 166, 147, 82, 147, - 132, 72, 132, 115, 61, 115, 98, 49, 99, 82, 36, 82, 64, 19, 64, - 42, 0, 41, 0, 0, 0, 167, 93, 150, 150, 83, 134, 133, 73, 120, - 116, 62, 104, 99, 49, 88, 82, 36, 72, 64, 20, 55, 41, 0, 33, - 0, 0, 0, 169, 93, 137, 150, 83, 122, 134, 73, 109, 116, 61, 94, - 99, 50, 80, 82, 37, 65, 64, 21, 49, 41, 0, 27, 0, 0, 0, - 169, 94, 123, 150, 83, 110, 133, 73, 97, 116, 61, 83, 99, 50, 70, - 82, 38, 57, 63, 23, 42, 41, 0, 20, 0, 0, 0, 169, 94, 109, - 150, 84, 97, 134, 73, 85, 116, 62, 73, 99, 51, 61, 81, 38, 48, - 63, 23, 33, 41, 1, 11, 0, 0, 0, 170, 94, 96, 150, 83, 84, - 134, 73, 74, 116, 61, 62, 99, 50, 51, 82, 38, 39, 64, 23, 24, - 40, 3, 4, 0, 0, 0, 171, 93, 79, 152, 82, 70, 135, 73, 61, - 116, 62, 51, 98, 51, 40, 81, 38, 28, 63, 24, 14, 39, 4, 0, - 0, 0, 0, 171, 94, 64, 152, 83, 55, 135, 73, 47, 116, 62, 37, - 98, 50, 27, 81, 38, 15, 63, 24, 1, 39, 4, 0, 0, 0, 0, - 172, 93, 51, 153, 82, 42, 135, 73, 35, 117, 62, 26, 99, 51, 16, - 81, 39, 3, 63, 25, 0, 38, 5, 0, 0, 0, 0, 166, 68, 153, - 148, 59, 137, 133, 49, 121, 115, 39, 106, 99, 28, 91, 82, 13, 75, - 65, 0, 58, 42, 0, 36, 0, 0, 0, 168, 68, 139, 150, 59, 124, - 134, 50, 110, 116, 40, 96, 99, 30, 81, 82, 16, 66, 64, 0, 50, - 41, 0, 29, 0, 0, 0, 169, 69, 126, 150, 59, 113, 134, 51, 101, - 117, 42, 87, 100, 30, 73, 82, 17, 59, 65, 0, 43, 41, 0, 23, - 0, 0, 0, 169, 70, 115, 150, 61, 102, 134, 52, 89, 116, 42, 77, - 99, 32, 65, 82, 19, 52, 64, 0, 36, 41, 0, 15, 0, 0, 0, - 169, 70, 101, 150, 61, 90, 134, 52, 79, 116, 43, 68, 99, 32, 55, - 82, 21, 43, 64, 2, 28, 41, 0, 6, 0, 0, 0, 170, 70, 89, - 151, 62, 79, 134, 53, 69, 116, 44, 58, 99, 33, 46, 81, 21, 34, - 64, 3, 20, 41, 0, 2, 0, 0, 0, 170, 71, 76, 152, 62, 66, - 134, 53, 57, 116, 43, 46, 99, 33, 36, 82, 22, 24, 64, 5, 10, - 40, 0, 0, 0, 0, 0, 171, 70, 61, 152, 62, 52, 135, 53, 44, - 116, 44, 35, 99, 34, 24, 82, 22, 12, 63, 6, 0, 39, 0, 0, - 0, 0, 0, 171, 71, 49, 153, 62, 41, 135, 54, 33, 117, 45, 25, - 98, 34, 13, 81, 23, 0, 63, 7, 0, 39, 0, 0, 0, 0, 0, - 167, 33, 142, 149, 24, 127, 134, 10, 113, 116, 0, 97, 100, 0, 83, - 83, 0, 68, 65, 0, 52, 40, 0, 30, 0, 0, 0, 169, 33, 129, - 150, 26, 115, 134, 17, 102, 116, 3, 89, 100, 0, 75, 83, 0, 60, - 65, 0, 45, 40, 0, 24, 0, 0, 0, 169, 36, 118, 151, 27, 104, - 134, 19, 93, 116, 7, 80, 100, 0, 67, 83, 0, 54, 65, 0, 38, - 41, 0, 17, 0, 0, 0, 169, 39, 107, 150, 30, 94, 134, 22, 84, - 116, 11, 71, 99, 0, 59, 83, 0, 46, 64, 0, 31, 40, 0, 9, - 0, 0, 0, 169, 39, 95, 151, 31, 83, 134, 24, 73, 116, 15, 62, - 100, 1, 51, 83, 0, 38, 64, 0, 24, 40, 0, 5, 0, 0, 0, - 169, 41, 83, 151, 33, 73, 134, 26, 64, 117, 17, 54, 99, 4, 42, - 82, 0, 30, 64, 0, 16, 40, 0, 1, 0, 0, 0, 170, 42, 71, - 152, 34, 62, 134, 28, 53, 117, 19, 44, 99, 6, 33, 82, 0, 21, - 63, 0, 4, 39, 0, 0, 0, 0, 0, 171, 42, 59, 152, 35, 50, - 134, 29, 42, 117, 21, 32, 99, 9, 22, 82, 0, 9, 63, 0, 0, - 38, 0, 0, 0, 0, 0, 172, 42, 48, 152, 36, 40, 135, 29, 32, - 117, 21, 23, 99, 10, 12, 82, 0, 0, 63, 0, 0, 38, 0, 0, - 0, 0, 0, 107, 207, 246, 96, 185, 220, 86, 165, 196, 73, 144, 171, - 60, 123, 147, 46, 103, 125, 32, 82, 100, 9, 56, 71, 0, 20, 33, - 115, 206, 221, 104, 184, 198, 92, 164, 178, 78, 143, 154, 64, 123, 133, - 51, 102, 111, 34, 81, 89, 10, 56, 63, 0, 20, 27, 122, 204, 200, - 108, 183, 180, 95, 163, 161, 82, 142, 140, 68, 122, 120, 54, 102, 101, - 36, 81, 79, 11, 56, 55, 0, 20, 20, 125, 203, 179, 111, 181, 160, - 97, 162, 143, 85, 141, 124, 70, 121, 107, 55, 101, 89, 38, 80, 69, - 14, 55, 46, 0, 19, 10, 128, 202, 156, 113, 180, 140, 102, 161, 125, - 87, 140, 108, 71, 120, 92, 56, 100, 76, 39, 79, 59, 14, 55, 38, - 0, 20, 3, 132, 200, 135, 117, 179, 121, 103, 159, 106, 88, 139, 93, - 73, 119, 79, 57, 100, 65, 41, 79, 49, 15, 54, 28, 0, 19, 0, - 134, 200, 111, 119, 178, 98, 105, 158, 87, 89, 138, 76, 74, 118, 64, - 58, 99, 51, 41, 78, 37, 16, 54, 17, 0, 19, 0, 137, 199, 85, - 122, 177, 75, 108, 158, 66, 91, 137, 56, 75, 118, 46, 59, 98, 35, - 42, 78, 22, 16, 54, 3, 0, 19, 0, 140, 198, 62, 125, 177, 55, - 109, 158, 47, 92, 137, 40, 76, 117, 32, 59, 98, 21, 42, 78, 6, - 16, 54, 0, 0, 18, 0, 118, 186, 231, 106, 167, 206, 93, 149, 184, - 81, 130, 161, 67, 111, 139, 54, 92, 117, 39, 72, 93, 17, 48, 66, - 0, 10, 29, 123, 185, 207, 110, 166, 186, 98, 148, 167, 85, 129, 145, - 71, 111, 125, 56, 92, 104, 40, 72, 83, 18, 48, 57, 0, 10, 22, - 128, 184, 188, 113, 165, 168, 102, 147, 151, 88, 128, 131, 73, 110, 113, - 58, 91, 94, 42, 71, 74, 19, 48, 50, 0, 9, 15, 131, 183, 168, - 116, 164, 151, 104, 146, 134, 89, 127, 117, 73, 109, 100, 58, 90, 83, - 42, 71, 65, 20, 48, 42, 0, 9, 5, 134, 182, 148, 120, 163, 131, - 105, 145, 118, 90, 126, 102, 75, 108, 86, 59, 90, 72, 43, 71, 55, - 19, 47, 34, 0, 9, 0, 136, 181, 128, 122, 162, 115, 107, 144, 102, - 92, 125, 87, 76, 107, 74, 61, 89, 60, 44, 70, 45, 20, 47, 24, - 0, 8, 0, 139, 180, 106, 124, 161, 95, 109, 144, 83, 93, 124, 71, - 77, 107, 60, 61, 89, 47, 44, 70, 33, 20, 47, 13, 0, 8, 0, - 142, 179, 82, 125, 160, 72, 111, 143, 63, 94, 124, 54, 77, 106, 44, - 61, 88, 32, 44, 69, 18, 20, 46, 0, 0, 8, 0, 143, 179, 62, - 127, 160, 54, 111, 142, 47, 94, 124, 39, 78, 106, 29, 62, 88, 18, - 45, 69, 3, 20, 46, 0, 0, 8, 0, 124, 167, 216, 112, 150, 194, - 99, 134, 174, 87, 117, 153, 73, 100, 131, 58, 82, 110, 43, 64, 88, - 23, 40, 61, 0, 0, 24, 129, 166, 195, 116, 150, 175, 103, 134, 158, - 89, 116, 137, 75, 99, 118, 60, 82, 98, 44, 63, 78, 23, 40, 53, - 0, 0, 17, 132, 166, 177, 119, 149, 160, 106, 133, 143, 90, 115, 124, - 76, 99, 107, 61, 81, 88, 45, 63, 69, 24, 40, 46, 0, 0, 9, - 136, 166, 159, 121, 148, 143, 107, 132, 126, 92, 115, 111, 77, 98, 94, - 62, 81, 78, 46, 63, 60, 23, 40, 38, 0, 0, 0, 138, 164, 140, - 122, 147, 125, 108, 131, 111, 93, 114, 97, 79, 98, 82, 63, 80, 67, - 46, 62, 50, 24, 40, 29, 0, 0, 0, 139, 163, 122, 124, 146, 109, - 110, 131, 96, 94, 114, 83, 79, 97, 70, 63, 81, 57, 46, 62, 41, - 24, 40, 21, 0, 0, 0, 141, 163, 101, 126, 145, 90, 111, 130, 79, - 95, 113, 68, 79, 96, 56, 63, 80, 44, 47, 62, 30, 23, 40, 10, - 0, 0, 0, 144, 162, 79, 127, 145, 70, 112, 129, 60, 95, 112, 51, - 79, 96, 41, 64, 79, 30, 47, 61, 15, 23, 40, 0, 0, 0, 0, - 145, 162, 60, 129, 145, 52, 113, 129, 46, 96, 112, 37, 79, 95, 27, - 64, 79, 16, 47, 61, 1, 23, 39, 0, 0, 0, 0, 131, 147, 202, - 117, 133, 181, 105, 119, 162, 91, 103, 142, 77, 87, 122, 62, 71, 102, - 47, 54, 81, 26, 31, 56, 0, 0, 18, 135, 147, 183, 120, 132, 164, - 107, 118, 147, 93, 102, 128, 78, 87, 110, 63, 71, 92, 47, 54, 72, - 26, 31, 48, 0, 0, 10, 138, 147, 166, 123, 131, 149, 108, 118, 133, - 94, 102, 116, 79, 86, 100, 64, 71, 82, 48, 54, 64, 27, 31, 41, - 0, 0, 2, 139, 146, 149, 124, 131, 134, 111, 117, 119, 94, 101, 103, - 79, 86, 88, 64, 70, 72, 48, 53, 55, 27, 31, 33, 0, 0, 0, - 141, 146, 132, 125, 131, 117, 111, 117, 104, 95, 101, 91, 80, 86, 77, - 65, 70, 62, 48, 53, 46, 26, 31, 25, 0, 0, 0, 143, 145, 115, - 126, 130, 101, 112, 116, 90, 96, 100, 78, 80, 85, 65, 65, 70, 52, - 49, 53, 37, 27, 32, 17, 0, 0, 0, 144, 144, 96, 128, 129, 85, - 112, 115, 75, 97, 100, 64, 81, 85, 52, 65, 69, 40, 49, 53, 26, - 26, 31, 5, 0, 0, 0, 146, 144, 76, 129, 129, 67, 114, 115, 58, - 97, 99, 48, 82, 84, 38, 66, 69, 27, 49, 53, 12, 26, 32, 0, - 0, 0, 0, 146, 144, 59, 130, 128, 51, 114, 114, 43, 98, 99, 35, - 82, 84, 25, 66, 69, 13, 49, 53, 0, 26, 32, 0, 0, 0, 0, - 135, 129, 189, 122, 115, 170, 107, 103, 152, 94, 89, 133, 79, 74, 114, - 64, 60, 95, 49, 43, 75, 29, 20, 51, 0, 0, 12, 138, 129, 171, - 124, 115, 153, 110, 103, 138, 95, 89, 120, 81, 74, 103, 66, 60, 86, - 50, 44, 67, 28, 21, 43, 0, 0, 3, 140, 129, 156, 125, 115, 140, - 111, 103, 125, 96, 89, 109, 81, 74, 93, 67, 60, 76, 50, 44, 59, - 29, 22, 36, 0, 0, 0, 142, 128, 140, 127, 115, 125, 112, 102, 112, - 97, 88, 97, 82, 74, 83, 67, 60, 67, 50, 44, 51, 29, 22, 29, - 0, 0, 0, 142, 128, 124, 127, 114, 111, 113, 102, 98, 98, 88, 85, - 82, 74, 71, 66, 60, 58, 50, 44, 42, 29, 22, 21, 0, 0, 0, - 144, 127, 108, 128, 114, 96, 113, 101, 85, 98, 87, 73, 82, 74, 61, - 67, 60, 48, 50, 44, 33, 28, 23, 12, 0, 0, 0, 145, 127, 91, - 129, 114, 81, 115, 101, 71, 98, 87, 60, 82, 73, 48, 67, 59, 37, - 50, 44, 22, 29, 23, 1, 0, 0, 0, 147, 127, 73, 130, 113, 63, - 115, 101, 55, 98, 87, 45, 83, 73, 35, 67, 59, 24, 50, 44, 10, - 28, 24, 0, 0, 0, 0, 147, 127, 58, 131, 113, 49, 115, 100, 42, - 99, 86, 33, 83, 73, 23, 67, 59, 10, 50, 44, 0, 27, 24, 0, - 0, 0, 0, 138, 110, 177, 124, 99, 159, 110, 88, 142, 96, 75, 125, - 82, 62, 107, 66, 48, 89, 51, 33, 70, 30, 8, 46, 0, 0, 5, - 142, 111, 160, 127, 99, 144, 113, 88, 130, 98, 75, 112, 82, 62, 96, - 68, 49, 80, 51, 33, 61, 30, 10, 39, 0, 0, 0, 143, 111, 146, - 128, 99, 131, 114, 88, 118, 98, 75, 101, 83, 62, 86, 68, 49, 71, - 52, 33, 54, 30, 11, 32, 0, 0, 0, 144, 111, 132, 128, 99, 118, - 113, 88, 106, 99, 75, 91, 83, 62, 77, 68, 49, 62, 52, 34, 46, - 30, 12, 25, 0, 0, 0, 144, 111, 117, 129, 98, 104, 114, 87, 92, - 99, 75, 80, 83, 62, 67, 68, 49, 53, 51, 34, 38, 30, 13, 18, - 0, 0, 0, 145, 111, 103, 130, 98, 91, 114, 87, 80, 99, 75, 68, - 83, 63, 57, 68, 50, 45, 51, 34, 30, 30, 14, 8, 0, 0, 0, - 146, 110, 87, 131, 98, 76, 115, 87, 67, 99, 75, 56, 83, 62, 45, - 68, 49, 33, 52, 35, 19, 30, 15, 2, 0, 0, 0, 148, 110, 70, - 131, 98, 60, 116, 86, 52, 99, 74, 43, 84, 62, 33, 69, 49, 21, - 52, 35, 6, 29, 15, 0, 0, 0, 0, 148, 110, 56, 132, 97, 48, - 117, 87, 40, 100, 75, 31, 84, 62, 22, 68, 49, 9, 51, 35, 0, - 28, 15, 0, 0, 0, 0, 142, 91, 166, 126, 80, 148, 113, 71, 132, - 98, 59, 115, 83, 47, 99, 69, 34, 82, 53, 17, 64, 32, 0, 41, - 0, 0, 0, 143, 91, 150, 128, 81, 135, 114, 71, 120, 99, 60, 104, - 85, 48, 89, 69, 35, 73, 53, 19, 56, 32, 0, 34, 0, 0, 0, - 145, 91, 137, 129, 81, 122, 115, 71, 109, 100, 60, 94, 85, 48, 81, - 69, 35, 65, 53, 19, 49, 32, 0, 28, 0, 0, 0, 146, 92, 124, - 130, 81, 110, 115, 71, 98, 100, 60, 84, 85, 49, 71, 69, 36, 57, - 53, 21, 42, 32, 0, 21, 0, 0, 0, 147, 91, 110, 130, 81, 97, - 115, 71, 86, 100, 60, 74, 84, 49, 62, 69, 36, 48, 53, 22, 34, - 32, 0, 13, 0, 0, 0, 147, 92, 97, 130, 81, 85, 116, 72, 76, - 100, 60, 63, 85, 49, 52, 69, 37, 40, 53, 22, 26, 31, 1, 5, - 0, 0, 0, 148, 92, 82, 131, 81, 71, 116, 71, 62, 100, 60, 53, - 84, 49, 42, 69, 37, 30, 52, 23, 16, 31, 2, 0, 0, 0, 0, - 148, 91, 67, 132, 81, 57, 117, 71, 49, 100, 60, 39, 84, 49, 30, - 69, 37, 18, 52, 23, 2, 30, 2, 0, 0, 0, 0, 149, 91, 54, - 132, 81, 46, 118, 71, 39, 101, 60, 29, 85, 49, 19, 69, 37, 6, - 52, 23, 0, 29, 3, 0, 0, 0, 0, 143, 68, 153, 128, 59, 137, - 115, 49, 122, 99, 39, 107, 85, 28, 91, 70, 13, 75, 54, 0, 58, - 32, 0, 36, 0, 0, 0, 146, 68, 140, 131, 59, 125, 116, 51, 111, - 100, 40, 97, 85, 29, 82, 70, 15, 67, 54, 0, 50, 32, 0, 29, - 0, 0, 0, 147, 68, 127, 131, 59, 114, 117, 51, 102, 101, 41, 88, - 86, 30, 74, 70, 17, 60, 54, 0, 44, 32, 0, 23, 0, 0, 0, - 147, 70, 115, 131, 60, 103, 116, 52, 91, 100, 42, 78, 85, 32, 65, - 70, 19, 53, 54, 1, 38, 32, 0, 17, 0, 0, 0, 147, 70, 103, - 131, 61, 91, 117, 53, 81, 101, 43, 69, 86, 32, 57, 70, 20, 44, - 54, 2, 30, 32, 0, 7, 0, 0, 0, 148, 70, 91, 132, 61, 80, - 117, 52, 70, 101, 43, 59, 85, 33, 48, 70, 21, 36, 53, 4, 22, - 32, 0, 3, 0, 0, 0, 148, 70, 78, 132, 62, 68, 117, 53, 58, - 101, 43, 48, 85, 34, 38, 70, 22, 26, 53, 6, 12, 31, 0, 0, - 0, 0, 0, 149, 71, 64, 132, 62, 54, 118, 54, 46, 101, 44, 37, - 85, 34, 27, 69, 23, 15, 53, 7, 1, 30, 0, 0, 0, 0, 0, - 150, 70, 53, 134, 61, 44, 118, 54, 36, 101, 44, 28, 85, 35, 17, - 69, 23, 4, 52, 8, 0, 30, 0, 0, 0, 0, 0, 145, 38, 143, - 130, 29, 128, 117, 18, 114, 101, 3, 98, 87, 0, 84, 72, 0, 69, - 54, 0, 53, 30, 0, 31, 0, 0, 0, 147, 38, 130, 132, 30, 116, - 117, 22, 103, 101, 8, 89, 87, 0, 76, 72, 0, 62, 54, 0, 46, - 30, 0, 24, 0, 0, 0, 148, 40, 119, 132, 31, 105, 117, 23, 94, - 101, 13, 81, 87, 0, 68, 71, 0, 55, 54, 0, 39, 30, 0, 18, - 0, 0, 0, 148, 42, 108, 132, 34, 96, 117, 25, 85, 102, 15, 73, - 86, 2, 60, 71, 0, 47, 54, 0, 33, 30, 0, 11, 0, 0, 0, - 148, 43, 96, 133, 35, 85, 117, 28, 75, 102, 18, 64, 87, 5, 52, - 71, 0, 40, 54, 0, 25, 30, 0, 5, 0, 0, 0, 149, 44, 85, - 132, 36, 75, 118, 29, 66, 101, 20, 55, 86, 8, 44, 70, 0, 32, - 53, 0, 18, 29, 0, 2, 0, 0, 0, 149, 45, 74, 133, 37, 64, - 118, 31, 55, 102, 21, 45, 85, 10, 34, 70, 0, 22, 53, 0, 6, - 28, 0, 0, 0, 0, 0, 150, 46, 61, 133, 39, 52, 118, 31, 44, - 102, 23, 34, 85, 12, 24, 70, 0, 12, 52, 0, 0, 28, 0, 0, - 0, 0, 0, 150, 46, 51, 133, 40, 42, 119, 32, 35, 102, 24, 25, - 85, 13, 14, 70, 0, 1, 52, 0, 0, 27, 0, 0, 0, 0, 0, - 53, 198, 244, 49, 177, 218, 41, 158, 195, 32, 138, 171, 22, 118, 147, - 11, 98, 124, 0, 78, 100, 0, 54, 71, 0, 18, 34, 69, 196, 220, - 64, 175, 196, 54, 157, 176, 45, 137, 154, 32, 117, 133, 19, 98, 111, - 0, 78, 89, 0, 53, 63, 0, 17, 27, 80, 195, 198, 69, 175, 179, - 60, 156, 159, 50, 136, 139, 38, 116, 120, 25, 98, 101, 4, 77, 80, - 0, 53, 55, 0, 17, 21, 84, 193, 177, 75, 173, 159, 64, 155, 142, - 55, 135, 124, 41, 116, 107, 27, 97, 89, 9, 76, 70, 0, 53, 47, - 0, 17, 11, 89, 193, 157, 79, 172, 140, 70, 154, 125, 57, 134, 109, - 44, 115, 92, 32, 96, 76, 13, 76, 59, 0, 52, 39, 0, 16, 4, - 94, 191, 135, 85, 171, 121, 72, 152, 108, 60, 133, 94, 47, 114, 80, - 32, 95, 65, 15, 76, 49, 0, 52, 29, 0, 16, 0, 98, 190, 113, - 87, 170, 100, 76, 152, 89, 62, 132, 77, 49, 113, 65, 35, 95, 52, - 18, 75, 37, 0, 52, 18, 0, 15, 0, 103, 190, 89, 90, 169, 80, - 78, 151, 70, 64, 132, 60, 51, 113, 49, 37, 94, 38, 20, 75, 25, - 0, 52, 5, 0, 15, 0, 106, 189, 69, 93, 169, 61, 80, 151, 53, - 66, 131, 45, 52, 113, 36, 37, 94, 25, 19, 74, 11, 0, 51, 0, - 0, 15, 0, 76, 178, 229, 68, 159, 205, 61, 142, 183, 50, 124, 160, - 40, 106, 138, 28, 88, 116, 12, 69, 93, 0, 45, 66, 0, 5, 29, - 86, 177, 207, 78, 158, 184, 67, 142, 166, 56, 123, 145, 45, 106, 125, - 31, 88, 105, 16, 69, 83, 0, 45, 58, 0, 6, 22, 93, 176, 187, - 81, 158, 168, 71, 141, 150, 61, 123, 131, 47, 105, 113, 35, 87, 94, - 20, 68, 74, 0, 45, 51, 0, 5, 16, 98, 175, 168, 84, 157, 150, - 75, 140, 134, 63, 122, 117, 50, 104, 100, 37, 87, 83, 21, 68, 65, - 0, 45, 42, 0, 4, 7, 100, 174, 149, 89, 155, 132, 76, 139, 117, - 65, 121, 102, 53, 104, 87, 39, 86, 72, 23, 67, 55, 0, 45, 34, - 0, 3, 0, 103, 173, 130, 92, 155, 115, 80, 138, 102, 68, 120, 88, - 53, 103, 75, 40, 86, 61, 24, 67, 45, 0, 45, 25, 0, 3, 0, - 107, 172, 108, 95, 154, 96, 82, 137, 85, 70, 119, 73, 55, 102, 61, - 42, 85, 49, 25, 67, 34, 0, 45, 14, 0, 3, 0, 110, 172, 86, - 97, 153, 76, 85, 137, 67, 70, 119, 57, 56, 102, 46, 42, 84, 35, - 26, 66, 21, 0, 44, 1, 0, 3, 0, 112, 171, 67, 98, 153, 59, - 86, 137, 52, 71, 119, 44, 58, 102, 34, 44, 85, 22, 27, 66, 7, - 0, 44, 0, 0, 3, 0, 90, 160, 215, 81, 144, 193, 70, 129, 173, - 61, 112, 151, 49, 95, 131, 37, 79, 109, 22, 61, 87, 0, 38, 61, - 0, 0, 25, 96, 160, 194, 86, 143, 174, 75, 128, 157, 65, 112, 137, - 53, 95, 117, 40, 78, 98, 25, 60, 78, 0, 38, 53, 0, 0, 17, - 100, 159, 177, 89, 143, 159, 79, 128, 143, 67, 111, 124, 55, 95, 107, - 42, 78, 89, 27, 60, 70, 2, 38, 46, 0, 0, 9, 104, 158, 159, - 92, 142, 143, 81, 127, 127, 69, 110, 110, 56, 94, 94, 43, 78, 78, - 28, 60, 60, 2, 38, 38, 0, 0, 1, 107, 157, 140, 94, 141, 125, - 82, 126, 112, 71, 110, 97, 59, 94, 82, 45, 77, 67, 29, 59, 51, - 4, 37, 30, 0, 0, 0, 110, 156, 122, 97, 140, 109, 85, 125, 97, - 72, 109, 83, 58, 93, 71, 45, 77, 57, 29, 60, 42, 5, 38, 22, - 0, 0, 0, 111, 156, 103, 99, 139, 91, 87, 125, 81, 73, 108, 69, - 60, 92, 58, 46, 77, 45, 30, 59, 31, 5, 38, 12, 0, 0, 0, - 115, 156, 82, 101, 140, 73, 88, 124, 63, 74, 108, 53, 60, 92, 44, - 46, 76, 32, 31, 59, 18, 6, 37, 0, 0, 0, 0, 116, 155, 65, - 102, 139, 58, 89, 124, 49, 75, 108, 41, 61, 92, 32, 48, 76, 21, - 31, 59, 6, 5, 37, 0, 0, 0, 0, 100, 141, 201, 88, 127, 181, - 79, 114, 162, 69, 99, 142, 57, 83, 122, 44, 68, 102, 30, 51, 81, - 7, 28, 56, 0, 0, 19, 105, 141, 182, 94, 127, 163, 83, 114, 146, - 71, 98, 128, 59, 83, 110, 46, 68, 91, 31, 51, 72, 10, 28, 48, - 0, 0, 11, 108, 141, 166, 96, 127, 149, 85, 113, 133, 73, 98, 116, - 60, 83, 99, 46, 68, 82, 32, 51, 64, 11, 29, 41, 0, 0, 2, - 111, 141, 149, 98, 126, 134, 88, 112, 119, 74, 97, 103, 61, 83, 88, - 48, 67, 72, 33, 51, 56, 11, 29, 34, 0, 0, 0, 112, 140, 132, - 100, 125, 118, 89, 112, 105, 75, 97, 91, 62, 82, 77, 49, 68, 62, - 33, 51, 47, 12, 29, 26, 0, 0, 0, 115, 140, 116, 102, 125, 103, - 90, 111, 91, 76, 96, 78, 62, 82, 65, 49, 67, 52, 34, 51, 38, - 13, 29, 18, 0, 0, 0, 117, 139, 97, 103, 124, 87, 91, 111, 77, - 78, 96, 65, 63, 81, 54, 49, 67, 41, 34, 51, 27, 12, 29, 7, - 0, 0, 0, 119, 138, 78, 105, 124, 69, 92, 110, 60, 78, 95, 50, - 65, 81, 40, 50, 67, 29, 34, 51, 15, 13, 30, 0, 0, 0, 0, - 120, 138, 64, 106, 124, 54, 93, 110, 47, 78, 95, 38, 65, 81, 29, - 50, 66, 17, 34, 50, 2, 13, 29, 0, 0, 0, 0, 107, 124, 189, - 96, 111, 169, 85, 99, 152, 73, 85, 132, 61, 71, 114, 48, 57, 95, - 34, 41, 75, 14, 18, 51, 0, 0, 13, 111, 124, 171, 100, 111, 153, - 88, 99, 137, 75, 85, 120, 63, 72, 103, 50, 58, 85, 36, 41, 66, - 15, 19, 43, 0, 0, 4, 113, 124, 156, 101, 111, 139, 90, 99, 125, - 77, 85, 109, 64, 71, 93, 51, 57, 77, 36, 42, 59, 17, 20, 37, - 0, 0, 0, 115, 124, 140, 103, 111, 125, 90, 99, 112, 78, 85, 97, - 64, 71, 82, 52, 57, 67, 36, 42, 50, 16, 20, 30, 0, 0, 0, - 117, 123, 125, 104, 110, 111, 92, 98, 99, 79, 85, 86, 65, 71, 72, - 51, 58, 59, 37, 42, 43, 17, 21, 22, 0, 0, 0, 118, 123, 110, - 105, 110, 97, 93, 98, 86, 78, 84, 74, 66, 71, 62, 52, 57, 49, - 37, 42, 34, 17, 22, 14, 0, 0, 0, 120, 123, 93, 106, 109, 82, - 94, 97, 72, 80, 84, 61, 66, 71, 50, 52, 57, 38, 37, 42, 24, - 17, 22, 2, 0, 0, 0, 121, 122, 75, 108, 109, 66, 95, 97, 58, - 80, 84, 48, 66, 71, 37, 52, 57, 26, 37, 42, 12, 16, 22, 0, - 0, 0, 0, 122, 123, 62, 108, 109, 52, 95, 97, 45, 81, 84, 36, - 67, 70, 26, 52, 57, 14, 37, 42, 0, 15, 22, 0, 0, 0, 0, - 113, 107, 177, 102, 96, 159, 89, 85, 141, 78, 72, 124, 65, 60, 107, - 52, 46, 89, 37, 30, 70, 18, 5, 46, 0, 0, 6, 116, 107, 160, - 104, 96, 144, 92, 85, 129, 80, 72, 112, 67, 60, 96, 53, 47, 80, - 38, 31, 62, 19, 7, 39, 0, 0, 0, 118, 107, 147, 105, 96, 131, - 93, 85, 118, 80, 72, 101, 67, 60, 87, 54, 47, 71, 39, 31, 54, - 19, 8, 32, 0, 0, 0, 119, 107, 132, 106, 96, 118, 94, 85, 106, - 81, 73, 91, 67, 60, 77, 54, 47, 63, 39, 32, 47, 20, 9, 25, - 0, 0, 0, 119, 107, 118, 106, 95, 105, 94, 85, 93, 81, 72, 80, - 68, 60, 68, 54, 47, 54, 39, 32, 39, 20, 11, 18, 0, 0, 0, - 121, 107, 104, 107, 96, 92, 95, 84, 80, 81, 72, 69, 68, 61, 58, - 54, 48, 46, 39, 33, 31, 20, 12, 9, 0, 0, 0, 123, 107, 88, - 108, 95, 77, 96, 84, 68, 82, 72, 57, 68, 60, 46, 54, 47, 35, - 39, 33, 20, 19, 13, 2, 0, 0, 0, 123, 106, 72, 110, 95, 63, - 96, 84, 54, 82, 72, 45, 69, 60, 35, 55, 48, 23, 39, 33, 9, - 18, 14, 0, 0, 0, 0, 125, 106, 60, 110, 94, 50, 98, 84, 42, - 83, 72, 34, 69, 60, 25, 55, 48, 12, 39, 33, 0, 17, 13, 0, - 0, 0, 0, 118, 89, 165, 105, 79, 148, 93, 69, 132, 81, 57, 115, - 68, 45, 99, 55, 32, 82, 41, 15, 64, 21, 0, 41, 0, 0, 0, - 120, 89, 150, 107, 79, 135, 96, 69, 121, 82, 58, 105, 70, 46, 89, - 56, 34, 73, 41, 17, 56, 21, 0, 34, 0, 0, 0, 121, 89, 137, - 108, 79, 123, 96, 69, 109, 82, 58, 95, 70, 47, 81, 56, 34, 66, - 41, 18, 49, 21, 0, 28, 0, 0, 0, 122, 90, 124, 109, 79, 110, - 96, 69, 99, 83, 58, 85, 70, 47, 72, 56, 35, 58, 41, 19, 42, - 21, 0, 22, 0, 0, 0, 123, 90, 111, 110, 79, 98, 97, 69, 87, - 83, 59, 75, 70, 47, 63, 56, 35, 50, 41, 20, 35, 21, 0, 14, - 0, 0, 0, 123, 90, 98, 110, 79, 87, 97, 70, 76, 84, 58, 64, - 70, 48, 53, 56, 36, 41, 40, 21, 26, 21, 0, 5, 0, 0, 0, - 125, 89, 84, 111, 79, 73, 97, 69, 64, 84, 59, 54, 70, 48, 43, - 56, 36, 31, 40, 22, 17, 20, 1, 1, 0, 0, 0, 125, 89, 69, - 112, 79, 60, 98, 70, 51, 84, 59, 42, 70, 48, 32, 56, 36, 20, - 41, 22, 5, 19, 2, 0, 0, 0, 0, 126, 89, 57, 112, 79, 49, - 99, 70, 41, 84, 59, 32, 70, 48, 22, 56, 36, 10, 40, 22, 0, - 18, 2, 0, 0, 0, 0, 121, 67, 154, 108, 58, 138, 97, 50, 124, - 84, 39, 107, 71, 28, 92, 58, 12, 76, 43, 0, 59, 20, 0, 37, - 0, 0, 0, 124, 68, 140, 111, 59, 126, 98, 50, 112, 84, 40, 98, - 71, 29, 83, 58, 15, 67, 42, 0, 51, 20, 0, 30, 0, 0, 0, - 124, 68, 129, 111, 59, 114, 99, 51, 102, 86, 41, 88, 71, 30, 75, - 58, 17, 60, 42, 0, 45, 20, 0, 24, 0, 0, 0, 125, 70, 116, - 111, 60, 103, 99, 51, 92, 85, 41, 79, 71, 31, 66, 58, 19, 53, - 42, 3, 38, 20, 0, 17, 0, 0, 0, 125, 70, 104, 111, 61, 93, - 99, 52, 81, 85, 43, 69, 72, 32, 58, 58, 20, 45, 42, 4, 31, - 20, 0, 8, 0, 0, 0, 126, 70, 92, 111, 61, 81, 99, 52, 71, - 85, 42, 60, 71, 33, 49, 57, 21, 37, 42, 6, 23, 20, 0, 3, - 0, 0, 0, 126, 70, 79, 112, 61, 70, 99, 53, 60, 85, 43, 50, - 71, 33, 39, 57, 22, 28, 41, 7, 13, 19, 0, 0, 0, 0, 0, - 127, 71, 66, 113, 62, 56, 100, 53, 48, 86, 44, 39, 71, 34, 29, - 57, 23, 18, 41, 8, 2, 18, 0, 0, 0, 0, 0, 128, 70, 55, - 114, 62, 46, 100, 54, 39, 86, 44, 30, 71, 34, 20, 57, 23, 7, - 41, 9, 0, 18, 0, 0, 0, 0, 0, 124, 41, 145, 111, 32, 128, - 99, 23, 114, 86, 10, 100, 73, 0, 85, 60, 0, 71, 43, 0, 54, - 17, 0, 32, 0, 0, 0, 126, 42, 131, 113, 33, 117, 100, 25, 104, - 86, 14, 90, 73, 0, 77, 60, 0, 63, 44, 0, 47, 18, 0, 25, - 0, 0, 0, 127, 43, 120, 113, 34, 106, 101, 26, 95, 86, 17, 82, - 73, 2, 69, 59, 0, 56, 43, 0, 41, 18, 0, 19, 0, 0, 0, - 127, 45, 109, 113, 37, 97, 101, 28, 85, 86, 19, 74, 73, 5, 61, - 59, 0, 48, 43, 0, 34, 19, 0, 11, 0, 0, 0, 127, 46, 98, - 114, 38, 86, 100, 30, 76, 87, 21, 65, 73, 9, 54, 59, 0, 41, - 43, 0, 26, 18, 0, 5, 0, 0, 0, 127, 47, 87, 113, 39, 76, - 101, 31, 67, 86, 22, 56, 72, 11, 45, 59, 0, 33, 43, 0, 19, - 18, 0, 2, 0, 0, 0, 128, 48, 75, 114, 39, 65, 101, 33, 56, - 86, 23, 46, 72, 12, 36, 58, 0, 24, 42, 0, 9, 17, 0, 0, - 0, 0, 0, 129, 48, 63, 114, 41, 54, 102, 33, 46, 87, 24, 36, - 72, 14, 26, 58, 1, 14, 42, 0, 2, 16, 0, 0, 0, 0, 0, - 128, 48, 53, 114, 41, 44, 102, 34, 37, 87, 25, 27, 72, 15, 17, - 58, 1, 3, 41, 0, 0, 15, 0, 0, 0, 0, 0, 0, 189, 242, - 0, 169, 217, 0, 151, 194, 0, 132, 170, 0, 113, 147, 0, 94, 123, - 0, 74, 99, 0, 51, 71, 0, 15, 34, 1, 187, 219, 1, 167, 195, - 0, 150, 175, 0, 131, 153, 0, 113, 132, 0, 94, 111, 0, 74, 89, - 0, 50, 63, 0, 13, 28, 1, 186, 198, 1, 167, 178, 0, 149, 158, - 0, 130, 139, 0, 111, 119, 0, 93, 100, 0, 74, 80, 0, 50, 55, - 0, 13, 22, 1, 185, 176, 1, 165, 159, 1, 148, 142, 0, 129, 123, - 0, 111, 106, 0, 93, 89, 0, 73, 70, 0, 50, 47, 0, 13, 13, - 1, 184, 157, 1, 164, 141, 1, 147, 125, 0, 128, 110, 0, 110, 93, - 0, 92, 77, 0, 73, 60, 0, 50, 39, 0, 12, 5, 25, 182, 137, - 25, 163, 122, 17, 146, 109, 0, 128, 96, 0, 110, 81, 0, 92, 66, - 0, 73, 51, 0, 50, 30, 0, 10, 0, 42, 181, 114, 35, 163, 102, - 30, 145, 91, 14, 127, 80, 0, 109, 67, 0, 91, 53, 0, 72, 39, - 0, 50, 19, 0, 10, 0, 52, 181, 92, 43, 162, 83, 32, 145, 73, - 19, 126, 63, 0, 108, 52, 0, 90, 40, 0, 72, 27, 0, 50, 7, - 0, 10, 0, 57, 181, 74, 48, 162, 66, 37, 144, 57, 24, 126, 49, - 7, 108, 40, 0, 90, 29, 0, 72, 15, 0, 49, 0, 0, 10, 0, - 1, 170, 227, 1, 152, 203, 0, 136, 182, 0, 119, 159, 0, 101, 137, - 0, 84, 115, 0, 65, 92, 0, 43, 66, 0, 1, 29, 1, 169, 206, - 1, 151, 184, 1, 136, 165, 0, 118, 144, 0, 102, 125, 0, 84, 105, - 0, 65, 83, 0, 43, 58, 0, 0, 22, 29, 168, 186, 21, 151, 167, - 14, 135, 150, 4, 118, 131, 0, 101, 112, 0, 83, 94, 0, 65, 75, - 0, 43, 51, 0, 0, 16, 41, 167, 167, 33, 150, 150, 31, 134, 134, - 19, 117, 117, 4, 100, 100, 0, 83, 83, 0, 65, 65, 0, 42, 43, - 0, 0, 8, 48, 167, 149, 41, 149, 133, 33, 133, 118, 25, 116, 103, - 13, 99, 88, 0, 83, 73, 0, 65, 56, 0, 42, 35, 0, 0, 0, - 58, 165, 130, 49, 148, 115, 42, 132, 103, 31, 115, 89, 18, 99, 75, - 0, 82, 61, 0, 64, 46, 0, 42, 26, 0, 0, 0, 62, 164, 110, - 55, 147, 97, 45, 132, 87, 35, 115, 75, 22, 98, 63, 5, 82, 50, - 0, 64, 36, 0, 42, 16, 0, 0, 0, 69, 164, 89, 60, 147, 78, - 50, 131, 70, 37, 114, 59, 26, 98, 49, 10, 81, 37, 0, 64, 24, - 0, 42, 4, 0, 0, 0, 71, 164, 71, 63, 147, 63, 53, 131, 55, - 40, 114, 47, 28, 98, 38, 13, 81, 26, 0, 64, 12, 0, 42, 0, - 0, 0, 0, 28, 153, 214, 24, 138, 193, 23, 123, 171, 16, 107, 150, - 0, 91, 130, 0, 75, 109, 0, 58, 87, 0, 35, 61, 0, 0, 25, - 48, 153, 194, 41, 138, 174, 34, 123, 156, 27, 107, 136, 16, 91, 117, - 1, 75, 98, 0, 57, 78, 0, 35, 53, 0, 0, 17, 55, 153, 177, - 47, 137, 158, 42, 122, 142, 33, 107, 124, 22, 91, 106, 6, 75, 88, - 0, 57, 70, 0, 35, 46, 0, 0, 9, 61, 152, 158, 53, 136, 143, - 45, 122, 127, 36, 106, 111, 24, 90, 94, 10, 74, 78, 0, 57, 61, - 0, 35, 39, 0, 0, 2, 67, 151, 141, 59, 135, 126, 49, 121, 112, - 39, 105, 98, 29, 90, 83, 14, 74, 68, 0, 57, 52, 0, 35, 31, - 0, 0, 0, 71, 150, 123, 62, 135, 110, 54, 120, 98, 42, 105, 84, - 31, 89, 71, 16, 74, 58, 0, 57, 43, 0, 35, 22, 0, 0, 0, - 74, 150, 105, 64, 134, 92, 55, 120, 83, 45, 104, 71, 34, 89, 59, - 20, 73, 47, 0, 57, 32, 0, 35, 13, 0, 0, 0, 78, 149, 84, - 69, 134, 75, 59, 120, 66, 47, 103, 56, 34, 88, 46, 22, 73, 34, - 1, 57, 20, 0, 35, 1, 0, 0, 0, 80, 149, 69, 70, 133, 61, - 60, 119, 53, 49, 103, 44, 36, 88, 35, 23, 73, 24, 2, 56, 10, - 0, 35, 0, 0, 0, 0, 58, 136, 200, 50, 122, 180, 45, 109, 162, - 38, 94, 141, 27, 80, 121, 15, 65, 102, 0, 48, 81, 0, 26, 56, - 0, 0, 19, 66, 136, 182, 59, 122, 163, 52, 109, 146, 42, 94, 128, - 32, 80, 109, 20, 65, 91, 2, 48, 72, 0, 26, 49, 0, 0, 11, - 70, 136, 165, 62, 122, 149, 55, 108, 133, 46, 94, 116, 35, 80, 99, - 21, 65, 82, 4, 49, 64, 0, 26, 41, 0, 0, 3, 76, 135, 149, - 66, 121, 133, 58, 108, 119, 48, 94, 103, 36, 79, 88, 23, 65, 73, - 7, 49, 56, 0, 27, 34, 0, 0, 0, 78, 135, 133, 69, 120, 118, - 60, 107, 106, 50, 93, 92, 39, 79, 77, 26, 65, 63, 8, 49, 47, - 0, 27, 26, 0, 0, 0, 82, 134, 117, 71, 120, 104, 62, 107, 92, - 51, 93, 79, 39, 78, 66, 27, 64, 53, 10, 48, 39, 0, 27, 18, - 0, 0, 0, 84, 134, 99, 73, 119, 87, 64, 106, 77, 53, 92, 66, - 42, 78, 55, 28, 64, 42, 11, 48, 29, 0, 28, 9, 0, 0, 0, - 87, 133, 81, 76, 119, 72, 66, 106, 62, 55, 92, 52, 43, 78, 42, - 29, 64, 31, 12, 48, 17, 0, 28, 0, 0, 0, 0, 88, 134, 67, - 77, 119, 58, 68, 106, 51, 56, 92, 42, 44, 78, 32, 30, 64, 20, - 12, 48, 6, 0, 28, 0, 0, 0, 0, 73, 120, 189, 64, 107, 168, - 57, 96, 151, 47, 82, 133, 38, 69, 114, 26, 55, 95, 11, 39, 75, - 0, 16, 51, 0, 0, 14, 78, 120, 171, 69, 107, 153, 62, 95, 137, - 51, 82, 119, 40, 69, 102, 29, 55, 85, 15, 39, 66, 0, 17, 44, - 0, 0, 4, 81, 120, 156, 71, 107, 140, 64, 95, 125, 53, 82, 109, - 42, 69, 93, 31, 55, 77, 16, 39, 59, 0, 18, 37, 0, 0, 0, - 85, 120, 141, 74, 107, 126, 65, 95, 112, 54, 82, 97, 43, 69, 82, - 32, 55, 67, 17, 39, 51, 0, 19, 30, 0, 0, 0, 86, 119, 126, - 76, 106, 112, 66, 95, 100, 56, 81, 85, 45, 69, 72, 33, 55, 59, - 18, 40, 43, 0, 19, 22, 0, 0, 0, 89, 119, 110, 78, 106, 98, - 69, 94, 87, 56, 81, 75, 46, 68, 62, 33, 55, 49, 18, 40, 35, - 0, 20, 15, 0, 0, 0, 89, 119, 95, 80, 106, 83, 70, 94, 73, - 58, 81, 63, 46, 68, 51, 34, 55, 39, 19, 40, 25, 0, 20, 4, - 0, 0, 0, 92, 118, 78, 82, 106, 68, 70, 93, 59, 59, 81, 49, - 47, 68, 39, 34, 55, 28, 19, 40, 14, 0, 20, 0, 0, 0, 0, - 93, 118, 65, 82, 105, 55, 72, 93, 48, 60, 81, 39, 47, 68, 29, - 34, 55, 18, 20, 40, 2, 0, 20, 0, 0, 0, 0, 83, 104, 177, - 74, 93, 159, 65, 82, 142, 56, 70, 124, 45, 57, 106, 33, 44, 89, - 20, 28, 70, 1, 4, 46, 0, 0, 8, 86, 104, 161, 78, 93, 145, - 68, 82, 128, 58, 70, 112, 48, 58, 96, 35, 45, 80, 21, 29, 62, - 1, 6, 40, 0, 0, 0, 89, 104, 147, 79, 93, 131, 69, 82, 118, - 59, 70, 102, 47, 58, 87, 36, 45, 72, 23, 29, 55, 3, 7, 33, - 0, 0, 0, 90, 104, 132, 80, 93, 119, 71, 82, 106, 60, 70, 91, - 48, 58, 77, 37, 45, 62, 23, 30, 47, 4, 7, 26, 0, 0, 0, - 92, 104, 118, 82, 93, 105, 72, 82, 93, 61, 69, 80, 50, 58, 68, - 37, 45, 55, 23, 30, 39, 4, 8, 18, 0, 0, 0, 94, 104, 105, - 82, 92, 93, 72, 82, 82, 61, 70, 70, 50, 58, 58, 38, 46, 46, - 23, 31, 31, 6, 10, 11, 0, 0, 0, 95, 104, 90, 84, 92, 79, - 74, 82, 70, 62, 70, 58, 50, 58, 48, 37, 46, 36, 23, 31, 22, - 4, 11, 3, 0, 0, 0, 96, 103, 74, 85, 92, 65, 75, 81, 56, - 63, 70, 47, 50, 58, 37, 38, 46, 25, 24, 31, 11, 3, 11, 0, - 0, 0, 0, 97, 103, 62, 86, 92, 53, 76, 81, 45, 63, 69, 36, - 51, 58, 27, 38, 46, 15, 23, 31, 0, 3, 11, 0, 0, 0, 0, - 90, 87, 165, 81, 77, 148, 72, 67, 132, 62, 55, 116, 50, 44, 99, - 39, 31, 82, 25, 14, 64, 1, 0, 42, 0, 0, 1, 93, 87, 150, - 83, 77, 135, 74, 67, 121, 63, 56, 105, 52, 45, 90, 40, 32, 74, - 25, 16, 57, 3, 0, 35, 0, 0, 0, 95, 87, 138, 85, 77, 123, - 75, 67, 109, 63, 57, 95, 53, 45, 81, 41, 33, 66, 26, 17, 50, - 4, 0, 28, 0, 0, 0, 95, 88, 124, 85, 77, 111, 75, 67, 99, - 63, 57, 86, 53, 45, 72, 41, 33, 58, 26, 18, 43, 5, 1, 22, - 0, 0, 0, 97, 88, 112, 87, 77, 100, 76, 68, 88, 64, 57, 76, - 53, 46, 63, 41, 34, 50, 26, 19, 35, 5, 2, 14, 0, 0, 0, - 99, 87, 99, 87, 78, 88, 76, 68, 77, 65, 57, 65, 53, 46, 54, - 41, 35, 42, 27, 20, 27, 6, 2, 5, 0, 0, 0, 100, 87, 85, - 88, 77, 75, 77, 68, 65, 65, 57, 54, 53, 46, 44, 41, 35, 32, - 27, 21, 19, 5, 3, 2, 0, 0, 0, 100, 88, 71, 89, 77, 61, - 78, 68, 53, 66, 57, 44, 53, 47, 33, 41, 35, 22, 27, 21, 7, - 5, 3, 0, 0, 0, 0, 101, 87, 60, 90, 77, 52, 79, 68, 44, - 66, 58, 34, 53, 47, 25, 41, 35, 13, 26, 22, 0, 5, 3, 0, - 0, 0, 0, 97, 67, 155, 86, 58, 138, 77, 50, 125, 66, 39, 108, - 55, 28, 92, 43, 12, 76, 29, 0, 59, 2, 0, 37, 0, 0, 0, - 99, 67, 141, 88, 59, 127, 78, 50, 113, 68, 40, 98, 56, 29, 83, - 44, 15, 68, 29, 0, 52, 3, 0, 30, 0, 0, 0, 100, 68, 129, - 89, 59, 115, 80, 51, 103, 68, 41, 89, 56, 30, 75, 44, 16, 61, - 30, 0, 45, 4, 0, 24, 0, 0, 0, 100, 69, 118, 90, 60, 104, - 80, 51, 92, 67, 41, 79, 56, 31, 66, 44, 18, 53, 29, 2, 38, - 4, 0, 18, 0, 0, 0, 101, 69, 104, 90, 61, 93, 79, 51, 82, - 67, 42, 70, 56, 32, 59, 44, 20, 46, 29, 4, 31, 6, 0, 9, - 0, 0, 0, 102, 69, 93, 90, 61, 83, 80, 52, 72, 68, 42, 61, - 56, 33, 50, 43, 20, 38, 29, 5, 23, 7, 0, 4, 0, 0, 0, - 102, 70, 80, 91, 61, 71, 80, 52, 61, 68, 43, 51, 56, 32, 40, - 44, 21, 29, 30, 6, 14, 7, 0, 0, 0, 0, 0, 103, 70, 68, - 92, 61, 58, 81, 53, 50, 69, 43, 41, 56, 34, 31, 43, 22, 19, - 29, 7, 3, 7, 0, 0, 0, 0, 0, 104, 70, 57, 92, 61, 48, - 82, 53, 40, 69, 43, 32, 56, 34, 22, 43, 23, 10, 29, 8, 0, - 6, 0, 0, 0, 0, 0, 101, 45, 145, 91, 35, 129, 80, 26, 116, - 69, 15, 101, 59, 0, 86, 46, 0, 71, 31, 0, 55, 0, 0, 33, - 0, 0, 0, 104, 44, 132, 92, 36, 118, 82, 28, 105, 71, 17, 91, - 58, 3, 77, 46, 0, 63, 31, 0, 48, 2, 0, 26, 0, 0, 0, - 104, 46, 121, 93, 37, 107, 82, 30, 96, 70, 20, 83, 58, 6, 70, - 46, 0, 57, 32, 0, 41, 4, 0, 20, 0, 0, 0, 104, 48, 110, - 93, 40, 98, 82, 31, 87, 70, 22, 74, 59, 9, 62, 45, 0, 49, - 31, 0, 35, 6, 0, 13, 0, 0, 0, 104, 48, 99, 92, 41, 88, - 82, 32, 77, 70, 23, 65, 58, 11, 54, 46, 0, 42, 32, 0, 27, - 7, 0, 5, 0, 0, 0, 105, 50, 88, 93, 41, 77, 82, 34, 68, - 71, 24, 57, 58, 13, 46, 45, 1, 35, 31, 0, 21, 7, 0, 2, - 0, 0, 0, 105, 50, 76, 94, 41, 66, 83, 34, 57, 71, 25, 47, - 58, 15, 37, 45, 2, 25, 32, 0, 11, 7, 0, 0, 0, 0, 0, - 106, 50, 64, 94, 42, 55, 83, 35, 47, 71, 26, 38, 58, 16, 27, - 45, 4, 17, 31, 0, 4, 7, 0, 0, 0, 0, 0, 106, 51, 54, - 95, 42, 45, 83, 35, 38, 71, 27, 30, 58, 16, 19, 45, 5, 7, - 30, 0, 0, 6, 0, 0, 0, 0, 0, 0, 181, 240, 0, 162, 216, - 0, 144, 193, 0, 126, 168, 0, 109, 146, 0, 91, 123, 0, 71, 98, - 0, 48, 71, 0, 9, 34, 0, 179, 218, 0, 161, 195, 0, 144, 174, - 0, 126, 153, 0, 108, 132, 0, 90, 110, 0, 71, 88, 0, 48, 63, - 0, 8, 29, 0, 178, 197, 0, 159, 177, 0, 143, 159, 0, 125, 139, - 0, 107, 119, 0, 90, 99, 0, 71, 79, 0, 48, 55, 0, 8, 22, - 0, 177, 177, 0, 158, 158, 0, 142, 141, 0, 124, 123, 0, 107, 106, - 0, 89, 88, 0, 71, 70, 0, 48, 47, 0, 8, 14, 0, 176, 157, - 0, 158, 141, 0, 141, 126, 0, 123, 109, 0, 106, 93, 0, 89, 78, - 0, 70, 60, 0, 47, 39, 0, 7, 5, 0, 175, 138, 0, 157, 123, - 0, 141, 110, 0, 123, 96, 0, 105, 81, 0, 88, 67, 0, 70, 51, - 0, 48, 30, 0, 6, 0, 0, 173, 115, 0, 155, 104, 0, 140, 92, - 0, 122, 80, 0, 105, 67, 0, 88, 55, 0, 69, 40, 0, 47, 20, - 0, 6, 0, 0, 173, 94, 0, 155, 85, 0, 139, 75, 0, 121, 64, - 0, 104, 53, 0, 88, 42, 0, 70, 28, 0, 47, 9, 0, 6, 0, - 0, 173, 76, 0, 155, 70, 0, 138, 61, 0, 122, 53, 0, 104, 44, - 0, 87, 32, 0, 69, 18, 0, 47, 0, 0, 6, 0, 0, 164, 226, - 0, 147, 203, 0, 131, 181, 0, 114, 158, 0, 97, 136, 0, 80, 115, - 0, 63, 92, 0, 40, 65, 0, 0, 30, 0, 162, 205, 0, 145, 184, - 0, 130, 164, 0, 114, 143, 0, 97, 124, 0, 81, 104, 0, 63, 83, - 0, 40, 58, 0, 0, 23, 0, 162, 187, 0, 145, 167, 0, 130, 150, - 0, 113, 131, 0, 96, 112, 0, 80, 93, 0, 62, 74, 0, 40, 50, - 0, 0, 16, 0, 160, 167, 0, 144, 150, 0, 129, 134, 0, 112, 116, - 0, 96, 100, 0, 80, 82, 0, 62, 65, 0, 40, 43, 0, 0, 7, - 0, 160, 148, 0, 143, 133, 0, 128, 118, 0, 111, 103, 0, 96, 88, - 0, 80, 73, 0, 62, 56, 0, 40, 35, 0, 0, 0, 0, 158, 130, - 0, 142, 117, 0, 127, 104, 0, 111, 89, 0, 95, 76, 0, 79, 62, - 0, 62, 46, 0, 40, 26, 0, 0, 0, 0, 158, 111, 0, 141, 99, - 0, 127, 88, 0, 111, 76, 0, 95, 63, 0, 79, 51, 0, 62, 37, - 0, 40, 18, 0, 0, 0, 0, 158, 91, 0, 141, 81, 0, 126, 72, - 0, 110, 62, 0, 94, 50, 0, 79, 39, 0, 62, 25, 0, 40, 5, - 0, 0, 0, 0, 157, 74, 0, 141, 66, 0, 126, 59, 0, 110, 49, - 0, 94, 40, 0, 78, 29, 0, 61, 15, 0, 40, 0, 0, 0, 0, - 0, 148, 214, 0, 133, 192, 0, 119, 171, 0, 103, 150, 0, 87, 129, - 0, 72, 108, 0, 55, 86, 0, 32, 61, 0, 0, 25, 0, 147, 193, - 0, 132, 173, 0, 118, 155, 0, 103, 136, 0, 87, 116, 0, 72, 98, - 0, 55, 78, 0, 32, 53, 0, 0, 17, 0, 147, 176, 0, 132, 158, - 0, 118, 142, 0, 102, 124, 0, 87, 106, 0, 72, 88, 0, 55, 69, - 0, 33, 46, 0, 0, 9, 0, 146, 159, 0, 131, 142, 0, 117, 127, - 0, 102, 111, 0, 87, 95, 0, 71, 79, 0, 55, 61, 0, 33, 39, - 0, 0, 2, 0, 145, 140, 0, 130, 126, 0, 117, 112, 0, 101, 98, - 0, 86, 83, 0, 71, 68, 0, 55, 52, 0, 33, 31, 0, 0, 0, - 0, 144, 124, 0, 130, 111, 0, 116, 99, 0, 101, 84, 0, 86, 72, - 0, 71, 59, 0, 55, 43, 0, 33, 23, 0, 0, 0, 0, 144, 106, - 0, 129, 94, 0, 115, 83, 0, 101, 72, 0, 85, 60, 0, 71, 48, - 0, 55, 34, 0, 33, 14, 0, 0, 0, 3, 143, 86, 0, 129, 77, - 0, 115, 68, 0, 100, 58, 0, 85, 48, 0, 70, 36, 0, 54, 22, - 0, 33, 3, 0, 0, 0, 18, 143, 72, 13, 128, 63, 0, 115, 57, - 0, 100, 47, 0, 85, 37, 0, 70, 26, 0, 54, 13, 0, 33, 0, - 0, 0, 0, 0, 132, 200, 0, 118, 179, 0, 105, 161, 0, 91, 140, - 0, 76, 121, 0, 62, 101, 0, 46, 81, 0, 24, 56, 0, 0, 19, - 0, 131, 182, 0, 118, 163, 0, 105, 146, 0, 91, 128, 0, 77, 110, - 0, 62, 91, 0, 46, 72, 0, 25, 48, 0, 0, 11, 0, 131, 165, - 0, 117, 149, 0, 104, 133, 0, 91, 116, 0, 77, 99, 0, 62, 82, - 0, 46, 64, 0, 25, 41, 0, 0, 4, 0, 131, 149, 0, 116, 134, - 0, 104, 119, 0, 91, 104, 0, 77, 89, 0, 62, 73, 0, 46, 56, - 0, 25, 34, 0, 0, 0, 10, 130, 133, 2, 116, 119, 0, 104, 106, - 0, 90, 91, 0, 76, 78, 0, 62, 64, 0, 46, 48, 0, 26, 27, - 0, 0, 0, 23, 130, 118, 20, 116, 104, 13, 103, 93, 3, 89, 79, - 0, 76, 67, 0, 62, 54, 0, 46, 39, 0, 26, 19, 0, 0, 0, - 33, 129, 101, 27, 115, 89, 19, 103, 79, 9, 89, 67, 0, 75, 56, - 0, 61, 43, 0, 46, 29, 0, 26, 10, 0, 0, 0, 41, 128, 83, - 35, 115, 73, 27, 102, 64, 15, 89, 55, 0, 76, 45, 0, 62, 33, - 0, 46, 18, 0, 26, 0, 0, 0, 0, 43, 129, 69, 38, 115, 61, - 30, 102, 54, 17, 89, 45, 2, 75, 34, 0, 61, 23, 0, 46, 9, - 0, 26, 0, 0, 0, 0, 1, 116, 188, 1, 104, 168, 0, 92, 151, - 0, 79, 132, 0, 66, 113, 0, 52, 94, 0, 36, 75, 0, 14, 52, - 0, 0, 14, 17, 116, 171, 16, 104, 153, 14, 92, 137, 8, 79, 119, - 0, 67, 102, 0, 53, 85, 0, 37, 67, 0, 16, 44, 0, 0, 4, - 31, 116, 155, 27, 104, 140, 21, 92, 125, 13, 79, 109, 3, 66, 93, - 0, 53, 77, 0, 37, 59, 0, 16, 38, 0, 0, 0, 37, 115, 141, - 30, 103, 126, 26, 92, 112, 16, 79, 98, 5, 66, 83, 0, 53, 67, - 0, 38, 51, 0, 17, 31, 0, 0, 0, 41, 115, 126, 37, 103, 112, - 31, 92, 100, 22, 79, 86, 10, 66, 72, 0, 53, 59, 0, 38, 44, - 0, 17, 23, 0, 0, 0, 48, 115, 111, 41, 102, 99, 34, 91, 88, - 24, 78, 76, 14, 66, 63, 0, 53, 50, 0, 38, 36, 0, 18, 15, - 0, 0, 0, 51, 115, 95, 46, 102, 85, 37, 91, 74, 26, 78, 63, - 16, 66, 52, 0, 53, 40, 0, 38, 26, 0, 18, 5, 0, 0, 0, - 55, 114, 80, 47, 102, 69, 40, 90, 60, 30, 78, 51, 19, 66, 41, - 3, 53, 29, 0, 38, 15, 0, 17, 0, 0, 0, 0, 56, 114, 66, - 50, 102, 58, 40, 91, 50, 32, 78, 41, 18, 66, 32, 4, 53, 21, - 0, 38, 5, 0, 17, 0, 0, 0, 0, 39, 102, 178, 37, 90, 159, - 30, 79, 142, 21, 68, 124, 14, 55, 106, 0, 42, 89, 0, 26, 70, - 0, 4, 46, 0, 0, 8, 48, 102, 161, 42, 90, 145, 35, 79, 128, - 26, 68, 112, 19, 55, 96, 3, 43, 79, 0, 27, 62, 0, 6, 40, - 0, 0, 0, 50, 102, 147, 44, 90, 132, 37, 79, 118, 30, 68, 102, - 20, 56, 87, 7, 43, 72, 0, 28, 55, 0, 6, 34, 0, 0, 0, - 53, 101, 133, 47, 90, 118, 41, 79, 106, 32, 68, 91, 21, 56, 78, - 9, 43, 63, 0, 28, 47, 0, 6, 26, 0, 0, 0, 57, 101, 119, - 50, 89, 106, 42, 79, 94, 34, 67, 81, 24, 56, 68, 9, 44, 55, - 0, 29, 40, 0, 6, 19, 0, 0, 0, 60, 100, 105, 50, 90, 94, - 45, 80, 83, 36, 68, 71, 24, 56, 59, 11, 44, 46, 0, 29, 32, - 0, 7, 12, 0, 0, 0, 63, 101, 91, 55, 90, 80, 46, 79, 70, - 37, 68, 59, 26, 56, 49, 12, 44, 37, 1, 29, 23, 0, 7, 3, - 0, 0, 0, 64, 101, 75, 56, 89, 67, 48, 79, 57, 37, 68, 48, - 27, 56, 37, 15, 44, 26, 0, 29, 12, 0, 7, 0, 0, 0, 0, - 66, 101, 64, 58, 89, 55, 49, 79, 47, 39, 68, 38, 27, 56, 29, - 14, 44, 18, 1, 30, 2, 0, 7, 0, 0, 0, 0, 57, 86, 165, - 51, 75, 148, 45, 65, 133, 38, 54, 116, 28, 43, 100, 16, 29, 83, - 0, 13, 64, 0, 0, 42, 0, 0, 3, 60, 86, 151, 55, 75, 135, - 47, 66, 121, 39, 55, 105, 30, 44, 90, 18, 31, 74, 3, 16, 57, - 0, 1, 35, 0, 0, 0, 62, 86, 139, 56, 75, 123, 49, 66, 110, - 40, 55, 95, 30, 44, 81, 19, 31, 66, 4, 17, 51, 0, 1, 29, - 0, 0, 0, 65, 86, 125, 56, 76, 112, 49, 66, 99, 39, 55, 86, - 31, 44, 72, 19, 32, 59, 5, 18, 44, 0, 1, 23, 0, 0, 0, - 67, 86, 113, 58, 75, 100, 51, 66, 88, 41, 56, 77, 31, 45, 64, - 20, 32, 51, 6, 18, 35, 0, 1, 14, 0, 0, 0, 69, 86, 99, - 61, 76, 88, 52, 66, 78, 43, 56, 66, 32, 45, 55, 20, 33, 42, - 7, 19, 27, 0, 1, 6, 0, 0, 0, 69, 86, 86, 61, 76, 75, - 53, 67, 66, 43, 56, 55, 33, 45, 45, 21, 34, 34, 8, 20, 20, - 0, 2, 2, 0, 0, 0, 71, 86, 72, 63, 75, 62, 54, 66, 55, - 45, 56, 45, 33, 45, 35, 22, 34, 23, 7, 20, 8, 0, 2, 0, - 0, 0, 0, 71, 86, 62, 64, 75, 53, 55, 66, 46, 45, 56, 36, - 33, 46, 27, 22, 34, 15, 8, 20, 0, 0, 2, 0, 0, 0, 0, - 69, 67, 156, 61, 58, 140, 53, 50, 125, 45, 39, 108, 35, 28, 93, - 25, 12, 77, 12, 0, 59, 0, 0, 37, 0, 0, 0, 71, 68, 142, - 63, 59, 126, 56, 50, 114, 47, 40, 98, 37, 28, 84, 26, 15, 68, - 12, 0, 53, 0, 0, 30, 0, 0, 0, 72, 68, 130, 63, 59, 116, - 56, 50, 104, 47, 40, 90, 38, 30, 75, 27, 16, 61, 13, 0, 46, - 0, 0, 24, 0, 0, 0, 73, 69, 118, 65, 59, 105, 57, 51, 92, - 47, 41, 80, 37, 30, 67, 26, 18, 53, 14, 1, 39, 0, 0, 18, - 0, 0, 0, 74, 69, 106, 65, 60, 93, 57, 51, 82, 48, 41, 70, - 38, 31, 59, 26, 19, 46, 13, 2, 32, 0, 0, 10, 0, 0, 0, - 76, 69, 95, 66, 61, 84, 58, 52, 73, 48, 42, 61, 37, 32, 50, - 26, 20, 38, 14, 4, 24, 0, 0, 4, 0, 0, 0, 76, 69, 81, - 68, 60, 72, 58, 52, 62, 48, 42, 51, 38, 32, 41, 27, 21, 30, - 14, 4, 16, 0, 0, 1, 0, 0, 0, 76, 69, 68, 68, 61, 60, - 60, 52, 51, 49, 43, 41, 38, 33, 32, 27, 21, 20, 14, 5, 5, - 0, 0, 0, 0, 0, 0, 78, 70, 59, 69, 61, 50, 60, 52, 42, - 49, 43, 34, 39, 33, 24, 27, 22, 13, 14, 7, 1, 0, 0, 0, - 0, 0, 0, 75, 46, 146, 68, 38, 131, 60, 30, 117, 50, 19, 102, - 41, 4, 87, 29, 0, 72, 13, 0, 55, 0, 0, 33, 0, 0, 0, - 78, 47, 132, 70, 39, 119, 61, 30, 105, 53, 20, 92, 42, 5, 78, - 30, 0, 64, 13, 0, 49, 0, 0, 27, 0, 0, 0, 79, 48, 122, - 70, 40, 108, 62, 32, 96, 52, 22, 84, 42, 9, 71, 30, 0, 58, - 14, 0, 42, 0, 0, 20, 0, 0, 0, 79, 50, 111, 70, 42, 99, - 62, 33, 88, 52, 23, 74, 41, 11, 63, 29, 0, 50, 14, 0, 36, - 0, 0, 14, 0, 0, 0, 80, 50, 99, 70, 42, 89, 61, 34, 78, - 52, 25, 67, 41, 14, 55, 30, 0, 42, 15, 0, 28, 0, 0, 6, - 0, 0, 0, 81, 51, 89, 71, 43, 78, 62, 35, 69, 52, 25, 58, - 42, 15, 47, 30, 3, 36, 15, 0, 22, 0, 0, 3, 0, 0, 0, - 81, 51, 77, 71, 44, 68, 63, 36, 59, 53, 26, 49, 41, 16, 38, - 31, 4, 27, 16, 0, 12, 0, 0, 0, 0, 0, 0, 81, 52, 65, - 72, 43, 56, 63, 36, 48, 53, 27, 39, 41, 17, 29, 30, 4, 18, - 14, 0, 3, 0, 0, 0, 0, 0, 0, 81, 52, 55, 73, 44, 47, - 64, 36, 39, 53, 28, 32, 42, 18, 21, 31, 6, 9, 14, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 174, 239, 0, 156, 214, 0, 139, 192, - 0, 121, 168, 0, 105, 145, 0, 87, 123, 0, 68, 98, 0, 46, 70, - 0, 3, 35, 0, 172, 217, 0, 155, 194, 0, 139, 173, 0, 121, 152, - 0, 104, 130, 0, 87, 110, 0, 69, 88, 0, 46, 63, 0, 4, 28, - 0, 171, 197, 0, 153, 175, 0, 138, 158, 0, 121, 139, 0, 103, 118, - 0, 86, 100, 0, 68, 79, 0, 46, 55, 0, 4, 22, 0, 170, 177, - 0, 152, 158, 0, 136, 141, 0, 119, 124, 0, 103, 106, 0, 86, 88, - 0, 68, 70, 0, 45, 47, 0, 3, 14, 0, 169, 157, 0, 152, 141, - 0, 136, 126, 0, 119, 109, 0, 102, 94, 0, 86, 78, 0, 68, 60, - 0, 46, 39, 0, 3, 5, 0, 167, 138, 0, 150, 124, 0, 135, 111, - 0, 118, 97, 0, 102, 82, 0, 85, 68, 0, 68, 52, 0, 46, 31, - 0, 3, 0, 0, 167, 118, 0, 150, 104, 0, 135, 94, 0, 118, 81, - 0, 101, 69, 0, 84, 56, 0, 67, 41, 0, 45, 21, 0, 3, 0, - 0, 166, 97, 0, 149, 87, 0, 134, 77, 0, 117, 67, 0, 101, 56, - 0, 85, 44, 0, 67, 30, 0, 45, 10, 0, 3, 0, 0, 165, 79, - 0, 149, 73, 0, 133, 64, 0, 117, 56, 0, 101, 46, 0, 85, 34, - 0, 68, 21, 0, 46, 1, 0, 3, 0, 0, 158, 225, 0, 141, 201, - 0, 126, 180, 0, 109, 158, 0, 94, 136, 0, 78, 114, 0, 60, 91, - 0, 38, 66, 0, 0, 30, 0, 156, 203, 0, 140, 183, 0, 125, 164, - 0, 109, 143, 0, 94, 124, 0, 78, 104, 0, 61, 83, 0, 38, 57, - 0, 0, 23, 0, 156, 186, 0, 140, 166, 0, 125, 150, 0, 109, 130, - 0, 93, 111, 0, 77, 93, 0, 60, 74, 0, 38, 50, 0, 0, 17, - 0, 155, 167, 0, 138, 149, 0, 124, 134, 0, 109, 117, 0, 93, 100, - 0, 76, 83, 0, 60, 65, 0, 38, 43, 0, 0, 9, 0, 153, 147, - 0, 138, 134, 0, 124, 120, 0, 107, 103, 0, 92, 88, 0, 77, 73, - 0, 60, 56, 0, 38, 35, 0, 0, 0, 0, 153, 131, 0, 137, 118, - 0, 122, 105, 0, 107, 90, 0, 91, 76, 0, 76, 63, 0, 60, 47, - 0, 39, 28, 0, 0, 0, 0, 153, 111, 0, 136, 100, 0, 123, 90, - 0, 107, 77, 0, 92, 65, 0, 76, 52, 0, 60, 37, 0, 38, 18, - 0, 0, 0, 0, 152, 93, 0, 136, 82, 0, 122, 74, 0, 106, 63, - 0, 91, 52, 0, 76, 40, 0, 59, 26, 0, 38, 6, 0, 0, 0, - 0, 151, 78, 0, 136, 69, 0, 121, 61, 0, 106, 52, 0, 91, 43, - 0, 76, 32, 0, 59, 17, 0, 38, 0, 0, 0, 0, 0, 143, 213, - 0, 128, 191, 0, 115, 171, 0, 100, 149, 0, 84, 128, 0, 69, 108, - 0, 52, 86, 0, 30, 61, 0, 0, 25, 0, 142, 193, 0, 127, 173, - 0, 114, 154, 0, 99, 134, 0, 84, 116, 0, 69, 98, 0, 52, 77, - 0, 31, 53, 0, 0, 18, 0, 141, 176, 0, 127, 158, 0, 114, 141, - 0, 98, 122, 0, 84, 105, 0, 69, 88, 0, 53, 69, 0, 31, 46, - 0, 0, 9, 0, 141, 159, 0, 126, 142, 0, 113, 127, 0, 98, 110, - 0, 83, 95, 0, 69, 78, 0, 53, 60, 0, 32, 39, 0, 0, 2, - 0, 140, 140, 0, 126, 126, 0, 112, 112, 0, 98, 98, 0, 83, 83, - 0, 68, 69, 0, 52, 52, 0, 31, 31, 0, 0, 0, 0, 140, 124, - 0, 125, 112, 0, 112, 100, 0, 97, 86, 0, 83, 72, 0, 68, 59, - 0, 52, 44, 0, 31, 23, 0, 0, 0, 0, 139, 106, 0, 125, 96, - 0, 111, 85, 0, 97, 72, 0, 83, 62, 0, 68, 49, 0, 52, 35, - 0, 31, 15, 0, 0, 0, 0, 138, 88, 0, 124, 79, 0, 111, 70, - 0, 96, 59, 0, 82, 48, 0, 68, 38, 0, 52, 24, 0, 31, 4, - 0, 0, 0, 0, 139, 76, 0, 124, 66, 0, 111, 58, 0, 96, 50, - 0, 82, 40, 0, 68, 29, 0, 52, 15, 0, 31, 0, 0, 0, 0, - 0, 129, 200, 0, 114, 179, 0, 102, 160, 0, 87, 139, 0, 74, 120, - 0, 60, 101, 0, 44, 81, 0, 22, 56, 0, 0, 19, 0, 127, 181, - 0, 114, 163, 0, 102, 146, 0, 88, 127, 0, 74, 109, 0, 60, 91, - 0, 44, 72, 0, 23, 48, 0, 0, 11, 0, 127, 166, 0, 113, 148, - 0, 101, 133, 0, 87, 115, 0, 74, 99, 0, 60, 82, 0, 44, 64, - 0, 23, 42, 0, 0, 4, 0, 127, 150, 0, 113, 134, 0, 101, 119, - 0, 87, 104, 0, 74, 89, 0, 60, 73, 0, 44, 56, 0, 23, 35, - 0, 0, 0, 0, 125, 134, 0, 112, 118, 0, 100, 106, 0, 87, 92, - 0, 73, 78, 0, 60, 64, 0, 44, 48, 0, 23, 27, 0, 0, 0, - 0, 125, 118, 0, 112, 105, 0, 100, 94, 0, 86, 80, 0, 73, 68, - 0, 60, 54, 0, 44, 39, 0, 23, 20, 0, 0, 0, 0, 125, 101, - 0, 111, 90, 0, 99, 80, 0, 86, 69, 0, 73, 58, 0, 59, 45, - 0, 44, 30, 0, 23, 11, 0, 0, 0, 0, 124, 85, 0, 111, 75, - 0, 99, 66, 0, 86, 56, 0, 73, 45, 0, 59, 34, 0, 44, 20, - 0, 23, 1, 0, 0, 0, 0, 125, 72, 0, 111, 62, 0, 99, 56, - 0, 86, 46, 0, 73, 36, 0, 60, 26, 0, 44, 12, 0, 23, 0, - 0, 0, 0, 0, 114, 188, 0, 101, 167, 0, 89, 150, 0, 77, 131, - 0, 64, 113, 0, 50, 95, 0, 34, 75, 0, 12, 52, 0, 0, 14, - 0, 113, 170, 0, 101, 153, 0, 89, 137, 0, 77, 120, 0, 64, 102, - 0, 50, 85, 0, 35, 67, 0, 12, 44, 0, 0, 4, 0, 113, 156, - 0, 100, 139, 0, 89, 125, 0, 77, 109, 0, 64, 92, 0, 51, 77, - 0, 35, 60, 0, 12, 38, 0, 0, 0, 0, 112, 141, 0, 100, 126, - 0, 89, 113, 0, 77, 98, 0, 64, 83, 0, 51, 68, 0, 35, 51, - 0, 12, 30, 0, 0, 0, 0, 112, 127, 0, 100, 112, 0, 89, 100, - 0, 76, 87, 0, 64, 74, 0, 51, 59, 0, 35, 44, 0, 13, 24, - 0, 0, 0, 0, 112, 111, 0, 100, 100, 0, 88, 88, 0, 76, 76, - 0, 64, 64, 0, 51, 52, 0, 36, 37, 0, 13, 17, 0, 0, 0, - 0, 111, 96, 0, 99, 85, 0, 88, 76, 0, 76, 64, 0, 64, 53, - 0, 51, 41, 0, 36, 27, 0, 13, 6, 0, 0, 0, 0, 111, 81, - 0, 99, 71, 0, 88, 62, 0, 76, 52, 0, 64, 43, 0, 51, 31, - 0, 36, 17, 0, 13, 0, 0, 0, 0, 0, 111, 69, 0, 99, 60, - 0, 88, 52, 0, 75, 43, 0, 63, 34, 0, 51, 21, 0, 36, 7, - 0, 13, 0, 0, 0, 0, 0, 99, 177, 0, 88, 158, 0, 77, 141, - 0, 66, 123, 0, 53, 106, 0, 40, 89, 0, 25, 71, 0, 5, 47, - 0, 0, 8, 0, 99, 160, 0, 88, 144, 0, 77, 129, 0, 66, 112, - 0, 54, 97, 0, 41, 80, 0, 26, 62, 0, 5, 40, 0, 0, 0, - 0, 99, 147, 0, 87, 132, 0, 78, 117, 0, 66, 102, 0, 54, 87, - 0, 42, 72, 0, 26, 55, 0, 5, 34, 0, 0, 0, 0, 99, 134, - 0, 88, 119, 0, 77, 107, 0, 66, 92, 0, 54, 78, 0, 42, 64, - 0, 27, 48, 0, 5, 27, 0, 0, 0, 0, 99, 120, 0, 87, 107, - 0, 78, 94, 0, 66, 81, 0, 54, 68, 0, 42, 55, 0, 27, 40, - 0, 6, 20, 0, 0, 0, 0, 98, 105, 0, 87, 94, 0, 77, 84, - 0, 65, 71, 0, 55, 59, 0, 42, 47, 0, 28, 33, 0, 6, 12, - 0, 0, 0, 0, 98, 93, 0, 87, 81, 0, 77, 72, 0, 66, 61, - 0, 54, 49, 0, 42, 37, 0, 28, 24, 0, 6, 4, 0, 0, 0, - 0, 98, 77, 0, 87, 68, 0, 77, 59, 0, 65, 49, 0, 54, 39, - 0, 42, 27, 0, 29, 14, 0, 6, 0, 0, 0, 0, 1, 98, 65, - 7, 87, 56, 0, 77, 49, 0, 66, 41, 0, 54, 30, 0, 42, 19, - 0, 29, 3, 0, 6, 0, 0, 0, 0, 0, 84, 166, 0, 74, 149, - 0, 64, 134, 0, 53, 117, 0, 41, 100, 0, 28, 83, 0, 11, 64, - 0, 0, 42, 0, 0, 3, 0, 84, 151, 0, 74, 135, 0, 64, 121, - 0, 53, 105, 0, 42, 90, 0, 30, 75, 0, 14, 58, 0, 0, 36, - 0, 0, 0, 0, 84, 138, 0, 74, 124, 1, 64, 110, 0, 54, 95, - 0, 43, 81, 0, 30, 67, 0, 15, 51, 0, 1, 29, 0, 0, 0, - 14, 84, 126, 12, 74, 112, 2, 65, 99, 0, 54, 85, 0, 44, 73, - 0, 31, 59, 0, 16, 44, 0, 1, 23, 0, 0, 0, 16, 84, 113, - 13, 74, 100, 6, 65, 89, 0, 54, 77, 0, 44, 65, 0, 31, 51, - 0, 17, 36, 0, 1, 16, 0, 0, 0, 24, 84, 100, 18, 74, 88, - 13, 65, 78, 2, 55, 68, 0, 44, 55, 0, 32, 43, 0, 18, 28, - 0, 1, 6, 0, 0, 0, 26, 84, 87, 24, 74, 76, 17, 65, 67, - 7, 54, 57, 0, 44, 46, 0, 32, 35, 0, 19, 21, 0, 2, 3, - 0, 0, 0, 30, 84, 74, 28, 74, 64, 20, 65, 55, 12, 55, 46, - 0, 44, 35, 0, 32, 24, 0, 18, 9, 0, 1, 0, 0, 0, 0, - 32, 84, 63, 28, 74, 54, 21, 65, 47, 13, 54, 38, 0, 44, 28, - 0, 32, 16, 0, 18, 1, 0, 1, 0, 0, 0, 0, 30, 67, 155, - 20, 58, 139, 20, 49, 126, 12, 39, 110, 0, 27, 94, 0, 13, 77, - 0, 0, 60, 0, 0, 37, 0, 0, 0, 35, 67, 142, 30, 58, 126, - 23, 50, 114, 16, 40, 99, 7, 29, 85, 0, 15, 69, 0, 0, 52, - 0, 0, 30, 0, 0, 0, 35, 68, 131, 30, 59, 116, 27, 50, 104, - 18, 40, 90, 9, 29, 76, 0, 17, 62, 0, 2, 46, 0, 0, 24, - 0, 0, 0, 37, 69, 119, 33, 59, 106, 27, 51, 94, 21, 41, 80, - 9, 30, 67, 0, 18, 54, 0, 3, 39, 0, 0, 18, 0, 0, 0, - 40, 69, 107, 36, 59, 94, 28, 51, 84, 18, 41, 72, 10, 31, 60, - 0, 19, 47, 0, 4, 32, 0, 0, 10, 0, 0, 0, 42, 69, 95, - 36, 59, 84, 29, 51, 74, 19, 41, 63, 10, 31, 52, 0, 20, 39, - 0, 4, 25, 0, 0, 4, 0, 0, 0, 43, 69, 83, 38, 60, 73, - 32, 51, 62, 23, 42, 53, 11, 31, 42, 0, 20, 31, 0, 5, 17, - 0, 0, 1, 0, 0, 0, 45, 69, 70, 39, 60, 60, 33, 51, 52, - 24, 42, 43, 13, 32, 33, 0, 21, 21, 0, 5, 6, 0, 0, 0, - 0, 0, 0, 47, 69, 59, 41, 60, 51, 34, 51, 43, 24, 42, 35, - 12, 33, 26, 1, 22, 14, 0, 5, 1, 0, 0, 0, 0, 0, 0, - 46, 48, 146, 42, 40, 131, 36, 32, 118, 27, 22, 103, 17, 6, 88, - 5, 0, 73, 0, 0, 55, 0, 0, 33, 0, 0, 0, 48, 48, 133, - 44, 40, 119, 37, 32, 107, 28, 22, 93, 20, 8, 79, 7, 0, 65, - 0, 0, 49, 0, 0, 27, 0, 0, 0, 48, 50, 123, 44, 41, 109, - 37, 33, 97, 30, 23, 83, 21, 11, 71, 8, 0, 58, 0, 0, 42, - 0, 0, 21, 0, 0, 0, 49, 51, 111, 45, 42, 99, 38, 34, 87, - 29, 25, 75, 20, 13, 63, 8, 0, 51, 0, 0, 36, 0, 0, 14, - 0, 0, 0, 52, 52, 100, 44, 43, 89, 38, 35, 79, 29, 26, 68, - 19, 15, 56, 10, 1, 43, 0, 0, 28, 0, 0, 6, 0, 0, 0, - 52, 52, 90, 47, 44, 79, 39, 36, 70, 30, 27, 59, 20, 16, 47, - 9, 2, 36, 0, 0, 22, 0, 0, 2, 0, 0, 0, 52, 53, 78, - 46, 44, 68, 39, 37, 60, 32, 27, 49, 22, 17, 39, 10, 3, 28, - 0, 0, 12, 0, 0, 0, 0, 0, 0, 53, 53, 66, 47, 44, 57, - 40, 36, 48, 32, 27, 39, 22, 18, 30, 9, 4, 18, 0, 0, 3, - 0, 0, 0, 0, 0, 0, 54, 53, 57, 48, 45, 49, 41, 37, 41, - 33, 28, 32, 22, 19, 23, 11, 6, 10, 1, 0, 0, 0, 0, 0, - 0, 0, 0, -}; - -void AdobeCMYK_to_sRGB1(uint8_t c, - uint8_t m, - uint8_t y, - uint8_t k, - uint8_t& R, - uint8_t& G, - uint8_t& B) { - int fix_c = c << 8; - int fix_m = m << 8; - int fix_y = y << 8; - int fix_k = k << 8; - int c_index = (fix_c + 4096) >> 13; - int m_index = (fix_m + 4096) >> 13; - int y_index = (fix_y + 4096) >> 13; - int k_index = (fix_k + 4096) >> 13; - int pos = (c_index * 9 * 9 * 9 + m_index * 9 * 9 + y_index * 9 + k_index) * 3; - int fix_r = g_CMYKSamples[pos] << 8; - int fix_g = g_CMYKSamples[pos + 1] << 8; - int fix_b = g_CMYKSamples[pos + 2] << 8; - int c1_index = fix_c >> 13; - if (c1_index == c_index) { - c1_index = c1_index == 8 ? c1_index - 1 : c1_index + 1; - } - int m1_index = fix_m >> 13; - if (m1_index == m_index) { - m1_index = m1_index == 8 ? m1_index - 1 : m1_index + 1; - } - int y1_index = fix_y >> 13; - if (y1_index == y_index) { - y1_index = y1_index == 8 ? y1_index - 1 : y1_index + 1; - } - int k1_index = fix_k >> 13; - if (k1_index == k_index) { - k1_index = k1_index == 8 ? k1_index - 1 : k1_index + 1; - } - int c1_pos = pos + (c1_index - c_index) * 9 * 9 * 9 * 3; - int m1_pos = pos + (m1_index - m_index) * 9 * 9 * 3; - int y1_pos = pos + (y1_index - y_index) * 9 * 3; - int k1_pos = pos + (k1_index - k_index) * 3; - int c_r_delta = g_CMYKSamples[pos] - g_CMYKSamples[c1_pos]; - int c_g_delta = g_CMYKSamples[pos + 1] - g_CMYKSamples[c1_pos + 1]; - int c_b_delta = g_CMYKSamples[pos + 2] - g_CMYKSamples[c1_pos + 2]; - int m_r_delta = g_CMYKSamples[pos] - g_CMYKSamples[m1_pos]; - int m_g_delta = g_CMYKSamples[pos + 1] - g_CMYKSamples[m1_pos + 1]; - int m_b_delta = g_CMYKSamples[pos + 2] - g_CMYKSamples[m1_pos + 2]; - int y_r_delta = g_CMYKSamples[pos] - g_CMYKSamples[y1_pos]; - int y_g_delta = g_CMYKSamples[pos + 1] - g_CMYKSamples[y1_pos + 1]; - int y_b_delta = g_CMYKSamples[pos + 2] - g_CMYKSamples[y1_pos + 2]; - int k_r_delta = g_CMYKSamples[pos] - g_CMYKSamples[k1_pos]; - int k_g_delta = g_CMYKSamples[pos + 1] - g_CMYKSamples[k1_pos + 1]; - int k_b_delta = g_CMYKSamples[pos + 2] - g_CMYKSamples[k1_pos + 2]; - int c_rate = (fix_c - (c_index << 13)) * (c_index - c1_index); - fix_r += c_r_delta * c_rate / 32; - fix_g += c_g_delta * c_rate / 32; - fix_b += c_b_delta * c_rate / 32; - int m_rate = (fix_m - (m_index << 13)) * (m_index - m1_index); - fix_r += m_r_delta * m_rate / 32; - fix_g += m_g_delta * m_rate / 32; - fix_b += m_b_delta * m_rate / 32; - int y_rate = (fix_y - (y_index << 13)) * (y_index - y1_index); - fix_r += y_r_delta * y_rate / 32; - fix_g += y_g_delta * y_rate / 32; - fix_b += y_b_delta * y_rate / 32; - int k_rate = (fix_k - (k_index << 13)) * (k_index - k1_index); - fix_r += k_r_delta * k_rate / 32; - fix_g += k_g_delta * k_rate / 32; - fix_b += k_b_delta * k_rate / 32; - if (fix_r < 0) { - fix_r = 0; - } - if (fix_g < 0) { - fix_g = 0; - } - if (fix_b < 0) { - fix_b = 0; - } - R = fix_r >> 8; - G = fix_g >> 8; - B = fix_b >> 8; -} -void AdobeCMYK_to_sRGB(float c, - float m, - float y, - float k, - float& R, - float& G, - float& B) { - // Convert to uint8_t with round-to-nearest. Avoid using FXSYS_round because - // it is incredibly expensive with VC++ (tested on VC++ 2015) because round() - // is very expensive. - // The 'magic' value of 0.49999997f, the float that precedes 0.5f, was chosen - // because it gives identical results to FXSYS_round(). Using the constant - // 0.5f gives different results (1 instead of 0) for one value, 0.0019607842. - // That value is close to the cusp but zero is the correct answer, and - // getting the same answer as before is desirable. - // All floats from 0.0 to 1.0 were tested and now give the same results. - const float rounding_offset = 0.49999997f; - uint8_t c1 = int(c * 255.f + rounding_offset); - uint8_t m1 = int(m * 255.f + rounding_offset); - uint8_t y1 = int(y * 255.f + rounding_offset); - uint8_t k1 = int(k * 255.f + rounding_offset); - - ASSERT(c1 == FXSYS_round(c * 255)); - ASSERT(m1 == FXSYS_round(m * 255)); - ASSERT(y1 == FXSYS_round(y * 255)); - ASSERT(k1 == FXSYS_round(k * 255)); - - uint8_t r, g, b; - AdobeCMYK_to_sRGB1(c1, m1, y1, k1, r, g, b); - // Multiply by a constant rather than dividing because division is much - // more expensive. - R = r * (1.0f / 255); - G = g * (1.0f / 255); - B = b * (1.0f / 255); + if (pTransform) + cmsDoTransform(pTransform->m_hTransform, pSrc, pDest, pixels); } diff --git a/chromium/third_party/pdfium/core/fxcodec/codec/fx_codec_jbig.cpp b/chromium/third_party/pdfium/core/fxcodec/codec/fx_codec_jbig.cpp index 7df87e981fc..4c545c3c3a4 100644 --- a/chromium/third_party/pdfium/core/fxcodec/codec/fx_codec_jbig.cpp +++ b/chromium/third_party/pdfium/core/fxcodec/codec/fx_codec_jbig.cpp @@ -33,8 +33,7 @@ CCodec_Jbig2Context::CCodec_Jbig2Context() m_pGlobalStream(nullptr), m_pSrcStream(nullptr), m_dest_buf(0), - m_dest_pitch(0), - m_pPause(nullptr) {} + m_dest_pitch(0) {} CCodec_Jbig2Context::~CCodec_Jbig2Context() {} @@ -61,11 +60,10 @@ FXCODEC_STATUS CCodec_Jbig2Module::StartDecode( pJbig2Context->m_pGlobalStream = global_stream; pJbig2Context->m_dest_buf = dest_buf; pJbig2Context->m_dest_pitch = dest_pitch; - pJbig2Context->m_pPause = pPause; memset(dest_buf, 0, height * dest_pitch); pJbig2Context->m_pContext = pdfium::MakeUnique<CJBig2_Context>( global_stream, src_stream, pJBig2DocumentContext->GetSymbolDictCache(), - pPause, false); + false); int ret = pJbig2Context->m_pContext->getFirstPage(dest_buf, width, height, dest_pitch, pPause); return Decode(pJbig2Context, ret); diff --git a/chromium/third_party/pdfium/core/fxcodec/codec/fx_codec_jpeg.cpp b/chromium/third_party/pdfium/core/fxcodec/codec/fx_codec_jpeg.cpp index 2211e795222..521053a3747 100644 --- a/chromium/third_party/pdfium/core/fxcodec/codec/fx_codec_jpeg.cpp +++ b/chromium/third_party/pdfium/core/fxcodec/codec/fx_codec_jpeg.cpp @@ -9,7 +9,7 @@ #include <memory> #include <utility> -#include "core/fxcodec/codec/codec_int.h" +#include "core/fxcodec/codec/ccodec_jpegmodule.h" #include "core/fxcodec/fx_codec.h" #include "core/fxcrt/fx_safe_types.h" #include "core/fxge/dib/cfx_dibsource.h" @@ -26,7 +26,21 @@ extern "C" { #else #include "third_party/libjpeg/jpeglib.h" #endif -} +} // extern "C" + +class CJpegContext : public CCodec_JpegModule::Context { + public: + CJpegContext(); + ~CJpegContext() override; + + jmp_buf m_JumpMark; + jpeg_decompress_struct m_Info; + jpeg_error_mgr m_ErrMgr; + jpeg_source_mgr m_SrcMgr; + unsigned int m_SkipSize; + void* (*m_AllocFunc)(unsigned int); + void (*m_FreeFunc)(void*); +}; extern "C" { @@ -80,7 +94,7 @@ static boolean _dest_empty(j_compress_ptr cinfo) { return false; } #endif -}; +} // extern "C" #define JPEG_MARKER_ICC (JPEG_APP0 + 2) #define JPEG_MARKER_MAXSIZE 0xFFFF @@ -346,71 +360,75 @@ bool CCodec_JpegModule::LoadInfo(const uint8_t* src_buf, bits_per_components, color_transform); } -struct FXJPEG_Context { - jmp_buf m_JumpMark; - jpeg_decompress_struct m_Info; - jpeg_error_mgr m_ErrMgr; - jpeg_source_mgr m_SrcMgr; - unsigned int m_SkipSize; - void* (*m_AllocFunc)(unsigned int); - void (*m_FreeFunc)(void*); -}; extern "C" { + static void _error_fatal1(j_common_ptr cinfo) { - longjmp(((FXJPEG_Context*)cinfo->client_data)->m_JumpMark, -1); + auto* pContext = reinterpret_cast<CJpegContext*>(cinfo->client_data); + longjmp(pContext->m_JumpMark, -1); } -}; -extern "C" { + static void _src_skip_data1(struct jpeg_decompress_struct* cinfo, long num) { if (cinfo->src->bytes_in_buffer < (size_t)num) { - ((FXJPEG_Context*)cinfo->client_data)->m_SkipSize = - (unsigned int)(num - cinfo->src->bytes_in_buffer); + auto* pContext = reinterpret_cast<CJpegContext*>(cinfo->client_data); + pContext->m_SkipSize = (unsigned int)(num - cinfo->src->bytes_in_buffer); cinfo->src->bytes_in_buffer = 0; } else { cinfo->src->next_input_byte += num; cinfo->src->bytes_in_buffer -= num; } } -}; + static void* jpeg_alloc_func(unsigned int size) { return FX_Alloc(char, size); } + static void jpeg_free_func(void* p) { FX_Free(p); } -FXJPEG_Context* CCodec_JpegModule::Start() { - FXJPEG_Context* p = FX_Alloc(FXJPEG_Context, 1); - p->m_AllocFunc = jpeg_alloc_func; - p->m_FreeFunc = jpeg_free_func; - p->m_ErrMgr.error_exit = _error_fatal1; - p->m_ErrMgr.emit_message = _error_do_nothing1; - p->m_ErrMgr.output_message = _error_do_nothing; - p->m_ErrMgr.format_message = _error_do_nothing2; - p->m_ErrMgr.reset_error_mgr = _error_do_nothing; - p->m_SrcMgr.init_source = _src_do_nothing; - p->m_SrcMgr.term_source = _src_do_nothing; - p->m_SrcMgr.skip_input_data = _src_skip_data1; - p->m_SrcMgr.fill_input_buffer = _src_fill_buffer; - p->m_SrcMgr.resync_to_restart = _src_resync; - p->m_Info.client_data = p; - p->m_Info.err = &p->m_ErrMgr; - if (setjmp(p->m_JumpMark) == -1) { - return 0; - } - jpeg_create_decompress(&p->m_Info); - p->m_Info.src = &p->m_SrcMgr; - p->m_SkipSize = 0; - return p; + +} // extern "C" + +CJpegContext::CJpegContext() + : m_SkipSize(0), m_AllocFunc(jpeg_alloc_func), m_FreeFunc(jpeg_free_func) { + memset(&m_Info, 0, sizeof(m_Info)); + m_Info.client_data = this; + m_Info.err = &m_ErrMgr; + + memset(&m_ErrMgr, 0, sizeof(m_ErrMgr)); + m_ErrMgr.error_exit = _error_fatal1; + m_ErrMgr.emit_message = _error_do_nothing1; + m_ErrMgr.output_message = _error_do_nothing; + m_ErrMgr.format_message = _error_do_nothing2; + m_ErrMgr.reset_error_mgr = _error_do_nothing; + + memset(&m_SrcMgr, 0, sizeof(m_SrcMgr)); + m_SrcMgr.init_source = _src_do_nothing; + m_SrcMgr.term_source = _src_do_nothing; + m_SrcMgr.skip_input_data = _src_skip_data1; + m_SrcMgr.fill_input_buffer = _src_fill_buffer; + m_SrcMgr.resync_to_restart = _src_resync; } -void CCodec_JpegModule::Finish(FXJPEG_Context* ctx) { - jpeg_destroy_decompress(&ctx->m_Info); - ctx->m_FreeFunc(ctx); +CJpegContext::~CJpegContext() { + jpeg_destroy_decompress(&m_Info); +} + +std::unique_ptr<CCodec_JpegModule::Context> CCodec_JpegModule::Start() { + // Use ordinary pointer until past the fear of a longjump. + auto* pContext = new CJpegContext(); + if (setjmp(pContext->m_JumpMark) == -1) + return nullptr; + + jpeg_create_decompress(&pContext->m_Info); + pContext->m_Info.src = &pContext->m_SrcMgr; + pContext->m_SkipSize = 0; + return pdfium::WrapUnique(pContext); } -void CCodec_JpegModule::Input(FXJPEG_Context* ctx, +void CCodec_JpegModule::Input(Context* pContext, const unsigned char* src_buf, uint32_t src_size) { + auto* ctx = static_cast<CJpegContext*>(pContext); if (ctx->m_SkipSize) { if (ctx->m_SkipSize > src_size) { ctx->m_SrcMgr.bytes_in_buffer = 0; @@ -426,17 +444,18 @@ void CCodec_JpegModule::Input(FXJPEG_Context* ctx, } #ifdef PDF_ENABLE_XFA -int CCodec_JpegModule::ReadHeader(FXJPEG_Context* ctx, +int CCodec_JpegModule::ReadHeader(Context* pContext, int* width, int* height, int* nComps, CFX_DIBAttribute* pAttribute) { #else // PDF_ENABLE_XFA -int CCodec_JpegModule::ReadHeader(FXJPEG_Context* ctx, +int CCodec_JpegModule::ReadHeader(Context* pContext, int* width, int* height, int* nComps) { #endif // PDF_ENABLE_XFA + auto* ctx = static_cast<CJpegContext*>(pContext); if (setjmp(ctx->m_JumpMark) == -1) return 1; @@ -455,7 +474,8 @@ int CCodec_JpegModule::ReadHeader(FXJPEG_Context* ctx, return 0; } -bool CCodec_JpegModule::StartScanline(FXJPEG_Context* ctx, int down_scale) { +bool CCodec_JpegModule::StartScanline(Context* pContext, int down_scale) { + auto* ctx = static_cast<CJpegContext*>(pContext); if (setjmp(ctx->m_JumpMark) == -1) return false; @@ -463,8 +483,9 @@ bool CCodec_JpegModule::StartScanline(FXJPEG_Context* ctx, int down_scale) { return !!jpeg_start_decompress(&ctx->m_Info); } -bool CCodec_JpegModule::ReadScanline(FXJPEG_Context* ctx, +bool CCodec_JpegModule::ReadScanline(Context* pContext, unsigned char* dest_buf) { + auto* ctx = static_cast<CJpegContext*>(pContext); if (setjmp(ctx->m_JumpMark) == -1) return false; @@ -472,8 +493,9 @@ bool CCodec_JpegModule::ReadScanline(FXJPEG_Context* ctx, return nlines == 1; } -uint32_t CCodec_JpegModule::GetAvailInput(FXJPEG_Context* ctx, +uint32_t CCodec_JpegModule::GetAvailInput(Context* pContext, uint8_t** avail_buf_ptr) { + auto* ctx = static_cast<CJpegContext*>(pContext); if (avail_buf_ptr) { *avail_buf_ptr = nullptr; if (ctx->m_SrcMgr.bytes_in_buffer > 0) { diff --git a/chromium/third_party/pdfium/core/fxcodec/codec/fx_codec_jpx_opj.cpp b/chromium/third_party/pdfium/core/fxcodec/codec/fx_codec_jpx_opj.cpp index 96270251645..32c808fa8ea 100644 --- a/chromium/third_party/pdfium/core/fxcodec/codec/fx_codec_jpx_opj.cpp +++ b/chromium/third_party/pdfium/core/fxcodec/codec/fx_codec_jpx_opj.cpp @@ -14,9 +14,11 @@ #include "core/fxcodec/codec/cjpx_decoder.h" #include "core/fxcodec/codec/codec_int.h" #include "core/fxcodec/fx_codec.h" +#include "core/fxcrt/fx_memory.h" #include "core/fxcrt/fx_safe_types.h" #include "third_party/base/ptr_util.h" #include "third_party/libopenjpeg20/openjpeg.h" +#include "third_party/libopenjpeg20/opj_malloc.h" #if defined(USE_SYSTEM_LCMS2) #include <lcms2.h> @@ -27,9 +29,11 @@ static void fx_error_callback(const char* msg, void* client_data) { (void)client_data; } + static void fx_warning_callback(const char* msg, void* client_data) { (void)client_data; } + static void fx_info_callback(const char* msg, void* client_data) { (void)client_data; } @@ -38,13 +42,13 @@ OPJ_SIZE_T opj_read_from_memory(void* p_buffer, OPJ_SIZE_T nb_bytes, void* p_user_data) { DecodeData* srcData = static_cast<DecodeData*>(p_user_data); - if (!srcData || !srcData->src_data || srcData->src_size == 0) { + if (!srcData || !srcData->src_data || srcData->src_size == 0) return static_cast<OPJ_SIZE_T>(-1); - } + // Reads at EOF return an error code. - if (srcData->offset >= srcData->src_size) { + if (srcData->offset >= srcData->src_size) return static_cast<OPJ_SIZE_T>(-1); - } + OPJ_SIZE_T bufferLength = srcData->src_size - srcData->offset; OPJ_SIZE_T readlength = nb_bytes < bufferLength ? nb_bytes : bufferLength; memcpy(p_buffer, &srcData->src_data[srcData->offset], readlength); @@ -54,16 +58,16 @@ OPJ_SIZE_T opj_read_from_memory(void* p_buffer, OPJ_OFF_T opj_skip_from_memory(OPJ_OFF_T nb_bytes, void* p_user_data) { DecodeData* srcData = static_cast<DecodeData*>(p_user_data); - if (!srcData || !srcData->src_data || srcData->src_size == 0) { + if (!srcData || !srcData->src_data || srcData->src_size == 0) return static_cast<OPJ_OFF_T>(-1); - } + // Offsets are signed and may indicate a negative skip. Do not support this // because of the strange return convention where either bytes skipped or // -1 is returned. Following that convention, a successful relative seek of // -1 bytes would be required to to give the same result as the error case. - if (nb_bytes < 0) { + if (nb_bytes < 0) return static_cast<OPJ_OFF_T>(-1); - } + // FIXME: use std::make_unsigned<OPJ_OFF_T>::type once c++11 lib is OK'd. uint64_t unsignedNbBytes = static_cast<uint64_t>(nb_bytes); // Additionally, the offset may take us beyond the range of a size_t (e.g. @@ -86,14 +90,14 @@ OPJ_OFF_T opj_skip_from_memory(OPJ_OFF_T nb_bytes, void* p_user_data) { OPJ_BOOL opj_seek_from_memory(OPJ_OFF_T nb_bytes, void* p_user_data) { DecodeData* srcData = static_cast<DecodeData*>(p_user_data); - if (!srcData || !srcData->src_data || srcData->src_size == 0) { + if (!srcData || !srcData->src_data || srcData->src_size == 0) return OPJ_FALSE; - } + // Offsets are signed and may indicate a negative position, which would // be before the start of the file. Do not support this. - if (nb_bytes < 0) { + if (nb_bytes < 0) return OPJ_FALSE; - } + // FIXME: use std::make_unsigned<OPJ_OFF_T>::type once c++11 lib is OK'd. uint64_t unsignedNbBytes = static_cast<uint64_t>(nb_bytes); // Additionally, the offset may take us beyond the range of a size_t (e.g. @@ -108,24 +112,26 @@ OPJ_BOOL opj_seek_from_memory(OPJ_OFF_T nb_bytes, void* p_user_data) { } return OPJ_TRUE; } -opj_stream_t* fx_opj_stream_create_memory_stream(DecodeData* data, - OPJ_SIZE_T p_size, - OPJ_BOOL p_is_read_stream) { - opj_stream_t* l_stream = 00; - if (!data || !data->src_data || data->src_size <= 0) { + +static opj_stream_t* fx_opj_stream_create_memory_stream( + DecodeData* data, + OPJ_SIZE_T p_size, + OPJ_BOOL p_is_read_stream) { + if (!data || !data->src_data || data->src_size <= 0) return nullptr; - } - l_stream = opj_stream_create(p_size, p_is_read_stream); - if (!l_stream) { + + opj_stream_t* stream = opj_stream_create(p_size, p_is_read_stream); + if (!stream) return nullptr; - } - opj_stream_set_user_data(l_stream, data, nullptr); - opj_stream_set_user_data_length(l_stream, data->src_size); - opj_stream_set_read_function(l_stream, opj_read_from_memory); - opj_stream_set_skip_function(l_stream, opj_skip_from_memory); - opj_stream_set_seek_function(l_stream, opj_seek_from_memory); - return l_stream; + + opj_stream_set_user_data(stream, data, nullptr); + opj_stream_set_user_data_length(stream, data->src_size); + opj_stream_set_read_function(stream, opj_read_from_memory); + opj_stream_set_skip_function(stream, opj_skip_from_memory); + opj_stream_set_seek_function(stream, opj_seek_from_memory); + return stream; } + static void sycc_to_rgb(int offset, int upb, int y, @@ -162,6 +168,9 @@ static void sycc_to_rgb(int offset, static void sycc444_to_rgb(opj_image_t* img) { int prec = img->comps[0].prec; + // If we shift 31 we're going to go negative, then things go bad. + if (prec > 30) + return; int offset = 1 << (prec - 1); int upb = (1 << prec) - 1; OPJ_UINT32 maxw = @@ -179,9 +188,9 @@ static void sycc444_to_rgb(opj_image_t* img) { if (!y || !cb || !cr) return; - int* r = FX_Alloc(int, max_size.ValueOrDie()); - int* g = FX_Alloc(int, max_size.ValueOrDie()); - int* b = FX_Alloc(int, max_size.ValueOrDie()); + int* r = static_cast<int*>(opj_calloc(max_size.ValueOrDie(), sizeof(int))); + int* g = static_cast<int*>(opj_calloc(max_size.ValueOrDie(), sizeof(int))); + int* b = static_cast<int*>(opj_calloc(max_size.ValueOrDie(), sizeof(int))); int* d0 = r; int* d1 = g; int* d2 = b; @@ -194,9 +203,9 @@ static void sycc444_to_rgb(opj_image_t* img) { ++g; ++b; } - FX_Free(img->comps[0].data); - FX_Free(img->comps[1].data); - FX_Free(img->comps[2].data); + opj_free(img->comps[0].data); + opj_free(img->comps[1].data); + opj_free(img->comps[2].data); img->comps[0].data = d0; img->comps[1].data = d1; img->comps[2].data = d2; @@ -208,14 +217,17 @@ static bool sycc420_422_size_is_valid(opj_image_t* img) { img->comps[1].w == img->comps[2].w && img->comps[1].h == img->comps[2].h); } + static bool sycc420_size_is_valid(opj_image_t* img) { return (sycc420_422_size_is_valid(img) && img->comps[0].h != std::numeric_limits<OPJ_UINT32>::max() && (img->comps[0].h + 1) / 2 == img->comps[1].h); } + static bool sycc422_size_is_valid(opj_image_t* img) { return (sycc420_422_size_is_valid(img) && img->comps[0].h == img->comps[1].h); } + static void sycc422_to_rgb(opj_image_t* img) { if (!sycc422_size_is_valid(img)) return; @@ -226,7 +238,6 @@ static void sycc422_to_rgb(opj_image_t* img) { int offset = 1 << (prec - 1); int upb = (1 << prec) - 1; - OPJ_UINT32 maxw = img->comps[0].w; OPJ_UINT32 maxh = img->comps[0].h; FX_SAFE_SIZE_T max_size = maxw; @@ -240,10 +251,12 @@ static void sycc422_to_rgb(opj_image_t* img) { if (!y || !cb || !cr) return; - int *d0, *d1, *d2, *r, *g, *b; - d0 = r = FX_Alloc(int, max_size.ValueOrDie()); - d1 = g = FX_Alloc(int, max_size.ValueOrDie()); - d2 = b = FX_Alloc(int, max_size.ValueOrDie()); + int* r = static_cast<int*>(opj_calloc(max_size.ValueOrDie(), sizeof(int))); + int* g = static_cast<int*>(opj_calloc(max_size.ValueOrDie(), sizeof(int))); + int* b = static_cast<int*>(opj_calloc(max_size.ValueOrDie(), sizeof(int))); + int* d0 = r; + int* d1 = g; + int* d2 = b; for (uint32_t i = 0; i < maxh; ++i) { OPJ_UINT32 j; for (j = 0; j < (maxw & ~static_cast<OPJ_UINT32>(1)); j += 2) { @@ -270,11 +283,11 @@ static void sycc422_to_rgb(opj_image_t* img) { ++cr; } } - FX_Free(img->comps[0].data); + opj_free(img->comps[0].data); + opj_free(img->comps[1].data); + opj_free(img->comps[2].data); img->comps[0].data = d0; - FX_Free(img->comps[1].data); img->comps[1].data = d1; - FX_Free(img->comps[2].data); img->comps[2].data = d2; img->comps[1].w = maxw; img->comps[1].h = maxh; @@ -285,9 +298,11 @@ static void sycc422_to_rgb(opj_image_t* img) { img->comps[1].dy = img->comps[0].dy; img->comps[2].dy = img->comps[0].dy; } + static bool sycc420_must_extend_cbcr(OPJ_UINT32 y, OPJ_UINT32 cbcr) { return (y & 1) && (cbcr == y / 2); } + void sycc420_to_rgb(opj_image_t* img) { if (!sycc420_size_is_valid(img)) return; @@ -295,6 +310,7 @@ void sycc420_to_rgb(opj_image_t* img) { OPJ_UINT32 prec = img->comps[0].prec; if (!prec) return; + OPJ_UINT32 offset = 1 << (prec - 1); OPJ_UINT32 upb = (1 << prec) - 1; OPJ_UINT32 yw = img->comps[0].w; @@ -308,9 +324,10 @@ void sycc420_to_rgb(opj_image_t* img) { safeSize *= yh; if (!safeSize.IsValid()) return; - int* r = FX_Alloc(int, safeSize.ValueOrDie()); - int* g = FX_Alloc(int, safeSize.ValueOrDie()); - int* b = FX_Alloc(int, safeSize.ValueOrDie()); + + int* r = static_cast<int*>(opj_calloc(safeSize.ValueOrDie(), sizeof(int))); + int* g = static_cast<int*>(opj_calloc(safeSize.ValueOrDie(), sizeof(int))); + int* b = static_cast<int*>(opj_calloc(safeSize.ValueOrDie(), sizeof(int))); int* d0 = r; int* d1 = g; int* d2 = b; @@ -406,11 +423,11 @@ void sycc420_to_rgb(opj_image_t* img) { } } - FX_Free(img->comps[0].data); + opj_free(img->comps[0].data); + opj_free(img->comps[1].data); + opj_free(img->comps[2].data); img->comps[0].data = d0; - FX_Free(img->comps[1].data); img->comps[1].data = d1; - FX_Free(img->comps[2].data); img->comps[2].data = d2; img->comps[1].w = yw; img->comps[1].h = yh; @@ -425,7 +442,8 @@ void sycc420_to_rgb(opj_image_t* img) { img->comps[1].dy = img->comps[0].dy; img->comps[2].dy = img->comps[0].dy; } -void color_sycc_to_rgb(opj_image_t* img) { + +static void color_sycc_to_rgb(opj_image_t* img) { if (img->numcomps < 3) { img->color_space = OPJ_CLRSPC_GRAY; return; @@ -447,250 +465,17 @@ void color_sycc_to_rgb(opj_image_t* img) { } img->color_space = OPJ_CLRSPC_SRGB; } -void color_apply_icc_profile(opj_image_t* image) { - cmsHPROFILE out_prof; - cmsUInt32Number in_type; - cmsUInt32Number out_type; - int* r; - int* g; - int* b; - int max; - cmsHPROFILE in_prof = - cmsOpenProfileFromMem(image->icc_profile_buf, image->icc_profile_len); - if (!in_prof) { - return; - } - cmsColorSpaceSignature out_space = cmsGetColorSpace(in_prof); - cmsUInt32Number intent = cmsGetHeaderRenderingIntent(in_prof); - int max_w = (int)image->comps[0].w; - int max_h = (int)image->comps[0].h; - int prec = (int)image->comps[0].prec; - OPJ_COLOR_SPACE oldspace = image->color_space; - if (out_space == cmsSigRgbData) { - if (prec <= 8) { - in_type = TYPE_RGB_8; - out_type = TYPE_RGB_8; - } else { - in_type = TYPE_RGB_16; - out_type = TYPE_RGB_16; - } - out_prof = cmsCreate_sRGBProfile(); - image->color_space = OPJ_CLRSPC_SRGB; - } else if (out_space == cmsSigGrayData) { - if (prec <= 8) { - in_type = TYPE_GRAY_8; - out_type = TYPE_RGB_8; - } else { - in_type = TYPE_GRAY_16; - out_type = TYPE_RGB_16; - } - out_prof = cmsCreate_sRGBProfile(); - image->color_space = OPJ_CLRSPC_SRGB; - } else if (out_space == cmsSigYCbCrData) { - in_type = TYPE_YCbCr_16; - out_type = TYPE_RGB_16; - out_prof = cmsCreate_sRGBProfile(); - image->color_space = OPJ_CLRSPC_SRGB; - } else { - return; - } - cmsHTRANSFORM transform = - cmsCreateTransform(in_prof, in_type, out_prof, out_type, intent, 0); - cmsCloseProfile(in_prof); - cmsCloseProfile(out_prof); - if (!transform) { - image->color_space = oldspace; - return; - } - if (image->numcomps > 2) { - if (prec <= 8) { - unsigned char *inbuf, *outbuf, *in, *out; - max = max_w * max_h; - cmsUInt32Number nr_samples = max * 3 * sizeof(unsigned char); - in = inbuf = FX_Alloc(unsigned char, nr_samples); - out = outbuf = FX_Alloc(unsigned char, nr_samples); - r = image->comps[0].data; - g = image->comps[1].data; - b = image->comps[2].data; - for (int i = 0; i < max; ++i) { - *in++ = (unsigned char)*r++; - *in++ = (unsigned char)*g++; - *in++ = (unsigned char)*b++; - } - cmsDoTransform(transform, inbuf, outbuf, (cmsUInt32Number)max); - r = image->comps[0].data; - g = image->comps[1].data; - b = image->comps[2].data; - for (int i = 0; i < max; ++i) { - *r++ = (int)*out++; - *g++ = (int)*out++; - *b++ = (int)*out++; - } - FX_Free(inbuf); - FX_Free(outbuf); - } else { - unsigned short *inbuf, *outbuf, *in, *out; - max = max_w * max_h; - cmsUInt32Number nr_samples = max * 3 * sizeof(unsigned short); - in = inbuf = FX_Alloc(unsigned short, nr_samples); - out = outbuf = FX_Alloc(unsigned short, nr_samples); - r = image->comps[0].data; - g = image->comps[1].data; - b = image->comps[2].data; - for (int i = 0; i < max; ++i) { - *in++ = (unsigned short)*r++; - *in++ = (unsigned short)*g++; - *in++ = (unsigned short)*b++; - } - cmsDoTransform(transform, inbuf, outbuf, (cmsUInt32Number)max); - r = image->comps[0].data; - g = image->comps[1].data; - b = image->comps[2].data; - for (int i = 0; i < max; ++i) { - *r++ = (int)*out++; - *g++ = (int)*out++; - *b++ = (int)*out++; - } - FX_Free(inbuf); - FX_Free(outbuf); - } - } else { - unsigned char *in, *inbuf, *out, *outbuf; - max = max_w * max_h; - cmsUInt32Number nr_samples = - (cmsUInt32Number)max * 3 * sizeof(unsigned char); - in = inbuf = FX_Alloc(unsigned char, nr_samples); - out = outbuf = FX_Alloc(unsigned char, nr_samples); - image->comps = (opj_image_comp_t*)realloc( - image->comps, (image->numcomps + 2) * sizeof(opj_image_comp_t)); - if (image->numcomps == 2) { - image->comps[3] = image->comps[1]; - } - image->comps[1] = image->comps[0]; - image->comps[2] = image->comps[0]; - image->comps[1].data = FX_Alloc(int, (size_t)max); - memset(image->comps[1].data, 0, sizeof(int) * (size_t)max); - image->comps[2].data = FX_Alloc(int, (size_t)max); - memset(image->comps[2].data, 0, sizeof(int) * (size_t)max); - image->numcomps += 2; - r = image->comps[0].data; - for (int i = 0; i < max; ++i) { - *in++ = (unsigned char)*r++; - } - cmsDoTransform(transform, inbuf, outbuf, (cmsUInt32Number)max); - r = image->comps[0].data; - g = image->comps[1].data; - b = image->comps[2].data; - for (int i = 0; i < max; ++i) { - *r++ = (int)*out++; - *g++ = (int)*out++; - *b++ = (int)*out++; - } - FX_Free(inbuf); - FX_Free(outbuf); - } - cmsDeleteTransform(transform); -} -void color_apply_conversion(opj_image_t* image) { - int* row; - int enumcs, numcomps; - numcomps = image->numcomps; - if (numcomps < 3) { - return; - } - row = (int*)image->icc_profile_buf; - enumcs = row[0]; - if (enumcs == 14) { - int *L, *a, *b, *red, *green, *blue, *src0, *src1, *src2; - double rl, ol, ra, oa, rb, ob, prec0, prec1, prec2; - double minL, maxL, mina, maxa, minb, maxb; - unsigned int default_type; - unsigned int i, max; - cmsHPROFILE in, out; - cmsHTRANSFORM transform; - cmsUInt16Number RGB[3]; - cmsCIELab Lab; - in = cmsCreateLab4Profile(nullptr); - out = cmsCreate_sRGBProfile(); - transform = cmsCreateTransform(in, TYPE_Lab_DBL, out, TYPE_RGB_16, - INTENT_PERCEPTUAL, 0); - cmsCloseProfile(in); - cmsCloseProfile(out); - if (!transform) { - return; - } - prec0 = (double)image->comps[0].prec; - prec1 = (double)image->comps[1].prec; - prec2 = (double)image->comps[2].prec; - default_type = row[1]; - if (default_type == 0x44454600) { - rl = 100; - ra = 170; - rb = 200; - ol = 0; - oa = pow(2, prec1 - 1); - ob = pow(2, prec2 - 2) + pow(2, prec2 - 3); - } else { - rl = row[2]; - ra = row[4]; - rb = row[6]; - ol = row[3]; - oa = row[5]; - ob = row[7]; - } - L = src0 = image->comps[0].data; - a = src1 = image->comps[1].data; - b = src2 = image->comps[2].data; - max = image->comps[0].w * image->comps[0].h; - red = FX_Alloc(int, max); - image->comps[0].data = red; - green = FX_Alloc(int, max); - image->comps[1].data = green; - blue = FX_Alloc(int, max); - image->comps[2].data = blue; - minL = -(rl * ol) / (pow(2, prec0) - 1); - maxL = minL + rl; - mina = -(ra * oa) / (pow(2, prec1) - 1); - maxa = mina + ra; - minb = -(rb * ob) / (pow(2, prec2) - 1); - maxb = minb + rb; - for (i = 0; i < max; ++i) { - Lab.L = minL + (double)(*L) * (maxL - minL) / (pow(2, prec0) - 1); - ++L; - Lab.a = mina + (double)(*a) * (maxa - mina) / (pow(2, prec1) - 1); - ++a; - Lab.b = minb + (double)(*b) * (maxb - minb) / (pow(2, prec2) - 1); - ++b; - cmsDoTransform(transform, &Lab, RGB, 1); - *red++ = RGB[0]; - *green++ = RGB[1]; - *blue++ = RGB[2]; - } - cmsDeleteTransform(transform); - FX_Free(src0); - FX_Free(src1); - FX_Free(src2); - image->color_space = OPJ_CLRSPC_SRGB; - image->comps[0].prec = 16; - image->comps[1].prec = 16; - image->comps[2].prec = 16; - return; - } -} CJPX_Decoder::CJPX_Decoder(CPDF_ColorSpace* cs) : image(nullptr), l_codec(nullptr), l_stream(nullptr), m_ColorSpace(cs) {} CJPX_Decoder::~CJPX_Decoder() { - if (l_codec) { + if (l_codec) opj_destroy_codec(l_codec); - } - if (l_stream) { + if (l_stream) opj_stream_destroy(l_stream); - } - if (image) { + if (image) opj_image_destroy(image); - } } bool CJPX_Decoder::Init(const unsigned char* src_data, uint32_t src_size) { @@ -766,14 +551,14 @@ bool CJPX_Decoder::Init(const unsigned char* src_data, uint32_t src_size) { color_sycc_to_rgb(image); } if (image->icc_profile_buf) { - FX_Free(image->icc_profile_buf); + // TODO(palmer): Using |opj_free| here resolves the crash described in + // https://crbug.com/737033, but ultimately we need to harmonize the + // memory allocation strategy across OpenJPEG and its PDFium callers. + opj_free(image->icc_profile_buf); image->icc_profile_buf = nullptr; image->icc_profile_len = 0; } - if (!image) { - return false; - } - return true; + return !!image; } void CJPX_Decoder::GetInfo(uint32_t* width, diff --git a/chromium/third_party/pdfium/core/fxcodec/codec/fx_codec_jpx_unittest.cpp b/chromium/third_party/pdfium/core/fxcodec/codec/fx_codec_jpx_unittest.cpp index 2acb76c355d..cc5c8601b18 100644 --- a/chromium/third_party/pdfium/core/fxcodec/codec/fx_codec_jpx_unittest.cpp +++ b/chromium/third_party/pdfium/core/fxcodec/codec/fx_codec_jpx_unittest.cpp @@ -7,8 +7,8 @@ #include <limits> #include "core/fxcodec/codec/codec_int.h" -#include "testing/fx_string_testhelpers.h" #include "testing/gtest/include/gtest/gtest.h" +#include "third_party/libopenjpeg20/opj_malloc.h" static const OPJ_OFF_T kSkipError = static_cast<OPJ_OFF_T>(-1); static const OPJ_SIZE_T kReadError = static_cast<OPJ_SIZE_T>(-1); @@ -35,10 +35,10 @@ TEST(fxcodec, CMYK_Rounding) { // Iterate through floats by incrementing the representation, as discussed in // https://randomascii.wordpress.com/2012/01/23/stupid-float-tricks-2/ for (Float_t f = startValue; f.f < endValue; f.i++) { - AdobeCMYK_to_sRGB(f.f, f.f, f.f, f.f, R, G, B); + std::tie(R, G, B) = AdobeCMYK_to_sRGB(f.f, f.f, f.f, f.f); } // Check various other 'special' numbers. - AdobeCMYK_to_sRGB(0.0f, 0.25f, 0.5f, 1.0f, R, G, B); + std::tie(R, G, B) = AdobeCMYK_to_sRGB(0.0f, 0.25f, 0.5f, 1.0f); } TEST(fxcodec, DecodeDataNullDecodeData) { @@ -436,11 +436,11 @@ TEST(fxcodec, YUV420ToRGB) { y.h = y.w; img.x1 = y.w; img.y1 = y.h; - y.data = FX_Alloc(OPJ_INT32, y.w * y.h); + y.data = static_cast<OPJ_INT32*>(opj_calloc(y.w * y.h, sizeof(OPJ_INT32))); + v.data = static_cast<OPJ_INT32*>(opj_calloc(v.w * v.h, sizeof(OPJ_INT32))); + u.data = static_cast<OPJ_INT32*>(opj_calloc(u.w * u.h, sizeof(OPJ_INT32))); memset(y.data, 1, y.w * y.h * sizeof(OPJ_INT32)); - u.data = FX_Alloc(OPJ_INT32, u.w * u.h); memset(u.data, 0, u.w * u.h * sizeof(OPJ_INT32)); - v.data = FX_Alloc(OPJ_INT32, v.w * v.h); memset(v.data, 0, v.w * v.h * sizeof(OPJ_INT32)); img.comps[0] = y; img.comps[1] = u; @@ -457,9 +457,9 @@ TEST(fxcodec, YUV420ToRGB) { EXPECT_NE(img.comps[0].w, img.comps[2].w); EXPECT_NE(img.comps[0].h, img.comps[2].h); } - FX_Free(img.comps[0].data); - FX_Free(img.comps[1].data); - FX_Free(img.comps[2].data); + opj_free(img.comps[0].data); + opj_free(img.comps[1].data); + opj_free(img.comps[2].data); } FX_Free(img.comps); } diff --git a/chromium/third_party/pdfium/core/fxcodec/codec/fx_codec_progress.cpp b/chromium/third_party/pdfium/core/fxcodec/codec/fx_codec_progress.cpp index 9e470f3f143..905a957184d 100644 --- a/chromium/third_party/pdfium/core/fxcodec/codec/fx_codec_progress.cpp +++ b/chromium/third_party/pdfium/core/fxcodec/codec/fx_codec_progress.cpp @@ -8,6 +8,7 @@ #include <algorithm> #include <memory> +#include <vector> #include "core/fxcodec/fx_codec.h" #include "core/fxge/dib/cfx_dibitmap.h" @@ -294,15 +295,6 @@ CCodec_ProgressiveDecoder::CCodec_ProgressiveDecoder( } CCodec_ProgressiveDecoder::~CCodec_ProgressiveDecoder() { - m_pFile = nullptr; - if (m_pJpegContext) - m_pCodecMgr->GetJpegModule()->Finish(m_pJpegContext); - if (m_pBmpContext) - m_pCodecMgr->GetBmpModule()->Finish(m_pBmpContext); - if (m_pPngContext) - m_pCodecMgr->GetPngModule()->Finish(m_pPngContext); - if (m_pTiffContext) - m_pCodecMgr->GetTiffModule()->DestroyDecoder(m_pTiffContext); FX_Free(m_pSrcBuf); FX_Free(m_pDecodeBuf); FX_Free(m_pSrcPalette); @@ -315,7 +307,7 @@ bool CCodec_ProgressiveDecoder::JpegReadMoreData(CCodec_JpegModule* pJpegModule, return false; } dwSize = dwSize - m_offSet; - uint32_t dwAvail = pJpegModule->GetAvailInput(m_pJpegContext, nullptr); + uint32_t dwAvail = pJpegModule->GetAvailInput(m_pJpegContext.get(), nullptr); if (dwAvail == m_SrcSize) { if (dwSize > FXCODEC_BLOCK_SIZE) { dwSize = FXCODEC_BLOCK_SIZE; @@ -341,7 +333,7 @@ bool CCodec_ProgressiveDecoder::JpegReadMoreData(CCodec_JpegModule* pJpegModule, return false; } m_offSet += dwSize; - pJpegModule->Input(m_pJpegContext, m_pSrcBuf, dwSize + dwAvail); + pJpegModule->Input(m_pJpegContext.get(), m_pSrcBuf, dwSize + dwAvail); return true; } @@ -851,7 +843,7 @@ bool CCodec_ProgressiveDecoder::BmpReadMoreData(CCodec_BmpModule* pBmpModule, return false; dwSize = dwSize - m_offSet; - uint32_t dwAvail = pBmpModule->GetAvailInput(m_pBmpContext, nullptr); + uint32_t dwAvail = pBmpModule->GetAvailInput(m_pBmpContext.get(), nullptr); if (dwAvail == m_SrcSize) { if (dwSize > FXCODEC_BLOCK_SIZE) { dwSize = FXCODEC_BLOCK_SIZE; @@ -877,7 +869,7 @@ bool CCodec_ProgressiveDecoder::BmpReadMoreData(CCodec_BmpModule* pBmpModule, return false; } m_offSet += dwSize; - pBmpModule->Input(m_pBmpContext, m_pSrcBuf, dwSize + dwAvail); + pBmpModule->Input(m_pBmpContext.get(), m_pSrcBuf, dwSize + dwAvail); return true; } @@ -887,18 +879,21 @@ bool CCodec_ProgressiveDecoder::BmpInputImagePositionBuf(uint32_t rcd_pos) { return BmpReadMoreData(m_pCodecMgr->GetBmpModule(), error_status); } -void CCodec_ProgressiveDecoder::BmpReadScanline(int32_t row_num, - uint8_t* row_buf) { +void CCodec_ProgressiveDecoder::BmpReadScanline( + uint32_t row_num, + const std::vector<uint8_t>& row_buf) { CFX_RetainPtr<CFX_DIBitmap> pDIBitmap = m_pDeviceBitmap; ASSERT(pDIBitmap); - memcpy(m_pDecodeBuf, row_buf, m_ScanlineSize); + std::copy(row_buf.begin(), row_buf.begin() + m_ScanlineSize, m_pDecodeBuf); int src_top = m_clipBox.top; int src_bottom = m_clipBox.bottom; int des_top = m_startY; int src_hei = m_clipBox.Height(); int des_hei = m_sizeY; - if (row_num < src_top || row_num >= src_bottom) + if ((src_top >= 0 && row_num < static_cast<uint32_t>(src_top)) || + src_bottom < 0 || row_num >= static_cast<uint32_t>(src_bottom)) { return; + } double scale_y = (double)des_hei / (double)src_hei; int src_row = row_num - src_top; @@ -1020,23 +1015,24 @@ bool CCodec_ProgressiveDecoder::DetectImageType(FXCODEC_IMAGE_TYPE imageType, m_status = FXCODEC_STATUS_ERR_MEMORY; return false; } - pBmpModule->SetDelegate(this); - m_pBmpContext = pBmpModule->Start(); + + m_pBmpContext = pBmpModule->Start(this); if (!m_pBmpContext) { m_status = FXCODEC_STATUS_ERR_MEMORY; return false; } - bool bResult = m_pFile->ReadBlock(m_pSrcBuf, 0, size); - if (!bResult) { + + if (!m_pFile->ReadBlock(m_pSrcBuf, 0, size)) { m_status = FXCODEC_STATUS_ERR_READ; return false; } + m_offSet += size; - pBmpModule->Input(m_pBmpContext, m_pSrcBuf, size); - uint32_t* pPalette = nullptr; + pBmpModule->Input(m_pBmpContext.get(), m_pSrcBuf, size); + std::vector<uint32_t> palette; int32_t readResult = pBmpModule->ReadHeader( - m_pBmpContext, &m_SrcWidth, &m_SrcHeight, &m_BmpIsTopBottom, - &m_SrcComponents, &m_SrcPaletteNumber, &pPalette, pAttribute); + m_pBmpContext.get(), &m_SrcWidth, &m_SrcHeight, &m_BmpIsTopBottom, + &m_SrcComponents, &m_SrcPaletteNumber, &palette, pAttribute); while (readResult == 2) { FXCODEC_STATUS error_status = FXCODEC_STATUS_ERR_FORMAT; if (!BmpReadMoreData(pBmpModule, error_status)) { @@ -1044,28 +1040,64 @@ bool CCodec_ProgressiveDecoder::DetectImageType(FXCODEC_IMAGE_TYPE imageType, return false; } readResult = pBmpModule->ReadHeader( - m_pBmpContext, &m_SrcWidth, &m_SrcHeight, &m_BmpIsTopBottom, - &m_SrcComponents, &m_SrcPaletteNumber, &pPalette, pAttribute); + m_pBmpContext.get(), &m_SrcWidth, &m_SrcHeight, &m_BmpIsTopBottom, + &m_SrcComponents, &m_SrcPaletteNumber, &palette, pAttribute); } - if (readResult == 1) { - m_SrcBPC = 8; - m_clipBox = FX_RECT(0, 0, m_SrcWidth, m_SrcHeight); - FX_Free(m_pSrcPalette); - if (m_SrcPaletteNumber) { - m_pSrcPalette = FX_Alloc(FX_ARGB, m_SrcPaletteNumber); - memcpy(m_pSrcPalette, pPalette, - m_SrcPaletteNumber * sizeof(uint32_t)); - } else { - m_pSrcPalette = nullptr; - } - return true; + + if (readResult != 1) { + m_pBmpContext.reset(); + m_status = FXCODEC_STATUS_ERR_FORMAT; + return false; } - if (m_pBmpContext) { - pBmpModule->Finish(m_pBmpContext); - m_pBmpContext = nullptr; + + FXDIB_Format format = FXDIB_Invalid; + switch (m_SrcComponents) { + case 1: + m_SrcFormat = FXCodec_8bppRgb; + format = FXDIB_8bppRgb; + break; + case 3: + m_SrcFormat = FXCodec_Rgb; + format = FXDIB_Rgb; + break; + case 4: + m_SrcFormat = FXCodec_Rgb32; + format = FXDIB_Rgb32; + break; + default: + m_pBmpContext.reset(); + m_status = FXCODEC_STATUS_ERR_FORMAT; + return false; + break; } - m_status = FXCODEC_STATUS_ERR_FORMAT; - return false; + + uint32_t pitch = 0; + uint32_t neededData = 0; + if (!CFX_DIBitmap::CalculatePitchAndSize(m_SrcWidth, m_SrcHeight, format, + &pitch, &neededData)) { + m_pBmpContext.reset(); + m_status = FXCODEC_STATUS_ERR_FORMAT; + return false; + } + + uint32_t availableData = m_SrcSize > m_offSet ? m_SrcSize - m_offSet : 0; + if (neededData > availableData) { + m_pBmpContext.reset(); + m_status = FXCODEC_STATUS_ERR_FORMAT; + return false; + } + + m_SrcBPC = 8; + m_clipBox = FX_RECT(0, 0, m_SrcWidth, m_SrcHeight); + FX_Free(m_pSrcPalette); + if (m_SrcPaletteNumber) { + m_pSrcPalette = FX_Alloc(FX_ARGB, m_SrcPaletteNumber); + memcpy(m_pSrcPalette, palette.data(), + m_SrcPaletteNumber * sizeof(FX_ARGB)); + } else { + m_pSrcPalette = nullptr; + } + return true; } case FXCODEC_IMAGE_JPG: { CCodec_JpegModule* pJpegModule = m_pCodecMgr->GetJpegModule(); @@ -1074,16 +1106,15 @@ bool CCodec_ProgressiveDecoder::DetectImageType(FXCODEC_IMAGE_TYPE imageType, m_status = FXCODEC_STATUS_ERR_MEMORY; return false; } - bool bResult = m_pFile->ReadBlock(m_pSrcBuf, 0, size); - if (!bResult) { + if (!m_pFile->ReadBlock(m_pSrcBuf, 0, size)) { m_status = FXCODEC_STATUS_ERR_READ; return false; } m_offSet += size; - pJpegModule->Input(m_pJpegContext, m_pSrcBuf, size); + pJpegModule->Input(m_pJpegContext.get(), m_pSrcBuf, size); int32_t readResult = - pJpegModule->ReadHeader(m_pJpegContext, &m_SrcWidth, &m_SrcHeight, - &m_SrcComponents, pAttribute); + pJpegModule->ReadHeader(m_pJpegContext.get(), &m_SrcWidth, + &m_SrcHeight, &m_SrcComponents, pAttribute); while (readResult == 2) { FXCODEC_STATUS error_status = FXCODEC_STATUS_ERR_FORMAT; if (!JpegReadMoreData(pJpegModule, error_status)) { @@ -1091,18 +1122,15 @@ bool CCodec_ProgressiveDecoder::DetectImageType(FXCODEC_IMAGE_TYPE imageType, return false; } readResult = - pJpegModule->ReadHeader(m_pJpegContext, &m_SrcWidth, &m_SrcHeight, - &m_SrcComponents, pAttribute); + pJpegModule->ReadHeader(m_pJpegContext.get(), &m_SrcWidth, + &m_SrcHeight, &m_SrcComponents, pAttribute); } if (!readResult) { m_SrcBPC = 8; m_clipBox = FX_RECT(0, 0, m_SrcWidth, m_SrcHeight); return true; } - if (m_pJpegContext) { - pJpegModule->Finish(m_pJpegContext); - m_pJpegContext = nullptr; - } + m_pJpegContext.reset(); m_status = FXCODEC_STATUS_ERR_FORMAT; return false; } @@ -1112,8 +1140,7 @@ bool CCodec_ProgressiveDecoder::DetectImageType(FXCODEC_IMAGE_TYPE imageType, m_status = FXCODEC_STATUS_ERR_MEMORY; return false; } - pPngModule->SetDelegate(this); - m_pPngContext = pPngModule->Start(); + m_pPngContext = pPngModule->Start(this); if (!m_pPngContext) { m_status = FXCODEC_STATUS_ERR_MEMORY; return false; @@ -1124,16 +1151,14 @@ bool CCodec_ProgressiveDecoder::DetectImageType(FXCODEC_IMAGE_TYPE imageType, return false; } m_offSet += size; - bResult = pPngModule->Input(m_pPngContext, m_pSrcBuf, size, pAttribute); + bResult = + pPngModule->Input(m_pPngContext.get(), m_pSrcBuf, size, pAttribute); while (bResult) { uint32_t remain_size = (uint32_t)m_pFile->GetSize() - m_offSet; uint32_t input_size = remain_size > FXCODEC_BLOCK_SIZE ? FXCODEC_BLOCK_SIZE : remain_size; if (input_size == 0) { - if (m_pPngContext) { - pPngModule->Finish(m_pPngContext); - } - m_pPngContext = nullptr; + m_pPngContext.reset(); m_status = FXCODEC_STATUS_ERR_FORMAT; return false; } @@ -1149,14 +1174,11 @@ bool CCodec_ProgressiveDecoder::DetectImageType(FXCODEC_IMAGE_TYPE imageType, return false; } m_offSet += input_size; - bResult = - pPngModule->Input(m_pPngContext, m_pSrcBuf, input_size, pAttribute); + bResult = pPngModule->Input(m_pPngContext.get(), m_pSrcBuf, input_size, + pAttribute); } ASSERT(!bResult); - if (m_pPngContext) { - pPngModule->Finish(m_pPngContext); - m_pPngContext = nullptr; - } + m_pPngContext.reset(); if (m_SrcPassNumber == 0) { m_status = FXCODEC_STATUS_ERR_FORMAT; return false; @@ -1169,8 +1191,7 @@ bool CCodec_ProgressiveDecoder::DetectImageType(FXCODEC_IMAGE_TYPE imageType, m_status = FXCODEC_STATUS_ERR_MEMORY; return false; } - pGifModule->SetDelegate(this); - m_pGifContext = pGifModule->Start(); + m_pGifContext = pGifModule->Start(this); bool bResult = m_pFile->ReadBlock(m_pSrcBuf, 0, size); if (!bResult) { m_status = FXCODEC_STATUS_ERR_READ; @@ -1213,14 +1234,13 @@ bool CCodec_ProgressiveDecoder::DetectImageType(FXCODEC_IMAGE_TYPE imageType, return false; } int32_t dummy_bpc; - bool ret = pTiffModule->LoadFrameInfo(m_pTiffContext, 0, &m_SrcWidth, - &m_SrcHeight, &m_SrcComponents, - &dummy_bpc, pAttribute); + bool ret = pTiffModule->LoadFrameInfo( + m_pTiffContext.get(), 0, &m_SrcWidth, &m_SrcHeight, &m_SrcComponents, + &dummy_bpc, pAttribute); m_SrcComponents = 4; m_clipBox = FX_RECT(0, 0, m_SrcWidth, m_SrcHeight); if (!ret) { - pTiffModule->DestroyDecoder(m_pTiffContext); - m_pTiffContext = nullptr; + m_pTiffContext.reset(); m_status = FXCODEC_STATUS_ERR_FORMAT; return false; } @@ -1493,10 +1513,12 @@ void CCodec_ProgressiveDecoder::ReSampleScanline( int pixel_weight = pPixelWeights->m_Weights[j - pPixelWeights->m_SrcStart]; const uint8_t* src_pixel = src_scan + j * src_Bpp; - uint8_t src_b = 0, src_g = 0, src_r = 0; - AdobeCMYK_to_sRGB1(255 - src_pixel[0], 255 - src_pixel[1], - 255 - src_pixel[2], 255 - src_pixel[3], src_r, - src_g, src_b); + uint8_t src_b = 0; + uint8_t src_g = 0; + uint8_t src_r = 0; + std::tie(src_r, src_g, src_b) = + AdobeCMYK_to_sRGB1(255 - src_pixel[0], 255 - src_pixel[1], + 255 - src_pixel[2], 255 - src_pixel[3]); des_b += pixel_weight * src_b; des_g += pixel_weight * src_g; des_r += pixel_weight * src_r; @@ -1590,10 +1612,12 @@ void CCodec_ProgressiveDecoder::ReSampleScanline( int pixel_weight = pPixelWeights->m_Weights[j - pPixelWeights->m_SrcStart]; const uint8_t* src_pixel = src_scan + j * src_Bpp; - uint8_t src_b = 0, src_g = 0, src_r = 0; - AdobeCMYK_to_sRGB1(255 - src_pixel[0], 255 - src_pixel[1], - 255 - src_pixel[2], 255 - src_pixel[3], src_r, - src_g, src_b); + uint8_t src_b = 0; + uint8_t src_g = 0; + uint8_t src_r = 0; + std::tie(src_r, src_g, src_b) = + AdobeCMYK_to_sRGB1(255 - src_pixel[0], 255 - src_pixel[1], + 255 - src_pixel[2], 255 - src_pixel[3]); des_b += pixel_weight * src_b; des_g += pixel_weight * src_g; des_r += pixel_weight * src_r; @@ -1873,7 +1897,8 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::StartDecode( int down_scale = 1; GetDownScale(down_scale); CCodec_JpegModule* pJpegModule = m_pCodecMgr->GetJpegModule(); - bool bStart = pJpegModule->StartScanline(m_pJpegContext, down_scale); + bool bStart = + pJpegModule->StartScanline(m_pJpegContext.get(), down_scale); while (!bStart) { FXCODEC_STATUS error_status = FXCODEC_STATUS_ERROR; if (!JpegReadMoreData(pJpegModule, error_status)) { @@ -1882,7 +1907,7 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::StartDecode( m_status = error_status; return m_status; } - bStart = pJpegModule->StartScanline(m_pJpegContext, down_scale); + bStart = pJpegModule->StartScanline(m_pJpegContext.get(), down_scale); } int scanline_size = (m_SrcWidth + down_scale - 1) / down_scale; scanline_size = (scanline_size * m_SrcComponents + 3) / 4 * 4; @@ -1915,11 +1940,7 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::StartDecode( m_status = FXCODEC_STATUS_ERR_MEMORY; return m_status; } - if (m_pPngContext) { - pPngModule->Finish(m_pPngContext); - m_pPngContext = nullptr; - } - m_pPngContext = pPngModule->Start(); + m_pPngContext = pPngModule->Start(this); if (!m_pPngContext) { m_pDeviceBitmap = nullptr; m_pFile = nullptr; @@ -1988,17 +2009,6 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::StartDecode( m_status = FXCODEC_STATUS_ERR_MEMORY; return m_status; } - switch (m_SrcComponents) { - case 1: - m_SrcFormat = FXCodec_8bppRgb; - break; - case 3: - m_SrcFormat = FXCodec_Rgb; - break; - case 4: - m_SrcFormat = FXCodec_Rgb32; - break; - } GetTransMethod(m_pDeviceBitmap->GetFormat(), m_SrcFormat); m_ScanlineSize = (m_SrcWidth * m_SrcComponents + 3) / 4 * 4; FX_Free(m_pDecodeBuf); @@ -2026,7 +2036,8 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::ContinueDecode() { case FXCODEC_IMAGE_JPG: { CCodec_JpegModule* pJpegModule = m_pCodecMgr->GetJpegModule(); while (true) { - bool readRes = pJpegModule->ReadScanline(m_pJpegContext, m_pDecodeBuf); + bool readRes = + pJpegModule->ReadScanline(m_pJpegContext.get(), m_pDecodeBuf); while (!readRes) { FXCODEC_STATUS error_status = FXCODEC_STATUS_DECODE_FINISH; if (!JpegReadMoreData(pJpegModule, error_status)) { @@ -2035,7 +2046,8 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::ContinueDecode() { m_status = error_status; return m_status; } - readRes = pJpegModule->ReadScanline(m_pJpegContext, m_pDecodeBuf); + readRes = + pJpegModule->ReadScanline(m_pJpegContext.get(), m_pDecodeBuf); } if (m_SrcFormat == FXCodec_Rgb) { int src_Bpp = (m_SrcFormat & 0xff) >> 3; @@ -2062,10 +2074,7 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::ContinueDecode() { uint32_t input_size = remain_size > FXCODEC_BLOCK_SIZE ? FXCODEC_BLOCK_SIZE : remain_size; if (input_size == 0) { - if (m_pPngContext) { - pPngModule->Finish(m_pPngContext); - } - m_pPngContext = nullptr; + m_pPngContext.reset(); m_pDeviceBitmap = nullptr; m_pFile = nullptr; m_status = FXCODEC_STATUS_DECODE_FINISH; @@ -2085,8 +2094,8 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::ContinueDecode() { return m_status; } m_offSet += input_size; - bResult = - pPngModule->Input(m_pPngContext, m_pSrcBuf, input_size, nullptr); + bResult = pPngModule->Input(m_pPngContext.get(), m_pSrcBuf, input_size, + nullptr); if (!bResult) { m_pDeviceBitmap = nullptr; m_pFile = nullptr; @@ -2134,7 +2143,7 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::ContinueDecode() { return m_status; } while (true) { - int32_t readRes = pBmpModule->LoadImage(m_pBmpContext); + int32_t readRes = pBmpModule->LoadImage(m_pBmpContext.get()); while (readRes == 2) { FXCODEC_STATUS error_status = FXCODEC_STATUS_DECODE_FINISH; if (!BmpReadMoreData(pBmpModule, error_status)) { @@ -2143,7 +2152,7 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::ContinueDecode() { m_status = error_status; return m_status; } - readRes = pBmpModule->LoadImage(m_pBmpContext); + readRes = pBmpModule->LoadImage(m_pBmpContext.get()); } if (readRes == 1) { m_pDeviceBitmap = nullptr; @@ -2170,7 +2179,7 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::ContinueDecode() { m_SrcHeight == m_sizeY && m_startX == 0 && m_startY == 0 && m_clipBox.left == 0 && m_clipBox.top == 0 && m_clipBox.right == m_SrcWidth && m_clipBox.bottom == m_SrcHeight) { - ret = pTiffModule->Decode(m_pTiffContext, m_pDeviceBitmap); + ret = pTiffModule->Decode(m_pTiffContext.get(), m_pDeviceBitmap); m_pDeviceBitmap = nullptr; m_pFile = nullptr; if (!ret) { @@ -2189,7 +2198,7 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::ContinueDecode() { m_status = FXCODEC_STATUS_ERR_MEMORY; return m_status; } - ret = pTiffModule->Decode(m_pTiffContext, pDIBitmap); + ret = pTiffModule->Decode(m_pTiffContext.get(), pDIBitmap); if (!ret) { m_pDeviceBitmap = nullptr; m_pFile = nullptr; diff --git a/chromium/third_party/pdfium/core/fxcodec/codec/fx_codec_rle_unittest.cpp b/chromium/third_party/pdfium/core/fxcodec/codec/fx_codec_rle_unittest.cpp index d90a515d450..7b0af908195 100644 --- a/chromium/third_party/pdfium/core/fxcodec/codec/fx_codec_rle_unittest.cpp +++ b/chromium/third_party/pdfium/core/fxcodec/codec/fx_codec_rle_unittest.cpp @@ -9,7 +9,6 @@ #include "core/fpdfapi/parser/fpdf_parser_decode.h" #include "core/fxcodec/codec/ccodec_basicmodule.h" #include "core/fxcodec/fx_codec.h" -#include "testing/fx_string_testhelpers.h" #include "testing/gtest/include/gtest/gtest.h" TEST(fxcodec, RLETestBadInputs) { @@ -75,7 +74,7 @@ TEST(fxcodec, RLETestNormalInputs) { pEncoders->RunLengthEncode(src_buf_1, src_size, &dest_buf, &dest_size)); uint8_t* decoded_buf = nullptr; uint32_t decoded_size = 0; - RunLengthDecode(dest_buf, dest_size, decoded_buf, decoded_size); + RunLengthDecode(dest_buf, dest_size, &decoded_buf, &decoded_size); ASSERT_EQ(src_size, decoded_size); for (uint32_t i = 0; i < src_size; i++) EXPECT_EQ(src_buf_1[i], decoded_buf[i]) << " at " << i; @@ -89,7 +88,7 @@ TEST(fxcodec, RLETestNormalInputs) { pEncoders->RunLengthEncode(src_buf_2, src_size, &dest_buf, &dest_size)); decoded_buf = nullptr; decoded_size = 0; - RunLengthDecode(dest_buf, dest_size, decoded_buf, decoded_size); + RunLengthDecode(dest_buf, dest_size, &decoded_buf, &decoded_size); ASSERT_EQ(src_size, decoded_size); for (uint32_t i = 0; i < src_size; i++) EXPECT_EQ(src_buf_2[i], decoded_buf[i]) << " at " << i; @@ -103,7 +102,7 @@ TEST(fxcodec, RLETestNormalInputs) { pEncoders->RunLengthEncode(src_buf_3, src_size, &dest_buf, &dest_size)); decoded_buf = nullptr; decoded_size = 0; - RunLengthDecode(dest_buf, dest_size, decoded_buf, decoded_size); + RunLengthDecode(dest_buf, dest_size, &decoded_buf, &decoded_size); ASSERT_EQ(src_size, decoded_size); for (uint32_t i = 0; i < src_size; i++) EXPECT_EQ(src_buf_3[i], decoded_buf[i]) << " at " << i; @@ -144,7 +143,7 @@ TEST(fxcodec, RLETestFullLengthInputs) { pEncoders->RunLengthEncode(src_buf_1, src_size, &dest_buf, &dest_size)); uint8_t* decoded_buf = nullptr; uint32_t decoded_size = 0; - RunLengthDecode(dest_buf, dest_size, decoded_buf, decoded_size); + RunLengthDecode(dest_buf, dest_size, &decoded_buf, &decoded_size); ASSERT_EQ(src_size, decoded_size); for (uint32_t i = 0; i < src_size; i++) EXPECT_EQ(src_buf_1[i], decoded_buf[i]) << " at " << i; @@ -158,7 +157,7 @@ TEST(fxcodec, RLETestFullLengthInputs) { pEncoders->RunLengthEncode(src_buf_2, src_size, &dest_buf, &dest_size)); decoded_buf = nullptr; decoded_size = 0; - RunLengthDecode(dest_buf, dest_size, decoded_buf, decoded_size); + RunLengthDecode(dest_buf, dest_size, &decoded_buf, &decoded_size); ASSERT_EQ(src_size, decoded_size); for (uint32_t i = 0; i < src_size; i++) EXPECT_EQ(src_buf_2[i], decoded_buf[i]) << " at " << i; @@ -172,7 +171,7 @@ TEST(fxcodec, RLETestFullLengthInputs) { pEncoders->RunLengthEncode(src_buf_3, src_size, &dest_buf, &dest_size)); decoded_buf = nullptr; decoded_size = 0; - RunLengthDecode(dest_buf, dest_size, decoded_buf, decoded_size); + RunLengthDecode(dest_buf, dest_size, &decoded_buf, &decoded_size); ASSERT_EQ(src_size, decoded_size); for (uint32_t i = 0; i < src_size; i++) EXPECT_EQ(src_buf_3[i], decoded_buf[i]) << " at " << i; @@ -186,7 +185,7 @@ TEST(fxcodec, RLETestFullLengthInputs) { pEncoders->RunLengthEncode(src_buf_4, src_size, &dest_buf, &dest_size)); decoded_buf = nullptr; decoded_size = 0; - RunLengthDecode(dest_buf, dest_size, decoded_buf, decoded_size); + RunLengthDecode(dest_buf, dest_size, &decoded_buf, &decoded_size); ASSERT_EQ(src_size, decoded_size); for (uint32_t i = 0; i < src_size; i++) EXPECT_EQ(src_buf_4[i], decoded_buf[i]) << " at " << i; diff --git a/chromium/third_party/pdfium/core/fxcodec/fx_codec.h b/chromium/third_party/pdfium/core/fxcodec/fx_codec.h index fd7b1748ff7..71b002282ca 100644 --- a/chromium/third_party/pdfium/core/fxcodec/fx_codec.h +++ b/chromium/third_party/pdfium/core/fxcodec/fx_codec.h @@ -9,6 +9,7 @@ #include <map> #include <memory> +#include <tuple> #include <utility> #include <vector> @@ -118,21 +119,14 @@ void sRGB_to_AdobeCMYK(float R, float& m, float& y, float& k); -void AdobeCMYK_to_sRGB(float c, - float m, - float y, - float k, - float& R, - float& G, - float& B); -void AdobeCMYK_to_sRGB1(uint8_t c, - uint8_t m, - uint8_t y, - uint8_t k, - uint8_t& R, - uint8_t& G, - uint8_t& B); -bool MD5ComputeID(const void* buf, uint32_t dwSize, uint8_t ID[16]); +std::tuple<float, float, float> AdobeCMYK_to_sRGB(float c, + float m, + float y, + float k); +std::tuple<uint8_t, uint8_t, uint8_t> AdobeCMYK_to_sRGB1(uint8_t c, + uint8_t m, + uint8_t y, + uint8_t k); void FaxG4Decode(const uint8_t* src_buf, uint32_t src_size, int* pbitpos, diff --git a/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_Context.cpp b/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_Context.cpp index c9570022bb0..eaaed312d6f 100644 --- a/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_Context.cpp +++ b/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_Context.cpp @@ -50,20 +50,18 @@ CJBig2_Context::CJBig2_Context( const CFX_RetainPtr<CPDF_StreamAcc>& pGlobalStream, const CFX_RetainPtr<CPDF_StreamAcc>& pSrcStream, std::list<CJBig2_CachePair>* pSymbolDictCache, - IFX_Pause* pPause, bool bIsGlobal) : m_nSegmentDecoded(0), m_bInPage(false), m_bBufSpecified(false), m_PauseStep(10), - m_pPause(pPause), m_ProcessingStatus(FXCODEC_STATUS_FRAME_READY), m_dwOffset(0), m_pSymbolDictCache(pSymbolDictCache), m_bIsGlobal(bIsGlobal) { - if (pGlobalStream && (pGlobalStream->GetSize() > 0)) { + if (pGlobalStream && pGlobalStream->GetSize() > 0) { m_pGlobalContext = pdfium::MakeUnique<CJBig2_Context>( - nullptr, pGlobalStream, pSymbolDictCache, pPause, true); + nullptr, pGlobalStream, pSymbolDictCache, true); } m_pStream = pdfium::MakeUnique<CJBig2_BitStream>(pSrcStream); } @@ -131,7 +129,7 @@ int32_t CJBig2_Context::decode_RandomOrgnazation_FirstPage(IFX_Pause* pPause) { break; } m_SegmentList.push_back(std::move(pSegment)); - if (pPause && m_pPause && pPause->NeedToPauseNow()) { + if (pPause && pPause->NeedToPauseNow()) { m_PauseStep = 3; m_ProcessingStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; return JBIG2_SUCCESS; @@ -464,7 +462,7 @@ int32_t CJBig2_Context::parseSymbolDict(CJBig2_Segment* pSegment) { CJBig2_Segment* pSeg = findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i]); if (pSeg->m_cFlags.s.type == 0) { - pSymbolDictDecoder->SDNUMINSYMS += pSeg->m_Result.sd->NumImages(); + pSymbolDictDecoder->SDNUMINSYMS += pSeg->m_SymbolDict->NumImages(); pLRSeg = pSeg; } } @@ -477,7 +475,7 @@ int32_t CJBig2_Context::parseSymbolDict(CJBig2_Segment* pSegment) { CJBig2_Segment* pSeg = findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i]); if (pSeg->m_cFlags.s.type == 0) { - const CJBig2_SymbolDict& dict = *pSeg->m_Result.sd; + const CJBig2_SymbolDict& dict = *pSeg->m_SymbolDict.get(); for (size_t j = 0; j < dict.NumImages(); ++j) SDINSYMS.get()[dwTemp + j] = dict.GetImage(j); dwTemp += dict.NumImages(); @@ -509,7 +507,7 @@ int32_t CJBig2_Context::parseSymbolDict(CJBig2_Segment* pSegment) { findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); if (!pSeg) return JBIG2_ERROR_FATAL; - pSymbolDictDecoder->SDHUFFDH = pSeg->m_Result.ht; + pSymbolDictDecoder->SDHUFFDH = pSeg->m_HuffmanTable.get(); } if (cSDHUFFDW == 0) { Table_B2 = pdfium::MakeUnique<CJBig2_HuffmanTable>( @@ -524,7 +522,7 @@ int32_t CJBig2_Context::parseSymbolDict(CJBig2_Segment* pSegment) { findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); if (!pSeg) return JBIG2_ERROR_FATAL; - pSymbolDictDecoder->SDHUFFDW = pSeg->m_Result.ht; + pSymbolDictDecoder->SDHUFFDW = pSeg->m_HuffmanTable.get(); } if (cSDHUFFBMSIZE == 0) { Table_B1 = pdfium::MakeUnique<CJBig2_HuffmanTable>( @@ -535,7 +533,7 @@ int32_t CJBig2_Context::parseSymbolDict(CJBig2_Segment* pSegment) { findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); if (!pSeg) return JBIG2_ERROR_FATAL; - pSymbolDictDecoder->SDHUFFBMSIZE = pSeg->m_Result.ht; + pSymbolDictDecoder->SDHUFFBMSIZE = pSeg->m_HuffmanTable.get(); } if (pSymbolDictDecoder->SDREFAGG == 1) { if (cSDHUFFAGGINST == 0) { @@ -549,7 +547,7 @@ int32_t CJBig2_Context::parseSymbolDict(CJBig2_Segment* pSegment) { findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); if (!pSeg) return JBIG2_ERROR_FATAL; - pSymbolDictDecoder->SDHUFFAGGINST = pSeg->m_Result.ht; + pSymbolDictDecoder->SDHUFFAGGINST = pSeg->m_HuffmanTable.get(); } } } @@ -564,12 +562,12 @@ int32_t CJBig2_Context::parseSymbolDict(CJBig2_Segment* pSegment) { std::vector<JBig2ArithCtx> grContext; if ((wFlags & 0x0100) && pLRSeg) { if (bUseGbContext) { - gbContext = pLRSeg->m_Result.sd->GbContext(); + gbContext = pLRSeg->m_SymbolDict->GbContext(); if (gbContext.size() != gbContextSize) return JBIG2_ERROR_FATAL; } if (bUseGrContext) { - grContext = pLRSeg->m_Result.sd->GrContext(); + grContext = pLRSeg->m_SymbolDict->GrContext(); if (grContext.size() != grContextSize) return JBIG2_ERROR_FATAL; } @@ -588,8 +586,7 @@ int32_t CJBig2_Context::parseSymbolDict(CJBig2_Segment* pSegment) { for (auto it = m_pSymbolDictCache->begin(); it != m_pSymbolDictCache->end(); ++it) { if (it->first == key) { - std::unique_ptr<CJBig2_SymbolDict> copy(it->second->DeepCopy()); - pSegment->m_Result.sd = copy.release(); + pSegment->m_SymbolDict = it->second->DeepCopy(); m_pSymbolDictCache->push_front( CJBig2_CachePair(key, std::move(it->second))); m_pSymbolDictCache->erase(it); @@ -602,23 +599,23 @@ int32_t CJBig2_Context::parseSymbolDict(CJBig2_Segment* pSegment) { if (bUseGbContext) { auto pArithDecoder = pdfium::MakeUnique<CJBig2_ArithDecoder>(m_pStream.get()); - pSegment->m_Result.sd = pSymbolDictDecoder->decode_Arith( + pSegment->m_SymbolDict = pSymbolDictDecoder->decode_Arith( pArithDecoder.get(), &gbContext, &grContext); - if (!pSegment->m_Result.sd) + if (!pSegment->m_SymbolDict) return JBIG2_ERROR_FATAL; m_pStream->alignByte(); m_pStream->offset(2); } else { - pSegment->m_Result.sd = pSymbolDictDecoder->decode_Huffman( + pSegment->m_SymbolDict = pSymbolDictDecoder->decode_Huffman( m_pStream.get(), &gbContext, &grContext); - if (!pSegment->m_Result.sd) + if (!pSegment->m_SymbolDict) return JBIG2_ERROR_FATAL; m_pStream->alignByte(); } if (m_bIsGlobal) { std::unique_ptr<CJBig2_SymbolDict> value = - pSegment->m_Result.sd->DeepCopy(); + pSegment->m_SymbolDict->DeepCopy(); int size = pdfium::CollectionSize<int>(*m_pSymbolDictCache); while (size >= kSymbolDictCacheMaxSize) { m_pSymbolDictCache->pop_back(); @@ -629,9 +626,9 @@ int32_t CJBig2_Context::parseSymbolDict(CJBig2_Segment* pSegment) { } if (wFlags & 0x0200) { if (bUseGbContext) - pSegment->m_Result.sd->SetGbContext(gbContext); + pSegment->m_SymbolDict->SetGbContext(gbContext); if (bUseGrContext) - pSegment->m_Result.sd->SetGrContext(grContext); + pSegment->m_SymbolDict->SetGrContext(grContext); } return JBIG2_SUCCESS; } @@ -701,7 +698,7 @@ int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) { CJBig2_Segment* pSeg = findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i]); if (pSeg->m_cFlags.s.type == 0) { - pTRD->SBNUMSYMS += pSeg->m_Result.sd->NumImages(); + pTRD->SBNUMSYMS += pSeg->m_SymbolDict->NumImages(); } } @@ -713,7 +710,7 @@ int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) { CJBig2_Segment* pSeg = findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i]); if (pSeg->m_cFlags.s.type == 0) { - const CJBig2_SymbolDict& dict = *pSeg->m_Result.sd; + const CJBig2_SymbolDict& dict = *pSeg->m_SymbolDict.get(); for (size_t j = 0; j < dict.NumImages(); ++j) SBSYMS.get()[dwTemp + j] = dict.GetImage(j); dwTemp += dict.NumImages(); @@ -724,15 +721,14 @@ int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) { pTRD->SBSYMS = nullptr; } - std::unique_ptr<JBig2HuffmanCode, FxFreeDeleter> SBSYMCODES; if (pTRD->SBHUFF == 1) { - SBSYMCODES.reset( - decodeSymbolIDHuffmanTable(m_pStream.get(), pTRD->SBNUMSYMS)); - if (!SBSYMCODES) + std::vector<JBig2HuffmanCode> SBSYMCODES = + decodeSymbolIDHuffmanTable(m_pStream.get(), pTRD->SBNUMSYMS); + if (SBSYMCODES.empty()) return JBIG2_ERROR_FATAL; m_pStream->alignByte(); - pTRD->SBSYMCODES = SBSYMCODES.get(); + pTRD->SBSYMCODES = std::move(SBSYMCODES); } else { dwTemp = 0; while ((uint32_t)(1 << dwTemp) < pTRD->SBNUMSYMS) { @@ -771,7 +767,7 @@ int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) { findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); if (!pSeg) return JBIG2_ERROR_FATAL; - pTRD->SBHUFFFS = pSeg->m_Result.ht; + pTRD->SBHUFFFS = pSeg->m_HuffmanTable.get(); } if (cSBHUFFDS == 0) { Table_B8 = pdfium::MakeUnique<CJBig2_HuffmanTable>( @@ -790,7 +786,7 @@ int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) { findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); if (!pSeg) return JBIG2_ERROR_FATAL; - pTRD->SBHUFFDS = pSeg->m_Result.ht; + pTRD->SBHUFFDS = pSeg->m_HuffmanTable.get(); } if (cSBHUFFDT == 0) { Table_B11 = pdfium::MakeUnique<CJBig2_HuffmanTable>( @@ -809,7 +805,7 @@ int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) { findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); if (!pSeg) return JBIG2_ERROR_FATAL; - pTRD->SBHUFFDT = pSeg->m_Result.ht; + pTRD->SBHUFFDT = pSeg->m_HuffmanTable.get(); } if (cSBHUFFRDW == 0) { Table_B14 = pdfium::MakeUnique<CJBig2_HuffmanTable>( @@ -824,7 +820,7 @@ int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) { findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); if (!pSeg) return JBIG2_ERROR_FATAL; - pTRD->SBHUFFRDW = pSeg->m_Result.ht; + pTRD->SBHUFFRDW = pSeg->m_HuffmanTable.get(); } if (cSBHUFFRDH == 0) { if (!Table_B14) { @@ -843,7 +839,7 @@ int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) { findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); if (!pSeg) return JBIG2_ERROR_FATAL; - pTRD->SBHUFFRDH = pSeg->m_Result.ht; + pTRD->SBHUFFRDH = pSeg->m_HuffmanTable.get(); } if (cSBHUFFRDX == 0) { if (!Table_B14) { @@ -862,7 +858,7 @@ int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) { findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); if (!pSeg) return JBIG2_ERROR_FATAL; - pTRD->SBHUFFRDX = pSeg->m_Result.ht; + pTRD->SBHUFFRDX = pSeg->m_HuffmanTable.get(); } if (cSBHUFFRDY == 0) { if (!Table_B14) { @@ -881,7 +877,7 @@ int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) { findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); if (!pSeg) return JBIG2_ERROR_FATAL; - pTRD->SBHUFFRDY = pSeg->m_Result.ht; + pTRD->SBHUFFRDY = pSeg->m_HuffmanTable.get(); } if (cSBHUFFRSIZE == 0) { Table_B1 = pdfium::MakeUnique<CJBig2_HuffmanTable>( @@ -892,7 +888,7 @@ int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) { findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); if (!pSeg) return JBIG2_ERROR_FATAL; - pTRD->SBHUFFRSIZE = pSeg->m_Result.ht; + pTRD->SBHUFFRSIZE = pSeg->m_HuffmanTable.get(); } } std::unique_ptr<JBig2ArithCtx, FxFreeDeleter> grContext; @@ -905,17 +901,16 @@ int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) { auto pArithDecoder = pdfium::MakeUnique<CJBig2_ArithDecoder>(m_pStream.get()); pSegment->m_nResultType = JBIG2_IMAGE_POINTER; - pSegment->m_Result.im = + pSegment->m_Image = pTRD->decode_Arith(pArithDecoder.get(), grContext.get(), nullptr); - if (!pSegment->m_Result.im) + if (!pSegment->m_Image) return JBIG2_ERROR_FATAL; m_pStream->alignByte(); m_pStream->offset(2); } else { pSegment->m_nResultType = JBIG2_IMAGE_POINTER; - pSegment->m_Result.im = - pTRD->decode_Huffman(m_pStream.get(), grContext.get()); - if (!pSegment->m_Result.im) + pSegment->m_Image = pTRD->decode_Huffman(m_pStream.get(), grContext.get()); + if (!pSegment->m_Image) return JBIG2_ERROR_FATAL; m_pStream->alignByte(); } @@ -927,10 +922,9 @@ int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) { m_pPage->expand(ri.y + ri.height, (pPageInfo->m_cFlags & 4) ? 1 : 0); } } - m_pPage->composeFrom(ri.x, ri.y, pSegment->m_Result.im, + m_pPage->composeFrom(ri.x, ri.y, pSegment->m_Image.get(), (JBig2ComposeOp)(ri.flags & 0x03)); - delete pSegment->m_Result.im; - pSegment->m_Result.im = nullptr; + pSegment->m_Image.reset(); } return JBIG2_SUCCESS; } @@ -958,16 +952,16 @@ int32_t CJBig2_Context::parsePatternDict(CJBig2_Segment* pSegment, JBIG2_memset(gbContext.get(), 0, sizeof(JBig2ArithCtx) * size); auto pArithDecoder = pdfium::MakeUnique<CJBig2_ArithDecoder>(m_pStream.get()); - pSegment->m_Result.pd = + pSegment->m_PatternDict = pPDD->decode_Arith(pArithDecoder.get(), gbContext.get(), pPause); - if (!pSegment->m_Result.pd) + if (!pSegment->m_PatternDict) return JBIG2_ERROR_FATAL; m_pStream->alignByte(); m_pStream->offset(2); } else { - pSegment->m_Result.pd = pPDD->decode_MMR(m_pStream.get()); - if (!pSegment->m_Result.pd) + pSegment->m_PatternDict = pPDD->decode_MMR(m_pStream.get()); + if (!pSegment->m_PatternDict) return JBIG2_ERROR_FATAL; m_pStream->alignByte(); } @@ -1008,12 +1002,12 @@ int32_t CJBig2_Context::parseHalftoneRegion(CJBig2_Segment* pSegment, if (!pSeg || (pSeg->m_cFlags.s.type != 16)) return JBIG2_ERROR_FATAL; - CJBig2_PatternDict* pPatternDict = pSeg->m_Result.pd; + const CJBig2_PatternDict* pPatternDict = pSeg->m_PatternDict.get(); if (!pPatternDict || (pPatternDict->NUMPATS == 0)) return JBIG2_ERROR_FATAL; pHRD->HNUMPATS = pPatternDict->NUMPATS; - pHRD->HPATS = pPatternDict->HDPATS; + pHRD->HPATS = &pPatternDict->HDPATS; pHRD->HPW = pPatternDict->HDPATS[0]->width(); pHRD->HPH = pPatternDict->HDPATS[0]->height(); pSegment->m_nResultType = JBIG2_IMAGE_POINTER; @@ -1024,16 +1018,16 @@ int32_t CJBig2_Context::parseHalftoneRegion(CJBig2_Segment* pSegment, JBIG2_memset(gbContext.get(), 0, sizeof(JBig2ArithCtx) * size); auto pArithDecoder = pdfium::MakeUnique<CJBig2_ArithDecoder>(m_pStream.get()); - pSegment->m_Result.im = + pSegment->m_Image = pHRD->decode_Arith(pArithDecoder.get(), gbContext.get(), pPause); - if (!pSegment->m_Result.im) + if (!pSegment->m_Image) return JBIG2_ERROR_FATAL; m_pStream->alignByte(); m_pStream->offset(2); } else { - pSegment->m_Result.im = pHRD->decode_MMR(m_pStream.get()); - if (!pSegment->m_Result.im) + pSegment->m_Image = pHRD->decode_MMR(m_pStream.get()); + if (!pSegment->m_Image) return JBIG2_ERROR_FATAL; m_pStream->alignByte(); } @@ -1045,10 +1039,9 @@ int32_t CJBig2_Context::parseHalftoneRegion(CJBig2_Segment* pSegment, m_pPage->expand(ri.y + ri.height, (pPageInfo->m_cFlags & 4) ? 1 : 0); } } - m_pPage->composeFrom(ri.x, ri.y, pSegment->m_Result.im, + m_pPage->composeFrom(ri.x, ri.y, pSegment->m_Image.get(), (JBig2ComposeOp)(ri.flags & 0x03)); - delete pSegment->m_Result.im; - pSegment->m_Result.im = nullptr; + pSegment->m_Image.reset(); } return JBIG2_SUCCESS; } @@ -1064,7 +1057,6 @@ int32_t CJBig2_Context::parseGenericRegion(CJBig2_Segment* pSegment, } if (m_ri.height < 0 || m_ri.width < 0) return JBIG2_FAILED; - pGRD->GBW = m_ri.width; pGRD->GBH = m_ri.height; pGRD->MMR = cFlags & 0x01; @@ -1073,15 +1065,13 @@ int32_t CJBig2_Context::parseGenericRegion(CJBig2_Segment* pSegment, if (pGRD->MMR == 0) { if (pGRD->GBTEMPLATE == 0) { for (int32_t i = 0; i < 8; ++i) { - if (m_pStream->read1Byte((uint8_t*)&pGRD->GBAT[i]) != 0) { + if (m_pStream->read1Byte((uint8_t*)&pGRD->GBAT[i]) != 0) return JBIG2_ERROR_TOO_SHORT; - } } } else { for (int32_t i = 0; i < 2; ++i) { - if (m_pStream->read1Byte((uint8_t*)&pGRD->GBAT[i]) != 0) { + if (m_pStream->read1Byte((uint8_t*)&pGRD->GBAT[i]) != 0) return JBIG2_ERROR_TOO_SHORT; - } } } } @@ -1090,18 +1080,16 @@ int32_t CJBig2_Context::parseGenericRegion(CJBig2_Segment* pSegment, } pSegment->m_nResultType = JBIG2_IMAGE_POINTER; if (m_pGRD->MMR == 0) { - if (m_gbContext.empty()) { - const size_t size = GetHuffContextSize(m_pGRD->GBTEMPLATE); - m_gbContext.resize(size); - } + if (m_gbContext.empty()) + m_gbContext.resize(GetHuffContextSize(m_pGRD->GBTEMPLATE)); if (!m_pArithDecoder) { m_pArithDecoder = pdfium::MakeUnique<CJBig2_ArithDecoder>(m_pStream.get()); - m_ProcessingStatus = m_pGRD->Start_decode_Arith(&pSegment->m_Result.im, - m_pArithDecoder.get(), - &m_gbContext[0], pPause); + m_ProcessingStatus = m_pGRD->Start_decode_Arith( + &pSegment->m_Image, m_pArithDecoder.get(), &m_gbContext[0], pPause); } else { - m_ProcessingStatus = m_pGRD->Continue_decode(pPause); + m_ProcessingStatus = + m_pGRD->Continue_decode(pPause, m_pArithDecoder.get()); } if (m_ProcessingStatus == FXCODEC_STATUS_DECODE_TOBECONTINUE) { if (pSegment->m_cFlags.s.type != 36) { @@ -1115,24 +1103,23 @@ int32_t CJBig2_Context::parseGenericRegion(CJBig2_Segment* pSegment, } FX_RECT Rect = m_pGRD->GetReplaceRect(); m_pPage->composeFrom(m_ri.x + Rect.left, m_ri.y + Rect.top, - pSegment->m_Result.im, + pSegment->m_Image.get(), (JBig2ComposeOp)(m_ri.flags & 0x03), &Rect); } return JBIG2_SUCCESS; - } else { - m_pArithDecoder.reset(); - m_gbContext.clear(); - if (!pSegment->m_Result.im) { - m_ProcessingStatus = FXCODEC_STATUS_ERROR; - m_pGRD.reset(); - return JBIG2_ERROR_FATAL; - } - m_pStream->alignByte(); - m_pStream->offset(2); } + m_pArithDecoder.reset(); + m_gbContext.clear(); + if (!pSegment->m_Image) { + m_ProcessingStatus = FXCODEC_STATUS_ERROR; + m_pGRD.reset(); + return JBIG2_ERROR_FATAL; + } + m_pStream->alignByte(); + m_pStream->offset(2); } else { - m_pGRD->Start_decode_MMR(&pSegment->m_Result.im, m_pStream.get()); - if (!pSegment->m_Result.im) { + m_pGRD->Start_decode_MMR(&pSegment->m_Image, m_pStream.get()); + if (!pSegment->m_Image) { m_pGRD.reset(); return JBIG2_ERROR_FATAL; } @@ -1149,10 +1136,9 @@ int32_t CJBig2_Context::parseGenericRegion(CJBig2_Segment* pSegment, } FX_RECT Rect = m_pGRD->GetReplaceRect(); m_pPage->composeFrom(m_ri.x + Rect.left, m_ri.y + Rect.top, - pSegment->m_Result.im, + pSegment->m_Image.get(), (JBig2ComposeOp)(m_ri.flags & 0x03), &Rect); - delete pSegment->m_Result.im; - pSegment->m_Result.im = nullptr; + pSegment->m_Image.reset(); } m_pGRD.reset(); return JBIG2_SUCCESS; @@ -1192,7 +1178,7 @@ int32_t CJBig2_Context::parseGenericRefinementRegion(CJBig2_Segment* pSegment) { if (i >= pSegment->m_nReferred_to_segment_count) return JBIG2_ERROR_FATAL; - pGRRD->GRREFERENCE = pSeg->m_Result.im; + pGRRD->GRREFERENCE = pSeg->m_Image.get(); } else { pGRRD->GRREFERENCE = m_pPage.get(); } @@ -1204,8 +1190,8 @@ int32_t CJBig2_Context::parseGenericRefinementRegion(CJBig2_Segment* pSegment) { JBIG2_memset(grContext.get(), 0, sizeof(JBig2ArithCtx) * size); auto pArithDecoder = pdfium::MakeUnique<CJBig2_ArithDecoder>(m_pStream.get()); pSegment->m_nResultType = JBIG2_IMAGE_POINTER; - pSegment->m_Result.im = pGRRD->decode(pArithDecoder.get(), grContext.get()); - if (!pSegment->m_Result.im) + pSegment->m_Image = pGRRD->decode(pArithDecoder.get(), grContext.get()); + if (!pSegment->m_Image) return JBIG2_ERROR_FATAL; m_pStream->alignByte(); @@ -1218,22 +1204,21 @@ int32_t CJBig2_Context::parseGenericRefinementRegion(CJBig2_Segment* pSegment) { m_pPage->expand(ri.y + ri.height, (pPageInfo->m_cFlags & 4) ? 1 : 0); } } - m_pPage->composeFrom(ri.x, ri.y, pSegment->m_Result.im, + m_pPage->composeFrom(ri.x, ri.y, pSegment->m_Image.get(), (JBig2ComposeOp)(ri.flags & 0x03)); - delete pSegment->m_Result.im; - pSegment->m_Result.im = nullptr; + pSegment->m_Image.reset(); } return JBIG2_SUCCESS; } int32_t CJBig2_Context::parseTable(CJBig2_Segment* pSegment) { pSegment->m_nResultType = JBIG2_HUFFMAN_TABLE_POINTER; - pSegment->m_Result.ht = nullptr; + pSegment->m_HuffmanTable.reset(); auto pHuff = pdfium::MakeUnique<CJBig2_HuffmanTable>(m_pStream.get()); if (!pHuff->IsOK()) return JBIG2_ERROR_FATAL; - pSegment->m_Result.ht = pHuff.release(); + pSegment->m_HuffmanTable = std::move(pHuff); m_pStream->alignByte(); return JBIG2_SUCCESS; } @@ -1249,35 +1234,33 @@ int32_t CJBig2_Context::parseRegionInfo(JBig2RegionInfo* pRI) { return JBIG2_SUCCESS; } -JBig2HuffmanCode* CJBig2_Context::decodeSymbolIDHuffmanTable( +std::vector<JBig2HuffmanCode> CJBig2_Context::decodeSymbolIDHuffmanTable( CJBig2_BitStream* pStream, uint32_t SBNUMSYMS) { const size_t kRunCodesSize = 35; - int32_t runcodes[kRunCodesSize]; - int32_t runcodes_len[kRunCodesSize]; + JBig2HuffmanCode huffman_codes[kRunCodesSize]; for (size_t i = 0; i < kRunCodesSize; ++i) { - if (pStream->readNBits(4, &runcodes_len[i]) != 0) - return nullptr; + if (pStream->readNBits(4, &huffman_codes[i].codelen) != 0) + return std::vector<JBig2HuffmanCode>(); } - huffman_assign_code(runcodes, runcodes_len, kRunCodesSize); + huffman_assign_code(huffman_codes, kRunCodesSize); - std::unique_ptr<JBig2HuffmanCode, FxFreeDeleter> SBSYMCODES( - FX_Alloc(JBig2HuffmanCode, SBNUMSYMS)); + std::vector<JBig2HuffmanCode> SBSYMCODES(SBNUMSYMS); int32_t run = 0; int32_t i = 0; - while (i < (int)SBNUMSYMS) { + while (i < static_cast<int>(SBNUMSYMS)) { size_t j; int32_t nVal = 0; int32_t nBits = 0; uint32_t nTemp; while (true) { if (pStream->read1Bit(&nTemp) != 0) - return nullptr; + return std::vector<JBig2HuffmanCode>(); nVal = (nVal << 1) | nTemp; ++nBits; for (j = 0; j < kRunCodesSize; ++j) { - if (nBits == runcodes_len[j] && nVal == runcodes[j]) + if (nBits == huffman_codes[j].codelen && nVal == huffman_codes[j].code) break; } if (j < kRunCodesSize) @@ -1285,110 +1268,58 @@ JBig2HuffmanCode* CJBig2_Context::decodeSymbolIDHuffmanTable( } int32_t runcode = static_cast<int32_t>(j); if (runcode < 32) { - SBSYMCODES.get()[i].codelen = runcode; + SBSYMCODES[i].codelen = runcode; run = 0; } else if (runcode == 32) { if (pStream->readNBits(2, &nTemp) != 0) - return nullptr; + return std::vector<JBig2HuffmanCode>(); run = nTemp + 3; } else if (runcode == 33) { if (pStream->readNBits(3, &nTemp) != 0) - return nullptr; + return std::vector<JBig2HuffmanCode>(); run = nTemp + 3; } else if (runcode == 34) { if (pStream->readNBits(7, &nTemp) != 0) - return nullptr; + return std::vector<JBig2HuffmanCode>(); run = nTemp + 11; } if (run > 0) { if (i + run > (int)SBNUMSYMS) - return nullptr; + return std::vector<JBig2HuffmanCode>(); for (int32_t k = 0; k < run; ++k) { - if (runcode == 32 && i > 0) { - SBSYMCODES.get()[i + k].codelen = SBSYMCODES.get()[i - 1].codelen; - } else { - SBSYMCODES.get()[i + k].codelen = 0; - } + if (runcode == 32 && i > 0) + SBSYMCODES[i + k].codelen = SBSYMCODES[i - 1].codelen; + else + SBSYMCODES[i + k].codelen = 0; } i += run; } else { ++i; } } - huffman_assign_code(SBSYMCODES.get(), SBNUMSYMS); - return SBSYMCODES.release(); -} - -void CJBig2_Context::huffman_assign_code(int* CODES, int* PREFLEN, int NTEMP) { - // TODO(thestig) CJBig2_HuffmanTable::parseFromCodedBuffer() has similar code. - int CURLEN, LENMAX, CURCODE, CURTEMP, i; - int* LENCOUNT; - int* FIRSTCODE; - LENMAX = 0; - for (i = 0; i < NTEMP; ++i) { - if (PREFLEN[i] > LENMAX) { - LENMAX = PREFLEN[i]; - } - } - LENCOUNT = FX_Alloc(int, LENMAX + 1); - JBIG2_memset(LENCOUNT, 0, sizeof(int) * (LENMAX + 1)); - FIRSTCODE = FX_Alloc(int, LENMAX + 1); - for (i = 0; i < NTEMP; ++i) { - ++LENCOUNT[PREFLEN[i]]; - } - CURLEN = 1; - FIRSTCODE[0] = 0; - LENCOUNT[0] = 0; - while (CURLEN <= LENMAX) { - FIRSTCODE[CURLEN] = (FIRSTCODE[CURLEN - 1] + LENCOUNT[CURLEN - 1]) << 1; - CURCODE = FIRSTCODE[CURLEN]; - CURTEMP = 0; - while (CURTEMP < NTEMP) { - if (PREFLEN[CURTEMP] == CURLEN) { - CODES[CURTEMP] = CURCODE; - CURCODE = CURCODE + 1; - } - CURTEMP = CURTEMP + 1; - } - CURLEN = CURLEN + 1; - } - FX_Free(LENCOUNT); - FX_Free(FIRSTCODE); + huffman_assign_code(SBSYMCODES.data(), SBNUMSYMS); + return SBSYMCODES; } void CJBig2_Context::huffman_assign_code(JBig2HuffmanCode* SBSYMCODES, int NTEMP) { - int CURLEN, LENMAX, CURCODE, CURTEMP, i; - int* LENCOUNT; - int* FIRSTCODE; - LENMAX = 0; - for (i = 0; i < NTEMP; ++i) { - if (SBSYMCODES[i].codelen > LENMAX) { - LENMAX = SBSYMCODES[i].codelen; - } - } - LENCOUNT = FX_Alloc(int, (LENMAX + 1)); - JBIG2_memset(LENCOUNT, 0, sizeof(int) * (LENMAX + 1)); - FIRSTCODE = FX_Alloc(int, (LENMAX + 1)); - for (i = 0; i < NTEMP; ++i) { + // TODO(thestig) CJBig2_HuffmanTable::parseFromCodedBuffer() has similar code. + int LENMAX = 0; + for (int i = 0; i < NTEMP; ++i) + LENMAX = std::max(LENMAX, SBSYMCODES[i].codelen); + std::vector<int> LENCOUNT(LENMAX + 1); + std::vector<int> FIRSTCODE(LENMAX + 1); + for (int i = 0; i < NTEMP; ++i) ++LENCOUNT[SBSYMCODES[i].codelen]; - } - CURLEN = 1; - FIRSTCODE[0] = 0; LENCOUNT[0] = 0; - while (CURLEN <= LENMAX) { + for (int CURLEN = 1; CURLEN <= LENMAX; ++CURLEN) { FIRSTCODE[CURLEN] = (FIRSTCODE[CURLEN - 1] + LENCOUNT[CURLEN - 1]) << 1; - CURCODE = FIRSTCODE[CURLEN]; - CURTEMP = 0; - while (CURTEMP < NTEMP) { + int CURCODE = FIRSTCODE[CURLEN]; + for (int CURTEMP = 0; CURTEMP < NTEMP; ++CURTEMP) { if (SBSYMCODES[CURTEMP].codelen == CURLEN) { SBSYMCODES[CURTEMP].code = CURCODE; CURCODE = CURCODE + 1; } - CURTEMP = CURTEMP + 1; } - CURLEN = CURLEN + 1; } - FX_Free(LENCOUNT); - FX_Free(FIRSTCODE); } diff --git a/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_Context.h b/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_Context.h index 4151fa356e3..9224d325b5d 100644 --- a/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_Context.h +++ b/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_Context.h @@ -43,7 +43,6 @@ class CJBig2_Context { CJBig2_Context(const CFX_RetainPtr<CPDF_StreamAcc>& pGlobalStream, const CFX_RetainPtr<CPDF_StreamAcc>& pSrcStream, std::list<CJBig2_CachePair>* pSymbolDictCache, - IFX_Pause* pPause, bool bIsGlobal); ~CJBig2_Context(); @@ -80,10 +79,10 @@ class CJBig2_Context { int32_t parseTable(CJBig2_Segment* pSegment); int32_t parseRegionInfo(JBig2RegionInfo* pRI); - JBig2HuffmanCode* decodeSymbolIDHuffmanTable(CJBig2_BitStream* pStream, - uint32_t SBNUMSYMS); + std::vector<JBig2HuffmanCode> decodeSymbolIDHuffmanTable( + CJBig2_BitStream* pStream, + uint32_t SBNUMSYMS); - void huffman_assign_code(int* CODES, int* PREFLEN, int NTEMP); void huffman_assign_code(JBig2HuffmanCode* SBSYMCODES, int NTEMP); std::unique_ptr<CJBig2_Context> m_pGlobalContext; @@ -95,7 +94,6 @@ class CJBig2_Context { bool m_bInPage; bool m_bBufSpecified; int32_t m_PauseStep; - CFX_UnownedPtr<IFX_Pause> const m_pPause; FXCODEC_STATUS m_ProcessingStatus; std::vector<JBig2ArithCtx> m_gbContext; std::unique_ptr<CJBig2_ArithDecoder> m_pArithDecoder; diff --git a/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_GrdProc.cpp b/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_GrdProc.cpp index 0d9f991d4c6..764723bc6dd 100644 --- a/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_GrdProc.cpp +++ b/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_GrdProc.cpp @@ -7,6 +7,7 @@ #include "core/fxcodec/jbig2/JBig2_GrdProc.h" #include <memory> +#include <utility> #include "core/fxcodec/fx_codec.h" #include "core/fxcodec/jbig2/JBig2_ArithDecoder.h" @@ -25,6 +26,8 @@ CJBig2_GRDProc::CJBig2_GRDProc() m_ReplaceRect.right = 0; } +CJBig2_GRDProc::~CJBig2_GRDProc() {} + bool CJBig2_GRDProc::UseTemplate0Opt3() const { return (GBAT[0] == 3) && (GBAT[1] == -1) && (GBAT[2] == -3) && (GBAT[3] == -1) && (GBAT[4] == 2) && (GBAT[5] == -2) && @@ -39,10 +42,11 @@ bool CJBig2_GRDProc::UseTemplate23Opt3() const { return (GBAT[0] == 2) && (GBAT[1] == -1); } -CJBig2_Image* CJBig2_GRDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder, - JBig2ArithCtx* gbContext) { +std::unique_ptr<CJBig2_Image> CJBig2_GRDProc::decode_Arith( + CJBig2_ArithDecoder* pArithDecoder, + JBig2ArithCtx* gbContext) { if (GBW == 0 || GBH == 0) - return new CJBig2_Image(GBW, GBH); + return pdfium::MakeUnique<CJBig2_Image>(GBW, GBH); if (GBTEMPLATE == 0) { if (UseTemplate0Opt3()) @@ -62,7 +66,8 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder, return decode_Arith_Template3_unopt(pArithDecoder, gbContext); } } -CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template0_opt3( + +std::unique_ptr<CJBig2_Image> CJBig2_GRDProc::decode_Arith_Template0_opt3( CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* gbContext) { auto GBREG = pdfium::MakeUnique<CJBig2_Image>(GBW, GBH); @@ -157,10 +162,10 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template0_opt3( } pLine += nStride; } - return GBREG.release(); + return GBREG; } -CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template0_unopt( +std::unique_ptr<CJBig2_Image> CJBig2_GRDProc::decode_Arith_Template0_unopt( CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* gbContext) { int LTP = 0; @@ -208,10 +213,10 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template0_unopt( } } } - return GBREG.release(); + return GBREG; } -CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template1_opt3( +std::unique_ptr<CJBig2_Image> CJBig2_GRDProc::decode_Arith_Template1_opt3( CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* gbContext) { auto GBREG = pdfium::MakeUnique<CJBig2_Image>(GBW, GBH); @@ -305,10 +310,10 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template1_opt3( } pLine += nStride; } - return GBREG.release(); + return GBREG; } -CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template1_unopt( +std::unique_ptr<CJBig2_Image> CJBig2_GRDProc::decode_Arith_Template1_unopt( CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* gbContext) { int LTP = 0; @@ -354,10 +359,10 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template1_unopt( } } } - return GBREG.release(); + return GBREG; } -CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template2_opt3( +std::unique_ptr<CJBig2_Image> CJBig2_GRDProc::decode_Arith_Template2_opt3( CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* gbContext) { auto GBREG = pdfium::MakeUnique<CJBig2_Image>(GBW, GBH); @@ -451,10 +456,10 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template2_opt3( } pLine += nStride; } - return GBREG.release(); + return GBREG; } -CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template2_unopt( +std::unique_ptr<CJBig2_Image> CJBig2_GRDProc::decode_Arith_Template2_unopt( CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* gbContext) { int LTP = 0; @@ -498,10 +503,10 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template2_unopt( } } } - return GBREG.release(); + return GBREG; } -CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template3_opt3( +std::unique_ptr<CJBig2_Image> CJBig2_GRDProc::decode_Arith_Template3_opt3( CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* gbContext) { auto GBREG = pdfium::MakeUnique<CJBig2_Image>(GBW, GBH); @@ -583,10 +588,10 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template3_opt3( } pLine += nStride; } - return GBREG.release(); + return GBREG; } -CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template3_unopt( +std::unique_ptr<CJBig2_Image> CJBig2_GRDProc::decode_Arith_Template3_unopt( CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* gbContext) { int LTP = 0; @@ -626,11 +631,11 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template3_unopt( } } } - return GBREG.release(); + return GBREG; } FXCODEC_STATUS CJBig2_GRDProc::Start_decode_Arith( - CJBig2_Image** pImage, + std::unique_ptr<CJBig2_Image>* pImage, CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* gbContext, IFX_Pause* pPause) { @@ -640,92 +645,93 @@ FXCODEC_STATUS CJBig2_GRDProc::Start_decode_Arith( } m_ProssiveStatus = FXCODEC_STATUS_DECODE_READY; if (!*pImage) - *pImage = new CJBig2_Image(GBW, GBH); + *pImage = pdfium::MakeUnique<CJBig2_Image>(GBW, GBH); if (!(*pImage)->m_pData) { - delete *pImage; *pImage = nullptr; m_ProssiveStatus = FXCODEC_STATUS_ERROR; return FXCODEC_STATUS_ERROR; } m_DecodeType = 1; - m_pImage = pImage; - (*m_pImage)->fill(0); - m_pArithDecoder = pArithDecoder; + m_pImage = pImage->get(); + m_pImage->fill(0); m_gbContext = gbContext; m_LTP = 0; m_pLine = nullptr; m_loopIndex = 0; - return decode_Arith(pPause); + return decode_Arith(pPause, pArithDecoder); } -FXCODEC_STATUS CJBig2_GRDProc::decode_Arith(IFX_Pause* pPause) { +FXCODEC_STATUS CJBig2_GRDProc::decode_Arith( + IFX_Pause* pPause, + CJBig2_ArithDecoder* pArithDecoder) { int iline = m_loopIndex; - CJBig2_Image* pImage = *m_pImage; if (GBTEMPLATE == 0) { if (UseTemplate0Opt3()) { - m_ProssiveStatus = decode_Arith_Template0_opt3(pImage, m_pArithDecoder, + m_ProssiveStatus = decode_Arith_Template0_opt3(m_pImage, pArithDecoder, m_gbContext, pPause); } else { - m_ProssiveStatus = decode_Arith_Template0_unopt(pImage, m_pArithDecoder, + m_ProssiveStatus = decode_Arith_Template0_unopt(m_pImage, pArithDecoder, m_gbContext, pPause); } } else if (GBTEMPLATE == 1) { if (UseTemplate1Opt3()) { - m_ProssiveStatus = decode_Arith_Template1_opt3(pImage, m_pArithDecoder, + m_ProssiveStatus = decode_Arith_Template1_opt3(m_pImage, pArithDecoder, m_gbContext, pPause); } else { - m_ProssiveStatus = decode_Arith_Template1_unopt(pImage, m_pArithDecoder, + m_ProssiveStatus = decode_Arith_Template1_unopt(m_pImage, pArithDecoder, m_gbContext, pPause); } } else if (GBTEMPLATE == 2) { if (UseTemplate23Opt3()) { - m_ProssiveStatus = decode_Arith_Template2_opt3(pImage, m_pArithDecoder, + m_ProssiveStatus = decode_Arith_Template2_opt3(m_pImage, pArithDecoder, m_gbContext, pPause); } else { - m_ProssiveStatus = decode_Arith_Template2_unopt(pImage, m_pArithDecoder, + m_ProssiveStatus = decode_Arith_Template2_unopt(m_pImage, pArithDecoder, m_gbContext, pPause); } } else { if (UseTemplate23Opt3()) { - m_ProssiveStatus = decode_Arith_Template3_opt3(pImage, m_pArithDecoder, + m_ProssiveStatus = decode_Arith_Template3_opt3(m_pImage, pArithDecoder, m_gbContext, pPause); } else { - m_ProssiveStatus = decode_Arith_Template3_unopt(pImage, m_pArithDecoder, + m_ProssiveStatus = decode_Arith_Template3_unopt(m_pImage, pArithDecoder, m_gbContext, pPause); } } m_ReplaceRect.left = 0; - m_ReplaceRect.right = pImage->width(); + m_ReplaceRect.right = m_pImage->width(); m_ReplaceRect.top = iline; m_ReplaceRect.bottom = m_loopIndex; - if (m_ProssiveStatus == FXCODEC_STATUS_DECODE_FINISH) { + if (m_ProssiveStatus == FXCODEC_STATUS_DECODE_FINISH) m_loopIndex = 0; - } + return m_ProssiveStatus; } -FXCODEC_STATUS CJBig2_GRDProc::Start_decode_MMR(CJBig2_Image** pImage, - CJBig2_BitStream* pStream) { +FXCODEC_STATUS CJBig2_GRDProc::Start_decode_MMR( + std::unique_ptr<CJBig2_Image>* pImage, + CJBig2_BitStream* pStream) { int bitpos, i; - *pImage = new CJBig2_Image(GBW, GBH); - if (!(*pImage)->m_pData) { - delete (*pImage); - (*pImage) = nullptr; + auto image = pdfium::MakeUnique<CJBig2_Image>(GBW, GBH); + if (!image->m_pData) { + *pImage = nullptr; m_ProssiveStatus = FXCODEC_STATUS_ERROR; return m_ProssiveStatus; } - bitpos = (int)pStream->getBitPos(); - FaxG4Decode(pStream->getBuf(), pStream->getLength(), &bitpos, - (*pImage)->m_pData, GBW, GBH, (*pImage)->stride()); + bitpos = static_cast<int>(pStream->getBitPos()); + FaxG4Decode(pStream->getBuf(), pStream->getLength(), &bitpos, image->m_pData, + GBW, GBH, image->stride()); pStream->setBitPos(bitpos); - for (i = 0; (uint32_t)i < (*pImage)->stride() * GBH; i++) { - (*pImage)->m_pData[i] = ~(*pImage)->m_pData[i]; - } + for (i = 0; (uint32_t)i < image->stride() * GBH; ++i) + image->m_pData[i] = ~image->m_pData[i]; m_ProssiveStatus = FXCODEC_STATUS_DECODE_FINISH; + *pImage = std::move(image); return m_ProssiveStatus; } -FXCODEC_STATUS CJBig2_GRDProc::Continue_decode(IFX_Pause* pPause) { +FXCODEC_STATUS CJBig2_GRDProc::Continue_decode( + IFX_Pause* pPause, + CJBig2_ArithDecoder* pArithDecoder) { if (m_ProssiveStatus != FXCODEC_STATUS_DECODE_TOBECONTINUE) return m_ProssiveStatus; @@ -733,8 +739,7 @@ FXCODEC_STATUS CJBig2_GRDProc::Continue_decode(IFX_Pause* pPause) { m_ProssiveStatus = FXCODEC_STATUS_ERROR; return m_ProssiveStatus; } - - return decode_Arith(pPause); + return decode_Arith(pPause, pArithDecoder); } FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template0_opt3( diff --git a/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_GrdProc.h b/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_GrdProc.h index 447447fe8bc..ef02a7d45aa 100644 --- a/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_GrdProc.h +++ b/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_GrdProc.h @@ -7,7 +7,10 @@ #ifndef CORE_FXCODEC_JBIG2_JBIG2_GRDPROC_H_ #define CORE_FXCODEC_JBIG2_JBIG2_GRDPROC_H_ +#include <memory> + #include "core/fxcodec/fx_codec_def.h" +#include "core/fxcrt/cfx_unowned_ptr.h" #include "core/fxcrt/fx_coordinates.h" #include "core/fxcrt/fx_system.h" @@ -20,17 +23,19 @@ struct JBig2ArithCtx; class CJBig2_GRDProc { public: CJBig2_GRDProc(); + ~CJBig2_GRDProc(); - CJBig2_Image* decode_Arith(CJBig2_ArithDecoder* pArithDecoder, - JBig2ArithCtx* gbContext); + std::unique_ptr<CJBig2_Image> decode_Arith(CJBig2_ArithDecoder* pArithDecoder, + JBig2ArithCtx* gbContext); - FXCODEC_STATUS Start_decode_Arith(CJBig2_Image** pImage, + FXCODEC_STATUS Start_decode_Arith(std::unique_ptr<CJBig2_Image>* pImage, CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* gbContext, IFX_Pause* pPause); - FXCODEC_STATUS Start_decode_MMR(CJBig2_Image** pImage, + FXCODEC_STATUS Start_decode_MMR(std::unique_ptr<CJBig2_Image>* pImage, CJBig2_BitStream* pStream); - FXCODEC_STATUS Continue_decode(IFX_Pause* pPause); + FXCODEC_STATUS Continue_decode(IFX_Pause* pPause, + CJBig2_ArithDecoder* pArithDecoder); FX_RECT GetReplaceRect() const { return m_ReplaceRect; } bool MMR; @@ -47,7 +52,8 @@ class CJBig2_GRDProc { bool UseTemplate1Opt3() const; bool UseTemplate23Opt3() const; - FXCODEC_STATUS decode_Arith(IFX_Pause* pPause); + FXCODEC_STATUS decode_Arith(IFX_Pause* pPause, + CJBig2_ArithDecoder* pArithDecoder); FXCODEC_STATUS decode_Arith_Template0_opt3(CJBig2_Image* pImage, CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* gbContext, @@ -84,35 +90,42 @@ class CJBig2_GRDProc { CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* gbContext, IFX_Pause* pPause); - CJBig2_Image* decode_Arith_Template0_opt3(CJBig2_ArithDecoder* pArithDecoder, - JBig2ArithCtx* gbContext); + std::unique_ptr<CJBig2_Image> decode_Arith_Template0_opt3( + CJBig2_ArithDecoder* pArithDecoder, + JBig2ArithCtx* gbContext); - CJBig2_Image* decode_Arith_Template0_unopt(CJBig2_ArithDecoder* pArithDecoder, - JBig2ArithCtx* gbContext); + std::unique_ptr<CJBig2_Image> decode_Arith_Template0_unopt( + CJBig2_ArithDecoder* pArithDecoder, + JBig2ArithCtx* gbContext); - CJBig2_Image* decode_Arith_Template1_opt3(CJBig2_ArithDecoder* pArithDecoder, - JBig2ArithCtx* gbContext); + std::unique_ptr<CJBig2_Image> decode_Arith_Template1_opt3( + CJBig2_ArithDecoder* pArithDecoder, + JBig2ArithCtx* gbContext); - CJBig2_Image* decode_Arith_Template1_unopt(CJBig2_ArithDecoder* pArithDecoder, - JBig2ArithCtx* gbContext); + std::unique_ptr<CJBig2_Image> decode_Arith_Template1_unopt( + CJBig2_ArithDecoder* pArithDecoder, + JBig2ArithCtx* gbContext); - CJBig2_Image* decode_Arith_Template2_opt3(CJBig2_ArithDecoder* pArithDecoder, - JBig2ArithCtx* gbContext); + std::unique_ptr<CJBig2_Image> decode_Arith_Template2_opt3( + CJBig2_ArithDecoder* pArithDecoder, + JBig2ArithCtx* gbContext); - CJBig2_Image* decode_Arith_Template2_unopt(CJBig2_ArithDecoder* pArithDecoder, - JBig2ArithCtx* gbContext); + std::unique_ptr<CJBig2_Image> decode_Arith_Template2_unopt( + CJBig2_ArithDecoder* pArithDecoder, + JBig2ArithCtx* gbContext); - CJBig2_Image* decode_Arith_Template3_opt3(CJBig2_ArithDecoder* pArithDecoder, - JBig2ArithCtx* gbContext); + std::unique_ptr<CJBig2_Image> decode_Arith_Template3_opt3( + CJBig2_ArithDecoder* pArithDecoder, + JBig2ArithCtx* gbContext); - CJBig2_Image* decode_Arith_Template3_unopt(CJBig2_ArithDecoder* pArithDecoder, - JBig2ArithCtx* gbContext); + std::unique_ptr<CJBig2_Image> decode_Arith_Template3_unopt( + CJBig2_ArithDecoder* pArithDecoder, + JBig2ArithCtx* gbContext); uint32_t m_loopIndex; uint8_t* m_pLine; FXCODEC_STATUS m_ProssiveStatus; - CJBig2_Image** m_pImage; - CJBig2_ArithDecoder* m_pArithDecoder; + CJBig2_Image* m_pImage; JBig2ArithCtx* m_gbContext; uint16_t m_DecodeType; int m_LTP; diff --git a/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_GrrdProc.cpp b/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_GrrdProc.cpp index 936b851d37f..11fa39945dd 100644 --- a/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_GrrdProc.cpp +++ b/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_GrrdProc.cpp @@ -13,10 +13,11 @@ #include "core/fxcodec/jbig2/JBig2_Image.h" #include "third_party/base/ptr_util.h" -CJBig2_Image* CJBig2_GRRDProc::decode(CJBig2_ArithDecoder* pArithDecoder, - JBig2ArithCtx* grContext) { +std::unique_ptr<CJBig2_Image> CJBig2_GRRDProc::decode( + CJBig2_ArithDecoder* pArithDecoder, + JBig2ArithCtx* grContext) { if (GRW == 0 || GRH == 0) - return new CJBig2_Image(GRW, GRH); + return pdfium::MakeUnique<CJBig2_Image>(GRW, GRH); if (!GRTEMPLATE) { if ((GRAT[0] == -1) && (GRAT[1] == -1) && (GRAT[2] == -1) && @@ -29,10 +30,11 @@ CJBig2_Image* CJBig2_GRRDProc::decode(CJBig2_ArithDecoder* pArithDecoder, if ((GRREFERENCEDX == 0) && (GRW == (uint32_t)GRREFERENCE->width())) return decode_Template1_opt(pArithDecoder, grContext); + return decode_Template1_unopt(pArithDecoder, grContext); } -CJBig2_Image* CJBig2_GRRDProc::decode_Template0_unopt( +std::unique_ptr<CJBig2_Image> CJBig2_GRRDProc::decode_Template0_unopt( CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* grContext) { int LTP = 0; @@ -145,10 +147,10 @@ CJBig2_Image* CJBig2_GRRDProc::decode_Template0_unopt( } } } - return GRREG.release(); + return GRREG; } -CJBig2_Image* CJBig2_GRRDProc::decode_Template0_opt( +std::unique_ptr<CJBig2_Image> CJBig2_GRRDProc::decode_Template0_opt( CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* grContext) { if (!GRREFERENCE->m_pData) @@ -273,14 +275,13 @@ CJBig2_Image* CJBig2_GRRDProc::decode_Template0_opt( } } pLine += nStride; - if (h < GRHR + GRREFERENCEDY) { + if (h < GRHR + GRREFERENCEDY) pLineR += nStrideR; - } } - return GRREG.release(); + return GRREG; } -CJBig2_Image* CJBig2_GRRDProc::decode_Template1_unopt( +std::unique_ptr<CJBig2_Image> CJBig2_GRRDProc::decode_Template1_unopt( CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* grContext) { int LTP = 0; @@ -379,10 +380,10 @@ CJBig2_Image* CJBig2_GRRDProc::decode_Template1_unopt( } } } - return GRREG.release(); + return GRREG; } -CJBig2_Image* CJBig2_GRRDProc::decode_Template1_opt( +std::unique_ptr<CJBig2_Image> CJBig2_GRRDProc::decode_Template1_opt( CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* grContext) { if (!GRREFERENCE->m_pData) @@ -496,9 +497,8 @@ CJBig2_Image* CJBig2_GRRDProc::decode_Template1_opt( } } pLine += nStride; - if (h < GRHR + GRREFERENCEDY) { + if (h < GRHR + GRREFERENCEDY) pLineR += nStrideR; - } } - return GRREG.release(); + return GRREG; } diff --git a/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_GrrdProc.h b/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_GrrdProc.h index bdb49d7e917..43f535335d4 100644 --- a/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_GrrdProc.h +++ b/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_GrrdProc.h @@ -7,6 +7,8 @@ #ifndef CORE_FXCODEC_JBIG2_JBIG2_GRRDPROC_H_ #define CORE_FXCODEC_JBIG2_JBIG2_GRRDPROC_H_ +#include <memory> + #include "core/fxcrt/fx_system.h" class CJBig2_ArithDecoder; @@ -15,21 +17,9 @@ struct JBig2ArithCtx; class CJBig2_GRRDProc { public: - CJBig2_Image* decode(CJBig2_ArithDecoder* pArithDecoder, - JBig2ArithCtx* grContext); - - CJBig2_Image* decode_Template0_unopt(CJBig2_ArithDecoder* pArithDecoder, - JBig2ArithCtx* grContext); - - CJBig2_Image* decode_Template0_opt(CJBig2_ArithDecoder* pArithDecoder, - JBig2ArithCtx* grContext); - - CJBig2_Image* decode_Template1_unopt(CJBig2_ArithDecoder* pArithDecoder, + std::unique_ptr<CJBig2_Image> decode(CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* grContext); - CJBig2_Image* decode_Template1_opt(CJBig2_ArithDecoder* pArithDecoder, - JBig2ArithCtx* grContext); - uint32_t GRW; uint32_t GRH; bool GRTEMPLATE; @@ -38,6 +28,23 @@ class CJBig2_GRRDProc { int32_t GRREFERENCEDY; bool TPGRON; int8_t GRAT[4]; + + private: + std::unique_ptr<CJBig2_Image> decode_Template0_unopt( + CJBig2_ArithDecoder* pArithDecoder, + JBig2ArithCtx* grContext); + + std::unique_ptr<CJBig2_Image> decode_Template0_opt( + CJBig2_ArithDecoder* pArithDecoder, + JBig2ArithCtx* grContext); + + std::unique_ptr<CJBig2_Image> decode_Template1_unopt( + CJBig2_ArithDecoder* pArithDecoder, + JBig2ArithCtx* grContext); + + std::unique_ptr<CJBig2_Image> decode_Template1_opt( + CJBig2_ArithDecoder* pArithDecoder, + JBig2ArithCtx* grContext); }; #endif // CORE_FXCODEC_JBIG2_JBIG2_GRRDPROC_H_ diff --git a/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_GsidProc.cpp b/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_GsidProc.cpp deleted file mode 100644 index 0f0a16da1be..00000000000 --- a/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_GsidProc.cpp +++ /dev/null @@ -1,112 +0,0 @@ -// Copyright 2015 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/fxcodec/jbig2/JBig2_GsidProc.h" - -#include <memory> -#include <vector> - -#include "core/fxcodec/jbig2/JBig2_BitStream.h" -#include "core/fxcodec/jbig2/JBig2_GrdProc.h" -#include "core/fxcodec/jbig2/JBig2_Image.h" -#include "core/fxcrt/fx_basic.h" -#include "third_party/base/ptr_util.h" - -uint32_t* CJBig2_GSIDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder, - JBig2ArithCtx* gbContext, - IFX_Pause* pPause) { - auto pGRD = pdfium::MakeUnique<CJBig2_GRDProc>(); - pGRD->MMR = GSMMR; - pGRD->GBW = GSW; - pGRD->GBH = GSH; - pGRD->GBTEMPLATE = GSTEMPLATE; - pGRD->TPGDON = 0; - pGRD->USESKIP = GSUSESKIP; - pGRD->SKIP = GSKIP; - if (GSTEMPLATE <= 1) { - pGRD->GBAT[0] = 3; - } else { - pGRD->GBAT[0] = 2; - } - pGRD->GBAT[1] = -1; - if (pGRD->GBTEMPLATE == 0) { - pGRD->GBAT[2] = -3; - pGRD->GBAT[3] = -1; - pGRD->GBAT[4] = 2; - pGRD->GBAT[5] = -2; - pGRD->GBAT[6] = -2; - pGRD->GBAT[7] = -2; - } - - std::vector<std::unique_ptr<CJBig2_Image>> GSPLANES(GSBPP); - for (int32_t i = GSBPP - 1; i >= 0; --i) { - CJBig2_Image* pImage = nullptr; - FXCODEC_STATUS status = - pGRD->Start_decode_Arith(&pImage, pArithDecoder, gbContext, nullptr); - while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) - status = pGRD->Continue_decode(pPause); - - if (!pImage) - return nullptr; - - GSPLANES[i].reset(pImage); - if (i < GSBPP - 1) - pImage->composeFrom(0, 0, GSPLANES[i + 1].get(), JBIG2_COMPOSE_XOR); - } - std::unique_ptr<uint32_t, FxFreeDeleter> GSVALS( - FX_Alloc2D(uint32_t, GSW, GSH)); - JBIG2_memset(GSVALS.get(), 0, sizeof(uint32_t) * GSW * GSH); - for (uint32_t y = 0; y < GSH; ++y) { - for (uint32_t x = 0; x < GSW; ++x) { - for (int32_t i = 0; i < GSBPP; ++i) - GSVALS.get()[y * GSW + x] |= GSPLANES[i]->getPixel(x, y) << i; - } - } - return GSVALS.release(); -} - -uint32_t* CJBig2_GSIDProc::decode_MMR(CJBig2_BitStream* pStream) { - auto pGRD = pdfium::MakeUnique<CJBig2_GRDProc>(); - pGRD->MMR = GSMMR; - pGRD->GBW = GSW; - pGRD->GBH = GSH; - - std::unique_ptr<CJBig2_Image*> GSPLANES(FX_Alloc(CJBig2_Image*, GSBPP)); - JBIG2_memset(GSPLANES.get(), 0, sizeof(CJBig2_Image*) * GSBPP); - pGRD->Start_decode_MMR(&GSPLANES.get()[GSBPP - 1], pStream); - if (!GSPLANES.get()[GSBPP - 1]) - return nullptr; - - pStream->alignByte(); - pStream->offset(3); - int32_t J = GSBPP - 2; - while (J >= 0) { - pGRD->Start_decode_MMR(&GSPLANES.get()[J], pStream); - if (!GSPLANES.get()[J]) { - for (int32_t K = GSBPP - 1; K > J; --K) - delete GSPLANES.get()[K]; - return nullptr; - } - pStream->alignByte(); - pStream->offset(3); - GSPLANES.get()[J]->composeFrom(0, 0, GSPLANES.get()[J + 1], - JBIG2_COMPOSE_XOR); - J = J - 1; - } - std::unique_ptr<uint32_t> GSVALS(FX_Alloc2D(uint32_t, GSW, GSH)); - JBIG2_memset(GSVALS.get(), 0, sizeof(uint32_t) * GSW * GSH); - for (uint32_t y = 0; y < GSH; ++y) { - for (uint32_t x = 0; x < GSW; ++x) { - for (J = 0; J < GSBPP; ++J) { - GSVALS.get()[y * GSW + x] |= GSPLANES.get()[J]->getPixel(x, y) << J; - } - } - } - for (J = 0; J < GSBPP; ++J) { - delete GSPLANES.get()[J]; - } - return GSVALS.release(); -} diff --git a/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_GsidProc.h b/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_GsidProc.h deleted file mode 100644 index 45e759968e4..00000000000 --- a/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_GsidProc.h +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2015 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 - -#ifndef CORE_FXCODEC_JBIG2_JBIG2_GSIDPROC_H_ -#define CORE_FXCODEC_JBIG2_JBIG2_GSIDPROC_H_ - -#include "core/fxcrt/fx_system.h" - -class CJBig2_ArithDecoder; -class CJBig2_BitStream; -class CJBig2_Image; -class IFX_Pause; -struct JBig2ArithCtx; - -class CJBig2_GSIDProc { - public: - uint32_t* decode_Arith(CJBig2_ArithDecoder* pArithDecoder, - JBig2ArithCtx* gbContext, - IFX_Pause* pPause); - - uint32_t* decode_MMR(CJBig2_BitStream* pStream); - - public: - bool GSMMR; - bool GSUSESKIP; - uint8_t GSBPP; - uint32_t GSW; - uint32_t GSH; - uint8_t GSTEMPLATE; - CJBig2_Image* GSKIP; -}; - -#endif // CORE_FXCODEC_JBIG2_JBIG2_GSIDPROC_H_ diff --git a/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_HtrdProc.cpp b/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_HtrdProc.cpp index 1e8710b417d..11070c11b92 100644 --- a/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_HtrdProc.cpp +++ b/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_HtrdProc.cpp @@ -6,30 +6,28 @@ #include "core/fxcodec/jbig2/JBig2_HtrdProc.h" -#include <memory> +#include <algorithm> +#include <utility> -#include "core/fxcodec/jbig2/JBig2_GsidProc.h" +#include "core/fxcodec/jbig2/JBig2_BitStream.h" +#include "core/fxcodec/jbig2/JBig2_GrdProc.h" +#include "core/fxcodec/jbig2/JBig2_Image.h" #include "core/fxcrt/fx_basic.h" #include "third_party/base/ptr_util.h" -CJBig2_Image* CJBig2_HTRDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder, - JBig2ArithCtx* gbContext, - IFX_Pause* pPause) { - uint32_t ng, mg; - int32_t x, y; - uint32_t HBPP; - uint32_t* GI; +std::unique_ptr<CJBig2_Image> CJBig2_HTRDProc::decode_Arith( + CJBig2_ArithDecoder* pArithDecoder, + JBig2ArithCtx* gbContext, + IFX_Pause* pPause) { std::unique_ptr<CJBig2_Image> HSKIP; - auto HTREG = pdfium::MakeUnique<CJBig2_Image>(HBW, HBH); - HTREG->fill(HDEFPIXEL); if (HENABLESKIP == 1) { HSKIP = pdfium::MakeUnique<CJBig2_Image>(HGW, HGH); - for (mg = 0; mg < HGH; mg++) { - for (ng = 0; ng < HGW; ng++) { - x = (HGX + mg * HRY + ng * HRX) >> 8; - y = (HGY + mg * HRX - ng * HRY) >> 8; - if ((x + HPW <= 0) | (x >= (int32_t)HBW) | (y + HPH <= 0) | - (y >= (int32_t)HPH)) { + for (uint32_t mg = 0; mg < HGH; ++mg) { + for (uint32_t ng = 0; ng < HGW; ++ng) { + int32_t x = (HGX + mg * HRY + ng * HRX) >> 8; + int32_t y = (HGY + mg * HRX - ng * HRY) >> 8; + if ((x + HPW <= 0) | (x >= static_cast<int32_t>(HBW)) | (y + HPH <= 0) | + (y >= static_cast<int32_t>(HPH))) { HSKIP->setPixel(ng, mg, 1); } else { HSKIP->setPixel(ng, mg, 0); @@ -37,68 +35,100 @@ CJBig2_Image* CJBig2_HTRDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder, } } } - HBPP = 1; - while ((uint32_t)(1 << HBPP) < HNUMPATS) { - HBPP++; + uint32_t HBPP = 1; + while (static_cast<uint32_t>(1 << HBPP) < HNUMPATS) + ++HBPP; + + CJBig2_GRDProc GRD; + GRD.MMR = HMMR; + GRD.GBW = HGW; + GRD.GBH = HGH; + GRD.GBTEMPLATE = HTEMPLATE; + GRD.TPGDON = 0; + GRD.USESKIP = HENABLESKIP; + GRD.SKIP = HSKIP.get(); + if (HTEMPLATE <= 1) + GRD.GBAT[0] = 3; + else + GRD.GBAT[0] = 2; + GRD.GBAT[1] = -1; + if (GRD.GBTEMPLATE == 0) { + GRD.GBAT[2] = -3; + GRD.GBAT[3] = -1; + GRD.GBAT[4] = 2; + GRD.GBAT[5] = -2; + GRD.GBAT[6] = -2; + GRD.GBAT[7] = -2; } - auto pGID = pdfium::MakeUnique<CJBig2_GSIDProc>(); - pGID->GSMMR = HMMR; - pGID->GSW = HGW; - pGID->GSH = HGH; - pGID->GSBPP = (uint8_t)HBPP; - pGID->GSUSESKIP = HENABLESKIP; - pGID->GSKIP = HSKIP.get(); - pGID->GSTEMPLATE = HTEMPLATE; - GI = pGID->decode_Arith(pArithDecoder, gbContext, pPause); - if (!GI) + + uint8_t GSBPP = static_cast<uint8_t>(HBPP); + std::vector<std::unique_ptr<CJBig2_Image>> GSPLANES(GSBPP); + for (int32_t i = GSBPP - 1; i >= 0; --i) { + std::unique_ptr<CJBig2_Image> pImage; + FXCODEC_STATUS status = + GRD.Start_decode_Arith(&pImage, pArithDecoder, gbContext, nullptr); + while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) + status = GRD.Continue_decode(pPause, pArithDecoder); + + if (!pImage) + return nullptr; + + GSPLANES[i] = std::move(pImage); + if (i < GSBPP - 1) + GSPLANES[i]->composeFrom(0, 0, GSPLANES[i + 1].get(), JBIG2_COMPOSE_XOR); + } + return decode_image(GSPLANES); +} + +std::unique_ptr<CJBig2_Image> CJBig2_HTRDProc::decode_MMR( + CJBig2_BitStream* pStream) { + uint32_t HBPP = 1; + while (static_cast<uint32_t>(1 << HBPP) < HNUMPATS) + ++HBPP; + + CJBig2_GRDProc GRD; + GRD.MMR = HMMR; + GRD.GBW = HGW; + GRD.GBH = HGH; + + uint8_t GSBPP = static_cast<uint8_t>(HBPP); + std::vector<std::unique_ptr<CJBig2_Image>> GSPLANES(GSBPP); + GRD.Start_decode_MMR(&GSPLANES[GSBPP - 1], pStream); + if (!GSPLANES[GSBPP - 1]) return nullptr; - for (mg = 0; mg < HGH; mg++) { - for (ng = 0; ng < HGW; ng++) { - x = (HGX + mg * HRY + ng * HRX) >> 8; - y = (HGY + mg * HRX - ng * HRY) >> 8; - uint32_t pat_index = GI[mg * HGW + ng]; - if (pat_index >= HNUMPATS) { - pat_index = HNUMPATS - 1; - } - HTREG->composeFrom(x, y, HPATS[pat_index], HCOMBOP); - } + pStream->alignByte(); + pStream->offset(3); + for (int32_t J = GSBPP - 2; J >= 0; --J) { + GRD.Start_decode_MMR(&GSPLANES[J], pStream); + if (!GSPLANES[J]) + return nullptr; + + pStream->alignByte(); + pStream->offset(3); + GSPLANES[J]->composeFrom(0, 0, GSPLANES[J + 1].get(), JBIG2_COMPOSE_XOR); } - FX_Free(GI); - return HTREG.release(); + return decode_image(GSPLANES); } -CJBig2_Image* CJBig2_HTRDProc::decode_MMR(CJBig2_BitStream* pStream) { - uint32_t ng, mg; - int32_t x, y; - uint32_t* GI; +std::unique_ptr<CJBig2_Image> CJBig2_HTRDProc::decode_image( + const std::vector<std::unique_ptr<CJBig2_Image>>& GSPLANES) { auto HTREG = pdfium::MakeUnique<CJBig2_Image>(HBW, HBH); HTREG->fill(HDEFPIXEL); - uint32_t HBPP = 1; - while ((uint32_t)(1 << HBPP) < HNUMPATS) { - HBPP++; + std::vector<uint32_t> GSVALS(HGW * HGH); + for (uint32_t y = 0; y < HGH; ++y) { + for (uint32_t x = 0; x < HGW; ++x) { + for (uint8_t J = 0; J < GSPLANES.size(); ++J) + GSVALS[y * HGW + x] |= GSPLANES[J]->getPixel(x, y) << J; + } } - auto pGID = pdfium::MakeUnique<CJBig2_GSIDProc>(); - pGID->GSMMR = HMMR; - pGID->GSW = HGW; - pGID->GSH = HGH; - pGID->GSBPP = (uint8_t)HBPP; - pGID->GSUSESKIP = 0; - GI = pGID->decode_MMR(pStream); - if (!GI) - return nullptr; - - for (mg = 0; mg < HGH; mg++) { - for (ng = 0; ng < HGW; ng++) { - x = (HGX + mg * HRY + ng * HRX) >> 8; - y = (HGY + mg * HRX - ng * HRY) >> 8; - uint32_t pat_index = GI[mg * HGW + ng]; - if (pat_index >= HNUMPATS) { - pat_index = HNUMPATS - 1; - } - HTREG->composeFrom(x, y, HPATS[pat_index], HCOMBOP); + for (uint32_t mg = 0; mg < HGH; ++mg) { + for (uint32_t ng = 0; ng < HGW; ++ng) { + int32_t x = (HGX + mg * HRY + ng * HRX) >> 8; + int32_t y = (HGY + mg * HRX - ng * HRY) >> 8; + uint32_t pat_index = std::min(GSVALS[mg * HGW + ng], HNUMPATS - 1); + HTREG->composeFrom(x, y, (*HPATS)[pat_index].get(), HCOMBOP); } } - FX_Free(GI); - return HTREG.release(); + return HTREG; } diff --git a/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_HtrdProc.h b/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_HtrdProc.h index e5621230984..75041ac41b4 100644 --- a/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_HtrdProc.h +++ b/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_HtrdProc.h @@ -7,6 +7,9 @@ #ifndef CORE_FXCODEC_JBIG2_JBIG2_HTRDPROC_H_ #define CORE_FXCODEC_JBIG2_JBIG2_HTRDPROC_H_ +#include <memory> +#include <vector> + #include "core/fxcodec/jbig2/JBig2_Image.h" #include "core/fxcrt/fx_system.h" @@ -17,11 +20,11 @@ struct JBig2ArithCtx; class CJBig2_HTRDProc { public: - CJBig2_Image* decode_Arith(CJBig2_ArithDecoder* pArithDecoder, - JBig2ArithCtx* gbContext, - IFX_Pause* pPause); + std::unique_ptr<CJBig2_Image> decode_Arith(CJBig2_ArithDecoder* pArithDecoder, + JBig2ArithCtx* gbContext, + IFX_Pause* pPause); - CJBig2_Image* decode_MMR(CJBig2_BitStream* pStream); + std::unique_ptr<CJBig2_Image> decode_MMR(CJBig2_BitStream* pStream); public: uint32_t HBW; @@ -29,7 +32,7 @@ class CJBig2_HTRDProc { bool HMMR; uint8_t HTEMPLATE; uint32_t HNUMPATS; - CJBig2_Image** HPATS; + const std::vector<std::unique_ptr<CJBig2_Image>>* HPATS; bool HDEFPIXEL; JBig2ComposeOp HCOMBOP; bool HENABLESKIP; @@ -41,6 +44,10 @@ class CJBig2_HTRDProc { uint16_t HRY; uint8_t HPW; uint8_t HPH; + + private: + std::unique_ptr<CJBig2_Image> decode_image( + const std::vector<std::unique_ptr<CJBig2_Image>>& GSPLANES); }; #endif // CORE_FXCODEC_JBIG2_JBIG2_HTRDPROC_H_ diff --git a/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_Image.cpp b/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_Image.cpp index 8f935ceb1f9..f026ce660ba 100644 --- a/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_Image.cpp +++ b/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_Image.cpp @@ -9,6 +9,7 @@ #include "core/fxcodec/jbig2/JBig2_Image.h" #include "core/fxcrt/fx_coordinates.h" #include "core/fxcrt/fx_safe_types.h" +#include "third_party/base/ptr_util.h" namespace { @@ -162,32 +163,37 @@ bool CJBig2_Image::composeFrom(int32_t x, CJBig2_Image* pSrc, JBig2ComposeOp op, const FX_RECT* pSrcRect) { - if (!m_pData) { - return false; - } - return pSrc->composeTo(this, x, y, op, pSrcRect); + return m_pData ? pSrc->composeTo(this, x, y, op, pSrcRect) : false; } + #define JBIG2_GETDWORD(buf) \ ((uint32_t)(((buf)[0] << 24) | ((buf)[1] << 16) | ((buf)[2] << 8) | (buf)[3])) -CJBig2_Image* CJBig2_Image::subImage(int32_t x, - int32_t y, - int32_t w, - int32_t h) { - int32_t m, n, j; - uint8_t *pLineSrc, *pLineDst; + +std::unique_ptr<CJBig2_Image> CJBig2_Image::subImage(int32_t x, + int32_t y, + int32_t w, + int32_t h) { + int32_t m; + int32_t n; + int32_t j; + uint8_t* pLineSrc; + uint8_t* pLineDst; uint32_t wTmp; - uint8_t *pSrc, *pSrcEnd, *pDst, *pDstEnd; - if (w == 0 || h == 0) { + uint8_t* pSrc; + uint8_t* pSrcEnd; + uint8_t* pDst; + uint8_t* pDstEnd; + if (w == 0 || h == 0) return nullptr; - } - CJBig2_Image* pImage = new CJBig2_Image(w, h); + + auto pImage = pdfium::MakeUnique<CJBig2_Image>(w, h); if (!m_pData) { pImage->fill(0); return pImage; } - if (!pImage->m_pData) { + if (!pImage->m_pData) return pImage; - } + pLineSrc = m_pData + m_nStride * y; pLineDst = pImage->m_pData; m = (x >> 5) << 2; diff --git a/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_Image.h b/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_Image.h index 54529ef868d..807468aa0b8 100644 --- a/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_Image.h +++ b/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_Image.h @@ -7,6 +7,8 @@ #ifndef CORE_FXCODEC_JBIG2_JBIG2_IMAGE_H_ #define CORE_FXCODEC_JBIG2_JBIG2_IMAGE_H_ +#include <memory> + #include "core/fxcodec/jbig2/JBig2_Define.h" struct FX_RECT; @@ -60,7 +62,10 @@ class CJBig2_Image { JBig2ComposeOp op, const FX_RECT* pSrcRect); - CJBig2_Image* subImage(int32_t x, int32_t y, int32_t w, int32_t h); + std::unique_ptr<CJBig2_Image> subImage(int32_t x, + int32_t y, + int32_t w, + int32_t h); void expand(int32_t h, bool v); uint8_t* m_pData; diff --git a/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_PatternDict.cpp b/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_PatternDict.cpp index cd6a2ad3c2c..450e78a8fa4 100644 --- a/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_PatternDict.cpp +++ b/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_PatternDict.cpp @@ -8,16 +8,7 @@ #include "core/fxcrt/fx_memory.h" -CJBig2_PatternDict::CJBig2_PatternDict() { - NUMPATS = 0; - HDPATS = nullptr; -} +CJBig2_PatternDict::CJBig2_PatternDict(uint32_t dict_size) + : NUMPATS(dict_size), HDPATS(dict_size) {} -CJBig2_PatternDict::~CJBig2_PatternDict() { - if (HDPATS) { - for (uint32_t i = 0; i < NUMPATS; i++) { - delete HDPATS[i]; - } - FX_Free(HDPATS); - } -} +CJBig2_PatternDict::~CJBig2_PatternDict() {} diff --git a/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_PatternDict.h b/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_PatternDict.h index dddd4747f0b..ad55917d6b5 100644 --- a/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_PatternDict.h +++ b/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_PatternDict.h @@ -7,17 +7,20 @@ #ifndef CORE_FXCODEC_JBIG2_JBIG2_PATTERNDICT_H_ #define CORE_FXCODEC_JBIG2_JBIG2_PATTERNDICT_H_ +#include <memory> +#include <vector> + #include "core/fxcodec/jbig2/JBig2_Define.h" #include "core/fxcodec/jbig2/JBig2_Image.h" class CJBig2_PatternDict { public: - CJBig2_PatternDict(); + explicit CJBig2_PatternDict(uint32_t dict_size); ~CJBig2_PatternDict(); uint32_t NUMPATS; - CJBig2_Image** HDPATS; + std::vector<std::unique_ptr<CJBig2_Image>> HDPATS; }; #endif // CORE_FXCODEC_JBIG2_JBIG2_PATTERNDICT_H_ diff --git a/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_PddProc.cpp b/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_PddProc.cpp index e3403eec26f..e195d8f403b 100644 --- a/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_PddProc.cpp +++ b/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_PddProc.cpp @@ -13,16 +13,13 @@ #include "core/fxcodec/jbig2/JBig2_PatternDict.h" #include "third_party/base/ptr_util.h" -CJBig2_PatternDict* CJBig2_PDDProc::decode_Arith( +std::unique_ptr<CJBig2_PatternDict> CJBig2_PDDProc::decode_Arith( CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* gbContext, IFX_Pause* pPause) { uint32_t GRAY; - CJBig2_Image* BHDC = nullptr; - auto pDict = pdfium::MakeUnique<CJBig2_PatternDict>(); - pDict->NUMPATS = GRAYMAX + 1; - pDict->HDPATS = FX_Alloc(CJBig2_Image*, pDict->NUMPATS); - JBIG2_memset(pDict->HDPATS, 0, sizeof(CJBig2_Image*) * pDict->NUMPATS); + std::unique_ptr<CJBig2_Image> BHDC; + auto pDict = pdfium::MakeUnique<CJBig2_PatternDict>(GRAYMAX + 1); auto pGRD = pdfium::MakeUnique<CJBig2_GRDProc>(); pGRD->MMR = HDMMR; @@ -44,7 +41,7 @@ CJBig2_PatternDict* CJBig2_PDDProc::decode_Arith( FXCODEC_STATUS status = pGRD->Start_decode_Arith(&BHDC, pArithDecoder, gbContext, nullptr); while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) - status = pGRD->Continue_decode(pPause); + status = pGRD->Continue_decode(pPause, pArithDecoder); if (!BHDC) return nullptr; @@ -53,17 +50,14 @@ CJBig2_PatternDict* CJBig2_PDDProc::decode_Arith( pDict->HDPATS[GRAY] = BHDC->subImage(HDPW * GRAY, 0, HDPW, HDPH); GRAY = GRAY + 1; } - delete BHDC; - return pDict.release(); + return pDict; } -CJBig2_PatternDict* CJBig2_PDDProc::decode_MMR(CJBig2_BitStream* pStream) { +std::unique_ptr<CJBig2_PatternDict> CJBig2_PDDProc::decode_MMR( + CJBig2_BitStream* pStream) { uint32_t GRAY; - CJBig2_Image* BHDC = nullptr; - auto pDict = pdfium::MakeUnique<CJBig2_PatternDict>(); - pDict->NUMPATS = GRAYMAX + 1; - pDict->HDPATS = FX_Alloc(CJBig2_Image*, pDict->NUMPATS); - JBIG2_memset(pDict->HDPATS, 0, sizeof(CJBig2_Image*) * pDict->NUMPATS); + std::unique_ptr<CJBig2_Image> BHDC; + auto pDict = pdfium::MakeUnique<CJBig2_PatternDict>(GRAYMAX + 1); auto pGRD = pdfium::MakeUnique<CJBig2_GRDProc>(); pGRD->MMR = HDMMR; @@ -78,6 +72,5 @@ CJBig2_PatternDict* CJBig2_PDDProc::decode_MMR(CJBig2_BitStream* pStream) { pDict->HDPATS[GRAY] = BHDC->subImage(HDPW * GRAY, 0, HDPW, HDPH); GRAY = GRAY + 1; } - delete BHDC; - return pDict.release(); + return pDict; } diff --git a/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_PddProc.h b/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_PddProc.h index 3bb97d06143..af27889ff10 100644 --- a/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_PddProc.h +++ b/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_PddProc.h @@ -7,6 +7,8 @@ #ifndef CORE_FXCODEC_JBIG2_JBIG2_PDDPROC_H_ #define CORE_FXCODEC_JBIG2_JBIG2_PDDPROC_H_ +#include <memory> + #include "core/fxcrt/fx_system.h" class CJBig2_ArithDecoder; @@ -17,11 +19,12 @@ struct JBig2ArithCtx; class CJBig2_PDDProc { public: - CJBig2_PatternDict* decode_Arith(CJBig2_ArithDecoder* pArithDecoder, - JBig2ArithCtx* gbContext, - IFX_Pause* pPause); + std::unique_ptr<CJBig2_PatternDict> decode_Arith( + CJBig2_ArithDecoder* pArithDecoder, + JBig2ArithCtx* gbContext, + IFX_Pause* pPause); - CJBig2_PatternDict* decode_MMR(CJBig2_BitStream* pStream); + std::unique_ptr<CJBig2_PatternDict> decode_MMR(CJBig2_BitStream* pStream); public: bool HDMMR; diff --git a/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_SddProc.cpp b/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_SddProc.cpp index e296e32d216..1a98b17d341 100644 --- a/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_SddProc.cpp +++ b/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_SddProc.cpp @@ -22,7 +22,7 @@ #include "core/fxcrt/fx_basic.h" #include "third_party/base/ptr_util.h" -CJBig2_SymbolDict* CJBig2_SDDProc::decode_Arith( +std::unique_ptr<CJBig2_SymbolDict> CJBig2_SDDProc::decode_Arith( CJBig2_ArithDecoder* pArithDecoder, std::vector<JBig2ArithCtx>* gbContext, std::vector<JBig2ArithCtx>* grContext) { @@ -31,7 +31,6 @@ CJBig2_SymbolDict* CJBig2_SDDProc::decode_Arith( int32_t HCDH; uint32_t SYMWIDTH, TOTWIDTH; int32_t DW; - CJBig2_Image* BS; uint32_t I, J, REFAGGNINST; std::vector<bool> EXFLAGS; uint32_t EXINDEX; @@ -69,7 +68,7 @@ CJBig2_SymbolDict* CJBig2_SDDProc::decode_Arith( HCHEIGHT = 0; NSYMSDECODED = 0; while (NSYMSDECODED < SDNUMNEWSYMS) { - BS = nullptr; + std::unique_ptr<CJBig2_Image> BS; IADH->decode(pArithDecoder, &HCDH); HCHEIGHT = HCHEIGHT + HCDH; if ((int)HCHEIGHT < 0 || (int)HCHEIGHT > JBIG2_MAX_IMAGE_SIZE) @@ -218,8 +217,7 @@ CJBig2_SymbolDict* CJBig2_SDDProc::decode_Arith( return nullptr; } } - SDNEWSYMS[NSYMSDECODED] = pdfium::WrapUnique<CJBig2_Image>(BS); - BS = nullptr; + SDNEWSYMS[NSYMSDECODED] = std::move(BS); NSYMSDECODED = NSYMSDECODED + 1; } } @@ -259,10 +257,10 @@ CJBig2_SymbolDict* CJBig2_SDDProc::decode_Arith( } ++J; } - return pDict.release(); + return pDict; } -CJBig2_SymbolDict* CJBig2_SDDProc::decode_Huffman( +std::unique_ptr<CJBig2_SymbolDict> CJBig2_SDDProc::decode_Huffman( CJBig2_BitStream* pStream, std::vector<JBig2ArithCtx>* gbContext, std::vector<JBig2ArithCtx>* grContext) { @@ -272,7 +270,6 @@ CJBig2_SymbolDict* CJBig2_SDDProc::decode_Huffman( int32_t HCDH; uint32_t SYMWIDTH, TOTWIDTH, HCFIRSTSYM; int32_t DW; - CJBig2_Image *BS, *BHC; uint32_t I, J, REFAGGNINST; std::vector<bool> EXFLAGS; uint32_t EXINDEX; @@ -282,7 +279,6 @@ CJBig2_SymbolDict* CJBig2_SDDProc::decode_Huffman( uint32_t nTmp; uint32_t SBNUMSYMS; uint8_t SBSYMCODELEN; - std::vector<JBig2HuffmanCode> SBSYMCODES; uint32_t IDI; int32_t RDXI, RDYI; uint32_t BMSIZE; @@ -292,7 +288,6 @@ CJBig2_SymbolDict* CJBig2_SDDProc::decode_Huffman( std::vector<CJBig2_Image*> SBSYMS; auto pHuffmanDecoder = pdfium::MakeUnique<CJBig2_HuffmanDecoder>(pStream); SDNEWSYMS.resize(SDNUMNEWSYMS); - BHC = nullptr; if (SDREFAGG == 0) SDNEWSYMWIDTHS.resize(SDNUMNEWSYMS); auto pDict = pdfium::MakeUnique<CJBig2_SymbolDict>(); @@ -300,7 +295,7 @@ CJBig2_SymbolDict* CJBig2_SDDProc::decode_Huffman( HCHEIGHT = 0; NSYMSDECODED = 0; - BS = nullptr; + std::unique_ptr<CJBig2_Image> BS; while (NSYMSDECODED < SDNUMNEWSYMS) { if (pHuffmanDecoder->decodeAValue(SDHUFFDH, &HCDH) != 0) return nullptr; @@ -349,16 +344,15 @@ CJBig2_SymbolDict* CJBig2_SDDProc::decode_Huffman( pDecoder->SBSTRIPS = 1; pDecoder->SBNUMSYMS = SDNUMINSYMS + NSYMSDECODED; SBNUMSYMS = pDecoder->SBNUMSYMS; - SBSYMCODES.resize(SBNUMSYMS); + std::vector<JBig2HuffmanCode> SBSYMCODES(SBNUMSYMS); nTmp = 1; - while ((uint32_t)(1 << nTmp) < SBNUMSYMS) { - nTmp++; - } - for (I = 0; I < SBNUMSYMS; I++) { + while (static_cast<uint32_t>(1 << nTmp) < SBNUMSYMS) + ++nTmp; + for (I = 0; I < SBNUMSYMS; ++I) { SBSYMCODES[I].codelen = nTmp; SBSYMCODES[I].code = I; } - pDecoder->SBSYMCODES = SBSYMCODES.data(); + pDecoder->SBSYMCODES = std::move(SBSYMCODES); SBSYMS.resize(SBNUMSYMS); std::copy(SDINSYMS, SDINSYMS + SDNUMINSYMS, SBSYMS.begin()); for (size_t i = 0; i < NSYMSDECODED; ++i) @@ -456,12 +450,10 @@ CJBig2_SymbolDict* CJBig2_SDDProc::decode_Huffman( pStream->alignByte(); pStream->offset(2); - if ((uint32_t)nVal != (pStream->getOffset() - nTmp)) { - delete BS; + if ((uint32_t)nVal != (pStream->getOffset() - nTmp)) return nullptr; - } } - SDNEWSYMS[NSYMSDECODED] = pdfium::WrapUnique<CJBig2_Image>(BS); + SDNEWSYMS[NSYMSDECODED] = std::move(BS); } if (SDREFAGG == 0) SDNEWSYMWIDTHS[NSYMSDECODED] = SYMWIDTH; @@ -472,10 +464,11 @@ CJBig2_SymbolDict* CJBig2_SDDProc::decode_Huffman( return nullptr; pStream->alignByte(); + std::unique_ptr<CJBig2_Image> BHC; if (BMSIZE == 0) { stride = (TOTWIDTH + 7) >> 3; if (pStream->getByteLeft() >= stride * HCHEIGHT) { - BHC = new CJBig2_Image(TOTWIDTH, HCHEIGHT); + BHC = pdfium::MakeUnique<CJBig2_Image>(TOTWIDTH, HCHEIGHT); for (I = 0; I < HCHEIGHT; I++) { JBIG2_memcpy(BHC->m_pData + I * BHC->stride(), pStream->getPointer(), stride); @@ -493,16 +486,13 @@ CJBig2_SymbolDict* CJBig2_SDDProc::decode_Huffman( pStream->alignByte(); } nTmp = 0; - if (!BHC) { + if (!BHC) continue; - } - for (I = HCFIRSTSYM; I < NSYMSDECODED; I++) { - SDNEWSYMS[I] = pdfium::WrapUnique<CJBig2_Image>( - BHC->subImage(nTmp, 0, SDNEWSYMWIDTHS[I], HCHEIGHT)); + + for (I = HCFIRSTSYM; I < NSYMSDECODED; ++I) { + SDNEWSYMS[I] = BHC->subImage(nTmp, 0, SDNEWSYMWIDTHS[I], HCHEIGHT); nTmp += SDNEWSYMWIDTHS[I]; } - delete BHC; - BHC = nullptr; } } EXINDEX = 0; @@ -519,7 +509,7 @@ CJBig2_SymbolDict* CJBig2_SDDProc::decode_Huffman( return nullptr; if (EXRUNLENGTH != 0) { - for (I = EXINDEX; I < EXINDEX + EXRUNLENGTH; I++) { + for (I = EXINDEX; I < EXINDEX + EXRUNLENGTH; ++I) { if (CUREXFLAG) num_ex_syms++; @@ -533,7 +523,7 @@ CJBig2_SymbolDict* CJBig2_SDDProc::decode_Huffman( return nullptr; I = J = 0; - for (I = 0; I < SDNUMINSYMS + SDNUMNEWSYMS; I++) { + for (I = 0; I < SDNUMINSYMS + SDNUMNEWSYMS; ++I) { if (!EXFLAGS[I] || J >= SDNUMEXSYMS) continue; if (I < SDNUMINSYMS) { @@ -545,5 +535,5 @@ CJBig2_SymbolDict* CJBig2_SDDProc::decode_Huffman( } ++J; } - return pDict.release(); + return pDict; } diff --git a/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_SddProc.h b/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_SddProc.h index 20e05699351..80b988ef98a 100644 --- a/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_SddProc.h +++ b/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_SddProc.h @@ -7,6 +7,7 @@ #ifndef CORE_FXCODEC_JBIG2_JBIG2_SDDPROC_H_ #define CORE_FXCODEC_JBIG2_JBIG2_SDDPROC_H_ +#include <memory> #include <vector> #include "core/fxcodec/jbig2/JBig2_ArithDecoder.h" @@ -19,13 +20,15 @@ class CJBig2_SymbolDict; class CJBig2_SDDProc { public: - CJBig2_SymbolDict* decode_Arith(CJBig2_ArithDecoder* pArithDecoder, - std::vector<JBig2ArithCtx>* gbContext, - std::vector<JBig2ArithCtx>* grContext); - - CJBig2_SymbolDict* decode_Huffman(CJBig2_BitStream* pStream, - std::vector<JBig2ArithCtx>* gbContext, - std::vector<JBig2ArithCtx>* grContext); + std::unique_ptr<CJBig2_SymbolDict> decode_Arith( + CJBig2_ArithDecoder* pArithDecoder, + std::vector<JBig2ArithCtx>* gbContext, + std::vector<JBig2ArithCtx>* grContext); + + std::unique_ptr<CJBig2_SymbolDict> decode_Huffman( + CJBig2_BitStream* pStream, + std::vector<JBig2ArithCtx>* gbContext, + std::vector<JBig2ArithCtx>* grContext); bool SDHUFF; bool SDREFAGG; diff --git a/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_Segment.cpp b/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_Segment.cpp index 610246b6e2c..886989abd84 100644 --- a/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_Segment.cpp +++ b/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_Segment.cpp @@ -20,25 +20,8 @@ CJBig2_Segment::CJBig2_Segment() { m_dwDataOffset = 0; m_State = JBIG2_SEGMENT_HEADER_UNPARSED; m_nResultType = JBIG2_VOID_POINTER; - m_Result.vd = nullptr; } + CJBig2_Segment::~CJBig2_Segment() { FX_Free(m_pReferred_to_segment_numbers); - - switch (m_nResultType) { - case JBIG2_IMAGE_POINTER: - delete m_Result.im; - break; - case JBIG2_SYMBOL_DICT_POINTER: - delete m_Result.sd; - break; - case JBIG2_PATTERN_DICT_POINTER: - delete m_Result.pd; - break; - case JBIG2_HUFFMAN_TABLE_POINTER: - delete m_Result.ht; - break; - default: - FX_Free(m_Result.vd); - } } diff --git a/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_Segment.h b/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_Segment.h index d89d6526992..26af0f6890c 100644 --- a/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_Segment.h +++ b/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_Segment.h @@ -7,6 +7,8 @@ #ifndef CORE_FXCODEC_JBIG2_JBIG2_SEGMENT_H_ #define CORE_FXCODEC_JBIG2_JBIG2_SEGMENT_H_ +#include <memory> + #include "core/fxcodec/jbig2/JBig2_Define.h" #include "core/fxcodec/jbig2/JBig2_HuffmanTable.h" #include "core/fxcodec/jbig2/JBig2_PatternDict.h" @@ -54,13 +56,10 @@ class CJBig2_Segment { uint32_t m_dwDataOffset; JBig2_SegmentState m_State; JBig2_ResultType m_nResultType; - union { - CJBig2_SymbolDict* sd; - CJBig2_PatternDict* pd; - CJBig2_Image* im; - CJBig2_HuffmanTable* ht; - void* vd; - } m_Result; + std::unique_ptr<CJBig2_SymbolDict> m_SymbolDict; + std::unique_ptr<CJBig2_PatternDict> m_PatternDict; + std::unique_ptr<CJBig2_Image> m_Image; + std::unique_ptr<CJBig2_HuffmanTable> m_HuffmanTable; }; #endif // CORE_FXCODEC_JBIG2_JBIG2_SEGMENT_H_ diff --git a/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_TrdProc.cpp b/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_TrdProc.cpp index f681e05569b..3fc43c067e8 100644 --- a/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_TrdProc.cpp +++ b/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_TrdProc.cpp @@ -12,10 +12,16 @@ #include "core/fxcodec/jbig2/JBig2_ArithIntDecoder.h" #include "core/fxcodec/jbig2/JBig2_GrrdProc.h" #include "core/fxcodec/jbig2/JBig2_HuffmanDecoder.h" +#include "core/fxcrt/cfx_maybe_owned.h" #include "third_party/base/ptr_util.h" -CJBig2_Image* CJBig2_TRDProc::decode_Huffman(CJBig2_BitStream* pStream, - JBig2ArithCtx* grContext) { +CJBig2_TRDProc::CJBig2_TRDProc() {} + +CJBig2_TRDProc::~CJBig2_TRDProc() {} + +std::unique_ptr<CJBig2_Image> CJBig2_TRDProc::decode_Huffman( + CJBig2_BitStream* pStream, + JBig2ArithCtx* grContext) { auto pHuffmanDecoder = pdfium::MakeUnique<CJBig2_HuffmanDecoder>(pStream); auto SBREG = pdfium::MakeUnique<CJBig2_Image>(SBW, SBH); SBREG->fill(SBDEFPIXEL); @@ -48,20 +54,19 @@ CJBig2_Image* CJBig2_TRDProc::decode_Huffman(CJBig2_BitStream* pStream, } else { int32_t IDS; int32_t nVal = pHuffmanDecoder->decodeAValue(SBHUFFDS, &IDS); - if (nVal == JBIG2_OOB) { + if (nVal == JBIG2_OOB) break; - } else if (nVal != 0) { + + if (nVal != 0) return nullptr; - } else { - CURS = CURS + IDS + SBDSOFFSET; - } + + CURS = CURS + IDS + SBDSOFFSET; } uint8_t CURT = 0; if (SBSTRIPS != 1) { uint32_t nTmp = 1; - while ((uint32_t)(1 << nTmp) < SBSTRIPS) { - nTmp++; - } + while (static_cast<uint32_t>(1 << nTmp) < SBSTRIPS) + ++nTmp; int32_t nVal; if (pStream->readNBits(nTmp, &nVal) != 0) return nullptr; @@ -82,22 +87,21 @@ CJBig2_Image* CJBig2_TRDProc::decode_Huffman(CJBig2_BitStream* pStream, return nullptr; nVal |= nTmp; - nBits++; - for (IDI = 0; IDI < SBNUMSYMS; IDI++) { + ++nBits; + for (IDI = 0; IDI < SBNUMSYMS; ++IDI) { if ((nBits == SBSYMCODES[IDI].codelen) && (nVal.ValueOrDie() == SBSYMCODES[IDI].code)) { break; } } - if (IDI < SBNUMSYMS) { + if (IDI < SBNUMSYMS) break; - } } bool RI = 0; - if (SBREFINE != 0 && pStream->read1Bit(&RI) != 0) { + if (SBREFINE != 0 && pStream->read1Bit(&RI) != 0) return nullptr; - } - CJBig2_Image* IBI = nullptr; + + CFX_MaybeOwned<CJBig2_Image> IBI; if (RI == 0) { IBI = SBSYMS[IDI]; } else { @@ -121,8 +125,10 @@ CJBig2_Image* CJBig2_TRDProc::decode_Huffman(CJBig2_BitStream* pStream, uint32_t WOI = IBOI->width(); uint32_t HOI = IBOI->height(); - if ((int)(WOI + RDWI) < 0 || (int)(HOI + RDHI) < 0) + if (static_cast<int>(WOI + RDWI) < 0 || + static_cast<int>(HOI + RDHI) < 0) { return nullptr; + } auto pGRRD = pdfium::MakeUnique<CJBig2_GRRDProc>(); pGRRD->GRW = WOI + RDWI; @@ -137,23 +143,19 @@ CJBig2_Image* CJBig2_TRDProc::decode_Huffman(CJBig2_BitStream* pStream, pGRRD->GRAT[2] = SBRAT[2]; pGRRD->GRAT[3] = SBRAT[3]; - { - auto pArithDecoder = pdfium::MakeUnique<CJBig2_ArithDecoder>(pStream); - IBI = pGRRD->decode(pArithDecoder.get(), grContext); - if (!IBI) - return nullptr; - } + auto pArithDecoder = pdfium::MakeUnique<CJBig2_ArithDecoder>(pStream); + IBI = pGRRD->decode(pArithDecoder.get(), grContext); + if (!IBI) + return nullptr; pStream->alignByte(); pStream->offset(2); - if (static_cast<uint32_t>(HUFFRSIZE) != (pStream->getOffset() - nTmp)) { - delete IBI; + if (static_cast<uint32_t>(HUFFRSIZE) != (pStream->getOffset() - nTmp)) return nullptr; - } } - if (!IBI) { + if (!IBI) continue; - } + uint32_t WI = IBI->width(); uint32_t HI = IBI->height(); if (TRANSPOSED == 0 && ((REFCORNER == JBIG2_CORNER_TOPRIGHT) || @@ -167,37 +169,34 @@ CJBig2_Image* CJBig2_TRDProc::decode_Huffman(CJBig2_BitStream* pStream, if (TRANSPOSED == 0) { switch (REFCORNER) { case JBIG2_CORNER_TOPLEFT: - SBREG->composeFrom(SI, TI, IBI, SBCOMBOP); + SBREG->composeFrom(SI, TI, IBI.Get(), SBCOMBOP); break; case JBIG2_CORNER_TOPRIGHT: - SBREG->composeFrom(SI - WI + 1, TI, IBI, SBCOMBOP); + SBREG->composeFrom(SI - WI + 1, TI, IBI.Get(), SBCOMBOP); break; case JBIG2_CORNER_BOTTOMLEFT: - SBREG->composeFrom(SI, TI - HI + 1, IBI, SBCOMBOP); + SBREG->composeFrom(SI, TI - HI + 1, IBI.Get(), SBCOMBOP); break; case JBIG2_CORNER_BOTTOMRIGHT: - SBREG->composeFrom(SI - WI + 1, TI - HI + 1, IBI, SBCOMBOP); + SBREG->composeFrom(SI - WI + 1, TI - HI + 1, IBI.Get(), SBCOMBOP); break; } } else { switch (REFCORNER) { case JBIG2_CORNER_TOPLEFT: - SBREG->composeFrom(TI, SI, IBI, SBCOMBOP); + SBREG->composeFrom(TI, SI, IBI.Get(), SBCOMBOP); break; case JBIG2_CORNER_TOPRIGHT: - SBREG->composeFrom(TI - WI + 1, SI, IBI, SBCOMBOP); + SBREG->composeFrom(TI - WI + 1, SI, IBI.Get(), SBCOMBOP); break; case JBIG2_CORNER_BOTTOMLEFT: - SBREG->composeFrom(TI, SI - HI + 1, IBI, SBCOMBOP); + SBREG->composeFrom(TI, SI - HI + 1, IBI.Get(), SBCOMBOP); break; case JBIG2_CORNER_BOTTOMRIGHT: - SBREG->composeFrom(TI - WI + 1, SI - HI + 1, IBI, SBCOMBOP); + SBREG->composeFrom(TI - WI + 1, SI - HI + 1, IBI.Get(), SBCOMBOP); break; } } - if (RI != 0) { - delete IBI; - } if (TRANSPOSED == 0 && ((REFCORNER == JBIG2_CORNER_TOPLEFT) || (REFCORNER == JBIG2_CORNER_BOTTOMLEFT))) { CURS = CURS + WI - 1; @@ -208,32 +207,23 @@ CJBig2_Image* CJBig2_TRDProc::decode_Huffman(CJBig2_BitStream* pStream, NINSTANCES = NINSTANCES + 1; } } - return SBREG.release(); + return SBREG; } -CJBig2_Image* CJBig2_TRDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder, - JBig2ArithCtx* grContext, - JBig2IntDecoderState* pIDS) { - std::unique_ptr<CJBig2_ArithIntDecoder> IADT; - std::unique_ptr<CJBig2_ArithIntDecoder> IAFS; - std::unique_ptr<CJBig2_ArithIntDecoder> IADS; - std::unique_ptr<CJBig2_ArithIntDecoder> IAIT; - std::unique_ptr<CJBig2_ArithIntDecoder> IARI; - std::unique_ptr<CJBig2_ArithIntDecoder> IARDW; - std::unique_ptr<CJBig2_ArithIntDecoder> IARDH; - std::unique_ptr<CJBig2_ArithIntDecoder> IARDX; - std::unique_ptr<CJBig2_ArithIntDecoder> IARDY; - std::unique_ptr<CJBig2_ArithIaidDecoder> IAID; - CJBig2_ArithIntDecoder* pIADT; - CJBig2_ArithIntDecoder* pIAFS; - CJBig2_ArithIntDecoder* pIADS; - CJBig2_ArithIntDecoder* pIAIT; - CJBig2_ArithIntDecoder* pIARI; - CJBig2_ArithIntDecoder* pIARDW; - CJBig2_ArithIntDecoder* pIARDH; - CJBig2_ArithIntDecoder* pIARDX; - CJBig2_ArithIntDecoder* pIARDY; - CJBig2_ArithIaidDecoder* pIAID; +std::unique_ptr<CJBig2_Image> CJBig2_TRDProc::decode_Arith( + CJBig2_ArithDecoder* pArithDecoder, + JBig2ArithCtx* grContext, + JBig2IntDecoderState* pIDS) { + CFX_MaybeOwned<CJBig2_ArithIntDecoder> pIADT; + CFX_MaybeOwned<CJBig2_ArithIntDecoder> pIAFS; + CFX_MaybeOwned<CJBig2_ArithIntDecoder> pIADS; + CFX_MaybeOwned<CJBig2_ArithIntDecoder> pIAIT; + CFX_MaybeOwned<CJBig2_ArithIntDecoder> pIARI; + CFX_MaybeOwned<CJBig2_ArithIntDecoder> pIARDW; + CFX_MaybeOwned<CJBig2_ArithIntDecoder> pIARDH; + CFX_MaybeOwned<CJBig2_ArithIntDecoder> pIARDX; + CFX_MaybeOwned<CJBig2_ArithIntDecoder> pIARDY; + CFX_MaybeOwned<CJBig2_ArithIaidDecoder> pIAID; if (pIDS) { pIADT = pIDS->IADT; pIAFS = pIDS->IAFS; @@ -246,32 +236,23 @@ CJBig2_Image* CJBig2_TRDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder, pIARDY = pIDS->IARDY; pIAID = pIDS->IAID; } else { - IADT = pdfium::MakeUnique<CJBig2_ArithIntDecoder>(); - IAFS = pdfium::MakeUnique<CJBig2_ArithIntDecoder>(); - IADS = pdfium::MakeUnique<CJBig2_ArithIntDecoder>(); - IAIT = pdfium::MakeUnique<CJBig2_ArithIntDecoder>(); - IARI = pdfium::MakeUnique<CJBig2_ArithIntDecoder>(); - IARDW = pdfium::MakeUnique<CJBig2_ArithIntDecoder>(); - IARDH = pdfium::MakeUnique<CJBig2_ArithIntDecoder>(); - IARDX = pdfium::MakeUnique<CJBig2_ArithIntDecoder>(); - IARDY = pdfium::MakeUnique<CJBig2_ArithIntDecoder>(); - IAID = pdfium::MakeUnique<CJBig2_ArithIaidDecoder>(SBSYMCODELEN); - pIADT = IADT.get(); - pIAFS = IAFS.get(); - pIADS = IADS.get(); - pIAIT = IAIT.get(); - pIARI = IARI.get(); - pIARDW = IARDW.get(); - pIARDH = IARDH.get(); - pIARDX = IARDX.get(); - pIARDY = IARDY.get(); - pIAID = IAID.get(); + pIADT = pdfium::MakeUnique<CJBig2_ArithIntDecoder>(); + pIAFS = pdfium::MakeUnique<CJBig2_ArithIntDecoder>(); + pIADS = pdfium::MakeUnique<CJBig2_ArithIntDecoder>(); + pIAIT = pdfium::MakeUnique<CJBig2_ArithIntDecoder>(); + pIARI = pdfium::MakeUnique<CJBig2_ArithIntDecoder>(); + pIARDW = pdfium::MakeUnique<CJBig2_ArithIntDecoder>(); + pIARDH = pdfium::MakeUnique<CJBig2_ArithIntDecoder>(); + pIARDX = pdfium::MakeUnique<CJBig2_ArithIntDecoder>(); + pIARDY = pdfium::MakeUnique<CJBig2_ArithIntDecoder>(); + pIAID = pdfium::MakeUnique<CJBig2_ArithIaidDecoder>(SBSYMCODELEN); } auto SBREG = pdfium::MakeUnique<CJBig2_Image>(SBW, SBH); SBREG->fill(SBDEFPIXEL); int32_t STRIPT; if (!pIADT->decode(pArithDecoder, &STRIPT)) return nullptr; + STRIPT *= SBSTRIPS; STRIPT = -STRIPT; int32_t FIRSTS = 0; @@ -281,6 +262,7 @@ CJBig2_Image* CJBig2_TRDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder, int32_t DT; if (!pIADT->decode(pArithDecoder, &DT)) return nullptr; + DT *= SBSTRIPS; STRIPT += DT; bool bFirst = true; @@ -295,11 +277,12 @@ CJBig2_Image* CJBig2_TRDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder, int32_t IDS; if (!pIADS->decode(pArithDecoder, &IDS)) break; + CURS += IDS + SBDSOFFSET; } - if (NINSTANCES >= SBNUMINSTANCES) { + if (NINSTANCES >= SBNUMINSTANCES) break; - } + int CURT = 0; if (SBSTRIPS != 1) pIAIT->decode(pArithDecoder, &CURT); @@ -316,8 +299,7 @@ CJBig2_Image* CJBig2_TRDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder, else pIARI->decode(pArithDecoder, &RI); - std::unique_ptr<CJBig2_Image> IBI; - CJBig2_Image* pIBI; + CFX_MaybeOwned<CJBig2_Image> pIBI; if (RI == 0) { pIBI = SBSYMS[IDI]; } else { @@ -335,8 +317,10 @@ CJBig2_Image* CJBig2_TRDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder, uint32_t WOI = IBOI->width(); uint32_t HOI = IBOI->height(); - if ((int)(WOI + RDWI) < 0 || (int)(HOI + RDHI) < 0) + if (static_cast<int>(WOI + RDWI) < 0 || + static_cast<int>(HOI + RDHI) < 0) { return nullptr; + } auto pGRRD = pdfium::MakeUnique<CJBig2_GRRDProc>(); pGRRD->GRW = WOI + RDWI; @@ -350,8 +334,7 @@ CJBig2_Image* CJBig2_TRDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder, pGRRD->GRAT[1] = SBRAT[1]; pGRRD->GRAT[2] = SBRAT[2]; pGRRD->GRAT[3] = SBRAT[3]; - IBI.reset(pGRRD->decode(pArithDecoder, grContext)); - pIBI = IBI.get(); + pIBI = pGRRD->decode(pArithDecoder, grContext); } if (!pIBI) return nullptr; @@ -369,31 +352,31 @@ CJBig2_Image* CJBig2_TRDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder, if (TRANSPOSED == 0) { switch (REFCORNER) { case JBIG2_CORNER_TOPLEFT: - SBREG->composeFrom(SI, TI, pIBI, SBCOMBOP); + SBREG->composeFrom(SI, TI, pIBI.Get(), SBCOMBOP); break; case JBIG2_CORNER_TOPRIGHT: - SBREG->composeFrom(SI - WI + 1, TI, pIBI, SBCOMBOP); + SBREG->composeFrom(SI - WI + 1, TI, pIBI.Get(), SBCOMBOP); break; case JBIG2_CORNER_BOTTOMLEFT: - SBREG->composeFrom(SI, TI - HI + 1, pIBI, SBCOMBOP); + SBREG->composeFrom(SI, TI - HI + 1, pIBI.Get(), SBCOMBOP); break; case JBIG2_CORNER_BOTTOMRIGHT: - SBREG->composeFrom(SI - WI + 1, TI - HI + 1, pIBI, SBCOMBOP); + SBREG->composeFrom(SI - WI + 1, TI - HI + 1, pIBI.Get(), SBCOMBOP); break; } } else { switch (REFCORNER) { case JBIG2_CORNER_TOPLEFT: - SBREG->composeFrom(TI, SI, pIBI, SBCOMBOP); + SBREG->composeFrom(TI, SI, pIBI.Get(), SBCOMBOP); break; case JBIG2_CORNER_TOPRIGHT: - SBREG->composeFrom(TI - WI + 1, SI, pIBI, SBCOMBOP); + SBREG->composeFrom(TI - WI + 1, SI, pIBI.Get(), SBCOMBOP); break; case JBIG2_CORNER_BOTTOMLEFT: - SBREG->composeFrom(TI, SI - HI + 1, pIBI, SBCOMBOP); + SBREG->composeFrom(TI, SI - HI + 1, pIBI.Get(), SBCOMBOP); break; case JBIG2_CORNER_BOTTOMRIGHT: - SBREG->composeFrom(TI - WI + 1, SI - HI + 1, pIBI, SBCOMBOP); + SBREG->composeFrom(TI - WI + 1, SI - HI + 1, pIBI.Get(), SBCOMBOP); break; } } @@ -407,5 +390,5 @@ CJBig2_Image* CJBig2_TRDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder, ++NINSTANCES; } } - return SBREG.release(); + return SBREG; } diff --git a/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_TrdProc.h b/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_TrdProc.h index be50ec152f4..a66415b0bd1 100644 --- a/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_TrdProc.h +++ b/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_TrdProc.h @@ -7,6 +7,9 @@ #ifndef CORE_FXCODEC_JBIG2_JBIG2_TRDPROC_H_ #define CORE_FXCODEC_JBIG2_JBIG2_TRDPROC_H_ +#include <memory> +#include <vector> + #include "core/fxcodec/jbig2/JBig2_Image.h" #include "core/fxcrt/fx_system.h" @@ -40,12 +43,15 @@ enum JBig2Corner { class CJBig2_TRDProc { public: - CJBig2_Image* decode_Huffman(CJBig2_BitStream* pStream, - JBig2ArithCtx* grContext); + CJBig2_TRDProc(); + ~CJBig2_TRDProc(); + + std::unique_ptr<CJBig2_Image> decode_Huffman(CJBig2_BitStream* pStream, + JBig2ArithCtx* grContext); - CJBig2_Image* decode_Arith(CJBig2_ArithDecoder* pArithDecoder, - JBig2ArithCtx* grContext, - JBig2IntDecoderState* pIDS); + std::unique_ptr<CJBig2_Image> decode_Arith(CJBig2_ArithDecoder* pArithDecoder, + JBig2ArithCtx* grContext, + JBig2IntDecoderState* pIDS); bool SBHUFF; bool SBREFINE; @@ -55,7 +61,7 @@ class CJBig2_TRDProc { uint32_t SBSTRIPS; uint32_t SBNUMSYMS; - JBig2HuffmanCode* SBSYMCODES; + std::vector<JBig2HuffmanCode> SBSYMCODES; uint8_t SBSYMCODELEN; CJBig2_Image** SBSYMS; diff --git a/chromium/third_party/pdfium/core/fxcodec/lbmp/fx_bmp.cpp b/chromium/third_party/pdfium/core/fxcodec/lbmp/fx_bmp.cpp index e4fa17dc89b..989b3a4f842 100644 --- a/chromium/third_party/pdfium/core/fxcodec/lbmp/fx_bmp.cpp +++ b/chromium/third_party/pdfium/core/fxcodec/lbmp/fx_bmp.cpp @@ -9,23 +9,17 @@ #include <algorithm> #include <limits> +#include "core/fxcrt/fx_system.h" +#include "third_party/base/ptr_util.h" + +static_assert(sizeof(BmpFileHeader) == 14, + "BmpFileHeader should have a size of 14"); + namespace { const size_t kBmpCoreHeaderSize = 12; const size_t kBmpInfoHeaderSize = 40; -// TODO(thestig): Replace with FXDWORD_GET_LSBFIRST? -uint32_t GetDWord_LSBFirst(uint8_t* p) { - return p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24); -} - -void SetDWord_LSBFirst(uint8_t* p, uint32_t v) { - p[0] = (uint8_t)v; - p[1] = (uint8_t)(v >> 8); - p[2] = (uint8_t)(v >> 16); - p[3] = (uint8_t)(v >> 24); -} - uint8_t HalfRoundUp(uint8_t value) { uint16_t value16 = value; return static_cast<uint8_t>((value16 + 1) / 2); @@ -36,323 +30,339 @@ uint8_t HalfRoundUp(uint8_t value) { uint16_t GetWord_LSBFirst(uint8_t* p) { return p[0] | (p[1] << 8); } -void SetWord_LSBFirst(uint8_t* p, uint16_t v) { - p[0] = (uint8_t)v; - p[1] = (uint8_t)(v >> 8); -} -void bmp_error(bmp_decompress_struct_p bmp_ptr, const char* err_msg) { - if (bmp_ptr && bmp_ptr->bmp_error_fn) { - bmp_ptr->bmp_error_fn(bmp_ptr, err_msg); - } + +BMPDecompressor::BMPDecompressor() + : err_ptr(nullptr), + context_ptr(nullptr), + next_in(nullptr), + header_offset(0), + width(0), + height(0), + compress_flag(0), + components(0), + src_row_bytes(0), + out_row_bytes(0), + bitCounts(0), + color_used(0), + imgTB_flag(false), + pal_num(0), + pal_type(0), + data_size(0), + img_data_offset(0), + img_ifh_size(0), + row_num(0), + col_num(0), + dpi_x(0), + dpi_y(0), + mask_red(0), + mask_green(0), + mask_blue(0), + avail_in(0), + skip_size(0), + decode_status(BMP_D_STATUS_HEADER) {} + +BMPDecompressor::~BMPDecompressor() {} + +void BMPDecompressor::Error(const char* err_msg) { + strncpy(err_ptr, err_msg, BMP_MAX_ERROR_SIZE - 1); + longjmp(jmpbuf, 1); } -bmp_decompress_struct_p bmp_create_decompress() { - bmp_decompress_struct_p bmp_ptr = FX_Alloc(bmp_decompress_struct, 1); - memset(bmp_ptr, 0, sizeof(bmp_decompress_struct)); - bmp_ptr->decode_status = BMP_D_STATUS_HEADER; - bmp_ptr->bmp_header_ptr = FX_Alloc(BmpFileHeader, 1); - return bmp_ptr; + +void BMPDecompressor::ReadScanline(uint32_t row_num, + const std::vector<uint8_t>& row_buf) { + auto* p = reinterpret_cast<CBmpContext*>(context_ptr); + p->m_pDelegate->BmpReadScanline(row_num, row_buf); } -void bmp_destroy_decompress(bmp_decompress_struct_pp bmp_ptr_ptr) { - if (!bmp_ptr_ptr || !*bmp_ptr_ptr) - return; - bmp_decompress_struct_p bmp_ptr = *bmp_ptr_ptr; - *bmp_ptr_ptr = nullptr; - FX_Free(bmp_ptr->out_row_buffer); - FX_Free(bmp_ptr->pal_ptr); - FX_Free(bmp_ptr->bmp_header_ptr); - FX_Free(bmp_ptr); +bool BMPDecompressor::GetDataPosition(uint32_t rcd_pos) { + auto* p = reinterpret_cast<CBmpContext*>(context_ptr); + return p->m_pDelegate->BmpInputImagePositionBuf(rcd_pos); } -int32_t bmp_read_header(bmp_decompress_struct_p bmp_ptr) { - if (!bmp_ptr) - return 0; - - uint32_t skip_size_org = bmp_ptr->skip_size; - if (bmp_ptr->decode_status == BMP_D_STATUS_HEADER) { - ASSERT(sizeof(BmpFileHeader) == 14); - BmpFileHeader* bmp_header_ptr = nullptr; - if (!bmp_read_data(bmp_ptr, (uint8_t**)&bmp_header_ptr, 14)) + +int32_t BMPDecompressor::ReadHeader() { + uint32_t skip_size_org = skip_size; + if (decode_status == BMP_D_STATUS_HEADER) { + BmpFileHeader* pBmp_header = nullptr; + if (!ReadData(reinterpret_cast<uint8_t**>(&pBmp_header), + sizeof(BmpFileHeader))) { return 2; + } - bmp_ptr->bmp_header_ptr->bfType = - GetWord_LSBFirst((uint8_t*)&bmp_header_ptr->bfType); - bmp_ptr->bmp_header_ptr->bfOffBits = - GetDWord_LSBFirst((uint8_t*)&bmp_header_ptr->bfOffBits); - bmp_ptr->data_size = GetDWord_LSBFirst((uint8_t*)&bmp_header_ptr->bfSize); - if (bmp_ptr->bmp_header_ptr->bfType != BMP_SIGNATURE) { - bmp_error(bmp_ptr, "Not A Bmp Image"); - return 0; + pBmp_header->bfType = + GetWord_LSBFirst(reinterpret_cast<uint8_t*>(&pBmp_header->bfType)); + pBmp_header->bfOffBits = FXDWORD_GET_LSBFIRST( + reinterpret_cast<uint8_t*>(&pBmp_header->bfOffBits)); + data_size = + FXDWORD_GET_LSBFIRST(reinterpret_cast<uint8_t*>(&pBmp_header->bfSize)); + if (pBmp_header->bfType != BMP_SIGNATURE) { + Error("Not A Bmp Image"); + NOTREACHED(); } - if (bmp_ptr->avail_in < sizeof(uint32_t)) { - bmp_ptr->skip_size = skip_size_org; + if (avail_in < sizeof(uint32_t)) { + skip_size = skip_size_org; return 2; } - bmp_ptr->img_ifh_size = - GetDWord_LSBFirst(bmp_ptr->next_in + bmp_ptr->skip_size); - bmp_ptr->pal_type = 0; + img_ifh_size = + FXDWORD_GET_LSBFIRST(static_cast<uint8_t*>(next_in + skip_size)); + pal_type = 0; static_assert(sizeof(BmpCoreHeader) == kBmpCoreHeaderSize, "BmpCoreHeader has wrong size"); static_assert(sizeof(BmpInfoHeader) == kBmpInfoHeaderSize, "BmpInfoHeader has wrong size"); - switch (bmp_ptr->img_ifh_size) { + switch (img_ifh_size) { case kBmpCoreHeaderSize: { - bmp_ptr->pal_type = 1; - BmpCoreHeaderPtr bmp_core_header_ptr = nullptr; - if (!bmp_read_data(bmp_ptr, (uint8_t**)&bmp_core_header_ptr, - bmp_ptr->img_ifh_size)) { - bmp_ptr->skip_size = skip_size_org; + pal_type = 1; + BmpCoreHeader* pBmp_core_header = nullptr; + if (!ReadData(reinterpret_cast<uint8_t**>(&pBmp_core_header), + img_ifh_size)) { + skip_size = skip_size_org; return 2; } - bmp_ptr->width = - GetWord_LSBFirst((uint8_t*)&bmp_core_header_ptr->bcWidth); - bmp_ptr->height = - GetWord_LSBFirst((uint8_t*)&bmp_core_header_ptr->bcHeight); - bmp_ptr->bitCounts = - GetWord_LSBFirst((uint8_t*)&bmp_core_header_ptr->bcBitCount); - bmp_ptr->compress_flag = BMP_RGB; - bmp_ptr->imgTB_flag = false; + width = GetWord_LSBFirst( + reinterpret_cast<uint8_t*>(&pBmp_core_header->bcWidth)); + height = GetWord_LSBFirst( + reinterpret_cast<uint8_t*>(&pBmp_core_header->bcHeight)); + bitCounts = GetWord_LSBFirst( + reinterpret_cast<uint8_t*>(&pBmp_core_header->bcBitCount)); + compress_flag = BMP_RGB; + imgTB_flag = false; } break; case kBmpInfoHeaderSize: { - BmpInfoHeaderPtr bmp_info_header_ptr = nullptr; - if (!bmp_read_data(bmp_ptr, (uint8_t**)&bmp_info_header_ptr, - bmp_ptr->img_ifh_size)) { - bmp_ptr->skip_size = skip_size_org; + BmpInfoHeader* pBmp_info_header = nullptr; + if (!ReadData(reinterpret_cast<uint8_t**>(&pBmp_info_header), + img_ifh_size)) { + skip_size = skip_size_org; return 2; } - bmp_ptr->width = - GetDWord_LSBFirst((uint8_t*)&bmp_info_header_ptr->biWidth); - bmp_ptr->height = - GetDWord_LSBFirst((uint8_t*)&bmp_info_header_ptr->biHeight); - bmp_ptr->bitCounts = - GetWord_LSBFirst((uint8_t*)&bmp_info_header_ptr->biBitCount); - bmp_ptr->compress_flag = - GetDWord_LSBFirst((uint8_t*)&bmp_info_header_ptr->biCompression); - bmp_ptr->color_used = - GetDWord_LSBFirst((uint8_t*)&bmp_info_header_ptr->biClrUsed); - bmp_ptr->dpi_x = (int32_t)GetDWord_LSBFirst( - (uint8_t*)&bmp_info_header_ptr->biXPelsPerMeter); - bmp_ptr->dpi_y = (int32_t)GetDWord_LSBFirst( - (uint8_t*)&bmp_info_header_ptr->biYPelsPerMeter); - if (bmp_ptr->height < 0) { - if (bmp_ptr->height == std::numeric_limits<int>::min()) { - bmp_error(bmp_ptr, "Unsupported height"); - return 0; - } - bmp_ptr->height = -bmp_ptr->height; - bmp_ptr->imgTB_flag = true; - } + width = FXDWORD_GET_LSBFIRST( + reinterpret_cast<uint8_t*>(&pBmp_info_header->biWidth)); + int32_t signed_height = FXDWORD_GET_LSBFIRST( + reinterpret_cast<uint8_t*>(&pBmp_info_header->biHeight)); + bitCounts = GetWord_LSBFirst( + reinterpret_cast<uint8_t*>(&pBmp_info_header->biBitCount)); + compress_flag = FXDWORD_GET_LSBFIRST( + reinterpret_cast<uint8_t*>(&pBmp_info_header->biCompression)); + color_used = FXDWORD_GET_LSBFIRST( + reinterpret_cast<uint8_t*>(&pBmp_info_header->biClrUsed)); + dpi_x = static_cast<int32_t>(FXDWORD_GET_LSBFIRST( + reinterpret_cast<uint8_t*>(&pBmp_info_header->biXPelsPerMeter))); + dpi_y = static_cast<int32_t>(FXDWORD_GET_LSBFIRST( + reinterpret_cast<uint8_t*>(&pBmp_info_header->biYPelsPerMeter))); + SetHeight(signed_height); } break; default: { - if (bmp_ptr->img_ifh_size > + if (img_ifh_size > std::min(kBmpInfoHeaderSize, sizeof(BmpInfoHeader))) { - BmpInfoHeaderPtr bmp_info_header_ptr = nullptr; - if (!bmp_read_data(bmp_ptr, (uint8_t**)&bmp_info_header_ptr, - bmp_ptr->img_ifh_size)) { - bmp_ptr->skip_size = skip_size_org; + BmpInfoHeader* pBmp_info_header = nullptr; + if (!ReadData(reinterpret_cast<uint8_t**>(&pBmp_info_header), + img_ifh_size)) { + skip_size = skip_size_org; return 2; } uint16_t biPlanes; - bmp_ptr->width = - GetDWord_LSBFirst((uint8_t*)&bmp_info_header_ptr->biWidth); - bmp_ptr->height = - GetDWord_LSBFirst((uint8_t*)&bmp_info_header_ptr->biHeight); - bmp_ptr->bitCounts = - GetWord_LSBFirst((uint8_t*)&bmp_info_header_ptr->biBitCount); - bmp_ptr->compress_flag = - GetDWord_LSBFirst((uint8_t*)&bmp_info_header_ptr->biCompression); - bmp_ptr->color_used = - GetDWord_LSBFirst((uint8_t*)&bmp_info_header_ptr->biClrUsed); - biPlanes = GetWord_LSBFirst((uint8_t*)&bmp_info_header_ptr->biPlanes); - bmp_ptr->dpi_x = GetDWord_LSBFirst( - (uint8_t*)&bmp_info_header_ptr->biXPelsPerMeter); - bmp_ptr->dpi_y = GetDWord_LSBFirst( - (uint8_t*)&bmp_info_header_ptr->biYPelsPerMeter); - if (bmp_ptr->height < 0) { - if (bmp_ptr->height == std::numeric_limits<int>::min()) { - bmp_error(bmp_ptr, "Unsupported height"); - return 0; - } - bmp_ptr->height = -bmp_ptr->height; - bmp_ptr->imgTB_flag = true; - } - if (bmp_ptr->compress_flag == BMP_RGB && biPlanes == 1 && - bmp_ptr->color_used == 0) { + width = FXDWORD_GET_LSBFIRST( + reinterpret_cast<uint8_t*>(&pBmp_info_header->biWidth)); + int32_t signed_height = FXDWORD_GET_LSBFIRST( + reinterpret_cast<uint8_t*>(&pBmp_info_header->biHeight)); + bitCounts = GetWord_LSBFirst( + reinterpret_cast<uint8_t*>(&pBmp_info_header->biBitCount)); + compress_flag = FXDWORD_GET_LSBFIRST( + reinterpret_cast<uint8_t*>(&pBmp_info_header->biCompression)); + color_used = FXDWORD_GET_LSBFIRST( + reinterpret_cast<uint8_t*>(&pBmp_info_header->biClrUsed)); + biPlanes = GetWord_LSBFirst( + reinterpret_cast<uint8_t*>(&pBmp_info_header->biPlanes)); + dpi_x = FXDWORD_GET_LSBFIRST( + reinterpret_cast<uint8_t*>(&pBmp_info_header->biXPelsPerMeter)); + dpi_y = FXDWORD_GET_LSBFIRST( + reinterpret_cast<uint8_t*>(&pBmp_info_header->biYPelsPerMeter)); + SetHeight(signed_height); + if (compress_flag == BMP_RGB && biPlanes == 1 && color_used == 0) break; - } } - bmp_error(bmp_ptr, "Unsupported Bmp File"); - return 0; + Error("Unsupported Bmp File"); + NOTREACHED(); } } - if (bmp_ptr->width <= 0 || bmp_ptr->width > BMP_MAX_WIDTH || - bmp_ptr->compress_flag > BMP_BITFIELDS) { - bmp_error(bmp_ptr, "The Bmp File Is Corrupt"); - return 0; + if (width > BMP_MAX_WIDTH || compress_flag > BMP_BITFIELDS) { + Error("The Bmp File Is Corrupt"); + NOTREACHED(); } - switch (bmp_ptr->bitCounts) { + switch (bitCounts) { case 1: case 4: case 8: case 16: case 24: { - if (bmp_ptr->color_used > ((uint32_t)1) << bmp_ptr->bitCounts) { - bmp_error(bmp_ptr, "The Bmp File Is Corrupt"); - return 0; + if (color_used > 1U << bitCounts) { + Error("The Bmp File Is Corrupt"); + NOTREACHED(); } } case 32: break; default: - bmp_error(bmp_ptr, "The Bmp File Is Corrupt"); - return 0; + Error("The Bmp File Is Corrupt"); + NOTREACHED(); } - bmp_ptr->src_row_bytes = BMP_WIDTHBYTES(bmp_ptr->width, bmp_ptr->bitCounts); - switch (bmp_ptr->bitCounts) { + src_row_bytes = BMP_WIDTHBYTES(width, bitCounts); + switch (bitCounts) { case 1: case 4: case 8: - bmp_ptr->out_row_bytes = BMP_WIDTHBYTES(bmp_ptr->width, 8); - bmp_ptr->components = 1; + out_row_bytes = BMP_WIDTHBYTES(width, 8); + components = 1; break; case 16: case 24: - bmp_ptr->out_row_bytes = BMP_WIDTHBYTES(bmp_ptr->width, 24); - bmp_ptr->components = 3; + out_row_bytes = BMP_WIDTHBYTES(width, 24); + components = 3; break; case 32: - bmp_ptr->out_row_bytes = bmp_ptr->src_row_bytes; - bmp_ptr->components = 4; + out_row_bytes = src_row_bytes; + components = 4; break; } - FX_Free(bmp_ptr->out_row_buffer); - bmp_ptr->out_row_buffer = nullptr; + out_row_buffer.clear(); - if (bmp_ptr->out_row_bytes <= 0) { - bmp_error(bmp_ptr, "The Bmp File Is Corrupt"); - return 0; + if (out_row_bytes <= 0) { + Error("The Bmp File Is Corrupt"); + NOTREACHED(); } - bmp_ptr->out_row_buffer = FX_Alloc(uint8_t, bmp_ptr->out_row_bytes); - memset(bmp_ptr->out_row_buffer, 0, bmp_ptr->out_row_bytes); - bmp_save_decoding_status(bmp_ptr, BMP_D_STATUS_PAL); + out_row_buffer.resize(out_row_bytes); + SaveDecodingStatus(BMP_D_STATUS_PAL); } - if (bmp_ptr->decode_status == BMP_D_STATUS_PAL) { - skip_size_org = bmp_ptr->skip_size; - if (bmp_ptr->compress_flag == BMP_BITFIELDS) { - if (bmp_ptr->bitCounts != 16 && bmp_ptr->bitCounts != 32) { - bmp_error(bmp_ptr, "The Bmp File Is Corrupt"); - return 0; + if (decode_status == BMP_D_STATUS_PAL) { + skip_size_org = skip_size; + if (compress_flag == BMP_BITFIELDS) { + if (bitCounts != 16 && bitCounts != 32) { + Error("The Bmp File Is Corrupt"); + NOTREACHED(); } uint32_t* mask; - if (bmp_read_data(bmp_ptr, (uint8_t**)&mask, 3 * sizeof(uint32_t)) == + if (ReadData(reinterpret_cast<uint8_t**>(&mask), 3 * sizeof(uint32_t)) == nullptr) { - bmp_ptr->skip_size = skip_size_org; + skip_size = skip_size_org; return 2; } - bmp_ptr->mask_red = GetDWord_LSBFirst((uint8_t*)&mask[0]); - bmp_ptr->mask_green = GetDWord_LSBFirst((uint8_t*)&mask[1]); - bmp_ptr->mask_blue = GetDWord_LSBFirst((uint8_t*)&mask[2]); - if (bmp_ptr->mask_red & bmp_ptr->mask_green || - bmp_ptr->mask_red & bmp_ptr->mask_blue || - bmp_ptr->mask_green & bmp_ptr->mask_blue) { - bmp_error(bmp_ptr, "The Bitfield Bmp File Is Corrupt"); - return 0; - } - if (bmp_ptr->bmp_header_ptr->bfOffBits < 26 + bmp_ptr->img_ifh_size) { - bmp_ptr->bmp_header_ptr->bfOffBits = 26 + bmp_ptr->img_ifh_size; + mask_red = FXDWORD_GET_LSBFIRST(reinterpret_cast<uint8_t*>(&mask[0])); + mask_green = FXDWORD_GET_LSBFIRST(reinterpret_cast<uint8_t*>(&mask[1])); + mask_blue = FXDWORD_GET_LSBFIRST(reinterpret_cast<uint8_t*>(&mask[2])); + if (mask_red & mask_green || mask_red & mask_blue || + mask_green & mask_blue) { + Error("The Bitfield Bmp File Is Corrupt"); + NOTREACHED(); } - bmp_save_decoding_status(bmp_ptr, BMP_D_STATUS_DATA_PRE); + header_offset = std::max(header_offset, 26 + img_ifh_size); + SaveDecodingStatus(BMP_D_STATUS_DATA_PRE); return 1; - } else if (bmp_ptr->bitCounts == 16) { - bmp_ptr->mask_red = 0x7C00; - bmp_ptr->mask_green = 0x03E0; - bmp_ptr->mask_blue = 0x001F; + } else if (bitCounts == 16) { + mask_red = 0x7C00; + mask_green = 0x03E0; + mask_blue = 0x001F; } - bmp_ptr->pal_num = 0; - if (bmp_ptr->bitCounts < 16) { - bmp_ptr->pal_num = 1 << bmp_ptr->bitCounts; - if (bmp_ptr->color_used != 0) { - bmp_ptr->pal_num = bmp_ptr->color_used; - } + pal_num = 0; + if (bitCounts < 16) { + pal_num = 1 << bitCounts; + if (color_used != 0) + pal_num = color_used; uint8_t* src_pal_ptr = nullptr; - uint32_t src_pal_size = bmp_ptr->pal_num * (bmp_ptr->pal_type ? 3 : 4); - if (bmp_read_data(bmp_ptr, (uint8_t**)&src_pal_ptr, src_pal_size) == - nullptr) { - bmp_ptr->skip_size = skip_size_org; + uint32_t src_pal_size = pal_num * (pal_type ? 3 : 4); + if (ReadData(&src_pal_ptr, src_pal_size) == nullptr) { + skip_size = skip_size_org; return 2; } - FX_Free(bmp_ptr->pal_ptr); - bmp_ptr->pal_ptr = FX_Alloc(uint32_t, bmp_ptr->pal_num); + palette.resize(pal_num); int32_t src_pal_index = 0; - if (bmp_ptr->pal_type == BMP_PAL_OLD) { - while (src_pal_index < bmp_ptr->pal_num) { - bmp_ptr->pal_ptr[src_pal_index++] = BMP_PAL_ENCODE( + if (pal_type == BMP_PAL_OLD) { + while (src_pal_index < pal_num) { + palette[src_pal_index++] = BMP_PAL_ENCODE( 0x00, src_pal_ptr[2], src_pal_ptr[1], src_pal_ptr[0]); src_pal_ptr += 3; } } else { - while (src_pal_index < bmp_ptr->pal_num) { - bmp_ptr->pal_ptr[src_pal_index++] = BMP_PAL_ENCODE( + while (src_pal_index < pal_num) { + palette[src_pal_index++] = BMP_PAL_ENCODE( src_pal_ptr[3], src_pal_ptr[2], src_pal_ptr[1], src_pal_ptr[0]); src_pal_ptr += 4; } } } - if (bmp_ptr->bmp_header_ptr->bfOffBits < - 14 + bmp_ptr->img_ifh_size + - bmp_ptr->pal_num * (bmp_ptr->pal_type ? 3 : 4)) { - bmp_ptr->bmp_header_ptr->bfOffBits = - 14 + bmp_ptr->img_ifh_size + - bmp_ptr->pal_num * (bmp_ptr->pal_type ? 3 : 4); - } - bmp_save_decoding_status(bmp_ptr, BMP_D_STATUS_DATA_PRE); + header_offset = std::max(header_offset, + 14 + img_ifh_size + pal_num * (pal_type ? 3 : 4)); + SaveDecodingStatus(BMP_D_STATUS_DATA_PRE); } return 1; } -int32_t bmp_decode_image(bmp_decompress_struct_p bmp_ptr) { - if (bmp_ptr->decode_status == BMP_D_STATUS_DATA_PRE) { - bmp_ptr->avail_in = 0; - if (!bmp_ptr->bmp_get_data_position_fn( - bmp_ptr, bmp_ptr->bmp_header_ptr->bfOffBits)) { - bmp_ptr->decode_status = BMP_D_STATUS_TAIL; - bmp_error(bmp_ptr, "The Bmp File Is Corrupt, Unexpected Stream Offset"); - return 0; - } - bmp_ptr->row_num = 0; - bmp_save_decoding_status(bmp_ptr, BMP_D_STATUS_DATA); + +bool BMPDecompressor::ValidateFlag() const { + switch (compress_flag) { + case BMP_RGB: + case BMP_BITFIELDS: + case BMP_RLE8: + case BMP_RLE4: + return true; + default: + return false; } - if (bmp_ptr->decode_status == BMP_D_STATUS_DATA) { - switch (bmp_ptr->compress_flag) { - case BMP_RGB: - case BMP_BITFIELDS: - return bmp_decode_rgb(bmp_ptr); - case BMP_RLE8: - return bmp_decode_rle8(bmp_ptr); - case BMP_RLE4: - return bmp_decode_rle4(bmp_ptr); +} + +int32_t BMPDecompressor::DecodeImage() { + if (decode_status == BMP_D_STATUS_DATA_PRE) { + avail_in = 0; + if (!GetDataPosition(header_offset)) { + decode_status = BMP_D_STATUS_TAIL; + Error("The Bmp File Is Corrupt, Unexpected Stream Offset"); + NOTREACHED(); } + row_num = 0; + SaveDecodingStatus(BMP_D_STATUS_DATA); } - bmp_error(bmp_ptr, "Any Uncontrol Error"); - return 0; + if (decode_status != BMP_D_STATUS_DATA || !ValidateFlag()) { + Error("Any Uncontrol Error"); + NOTREACHED(); + } + switch (compress_flag) { + case BMP_RGB: + case BMP_BITFIELDS: + return DecodeRGB(); + case BMP_RLE8: + return DecodeRLE8(); + case BMP_RLE4: + return DecodeRLE4(); + default: + return 0; + } +} + +bool BMPDecompressor::ValidateColorIndex(uint8_t val) { + if (val >= pal_num) { + Error("A color index exceeds range determined by pal_num"); + NOTREACHED(); + } + return true; } -int32_t bmp_decode_rgb(bmp_decompress_struct_p bmp_ptr) { - uint8_t* row_buf = bmp_ptr->out_row_buffer; + +int32_t BMPDecompressor::DecodeRGB() { uint8_t* des_buf = nullptr; - while (bmp_ptr->row_num < bmp_ptr->height) { - if (!bmp_read_data(bmp_ptr, &des_buf, bmp_ptr->src_row_bytes)) + while (row_num < height) { + size_t idx = 0; + if (!ReadData(&des_buf, src_row_bytes)) return 2; - bmp_save_decoding_status(bmp_ptr, BMP_D_STATUS_DATA); - switch (bmp_ptr->bitCounts) { + SaveDecodingStatus(BMP_D_STATUS_DATA); + switch (bitCounts) { case 1: { - for (int32_t col = 0; col < bmp_ptr->width; col++) { - *row_buf++ = des_buf[col >> 3] & (0x80 >> (col % 8)) ? 0x01 : 0x00; - } + for (uint32_t col = 0; col < width; ++col) + out_row_buffer[idx++] = + des_buf[col >> 3] & (0x80 >> (col % 8)) ? 0x01 : 0x00; } break; case 4: { - for (int32_t col = 0; col < bmp_ptr->width; col++) { - *row_buf++ = (col & 0x01) ? (des_buf[col >> 1] & 0x0F) - : ((des_buf[col >> 1] & 0xF0) >> 4); + for (uint32_t col = 0; col < width; ++col) { + out_row_buffer[idx++] = (col & 0x01) + ? (des_buf[col >> 1] & 0x0F) + : ((des_buf[col >> 1] & 0xF0) >> 4); } } break; case 16: { @@ -361,15 +371,12 @@ int32_t bmp_decode_rgb(bmp_decompress_struct_p bmp_ptr) { uint8_t green_bits = 0; uint8_t red_bits = 0; for (int32_t i = 0; i < 16; i++) { - if ((bmp_ptr->mask_blue >> i) & 0x01) { + if ((mask_blue >> i) & 0x01) blue_bits++; - } - if ((bmp_ptr->mask_green >> i) & 0x01) { + if ((mask_green >> i) & 0x01) green_bits++; - } - if ((bmp_ptr->mask_red >> i) & 0x01) { + if ((mask_red >> i) & 0x01) red_bits++; - } } green_bits += blue_bits; red_bits += green_bits; @@ -378,584 +385,292 @@ int32_t bmp_decode_rgb(bmp_decompress_struct_p bmp_ptr) { blue_bits = 8 - blue_bits; green_bits -= 8; red_bits -= 8; - for (int32_t col = 0; col < bmp_ptr->width; col++) { - *buf = GetWord_LSBFirst((uint8_t*)buf); - *row_buf++ = (uint8_t)((*buf & bmp_ptr->mask_blue) << blue_bits); - *row_buf++ = (uint8_t)((*buf & bmp_ptr->mask_green) >> green_bits); - *row_buf++ = (uint8_t)((*buf++ & bmp_ptr->mask_red) >> red_bits); + for (uint32_t col = 0; col < width; ++col) { + *buf = GetWord_LSBFirst(reinterpret_cast<uint8_t*>(buf)); + out_row_buffer[idx++] = + static_cast<uint8_t>((*buf & mask_blue) << blue_bits); + out_row_buffer[idx++] = + static_cast<uint8_t>((*buf & mask_green) >> green_bits); + out_row_buffer[idx++] = + static_cast<uint8_t>((*buf++ & mask_red) >> red_bits); } } break; case 8: case 24: case 32: - memcpy(bmp_ptr->out_row_buffer, des_buf, bmp_ptr->src_row_bytes); + std::copy(des_buf, des_buf + src_row_bytes, out_row_buffer.begin()); + idx += src_row_bytes; break; } - row_buf = bmp_ptr->out_row_buffer; - bmp_ptr->bmp_get_row_fn(bmp_ptr, - bmp_ptr->imgTB_flag - ? bmp_ptr->row_num++ - : (bmp_ptr->height - 1 - bmp_ptr->row_num++), - bmp_ptr->out_row_buffer); + for (uint8_t byte : out_row_buffer) { + if (!ValidateColorIndex(byte)) + return 0; + } + ReadScanline(imgTB_flag ? row_num++ : (height - 1 - row_num++), + out_row_buffer); } - bmp_save_decoding_status(bmp_ptr, BMP_D_STATUS_TAIL); + SaveDecodingStatus(BMP_D_STATUS_TAIL); return 1; } -int32_t bmp_decode_rle8(bmp_decompress_struct_p bmp_ptr) { + +int32_t BMPDecompressor::DecodeRLE8() { uint8_t* first_byte_ptr = nullptr; uint8_t* second_byte_ptr = nullptr; - bmp_ptr->col_num = 0; + col_num = 0; while (true) { - uint32_t skip_size_org = bmp_ptr->skip_size; - if (!bmp_read_data(bmp_ptr, &first_byte_ptr, 1)) + uint32_t skip_size_org = skip_size; + if (!ReadData(&first_byte_ptr, 1)) return 2; switch (*first_byte_ptr) { case RLE_MARKER: { - if (!bmp_read_data(bmp_ptr, &first_byte_ptr, 1)) { - bmp_ptr->skip_size = skip_size_org; + if (!ReadData(&first_byte_ptr, 1)) { + skip_size = skip_size_org; return 2; } switch (*first_byte_ptr) { case RLE_EOL: { - if (bmp_ptr->row_num >= bmp_ptr->height) { - bmp_save_decoding_status(bmp_ptr, BMP_D_STATUS_TAIL); - bmp_error(bmp_ptr, "The Bmp File Is Corrupt"); - return 0; + if (row_num >= height) { + SaveDecodingStatus(BMP_D_STATUS_TAIL); + Error("The Bmp File Is Corrupt"); + NOTREACHED(); } - bmp_ptr->bmp_get_row_fn( - bmp_ptr, bmp_ptr->imgTB_flag - ? bmp_ptr->row_num++ - : (bmp_ptr->height - 1 - bmp_ptr->row_num++), - bmp_ptr->out_row_buffer); - bmp_ptr->col_num = 0; - memset(bmp_ptr->out_row_buffer, 0, bmp_ptr->out_row_bytes); - bmp_save_decoding_status(bmp_ptr, BMP_D_STATUS_DATA); + ReadScanline(imgTB_flag ? row_num++ : (height - 1 - row_num++), + out_row_buffer); + col_num = 0; + std::fill(out_row_buffer.begin(), out_row_buffer.end(), 0); + SaveDecodingStatus(BMP_D_STATUS_DATA); continue; } case RLE_EOI: { - if (bmp_ptr->row_num < bmp_ptr->height) { - bmp_ptr->bmp_get_row_fn( - bmp_ptr, bmp_ptr->imgTB_flag - ? bmp_ptr->row_num++ - : (bmp_ptr->height - 1 - bmp_ptr->row_num++), - bmp_ptr->out_row_buffer); + if (row_num < height) { + ReadScanline(imgTB_flag ? row_num++ : (height - 1 - row_num++), + out_row_buffer); } - bmp_save_decoding_status(bmp_ptr, BMP_D_STATUS_TAIL); + SaveDecodingStatus(BMP_D_STATUS_TAIL); return 1; } case RLE_DELTA: { uint8_t* delta_ptr; - if (!bmp_read_data(bmp_ptr, &delta_ptr, 2)) { - bmp_ptr->skip_size = skip_size_org; + if (!ReadData(&delta_ptr, 2)) { + skip_size = skip_size_org; return 2; } - bmp_ptr->col_num += (int32_t)delta_ptr[0]; - int32_t bmp_row_num_next = bmp_ptr->row_num + (int32_t)delta_ptr[1]; - if (bmp_ptr->col_num >= bmp_ptr->out_row_bytes || - bmp_row_num_next >= bmp_ptr->height) { - bmp_error(bmp_ptr, "The Bmp File Is Corrupt Or Not Supported"); - return 0; + col_num += delta_ptr[0]; + size_t bmp_row_num_next = row_num + delta_ptr[1]; + if (col_num >= out_row_bytes || bmp_row_num_next >= height) { + Error("The Bmp File Is Corrupt Or Not Supported"); + NOTREACHED(); } - while (bmp_ptr->row_num < bmp_row_num_next) { - memset(bmp_ptr->out_row_buffer, 0, bmp_ptr->out_row_bytes); - bmp_ptr->bmp_get_row_fn( - bmp_ptr, bmp_ptr->imgTB_flag - ? bmp_ptr->row_num++ - : (bmp_ptr->height - 1 - bmp_ptr->row_num++), - bmp_ptr->out_row_buffer); + while (row_num < bmp_row_num_next) { + std::fill(out_row_buffer.begin(), out_row_buffer.end(), 0); + ReadScanline(imgTB_flag ? row_num++ : (height - 1 - row_num++), + out_row_buffer); } } break; default: { - int32_t avail_size = bmp_ptr->out_row_bytes - bmp_ptr->col_num; + int32_t avail_size = out_row_bytes - col_num; if (!avail_size || static_cast<int32_t>(*first_byte_ptr) > avail_size) { - bmp_error(bmp_ptr, "The Bmp File Is Corrupt"); - return 0; + Error("The Bmp File Is Corrupt"); + NOTREACHED(); } - if (!bmp_read_data(bmp_ptr, &second_byte_ptr, - *first_byte_ptr & 1 ? *first_byte_ptr + 1 - : *first_byte_ptr)) { - bmp_ptr->skip_size = skip_size_org; + if (!ReadData(&second_byte_ptr, *first_byte_ptr & 1 + ? *first_byte_ptr + 1 + : *first_byte_ptr)) { + skip_size = skip_size_org; return 2; } - memcpy(bmp_ptr->out_row_buffer + bmp_ptr->col_num, second_byte_ptr, - *first_byte_ptr); - bmp_ptr->col_num += (int32_t)(*first_byte_ptr); + std::copy(second_byte_ptr, second_byte_ptr + *first_byte_ptr, + out_row_buffer.begin() + col_num); + for (size_t i = col_num; i < col_num + *first_byte_ptr; ++i) { + if (!ValidateColorIndex(out_row_buffer[i])) + return 0; + } + col_num += *first_byte_ptr; } } } break; default: { - int32_t avail_size = bmp_ptr->out_row_bytes - bmp_ptr->col_num; + int32_t avail_size = out_row_bytes - col_num; if (!avail_size || static_cast<int32_t>(*first_byte_ptr) > avail_size) { - bmp_error(bmp_ptr, "The Bmp File Is Corrupt"); - return 0; + Error("The Bmp File Is Corrupt"); + NOTREACHED(); } - if (!bmp_read_data(bmp_ptr, &second_byte_ptr, 1)) { - bmp_ptr->skip_size = skip_size_org; + if (!ReadData(&second_byte_ptr, 1)) { + skip_size = skip_size_org; return 2; } - memset(bmp_ptr->out_row_buffer + bmp_ptr->col_num, *second_byte_ptr, - *first_byte_ptr); - bmp_ptr->col_num += (int32_t)(*first_byte_ptr); + std::fill(out_row_buffer.begin() + col_num, + out_row_buffer.begin() + col_num + *first_byte_ptr, + *second_byte_ptr); + if (!ValidateColorIndex(out_row_buffer[col_num])) + return 0; + col_num += *first_byte_ptr; } } } - bmp_error(bmp_ptr, "Any Uncontrol Error"); - return 0; + Error("Any Uncontrol Error"); + NOTREACHED(); } -int32_t bmp_decode_rle4(bmp_decompress_struct_p bmp_ptr) { +int32_t BMPDecompressor::DecodeRLE4() { uint8_t* first_byte_ptr = nullptr; uint8_t* second_byte_ptr = nullptr; - bmp_ptr->col_num = 0; + col_num = 0; while (true) { - uint32_t skip_size_org = bmp_ptr->skip_size; - if (!bmp_read_data(bmp_ptr, &first_byte_ptr, 1)) + uint32_t skip_size_org = skip_size; + if (!ReadData(&first_byte_ptr, 1)) return 2; switch (*first_byte_ptr) { case RLE_MARKER: { - if (!bmp_read_data(bmp_ptr, &first_byte_ptr, 1)) { - bmp_ptr->skip_size = skip_size_org; + if (!ReadData(&first_byte_ptr, 1)) { + skip_size = skip_size_org; return 2; } switch (*first_byte_ptr) { case RLE_EOL: { - if (bmp_ptr->row_num >= bmp_ptr->height) { - bmp_save_decoding_status(bmp_ptr, BMP_D_STATUS_TAIL); - bmp_error(bmp_ptr, "The Bmp File Is Corrupt"); - return 0; + if (row_num >= height) { + SaveDecodingStatus(BMP_D_STATUS_TAIL); + Error("The Bmp File Is Corrupt"); + NOTREACHED(); } - bmp_ptr->bmp_get_row_fn( - bmp_ptr, bmp_ptr->imgTB_flag - ? bmp_ptr->row_num++ - : (bmp_ptr->height - 1 - bmp_ptr->row_num++), - bmp_ptr->out_row_buffer); - bmp_ptr->col_num = 0; - memset(bmp_ptr->out_row_buffer, 0, bmp_ptr->out_row_bytes); - bmp_save_decoding_status(bmp_ptr, BMP_D_STATUS_DATA); + ReadScanline(imgTB_flag ? row_num++ : (height - 1 - row_num++), + out_row_buffer); + col_num = 0; + std::fill(out_row_buffer.begin(), out_row_buffer.end(), 0); + SaveDecodingStatus(BMP_D_STATUS_DATA); continue; } case RLE_EOI: { - if (bmp_ptr->row_num < bmp_ptr->height) { - bmp_ptr->bmp_get_row_fn( - bmp_ptr, bmp_ptr->imgTB_flag - ? bmp_ptr->row_num++ - : (bmp_ptr->height - 1 - bmp_ptr->row_num++), - bmp_ptr->out_row_buffer); + if (row_num < height) { + ReadScanline(imgTB_flag ? row_num++ : (height - 1 - row_num++), + out_row_buffer); } - bmp_save_decoding_status(bmp_ptr, BMP_D_STATUS_TAIL); + SaveDecodingStatus(BMP_D_STATUS_TAIL); return 1; } case RLE_DELTA: { uint8_t* delta_ptr; - if (!bmp_read_data(bmp_ptr, &delta_ptr, 2)) { - bmp_ptr->skip_size = skip_size_org; + if (!ReadData(&delta_ptr, 2)) { + skip_size = skip_size_org; return 2; } - bmp_ptr->col_num += (int32_t)delta_ptr[0]; - int32_t bmp_row_num_next = bmp_ptr->row_num + (int32_t)delta_ptr[1]; - if (bmp_ptr->col_num >= bmp_ptr->out_row_bytes || - bmp_row_num_next >= bmp_ptr->height) { - bmp_error(bmp_ptr, "The Bmp File Is Corrupt Or Not Supported"); - return 0; + col_num += delta_ptr[0]; + size_t bmp_row_num_next = row_num + delta_ptr[1]; + if (col_num >= out_row_bytes || bmp_row_num_next >= height) { + Error("The Bmp File Is Corrupt Or Not Supported"); + NOTREACHED(); } - while (bmp_ptr->row_num < bmp_row_num_next) { - memset(bmp_ptr->out_row_buffer, 0, bmp_ptr->out_row_bytes); - bmp_ptr->bmp_get_row_fn( - bmp_ptr, bmp_ptr->imgTB_flag - ? bmp_ptr->row_num++ - : (bmp_ptr->height - 1 - bmp_ptr->row_num++), - bmp_ptr->out_row_buffer); + while (row_num < bmp_row_num_next) { + std::fill(out_row_buffer.begin(), out_row_buffer.end(), 0); + ReadScanline(imgTB_flag ? row_num++ : (height - 1 - row_num++), + out_row_buffer); } } break; default: { - int32_t avail_size = bmp_ptr->out_row_bytes - bmp_ptr->col_num; + int32_t avail_size = out_row_bytes - col_num; if (!avail_size) { - bmp_error(bmp_ptr, "The Bmp File Is Corrupt"); - return 0; + Error("The Bmp File Is Corrupt"); + NOTREACHED(); } uint8_t size = HalfRoundUp(*first_byte_ptr); if (static_cast<int32_t>(*first_byte_ptr) > avail_size) { - if (size + (bmp_ptr->col_num >> 1) > bmp_ptr->src_row_bytes) { - bmp_error(bmp_ptr, "The Bmp File Is Corrupt"); - return 0; + if (size + (col_num >> 1) > src_row_bytes) { + Error("The Bmp File Is Corrupt"); + NOTREACHED(); } *first_byte_ptr = avail_size - 1; } - if (!bmp_read_data(bmp_ptr, &second_byte_ptr, - size & 1 ? size + 1 : size)) { - bmp_ptr->skip_size = skip_size_org; + if (!ReadData(&second_byte_ptr, size & 1 ? size + 1 : size)) { + skip_size = skip_size_org; return 2; } for (uint8_t i = 0; i < *first_byte_ptr; i++) { - if (i & 0x01) { - *(bmp_ptr->out_row_buffer + bmp_ptr->col_num++) = - (*second_byte_ptr++ & 0x0F); - } else { - *(bmp_ptr->out_row_buffer + bmp_ptr->col_num++) = - ((*second_byte_ptr & 0xF0) >> 4); - } + uint8_t color = (i & 0x01) ? (*second_byte_ptr++ & 0x0F) + : (*second_byte_ptr & 0xF0) >> 4; + if (!ValidateColorIndex(color)) + return 0; + + out_row_buffer[col_num++] = color; } } } } break; default: { - int32_t avail_size = bmp_ptr->out_row_bytes - bmp_ptr->col_num; + int32_t avail_size = out_row_bytes - col_num; if (!avail_size) { - bmp_error(bmp_ptr, "The Bmp File Is Corrupt"); - return 0; + Error("The Bmp File Is Corrupt"); + NOTREACHED(); } if (static_cast<int32_t>(*first_byte_ptr) > avail_size) { uint8_t size = HalfRoundUp(*first_byte_ptr); - if (size + (bmp_ptr->col_num >> 1) > bmp_ptr->src_row_bytes) { - bmp_error(bmp_ptr, "The Bmp File Is Corrupt"); - return 0; + if (size + (col_num >> 1) > src_row_bytes) { + Error("The Bmp File Is Corrupt"); + NOTREACHED(); } *first_byte_ptr = avail_size - 1; } - if (!bmp_read_data(bmp_ptr, &second_byte_ptr, 1)) { - bmp_ptr->skip_size = skip_size_org; + if (!ReadData(&second_byte_ptr, 1)) { + skip_size = skip_size_org; return 2; } for (uint8_t i = 0; i < *first_byte_ptr; i++) { uint8_t second_byte = *second_byte_ptr; second_byte = i & 0x01 ? (second_byte & 0x0F) : (second_byte & 0xF0) >> 4; - *(bmp_ptr->out_row_buffer + bmp_ptr->col_num++) = second_byte; + if (!ValidateColorIndex(second_byte)) + return 0; + out_row_buffer[col_num++] = second_byte; } } } } - bmp_error(bmp_ptr, "Any Uncontrol Error"); - return 0; + Error("Any Uncontrol Error"); + NOTREACHED(); } -uint8_t* bmp_read_data(bmp_decompress_struct_p bmp_ptr, - uint8_t** des_buf_pp, - uint32_t data_size) { - if (!bmp_ptr || bmp_ptr->avail_in < bmp_ptr->skip_size + data_size) +uint8_t* BMPDecompressor::ReadData(uint8_t** des_buf, uint32_t data_size) { + if (avail_in < skip_size + data_size) return nullptr; - *des_buf_pp = bmp_ptr->next_in + bmp_ptr->skip_size; - bmp_ptr->skip_size += data_size; - return *des_buf_pp; -} -void bmp_save_decoding_status(bmp_decompress_struct_p bmp_ptr, int32_t status) { - bmp_ptr->decode_status = status; - bmp_ptr->next_in += bmp_ptr->skip_size; - bmp_ptr->avail_in -= bmp_ptr->skip_size; - bmp_ptr->skip_size = 0; -} -void bmp_input_buffer(bmp_decompress_struct_p bmp_ptr, - uint8_t* src_buf, - uint32_t src_size) { - bmp_ptr->next_in = src_buf; - bmp_ptr->avail_in = src_size; - bmp_ptr->skip_size = 0; -} -uint32_t bmp_get_avail_input(bmp_decompress_struct_p bmp_ptr, - uint8_t** avail_buf_ptr) { - if (avail_buf_ptr) { - *avail_buf_ptr = nullptr; - if (bmp_ptr->avail_in > 0) { - *avail_buf_ptr = bmp_ptr->next_in; - } - } - return bmp_ptr->avail_in; -} -bmp_compress_struct_p bmp_create_compress() { - bmp_compress_struct_p bmp_ptr; - bmp_ptr = FX_Alloc(bmp_compress_struct, 1); - if (bmp_ptr) { - memset(bmp_ptr, 0, sizeof(bmp_compress_struct)); - } - return bmp_ptr; -} -void bmp_destroy_compress(bmp_compress_struct_p bmp_ptr) { - if (bmp_ptr) { - if (bmp_ptr->src_free && bmp_ptr->src_buf) { - FX_Free(bmp_ptr->src_buf); - } - FX_Free(bmp_ptr); - } + *des_buf = next_in + skip_size; + skip_size += data_size; + return *des_buf; } -static void WriteFileHeader(BmpFileHeaderPtr head_ptr, uint8_t* dst_buf) { - uint32_t offset; - offset = 0; - SetWord_LSBFirst(&dst_buf[offset], head_ptr->bfType); - offset += 2; - SetDWord_LSBFirst(&dst_buf[offset], head_ptr->bfSize); - offset += 4; - SetWord_LSBFirst(&dst_buf[offset], head_ptr->bfReserved1); - offset += 2; - SetWord_LSBFirst(&dst_buf[offset], head_ptr->bfReserved2); - offset += 2; - SetDWord_LSBFirst(&dst_buf[offset], head_ptr->bfOffBits); - offset += 4; + +void BMPDecompressor::SaveDecodingStatus(int32_t status) { + decode_status = status; + next_in += skip_size; + avail_in -= skip_size; + skip_size = 0; } -static void WriteInfoHeader(BmpInfoHeaderPtr info_head_ptr, uint8_t* dst_buf) { - uint32_t offset; - offset = sizeof(BmpFileHeader); - SetDWord_LSBFirst(&dst_buf[offset], info_head_ptr->biSize); - offset += 4; - SetDWord_LSBFirst(&dst_buf[offset], info_head_ptr->biWidth); - offset += 4; - SetDWord_LSBFirst(&dst_buf[offset], info_head_ptr->biHeight); - offset += 4; - SetWord_LSBFirst(&dst_buf[offset], info_head_ptr->biPlanes); - offset += 2; - SetWord_LSBFirst(&dst_buf[offset], info_head_ptr->biBitCount); - offset += 2; - SetDWord_LSBFirst(&dst_buf[offset], info_head_ptr->biCompression); - offset += 4; - SetDWord_LSBFirst(&dst_buf[offset], info_head_ptr->biSizeImage); - offset += 4; - SetDWord_LSBFirst(&dst_buf[offset], info_head_ptr->biXPelsPerMeter); - offset += 4; - SetDWord_LSBFirst(&dst_buf[offset], info_head_ptr->biYPelsPerMeter); - offset += 4; - SetDWord_LSBFirst(&dst_buf[offset], info_head_ptr->biClrUsed); - offset += 4; - SetDWord_LSBFirst(&dst_buf[offset], info_head_ptr->biClrImportant); - offset += 4; + +void BMPDecompressor::SetInputBuffer(uint8_t* src_buf, uint32_t src_size) { + next_in = src_buf; + avail_in = src_size; + skip_size = 0; } -static void bmp_encode_bitfields(bmp_compress_struct_p bmp_ptr, - uint8_t*& dst_buf, - uint32_t& dst_size) { - if (bmp_ptr->info_header.biBitCount != 16 && - bmp_ptr->info_header.biBitCount != 32) { - return; - } - uint32_t size, dst_pos, i; - size = bmp_ptr->src_pitch * bmp_ptr->src_row * - bmp_ptr->info_header.biBitCount / 16; - dst_pos = bmp_ptr->file_header.bfOffBits; - dst_size += size; - dst_buf = FX_Realloc(uint8_t, dst_buf, dst_size); - memset(&dst_buf[dst_pos], 0, size); - uint32_t mask_red; - uint32_t mask_green; - uint32_t mask_blue; - mask_red = 0x7C00; - mask_green = 0x03E0; - mask_blue = 0x001F; - if (bmp_ptr->info_header.biCompression == BMP_BITFIELDS) { - if (bmp_ptr->bit_type == BMP_BIT_565) { - mask_red = 0xF800; - mask_green = 0x07E0; - mask_blue = 0x001F; - } - if (bmp_ptr->info_header.biBitCount == 32) { - mask_red = 0xFF0000; - mask_green = 0x00FF00; - mask_blue = 0x0000FF; - } - SetDWord_LSBFirst(&dst_buf[dst_pos], mask_red); - dst_pos += 4; - SetDWord_LSBFirst(&dst_buf[dst_pos], mask_green); - dst_pos += 4; - SetDWord_LSBFirst(&dst_buf[dst_pos], mask_blue); - dst_pos += 4; - bmp_ptr->file_header.bfOffBits = dst_pos; - } - uint8_t blue_bits = 0; - uint8_t green_bits = 0; - uint8_t red_bits = 0; - for (i = 0; i < bmp_ptr->info_header.biBitCount; i++) { - if ((mask_blue >> i) & 0x01) { - blue_bits++; - } - if ((mask_green >> i) & 0x01) { - green_bits++; - } - if ((mask_red >> i) & 0x01) { - red_bits++; - } - } - green_bits += blue_bits; - red_bits += green_bits; - blue_bits = 8 - blue_bits; - green_bits -= 8; - red_bits -= 8; - i = 0; - for (int32_t row_num = bmp_ptr->src_row - 1; row_num > -1; row_num--, i = 0) { - while (i < bmp_ptr->src_width * bmp_ptr->src_bpp / 8) { - uint8_t b = bmp_ptr->src_buf[row_num * bmp_ptr->src_pitch + i++]; - uint8_t g = bmp_ptr->src_buf[row_num * bmp_ptr->src_pitch + i++]; - uint8_t r = bmp_ptr->src_buf[row_num * bmp_ptr->src_pitch + i++]; - if (bmp_ptr->src_bpp == 32) { - i++; - } - uint32_t pix_val = 0; - pix_val |= (b >> blue_bits) & mask_blue; - pix_val |= (g << green_bits) & mask_green; - pix_val |= (r << red_bits) & mask_red; - if (bmp_ptr->info_header.biBitCount == 16) { - SetWord_LSBFirst(&dst_buf[dst_pos], pix_val); - dst_pos += 2; - } else { - SetDWord_LSBFirst(&dst_buf[dst_pos], pix_val); - dst_pos += 4; - } - } + +uint32_t BMPDecompressor::GetAvailInput(uint8_t** avail_buf) { + if (avail_buf) { + *avail_buf = nullptr; + if (avail_in > 0) + *avail_buf = next_in; } - dst_size = dst_pos; + return avail_in; } -static void bmp_encode_rgb(bmp_compress_struct_p bmp_ptr, - uint8_t*& dst_buf, - uint32_t& dst_size) { - if (bmp_ptr->info_header.biBitCount == 16) { - bmp_encode_bitfields(bmp_ptr, dst_buf, dst_size); +void BMPDecompressor::SetHeight(int32_t signed_height) { + if (signed_height >= 0) { + height = signed_height; return; } - uint32_t size, dst_pos; - uint32_t dst_pitch = - (bmp_ptr->src_width * bmp_ptr->info_header.biBitCount + 31) / 32 * 4; - size = dst_pitch * bmp_ptr->src_row; - dst_pos = bmp_ptr->file_header.bfOffBits; - dst_size += size; - dst_buf = FX_Realloc(uint8_t, dst_buf, dst_size); - memset(&dst_buf[dst_pos], 0, size); - for (int32_t row_num = bmp_ptr->src_row - 1; row_num > -1; row_num--) { - memcpy(&dst_buf[dst_pos], &bmp_ptr->src_buf[row_num * bmp_ptr->src_pitch], - bmp_ptr->src_pitch); - dst_pos += dst_pitch; - } - dst_size = dst_pos; -} -static uint8_t bmp_rle8_search(const uint8_t* buf, int32_t len) { - uint8_t num; - num = 1; - while (num < len) { - if (buf[num - 1] != buf[num] || num == 0xFF) { - break; - } - num++; - } - return num; -} -static void bmp_encode_rle8(bmp_compress_struct_p bmp_ptr, - uint8_t*& dst_buf, - uint32_t& dst_size) { - uint32_t size, dst_pos, index; - uint8_t rle[2] = {0}; - size = bmp_ptr->src_pitch * bmp_ptr->src_row * 2; - dst_pos = bmp_ptr->file_header.bfOffBits; - dst_size += size; - dst_buf = FX_Realloc(uint8_t, dst_buf, dst_size); - memset(&dst_buf[dst_pos], 0, size); - for (int32_t row_num = bmp_ptr->src_row - 1, i = 0; row_num > -1;) { - index = row_num * bmp_ptr->src_pitch; - rle[0] = bmp_rle8_search(&bmp_ptr->src_buf[index + i], size - index - i); - rle[1] = bmp_ptr->src_buf[index + i]; - if (i + rle[0] >= (int32_t)bmp_ptr->src_pitch) { - rle[0] = uint8_t(bmp_ptr->src_pitch - i); - if (rle[0]) { - dst_buf[dst_pos++] = rle[0]; - dst_buf[dst_pos++] = rle[1]; - } - dst_buf[dst_pos++] = RLE_MARKER; - dst_buf[dst_pos++] = RLE_EOL; - i = 0; - row_num--; - } else { - i += rle[0]; - dst_buf[dst_pos++] = rle[0]; - dst_buf[dst_pos++] = rle[1]; - } + if (signed_height == std::numeric_limits<int>::min()) { + Error("Unsupported height"); + NOTREACHED(); } - dst_buf[dst_pos++] = RLE_MARKER; - dst_buf[dst_pos++] = RLE_EOI; - dst_size = dst_pos; -} -static uint8_t bmp_rle4_search(const uint8_t* buf, int32_t len) { - uint8_t num; - num = 2; - while (num < len) { - if (buf[num - 2] != buf[num] || num == 0xFF) { - break; - } - num++; - } - return num; -} -static void bmp_encode_rle4(bmp_compress_struct_p bmp_ptr, - uint8_t*& dst_buf, - uint32_t& dst_size) { - uint32_t size, dst_pos, index; - uint8_t rle[2] = {0}; - size = bmp_ptr->src_pitch * bmp_ptr->src_row; - dst_pos = bmp_ptr->file_header.bfOffBits; - dst_size += size; - dst_buf = FX_Realloc(uint8_t, dst_buf, dst_size); - memset(&dst_buf[dst_pos], 0, size); - for (int32_t row_num = bmp_ptr->src_row - 1, i = 0; row_num > -1; - rle[1] = 0) { - index = row_num * bmp_ptr->src_pitch; - rle[0] = bmp_rle4_search(&bmp_ptr->src_buf[index + i], size - index - i); - rle[1] |= (bmp_ptr->src_buf[index + i] & 0x0f) << 4; - rle[1] |= bmp_ptr->src_buf[index + i + 1] & 0x0f; - if (i + rle[0] >= (int32_t)bmp_ptr->src_pitch) { - rle[0] = uint8_t(bmp_ptr->src_pitch - i); - if (rle[0]) { - dst_buf[dst_pos++] = rle[0]; - dst_buf[dst_pos++] = rle[1]; - } - dst_buf[dst_pos++] = RLE_MARKER; - dst_buf[dst_pos++] = RLE_EOL; - i = 0; - row_num--; - } else { - i += rle[0]; - dst_buf[dst_pos++] = rle[0]; - dst_buf[dst_pos++] = rle[1]; - } - } - dst_buf[dst_pos++] = RLE_MARKER; - dst_buf[dst_pos++] = RLE_EOI; - dst_size = dst_pos; -} -bool bmp_encode_image(bmp_compress_struct_p bmp_ptr, - uint8_t*& dst_buf, - uint32_t& dst_size) { - uint32_t head_size = sizeof(BmpFileHeader) + sizeof(BmpInfoHeader); - uint32_t pal_size = sizeof(uint32_t) * bmp_ptr->pal_num; - if (bmp_ptr->info_header.biClrUsed > 0 && - bmp_ptr->info_header.biClrUsed < bmp_ptr->pal_num) { - pal_size = sizeof(uint32_t) * bmp_ptr->info_header.biClrUsed; - } - dst_size = head_size + sizeof(uint32_t) * bmp_ptr->pal_num; - dst_buf = FX_TryAlloc(uint8_t, dst_size); - if (!dst_buf) - return false; - - memset(dst_buf, 0, dst_size); - bmp_ptr->file_header.bfOffBits = head_size; - if (bmp_ptr->pal_ptr && pal_size) { - memcpy(&dst_buf[head_size], bmp_ptr->pal_ptr, pal_size); - bmp_ptr->file_header.bfOffBits += pal_size; - } - WriteInfoHeader(&bmp_ptr->info_header, dst_buf); - switch (bmp_ptr->info_header.biCompression) { - case BMP_RGB: - bmp_encode_rgb(bmp_ptr, dst_buf, dst_size); - break; - case BMP_BITFIELDS: - bmp_encode_bitfields(bmp_ptr, dst_buf, dst_size); - break; - case BMP_RLE8: - bmp_encode_rle8(bmp_ptr, dst_buf, dst_size); - break; - case BMP_RLE4: - bmp_encode_rle4(bmp_ptr, dst_buf, dst_size); - break; - default: - break; - } - bmp_ptr->file_header.bfSize = dst_size; - WriteFileHeader(&bmp_ptr->file_header, dst_buf); - return true; + height = -signed_height; + imgTB_flag = true; } diff --git a/chromium/third_party/pdfium/core/fxcodec/lbmp/fx_bmp.h b/chromium/third_party/pdfium/core/fxcodec/lbmp/fx_bmp.h index 5d1f799fd1f..175d9bede5b 100644 --- a/chromium/third_party/pdfium/core/fxcodec/lbmp/fx_bmp.h +++ b/chromium/third_party/pdfium/core/fxcodec/lbmp/fx_bmp.h @@ -9,6 +9,10 @@ #include <setjmp.h> +#include <memory> +#include <vector> + +#include "core/fxcodec/codec/ccodec_bmpmodule.h" #include "core/fxcrt/fx_basic.h" #define BMP_WIDTHBYTES(width, bitCount) ((width * bitCount) + 31) / 32 * 4 @@ -42,14 +46,14 @@ typedef struct tagBmpFileHeader { uint16_t bfReserved1; uint16_t bfReserved2; uint32_t bfOffBits; -} BmpFileHeader, *BmpFileHeaderPtr; +} BmpFileHeader; typedef struct tagBmpCoreHeader { uint32_t bcSize; uint16_t bcWidth; uint16_t bcHeight; uint16_t bcPlanes; uint16_t bcBitCount; -} BmpCoreHeader, *BmpCoreHeaderPtr; +} BmpCoreHeader; typedef struct tagBmpInfoHeader { uint32_t biSize; int32_t biWidth; @@ -62,96 +66,80 @@ typedef struct tagBmpInfoHeader { int32_t biYPelsPerMeter; uint32_t biClrUsed; uint32_t biClrImportant; -} BmpInfoHeader, *BmpInfoHeaderPtr; +} BmpInfoHeader; #pragma pack() -typedef struct tag_bmp_decompress_struct bmp_decompress_struct; -typedef bmp_decompress_struct* bmp_decompress_struct_p; -typedef bmp_decompress_struct_p* bmp_decompress_struct_pp; -struct tag_bmp_decompress_struct { +class BMPDecompressor { + public: + BMPDecompressor(); + ~BMPDecompressor(); + + void Error(const char* err_msg); + int32_t DecodeImage(); + int32_t ReadHeader(); + void SetInputBuffer(uint8_t* src_buf, uint32_t src_size); + uint32_t GetAvailInput(uint8_t** avail_buf); + jmp_buf jmpbuf; char* err_ptr; - void (*bmp_error_fn)(bmp_decompress_struct_p gif_ptr, const char* err_msg); void* context_ptr; - BmpFileHeaderPtr bmp_header_ptr; - BmpInfoHeaderPtr bmp_infoheader_ptr; - int32_t width; - int32_t height; + std::vector<uint8_t> out_row_buffer; + std::vector<uint32_t> palette; + uint8_t* next_in; + + uint32_t header_offset; + uint32_t width; + uint32_t height; uint32_t compress_flag; int32_t components; - int32_t src_row_bytes; - int32_t out_row_bytes; - uint8_t* out_row_buffer; + size_t src_row_bytes; + size_t out_row_bytes; uint16_t bitCounts; uint32_t color_used; bool imgTB_flag; int32_t pal_num; int32_t pal_type; - uint32_t* pal_ptr; uint32_t data_size; uint32_t img_data_offset; uint32_t img_ifh_size; - int32_t row_num; - int32_t col_num; + size_t row_num; + size_t col_num; int32_t dpi_x; int32_t dpi_y; uint32_t mask_red; uint32_t mask_green; uint32_t mask_blue; - bool (*bmp_get_data_position_fn)(bmp_decompress_struct_p bmp_ptr, - uint32_t cur_pos); - void (*bmp_get_row_fn)(bmp_decompress_struct_p bmp_ptr, - int32_t row_num, - uint8_t* row_buf); - uint8_t* next_in; uint32_t avail_in; uint32_t skip_size; int32_t decode_status; -}; -void bmp_error(bmp_decompress_struct_p bmp_ptr, const char* err_msg); -bmp_decompress_struct_p bmp_create_decompress(); -void bmp_destroy_decompress(bmp_decompress_struct_pp bmp_ptr_ptr); -int32_t bmp_read_header(bmp_decompress_struct_p bmp_ptr); -int32_t bmp_decode_image(bmp_decompress_struct_p bmp_ptr); -int32_t bmp_decode_rgb(bmp_decompress_struct_p bmp_ptr); -int32_t bmp_decode_rle8(bmp_decompress_struct_p bmp_ptr); -int32_t bmp_decode_rle4(bmp_decompress_struct_p bmp_ptr); -uint8_t* bmp_read_data(bmp_decompress_struct_p bmp_ptr, - uint8_t** des_buf_pp, - uint32_t data_size); -void bmp_save_decoding_status(bmp_decompress_struct_p bmp_ptr, int32_t status); -void bmp_input_buffer(bmp_decompress_struct_p bmp_ptr, - uint8_t* src_buf, - uint32_t src_size); -uint32_t bmp_get_avail_input(bmp_decompress_struct_p bmp_ptr, - uint8_t** avail_buf_ptr); -typedef struct tag_bmp_compress_struct bmp_compress_struct; -typedef bmp_compress_struct* bmp_compress_struct_p; -typedef bmp_compress_struct_p* bmp_compress_struct_pp; -struct tag_bmp_compress_struct { - BmpFileHeader file_header; - BmpInfoHeader info_header; - uint8_t* src_buf; - uint32_t src_pitch; - uint32_t src_row; - uint8_t src_bpp; - uint32_t src_width; - bool src_free; - uint32_t* pal_ptr; - uint16_t pal_num; - uint8_t bit_type; + + private: + bool GetDataPosition(uint32_t cur_pos); + void ReadScanline(uint32_t row_num, const std::vector<uint8_t>& row_buf); + int32_t DecodeRGB(); + int32_t DecodeRLE8(); + int32_t DecodeRLE4(); + uint8_t* ReadData(uint8_t** des_buf, uint32_t data_size); + void SaveDecodingStatus(int32_t status); + bool ValidateColorIndex(uint8_t val); + bool ValidateFlag() const; + void SetHeight(int32_t signed_height); }; -bmp_compress_struct_p bmp_create_compress(); -void bmp_destroy_compress(bmp_compress_struct_p bmp_ptr); -bool bmp_encode_image(bmp_compress_struct_p bmp_ptr, - uint8_t*& dst_buf, - uint32_t& dst_size); +class CBmpContext : public CCodec_BmpModule::Context { + public: + CBmpContext(CCodec_BmpModule* pModule, CCodec_BmpModule::Delegate* pDelegate); + ~CBmpContext() override; + + BMPDecompressor m_Bmp; + CFX_UnownedPtr<CCodec_BmpModule> const m_pModule; + CFX_UnownedPtr<CCodec_BmpModule::Delegate> const m_pDelegate; + char m_szLastError[256]; +}; uint16_t GetWord_LSBFirst(uint8_t* p); -void SetWord_LSBFirst(uint8_t* p, uint16_t v); #endif // CORE_FXCODEC_LBMP_FX_BMP_H_ diff --git a/chromium/third_party/pdfium/core/fxcodec/lgif/cgifcontext.cpp b/chromium/third_party/pdfium/core/fxcodec/lgif/cgifcontext.cpp index 9c03cffa21a..e57e9782185 100644 --- a/chromium/third_party/pdfium/core/fxcodec/lgif/cgifcontext.cpp +++ b/chromium/third_party/pdfium/core/fxcodec/lgif/cgifcontext.cpp @@ -13,15 +13,16 @@ #include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" -CGifContext::CGifContext(CCodec_GifModule* gif_module, char* error_string) - : global_pal_num(0), +CGifContext::CGifContext(CCodec_GifModule* gif_module, + CCodec_GifModule::Delegate* pDelegate) + : m_pModule(gif_module), + m_pDelegate(pDelegate), + global_pal_num(0), img_row_offset(0), img_row_avail_size(0), avail_in(0), decode_status(GIF_D_STATUS_SIG), skip_size(0), - m_Module(gif_module), - err_ptr(error_string), next_in(nullptr), width(0), height(0), @@ -29,20 +30,22 @@ CGifContext::CGifContext(CCodec_GifModule* gif_module, char* error_string) pixel_aspect(0), global_sort_flag(0), global_color_resolution(0), - img_pass_num(0) {} + img_pass_num(0) { + memset(m_szLastError, 0, sizeof(m_szLastError)); +} CGifContext::~CGifContext() {} void CGifContext::AddError(const char* err_msg) { - strncpy(err_ptr, err_msg, GIF_MAX_ERROR_SIZE - 1); + strncpy(m_szLastError, err_msg, GIF_MAX_ERROR_SIZE - 1); } void CGifContext::RecordCurrentPosition(uint32_t* cur_pos_ptr) { - m_Module->GetDelegate()->GifRecordCurrentPosition(*cur_pos_ptr); + m_pDelegate->GifRecordCurrentPosition(*cur_pos_ptr); } void CGifContext::ReadScanline(int32_t row_num, uint8_t* row_buf) { - m_Module->GetDelegate()->GifReadScanline(row_num, row_buf); + m_pDelegate->GifReadScanline(row_num, row_buf); } bool CGifContext::GetRecordPosition(uint32_t cur_pos, @@ -57,7 +60,7 @@ bool CGifContext::GetRecordPosition(uint32_t cur_pos, int32_t trans_index, int32_t disposal_method, bool interlace) { - return m_Module->GetDelegate()->GifInputRecordPositionBuf( + return m_pDelegate->GifInputRecordPositionBuf( cur_pos, FX_RECT(left, top, left + width, top + height), pal_num, pal_ptr, delay_time, user_input, trans_index, disposal_method, interlace); } diff --git a/chromium/third_party/pdfium/core/fxcodec/lgif/cgifcontext.h b/chromium/third_party/pdfium/core/fxcodec/lgif/cgifcontext.h index 08a66c18e29..fa46b14559b 100644 --- a/chromium/third_party/pdfium/core/fxcodec/lgif/cgifcontext.h +++ b/chromium/third_party/pdfium/core/fxcodec/lgif/cgifcontext.h @@ -10,15 +10,16 @@ #include <memory> #include <vector> +#include "core/fxcodec/codec/ccodec_gifmodule.h" #include "core/fxcodec/lgif/fx_gif.h" +#include "core/fxcrt/cfx_unowned_ptr.h" #include "core/fxcrt/fx_basic.h" -class CCodec_GifModule; - -class CGifContext { +class CGifContext : public CCodec_GifModule::Context { public: - CGifContext(CCodec_GifModule* gif_module, char* error_string); - ~CGifContext(); + CGifContext(CCodec_GifModule* gif_module, + CCodec_GifModule::Delegate* pDelegate); + ~CGifContext() override; void AddError(const char* err_msg); void RecordCurrentPosition(uint32_t* cur_pos_ptr); @@ -36,6 +37,8 @@ class CGifContext { int32_t disposal_method, bool interlace); + CFX_UnownedPtr<CCodec_GifModule> m_pModule; + CFX_UnownedPtr<CCodec_GifModule::Delegate> m_pDelegate; std::vector<GifPalette> m_GlobalPalette; int32_t global_pal_num; uint32_t img_row_offset; @@ -43,23 +46,19 @@ class CGifContext { uint32_t avail_in; int32_t decode_status; uint32_t skip_size; - - CCodec_GifModule* m_Module; - char* err_ptr; CFX_ByteString cmt_data; std::unique_ptr<GifGCE> m_GifGCE; uint8_t* next_in; std::vector<std::unique_ptr<GifImage>> m_Images; std::unique_ptr<CGifLZWDecoder> m_ImgDecoder; - int width; int height; - uint8_t bc_index; uint8_t pixel_aspect; uint8_t global_sort_flag; uint8_t global_color_resolution; uint8_t img_pass_num; + char m_szLastError[GIF_MAX_ERROR_SIZE]; }; #endif // CORE_FXCODEC_LGIF_CGIFCONTEXT_H_ diff --git a/chromium/third_party/pdfium/core/fxcodec/lgif/fx_gif.cpp b/chromium/third_party/pdfium/core/fxcodec/lgif/fx_gif.cpp index b4fe328f6c4..cef4f9a9a5b 100644 --- a/chromium/third_party/pdfium/core/fxcodec/lgif/fx_gif.cpp +++ b/chromium/third_party/pdfium/core/fxcodec/lgif/fx_gif.cpp @@ -565,7 +565,7 @@ GifDecodeStatus gif_load_frame(CGifContext* context, int32_t frame_num) { } if (!context->m_ImgDecoder.get()) context->m_ImgDecoder = - pdfium::MakeUnique<CGifLZWDecoder>(context->err_ptr); + pdfium::MakeUnique<CGifLZWDecoder>(context->m_szLastError); context->m_ImgDecoder->InitTable(gif_image_ptr->image_code_size); context->img_row_offset = 0; context->img_row_avail_size = 0; diff --git a/chromium/third_party/pdfium/core/fxcrt/cfx_bytestring.cpp b/chromium/third_party/pdfium/core/fxcrt/cfx_bytestring.cpp index f0dc370cc90..c88ad51ab32 100644 --- a/chromium/third_party/pdfium/core/fxcrt/cfx_bytestring.cpp +++ b/chromium/third_party/pdfium/core/fxcrt/cfx_bytestring.cpp @@ -101,15 +101,16 @@ CFX_ByteString GetByteString(uint16_t codepage, const CFX_WideStringC& wstr) { ASSERT(IsValidCodePage(codepage)); int src_len = wstr.GetLength(); - int dest_len = FXSYS_WideCharToMultiByte(codepage, 0, wstr.c_str(), src_len, - nullptr, 0, nullptr, nullptr); + int dest_len = + FXSYS_WideCharToMultiByte(codepage, 0, wstr.unterminated_c_str(), src_len, + nullptr, 0, nullptr, nullptr); if (!dest_len) return CFX_ByteString(); CFX_ByteString bstr; char* dest_buf = bstr.GetBuffer(dest_len); - FXSYS_WideCharToMultiByte(codepage, 0, wstr.c_str(), src_len, dest_buf, - dest_len, nullptr, nullptr); + FXSYS_WideCharToMultiByte(codepage, 0, wstr.unterminated_c_str(), src_len, + dest_buf, dest_len, nullptr, nullptr); bstr.ReleaseBuffer(dest_len); return bstr; } @@ -153,7 +154,8 @@ CFX_ByteString::CFX_ByteString(const char* ptr) CFX_ByteString::CFX_ByteString(const CFX_ByteStringC& stringSrc) { if (!stringSrc.IsEmpty()) - m_pData.Reset(StringData::Create(stringSrc.c_str(), stringSrc.GetLength())); + m_pData.Reset(StringData::Create(stringSrc.unterminated_c_str(), + stringSrc.GetLength())); } CFX_ByteString::CFX_ByteString(const CFX_ByteStringC& str1, @@ -166,8 +168,9 @@ CFX_ByteString::CFX_ByteString(const CFX_ByteStringC& str1, return; m_pData.Reset(StringData::Create(nNewLen)); - m_pData->CopyContents(str1.c_str(), str1.GetLength()); - m_pData->CopyContentsAt(str1.GetLength(), str2.c_str(), str2.GetLength()); + m_pData->CopyContents(str1.unterminated_c_str(), str1.GetLength()); + m_pData->CopyContentsAt(str1.GetLength(), str2.unterminated_c_str(), + str2.GetLength()); } CFX_ByteString::CFX_ByteString( @@ -184,11 +187,16 @@ CFX_ByteString::CFX_ByteString( FX_STRSIZE nOffset = 0; for (const auto& item : list) { - m_pData->CopyContentsAt(nOffset, item.c_str(), item.GetLength()); + m_pData->CopyContentsAt(nOffset, item.unterminated_c_str(), + item.GetLength()); nOffset += item.GetLength(); } } +CFX_ByteString::CFX_ByteString(std::ostringstream& outStream) + : CFX_ByteString(outStream.str().c_str(), + static_cast<int>(outStream.tellp())) {} + CFX_ByteString::~CFX_ByteString() {} const CFX_ByteString& CFX_ByteString::operator=(const char* pStr) { @@ -205,7 +213,7 @@ const CFX_ByteString& CFX_ByteString::operator=( if (stringSrc.IsEmpty()) clear(); else - AssignCopy(stringSrc.c_str(), stringSrc.GetLength()); + AssignCopy(stringSrc.unterminated_c_str(), stringSrc.GetLength()); return *this; } @@ -239,7 +247,7 @@ const CFX_ByteString& CFX_ByteString::operator+=(const CFX_ByteString& str) { const CFX_ByteString& CFX_ByteString::operator+=(const CFX_ByteStringC& str) { if (!str.IsEmpty()) - Concat(str.c_str(), str.GetLength()); + Concat(str.unterminated_c_str(), str.GetLength()); return *this; } @@ -260,7 +268,8 @@ bool CFX_ByteString::operator==(const CFX_ByteStringC& str) const { return str.IsEmpty(); return m_pData->m_nDataLength == str.GetLength() && - memcmp(m_pData->m_String, str.c_str(), str.GetLength()) == 0; + memcmp(m_pData->m_String, str.unterminated_c_str(), str.GetLength()) == + 0; } bool CFX_ByteString::operator==(const CFX_ByteString& other) const { @@ -590,7 +599,7 @@ FX_STRSIZE CFX_ByteString::Find(const CFX_ByteStringC& pSub, const char* pStr = FX_strstr(m_pData->m_String + nStart, m_pData->m_nDataLength - nStart, - pSub.c_str(), pSub.GetLength()); + pSub.unterminated_c_str(), pSub.GetLength()); return pStr ? (int)(pStr - m_pData->m_String) : -1; } @@ -656,7 +665,7 @@ FX_STRSIZE CFX_ByteString::Replace(const CFX_ByteStringC& pOld, char* pEnd = m_pData->m_String + m_pData->m_nDataLength; while (1) { const char* pTarget = FX_strstr(pStart, (FX_STRSIZE)(pEnd - pStart), - pOld.c_str(), nSourceLen); + pOld.unterminated_c_str(), nSourceLen); if (!pTarget) break; @@ -679,10 +688,10 @@ FX_STRSIZE CFX_ByteString::Replace(const CFX_ByteStringC& pOld, char* pDest = pNewData->m_String; for (FX_STRSIZE i = 0; i < nCount; i++) { const char* pTarget = FX_strstr(pStart, (FX_STRSIZE)(pEnd - pStart), - pOld.c_str(), nSourceLen); + pOld.unterminated_c_str(), nSourceLen); memcpy(pDest, pStart, pTarget - pStart); pDest += pTarget - pStart; - memcpy(pDest, pNew.c_str(), pNew.GetLength()); + memcpy(pDest, pNew.unterminated_c_str(), pNew.GetLength()); pDest += pNew.GetLength(); pStart = pTarget + nSourceLen; } @@ -863,8 +872,17 @@ FX_STRSIZE FX_ftoa(float d, char* buf) { } return buf_size; } + CFX_ByteString CFX_ByteString::FormatFloat(float d, int precision) { char buf[32]; FX_STRSIZE len = FX_ftoa(d, buf); return CFX_ByteString(buf, len); } + +std::ostream& operator<<(std::ostream& os, const CFX_ByteString& str) { + return os.write(str.c_str(), str.GetLength()); +} + +std::ostream& operator<<(std::ostream& os, const CFX_ByteStringC& str) { + return os.write(str.unterminated_c_str(), str.GetLength()); +} diff --git a/chromium/third_party/pdfium/core/fxcrt/cfx_bytestring.h b/chromium/third_party/pdfium/core/fxcrt/cfx_bytestring.h index c4d48954ba2..abf8ac80c84 100644 --- a/chromium/third_party/pdfium/core/fxcrt/cfx_bytestring.h +++ b/chromium/third_party/pdfium/core/fxcrt/cfx_bytestring.h @@ -8,6 +8,7 @@ #define CORE_FXCRT_CFX_BYTESTRING_H_ #include <functional> +#include <sstream> #include <utility> #include "core/fxcrt/cfx_retain_ptr.h" @@ -45,6 +46,7 @@ class CFX_ByteString { explicit CFX_ByteString(const CFX_ByteStringC& bstrc); CFX_ByteString(const CFX_ByteStringC& bstrc1, const CFX_ByteStringC& bstrc2); CFX_ByteString(const std::initializer_list<CFX_ByteStringC>& list); + explicit CFX_ByteString(std::ostringstream& outStream); ~CFX_ByteString(); @@ -231,6 +233,9 @@ inline CFX_ByteString operator+(const CFX_ByteStringC& str1, uint32_t FX_HashCode_GetA(const CFX_ByteStringC& str, bool bIgnoreCase); +std::ostream& operator<<(std::ostream& os, const CFX_ByteString& str); +std::ostream& operator<<(std::ostream& os, const CFX_ByteStringC& str); + namespace std { template <> diff --git a/chromium/third_party/pdfium/core/fxcrt/cfx_bytestring_unittest.cpp b/chromium/third_party/pdfium/core/fxcrt/cfx_bytestring_unittest.cpp index c53b90025b0..f5d9413b7dd 100644 --- a/chromium/third_party/pdfium/core/fxcrt/cfx_bytestring_unittest.cpp +++ b/chromium/third_party/pdfium/core/fxcrt/cfx_bytestring_unittest.cpp @@ -3,11 +3,11 @@ // found in the LICENSE file. #include "core/fxcrt/cfx_bytestring.h" +#include "core/fxcrt/fx_string.h" #include <algorithm> #include <vector> -#include "testing/fx_string_testhelpers.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/base/stl_util.h" @@ -1259,3 +1259,123 @@ TEST(fxcrt, EqualNoCase) { EXPECT_FALSE(str.EqualNoCase("a")); EXPECT_FALSE(str.EqualNoCase("")); } + +TEST(fxcrt, OStreamByteStringOverload) { + std::ostringstream stream; + + // Basic case, empty string + CFX_ByteString str; + stream << str; + EXPECT_EQ("", stream.str()); + + // Basic case, non-empty string + str = "def"; + stream.str(""); + stream << "abc" << str << "ghi"; + EXPECT_EQ("abcdefghi", stream.str()); + + // Changing the CFX_ByteString does not change the stream it was written to. + str = "123"; + EXPECT_EQ("abcdefghi", stream.str()); + + // Writing it again to the stream will use the latest value. + stream.str(""); + stream << "abc" << str << "ghi"; + EXPECT_EQ("abc123ghi", stream.str()); + + char stringWithNulls[]{'x', 'y', '\0', 'z'}; + + // Writing a CFX_ByteString with nulls and no specified length treats it as + // a C-style null-terminated string. + str = CFX_ByteString(stringWithNulls); + EXPECT_EQ(2, str.GetLength()); + stream.str(""); + stream << str; + EXPECT_EQ(2u, stream.tellp()); + + // Writing a CFX_ByteString with nulls but specifying its length treats it as + // a C++-style string. + str = CFX_ByteString(stringWithNulls, 4); + EXPECT_EQ(4, str.GetLength()); + stream.str(""); + stream << str; + EXPECT_EQ(4u, stream.tellp()); + + // << operators can be chained. + CFX_ByteString str1("abc"); + CFX_ByteString str2("def"); + stream.str(""); + stream << str1 << str2; + EXPECT_EQ("abcdef", stream.str()); +} + +TEST(fxcrt, OStreamByteStringCOverload) { + // Basic case, empty string + { + std::ostringstream stream; + CFX_ByteStringC str; + stream << str; + EXPECT_EQ("", stream.str()); + } + + // Basic case, non-empty string + { + std::ostringstream stream; + CFX_ByteStringC str("def"); + stream << "abc" << str << "ghi"; + EXPECT_EQ("abcdefghi", stream.str()); + } + + // Changing the CFX_ByteStringC does not change the stream it was written to. + { + std::ostringstream stream; + CFX_ByteStringC str("abc"); + stream << str; + str = "123"; + EXPECT_EQ("abc", stream.str()); + } + + // Writing it again to the stream will use the latest value. + { + std::ostringstream stream; + CFX_ByteStringC str("abc"); + stream << str; + stream.str(""); + str = "123"; + stream << str; + EXPECT_EQ("123", stream.str()); + } + + // Writing a CFX_ByteStringC with nulls and no specified length treats it as + // a C-style null-terminated string. + { + std::ostringstream stream; + char stringWithNulls[]{'x', 'y', '\0', 'z'}; + CFX_ByteStringC str(stringWithNulls); + EXPECT_EQ(2, str.GetLength()); + stream << str; + EXPECT_EQ(2u, stream.tellp()); + str = ""; + } + + // Writing a CFX_ByteStringC with nulls but specifying its length treats it as + // a C++-style string. + { + std::ostringstream stream; + char stringWithNulls[]{'x', 'y', '\0', 'z'}; + CFX_ByteStringC str(stringWithNulls, 4); + EXPECT_EQ(4, str.GetLength()); + stream << str; + EXPECT_EQ(4u, stream.tellp()); + str = ""; + } + + // << operators can be chained. + { + std::ostringstream stream; + CFX_ByteStringC str1("abc"); + CFX_ByteStringC str2("def"); + stream << str1 << str2; + EXPECT_EQ("abcdef", stream.str()); + } +} diff --git a/chromium/third_party/pdfium/core/fxcrt/cfx_datetime.cpp b/chromium/third_party/pdfium/core/fxcrt/cfx_datetime.cpp index dcf25d54638..833fe58907a 100644 --- a/chromium/third_party/pdfium/core/fxcrt/cfx_datetime.cpp +++ b/chromium/third_party/pdfium/core/fxcrt/cfx_datetime.cpp @@ -127,3 +127,9 @@ int32_t CFX_DateTime::GetDayOfWeek() const { v += 7; return v; } + +bool CFX_DateTime::operator==(const CFX_DateTime& other) const { + return year_ == other.year_ && month_ == other.month_ && day_ == other.day_ && + hour_ == other.hour_ && minute_ == other.minute_ && + second_ == other.second_ && millisecond_ == other.millisecond_; +} diff --git a/chromium/third_party/pdfium/core/fxcrt/cfx_datetime.h b/chromium/third_party/pdfium/core/fxcrt/cfx_datetime.h index 2de75c4e387..272c2496ccf 100644 --- a/chromium/third_party/pdfium/core/fxcrt/cfx_datetime.h +++ b/chromium/third_party/pdfium/core/fxcrt/cfx_datetime.h @@ -79,6 +79,8 @@ class CFX_DateTime { uint16_t GetMillisecond() const { return millisecond_; } int32_t GetDayOfWeek() const; + bool operator==(const CFX_DateTime& other) const; + private: int32_t year_; uint8_t month_; diff --git a/chromium/third_party/pdfium/core/fxcrt/cfx_decimal.cpp b/chromium/third_party/pdfium/core/fxcrt/cfx_decimal.cpp index a463305f6a7..b900e069a77 100644 --- a/chromium/third_party/pdfium/core/fxcrt/cfx_decimal.cpp +++ b/chromium/third_party/pdfium/core/fxcrt/cfx_decimal.cpp @@ -295,7 +295,7 @@ CFX_Decimal::CFX_Decimal(float val, uint8_t scale) { } CFX_Decimal::CFX_Decimal(const CFX_WideStringC& strObj) { - const wchar_t* str = strObj.c_str(); + const wchar_t* str = strObj.unterminated_c_str(); const wchar_t* strBound = str + strObj.GetLength(); bool pointmet = false; bool negmet = false; diff --git a/chromium/third_party/pdfium/core/fxcrt/cfx_maybe_owned_unittest.cpp b/chromium/third_party/pdfium/core/fxcrt/cfx_maybe_owned_unittest.cpp index 8f513a358d4..a716182ce51 100644 --- a/chromium/third_party/pdfium/core/fxcrt/cfx_maybe_owned_unittest.cpp +++ b/chromium/third_party/pdfium/core/fxcrt/cfx_maybe_owned_unittest.cpp @@ -8,7 +8,6 @@ #include <utility> #include "core/fxcrt/fx_memory.h" -#include "testing/fx_string_testhelpers.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/base/ptr_util.h" diff --git a/chromium/third_party/pdfium/core/fxcrt/cfx_observable_unittest.cpp b/chromium/third_party/pdfium/core/fxcrt/cfx_observable_unittest.cpp index 3c0fabb13e9..f7c78c1112d 100644 --- a/chromium/third_party/pdfium/core/fxcrt/cfx_observable_unittest.cpp +++ b/chromium/third_party/pdfium/core/fxcrt/cfx_observable_unittest.cpp @@ -7,7 +7,6 @@ #include <utility> #include <vector> -#include "testing/fx_string_testhelpers.h" #include "testing/gtest/include/gtest/gtest.h" namespace { diff --git a/chromium/third_party/pdfium/core/fxcrt/cfx_retain_ptr_unittest.cpp b/chromium/third_party/pdfium/core/fxcrt/cfx_retain_ptr_unittest.cpp index fc0309467c0..eae542fe888 100644 --- a/chromium/third_party/pdfium/core/fxcrt/cfx_retain_ptr_unittest.cpp +++ b/chromium/third_party/pdfium/core/fxcrt/cfx_retain_ptr_unittest.cpp @@ -7,7 +7,6 @@ #include <utility> #include <vector> -#include "testing/fx_string_testhelpers.h" #include "testing/gtest/include/gtest/gtest.h" namespace { diff --git a/chromium/third_party/pdfium/core/fxcrt/cfx_seekablestreamproxy.cpp b/chromium/third_party/pdfium/core/fxcrt/cfx_seekablestreamproxy.cpp index 37dbed1fcaf..8cf855217a7 100644 --- a/chromium/third_party/pdfium/core/fxcrt/cfx_seekablestreamproxy.cpp +++ b/chromium/third_party/pdfium/core/fxcrt/cfx_seekablestreamproxy.cpp @@ -294,7 +294,7 @@ void CFX_SeekableStreamProxy::WriteString(const CFX_WideStringC& str) { m_wCodePage != FX_CODEPAGE_UTF8) { return; } - if (!m_pStream->WriteBlock(str.c_str(), m_iPosition, + if (!m_pStream->WriteBlock(str.unterminated_c_str(), m_iPosition, str.GetLength() * sizeof(wchar_t))) { return; } diff --git a/chromium/third_party/pdfium/core/fxcrt/cfx_shared_copy_on_write_unittest.cpp b/chromium/third_party/pdfium/core/fxcrt/cfx_shared_copy_on_write_unittest.cpp index b0205d899bc..797837465b6 100644 --- a/chromium/third_party/pdfium/core/fxcrt/cfx_shared_copy_on_write_unittest.cpp +++ b/chromium/third_party/pdfium/core/fxcrt/cfx_shared_copy_on_write_unittest.cpp @@ -7,7 +7,6 @@ #include <map> #include <string> -#include "testing/fx_string_testhelpers.h" #include "testing/gtest/include/gtest/gtest.h" namespace { diff --git a/chromium/third_party/pdfium/core/fxcrt/cfx_string_c_template.h b/chromium/third_party/pdfium/core/fxcrt/cfx_string_c_template.h index 89d0727b0f5..cd3cd27e754 100644 --- a/chromium/third_party/pdfium/core/fxcrt/cfx_string_c_template.h +++ b/chromium/third_party/pdfium/core/fxcrt/cfx_string_c_template.h @@ -35,7 +35,7 @@ class CFX_StringCTemplate { CFX_StringCTemplate(const CharType* ptr, FX_STRSIZE len) : m_Ptr(reinterpret_cast<const UnsignedType*>(ptr)), - m_Length(len == -1 ? FXSYS_len(ptr) : len) {} + m_Length(len < 0 ? FXSYS_len(ptr) : len) {} template <typename U = UnsignedType> CFX_StringCTemplate( @@ -112,7 +112,7 @@ class CFX_StringCTemplate { } const UnsignedType* raw_str() const { return m_Ptr.Get(); } - const CharType* c_str() const { + const CharType* unterminated_c_str() const { return reinterpret_cast<const CharType*>(m_Ptr.Get()); } @@ -167,6 +167,13 @@ class CFX_StringCTemplate { return result < 0 || (result == 0 && m_Length < that.m_Length); } + bool operator>(const CFX_StringCTemplate& that) const { + int result = FXSYS_cmp(reinterpret_cast<const CharType*>(m_Ptr.Get()), + reinterpret_cast<const CharType*>(that.m_Ptr.Get()), + std::min(m_Length, that.m_Length)); + return result > 0 || (result == 0 && m_Length > that.m_Length); + } + protected: CFX_UnownedPtr<const UnsignedType> m_Ptr; FX_STRSIZE m_Length; diff --git a/chromium/third_party/pdfium/core/fxcrt/cfx_string_pool_template_unittest.cpp b/chromium/third_party/pdfium/core/fxcrt/cfx_string_pool_template_unittest.cpp index d0f5fbe96d1..a4e603c8fa8 100644 --- a/chromium/third_party/pdfium/core/fxcrt/cfx_string_pool_template_unittest.cpp +++ b/chromium/third_party/pdfium/core/fxcrt/cfx_string_pool_template_unittest.cpp @@ -4,7 +4,6 @@ #include "core/fxcrt/cfx_string_pool_template.h" #include "core/fxcrt/fx_string.h" -#include "testing/fx_string_testhelpers.h" #include "testing/gtest/include/gtest/gtest.h" TEST(fxcrt, ByteStringPool) { diff --git a/chromium/third_party/pdfium/core/fxcrt/cfx_unowned_ptr.h b/chromium/third_party/pdfium/core/fxcrt/cfx_unowned_ptr.h index da1875c7abc..5376781d6ae 100644 --- a/chromium/third_party/pdfium/core/fxcrt/cfx_unowned_ptr.h +++ b/chromium/third_party/pdfium/core/fxcrt/cfx_unowned_ptr.h @@ -10,6 +10,30 @@ #include <type_traits> #include <utility> +// CFX_UnownedPtr is a smart pointer class that behaves very much like a +// standard C-style pointer. The advantages of using it over raw +// pointers are: +// +// 1. It documents the nature of the pointer with no need to add a comment +// explaining that is it // Not owned. Additionally, an attempt to delete +// an unowned ptr will fail to compile rather than silently succeeding, +// since it is a class and not a raw pointer. +// +// 2. When built for a memory tool like ASAN, the class provides a destructor +// which checks that the object being pointed to is still alive. +// +// Hence, when using UnownedPtr, no dangling pointers are ever permitted, +// even if they are not de-referenced after becoming dangling. The style of +// programming required is that the lifetime an object containing an +// UnownedPtr must be strictly less than the object to which it points. +// +// The same checks are also performed at assignment time to prove that the +// old value was not a dangling pointer, either. +// +// The array indexing operation [] is not supported on an unowned ptr, +// because an unowned ptr expresses a one to one relationship with some +// other heap object. + template <class T> class CFX_UnownedPtr { public: @@ -23,16 +47,16 @@ class CFX_UnownedPtr { // NOLINTNEXTLINE(runtime/explicit) CFX_UnownedPtr(std::nullptr_t ptr) {} - ~CFX_UnownedPtr() { Probe(); } + ~CFX_UnownedPtr() { ProbeForLowSeverityLifetimeIssue(); } CFX_UnownedPtr& operator=(T* that) { - Probe(); + ProbeForLowSeverityLifetimeIssue(); m_pObj = that; return *this; } CFX_UnownedPtr& operator=(const CFX_UnownedPtr& that) { - Probe(); + ProbeForLowSeverityLifetimeIssue(); if (*this != that) m_pObj = that.Get(); return *this; @@ -59,7 +83,7 @@ class CFX_UnownedPtr { T* Get() const { return m_pObj; } T* Release() { - Probe(); + ProbeForLowSeverityLifetimeIssue(); T* pTemp = nullptr; std::swap(pTemp, m_pObj); return pTemp; @@ -70,7 +94,7 @@ class CFX_UnownedPtr { T* operator->() const { return m_pObj; } private: - inline void Probe() { + inline void ProbeForLowSeverityLifetimeIssue() { #if defined(MEMORY_TOOL_REPLACES_ALLOCATOR) if (m_pObj) reinterpret_cast<const volatile uint8_t*>(m_pObj)[0]; diff --git a/chromium/third_party/pdfium/core/fxcrt/cfx_unowned_ptr_unittest.cpp b/chromium/third_party/pdfium/core/fxcrt/cfx_unowned_ptr_unittest.cpp index 6218679fa27..46230e7ebd4 100644 --- a/chromium/third_party/pdfium/core/fxcrt/cfx_unowned_ptr_unittest.cpp +++ b/chromium/third_party/pdfium/core/fxcrt/cfx_unowned_ptr_unittest.cpp @@ -7,7 +7,6 @@ #include <utility> #include <vector> -#include "testing/fx_string_testhelpers.h" #include "testing/gtest/include/gtest/gtest.h" namespace { diff --git a/chromium/third_party/pdfium/core/fxcrt/cfx_weak_ptr_unittest.cpp b/chromium/third_party/pdfium/core/fxcrt/cfx_weak_ptr_unittest.cpp index 47f63c35b24..aafcf16b3d7 100644 --- a/chromium/third_party/pdfium/core/fxcrt/cfx_weak_ptr_unittest.cpp +++ b/chromium/third_party/pdfium/core/fxcrt/cfx_weak_ptr_unittest.cpp @@ -8,7 +8,6 @@ #include <utility> #include "core/fxcrt/fx_memory.h" -#include "testing/fx_string_testhelpers.h" #include "testing/gtest/include/gtest/gtest.h" namespace { diff --git a/chromium/third_party/pdfium/core/fxcrt/cfx_widestring.cpp b/chromium/third_party/pdfium/core/fxcrt/cfx_widestring.cpp index ef6aaad9312..6a4fbb98462 100644 --- a/chromium/third_party/pdfium/core/fxcrt/cfx_widestring.cpp +++ b/chromium/third_party/pdfium/core/fxcrt/cfx_widestring.cpp @@ -263,15 +263,15 @@ CFX_WideString GetWideString(uint16_t codepage, const CFX_ByteStringC& bstr) { ASSERT(IsValidCodePage(codepage)); int src_len = bstr.GetLength(); - int dest_len = - FXSYS_MultiByteToWideChar(codepage, 0, bstr.c_str(), src_len, nullptr, 0); + int dest_len = FXSYS_MultiByteToWideChar( + codepage, 0, bstr.unterminated_c_str(), src_len, nullptr, 0); if (!dest_len) return CFX_WideString(); CFX_WideString wstr; wchar_t* dest_buf = wstr.GetBuffer(dest_len); - FXSYS_MultiByteToWideChar(codepage, 0, bstr.c_str(), src_len, dest_buf, - dest_len); + FXSYS_MultiByteToWideChar(codepage, 0, bstr.unterminated_c_str(), src_len, + dest_buf, dest_len); wstr.ReleaseBuffer(dest_len); return wstr; } @@ -308,7 +308,8 @@ CFX_WideString::CFX_WideString(const wchar_t* ptr) CFX_WideString::CFX_WideString(const CFX_WideStringC& stringSrc) { if (!stringSrc.IsEmpty()) { - m_pData.Reset(StringData::Create(stringSrc.c_str(), stringSrc.GetLength())); + m_pData.Reset(StringData::Create(stringSrc.unterminated_c_str(), + stringSrc.GetLength())); } } @@ -322,8 +323,9 @@ CFX_WideString::CFX_WideString(const CFX_WideStringC& str1, return; m_pData.Reset(StringData::Create(nNewLen)); - m_pData->CopyContents(str1.c_str(), str1.GetLength()); - m_pData->CopyContentsAt(str1.GetLength(), str2.c_str(), str2.GetLength()); + m_pData->CopyContents(str1.unterminated_c_str(), str1.GetLength()); + m_pData->CopyContentsAt(str1.GetLength(), str2.unterminated_c_str(), + str2.GetLength()); } CFX_WideString::CFX_WideString( @@ -340,7 +342,8 @@ CFX_WideString::CFX_WideString( FX_STRSIZE nOffset = 0; for (const auto& item : list) { - m_pData->CopyContentsAt(nOffset, item.c_str(), item.GetLength()); + m_pData->CopyContentsAt(nOffset, item.unterminated_c_str(), + item.GetLength()); nOffset += item.GetLength(); } } @@ -361,7 +364,7 @@ const CFX_WideString& CFX_WideString::operator=( if (stringSrc.IsEmpty()) clear(); else - AssignCopy(stringSrc.c_str(), stringSrc.GetLength()); + AssignCopy(stringSrc.unterminated_c_str(), stringSrc.GetLength()); return *this; } @@ -395,7 +398,7 @@ const CFX_WideString& CFX_WideString::operator+=(const CFX_WideString& str) { const CFX_WideString& CFX_WideString::operator+=(const CFX_WideStringC& str) { if (!str.IsEmpty()) - Concat(str.c_str(), str.GetLength()); + Concat(str.unterminated_c_str(), str.GetLength()); return *this; } @@ -416,7 +419,8 @@ bool CFX_WideString::operator==(const CFX_WideStringC& str) const { return str.IsEmpty(); return m_pData->m_nDataLength == str.GetLength() && - wmemcmp(m_pData->m_String, str.c_str(), str.GetLength()) == 0; + wmemcmp(m_pData->m_String, str.unterminated_c_str(), + str.GetLength()) == 0; } bool CFX_WideString::operator==(const CFX_WideString& other) const { @@ -746,7 +750,7 @@ FX_STRSIZE CFX_WideString::Find(const CFX_WideStringC& pSub, const wchar_t* pStr = FX_wcsstr(m_pData->m_String + nStart, m_pData->m_nDataLength - nStart, - pSub.c_str(), pSub.GetLength()); + pSub.unterminated_c_str(), pSub.GetLength()); return pStr ? (int)(pStr - m_pData->m_String) : -1; } @@ -812,7 +816,7 @@ FX_STRSIZE CFX_WideString::Replace(const CFX_WideStringC& pOld, wchar_t* pEnd = m_pData->m_String + m_pData->m_nDataLength; while (1) { const wchar_t* pTarget = FX_wcsstr(pStart, (FX_STRSIZE)(pEnd - pStart), - pOld.c_str(), nSourceLen); + pOld.unterminated_c_str(), nSourceLen); if (!pTarget) break; @@ -835,10 +839,10 @@ FX_STRSIZE CFX_WideString::Replace(const CFX_WideStringC& pOld, wchar_t* pDest = pNewData->m_String; for (FX_STRSIZE i = 0; i < nCount; i++) { const wchar_t* pTarget = FX_wcsstr(pStart, (FX_STRSIZE)(pEnd - pStart), - pOld.c_str(), nSourceLen); + pOld.unterminated_c_str(), nSourceLen); wmemcpy(pDest, pStart, pTarget - pStart); pDest += pTarget - pStart; - wmemcpy(pDest, pNew.c_str(), pNew.GetLength()); + wmemcpy(pDest, pNew.unterminated_c_str(), pNew.GetLength()); pDest += pNew.GetLength(); pStart = pTarget + nSourceLen; } @@ -1049,3 +1053,21 @@ int CFX_WideString::GetInteger() const { float CFX_WideString::GetFloat() const { return m_pData ? FX_wtof(m_pData->m_String, m_pData->m_nDataLength) : 0.0f; } + +std::wostream& operator<<(std::wostream& os, const CFX_WideString& str) { + return os.write(str.c_str(), str.GetLength()); +} + +std::ostream& operator<<(std::ostream& os, const CFX_WideString& str) { + os << str.UTF8Encode(); + return os; +} + +std::wostream& operator<<(std::wostream& os, const CFX_WideStringC& str) { + return os.write(str.unterminated_c_str(), str.GetLength()); +} + +std::ostream& operator<<(std::ostream& os, const CFX_WideStringC& str) { + os << FX_UTF8Encode(str); + return os; +} diff --git a/chromium/third_party/pdfium/core/fxcrt/cfx_widestring.h b/chromium/third_party/pdfium/core/fxcrt/cfx_widestring.h index 977114816d2..0e477bfc8be 100644 --- a/chromium/third_party/pdfium/core/fxcrt/cfx_widestring.h +++ b/chromium/third_party/pdfium/core/fxcrt/cfx_widestring.h @@ -228,6 +228,11 @@ inline bool operator!=(const CFX_WideStringC& lhs, const CFX_WideString& rhs) { uint32_t FX_HashCode_GetW(const CFX_WideStringC& str, bool bIgnoreCase); +std::wostream& operator<<(std::wostream& os, const CFX_WideString& str); +std::ostream& operator<<(std::ostream& os, const CFX_WideString& str); +std::wostream& operator<<(std::wostream& os, const CFX_WideStringC& str); +std::ostream& operator<<(std::ostream& os, const CFX_WideStringC& str); + namespace std { template <> diff --git a/chromium/third_party/pdfium/core/fxcrt/cfx_widestring_unittest.cpp b/chromium/third_party/pdfium/core/fxcrt/cfx_widestring_unittest.cpp index f5a0e125607..4cd71d99977 100644 --- a/chromium/third_party/pdfium/core/fxcrt/cfx_widestring_unittest.cpp +++ b/chromium/third_party/pdfium/core/fxcrt/cfx_widestring_unittest.cpp @@ -3,11 +3,11 @@ // found in the LICENSE file. #include "core/fxcrt/cfx_widestring.h" +#include "core/fxcrt/fx_string.h" #include <algorithm> #include <vector> -#include "testing/fx_string_testhelpers.h" #include "testing/gtest/include/gtest/gtest.h" TEST(fxcrt, WideStringOperatorSubscript) { @@ -1102,3 +1102,267 @@ TEST(fxcrt, WideStringAnyAllNoneOf) { EXPECT_TRUE(pdfium::ContainsValue(str, L'b')); EXPECT_FALSE(pdfium::ContainsValue(str, L'z')); } + +TEST(fxcrt, OStreamWideStringOverload) { + std::ostringstream stream; + + // Basic case, empty string + CFX_WideString str; + stream << str; + EXPECT_EQ("", stream.str()); + + // Basic case, wide character + str = L"\u20AC"; + stream << str; + EXPECT_EQ("\u20AC", stream.str()); + + // Basic case, non-empty string + str = L"def"; + stream.str(""); + stream << "abc" << str << "ghi"; + EXPECT_EQ("abcdefghi", stream.str()); + + // Changing the CFX_WideString does not change the stream it was written to. + str = L"123"; + EXPECT_EQ("abcdefghi", stream.str()); + + // Writing it again to the stream will use the latest value. + stream.str(""); + stream << "abc" << str << "ghi"; + EXPECT_EQ("abc123ghi", stream.str()); + + wchar_t stringWithNulls[]{'x', 'y', '\0', 'z'}; + + // Writing a CFX_WideString with nulls and no specified length treats it as + // a C-style null-terminated string. + str = CFX_WideString(stringWithNulls); + EXPECT_EQ(2, str.GetLength()); + stream.str(""); + stream << str; + EXPECT_EQ(2u, stream.tellp()); + + // Writing a CFX_WideString with nulls but specifying its length treats it as + // a C++-style string. + str = CFX_WideString(stringWithNulls, 4); + EXPECT_EQ(4, str.GetLength()); + stream.str(""); + stream << str; + EXPECT_EQ(4u, stream.tellp()); + + // << operators can be chained. + CFX_WideString str1(L"abc"); + CFX_WideString str2(L"def"); + stream.str(""); + stream << str1 << str2; + EXPECT_EQ("abcdef", stream.str()); +} + +TEST(fxcrt, WideOStreamWideStringOverload) { + std::wostringstream stream; + + // Basic case, empty string + CFX_WideString str; + stream << str; + EXPECT_EQ(L"", stream.str()); + + // Basic case, wide character + str = L"\u20AC"; + stream << str; + EXPECT_EQ(L"\u20AC", stream.str()); + + // Basic case, non-empty string + str = L"def"; + stream.str(L""); + stream << L"abc" << str << L"ghi"; + EXPECT_EQ(L"abcdefghi", stream.str()); + + // Changing the CFX_WideString does not change the stream it was written to. + str = L"123"; + EXPECT_EQ(L"abcdefghi", stream.str()); + + // Writing it again to the stream will use the latest value. + stream.str(L""); + stream << L"abc" << str << L"ghi"; + EXPECT_EQ(L"abc123ghi", stream.str()); + + wchar_t stringWithNulls[]{'x', 'y', '\0', 'z'}; + + // Writing a CFX_WideString with nulls and no specified length treats it as + // a C-style null-terminated string. + str = CFX_WideString(stringWithNulls); + EXPECT_EQ(2, str.GetLength()); + stream.str(L""); + stream << str; + EXPECT_EQ(2u, stream.tellp()); + + // Writing a CFX_WideString with nulls but specifying its length treats it as + // a C++-style string. + str = CFX_WideString(stringWithNulls, 4); + EXPECT_EQ(4, str.GetLength()); + stream.str(L""); + stream << str; + EXPECT_EQ(4u, stream.tellp()); + + // << operators can be chained. + CFX_WideString str1(L"abc"); + CFX_WideString str2(L"def"); + stream.str(L""); + stream << str1 << str2; + EXPECT_EQ(L"abcdef", stream.str()); +} + +TEST(fxcrt, OStreamWideStringCOverload) { + // Basic case, empty string + { + std::ostringstream stream; + CFX_WideStringC str; + stream << str; + EXPECT_EQ("", stream.str()); + } + + // Basic case, non-empty string + { + std::ostringstream stream; + CFX_WideStringC str(L"def"); + stream << "abc" << str << "ghi"; + EXPECT_EQ("abcdefghi", stream.str()); + } + + // Basic case, wide character + { + std::ostringstream stream; + CFX_WideStringC str(L"\u20AC"); + stream << str; + EXPECT_EQ("\u20AC", stream.str()); + } + + // Changing the CFX_WideStringC does not change the stream it was written to. + { + std::ostringstream stream; + CFX_WideStringC str(L"abc"); + stream << str; + str = L"123"; + EXPECT_EQ("abc", stream.str()); + } + + // Writing it again to the stream will use the latest value. + { + std::ostringstream stream; + CFX_WideStringC str(L"abc"); + stream << str; + stream.str(""); + str = L"123"; + stream << str; + EXPECT_EQ("123", stream.str()); + } + + // Writing a CFX_WideStringC with nulls and no specified length treats it as + // a C-style null-terminated string. + { + wchar_t stringWithNulls[]{'x', 'y', '\0', 'z'}; + std::ostringstream stream; + CFX_WideStringC str(stringWithNulls); + EXPECT_EQ(2, str.GetLength()); + stream << str; + EXPECT_EQ(2u, stream.tellp()); + str = L""; + } + + // Writing a CFX_WideStringC with nulls but specifying its length treats it as + // a C++-style string. + { + wchar_t stringWithNulls[]{'x', 'y', '\0', 'z'}; + std::ostringstream stream; + CFX_WideStringC str(stringWithNulls, 4); + EXPECT_EQ(4, str.GetLength()); + stream << str; + EXPECT_EQ(4u, stream.tellp()); + str = L""; + } + + // << operators can be chained. + { + std::ostringstream stream; + CFX_WideStringC str1(L"abc"); + CFX_WideStringC str2(L"def"); + stream << str1 << str2; + EXPECT_EQ("abcdef", stream.str()); + } +} + +TEST(fxcrt, WideOStreamWideStringCOverload) { + // Basic case, empty string + { + std::wostringstream stream; + CFX_WideStringC str; + stream << str; + EXPECT_EQ(L"", stream.str()); + } + + // Basic case, non-empty string + { + std::wostringstream stream; + CFX_WideStringC str(L"def"); + stream << "abc" << str << "ghi"; + EXPECT_EQ(L"abcdefghi", stream.str()); + } + + // Basic case, wide character + { + std::wostringstream stream; + CFX_WideStringC str(L"\u20AC"); + stream << str; + EXPECT_EQ(L"\u20AC", stream.str()); + } + + // Changing the CFX_WideStringC does not change the stream it was written to. + { + std::wostringstream stream; + CFX_WideStringC str(L"abc"); + stream << str; + str = L"123"; + EXPECT_EQ(L"abc", stream.str()); + } + + // Writing it again to the stream will use the latest value. + { + std::wostringstream stream; + CFX_WideStringC str(L"abc"); + stream << str; + stream.str(L""); + str = L"123"; + stream << str; + EXPECT_EQ(L"123", stream.str()); + } + + // Writing a CFX_WideStringC with nulls and no specified length treats it as + // a C-style null-terminated string. + { + wchar_t stringWithNulls[]{'x', 'y', '\0', 'z'}; + std::wostringstream stream; + CFX_WideStringC str(stringWithNulls); + EXPECT_EQ(2, str.GetLength()); + stream << str; + EXPECT_EQ(2u, stream.tellp()); + } + + // Writing a CFX_WideStringC with nulls but specifying its length treats it as + // a C++-style string. + { + wchar_t stringWithNulls[]{'x', 'y', '\0', 'z'}; + std::wostringstream stream; + CFX_WideStringC str(stringWithNulls, 4); + EXPECT_EQ(4, str.GetLength()); + stream << str; + EXPECT_EQ(4u, stream.tellp()); + } + + // << operators can be chained. + { + std::wostringstream stream; + CFX_WideStringC str1(L"abc"); + CFX_WideStringC str2(L"def"); + stream << str1 << str2; + EXPECT_EQ(L"abcdef", stream.str()); + } +} diff --git a/chromium/third_party/pdfium/core/fxcrt/fx_basic_buffer.cpp b/chromium/third_party/pdfium/core/fxcrt/fx_basic_buffer.cpp index 36da3f40532..bcf0570d32b 100644 --- a/chromium/third_party/pdfium/core/fxcrt/fx_basic_buffer.cpp +++ b/chromium/third_party/pdfium/core/fxcrt/fx_basic_buffer.cpp @@ -133,7 +133,7 @@ void CFX_WideTextBuf::AppendChar(wchar_t ch) { } CFX_WideTextBuf& CFX_WideTextBuf::operator<<(const CFX_WideStringC& str) { - AppendBlock(str.c_str(), str.GetLength() * sizeof(wchar_t)); + AppendBlock(str.unterminated_c_str(), str.GetLength() * sizeof(wchar_t)); return *this; } diff --git a/chromium/third_party/pdfium/core/fxcrt/fx_basic_utf.cpp b/chromium/third_party/pdfium/core/fxcrt/fx_basic_utf.cpp index 10aa918962b..4dbfa372840 100644 --- a/chromium/third_party/pdfium/core/fxcrt/fx_basic_utf.cpp +++ b/chromium/third_party/pdfium/core/fxcrt/fx_basic_utf.cpp @@ -76,7 +76,7 @@ void CFX_UTF8Encoder::Input(wchar_t unicode) { CFX_ByteString FX_UTF8Encode(const CFX_WideStringC& wsStr) { FX_STRSIZE len = wsStr.GetLength(); - const wchar_t* pStr = wsStr.c_str(); + const wchar_t* pStr = wsStr.unterminated_c_str(); CFX_UTF8Encoder encoder; while (len-- > 0) encoder.Input(*pStr++); diff --git a/chromium/third_party/pdfium/core/fxcrt/fx_basic_util_unittest.cpp b/chromium/third_party/pdfium/core/fxcrt/fx_basic_util_unittest.cpp index 471c6deeb3f..f4e3f794d35 100644 --- a/chromium/third_party/pdfium/core/fxcrt/fx_basic_util_unittest.cpp +++ b/chromium/third_party/pdfium/core/fxcrt/fx_basic_util_unittest.cpp @@ -5,7 +5,6 @@ #include <limits> #include "core/fxcrt/fx_basic.h" -#include "testing/fx_string_testhelpers.h" #include "testing/gtest/include/gtest/gtest.h" namespace { diff --git a/chromium/third_party/pdfium/core/fxcrt/fx_coordinates.cpp b/chromium/third_party/pdfium/core/fxcrt/fx_coordinates.cpp index ca40a422278..752591d3ed2 100644 --- a/chromium/third_party/pdfium/core/fxcrt/fx_coordinates.cpp +++ b/chromium/third_party/pdfium/core/fxcrt/fx_coordinates.cpp @@ -7,6 +7,7 @@ #include "core/fxcrt/fx_coordinates.h" #include <algorithm> +#include <utility> #include "core/fxcrt/fx_extension.h" @@ -26,70 +27,60 @@ void MatchFloatRange(float f1, float f2, int* i1, int* i2) { } // namespace void FX_RECT::Normalize() { - if (left > right) { - int temp = left; - left = right; - right = temp; - } - if (top > bottom) { - int temp = top; - top = bottom; - bottom = temp; - } + if (left > right) + std::swap(left, right); + if (top > bottom) + std::swap(top, bottom); } void FX_RECT::Intersect(const FX_RECT& src) { FX_RECT src_n = src; src_n.Normalize(); Normalize(); - left = left > src_n.left ? left : src_n.left; - top = top > src_n.top ? top : src_n.top; - right = right < src_n.right ? right : src_n.right; - bottom = bottom < src_n.bottom ? bottom : src_n.bottom; + left = std::max(left, src_n.left); + top = std::max(top, src_n.top); + right = std::min(right, src_n.right); + bottom = std::min(bottom, src_n.bottom); if (left > right || top > bottom) { left = top = right = bottom = 0; } } CFX_FloatRect::CFX_FloatRect(const FX_RECT& rect) { - left = (float)(rect.left); - right = (float)(rect.right); - bottom = (float)(rect.top); - top = (float)(rect.bottom); + left = static_cast<float>(rect.left); + top = static_cast<float>(rect.bottom); + right = static_cast<float>(rect.right); + bottom = static_cast<float>(rect.top); } + void CFX_FloatRect::Normalize() { - float temp; - if (left > right) { - temp = left; - left = right; - right = temp; - } - if (bottom > top) { - temp = top; - top = bottom; - bottom = temp; - } + if (left > right) + std::swap(left, right); + if (bottom > top) + std::swap(top, bottom); } + void CFX_FloatRect::Intersect(const CFX_FloatRect& other_rect) { Normalize(); CFX_FloatRect other = other_rect; other.Normalize(); - left = left > other.left ? left : other.left; - right = right < other.right ? right : other.right; - bottom = bottom > other.bottom ? bottom : other.bottom; - top = top < other.top ? top : other.top; + left = std::max(left, other.left); + bottom = std::max(bottom, other.bottom); + right = std::min(right, other.right); + top = std::min(top, other.top); if (left > right || bottom > top) { - left = right = bottom = top = 0; + left = bottom = right = top = 0; } } + void CFX_FloatRect::Union(const CFX_FloatRect& other_rect) { Normalize(); CFX_FloatRect other = other_rect; other.Normalize(); - left = left < other.left ? left : other.left; - right = right > other.right ? right : other.right; - bottom = bottom < other.bottom ? bottom : other.bottom; - top = top > other.top ? top : other.top; + left = std::min(left, other.left); + bottom = std::min(bottom, other.bottom); + right = std::max(right, other.right); + top = std::max(top, other.top); } int CFX_FloatRect::Substract4(CFX_FloatRect& s, CFX_FloatRect* pRects) { @@ -99,35 +90,35 @@ int CFX_FloatRect::Substract4(CFX_FloatRect& s, CFX_FloatRect* pRects) { CFX_FloatRect rects[4]; if (left < s.left) { rects[nRects].left = left; - rects[nRects].right = s.left; rects[nRects].bottom = bottom; + rects[nRects].right = s.left; rects[nRects].top = top; nRects++; } if (s.left < right && s.top < top) { rects[nRects].left = s.left; - rects[nRects].right = right; rects[nRects].bottom = s.top; + rects[nRects].right = right; rects[nRects].top = top; nRects++; } if (s.top > bottom && s.right < right) { rects[nRects].left = s.right; - rects[nRects].right = right; rects[nRects].bottom = bottom; + rects[nRects].right = right; rects[nRects].top = s.top; nRects++; } if (s.bottom > bottom) { rects[nRects].left = s.left; - rects[nRects].right = s.right; rects[nRects].bottom = bottom; + rects[nRects].right = s.right; rects[nRects].top = s.bottom; nRects++; } - if (nRects == 0) { + if (nRects == 0) return 0; - } + for (int i = 0; i < nRects; i++) { pRects[i] = rects[i]; pRects[i].Intersect(*this); @@ -138,10 +129,10 @@ int CFX_FloatRect::Substract4(CFX_FloatRect& s, CFX_FloatRect* pRects) { FX_RECT CFX_FloatRect::GetOuterRect() const { CFX_FloatRect rect1 = *this; FX_RECT rect; - rect.left = (int)floor(rect1.left); - rect.right = (int)ceil(rect1.right); - rect.top = (int)floor(rect1.bottom); - rect.bottom = (int)ceil(rect1.top); + rect.left = static_cast<int>(floor(rect1.left)); + rect.bottom = static_cast<int>(ceil(rect1.top)); + rect.right = static_cast<int>(ceil(rect1.right)); + rect.top = static_cast<int>(floor(rect1.bottom)); rect.Normalize(); return rect; } @@ -149,10 +140,10 @@ FX_RECT CFX_FloatRect::GetOuterRect() const { FX_RECT CFX_FloatRect::GetInnerRect() const { CFX_FloatRect rect1 = *this; FX_RECT rect; - rect.left = (int)ceil(rect1.left); - rect.right = (int)floor(rect1.right); - rect.top = (int)ceil(rect1.bottom); - rect.bottom = (int)floor(rect1.top); + rect.left = static_cast<int>(ceil(rect1.left)); + rect.bottom = static_cast<int>(floor(rect1.top)); + rect.right = static_cast<int>(floor(rect1.right)); + rect.top = static_cast<int>(ceil(rect1.bottom)); rect.Normalize(); return rect; } @@ -166,6 +157,17 @@ FX_RECT CFX_FloatRect::GetClosestRect() const { return rect; } +CFX_FloatRect CFX_FloatRect::GetCenterSquare() const { + float fWidth = right - left; + float fHeight = top - bottom; + float fHalfWidth = (fWidth > fHeight) ? fHeight / 2 : fWidth / 2; + + float fCenterX = (left + right) / 2.0f; + float fCenterY = (top + bottom) / 2.0f; + return CFX_FloatRect(fCenterX - fHalfWidth, fCenterY - fHalfWidth, + fCenterX + fHalfWidth, fCenterY + fHalfWidth); +} + bool CFX_FloatRect::Contains(const CFX_PointF& point) const { CFX_FloatRect n1(*this); n1.Normalize(); @@ -184,8 +186,8 @@ bool CFX_FloatRect::Contains(const CFX_FloatRect& other_rect) const { void CFX_FloatRect::UpdateRect(float x, float y) { left = std::min(left, x); - right = std::max(right, x); bottom = std::min(bottom, y); + right = std::max(right, x); top = std::max(top, y); } @@ -206,18 +208,20 @@ CFX_FloatRect CFX_FloatRect::GetBBox(const CFX_PointF* pPoints, int nPoints) { return CFX_FloatRect(min_x, min_y, max_x, max_y); } -void CFX_Matrix::SetReverse(const CFX_Matrix& m) { - float i = m.a * m.d - m.b * m.c; +CFX_Matrix CFX_Matrix::GetInverse() const { + CFX_Matrix inverse; + float i = a * d - b * c; if (fabs(i) == 0) - return; + return inverse; float j = -i; - a = m.d / i; - b = m.b / j; - c = m.c / j; - d = m.a / i; - e = (m.c * m.f - m.d * m.e) / i; - f = (m.a * m.f - m.b * m.e) / j; + inverse.a = d / i; + inverse.b = b / j; + inverse.c = c / j; + inverse.d = a / i; + inverse.e = (c * f - d * e) / i; + inverse.f = (a * f - b * e) / j; + return inverse; } void CFX_Matrix::Concat(const CFX_Matrix& m, bool bPrepended) { @@ -225,9 +229,7 @@ void CFX_Matrix::Concat(const CFX_Matrix& m, bool bPrepended) { } void CFX_Matrix::ConcatInverse(const CFX_Matrix& src, bool bPrepended) { - CFX_Matrix m; - m.SetReverse(src); - Concat(m, bPrepended); + Concat(src.GetInverse(), bPrepended); } bool CFX_Matrix::Is90Rotated() const { diff --git a/chromium/third_party/pdfium/core/fxcrt/fx_coordinates.h b/chromium/third_party/pdfium/core/fxcrt/fx_coordinates.h index fc51c458a0c..bcbdc0b8042 100644 --- a/chromium/third_party/pdfium/core/fxcrt/fx_coordinates.h +++ b/chromium/third_party/pdfium/core/fxcrt/fx_coordinates.h @@ -482,6 +482,7 @@ class CFX_FloatRect { FX_RECT GetInnerRect() const; FX_RECT GetOuterRect() const; FX_RECT GetClosestRect() const; + CFX_FloatRect GetCenterSquare() const; int Substract4(CFX_FloatRect& substract_rect, CFX_FloatRect* pRects); @@ -542,6 +543,16 @@ class CFX_FloatRect { Deflate(rt.left, rt.bottom, rt.right, rt.top); } + CFX_FloatRect GetDeflated(float x, float y) const { + if (IsEmpty()) + return CFX_FloatRect(); + + CFX_FloatRect that = *this; + that.Deflate(x, y); + that.Normalize(); + return that; + } + void Translate(float e, float f) { left += e; right += e; @@ -549,6 +560,19 @@ class CFX_FloatRect { bottom += f; } + void Scale(float fScale) { + float fHalfWidth = (right - left) / 2.0f; + float fHalfHeight = (top - bottom) / 2.0f; + + float center_x = (left + right) / 2; + float center_y = (top + bottom) / 2; + + left = center_x - fHalfWidth * fScale; + bottom = center_y - fHalfHeight * fScale; + right = center_x + fHalfWidth * fScale; + top = center_y + fHalfHeight * fScale; + } + static CFX_FloatRect GetBBox(const CFX_PointF* pPoints, int nPoints); FX_RECT ToFxRect() const { @@ -608,7 +632,7 @@ class CFX_Matrix { f = 0; } - void SetReverse(const CFX_Matrix& m); + CFX_Matrix GetInverse() const; void Concat(const CFX_Matrix& m, bool bPrepended = false); void ConcatInverse(const CFX_Matrix& m, bool bPrepended = false); diff --git a/chromium/third_party/pdfium/core/fxcrt/fx_coordinates_unittest.cpp b/chromium/third_party/pdfium/core/fxcrt/fx_coordinates_unittest.cpp index 12ddb97330f..e998b440f5c 100644 --- a/chromium/third_party/pdfium/core/fxcrt/fx_coordinates_unittest.cpp +++ b/chromium/third_party/pdfium/core/fxcrt/fx_coordinates_unittest.cpp @@ -8,10 +8,9 @@ TEST(CFX_Matrix, ReverseIdentity) { CFX_Matrix m; - CFX_Matrix rev; - m.SetIdentity(); - rev.SetReverse(m); + CFX_Matrix rev = m.GetInverse(); + EXPECT_FLOAT_EQ(1.0, rev.a); EXPECT_FLOAT_EQ(0.0, rev.b); EXPECT_FLOAT_EQ(0.0, rev.c); @@ -28,9 +27,8 @@ TEST(CFX_Matrix, ReverseIdentity) { TEST(CFX_Matrix, Reverse) { float data[6] = {3, 0, 2, 3, 1, 4}; CFX_Matrix m(data); - CFX_Matrix rev; + CFX_Matrix rev = m.GetInverse(); - rev.SetReverse(m); EXPECT_FLOAT_EQ(0.33333334f, rev.a); EXPECT_FLOAT_EQ(0.0f, rev.b); EXPECT_FLOAT_EQ(-0.22222222f, rev.c); @@ -50,9 +48,8 @@ TEST(CFX_Matrix, ReverseCR702041) { float data[6] = {0.947368443f, -0.108947366f, -0.923076928f, 0.106153846f, 18.0f, 787.929993f}; CFX_Matrix m(data); - CFX_Matrix rev; + CFX_Matrix rev = m.GetInverse(); - rev.SetReverse(m); EXPECT_FLOAT_EQ(14247728.0f, rev.a); EXPECT_FLOAT_EQ(14622668.0f, rev.b); EXPECT_FLOAT_EQ(1.2389329e+08f, rev.c); @@ -71,9 +68,8 @@ TEST(CFX_Matrix, ReverseCR714187) { // The determinate is < std::numeric_limits<float>::epsilon() float data[6] = {0.000037f, 0.0f, 0.0f, -0.000037f, 182.413101f, 136.977646f}; CFX_Matrix m(data); - CFX_Matrix rev; + CFX_Matrix rev = m.GetInverse(); - rev.SetReverse(m); EXPECT_FLOAT_EQ(27027.025f, rev.a); EXPECT_FLOAT_EQ(0.0f, rev.b); EXPECT_FLOAT_EQ(0.0f, rev.c); diff --git a/chromium/third_party/pdfium/core/fxcrt/fx_memory.cpp b/chromium/third_party/pdfium/core/fxcrt/fx_memory.cpp index 2afcbceceef..6a592a12d28 100644 --- a/chromium/third_party/pdfium/core/fxcrt/fx_memory.cpp +++ b/chromium/third_party/pdfium/core/fxcrt/fx_memory.cpp @@ -5,10 +5,12 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com #include "core/fxcrt/fx_memory.h" +#include "core/fxcrt/fx_safe_types.h" #include <stdlib.h> // For abort(). pdfium::base::PartitionAllocatorGeneric gArrayBufferPartitionAllocator; +pdfium::base::PartitionAllocatorGeneric gGeneralPartitionAllocator; pdfium::base::PartitionAllocatorGeneric gStringPartitionAllocator; void FXMEM_InitializePartitionAlloc() { @@ -16,25 +18,32 @@ void FXMEM_InitializePartitionAlloc() { if (!s_gPartitionAllocatorsInitialized) { pdfium::base::PartitionAllocGlobalInit(FX_OutOfMemoryTerminate); gArrayBufferPartitionAllocator.init(); + gGeneralPartitionAllocator.init(); gStringPartitionAllocator.init(); s_gPartitionAllocatorsInitialized = true; } } +// TODO(palmer): Remove the |flags| argument. void* FXMEM_DefaultAlloc(size_t byte_size, int flags) { - return (void*)malloc(byte_size); + return pdfium::base::PartitionAllocGenericFlags( + gGeneralPartitionAllocator.root(), pdfium::base::PartitionAllocReturnNull, + byte_size, "GeneralPartition"); } void* FXMEM_DefaultCalloc(size_t num_elems, size_t byte_size) { - return calloc(num_elems, byte_size); + return FX_SafeAlloc(num_elems, byte_size); } +// TODO(palmer): Remove the |flags| argument. void* FXMEM_DefaultRealloc(void* pointer, size_t new_size, int flags) { - return realloc(pointer, new_size); + return pdfium::base::PartitionReallocGeneric( + gGeneralPartitionAllocator.root(), pointer, new_size, "GeneralPartition"); } +// TODO(palmer): Remove the |flags| argument. void FXMEM_DefaultFree(void* pointer, int flags) { - free(pointer); + pdfium::base::PartitionFree(pointer); } NEVER_INLINE void FX_OutOfMemoryTerminate() { diff --git a/chromium/third_party/pdfium/core/fxcrt/fx_memory.h b/chromium/third_party/pdfium/core/fxcrt/fx_memory.h index 9a7de4cc2b0..65cf19c9802 100644 --- a/chromium/third_party/pdfium/core/fxcrt/fx_memory.h +++ b/chromium/third_party/pdfium/core/fxcrt/fx_memory.h @@ -27,34 +27,54 @@ void FXMEM_DefaultFree(void* pointer, int flags); #include <memory> #include <new> +#include "core/fxcrt/fx_safe_types.h" #include "third_party/base/allocator/partition_allocator/partition_alloc.h" extern pdfium::base::PartitionAllocatorGeneric gArrayBufferPartitionAllocator; +extern pdfium::base::PartitionAllocatorGeneric gGeneralPartitionAllocator; extern pdfium::base::PartitionAllocatorGeneric gStringPartitionAllocator; void FXMEM_InitializePartitionAlloc(); NEVER_INLINE void FX_OutOfMemoryTerminate(); +inline void* FX_SafeAlloc(size_t num_members, size_t member_size) { + FX_SAFE_SIZE_T total = member_size; + total *= num_members; + if (!total.IsValid()) + return nullptr; + + void* result = pdfium::base::PartitionAllocGenericFlags( + gGeneralPartitionAllocator.root(), pdfium::base::PartitionAllocReturnNull, + total.ValueOrDie(), "GeneralPartition"); + if (result) + memset(result, 0, total.ValueOrDie()); + return result; +} + inline void* FX_SafeRealloc(void* ptr, size_t num_members, size_t member_size) { - if (num_members < std::numeric_limits<size_t>::max() / member_size) { - return realloc(ptr, num_members * member_size); - } - return nullptr; + FX_SAFE_SIZE_T size = num_members; + size *= member_size; + if (!size.IsValid()) + return nullptr; + + return pdfium::base::PartitionReallocGeneric( + gGeneralPartitionAllocator.root(), ptr, size.ValueOrDie(), + "GeneralPartition"); } inline void* FX_AllocOrDie(size_t num_members, size_t member_size) { // TODO(tsepez): See if we can avoid the implicit memset(0). - if (void* result = calloc(num_members, member_size)) { + if (void* result = FX_SafeAlloc(num_members, member_size)) return result; - } + FX_OutOfMemoryTerminate(); // Never returns. return nullptr; // Suppress compiler warning. } inline void* FX_AllocOrDie2D(size_t w, size_t h, size_t member_size) { - if (w < std::numeric_limits<size_t>::max() / h) { + if (w < std::numeric_limits<size_t>::max() / h) return FX_AllocOrDie(w * h, member_size); - } + FX_OutOfMemoryTerminate(); // Never returns. return nullptr; // Suppress compiler warning. } @@ -62,25 +82,39 @@ inline void* FX_AllocOrDie2D(size_t w, size_t h, size_t member_size) { inline void* FX_ReallocOrDie(void* ptr, size_t num_members, size_t member_size) { - if (void* result = FX_SafeRealloc(ptr, num_members, member_size)) { + if (void* result = FX_SafeRealloc(ptr, num_members, member_size)) return result; - } + FX_OutOfMemoryTerminate(); // Never returns. return nullptr; // Suppress compiler warning. } -// Never returns nullptr. -#define FX_Alloc(type, size) (type*)FX_AllocOrDie(size, sizeof(type)) -#define FX_Alloc2D(type, w, h) (type*)FX_AllocOrDie2D(w, h, sizeof(type)) +// These never return nullptr. +#define FX_Alloc(type, size) \ + static_cast<type*>(FX_AllocOrDie(size, sizeof(type))) +#define FX_Alloc2D(type, w, h) \ + static_cast<type*>(FX_AllocOrDie2D(w, h, sizeof(type))) #define FX_Realloc(type, ptr, size) \ - (type*)FX_ReallocOrDie(ptr, size, sizeof(type)) + static_cast<type*>(FX_ReallocOrDie(ptr, size, sizeof(type))) // May return nullptr. -#define FX_TryAlloc(type, size) (type*)calloc(size, sizeof(type)) +#define FX_TryAlloc(type, size) \ + static_cast<type*>(FX_SafeAlloc(size, sizeof(type))) #define FX_TryRealloc(type, ptr, size) \ - (type*)FX_SafeRealloc(ptr, size, sizeof(type)) - -#define FX_Free(ptr) free(ptr) + static_cast<type*>(FX_SafeRealloc(ptr, size, sizeof(type))) + +inline void FX_Free(void* ptr) { + // TODO(palmer): Removing this check exposes crashes when PDFium callers + // attempt to free |nullptr|. Although libc's |free| allows freeing |NULL|, no + // other Partition Alloc callers need this tolerant behavior. Additionally, + // checking for |nullptr| adds a branch to |PartitionFree|, and it's nice to + // not have to have that. + // + // So this check is hiding (what I consider to be) bugs, and we should try to + // fix them. https://bugs.chromium.org/p/pdfium/issues/detail?id=690 + if (ptr) + pdfium::base::PartitionFree(ptr); +} // The FX_ArraySize(arr) macro returns the # of elements in an array arr. // The expression is a compile-time constant, and therefore can be diff --git a/chromium/third_party/pdfium/core/fxcrt/fx_stream.cpp b/chromium/third_party/pdfium/core/fxcrt/fx_stream.cpp index ba214610980..a64b239546e 100644 --- a/chromium/third_party/pdfium/core/fxcrt/fx_stream.cpp +++ b/chromium/third_party/pdfium/core/fxcrt/fx_stream.cpp @@ -95,5 +95,5 @@ bool IFX_SeekableStream::WriteBlock(const void* buffer, size_t size) { } bool IFX_SeekableStream::WriteString(const CFX_ByteStringC& str) { - return WriteBlock(str.c_str(), str.GetLength()); + return WriteBlock(str.unterminated_c_str(), str.GetLength()); } diff --git a/chromium/third_party/pdfium/core/fxcrt/fx_system.cpp b/chromium/third_party/pdfium/core/fxcrt/fx_system.cpp index cf1c7e5920f..83f761ff85f 100644 --- a/chromium/third_party/pdfium/core/fxcrt/fx_system.cpp +++ b/chromium/third_party/pdfium/core/fxcrt/fx_system.cpp @@ -24,11 +24,12 @@ size_t FXSYS_wcsftime(wchar_t* strDest, const struct tm* timeptr) { // Avoid tripping an invalid parameter handler and crashing process. // Note: leap seconds may cause tm_sec == 60. - if (timeptr->tm_year < 0 || timeptr->tm_mon < 0 || timeptr->tm_mon > 11 || - timeptr->tm_mday < 1 || timeptr->tm_mday > 31 || timeptr->tm_hour < 0 || - timeptr->tm_hour > 23 || timeptr->tm_min < 0 || timeptr->tm_min > 59 || - timeptr->tm_sec < 0 || timeptr->tm_sec > 60 || timeptr->tm_wday < 0 || - timeptr->tm_wday > 6 || timeptr->tm_yday < 0 || timeptr->tm_yday > 365) { + if (timeptr->tm_year < -1900 || timeptr->tm_year > 8099 || + timeptr->tm_mon < 0 || timeptr->tm_mon > 11 || timeptr->tm_mday < 1 || + timeptr->tm_mday > 31 || timeptr->tm_hour < 0 || timeptr->tm_hour > 23 || + timeptr->tm_min < 0 || timeptr->tm_min > 59 || timeptr->tm_sec < 0 || + timeptr->tm_sec > 60 || timeptr->tm_wday < 0 || timeptr->tm_wday > 6 || + timeptr->tm_yday < 0 || timeptr->tm_yday > 365) { strDest[0] = L'\0'; return 0; } diff --git a/chromium/third_party/pdfium/core/fxcrt/fx_system_unittest.cpp b/chromium/third_party/pdfium/core/fxcrt/fx_system_unittest.cpp index 5a7660d2565..958d295a247 100644 --- a/chromium/third_party/pdfium/core/fxcrt/fx_system_unittest.cpp +++ b/chromium/third_party/pdfium/core/fxcrt/fx_system_unittest.cpp @@ -3,10 +3,9 @@ // found in the LICENSE file. #include <limits> -#include <string> +#include "core/fxcrt/fx_string.h" #include "core/fxcrt/fx_system.h" -#include "testing/fx_string_testhelpers.h" #include "testing/gtest/include/gtest/gtest.h" // Unit test covering cases where PDFium replaces well-known library @@ -23,7 +22,7 @@ void Check32BitBase16Itoa(int32_t input, const char* expected_output) { char buf[kBufLen]; buf[kBufLen - 1] = kSentinel; FXSYS_itoa(input, buf, 16); - EXPECT_EQ(std::string(expected_output), buf); + EXPECT_STREQ(expected_output, buf); EXPECT_EQ(kSentinel, buf[kBufLen - 1]); } @@ -32,7 +31,7 @@ void Check32BitBase10Itoa(int32_t input, const char* expected_output) { char buf[kBufLen]; buf[kBufLen - 1] = kSentinel; FXSYS_itoa(input, buf, 10); - EXPECT_EQ(std::string(expected_output), buf); + EXPECT_STREQ(expected_output, buf); EXPECT_EQ(kSentinel, buf[kBufLen - 1]); } @@ -41,7 +40,7 @@ void Check32BitBase2Itoa(int32_t input, const char* expected_output) { char buf[kBufLen]; buf[kBufLen - 1] = kSentinel; FXSYS_itoa(input, buf, 2); - EXPECT_EQ(std::string(expected_output), buf); + EXPECT_STREQ(expected_output, buf); EXPECT_EQ(kSentinel, buf[kBufLen - 1]); } @@ -50,7 +49,7 @@ void Check64BitBase16Itoa(int64_t input, const char* expected_output) { char buf[kBufLen]; buf[kBufLen - 1] = kSentinel; FXSYS_i64toa(input, buf, 16); - EXPECT_EQ(std::string(expected_output), buf); + EXPECT_STREQ(expected_output, buf); EXPECT_EQ(kSentinel, buf[kBufLen - 1]); } @@ -59,7 +58,7 @@ void Check64BitBase10Itoa(int64_t input, const char* expected_output) { char buf[kBufLen]; buf[kBufLen - 1] = kSentinel; FXSYS_i64toa(input, buf, 10); - EXPECT_EQ(std::string(expected_output), buf); + EXPECT_STREQ(expected_output, buf); EXPECT_EQ(kSentinel, buf[kBufLen - 1]); } @@ -68,7 +67,7 @@ void Check64BitBase2Itoa(int64_t input, const char* expected_output) { char buf[kBufLen]; buf[kBufLen - 1] = kSentinel; FXSYS_i64toa(input, buf, 2); - EXPECT_EQ(std::string(expected_output), buf); + EXPECT_STREQ(expected_output, buf); EXPECT_EQ(kSentinel, buf[kBufLen - 1]); } @@ -78,16 +77,16 @@ TEST(fxcrt, FXSYS_itoa_InvalidRadix) { char buf[32]; FXSYS_itoa(42, buf, 17); // Ours stops at 16. - EXPECT_EQ(std::string(""), buf); + EXPECT_STREQ("", buf); FXSYS_itoa(42, buf, 1); - EXPECT_EQ(std::string(""), buf); + EXPECT_STREQ("", buf); FXSYS_itoa(42, buf, 0); - EXPECT_EQ(std::string(""), buf); + EXPECT_STREQ("", buf); FXSYS_itoa(42, buf, -1); - EXPECT_EQ(std::string(""), buf); + EXPECT_STREQ("", buf); } TEST(fxcrt, FXSYS_itoa) { @@ -118,16 +117,16 @@ TEST(fxcrt, FXSYS_i64toa_InvalidRadix) { char buf[32]; FXSYS_i64toa(42, buf, 17); // Ours stops at 16. - EXPECT_EQ(std::string(""), buf); + EXPECT_STREQ("", buf); FXSYS_i64toa(42, buf, 1); - EXPECT_EQ(std::string(""), buf); + EXPECT_STREQ("", buf); FXSYS_i64toa(42, buf, 0); - EXPECT_EQ(std::string(""), buf); + EXPECT_STREQ("", buf); FXSYS_i64toa(42, buf, -1); - EXPECT_EQ(std::string(""), buf); + EXPECT_STREQ("", buf); } TEST(fxcrt, FXSYS_i64toa) { @@ -173,7 +172,22 @@ TEST(fxcrt, FXSYS_wcsftime) { wchar_t buf[100] = {}; EXPECT_EQ(19u, FXSYS_wcsftime(buf, FX_ArraySize(buf), L"%Y-%m-%dT%H:%M:%S", &good_time)); - EXPECT_EQ(std::wstring(L"1974-08-09T11:59:59"), buf); + EXPECT_STREQ(L"1974-08-09T11:59:59", buf); + + // Ensure wcsftime handles a wide range of years without crashing. + struct tm year_time = {}; + year_time.tm_mon = 7; // 0-based. + year_time.tm_mday = 9; // 1-based. + year_time.tm_hour = 11; + year_time.tm_min = 59; + year_time.tm_sec = 59; + + for (int year = -2500; year <= 8500; ++year) { + year_time.tm_year = year; + wchar_t year_buf[100] = {}; + FXSYS_wcsftime(year_buf, FX_ArraySize(year_buf), L"%Y-%m-%dT%H:%M:%S", + &year_time); + } // Ensure wcsftime handles bad years, etc. without crashing. struct tm bad_time = {}; diff --git a/chromium/third_party/pdfium/core/fxcrt/fxcrt_posix.cpp b/chromium/third_party/pdfium/core/fxcrt/fxcrt_posix.cpp index ca4ac161a4d..4d867dd6888 100644 --- a/chromium/third_party/pdfium/core/fxcrt/fxcrt_posix.cpp +++ b/chromium/third_party/pdfium/core/fxcrt/fxcrt_posix.cpp @@ -56,7 +56,9 @@ bool CFXCRT_FileAccess_Posix::Open(const CFX_ByteStringC& fileName, int32_t nFlags; int32_t nMasks; FXCRT_Posix_GetFileMode(dwMode, nFlags, nMasks); - m_nFD = open(fileName.c_str(), nFlags, nMasks); + + // TODO(tsepez): check usage of c_str() below. + m_nFD = open(fileName.unterminated_c_str(), nFlags, nMasks); return m_nFD > -1; } diff --git a/chromium/third_party/pdfium/core/fxcrt/fxcrt_windows.cpp b/chromium/third_party/pdfium/core/fxcrt/fxcrt_windows.cpp index 6230c74eb7b..1a2a36735eb 100644 --- a/chromium/third_party/pdfium/core/fxcrt/fxcrt_windows.cpp +++ b/chromium/third_party/pdfium/core/fxcrt/fxcrt_windows.cpp @@ -57,8 +57,8 @@ bool CFXCRT_FileAccess_Win64::Open(const CFX_ByteStringC& fileName, uint32_t dwAccess, dwShare, dwCreation; FXCRT_Windows_GetFileMode(dwMode, dwAccess, dwShare, dwCreation); - m_hFile = ::CreateFileA(fileName.c_str(), dwAccess, dwShare, nullptr, - dwCreation, FILE_ATTRIBUTE_NORMAL, nullptr); + m_hFile = ::CreateFileA(fileName.unterminated_c_str(), dwAccess, dwShare, + nullptr, dwCreation, FILE_ATTRIBUTE_NORMAL, nullptr); if (m_hFile == INVALID_HANDLE_VALUE) m_hFile = nullptr; @@ -72,8 +72,9 @@ bool CFXCRT_FileAccess_Win64::Open(const CFX_WideStringC& fileName, uint32_t dwAccess, dwShare, dwCreation; FXCRT_Windows_GetFileMode(dwMode, dwAccess, dwShare, dwCreation); - m_hFile = ::CreateFileW((LPCWSTR)fileName.c_str(), dwAccess, dwShare, nullptr, - dwCreation, FILE_ATTRIBUTE_NORMAL, nullptr); + m_hFile = + ::CreateFileW((LPCWSTR)fileName.unterminated_c_str(), dwAccess, dwShare, + nullptr, dwCreation, FILE_ATTRIBUTE_NORMAL, nullptr); if (m_hFile == INVALID_HANDLE_VALUE) m_hFile = nullptr; diff --git a/chromium/third_party/pdfium/core/fxcrt/xml/cfx_saxcontext.cpp b/chromium/third_party/pdfium/core/fxcrt/xml/cfx_saxcontext.cpp new file mode 100644 index 00000000000..4e2f0c58c92 --- /dev/null +++ b/chromium/third_party/pdfium/core/fxcrt/xml/cfx_saxcontext.cpp @@ -0,0 +1,9 @@ +// Copyright 2017 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. + +#include "core/fxcrt/xml/cfx_saxcontext.h" + +CFX_SAXContext::CFX_SAXContext() : m_eNode(CFX_SAXItem::Type::Unknown) {} + +CFX_SAXContext::~CFX_SAXContext() {} diff --git a/chromium/third_party/pdfium/core/fxcrt/xml/cfx_saxcontext.h b/chromium/third_party/pdfium/core/fxcrt/xml/cfx_saxcontext.h index 7afebed98d5..fcc889f7a38 100644 --- a/chromium/third_party/pdfium/core/fxcrt/xml/cfx_saxcontext.h +++ b/chromium/third_party/pdfium/core/fxcrt/xml/cfx_saxcontext.h @@ -7,15 +7,18 @@ #ifndef CORE_FXCRT_XML_CFX_SAXCONTEXT_H_ #define CORE_FXCRT_XML_CFX_SAXCONTEXT_H_ +#include <sstream> + #include "core/fxcrt/fx_basic.h" #include "core/fxcrt/fx_string.h" #include "core/fxcrt/xml/cfx_saxreader.h" class CFX_SAXContext { public: - CFX_SAXContext() : m_eNode(CFX_SAXItem::Type::Unknown) {} + CFX_SAXContext(); + ~CFX_SAXContext(); - CFX_ByteTextBuf m_TextBuf; + std::ostringstream m_TextBuf; CFX_ByteString m_bsTagName; CFX_SAXItem::Type m_eNode; }; diff --git a/chromium/third_party/pdfium/core/fxcrt/xml/cfx_saxreaderhandler.cpp b/chromium/third_party/pdfium/core/fxcrt/xml/cfx_saxreaderhandler.cpp index e7b6cd186c4..b8399ff5cce 100644 --- a/chromium/third_party/pdfium/core/fxcrt/xml/cfx_saxreaderhandler.cpp +++ b/chromium/third_party/pdfium/core/fxcrt/xml/cfx_saxreaderhandler.cpp @@ -6,6 +6,8 @@ #include "core/fxcrt/xml/cfx_saxreaderhandler.h" +#include <string> + #include "core/fxcrt/cfx_checksumcontext.h" CFX_SAXReaderHandler::CFX_SAXReaderHandler(CFX_ChecksumContext* pContext) @@ -26,12 +28,11 @@ CFX_SAXContext* CFX_SAXReaderHandler::OnTagEnter( } m_SAXContext.m_eNode = eType; - CFX_ByteTextBuf& textBuf = m_SAXContext.m_TextBuf; - textBuf << "<"; + m_SAXContext.m_TextBuf << "<"; if (eType == CFX_SAXItem::Type::Instruction) - textBuf << "?"; + m_SAXContext.m_TextBuf << "?"; - textBuf << bsTagName; + m_SAXContext.m_TextBuf << bsTagName; m_SAXContext.m_bsTagName = bsTagName; return &m_SAXContext; } @@ -59,24 +60,22 @@ void CFX_SAXReaderHandler::OnTagData(CFX_SAXContext* pTag, if (!pTag) return; - CFX_ByteTextBuf& textBuf = pTag->m_TextBuf; if (eType == CFX_SAXItem::Type::CharData) - textBuf << "<![CDATA["; + pTag->m_TextBuf << "<![CDATA["; - textBuf << bsData; + pTag->m_TextBuf << bsData; if (eType == CFX_SAXItem::Type::CharData) - textBuf << "]]>"; + pTag->m_TextBuf << "]]>"; } void CFX_SAXReaderHandler::OnTagClose(CFX_SAXContext* pTag, uint32_t dwEndPos) { if (!pTag) return; - CFX_ByteTextBuf& textBuf = pTag->m_TextBuf; if (pTag->m_eNode == CFX_SAXItem::Type::Instruction) - textBuf << "?>"; + pTag->m_TextBuf << "?>"; else if (pTag->m_eNode == CFX_SAXItem::Type::Tag) - textBuf << "></" << pTag->m_bsTagName.AsStringC() << ">"; + pTag->m_TextBuf << "></" << pTag->m_bsTagName.AsStringC() << ">"; UpdateChecksum(false); } @@ -107,11 +106,12 @@ void CFX_SAXReaderHandler::OnTargetData(CFX_SAXContext* pTag, } void CFX_SAXReaderHandler::UpdateChecksum(bool bCheckSpace) { - int32_t iLength = m_SAXContext.m_TextBuf.GetLength(); + int32_t iLength = m_SAXContext.m_TextBuf.tellp(); if (iLength < 1) return; - uint8_t* pBuffer = m_SAXContext.m_TextBuf.GetBuffer(); + std::string sBuffer = m_SAXContext.m_TextBuf.str(); + const uint8_t* pBuffer = reinterpret_cast<const uint8_t*>(sBuffer.c_str()); bool bUpdata = true; if (bCheckSpace) { bUpdata = false; @@ -124,5 +124,5 @@ void CFX_SAXReaderHandler::UpdateChecksum(bool bCheckSpace) { if (bUpdata) m_pContext->Update(CFX_ByteStringC(pBuffer, iLength)); - m_SAXContext.m_TextBuf.Clear(); + m_SAXContext.m_TextBuf.str(""); } diff --git a/chromium/third_party/pdfium/core/fxcrt/xml/cxml_parser.cpp b/chromium/third_party/pdfium/core/fxcrt/xml/cxml_parser.cpp index d43fbd65814..a741d8409e8 100644 --- a/chromium/third_party/pdfium/core/fxcrt/xml/cxml_parser.cpp +++ b/chromium/third_party/pdfium/core/fxcrt/xml/cxml_parser.cpp @@ -6,6 +6,8 @@ #include <algorithm> #include <memory> +#include <sstream> +#include <string> #include <utility> #include <vector> @@ -140,16 +142,15 @@ void CXML_Parser::GetName(CFX_ByteString* space, CFX_ByteString* name) { if (IsEOF()) return; - CFX_ByteTextBuf buf; - uint8_t ch; + std::ostringstream buf; do { while (m_dwIndex < m_dwBufferSize) { - ch = m_pBuffer[m_dwIndex]; + uint8_t ch = m_pBuffer[m_dwIndex]; if (ch == ':') { - *space = buf.AsStringC(); - buf.Clear(); + *space = CFX_ByteString(buf); + buf.str(""); } else if (g_FXCRT_XML_IsNameChar(ch)) { - buf.AppendChar(ch); + buf << static_cast<char>(ch); } else { break; } @@ -159,7 +160,7 @@ void CXML_Parser::GetName(CFX_ByteString* space, CFX_ByteString* name) { if (m_dwIndex < m_dwBufferSize || IsEOF()) break; } while (ReadNextBlock()); - *name = buf.AsStringC(); + *name = CFX_ByteString(buf); } void CXML_Parser::SkipLiterals(const CFX_ByteStringC& str) { @@ -199,7 +200,7 @@ uint32_t CXML_Parser::GetCharRef() { uint8_t ch; int32_t iState = 0; - CFX_ByteTextBuf buf; + std::ostringstream buf; uint32_t code = 0; do { while (m_dwIndex < m_dwBufferSize) { @@ -215,7 +216,7 @@ uint32_t CXML_Parser::GetCharRef() { case 1: m_dwIndex++; if (ch == ';') { - CFX_ByteStringC ref = buf.AsStringC(); + std::string ref = buf.str(); if (ref == "gt") code = '>'; else if (ref == "lt") @@ -229,7 +230,7 @@ uint32_t CXML_Parser::GetCharRef() { iState = 10; break; } - buf.AppendByte(ch); + buf << static_cast<char>(ch); break; case 2: if (ch == 'x') { diff --git a/chromium/third_party/pdfium/core/fxge/ge/DEPS b/chromium/third_party/pdfium/core/fxge/DEPS index 6492756b7ef..6492756b7ef 100644 --- a/chromium/third_party/pdfium/core/fxge/ge/DEPS +++ b/chromium/third_party/pdfium/core/fxge/DEPS diff --git a/chromium/third_party/pdfium/core/fxge/agg/fx_agg_driver.cpp b/chromium/third_party/pdfium/core/fxge/agg/fx_agg_driver.cpp index 6174f6e18f4..846920240e3 100644 --- a/chromium/third_party/pdfium/core/fxge/agg/fx_agg_driver.cpp +++ b/chromium/third_party/pdfium/core/fxge/agg/fx_agg_driver.cpp @@ -10,12 +10,12 @@ #include <utility> #include "core/fxcodec/fx_codec.h" +#include "core/fxge/cfx_cliprgn.h" #include "core/fxge/cfx_defaultrenderdevice.h" #include "core/fxge/cfx_graphstatedata.h" #include "core/fxge/cfx_pathdata.h" #include "core/fxge/dib/cfx_imagerenderer.h" #include "core/fxge/dib/cfx_imagestretcher.h" -#include "core/fxge/ge/cfx_cliprgn.h" #include "third_party/agg23/agg_conv_dash.h" #include "third_party/agg23/agg_conv_stroke.h" #include "third_party/agg23/agg_curves.h" @@ -438,7 +438,7 @@ class CFX_Renderer { CFX_RetainPtr<CFX_DIBitmap> m_pOriDevice; CFX_RetainPtr<CFX_DIBitmap> m_pClipMask; CFX_RetainPtr<CFX_DIBitmap> m_pDevice; - const CFX_ClipRgn* m_pClipRgn; + CFX_UnownedPtr<const CFX_ClipRgn> m_pClipRgn; }; void CFX_Renderer::CompositeSpan(uint8_t* dest_scan, @@ -1349,10 +1349,8 @@ bool CFX_AggDeviceDriver::DrawPath(const CFX_PathData* pPathData, pObject2Device->a / matrix1.a, pObject2Device->b / matrix1.a, pObject2Device->c / matrix1.d, pObject2Device->d / matrix1.d, 0, 0); - CFX_Matrix mtRervese; - mtRervese.SetReverse(matrix2); matrix1 = *pObject2Device; - matrix1.Concat(mtRervese); + matrix1.Concat(matrix2.GetInverse()); } CAgg_PathData path_data; @@ -1548,9 +1546,9 @@ bool CFX_AggDeviceDriver::StartDIBits( if (!m_pBitmap->GetBuffer()) return true; - *handle = pdfium::MakeUnique<CFX_ImageRenderer>(); - (*handle)->Start(m_pBitmap, m_pClipRgn.get(), pSource, bitmap_alpha, argb, - pMatrix, render_flags, m_bRgbByteOrder); + *handle = pdfium::MakeUnique<CFX_ImageRenderer>( + m_pBitmap, m_pClipRgn.get(), pSource, bitmap_alpha, argb, pMatrix, + render_flags, m_bRgbByteOrder); return true; } diff --git a/chromium/third_party/pdfium/core/fxge/android/cfpf_skiafont.h b/chromium/third_party/pdfium/core/fxge/android/cfpf_skiafont.h index 657ced88f25..5686e9e31fc 100644 --- a/chromium/third_party/pdfium/core/fxge/android/cfpf_skiafont.h +++ b/chromium/third_party/pdfium/core/fxge/android/cfpf_skiafont.h @@ -7,6 +7,7 @@ #ifndef CORE_FXGE_ANDROID_CFPF_SKIAFONT_H_ #define CORE_FXGE_ANDROID_CFPF_SKIAFONT_H_ +#include "core/fxcrt/cfx_unowned_ptr.h" #include "core/fxcrt/fx_system.h" #include "core/fxge/fx_font.h" @@ -42,8 +43,8 @@ class CFPF_SkiaFont { uint8_t uCharset); private: - CFPF_SkiaFontMgr* m_pFontMgr; - CFPF_SkiaFontDescriptor* m_pFontDes; + CFX_UnownedPtr<CFPF_SkiaFontMgr> m_pFontMgr; + CFX_UnownedPtr<CFPF_SkiaFontDescriptor> m_pFontDes; FXFT_Face m_Face; uint32_t m_dwStyle; uint8_t m_uCharset; diff --git a/chromium/third_party/pdfium/core/fxge/android/cfpf_skiafontmgr.cpp b/chromium/third_party/pdfium/core/fxge/android/cfpf_skiafontmgr.cpp index ec5c610150a..23fcd5bbec6 100644 --- a/chromium/third_party/pdfium/core/fxge/android/cfpf_skiafontmgr.cpp +++ b/chromium/third_party/pdfium/core/fxge/android/cfpf_skiafontmgr.cpp @@ -161,7 +161,7 @@ uint32_t FPF_SkiaGetCharset(uint8_t uCharset) { uint32_t FPF_SKIANormalizeFontName(const CFX_ByteStringC& bsfamily) { uint32_t dwHash = 0; int32_t iLength = bsfamily.GetLength(); - const char* pBuffer = bsfamily.c_str(); + const char* pBuffer = bsfamily.unterminated_c_str(); for (int32_t i = 0; i < iLength; i++) { char ch = pBuffer[i]; if (ch == ' ' || ch == '-' || ch == ',') @@ -395,7 +395,7 @@ FXFT_Face CFPF_SkiaFontMgr::GetFontFace(const CFX_ByteStringC& bsFile, return nullptr; FXFT_Open_Args args; args.flags = FT_OPEN_PATHNAME; - args.pathname = const_cast<FT_String*>(bsFile.c_str()); + args.pathname = const_cast<FT_String*>(bsFile.unterminated_c_str()); FXFT_Face face; if (FXFT_Open_Face(m_FTLibrary, &args, iFaceIndex, &face)) return nullptr; diff --git a/chromium/third_party/pdfium/core/fxge/android/cfx_androidfontinfo.h b/chromium/third_party/pdfium/core/fxge/android/cfx_androidfontinfo.h index ce08f2558a1..17bbf89a3e5 100644 --- a/chromium/third_party/pdfium/core/fxge/android/cfx_androidfontinfo.h +++ b/chromium/third_party/pdfium/core/fxge/android/cfx_androidfontinfo.h @@ -7,6 +7,7 @@ #ifndef CORE_FXGE_ANDROID_CFX_ANDROIDFONTINFO_H_ #define CORE_FXGE_ANDROID_CFX_ANDROIDFONTINFO_H_ +#include "core/fxcrt/cfx_unowned_ptr.h" #include "core/fxcrt/fx_system.h" #include "core/fxge/cfx_fontmapper.h" #include "core/fxge/fx_font.h" @@ -39,7 +40,7 @@ class CFX_AndroidFontInfo : public IFX_SystemFontInfo { void DeleteFont(void* hFont) override; protected: - CFPF_SkiaFontMgr* m_pFontMgr; + CFX_UnownedPtr<CFPF_SkiaFontMgr> m_pFontMgr; }; #endif // CORE_FXGE_ANDROID_CFX_ANDROIDFONTINFO_H_ diff --git a/chromium/third_party/pdfium/core/fxge/apple/fx_apple_platform.cpp b/chromium/third_party/pdfium/core/fxge/apple/fx_apple_platform.cpp index 1a56b183cf4..56b15b35d09 100644 --- a/chromium/third_party/pdfium/core/fxge/apple/fx_apple_platform.cpp +++ b/chromium/third_party/pdfium/core/fxge/apple/fx_apple_platform.cpp @@ -13,12 +13,12 @@ #endif #include "core/fxge/apple/apple_int.h" +#include "core/fxge/cfx_cliprgn.h" #include "core/fxge/cfx_facecache.h" #include "core/fxge/cfx_gemodule.h" #include "core/fxge/cfx_renderdevice.h" #include "core/fxge/fx_freetype.h" -#include "core/fxge/ge/cfx_cliprgn.h" -#include "core/fxge/ge/fx_text_int.h" +#include "core/fxge/fx_text_int.h" #ifndef _SKIA_SUPPORT_ diff --git a/chromium/third_party/pdfium/core/fxge/apple/fx_mac_imp.cpp b/chromium/third_party/pdfium/core/fxge/apple/fx_mac_imp.cpp index ced08d2776a..78fe16459cd 100644 --- a/chromium/third_party/pdfium/core/fxge/apple/fx_mac_imp.cpp +++ b/chromium/third_party/pdfium/core/fxge/apple/fx_mac_imp.cpp @@ -9,8 +9,8 @@ #include "core/fxcrt/fx_codepage.h" #include "core/fxge/apple/apple_int.h" +#include "core/fxge/cfx_folderfontinfo.h" #include "core/fxge/cfx_gemodule.h" -#include "core/fxge/ge/cfx_folderfontinfo.h" #include "core/fxge/ifx_systemfontinfo.h" #include "third_party/base/ptr_util.h" diff --git a/chromium/third_party/pdfium/core/fxge/apple/fx_quartz_device.cpp b/chromium/third_party/pdfium/core/fxge/apple/fx_quartz_device.cpp index ad09f91f615..f92db2b30bf 100644 --- a/chromium/third_party/pdfium/core/fxge/apple/fx_quartz_device.cpp +++ b/chromium/third_party/pdfium/core/fxge/apple/fx_quartz_device.cpp @@ -15,7 +15,7 @@ #include "core/fxge/cfx_pathdata.h" #include "core/fxge/cfx_renderdevice.h" #include "core/fxge/fx_freetype.h" -#include "core/fxge/ge/fx_text_int.h" +#include "core/fxge/fx_text_int.h" #include "third_party/base/ptr_util.h" #include "core/fxge/apple/apple_int.h" diff --git a/chromium/third_party/pdfium/core/fxge/ge/cfx_cliprgn.cpp b/chromium/third_party/pdfium/core/fxge/cfx_cliprgn.cpp index e00cb7c3ad4..087c11089a9 100644 --- a/chromium/third_party/pdfium/core/fxge/ge/cfx_cliprgn.cpp +++ b/chromium/third_party/pdfium/core/fxge/cfx_cliprgn.cpp @@ -4,7 +4,7 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "core/fxge/ge/cfx_cliprgn.h" +#include "core/fxge/cfx_cliprgn.h" #include <utility> diff --git a/chromium/third_party/pdfium/core/fxge/ge/cfx_cliprgn.h b/chromium/third_party/pdfium/core/fxge/cfx_cliprgn.h index 800e6ddbeef..866af9b2053 100644 --- a/chromium/third_party/pdfium/core/fxge/ge/cfx_cliprgn.h +++ b/chromium/third_party/pdfium/core/fxge/cfx_cliprgn.h @@ -4,8 +4,8 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef CORE_FXGE_GE_CFX_CLIPRGN_H_ -#define CORE_FXGE_GE_CFX_CLIPRGN_H_ +#ifndef CORE_FXGE_CFX_CLIPRGN_H_ +#define CORE_FXGE_CFX_CLIPRGN_H_ #include "core/fxcrt/fx_coordinates.h" @@ -39,4 +39,4 @@ class CFX_ClipRgn { CFX_RetainPtr<CFX_DIBitmap> m_Mask; }; -#endif // CORE_FXGE_GE_CFX_CLIPRGN_H_ +#endif // CORE_FXGE_CFX_CLIPRGN_H_ diff --git a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_color.cpp b/chromium/third_party/pdfium/core/fxge/cfx_color.cpp index 689c3dec452..eebdd2cf1c0 100644 --- a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_color.cpp +++ b/chromium/third_party/pdfium/core/fxge/cfx_color.cpp @@ -4,7 +4,7 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "fpdfsdk/pdfwindow/cpwl_color.h" +#include "core/fxge/cfx_color.h" #include <algorithm> @@ -14,57 +14,57 @@ bool InRange(float comp) { return comp >= 0.0f && comp <= 1.0f; } -CPWL_Color ConvertCMYK2GRAY(float dC, float dM, float dY, float dK) { +CFX_Color ConvertCMYK2GRAY(float dC, float dM, float dY, float dK) { if (!InRange(dC) || !InRange(dM) || !InRange(dY) || !InRange(dK)) - return CPWL_Color(COLORTYPE_GRAY); - return CPWL_Color( + return CFX_Color(COLORTYPE_GRAY); + return CFX_Color( COLORTYPE_GRAY, 1.0f - std::min(1.0f, 0.3f * dC + 0.59f * dM + 0.11f * dY + dK)); } -CPWL_Color ConvertGRAY2CMYK(float dGray) { +CFX_Color ConvertGRAY2CMYK(float dGray) { if (!InRange(dGray)) - return CPWL_Color(COLORTYPE_CMYK); - return CPWL_Color(COLORTYPE_CMYK, 0.0f, 0.0f, 0.0f, 1.0f - dGray); + return CFX_Color(COLORTYPE_CMYK); + return CFX_Color(COLORTYPE_CMYK, 0.0f, 0.0f, 0.0f, 1.0f - dGray); } -CPWL_Color ConvertGRAY2RGB(float dGray) { +CFX_Color ConvertGRAY2RGB(float dGray) { if (!InRange(dGray)) - return CPWL_Color(COLORTYPE_RGB); - return CPWL_Color(COLORTYPE_RGB, dGray, dGray, dGray); + return CFX_Color(COLORTYPE_RGB); + return CFX_Color(COLORTYPE_RGB, dGray, dGray, dGray); } -CPWL_Color ConvertRGB2GRAY(float dR, float dG, float dB) { +CFX_Color ConvertRGB2GRAY(float dR, float dG, float dB) { if (!InRange(dR) || !InRange(dG) || !InRange(dB)) - return CPWL_Color(COLORTYPE_GRAY); - return CPWL_Color(COLORTYPE_GRAY, 0.3f * dR + 0.59f * dG + 0.11f * dB); + return CFX_Color(COLORTYPE_GRAY); + return CFX_Color(COLORTYPE_GRAY, 0.3f * dR + 0.59f * dG + 0.11f * dB); } -CPWL_Color ConvertCMYK2RGB(float dC, float dM, float dY, float dK) { +CFX_Color ConvertCMYK2RGB(float dC, float dM, float dY, float dK) { if (!InRange(dC) || !InRange(dM) || !InRange(dY) || !InRange(dK)) - return CPWL_Color(COLORTYPE_RGB); - return CPWL_Color(COLORTYPE_RGB, 1.0f - std::min(1.0f, dC + dK), - 1.0f - std::min(1.0f, dM + dK), - 1.0f - std::min(1.0f, dY + dK)); + return CFX_Color(COLORTYPE_RGB); + return CFX_Color(COLORTYPE_RGB, 1.0f - std::min(1.0f, dC + dK), + 1.0f - std::min(1.0f, dM + dK), + 1.0f - std::min(1.0f, dY + dK)); } -CPWL_Color ConvertRGB2CMYK(float dR, float dG, float dB) { +CFX_Color ConvertRGB2CMYK(float dR, float dG, float dB) { if (!InRange(dR) || !InRange(dG) || !InRange(dB)) - return CPWL_Color(COLORTYPE_CMYK); + return CFX_Color(COLORTYPE_CMYK); float c = 1.0f - dR; float m = 1.0f - dG; float y = 1.0f - dB; - return CPWL_Color(COLORTYPE_CMYK, c, m, y, std::min(c, std::min(m, y))); + return CFX_Color(COLORTYPE_CMYK, c, m, y, std::min(c, std::min(m, y))); } } // namespace -CPWL_Color CPWL_Color::ConvertColorType(int32_t nConvertColorType) const { +CFX_Color CFX_Color::ConvertColorType(int32_t nConvertColorType) const { if (nColorType == nConvertColorType) return *this; - CPWL_Color ret; + CFX_Color ret; switch (nColorType) { case COLORTYPE_TRANSPARENT: ret = *this; @@ -104,11 +104,11 @@ CPWL_Color CPWL_Color::ConvertColorType(int32_t nConvertColorType) const { return ret; } -FX_COLORREF CPWL_Color::ToFXColor(int32_t nTransparency) const { - CPWL_Color ret; +FX_COLORREF CFX_Color::ToFXColor(int32_t nTransparency) const { + CFX_Color ret; switch (nColorType) { case COLORTYPE_TRANSPARENT: { - ret = CPWL_Color(COLORTYPE_TRANSPARENT, 0, 0, 0, 0); + ret = CFX_Color(COLORTYPE_TRANSPARENT, 0, 0, 0, 0); break; } case COLORTYPE_GRAY: { @@ -117,7 +117,7 @@ FX_COLORREF CPWL_Color::ToFXColor(int32_t nTransparency) const { break; } case COLORTYPE_RGB: { - ret = CPWL_Color(COLORTYPE_RGB, fColor1, fColor2, fColor3); + ret = CFX_Color(COLORTYPE_RGB, fColor1, fColor2, fColor3); ret.fColor4 = nTransparency; break; } @@ -132,8 +132,8 @@ FX_COLORREF CPWL_Color::ToFXColor(int32_t nTransparency) const { static_cast<int32_t>(ret.fColor3 * 255)); } -CPWL_Color CPWL_Color::operator-(float fColorSub) const { - CPWL_Color sRet(nColorType); +CFX_Color CFX_Color::operator-(float fColorSub) const { + CFX_Color sRet(nColorType); switch (nColorType) { case COLORTYPE_TRANSPARENT: sRet.nColorType = COLORTYPE_RGB; @@ -153,8 +153,8 @@ CPWL_Color CPWL_Color::operator-(float fColorSub) const { return sRet; } -CPWL_Color CPWL_Color::operator/(float fColorDivide) const { - CPWL_Color sRet(nColorType); +CFX_Color CFX_Color::operator/(float fColorDivide) const { + CFX_Color sRet(nColorType); switch (nColorType) { case COLORTYPE_TRANSPARENT: sRet.nColorType = COLORTYPE_RGB; diff --git a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_color.h b/chromium/third_party/pdfium/core/fxge/cfx_color.h index 6eae48738fc..b92c0bcc288 100644 --- a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_color.h +++ b/chromium/third_party/pdfium/core/fxge/cfx_color.h @@ -4,34 +4,38 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef FPDFSDK_PDFWINDOW_CPWL_COLOR_H_ -#define FPDFSDK_PDFWINDOW_CPWL_COLOR_H_ +#ifndef CORE_FXGE_CFX_COLOR_H_ +#define CORE_FXGE_CFX_COLOR_H_ #include "core/fpdfdoc/cpdf_formcontrol.h" +#include "core/fxge/fx_dib.h" -struct CPWL_Color { - CPWL_Color(int32_t type = COLORTYPE_TRANSPARENT, - float color1 = 0.0f, - float color2 = 0.0f, - float color3 = 0.0f, - float color4 = 0.0f) +struct CFX_Color { + explicit CFX_Color(FX_COLORREF ref) + : CFX_Color(FXARGB_R(ref), FXARGB_G(ref), FXARGB_B(ref)) {} + + CFX_Color(int32_t type = COLORTYPE_TRANSPARENT, + float color1 = 0.0f, + float color2 = 0.0f, + float color3 = 0.0f, + float color4 = 0.0f) : nColorType(type), fColor1(color1), fColor2(color2), fColor3(color3), fColor4(color4) {} - CPWL_Color(int32_t r, int32_t g, int32_t b) + CFX_Color(int32_t r, int32_t g, int32_t b) : nColorType(COLORTYPE_RGB), fColor1(r / 255.0f), fColor2(g / 255.0f), fColor3(b / 255.0f), fColor4(0) {} - CPWL_Color operator/(float fColorDivide) const; - CPWL_Color operator-(float fColorSub) const; + CFX_Color operator/(float fColorDivide) const; + CFX_Color operator-(float fColorSub) const; - CPWL_Color ConvertColorType(int32_t other_nColorType) const; + CFX_Color ConvertColorType(int32_t other_nColorType) const; FX_COLORREF ToFXColor(int32_t nTransparency) const; @@ -50,4 +54,4 @@ struct CPWL_Color { float fColor4; }; -#endif // FPDFSDK_PDFWINDOW_CPWL_COLOR_H_ +#endif // CORE_FXGE_CFX_COLOR_H_ diff --git a/chromium/third_party/pdfium/core/fxge/ge/cfx_facecache.cpp b/chromium/third_party/pdfium/core/fxge/cfx_facecache.cpp index 9c79444dd30..eac28074fcf 100644 --- a/chromium/third_party/pdfium/core/fxge/ge/cfx_facecache.cpp +++ b/chromium/third_party/pdfium/core/fxge/cfx_facecache.cpp @@ -17,7 +17,7 @@ #include "core/fxge/cfx_pathdata.h" #include "core/fxge/cfx_substfont.h" #include "core/fxge/fx_freetype.h" -#include "core/fxge/ge/fx_text_int.h" +#include "core/fxge/fx_text_int.h" #include "third_party/base/numerics/safe_math.h" #include "third_party/base/ptr_util.h" @@ -88,11 +88,7 @@ CFX_FaceCache::CFX_FaceCache(FXFT_Face face) { } -CFX_FaceCache::~CFX_FaceCache() { -#if defined _SKIA_SUPPORT_ || _SKIA_SUPPORT_PATHS_ - SkSafeUnref(m_pTypeface); -#endif -} +CFX_FaceCache::~CFX_FaceCache() {} std::unique_ptr<CFX_GlyphBitmap> CFX_FaceCache::RenderGlyph( const CFX_Font* pFont, @@ -358,19 +354,17 @@ const CFX_GlyphBitmap* CFX_FaceCache::LoadGlyphBitmap(const CFX_Font* pFont, #if defined _SKIA_SUPPORT_ || defined _SKIA_SUPPORT_PATHS_ CFX_TypeFace* CFX_FaceCache::GetDeviceCache(const CFX_Font* pFont) { if (!m_pTypeface) { - m_pTypeface = - SkTypeface::MakeFromStream( - new SkMemoryStream(pFont->GetFontData(), pFont->GetSize())) - .release(); + m_pTypeface = SkTypeface::MakeFromStream( + new SkMemoryStream(pFont->GetFontData(), pFont->GetSize())); } #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ if (!m_pTypeface) { sk_sp<SkFontMgr> customMgr(SkFontMgr_New_Custom_Empty()); - m_pTypeface = customMgr->createFromStream( - new SkMemoryStream(pFont->GetFontData(), pFont->GetSize())); + m_pTypeface.reset(customMgr->createFromStream( + new SkMemoryStream(pFont->GetFontData(), pFont->GetSize()))); } #endif - return m_pTypeface; + return m_pTypeface.get(); } #endif diff --git a/chromium/third_party/pdfium/core/fxge/cfx_facecache.h b/chromium/third_party/pdfium/core/fxge/cfx_facecache.h index 5857a6310b7..076ba1f3303 100644 --- a/chromium/third_party/pdfium/core/fxge/cfx_facecache.h +++ b/chromium/third_party/pdfium/core/fxge/cfx_facecache.h @@ -10,9 +10,14 @@ #include <map> #include <memory> +#include "core/fxcrt/cfx_unowned_ptr.h" #include "core/fxge/fx_font.h" #include "core/fxge/fx_freetype.h" +#if defined _SKIA_SUPPORT_ || _SKIA_SUPPORT_PATHS_ +#include "third_party/skia/include/core/SkTypeface.h" +#endif + class CFX_FaceCache { public: explicit CFX_FaceCache(FXFT_Face face); @@ -59,7 +64,7 @@ class CFX_FaceCache { std::map<CFX_ByteString, std::unique_ptr<CFX_SizeGlyphCache>> m_SizeMap; std::map<uint32_t, std::unique_ptr<CFX_PathData>> m_PathMap; #if defined _SKIA_SUPPORT_ || _SKIA_SUPPORT_PATHS_ - CFX_TypeFace* m_pTypeface; + sk_sp<SkTypeface> m_pTypeface; #endif }; diff --git a/chromium/third_party/pdfium/core/fxge/ge/cfx_folderfontinfo.cpp b/chromium/third_party/pdfium/core/fxge/cfx_folderfontinfo.cpp index a13af068e8c..12e7dd25fcf 100644 --- a/chromium/third_party/pdfium/core/fxge/ge/cfx_folderfontinfo.cpp +++ b/chromium/third_party/pdfium/core/fxge/cfx_folderfontinfo.cpp @@ -4,7 +4,7 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "core/fxge/ge/cfx_folderfontinfo.h" +#include "core/fxge/cfx_folderfontinfo.h" #include <limits> #include <utility> diff --git a/chromium/third_party/pdfium/core/fxge/ge/cfx_folderfontinfo.h b/chromium/third_party/pdfium/core/fxge/cfx_folderfontinfo.h index 6aadb1526f5..82ed902b22b 100644 --- a/chromium/third_party/pdfium/core/fxge/ge/cfx_folderfontinfo.h +++ b/chromium/third_party/pdfium/core/fxge/cfx_folderfontinfo.h @@ -4,13 +4,14 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef CORE_FXGE_GE_CFX_FOLDERFONTINFO_H_ -#define CORE_FXGE_GE_CFX_FOLDERFONTINFO_H_ +#ifndef CORE_FXGE_CFX_FOLDERFONTINFO_H_ +#define CORE_FXGE_CFX_FOLDERFONTINFO_H_ #include <map> #include <memory> #include <vector> +#include "core/fxcrt/cfx_unowned_ptr.h" #include "core/fxge/cfx_fontmapper.h" #include "core/fxge/fx_font.h" #include "core/fxge/ifx_systemfontinfo.h" @@ -62,7 +63,7 @@ class CFX_FolderFontInfo : public IFX_SystemFontInfo { std::map<CFX_ByteString, std::unique_ptr<CFX_FontFaceInfo>> m_FontList; std::vector<CFX_ByteString> m_PathList; - CFX_FontMapper* m_pMapper; + CFX_UnownedPtr<CFX_FontMapper> m_pMapper; }; -#endif // CORE_FXGE_GE_CFX_FOLDERFONTINFO_H_ +#endif // CORE_FXGE_CFX_FOLDERFONTINFO_H_ diff --git a/chromium/third_party/pdfium/core/fxge/ge/cfx_font.cpp b/chromium/third_party/pdfium/core/fxge/cfx_font.cpp index 229ede78943..a8e271dd9a4 100644 --- a/chromium/third_party/pdfium/core/fxge/ge/cfx_font.cpp +++ b/chromium/third_party/pdfium/core/fxge/cfx_font.cpp @@ -21,19 +21,19 @@ #include "core/fxge/cfx_pathdata.h" #include "core/fxge/cfx_substfont.h" #include "core/fxge/fx_freetype.h" -#include "core/fxge/ge/fx_text_int.h" +#include "core/fxge/fx_text_int.h" #include "third_party/base/ptr_util.h" #define EM_ADJUST(em, a) (em == 0 ? (a) : (a)*1000 / em) namespace { -typedef struct { +struct OUTLINE_PARAMS { CFX_PathData* m_pPath; int m_CurX; int m_CurY; float m_CoordUnit; -} OUTLINE_PARAMS; +}; #ifdef PDF_ENABLE_XFA @@ -560,9 +560,8 @@ void CFX_Font::AdjustMMParams(int glyph_index, FXFT_Free(m_Face, pMasters); return; } - int param = min_param + - (max_param - min_param) * (dest_width - min_width) / - (max_width - min_width); + int param = min_param + (max_param - min_param) * (dest_width - min_width) / + (max_width - min_width); coords[1] = param; } FXFT_Free(m_Face, pMasters); diff --git a/chromium/third_party/pdfium/core/fxge/ge/cfx_fontcache.cpp b/chromium/third_party/pdfium/core/fxge/cfx_fontcache.cpp index 5ccac8cfbcd..5ccac8cfbcd 100644 --- a/chromium/third_party/pdfium/core/fxge/ge/cfx_fontcache.cpp +++ b/chromium/third_party/pdfium/core/fxge/cfx_fontcache.cpp diff --git a/chromium/third_party/pdfium/core/fxge/ge/cfx_fontmapper.cpp b/chromium/third_party/pdfium/core/fxge/cfx_fontmapper.cpp index 4d5e9c4831c..5b4ceaac593 100644 --- a/chromium/third_party/pdfium/core/fxge/ge/cfx_fontmapper.cpp +++ b/chromium/third_party/pdfium/core/fxge/cfx_fontmapper.cpp @@ -8,6 +8,7 @@ #include <algorithm> #include <memory> +#include <sstream> #include <utility> #include <vector> @@ -225,16 +226,16 @@ CFX_ByteString GetFontFamily(CFX_ByteString fontName, int nStyle) { } CFX_ByteString ParseStyle(const char* pStyle, int iLen, int iIndex) { - CFX_ByteTextBuf buf; + std::ostringstream buf; if (!iLen || iLen <= iIndex) - return buf.MakeString(); + return CFX_ByteString(buf); while (iIndex < iLen) { if (pStyle[iIndex] == ',') break; - buf.AppendChar(pStyle[iIndex]); + buf << pStyle[iIndex]; ++iIndex; } - return buf.MakeString(); + return CFX_ByteString(buf); } int32_t GetStyleType(const CFX_ByteString& bsStyle, bool bReverse) { diff --git a/chromium/third_party/pdfium/core/fxge/ge/cfx_fontmgr.cpp b/chromium/third_party/pdfium/core/fxge/cfx_fontmgr.cpp index ec184ae2665..c8beb515f09 100644 --- a/chromium/third_party/pdfium/core/fxge/ge/cfx_fontmgr.cpp +++ b/chromium/third_party/pdfium/core/fxge/cfx_fontmgr.cpp @@ -11,9 +11,9 @@ #include "core/fxge/cfx_fontmapper.h" #include "core/fxge/cfx_substfont.h" +#include "core/fxge/cttfontdesc.h" #include "core/fxge/fontdata/chromefontdata/chromefontdata.h" #include "core/fxge/fx_font.h" -#include "core/fxge/ge/cttfontdesc.h" #include "core/fxge/ifx_systemfontinfo.h" #include "third_party/base/ptr_util.h" diff --git a/chromium/third_party/pdfium/core/fxge/ge/cfx_gemodule.cpp b/chromium/third_party/pdfium/core/fxge/cfx_gemodule.cpp index 4516d61e277..a28a88243a3 100644 --- a/chromium/third_party/pdfium/core/fxge/ge/cfx_gemodule.cpp +++ b/chromium/third_party/pdfium/core/fxge/cfx_gemodule.cpp @@ -6,10 +6,10 @@ #include "core/fxge/cfx_gemodule.h" +#include "core/fxge/cfx_folderfontinfo.h" #include "core/fxge/cfx_fontcache.h" #include "core/fxge/cfx_fontmgr.h" -#include "core/fxge/ge/cfx_folderfontinfo.h" -#include "core/fxge/ge/fx_text_int.h" +#include "core/fxge/fx_text_int.h" #include "third_party/base/ptr_util.h" namespace { diff --git a/chromium/third_party/pdfium/core/fxge/ge/cfx_graphstate.cpp b/chromium/third_party/pdfium/core/fxge/cfx_graphstate.cpp index 54443b96365..ad6b5fc6c7c 100644 --- a/chromium/third_party/pdfium/core/fxge/ge/cfx_graphstate.cpp +++ b/chromium/third_party/pdfium/core/fxge/cfx_graphstate.cpp @@ -36,14 +36,16 @@ void CFX_GraphState::SetLineWidth(float width) { } CFX_GraphStateData::LineCap CFX_GraphState::GetLineCap() const { - return m_Ref.GetObject()->m_LineCap; + return m_Ref.GetObject() ? m_Ref.GetObject()->m_LineCap + : CFX_GraphStateData::LineCapButt; } void CFX_GraphState::SetLineCap(CFX_GraphStateData::LineCap cap) { m_Ref.GetPrivateCopy()->m_LineCap = cap; } CFX_GraphStateData::LineJoin CFX_GraphState::GetLineJoin() const { - return m_Ref.GetObject()->m_LineJoin; + return m_Ref.GetObject() ? m_Ref.GetObject()->m_LineJoin + : CFX_GraphStateData::LineJoinMiter; } void CFX_GraphState::SetLineJoin(CFX_GraphStateData::LineJoin join) { diff --git a/chromium/third_party/pdfium/core/fxge/ge/cfx_graphstatedata.cpp b/chromium/third_party/pdfium/core/fxge/cfx_graphstatedata.cpp index 82fede176a5..82fede176a5 100644 --- a/chromium/third_party/pdfium/core/fxge/ge/cfx_graphstatedata.cpp +++ b/chromium/third_party/pdfium/core/fxge/cfx_graphstatedata.cpp diff --git a/chromium/third_party/pdfium/core/fxge/ge/cfx_pathdata.cpp b/chromium/third_party/pdfium/core/fxge/cfx_pathdata.cpp index 6fae44acb1f..fe3c6778d53 100644 --- a/chromium/third_party/pdfium/core/fxge/ge/cfx_pathdata.cpp +++ b/chromium/third_party/pdfium/core/fxge/cfx_pathdata.cpp @@ -240,6 +240,9 @@ CFX_FloatRect CFX_PathData::GetBoundingBox(float line_width, bool bJoin; while (iPoint < m_Points.size()) { if (m_Points[iPoint].IsTypeAndOpen(FXPT_TYPE::MoveTo)) { + if (iPoint + 1 == m_Points.size()) + break; + iStartPoint = iPoint + 1; iEndPoint = iPoint; bJoin = false; diff --git a/chromium/third_party/pdfium/core/fxge/ge/cfx_renderdevice.cpp b/chromium/third_party/pdfium/core/fxge/cfx_renderdevice.cpp index f9153d1cdbb..407c090c731 100644 --- a/chromium/third_party/pdfium/core/fxge/ge/cfx_renderdevice.cpp +++ b/chromium/third_party/pdfium/core/fxge/cfx_renderdevice.cpp @@ -121,6 +121,12 @@ uint8_t CalculateDestAlpha(uint8_t back_alpha, int src_alpha) { return back_alpha + src_alpha - back_alpha * src_alpha / 255; } +void ApplyAlpha(uint8_t* dest, int b, int g, int r, int alpha) { + dest[0] = FXDIB_ALPHA_MERGE(dest[0], b, alpha); + dest[1] = FXDIB_ALPHA_MERGE(dest[1], g, alpha); + dest[2] = FXDIB_ALPHA_MERGE(dest[2], r, alpha); +} + void ApplyDestAlpha(uint8_t back_alpha, int src_alpha, int r, @@ -128,61 +134,57 @@ void ApplyDestAlpha(uint8_t back_alpha, int b, uint8_t* dest) { uint8_t dest_alpha = CalculateDestAlpha(back_alpha, src_alpha); - int alpha_ratio = src_alpha * 255 / dest_alpha; - dest[0] = FXDIB_ALPHA_MERGE(dest[0], b, alpha_ratio); - dest[1] = FXDIB_ALPHA_MERGE(dest[1], g, alpha_ratio); - dest[2] = FXDIB_ALPHA_MERGE(dest[2], r, alpha_ratio); + ApplyAlpha(dest, b, g, r, src_alpha * 255 / dest_alpha); dest[3] = dest_alpha; } -void NormalizeRgbDst(int src_value, int r, int g, int b, int a, uint8_t* dest) { - int src_alpha = CalcAlpha(TextGammaAdjust(src_value), a); - dest[0] = FXDIB_ALPHA_MERGE(dest[0], b, src_alpha); - dest[1] = FXDIB_ALPHA_MERGE(dest[1], g, src_alpha); - dest[2] = FXDIB_ALPHA_MERGE(dest[2], r, src_alpha); -} - -void NormalizeRgbSrc(int src_value, int r, int g, int b, int a, uint8_t* dest) { - int src_alpha = CalcAlpha(TextGammaAdjust(src_value), a); - if (src_alpha == 0) - return; - - dest[0] = FXDIB_ALPHA_MERGE(dest[0], b, src_alpha); - dest[1] = FXDIB_ALPHA_MERGE(dest[1], g, src_alpha); - dest[2] = FXDIB_ALPHA_MERGE(dest[2], r, src_alpha); -} - -void NormalizeArgbDest(int src_value, - int r, - int g, - int b, - int a, - uint8_t* dest) { - int src_alpha = CalcAlpha(TextGammaAdjust(src_value), a); +void NormalizeArgb(int src_value, + int r, + int g, + int b, + int a, + uint8_t* dest, + int src_alpha) { uint8_t back_alpha = dest[3]; - if (back_alpha == 0) { + if (back_alpha == 0) FXARGB_SETDIB(dest, FXARGB_MAKE(src_alpha, r, g, b)); - } else if (src_alpha != 0) { + else if (src_alpha != 0) ApplyDestAlpha(back_alpha, src_alpha, r, g, b, dest); - } } -void NormalizeArgbSrc(int src_value, - int r, - int g, - int b, - int a, - uint8_t* dest) { +void NormalizeDest(bool has_alpha, + int src_value, + int r, + int g, + int b, + int a, + uint8_t* dest) { + if (has_alpha) { + NormalizeArgb(src_value, r, g, b, a, dest, + CalcAlpha(TextGammaAdjust(src_value), a)); + return; + } int src_alpha = CalcAlpha(TextGammaAdjust(src_value), a); if (src_alpha == 0) return; - uint8_t back_alpha = dest[3]; - if (back_alpha == 0) { - FXARGB_SETDIB(dest, FXARGB_MAKE(src_alpha, r, g, b)); - } else { - ApplyDestAlpha(back_alpha, src_alpha, r, g, b, dest); + ApplyAlpha(dest, b, g, r, src_alpha); +} + +void NormalizeSrc(bool has_alpha, + int src_value, + int r, + int g, + int b, + int a, + uint8_t* dest) { + if (!has_alpha) { + ApplyAlpha(dest, b, g, r, CalcAlpha(TextGammaAdjust(src_value), a)); + return; } + int src_alpha = CalcAlpha(TextGammaAdjust(src_value), a); + if (src_alpha != 0) + NormalizeArgb(src_value, r, g, b, a, dest, src_alpha); } void NextPixel(uint8_t** src_scan, uint8_t** dst_scan, int bpp) { @@ -190,12 +192,11 @@ void NextPixel(uint8_t** src_scan, uint8_t** dst_scan, int bpp) { *dst_scan += bpp; } -void SetAlpha(uint8_t* alpha) { - alpha[3] = 255; +void SetAlpha(bool has_alpha, uint8_t* alpha) { + if (has_alpha) + alpha[3] = 255; } -void SetAlphaDoNothing(uint8_t* alpha) {} - void DrawNormalTextHelper(const CFX_RetainPtr<CFX_DIBitmap>& bitmap, const CFX_RetainPtr<CFX_DIBitmap>& pGlyph, int nrows, @@ -216,11 +217,7 @@ void DrawNormalTextHelper(const CFX_RetainPtr<CFX_DIBitmap>& bitmap, uint8_t* dest_buf = bitmap->GetBuffer(); int dest_pitch = bitmap->GetPitch(); const int Bpp = has_alpha ? 4 : bitmap->GetBPP() / 8; - auto* pNormalizeSrcFunc = has_alpha ? &NormalizeArgbSrc : &NormalizeRgbDst; - auto* pNormalizeDstFunc = has_alpha ? &NormalizeArgbDest : &NormalizeRgbSrc; - auto* pSetAlpha = has_alpha ? &SetAlpha : &SetAlphaDoNothing; - - for (int row = 0; row < nrows; row++) { + for (int row = 0; row < nrows; ++row) { int dest_row = row + top; if (dest_row < 0 || dest_row >= bitmap->GetHeight()) continue; @@ -229,7 +226,7 @@ void DrawNormalTextHelper(const CFX_RetainPtr<CFX_DIBitmap>& bitmap, uint8_t* dest_scan = dest_buf + dest_row * dest_pitch + start_col * Bpp; if (bBGRStripe) { if (x_subpixel == 0) { - for (int col = start_col; col < end_col; col++) { + for (int col = start_col; col < end_col; ++col) { if (has_alpha) { Merge(src_scan[2], r, a, &dest_scan[2]); Merge(src_scan[1], g, a, &dest_scan[1]); @@ -237,95 +234,99 @@ void DrawNormalTextHelper(const CFX_RetainPtr<CFX_DIBitmap>& bitmap, } else { MergeGammaAdjustBgr(&src_scan[0], r, g, b, a, &dest_scan[0]); } - pSetAlpha(dest_scan); + SetAlpha(has_alpha, dest_scan); NextPixel(&src_scan, &dest_scan, Bpp); } - } else if (x_subpixel == 1) { + continue; + } + if (x_subpixel == 1) { MergeGammaAdjust(src_scan[1], r, a, &dest_scan[2]); MergeGammaAdjust(src_scan[0], g, a, &dest_scan[1]); if (start_col > left) MergeGammaAdjust(src_scan[-1], b, a, &dest_scan[0]); - pSetAlpha(dest_scan); + SetAlpha(has_alpha, dest_scan); NextPixel(&src_scan, &dest_scan, Bpp); - for (int col = start_col + 1; col < end_col - 1; col++) { + for (int col = start_col + 1; col < end_col - 1; ++col) { MergeGammaAdjustBgr(&src_scan[-1], r, g, b, a, &dest_scan[0]); - pSetAlpha(dest_scan); + SetAlpha(has_alpha, dest_scan); NextPixel(&src_scan, &dest_scan, Bpp); } - } else { - MergeGammaAdjust(src_scan[0], r, a, &dest_scan[2]); - if (start_col > left) { - MergeGammaAdjust(src_scan[-1], g, a, &dest_scan[1]); - MergeGammaAdjust(src_scan[-2], b, a, &dest_scan[0]); - } - pSetAlpha(dest_scan); + continue; + } + MergeGammaAdjust(src_scan[0], r, a, &dest_scan[2]); + if (start_col > left) { + MergeGammaAdjust(src_scan[-1], g, a, &dest_scan[1]); + MergeGammaAdjust(src_scan[-2], b, a, &dest_scan[0]); + } + SetAlpha(has_alpha, dest_scan); + NextPixel(&src_scan, &dest_scan, Bpp); + for (int col = start_col + 1; col < end_col - 1; ++col) { + MergeGammaAdjustBgr(&src_scan[-2], r, g, b, a, &dest_scan[0]); + SetAlpha(has_alpha, dest_scan); NextPixel(&src_scan, &dest_scan, Bpp); - for (int col = start_col + 1; col < end_col - 1; col++) { - MergeGammaAdjustBgr(&src_scan[-2], r, g, b, a, &dest_scan[0]); - pSetAlpha(dest_scan); - NextPixel(&src_scan, &dest_scan, Bpp); - } } - } else { - if (x_subpixel == 0) { - for (int col = start_col; col < end_col; col++) { - if (bNormal) { - int src_value = AverageRgb(&src_scan[0]); - pNormalizeDstFunc(src_value, r, g, b, a, dest_scan); - } else { - MergeGammaAdjustRgb(&src_scan[0], r, g, b, a, &dest_scan[0]); - pSetAlpha(dest_scan); - } - NextPixel(&src_scan, &dest_scan, Bpp); - } - } else if (x_subpixel == 1) { + continue; + } + if (x_subpixel == 0) { + for (int col = start_col; col < end_col; ++col) { if (bNormal) { - int src_value = start_col > left ? AverageRgb(&src_scan[-1]) - : (src_scan[0] + src_scan[1]) / 3; - pNormalizeSrcFunc(src_value, r, g, b, a, dest_scan); + int src_value = AverageRgb(&src_scan[0]); + NormalizeDest(has_alpha, src_value, r, g, b, a, dest_scan); } else { - if (start_col > left) - MergeGammaAdjust(src_scan[-1], r, a, &dest_scan[2]); - MergeGammaAdjust(src_scan[0], g, a, &dest_scan[1]); - MergeGammaAdjust(src_scan[1], b, a, &dest_scan[0]); - pSetAlpha(dest_scan); + MergeGammaAdjustRgb(&src_scan[0], r, g, b, a, &dest_scan[0]); + SetAlpha(has_alpha, dest_scan); } NextPixel(&src_scan, &dest_scan, Bpp); - for (int col = start_col + 1; col < end_col; col++) { - if (bNormal) { - int src_value = AverageRgb(&src_scan[-1]); - pNormalizeDstFunc(src_value, r, g, b, a, dest_scan); - } else { - MergeGammaAdjustRgb(&src_scan[-1], r, g, b, a, &dest_scan[0]); - pSetAlpha(dest_scan); - } - NextPixel(&src_scan, &dest_scan, Bpp); - } + } + continue; + } + if (x_subpixel == 1) { + if (bNormal) { + int src_value = start_col > left ? AverageRgb(&src_scan[-1]) + : (src_scan[0] + src_scan[1]) / 3; + NormalizeSrc(has_alpha, src_value, r, g, b, a, dest_scan); } else { + if (start_col > left) + MergeGammaAdjust(src_scan[-1], r, a, &dest_scan[2]); + MergeGammaAdjust(src_scan[0], g, a, &dest_scan[1]); + MergeGammaAdjust(src_scan[1], b, a, &dest_scan[0]); + SetAlpha(has_alpha, dest_scan); + } + NextPixel(&src_scan, &dest_scan, Bpp); + for (int col = start_col + 1; col < end_col; ++col) { if (bNormal) { - int src_value = - start_col > left ? AverageRgb(&src_scan[-2]) : src_scan[0] / 3; - pNormalizeSrcFunc(src_value, r, g, b, a, dest_scan); + int src_value = AverageRgb(&src_scan[-1]); + NormalizeDest(has_alpha, src_value, r, g, b, a, dest_scan); } else { - if (start_col > left) { - MergeGammaAdjust(src_scan[-2], r, a, &dest_scan[2]); - MergeGammaAdjust(src_scan[-1], g, a, &dest_scan[1]); - } - MergeGammaAdjust(src_scan[0], b, a, &dest_scan[0]); - pSetAlpha(dest_scan); + MergeGammaAdjustRgb(&src_scan[-1], r, g, b, a, &dest_scan[0]); + SetAlpha(has_alpha, dest_scan); } NextPixel(&src_scan, &dest_scan, Bpp); - for (int col = start_col + 1; col < end_col; col++) { - if (bNormal) { - int src_value = AverageRgb(&src_scan[-2]); - pNormalizeDstFunc(src_value, r, g, b, a, dest_scan); - } else { - MergeGammaAdjustRgb(&src_scan[-2], r, g, b, a, &dest_scan[0]); - pSetAlpha(dest_scan); - } - NextPixel(&src_scan, &dest_scan, Bpp); - } } + continue; + } + if (bNormal) { + int src_value = + start_col > left ? AverageRgb(&src_scan[-2]) : src_scan[0] / 3; + NormalizeSrc(has_alpha, src_value, r, g, b, a, dest_scan); + } else { + if (start_col > left) { + MergeGammaAdjust(src_scan[-2], r, a, &dest_scan[2]); + MergeGammaAdjust(src_scan[-1], g, a, &dest_scan[1]); + } + MergeGammaAdjust(src_scan[0], b, a, &dest_scan[0]); + SetAlpha(has_alpha, dest_scan); + } + NextPixel(&src_scan, &dest_scan, Bpp); + for (int col = start_col + 1; col < end_col; ++col) { + if (bNormal) { + int src_value = AverageRgb(&src_scan[-2]); + NormalizeDest(has_alpha, src_value, r, g, b, a, dest_scan); + } else { + MergeGammaAdjustRgb(&src_scan[-2], r, g, b, a, &dest_scan[0]); + SetAlpha(has_alpha, dest_scan); + } + NextPixel(&src_scan, &dest_scan, Bpp); } } } @@ -348,7 +349,8 @@ bool ShouldDrawDeviceText(const CFX_Font* pFont, uint32_t text_flags) { } // namespace FXTEXT_CHARPOS::FXTEXT_CHARPOS() - : m_GlyphIndex(0), + : m_Unicode(0), + m_GlyphIndex(0), m_FontCharWidth(0), #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ m_ExtGID(0), @@ -371,6 +373,7 @@ CFX_RenderDevice::CFX_RenderDevice() m_DeviceClass(0) {} CFX_RenderDevice::~CFX_RenderDevice() { + RestoreState(false); #if defined _SKIA_SUPPORT_ || defined _SKIA_SUPPORT_PATHS_ Flush(); #endif @@ -407,13 +410,16 @@ void CFX_RenderDevice::SaveState() { } void CFX_RenderDevice::RestoreState(bool bKeepSaved) { - m_pDeviceDriver->RestoreState(bKeepSaved); - UpdateClipBox(); + if (m_pDeviceDriver) { + m_pDeviceDriver->RestoreState(bKeepSaved); + UpdateClipBox(); + } } int CFX_RenderDevice::GetDeviceCaps(int caps_id) const { return m_pDeviceDriver->GetDeviceCaps(caps_id); } + CFX_Matrix CFX_RenderDevice::GetCTM() const { return m_pDeviceDriver->GetCTM(); } @@ -423,16 +429,16 @@ bool CFX_RenderDevice::CreateCompatibleBitmap( int width, int height) const { if (m_RenderCaps & FXRC_CMYK_OUTPUT) { - return pDIB->Create(width, height, m_RenderCaps & FXRC_ALPHA_OUTPUT - ? FXDIB_Cmyka - : FXDIB_Cmyk); + return pDIB->Create( + width, height, + m_RenderCaps & FXRC_ALPHA_OUTPUT ? FXDIB_Cmyka : FXDIB_Cmyk); } if (m_RenderCaps & FXRC_BYTEMASK_OUTPUT) return pDIB->Create(width, height, FXDIB_8bppMask); #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ || defined _SKIA_SUPPORT_PATHS_ - return pDIB->Create(width, height, m_RenderCaps & FXRC_ALPHA_OUTPUT - ? FXDIB_Argb - : FXDIB_Rgb32); + return pDIB->Create( + width, height, + m_RenderCaps & FXRC_ALPHA_OUTPUT ? FXDIB_Argb : FXDIB_Rgb32); #else return pDIB->Create( width, height, m_RenderCaps & FXRC_ALPHA_OUTPUT ? FXDIB_Argb : FXDIB_Rgb); @@ -515,32 +521,32 @@ bool CFX_RenderDevice::DrawPathWithBlend(const CFX_PathData* pPathData, if (!rect_i.Valid()) return false; - int width = (int)ceil(rect_f.right - rect_f.left); + int width = static_cast<int>(ceil(rect_f.right - rect_f.left)); if (width < 1) { width = 1; if (rect_i.left == rect_i.right) - rect_i.right++; + ++rect_i.right; } - int height = (int)ceil(rect_f.top - rect_f.bottom); + int height = static_cast<int>(ceil(rect_f.top - rect_f.bottom)); if (height < 1) { height = 1; if (rect_i.bottom == rect_i.top) - rect_i.bottom++; + ++rect_i.bottom; } if (rect_i.Width() >= width + 1) { - if (rect_f.left - (float)(rect_i.left) > - (float)(rect_i.right) - rect_f.right) { - rect_i.left++; + if (rect_f.left - static_cast<float>(rect_i.left) > + static_cast<float>(rect_i.right) - rect_f.right) { + ++rect_i.left; } else { - rect_i.right--; + --rect_i.right; } } if (rect_i.Height() >= height + 1) { - if (rect_f.top - (float)(rect_i.top) > - (float)(rect_i.bottom) - rect_f.bottom) { - rect_i.top++; + if (rect_f.top - static_cast<float>(rect_i.top) > + static_cast<float>(rect_i.bottom) - rect_f.bottom) { + ++rect_i.top; } else { - rect_i.bottom--; + --rect_i.bottom; } } if (FillRectWithBlend(&rect_i, fill_color, blend_type)) @@ -649,14 +655,6 @@ bool CFX_RenderDevice::DrawFillStrokePath(const CFX_PathData* pPathData, FXDIB_BLEND_NORMAL); } -bool CFX_RenderDevice::SetPixel(int x, int y, uint32_t color) { - if (m_pDeviceDriver->SetPixel(x, y, color)) - return true; - - FX_RECT rect(x, y, x + 1, y + 1); - return FillRectWithBlend(&rect, color, FXDIB_BLEND_NORMAL); -} - bool CFX_RenderDevice::FillRectWithBlend(const FX_RECT* pRect, uint32_t fill_color, int blend_type) { @@ -705,9 +703,8 @@ bool CFX_RenderDevice::DrawCosmeticLine(float x1, bool CFX_RenderDevice::GetDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, int left, int top) { - if (!(m_RenderCaps & FXRC_GET_BITS)) - return false; - return m_pDeviceDriver->GetDIBits(pBitmap, left, top); + return (m_RenderCaps & FXRC_GET_BITS) && + m_pDeviceDriver->GetDIBits(pBitmap, left, top); } CFX_RetainPtr<CFX_DIBitmap> CFX_RenderDevice::GetBackDrop() { @@ -737,34 +734,33 @@ bool CFX_RenderDevice::SetDIBitsWithBlend( src_rect.top = FXSYS_round(src_rect.top * fScaleY); src_rect.right = FXSYS_round(src_rect.right * fScaleX); src_rect.bottom = FXSYS_round(src_rect.bottom * fScaleY); - if ((blend_mode != FXDIB_BLEND_NORMAL && !(m_RenderCaps & FXRC_BLEND_MODE)) || - (pBitmap->HasAlpha() && !(m_RenderCaps & FXRC_ALPHA_IMAGE))) { - if (!(m_RenderCaps & FXRC_GET_BITS)) - return false; + if ((blend_mode == FXDIB_BLEND_NORMAL || (m_RenderCaps & FXRC_BLEND_MODE)) && + (!pBitmap->HasAlpha() || (m_RenderCaps & FXRC_ALPHA_IMAGE))) { + return m_pDeviceDriver->SetDIBits(pBitmap, 0, &src_rect, dest_rect.left, + dest_rect.top, blend_mode); + } + if (!(m_RenderCaps & FXRC_GET_BITS)) + return false; - int bg_pixel_width = FXSYS_round(dest_rect.Width() * fScaleX); - int bg_pixel_height = FXSYS_round(dest_rect.Height() * fScaleY); - auto background = pdfium::MakeRetain<CFX_DIBitmap>(); - if (!background->Create( - bg_pixel_width, bg_pixel_height, - (m_RenderCaps & FXRC_CMYK_OUTPUT) ? FXDIB_Cmyk : FXDIB_Rgb32)) { - return false; - } - if (!m_pDeviceDriver->GetDIBits(background, dest_rect.left, - dest_rect.top)) { - return false; - } - if (!background->CompositeBitmap(0, 0, bg_pixel_width, bg_pixel_height, - pBitmap, src_rect.left, src_rect.top, - blend_mode, nullptr, false)) { - return false; - } - FX_RECT rect(0, 0, bg_pixel_width, bg_pixel_height); - return m_pDeviceDriver->SetDIBits(background, 0, &rect, dest_rect.left, - dest_rect.top, FXDIB_BLEND_NORMAL); + int bg_pixel_width = FXSYS_round(dest_rect.Width() * fScaleX); + int bg_pixel_height = FXSYS_round(dest_rect.Height() * fScaleY); + auto background = pdfium::MakeRetain<CFX_DIBitmap>(); + if (!background->Create( + bg_pixel_width, bg_pixel_height, + (m_RenderCaps & FXRC_CMYK_OUTPUT) ? FXDIB_Cmyk : FXDIB_Rgb32)) { + return false; + } + if (!m_pDeviceDriver->GetDIBits(background, dest_rect.left, dest_rect.top)) { + return false; + } + if (!background->CompositeBitmap(0, 0, bg_pixel_width, bg_pixel_height, + pBitmap, src_rect.left, src_rect.top, + blend_mode, nullptr, false)) { + return false; } - return m_pDeviceDriver->SetDIBits(pBitmap, 0, &src_rect, dest_rect.left, - dest_rect.top, blend_mode); + FX_RECT rect(0, 0, bg_pixel_width, bg_pixel_height); + return m_pDeviceDriver->SetDIBits(background, 0, &rect, dest_rect.left, + dest_rect.top, FXDIB_BLEND_NORMAL); } bool CFX_RenderDevice::StretchDIBitsWithFlagsAndBlend( @@ -778,11 +774,9 @@ bool CFX_RenderDevice::StretchDIBitsWithFlagsAndBlend( FX_RECT dest_rect(left, top, left + dest_width, top + dest_height); FX_RECT clip_box = m_ClipBox; clip_box.Intersect(dest_rect); - if (clip_box.IsEmpty()) - return true; - return m_pDeviceDriver->StretchDIBits(pBitmap, 0, left, top, dest_width, - dest_height, &clip_box, flags, - blend_mode); + return clip_box.IsEmpty() || m_pDeviceDriver->StretchDIBits( + pBitmap, 0, left, top, dest_width, + dest_height, &clip_box, flags, blend_mode); } bool CFX_RenderDevice::SetBitMask(const CFX_RetainPtr<CFX_DIBSource>& pBitmap, @@ -963,10 +957,10 @@ bool CFX_RenderDevice::DrawNormalText(int nChars, FX_RECT bmp_rect1 = FXGE_GetGlyphsBBox(glyphs, anti_alias, 1.0f, 1.0f); if (scale_x > 1 && scale_y > 1) { - bmp_rect1.left--; - bmp_rect1.top--; - bmp_rect1.right++; - bmp_rect1.bottom++; + --bmp_rect1.left; + --bmp_rect1.top; + ++bmp_rect1.right; + ++bmp_rect1.bottom; } FX_RECT bmp_rect(FXSYS_round((float)(bmp_rect1.left) / scale_x), FXSYS_round((float)(bmp_rect1.top) / scale_y), @@ -1085,7 +1079,7 @@ bool CFX_RenderDevice::DrawTextPath(int nChars, FX_ARGB stroke_color, CFX_PathData* pClippingPath, int nFlag) { - for (int iChar = 0; iChar < nChars; iChar++) { + for (int iChar = 0; iChar < nChars; ++iChar) { const FXTEXT_CHARPOS& charpos = pCharPos[iChar]; CFX_Matrix matrix; if (charpos.m_bGlyphAdjust) { @@ -1120,3 +1114,236 @@ bool CFX_RenderDevice::DrawTextPath(int nChars, } return true; } + +void CFX_RenderDevice::DrawFillRect(CFX_Matrix* pUser2Device, + const CFX_FloatRect& rect, + const FX_COLORREF& color) { + CFX_PathData path; + CFX_FloatRect rcTemp(rect); + path.AppendRect(rcTemp.left, rcTemp.bottom, rcTemp.right, rcTemp.top); + DrawPath(&path, pUser2Device, nullptr, color, 0, FXFILL_WINDING); +} + +void CFX_RenderDevice::DrawFillArea(CFX_Matrix* pUser2Device, + const CFX_PointF* pPts, + int32_t nCount, + const FX_COLORREF& color) { + CFX_PathData path; + path.AppendPoint(pPts[0], FXPT_TYPE::MoveTo, false); + for (int32_t i = 1; i < nCount; i++) + path.AppendPoint(pPts[i], FXPT_TYPE::LineTo, false); + + DrawPath(&path, pUser2Device, nullptr, color, 0, FXFILL_ALTERNATE); +} + +void CFX_RenderDevice::DrawStrokeRect(CFX_Matrix* pUser2Device, + const CFX_FloatRect& rect, + const FX_COLORREF& color, + float fWidth) { + CFX_PathData path; + CFX_FloatRect rcTemp(rect); + path.AppendRect(rcTemp.left, rcTemp.bottom, rcTemp.right, rcTemp.top); + + CFX_GraphStateData gsd; + gsd.m_LineWidth = fWidth; + + DrawPath(&path, pUser2Device, &gsd, 0, color, FXFILL_ALTERNATE); +} + +void CFX_RenderDevice::DrawStrokeLine(CFX_Matrix* pUser2Device, + const CFX_PointF& ptMoveTo, + const CFX_PointF& ptLineTo, + const FX_COLORREF& color, + float fWidth) { + CFX_PathData path; + path.AppendPoint(ptMoveTo, FXPT_TYPE::MoveTo, false); + path.AppendPoint(ptLineTo, FXPT_TYPE::LineTo, false); + + CFX_GraphStateData gsd; + gsd.m_LineWidth = fWidth; + + DrawPath(&path, pUser2Device, &gsd, 0, color, FXFILL_ALTERNATE); +} + +void CFX_RenderDevice::DrawFillRect(CFX_Matrix* pUser2Device, + const CFX_FloatRect& rect, + const CFX_Color& color, + int32_t nTransparency) { + DrawFillRect(pUser2Device, rect, color.ToFXColor(nTransparency)); +} + +void CFX_RenderDevice::DrawShadow(CFX_Matrix* pUser2Device, + bool bVertical, + bool bHorizontal, + CFX_FloatRect rect, + int32_t nTransparency, + int32_t nStartGray, + int32_t nEndGray) { + float fStepGray = 1.0f; + + if (bVertical) { + fStepGray = (nEndGray - nStartGray) / rect.Height(); + + for (float fy = rect.bottom + 0.5f; fy <= rect.top - 0.5f; fy += 1.0f) { + int32_t nGray = nStartGray + (int32_t)(fStepGray * (fy - rect.bottom)); + DrawStrokeLine(pUser2Device, CFX_PointF(rect.left, fy), + CFX_PointF(rect.right, fy), + ArgbEncode(nTransparency, nGray, nGray, nGray), 1.5f); + } + } + + if (bHorizontal) { + fStepGray = (nEndGray - nStartGray) / rect.Width(); + + for (float fx = rect.left + 0.5f; fx <= rect.right - 0.5f; fx += 1.0f) { + int32_t nGray = nStartGray + (int32_t)(fStepGray * (fx - rect.left)); + DrawStrokeLine(pUser2Device, CFX_PointF(fx, rect.bottom), + CFX_PointF(fx, rect.top), + ArgbEncode(nTransparency, nGray, nGray, nGray), 1.5f); + } + } +} + +void CFX_RenderDevice::DrawBorder(CFX_Matrix* pUser2Device, + const CFX_FloatRect& rect, + float fWidth, + const CFX_Color& color, + const CFX_Color& crLeftTop, + const CFX_Color& crRightBottom, + BorderStyle nStyle, + int32_t nTransparency) { + float fLeft = rect.left; + float fRight = rect.right; + float fTop = rect.top; + float fBottom = rect.bottom; + + if (fWidth > 0.0f) { + float fHalfWidth = fWidth / 2.0f; + + switch (nStyle) { + default: + case BorderStyle::SOLID: { + CFX_PathData path; + path.AppendRect(fLeft, fBottom, fRight, fTop); + path.AppendRect(fLeft + fWidth, fBottom + fWidth, fRight - fWidth, + fTop - fWidth); + DrawPath(&path, pUser2Device, nullptr, color.ToFXColor(nTransparency), + 0, FXFILL_ALTERNATE); + break; + } + case BorderStyle::DASH: { + CFX_PathData path; + path.AppendPoint( + CFX_PointF(fLeft + fWidth / 2.0f, fBottom + fWidth / 2.0f), + FXPT_TYPE::MoveTo, false); + path.AppendPoint( + CFX_PointF(fLeft + fWidth / 2.0f, fTop - fWidth / 2.0f), + FXPT_TYPE::LineTo, false); + path.AppendPoint( + CFX_PointF(fRight - fWidth / 2.0f, fTop - fWidth / 2.0f), + FXPT_TYPE::LineTo, false); + path.AppendPoint( + CFX_PointF(fRight - fWidth / 2.0f, fBottom + fWidth / 2.0f), + FXPT_TYPE::LineTo, false); + path.AppendPoint( + CFX_PointF(fLeft + fWidth / 2.0f, fBottom + fWidth / 2.0f), + FXPT_TYPE::LineTo, false); + + CFX_GraphStateData gsd; + gsd.SetDashCount(2); + gsd.m_DashArray[0] = 3.0f; + gsd.m_DashArray[1] = 3.0f; + gsd.m_DashPhase = 0; + + gsd.m_LineWidth = fWidth; + DrawPath(&path, pUser2Device, &gsd, 0, color.ToFXColor(nTransparency), + FXFILL_WINDING); + break; + } + case BorderStyle::BEVELED: + case BorderStyle::INSET: { + CFX_GraphStateData gsd; + gsd.m_LineWidth = fHalfWidth; + + CFX_PathData pathLT; + + pathLT.AppendPoint(CFX_PointF(fLeft + fHalfWidth, fBottom + fHalfWidth), + FXPT_TYPE::MoveTo, false); + pathLT.AppendPoint(CFX_PointF(fLeft + fHalfWidth, fTop - fHalfWidth), + FXPT_TYPE::LineTo, false); + pathLT.AppendPoint(CFX_PointF(fRight - fHalfWidth, fTop - fHalfWidth), + FXPT_TYPE::LineTo, false); + pathLT.AppendPoint( + CFX_PointF(fRight - fHalfWidth * 2, fTop - fHalfWidth * 2), + FXPT_TYPE::LineTo, false); + pathLT.AppendPoint( + CFX_PointF(fLeft + fHalfWidth * 2, fTop - fHalfWidth * 2), + FXPT_TYPE::LineTo, false); + pathLT.AppendPoint( + CFX_PointF(fLeft + fHalfWidth * 2, fBottom + fHalfWidth * 2), + FXPT_TYPE::LineTo, false); + pathLT.AppendPoint(CFX_PointF(fLeft + fHalfWidth, fBottom + fHalfWidth), + FXPT_TYPE::LineTo, false); + + DrawPath(&pathLT, pUser2Device, &gsd, + crLeftTop.ToFXColor(nTransparency), 0, FXFILL_ALTERNATE); + + CFX_PathData pathRB; + pathRB.AppendPoint(CFX_PointF(fRight - fHalfWidth, fTop - fHalfWidth), + FXPT_TYPE::MoveTo, false); + pathRB.AppendPoint( + CFX_PointF(fRight - fHalfWidth, fBottom + fHalfWidth), + FXPT_TYPE::LineTo, false); + pathRB.AppendPoint(CFX_PointF(fLeft + fHalfWidth, fBottom + fHalfWidth), + FXPT_TYPE::LineTo, false); + pathRB.AppendPoint( + CFX_PointF(fLeft + fHalfWidth * 2, fBottom + fHalfWidth * 2), + FXPT_TYPE::LineTo, false); + pathRB.AppendPoint( + CFX_PointF(fRight - fHalfWidth * 2, fBottom + fHalfWidth * 2), + FXPT_TYPE::LineTo, false); + pathRB.AppendPoint( + CFX_PointF(fRight - fHalfWidth * 2, fTop - fHalfWidth * 2), + FXPT_TYPE::LineTo, false); + pathRB.AppendPoint(CFX_PointF(fRight - fHalfWidth, fTop - fHalfWidth), + FXPT_TYPE::LineTo, false); + + DrawPath(&pathRB, pUser2Device, &gsd, + crRightBottom.ToFXColor(nTransparency), 0, FXFILL_ALTERNATE); + + CFX_PathData path; + + path.AppendRect(fLeft, fBottom, fRight, fTop); + path.AppendRect(fLeft + fHalfWidth, fBottom + fHalfWidth, + fRight - fHalfWidth, fTop - fHalfWidth); + + DrawPath(&path, pUser2Device, &gsd, color.ToFXColor(nTransparency), 0, + FXFILL_ALTERNATE); + break; + } + case BorderStyle::UNDERLINE: { + CFX_PathData path; + path.AppendPoint(CFX_PointF(fLeft, fBottom + fWidth / 2), + FXPT_TYPE::MoveTo, false); + path.AppendPoint(CFX_PointF(fRight, fBottom + fWidth / 2), + FXPT_TYPE::LineTo, false); + + CFX_GraphStateData gsd; + gsd.m_LineWidth = fWidth; + + DrawPath(&path, pUser2Device, &gsd, 0, color.ToFXColor(nTransparency), + FXFILL_ALTERNATE); + break; + } + } + } +} + +CFX_RenderDevice::StateRestorer::StateRestorer(CFX_RenderDevice* pDevice) + : m_pDevice(pDevice) { + m_pDevice->SaveState(); +} + +CFX_RenderDevice::StateRestorer::~StateRestorer() { + m_pDevice->RestoreState(false); +} diff --git a/chromium/third_party/pdfium/core/fxge/cfx_renderdevice.h b/chromium/third_party/pdfium/core/fxge/cfx_renderdevice.h index 4d8b407b354..ef15718d58f 100644 --- a/chromium/third_party/pdfium/core/fxge/cfx_renderdevice.h +++ b/chromium/third_party/pdfium/core/fxge/cfx_renderdevice.h @@ -9,6 +9,8 @@ #include <memory> +#include "core/fxcrt/cfx_unowned_ptr.h" +#include "core/fxge/cfx_color.h" #include "core/fxge/fx_dib.h" #include "core/fxge/fx_font.h" @@ -70,6 +72,7 @@ class FXTEXT_CHARPOS { float m_AdjustMatrix[4]; CFX_PointF m_Origin; + uint32_t m_Unicode; uint32_t m_GlyphIndex; int32_t m_FontCharWidth; #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ @@ -84,13 +87,11 @@ class CFX_RenderDevice { public: class StateRestorer { public: - explicit StateRestorer(CFX_RenderDevice* pDevice) : m_pDevice(pDevice) { - m_pDevice->SaveState(); - } - ~StateRestorer() { m_pDevice->RestoreState(false); } + explicit StateRestorer(CFX_RenderDevice* pDevice); + ~StateRestorer(); private: - CFX_RenderDevice* m_pDevice; + CFX_UnownedPtr<CFX_RenderDevice> m_pDevice; }; CFX_RenderDevice(); @@ -142,18 +143,9 @@ class CFX_RenderDevice { uint32_t stroke_color, int fill_mode, int blend_type); - bool SetPixel(int x, int y, uint32_t color); bool FillRect(const FX_RECT* pRect, uint32_t color) { return FillRectWithBlend(pRect, color, FXDIB_BLEND_NORMAL); } - bool FillRectWithBlend(const FX_RECT* pRect, uint32_t color, int blend_type); - bool DrawCosmeticLine(float x1, - float y1, - float x2, - float y2, - uint32_t color, - int fill_mode, - int blend_type); CFX_RetainPtr<CFX_DIBitmap> GetBackDrop(); bool GetDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, int left, int top); @@ -236,6 +228,42 @@ class CFX_RenderDevice { CFX_PathData* pClippingPath, int nFlag); + void DrawFillRect(CFX_Matrix* pUser2Device, + const CFX_FloatRect& rect, + const CFX_Color& color, + int32_t nTransparency); + void DrawFillRect(CFX_Matrix* pUser2Device, + const CFX_FloatRect& rect, + const FX_COLORREF& color); + void DrawStrokeRect(CFX_Matrix* pUser2Device, + const CFX_FloatRect& rect, + const FX_COLORREF& color, + float fWidth); + void DrawStrokeLine(CFX_Matrix* pUser2Device, + const CFX_PointF& ptMoveTo, + const CFX_PointF& ptLineTo, + const FX_COLORREF& color, + float fWidth); + void DrawBorder(CFX_Matrix* pUser2Device, + const CFX_FloatRect& rect, + float fWidth, + const CFX_Color& color, + const CFX_Color& crLeftTop, + const CFX_Color& crRightBottom, + BorderStyle nStyle, + int32_t nTransparency); + void DrawFillArea(CFX_Matrix* pUser2Device, + const CFX_PointF* pPts, + int32_t nCount, + const FX_COLORREF& color); + void DrawShadow(CFX_Matrix* pUser2Device, + bool bVertical, + bool bHorizontal, + CFX_FloatRect rect, + int32_t nTransparency, + int32_t nStartGray, + int32_t nEndGray); + #ifdef _SKIA_SUPPORT_ virtual void DebugVerifyBitmapIsPreMultiplied() const; virtual bool SetBitsWithMask(const CFX_RetainPtr<CFX_DIBSource>& pBitmap, @@ -259,6 +287,14 @@ class CFX_RenderDevice { uint32_t stroke_color, int fill_mode, int blend_type); + bool DrawCosmeticLine(float x1, + float y1, + float x2, + float y2, + uint32_t color, + int fill_mode, + int blend_type); + bool FillRectWithBlend(const FX_RECT* pRect, uint32_t color, int blend_type); CFX_RetainPtr<CFX_DIBitmap> m_pBitmap; int m_Width; diff --git a/chromium/third_party/pdfium/core/fxge/ge/cfx_substfont.cpp b/chromium/third_party/pdfium/core/fxge/cfx_substfont.cpp index 27d3bc3059d..27d3bc3059d 100644 --- a/chromium/third_party/pdfium/core/fxge/ge/cfx_substfont.cpp +++ b/chromium/third_party/pdfium/core/fxge/cfx_substfont.cpp diff --git a/chromium/third_party/pdfium/core/fxge/ge/cfx_unicodeencoding.cpp b/chromium/third_party/pdfium/core/fxge/cfx_unicodeencoding.cpp index 494ae33bb0d..494ae33bb0d 100644 --- a/chromium/third_party/pdfium/core/fxge/ge/cfx_unicodeencoding.cpp +++ b/chromium/third_party/pdfium/core/fxge/cfx_unicodeencoding.cpp diff --git a/chromium/third_party/pdfium/core/fxge/ge/cfx_unicodeencodingex.cpp b/chromium/third_party/pdfium/core/fxge/cfx_unicodeencodingex.cpp index 3f28d4295e8..3f28d4295e8 100644 --- a/chromium/third_party/pdfium/core/fxge/ge/cfx_unicodeencodingex.cpp +++ b/chromium/third_party/pdfium/core/fxge/cfx_unicodeencodingex.cpp diff --git a/chromium/third_party/pdfium/core/fxge/cfx_windowsrenderdevice.h b/chromium/third_party/pdfium/core/fxge/cfx_windowsrenderdevice.h index 7156dcdc4e2..f1e0cbdb7a3 100644 --- a/chromium/third_party/pdfium/core/fxge/cfx_windowsrenderdevice.h +++ b/chromium/third_party/pdfium/core/fxge/cfx_windowsrenderdevice.h @@ -14,6 +14,13 @@ #include "core/fxge/cfx_renderdevice.h" +enum WindowsPrintMode { + kModeEmf = 0, + kModeTextOnly = 1, + kModePostScript2 = 2, + kModePostScript3 = 3, +}; + class IFX_RenderDeviceDriver; #if defined(PDFIUM_PRINT_TEXT_WITH_GDI) @@ -25,7 +32,7 @@ extern bool g_pdfium_print_text_with_gdi; extern PDFiumEnsureTypefaceCharactersAccessible g_pdfium_typeface_accessible_func; #endif -extern int g_pdfium_print_postscript_level; +extern int g_pdfium_print_mode; class CFX_WindowsRenderDevice : public CFX_RenderDevice { public: diff --git a/chromium/third_party/pdfium/core/fxge/ge/cttfontdesc.cpp b/chromium/third_party/pdfium/core/fxge/cttfontdesc.cpp index f75039567f3..cf900a8b956 100644 --- a/chromium/third_party/pdfium/core/fxge/ge/cttfontdesc.cpp +++ b/chromium/third_party/pdfium/core/fxge/cttfontdesc.cpp @@ -4,7 +4,7 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "core/fxge/ge/cttfontdesc.h" +#include "core/fxge/cttfontdesc.h" #include "core/fxge/fx_freetype.h" diff --git a/chromium/third_party/pdfium/core/fxge/ge/cttfontdesc.h b/chromium/third_party/pdfium/core/fxge/cttfontdesc.h index d756cb947a2..6eb36360c04 100644 --- a/chromium/third_party/pdfium/core/fxge/ge/cttfontdesc.h +++ b/chromium/third_party/pdfium/core/fxge/cttfontdesc.h @@ -4,8 +4,8 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef CORE_FXGE_GE_CTTFONTDESC_H_ -#define CORE_FXGE_GE_CTTFONTDESC_H_ +#ifndef CORE_FXGE_CTTFONTDESC_H_ +#define CORE_FXGE_CTTFONTDESC_H_ #include "core/fxcrt/fx_system.h" #include "core/fxge/fx_font.h" @@ -37,4 +37,4 @@ class CTTFontDesc { int m_RefCount; }; -#endif // CORE_FXGE_GE_CTTFONTDESC_H_ +#endif // CORE_FXGE_CTTFONTDESC_H_ diff --git a/chromium/third_party/pdfium/core/fxge/dib/cfx_bitmapcomposer.cpp b/chromium/third_party/pdfium/core/fxge/dib/cfx_bitmapcomposer.cpp index 3f75fae1b60..86646066457 100644 --- a/chromium/third_party/pdfium/core/fxge/dib/cfx_bitmapcomposer.cpp +++ b/chromium/third_party/pdfium/core/fxge/dib/cfx_bitmapcomposer.cpp @@ -7,8 +7,8 @@ #include "core/fxge/dib/cfx_bitmapcomposer.h" #include "core/fxcodec/fx_codec.h" +#include "core/fxge/cfx_cliprgn.h" #include "core/fxge/dib/cfx_dibitmap.h" -#include "core/fxge/ge/cfx_cliprgn.h" CFX_BitmapComposer::CFX_BitmapComposer() : m_bRgbByteOrder(false), m_BlendType(FXDIB_BLEND_NORMAL) {} diff --git a/chromium/third_party/pdfium/core/fxge/dib/cfx_bitmapcomposer.h b/chromium/third_party/pdfium/core/fxge/dib/cfx_bitmapcomposer.h index 6e961cbd457..cc4ecb13fea 100644 --- a/chromium/third_party/pdfium/core/fxge/dib/cfx_bitmapcomposer.h +++ b/chromium/third_party/pdfium/core/fxge/dib/cfx_bitmapcomposer.h @@ -10,6 +10,7 @@ #include <vector> #include "core/fxcrt/cfx_retain_ptr.h" +#include "core/fxcrt/cfx_unowned_ptr.h" #include "core/fxcrt/fx_coordinates.h" #include "core/fxge/dib/cfx_scanlinecompositor.h" #include "core/fxge/dib/ifx_scanlinecomposer.h" @@ -56,7 +57,7 @@ class CFX_BitmapComposer : public IFX_ScanlineComposer { const uint8_t* scan_extra_alpha); CFX_RetainPtr<CFX_DIBitmap> m_pBitmap; - const CFX_ClipRgn* m_pClipRgn; + CFX_UnownedPtr<const CFX_ClipRgn> m_pClipRgn; FXDIB_Format m_SrcFormat; int m_DestLeft; int m_DestTop; diff --git a/chromium/third_party/pdfium/core/fxge/dib/cfx_dibitmap.cpp b/chromium/third_party/pdfium/core/fxge/dib/cfx_dibitmap.cpp index 48cbc3291c9..fd6defece21 100644 --- a/chromium/third_party/pdfium/core/fxge/dib/cfx_dibitmap.cpp +++ b/chromium/third_party/pdfium/core/fxge/dib/cfx_dibitmap.cpp @@ -11,8 +11,8 @@ #include <utility> #include "core/fxcodec/fx_codec.h" +#include "core/fxge/cfx_cliprgn.h" #include "core/fxge/dib/cfx_scanlinecompositor.h" -#include "core/fxge/ge/cfx_cliprgn.h" #include "third_party/base/ptr_util.h" #define MAX_OOM_LIMIT 12000000 @@ -34,36 +34,32 @@ bool CFX_DIBitmap::Create(int width, int height, FXDIB_Format format, uint8_t* pBuffer, - int pitch) { + uint32_t pitch) { m_pBuffer = nullptr; m_bpp = static_cast<uint8_t>(format); m_AlphaFlag = static_cast<uint8_t>(format >> 8); - m_Width = m_Height = m_Pitch = 0; - if (width <= 0 || height <= 0 || pitch < 0) - return false; - - if ((INT_MAX - 31) / width < (format & 0xff)) - return false; - - if (!pitch) - pitch = (width * (format & 0xff) + 31) / 32 * 4; + m_Width = 0; + m_Height = 0; + m_Pitch = 0; - if ((1 << 30) / pitch < height) + uint32_t calculatedSize; + if (!CFX_DIBitmap::CalculatePitchAndSize(height, width, format, &pitch, + &calculatedSize)) return false; if (pBuffer) { m_pBuffer.Reset(pBuffer); } else { - int size = pitch * height + 4; - int oomlimit = MAX_OOM_LIMIT; - if (oomlimit >= 0 && size >= oomlimit) { - m_pBuffer = - std::unique_ptr<uint8_t, FxFreeDeleter>(FX_TryAlloc(uint8_t, size)); + size_t bufferSize = calculatedSize + 4; + size_t oomlimit = MAX_OOM_LIMIT; + if (bufferSize >= oomlimit) { + m_pBuffer = std::unique_ptr<uint8_t, FxFreeDeleter>( + FX_TryAlloc(uint8_t, bufferSize)); if (!m_pBuffer) return false; } else { - m_pBuffer = - std::unique_ptr<uint8_t, FxFreeDeleter>(FX_Alloc(uint8_t, size)); + m_pBuffer = std::unique_ptr<uint8_t, FxFreeDeleter>( + FX_Alloc(uint8_t, bufferSize)); } } m_Width = width; @@ -759,10 +755,11 @@ void CFX_DIBitmap::ConvertCMYKColorScale(uint32_t forecolor, uint8_t r; uint8_t g; uint8_t b; - AdobeCMYK_to_sRGB1(FXSYS_GetCValue(m_pPalette.get()[i]), - FXSYS_GetMValue(m_pPalette.get()[i]), - FXSYS_GetYValue(m_pPalette.get()[i]), - FXSYS_GetKValue(m_pPalette.get()[i]), r, g, b); + std::tie(r, g, b) = + AdobeCMYK_to_sRGB1(FXSYS_GetCValue(m_pPalette.get()[i]), + FXSYS_GetMValue(m_pPalette.get()[i]), + FXSYS_GetYValue(m_pPalette.get()[i]), + FXSYS_GetKValue(m_pPalette.get()[i])); int gray = 255 - FXRGB2GRAY(r, g, b); m_pPalette.get()[i] = CmykEncode(bc + (fc - bc) * gray / 255, bm + (fm - bm) * gray / 255, @@ -777,8 +774,8 @@ void CFX_DIBitmap::ConvertCMYKColorScale(uint32_t forecolor, uint8_t r; uint8_t g; uint8_t b; - AdobeCMYK_to_sRGB1(scanline[0], scanline[1], scanline[2], scanline[3], - r, g, b); + std::tie(r, g, b) = AdobeCMYK_to_sRGB1(scanline[0], scanline[1], + scanline[2], scanline[3]); *scanline++ = 0; *scanline++ = 0; *scanline++ = 0; @@ -793,8 +790,8 @@ void CFX_DIBitmap::ConvertCMYKColorScale(uint32_t forecolor, uint8_t r; uint8_t g; uint8_t b; - AdobeCMYK_to_sRGB1(scanline[0], scanline[1], scanline[2], scanline[3], r, - g, b); + std::tie(r, g, b) = AdobeCMYK_to_sRGB1(scanline[0], scanline[1], + scanline[2], scanline[3]); int gray = 255 - FXRGB2GRAY(r, g, b); *scanline++ = bc + (fc - bc) * gray / 255; *scanline++ = bm + (fm - bm) * gray / 255; @@ -816,6 +813,27 @@ bool CFX_DIBitmap::ConvertColorScale(uint32_t forecolor, uint32_t backcolor) { return true; } +bool CFX_DIBitmap::CalculatePitchAndSize(int height, + int width, + FXDIB_Format format, + uint32_t* pitch, + uint32_t* size) { + if (width <= 0 || height <= 0) + return false; + + if ((INT_MAX - 31) / width < (format & 0xFF)) + return false; + + if (!*pitch) + *pitch = static_cast<uint32_t>((width * (format & 0xff) + 31) / 32 * 4); + + if ((1 << 30) / *pitch < static_cast<uint32_t>(height)) + return false; + + *size = *pitch * static_cast<uint32_t>(height); + return true; +} + bool CFX_DIBitmap::CompositeBitmap( int dest_left, int dest_top, @@ -990,8 +1008,8 @@ bool CFX_DIBitmap::CompositeRect(int left, uint8_t r; uint8_t g; uint8_t b; - AdobeCMYK_to_sRGB1(color_p[0], color_p[1], color_p[2], color_p[3], r, g, - b); + std::tie(r, g, b) = + AdobeCMYK_to_sRGB1(color_p[0], color_p[1], color_p[2], color_p[3]); gray = FXRGB2GRAY(r, g, b); } else { gray = (uint8_t)FXRGB2GRAY((int)color_p[2], color_p[1], color_p[0]); @@ -1057,9 +1075,9 @@ bool CFX_DIBitmap::CompositeRect(int left, if (m_bpp < 24 || (!(alpha_flag >> 8) && IsCmykImage())) return false; if (alpha_flag >> 8 && !IsCmykImage()) { - AdobeCMYK_to_sRGB1(FXSYS_GetCValue(color), FXSYS_GetMValue(color), - FXSYS_GetYValue(color), FXSYS_GetKValue(color), - color_p[2], color_p[1], color_p[0]); + std::tie(color_p[2], color_p[1], color_p[0]) = + AdobeCMYK_to_sRGB1(FXSYS_GetCValue(color), FXSYS_GetMValue(color), + FXSYS_GetYValue(color), FXSYS_GetKValue(color)); } if (!IsCmykImage()) color_p[3] = static_cast<uint8_t>(src_alpha); diff --git a/chromium/third_party/pdfium/core/fxge/dib/cfx_dibitmap.h b/chromium/third_party/pdfium/core/fxge/dib/cfx_dibitmap.h index df751db3df3..2b5555befc3 100644 --- a/chromium/third_party/pdfium/core/fxge/dib/cfx_dibitmap.h +++ b/chromium/third_party/pdfium/core/fxge/dib/cfx_dibitmap.h @@ -25,7 +25,7 @@ class CFX_DIBitmap : public CFX_DIBSource { int height, FXDIB_Format format, uint8_t* pBuffer = nullptr, - int pitch = 0); + uint32_t pitch = 0); bool Copy(const CFX_RetainPtr<CFX_DIBSource>& pSrc); @@ -96,6 +96,12 @@ class CFX_DIBitmap : public CFX_DIBSource { bool ConvertColorScale(uint32_t forecolor, uint32_t backcolor); + static bool CalculatePitchAndSize(int height, + int width, + FXDIB_Format format, + uint32_t* pitch, + uint32_t* size); + #if defined _SKIA_SUPPORT_ || _SKIA_SUPPORT_PATHS_ void PreMultiply(); #endif diff --git a/chromium/third_party/pdfium/core/fxge/dib/cfx_dibsource.cpp b/chromium/third_party/pdfium/core/fxge/dib/cfx_dibsource.cpp index deb8e15f49d..a0ed95055ba 100644 --- a/chromium/third_party/pdfium/core/fxge/dib/cfx_dibsource.cpp +++ b/chromium/third_party/pdfium/core/fxge/dib/cfx_dibsource.cpp @@ -12,11 +12,11 @@ #include <vector> #include "core/fxcodec/fx_codec.h" +#include "core/fxge/cfx_cliprgn.h" #include "core/fxge/dib/cfx_bitmapstorer.h" #include "core/fxge/dib/cfx_dibitmap.h" #include "core/fxge/dib/cfx_imagestretcher.h" #include "core/fxge/dib/cfx_imagetransformer.h" -#include "core/fxge/ge/cfx_cliprgn.h" #include "third_party/base/logging.h" #include "third_party/base/ptr_util.h" @@ -153,12 +153,12 @@ bool ConvertBuffer_1bppPlt2Gray(uint8_t* dest_buf, uint8_t set_g; uint8_t set_b; if (pSrcBitmap->IsCmykImage()) { - AdobeCMYK_to_sRGB1(FXSYS_GetCValue(src_plt[0]), FXSYS_GetMValue(src_plt[0]), - FXSYS_GetYValue(src_plt[0]), FXSYS_GetKValue(src_plt[0]), - reset_r, reset_g, reset_b); - AdobeCMYK_to_sRGB1(FXSYS_GetCValue(src_plt[1]), FXSYS_GetMValue(src_plt[1]), - FXSYS_GetYValue(src_plt[1]), FXSYS_GetKValue(src_plt[1]), - set_r, set_g, set_b); + std::tie(reset_r, reset_g, reset_b) = AdobeCMYK_to_sRGB1( + FXSYS_GetCValue(src_plt[0]), FXSYS_GetMValue(src_plt[0]), + FXSYS_GetYValue(src_plt[0]), FXSYS_GetKValue(src_plt[0])); + std::tie(set_r, set_g, set_b) = AdobeCMYK_to_sRGB1( + FXSYS_GetCValue(src_plt[1]), FXSYS_GetMValue(src_plt[1]), + FXSYS_GetYValue(src_plt[1]), FXSYS_GetKValue(src_plt[1])); } else { reset_r = FXARGB_R(src_plt[0]); reset_g = FXARGB_G(src_plt[0]); @@ -198,9 +198,9 @@ bool ConvertBuffer_8bppPlt2Gray(uint8_t* dest_buf, uint8_t g; uint8_t b; for (size_t i = 0; i < FX_ArraySize(gray); i++) { - AdobeCMYK_to_sRGB1( + std::tie(r, g, b) = AdobeCMYK_to_sRGB1( FXSYS_GetCValue(src_plt[i]), FXSYS_GetMValue(src_plt[i]), - FXSYS_GetYValue(src_plt[i]), FXSYS_GetKValue(src_plt[i]), r, g, b); + FXSYS_GetYValue(src_plt[i]), FXSYS_GetKValue(src_plt[i])); gray[i] = FXRGB2GRAY(r, g, b); } } else { @@ -235,12 +235,14 @@ bool ConvertBuffer_RgbOrCmyk2Gray( const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left * 4; for (int col = 0; col < width; col++) { - uint8_t r, g, b; - AdobeCMYK_to_sRGB1(FXSYS_GetCValue(static_cast<uint32_t>(src_scan[0])), - FXSYS_GetMValue(static_cast<uint32_t>(src_scan[1])), - FXSYS_GetYValue(static_cast<uint32_t>(src_scan[2])), - FXSYS_GetKValue(static_cast<uint32_t>(src_scan[3])), - r, g, b); + uint8_t r; + uint8_t g; + uint8_t b; + std::tie(r, g, b) = AdobeCMYK_to_sRGB1( + FXSYS_GetCValue(static_cast<uint32_t>(src_scan[0])), + FXSYS_GetMValue(static_cast<uint32_t>(src_scan[1])), + FXSYS_GetYValue(static_cast<uint32_t>(src_scan[2])), + FXSYS_GetKValue(static_cast<uint32_t>(src_scan[3]))); *dest_scan++ = FXRGB2GRAY(r, g, b); src_scan += 4; } @@ -305,9 +307,9 @@ bool ConvertBuffer_Plt2PltRgb8(uint8_t* dest_buf, uint8_t r; uint8_t g; uint8_t b; - AdobeCMYK_to_sRGB1( + std::tie(r, g, b) = AdobeCMYK_to_sRGB1( FXSYS_GetCValue(src_plt[i]), FXSYS_GetMValue(src_plt[i]), - FXSYS_GetYValue(src_plt[i]), FXSYS_GetKValue(src_plt[i]), r, g, b); + FXSYS_GetYValue(src_plt[i]), FXSYS_GetKValue(src_plt[i])); dst_plt[i] = FXARGB_MAKE(0xff, r, g, b); } } else { @@ -458,12 +460,12 @@ bool ConvertBuffer_1bppPlt2Rgb(FXDIB_Format dst_format, } if (pSrcBitmap->IsCmykImage()) { - AdobeCMYK_to_sRGB1(FXSYS_GetCValue(src_plt[0]), FXSYS_GetMValue(src_plt[0]), - FXSYS_GetYValue(src_plt[0]), FXSYS_GetKValue(src_plt[0]), - bgr_ptr[2], bgr_ptr[1], bgr_ptr[0]); - AdobeCMYK_to_sRGB1(FXSYS_GetCValue(src_plt[1]), FXSYS_GetMValue(src_plt[1]), - FXSYS_GetYValue(src_plt[1]), FXSYS_GetKValue(src_plt[1]), - bgr_ptr[5], bgr_ptr[4], bgr_ptr[3]); + std::tie(bgr_ptr[2], bgr_ptr[1], bgr_ptr[0]) = AdobeCMYK_to_sRGB1( + FXSYS_GetCValue(src_plt[0]), FXSYS_GetMValue(src_plt[0]), + FXSYS_GetYValue(src_plt[0]), FXSYS_GetKValue(src_plt[0])); + std::tie(bgr_ptr[5], bgr_ptr[4], bgr_ptr[3]) = AdobeCMYK_to_sRGB1( + FXSYS_GetCValue(src_plt[1]), FXSYS_GetMValue(src_plt[1]), + FXSYS_GetYValue(src_plt[1]), FXSYS_GetKValue(src_plt[1])); } for (int row = 0; row < height; row++) { @@ -508,10 +510,9 @@ bool ConvertBuffer_8bppPlt2Rgb(FXDIB_Format dst_format, if (pSrcBitmap->IsCmykImage()) { for (int i = 0; i < 256; i++) { - AdobeCMYK_to_sRGB1( + std::tie(bgr_ptr[2], bgr_ptr[1], bgr_ptr[0]) = AdobeCMYK_to_sRGB1( FXSYS_GetCValue(src_plt[i]), FXSYS_GetMValue(src_plt[i]), - FXSYS_GetYValue(src_plt[i]), FXSYS_GetKValue(src_plt[i]), bgr_ptr[2], - bgr_ptr[1], bgr_ptr[0]); + FXSYS_GetYValue(src_plt[i]), FXSYS_GetKValue(src_plt[i])); bgr_ptr += 3; } bgr_ptr = reinterpret_cast<uint8_t*>(plt); @@ -606,8 +607,8 @@ bool ConvertBuffer_32bppCmyk2Rgb32( const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left * 4; for (int col = 0; col < width; col++) { - AdobeCMYK_to_sRGB1(src_scan[0], src_scan[1], src_scan[2], src_scan[3], - dest_scan[2], dest_scan[1], dest_scan[0]); + std::tie(dest_scan[2], dest_scan[1], dest_scan[0]) = AdobeCMYK_to_sRGB1( + src_scan[0], src_scan[1], src_scan[2], src_scan[3]); dest_scan += 4; src_scan += 4; } @@ -1089,7 +1090,6 @@ CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::TransformTo( int* result_top) { CFX_RetainPtr<CFX_DIBSource> holder(this); CFX_ImageTransformer transformer(holder, pDestMatrix, 0, nullptr); - transformer.Start(); transformer.Continue(nullptr); *result_left = transformer.result().left; *result_top = transformer.result().top; diff --git a/chromium/third_party/pdfium/core/fxge/dib/cfx_imagerenderer.cpp b/chromium/third_party/pdfium/core/fxge/dib/cfx_imagerenderer.cpp index cff95fdd700..6448014ba51 100644 --- a/chromium/third_party/pdfium/core/fxge/dib/cfx_imagerenderer.cpp +++ b/chromium/third_party/pdfium/core/fxge/dib/cfx_imagerenderer.cpp @@ -8,44 +8,35 @@ #include <memory> +#include "core/fxge/cfx_cliprgn.h" #include "core/fxge/dib/cfx_imagestretcher.h" #include "core/fxge/dib/cfx_imagetransformer.h" -#include "core/fxge/ge/cfx_cliprgn.h" #include "third_party/base/ptr_util.h" -CFX_ImageRenderer::CFX_ImageRenderer() - : m_Status(0), - m_bRgbByteOrder(false), - m_BlendType(FXDIB_BLEND_NORMAL) {} - -CFX_ImageRenderer::~CFX_ImageRenderer() {} - -bool CFX_ImageRenderer::Start(const CFX_RetainPtr<CFX_DIBitmap>& pDevice, - const CFX_ClipRgn* pClipRgn, - const CFX_RetainPtr<CFX_DIBSource>& pSource, - int bitmap_alpha, - uint32_t mask_color, - const CFX_Matrix* pMatrix, - uint32_t dib_flags, - bool bRgbByteOrder) { - m_Matrix = *pMatrix; - CFX_FloatRect image_rect_f = m_Matrix.GetUnitRect(); - FX_RECT image_rect = image_rect_f.GetOuterRect(); +CFX_ImageRenderer::CFX_ImageRenderer( + const CFX_RetainPtr<CFX_DIBitmap>& pDevice, + const CFX_ClipRgn* pClipRgn, + const CFX_RetainPtr<CFX_DIBSource>& pSource, + int bitmap_alpha, + uint32_t mask_color, + const CFX_Matrix* pMatrix, + uint32_t dib_flags, + bool bRgbByteOrder) + : m_pDevice(pDevice), + m_pClipRgn(pClipRgn), + m_Matrix(*pMatrix), + m_BitmapAlpha(bitmap_alpha), + m_BlendType(FXDIB_BLEND_NORMAL), + m_bRgbByteOrder(bRgbByteOrder), + m_MaskColor(mask_color), + m_Status(0), + m_AlphaFlag(0) { + FX_RECT image_rect = m_Matrix.GetUnitRect().GetOuterRect(); m_ClipBox = pClipRgn ? pClipRgn->GetBox() : FX_RECT(0, 0, pDevice->GetWidth(), pDevice->GetHeight()); m_ClipBox.Intersect(image_rect); if (m_ClipBox.IsEmpty()) - return false; - - m_pDevice = pDevice; - m_pClipRgn = pClipRgn; - m_MaskColor = mask_color; - m_BitmapAlpha = bitmap_alpha; - m_Matrix = *pMatrix; - m_Flags = dib_flags; - m_AlphaFlag = 0; - m_bRgbByteOrder = bRgbByteOrder; - m_BlendType = FXDIB_BLEND_NORMAL; + return; if ((fabs(m_Matrix.b) >= 0.5f || m_Matrix.a == 0) || (fabs(m_Matrix.c) >= 0.5f || m_Matrix.d == 0)) { @@ -64,17 +55,14 @@ bool CFX_ImageRenderer::Start(const CFX_RetainPtr<CFX_DIBitmap>& pDevice, m_Stretcher = pdfium::MakeUnique<CFX_ImageStretcher>( &m_Composer, pSource, dest_height, dest_width, bitmap_clip, dib_flags); - if (!m_Stretcher->Start()) - return false; - - m_Status = 1; - return true; + if (m_Stretcher->Start()) + m_Status = 1; + return; } m_Status = 2; m_pTransformer = pdfium::MakeUnique<CFX_ImageTransformer>( pSource, &m_Matrix, dib_flags, &m_ClipBox); - m_pTransformer->Start(); - return true; + return; } int dest_width = image_rect.Width(); @@ -86,7 +74,7 @@ bool CFX_ImageRenderer::Start(const CFX_RetainPtr<CFX_DIBitmap>& pDevice, dest_height = -dest_height; if (dest_width == 0 || dest_height == 0) - return false; + return; FX_RECT bitmap_clip = m_ClipBox; bitmap_clip.Offset(-image_rect.left, -image_rect.top); @@ -95,9 +83,11 @@ bool CFX_ImageRenderer::Start(const CFX_RetainPtr<CFX_DIBitmap>& pDevice, m_Status = 1; m_Stretcher = pdfium::MakeUnique<CFX_ImageStretcher>( &m_Composer, pSource, dest_width, dest_height, bitmap_clip, dib_flags); - return m_Stretcher->Start(); + m_Stretcher->Start(); } +CFX_ImageRenderer::~CFX_ImageRenderer() {} + bool CFX_ImageRenderer::Continue(IFX_Pause* pPause) { if (m_Status == 1) return m_Stretcher->Continue(pPause); @@ -122,14 +112,14 @@ bool CFX_ImageRenderer::Continue(IFX_Pause* pPause) { m_pDevice->CompositeMask( m_pTransformer->result().left, m_pTransformer->result().top, pBitmap->GetWidth(), pBitmap->GetHeight(), pBitmap, m_MaskColor, 0, 0, - m_BlendType, m_pClipRgn, m_bRgbByteOrder, m_AlphaFlag); + m_BlendType, m_pClipRgn.Get(), m_bRgbByteOrder, m_AlphaFlag); } else { if (m_BitmapAlpha != 255) pBitmap->MultiplyAlpha(m_BitmapAlpha); m_pDevice->CompositeBitmap( m_pTransformer->result().left, m_pTransformer->result().top, pBitmap->GetWidth(), pBitmap->GetHeight(), pBitmap, 0, 0, m_BlendType, - m_pClipRgn, m_bRgbByteOrder); + m_pClipRgn.Get(), m_bRgbByteOrder); } return false; } diff --git a/chromium/third_party/pdfium/core/fxge/dib/cfx_imagerenderer.h b/chromium/third_party/pdfium/core/fxge/dib/cfx_imagerenderer.h index f3d1286dc62..97427ceb917 100644 --- a/chromium/third_party/pdfium/core/fxge/dib/cfx_imagerenderer.h +++ b/chromium/third_party/pdfium/core/fxge/dib/cfx_imagerenderer.h @@ -10,6 +10,7 @@ #include <memory> #include "core/fxcrt/cfx_retain_ptr.h" +#include "core/fxcrt/cfx_unowned_ptr.h" #include "core/fxcrt/fx_coordinates.h" #include "core/fxge/dib/cfx_bitmapcomposer.h" #include "core/fxge/dib/cfx_dibitmap.h" @@ -22,35 +23,32 @@ class CFX_ImageStretcher; class CFX_ImageRenderer { public: - CFX_ImageRenderer(); + CFX_ImageRenderer(const CFX_RetainPtr<CFX_DIBitmap>& pDevice, + const CFX_ClipRgn* pClipRgn, + const CFX_RetainPtr<CFX_DIBSource>& pSource, + int bitmap_alpha, + uint32_t mask_color, + const CFX_Matrix* pMatrix, + uint32_t dib_flags, + bool bRgbByteOrder); ~CFX_ImageRenderer(); - bool Start(const CFX_RetainPtr<CFX_DIBitmap>& pDevice, - const CFX_ClipRgn* pClipRgn, - const CFX_RetainPtr<CFX_DIBSource>& pSource, - int bitmap_alpha, - uint32_t mask_color, - const CFX_Matrix* pMatrix, - uint32_t dib_flags, - bool bRgbByteOrder); - bool Continue(IFX_Pause* pPause); private: - CFX_RetainPtr<CFX_DIBitmap> m_pDevice; - const CFX_ClipRgn* m_pClipRgn; - int m_BitmapAlpha; + const CFX_RetainPtr<CFX_DIBitmap> m_pDevice; + const CFX_UnownedPtr<const CFX_ClipRgn> m_pClipRgn; + const CFX_Matrix m_Matrix; + const int m_BitmapAlpha; + const int m_BlendType; + const bool m_bRgbByteOrder; uint32_t m_MaskColor; - CFX_Matrix m_Matrix; std::unique_ptr<CFX_ImageTransformer> m_pTransformer; std::unique_ptr<CFX_ImageStretcher> m_Stretcher; CFX_BitmapComposer m_Composer; int m_Status; FX_RECT m_ClipBox; - uint32_t m_Flags; int m_AlphaFlag; - bool m_bRgbByteOrder; - int m_BlendType; }; #endif // CORE_FXGE_DIB_CFX_IMAGERENDERER_H_ diff --git a/chromium/third_party/pdfium/core/fxge/dib/cfx_imagetransformer.cpp b/chromium/third_party/pdfium/core/fxge/dib/cfx_imagetransformer.cpp index 6174a51c293..7a097ced123 100644 --- a/chromium/third_party/pdfium/core/fxge/dib/cfx_imagetransformer.cpp +++ b/chromium/third_party/pdfium/core/fxge/dib/cfx_imagetransformer.cpp @@ -186,19 +186,14 @@ CFX_ImageTransformer::CFX_ImageTransformer( m_pMatrix(pMatrix), m_pClip(pClip), m_Flags(flags), - m_Status(0) {} - -CFX_ImageTransformer::~CFX_ImageTransformer() {} - -bool CFX_ImageTransformer::Start() { - CFX_FloatRect unit_rect = m_pMatrix->GetUnitRect(); - FX_RECT result_rect = unit_rect.GetClosestRect(); + m_Status(0) { + FX_RECT result_rect = m_pMatrix->GetUnitRect().GetClosestRect(); FX_RECT result_clip = result_rect; if (m_pClip) result_clip.Intersect(*m_pClip); if (result_clip.IsEmpty()) - return false; + return; m_result = result_clip; if (fabs(m_pMatrix->a) < fabs(m_pMatrix->b) / 20 && @@ -213,29 +208,30 @@ bool CFX_ImageTransformer::Start() { &m_Storer, m_pSrc, dest_height, dest_width, result_clip, m_Flags); m_Stretcher->Start(); m_Status = 1; - return true; + return; } if (fabs(m_pMatrix->b) < FIX16_005 && fabs(m_pMatrix->c) < FIX16_005) { - int dest_width = - m_pMatrix->a > 0 ? (int)ceil(m_pMatrix->a) : (int)floor(m_pMatrix->a); - int dest_height = - m_pMatrix->d > 0 ? (int)-ceil(m_pMatrix->d) : (int)-floor(m_pMatrix->d); + int dest_width = static_cast<int>(m_pMatrix->a > 0 ? ceil(m_pMatrix->a) + : floor(m_pMatrix->a)); + int dest_height = static_cast<int>(m_pMatrix->d > 0 ? -ceil(m_pMatrix->d) + : -floor(m_pMatrix->d)); result_clip.Offset(-result_rect.left, -result_rect.top); m_Stretcher = pdfium::MakeUnique<CFX_ImageStretcher>( &m_Storer, m_pSrc, dest_width, dest_height, result_clip, m_Flags); m_Stretcher->Start(); m_Status = 2; - return true; + return; } - int stretch_width = (int)ceil(FXSYS_sqrt2(m_pMatrix->a, m_pMatrix->b)); - int stretch_height = (int)ceil(FXSYS_sqrt2(m_pMatrix->c, m_pMatrix->d)); - CFX_Matrix stretch2dest(1.0f, 0.0f, 0.0f, -1.0f, 0.0f, - (float)(stretch_height)); + int stretch_width = + static_cast<int>(ceil(FXSYS_sqrt2(m_pMatrix->a, m_pMatrix->b))); + int stretch_height = + static_cast<int>(ceil(FXSYS_sqrt2(m_pMatrix->c, m_pMatrix->d))); + CFX_Matrix stretch2dest(1.0f, 0.0f, 0.0f, -1.0f, 0.0f, stretch_height); stretch2dest.Concat( CFX_Matrix(m_pMatrix->a / stretch_width, m_pMatrix->b / stretch_width, m_pMatrix->c / stretch_height, m_pMatrix->d / stretch_height, m_pMatrix->e, m_pMatrix->f)); - m_dest2stretch.SetReverse(stretch2dest); + m_dest2stretch = stretch2dest.GetInverse(); CFX_FloatRect clip_rect_f(result_clip); m_dest2stretch.TransformRect(clip_rect_f); @@ -245,9 +241,10 @@ bool CFX_ImageTransformer::Start() { &m_Storer, m_pSrc, stretch_width, stretch_height, m_StretchClip, m_Flags); m_Stretcher->Start(); m_Status = 3; - return true; } +CFX_ImageTransformer::~CFX_ImageTransformer() {} + bool CFX_ImageTransformer::Continue(IFX_Pause* pPause) { if (m_Status == 1) { if (m_Stretcher->Continue(pPause)) diff --git a/chromium/third_party/pdfium/core/fxge/dib/cfx_imagetransformer.h b/chromium/third_party/pdfium/core/fxge/dib/cfx_imagetransformer.h index 90f605dce99..60e4714a65f 100644 --- a/chromium/third_party/pdfium/core/fxge/dib/cfx_imagetransformer.h +++ b/chromium/third_party/pdfium/core/fxge/dib/cfx_imagetransformer.h @@ -25,7 +25,6 @@ class CFX_ImageTransformer { const FX_RECT* pClip); ~CFX_ImageTransformer(); - bool Start(); bool Continue(IFX_Pause* pPause); const FX_RECT& result() const { return m_result; } diff --git a/chromium/third_party/pdfium/core/fxge/dib/cfx_scanlinecompositor.cpp b/chromium/third_party/pdfium/core/fxge/dib/cfx_scanlinecompositor.cpp index 5bd654b3e63..b9c51f6122e 100644 --- a/chromium/third_party/pdfium/core/fxge/dib/cfx_scanlinecompositor.cpp +++ b/chromium/third_party/pdfium/core/fxge/dib/cfx_scanlinecompositor.cpp @@ -2881,8 +2881,8 @@ void CFX_ScanlineCompositor::InitSourceMask(int alpha_flag, uint8_t r; uint8_t g; uint8_t b; - AdobeCMYK_to_sRGB1(m_MaskRed, m_MaskGreen, m_MaskBlue, mask_black, r, g, - b); + std::tie(r, g, b) = + AdobeCMYK_to_sRGB1(m_MaskRed, m_MaskGreen, m_MaskBlue, mask_black); m_MaskRed = FXRGB2GRAY(r, g, b); } else { m_MaskRed = FXRGB2GRAY(m_MaskRed, m_MaskGreen, m_MaskBlue); @@ -2895,9 +2895,9 @@ void CFX_ScanlineCompositor::InitSourceMask(int alpha_flag, mask_color = (alpha_flag >> 8) ? FXCMYK_TODIB(mask_color) : FXARGB_TODIB(mask_color); if (alpha_flag >> 8) { - AdobeCMYK_to_sRGB1(mask_color_p[0], mask_color_p[1], mask_color_p[2], - mask_color_p[3], mask_color_p[2], mask_color_p[1], - mask_color_p[0]); + std::tie(mask_color_p[2], mask_color_p[1], mask_color_p[0]) = + AdobeCMYK_to_sRGB1(mask_color_p[0], mask_color_p[1], mask_color_p[2], + mask_color_p[3]); m_MaskRed = mask_color_p[2]; m_MaskGreen = mask_color_p[1]; m_MaskBlue = mask_color_p[0]; @@ -2918,10 +2918,12 @@ void CFX_ScanlineCompositor::InitSourcePalette(FXDIB_Format src_format, if (isSrcCmyk) { for (int i = 0; i < pal_count; ++i) { FX_CMYK cmyk = pSrcPalette[i]; - uint8_t r, g, b; - AdobeCMYK_to_sRGB1(FXSYS_GetCValue(cmyk), FXSYS_GetMValue(cmyk), - FXSYS_GetYValue(cmyk), FXSYS_GetKValue(cmyk), r, g, - b); + uint8_t r; + uint8_t g; + uint8_t b; + std::tie(r, g, b) = + AdobeCMYK_to_sRGB1(FXSYS_GetCValue(cmyk), FXSYS_GetMValue(cmyk), + FXSYS_GetYValue(cmyk), FXSYS_GetKValue(cmyk)); *gray_pal++ = FXRGB2GRAY(r, g, b); } } else { @@ -2941,10 +2943,12 @@ void CFX_ScanlineCompositor::InitSourcePalette(FXDIB_Format src_format, } else { for (int i = 0; i < palsize; ++i) { FX_CMYK cmyk = pSrcPalette[i]; - uint8_t r, g, b; - AdobeCMYK_to_sRGB1(FXSYS_GetCValue(cmyk), FXSYS_GetMValue(cmyk), - FXSYS_GetYValue(cmyk), FXSYS_GetKValue(cmyk), r, g, - b); + uint8_t r; + uint8_t g; + uint8_t b; + std::tie(r, g, b) = + AdobeCMYK_to_sRGB1(FXSYS_GetCValue(cmyk), FXSYS_GetMValue(cmyk), + FXSYS_GetYValue(cmyk), FXSYS_GetKValue(cmyk)); pPalette[i] = FXARGB_MAKE(0xff, r, g, b); } } @@ -2976,9 +2980,12 @@ void CFX_ScanlineCompositor::InitSourcePalette(FXDIB_Format src_format, if (isSrcCmyk != isDstCmyk) { for (int i = 0; i < palsize; ++i) { FX_CMYK cmyk = pPalette[i]; - uint8_t r, g, b; - AdobeCMYK_to_sRGB1(FXSYS_GetCValue(cmyk), FXSYS_GetMValue(cmyk), - FXSYS_GetYValue(cmyk), FXSYS_GetKValue(cmyk), r, g, b); + uint8_t r; + uint8_t g; + uint8_t b; + std::tie(r, g, b) = + AdobeCMYK_to_sRGB1(FXSYS_GetCValue(cmyk), FXSYS_GetMValue(cmyk), + FXSYS_GetYValue(cmyk), FXSYS_GetKValue(cmyk)); pPalette[i] = FXARGB_MAKE(0xff, r, g, b); } } diff --git a/chromium/third_party/pdfium/core/fxge/dib/cstretchengine.h b/chromium/third_party/pdfium/core/fxge/dib/cstretchengine.h index 280641cb59d..049059361e3 100644 --- a/chromium/third_party/pdfium/core/fxge/dib/cstretchengine.h +++ b/chromium/third_party/pdfium/core/fxge/dib/cstretchengine.h @@ -9,6 +9,7 @@ #include <vector> +#include "core/fxcrt/cfx_unowned_ptr.h" #include "core/fxcrt/fx_coordinates.h" #include "core/fxge/fx_dib.h" @@ -58,7 +59,7 @@ class CStretchEngine { int m_DestBpp; int m_SrcBpp; int m_bHasAlpha; - IFX_ScanlineComposer* m_pDestBitmap; + CFX_UnownedPtr<IFX_ScanlineComposer> m_pDestBitmap; int m_DestWidth; int m_DestHeight; FX_RECT m_DestClip; diff --git a/chromium/third_party/pdfium/core/fxge/fx_dib.h b/chromium/third_party/pdfium/core/fxge/fx_dib.h index fa38573df8d..9a7da01467e 100644 --- a/chromium/third_party/pdfium/core/fxge/fx_dib.h +++ b/chromium/third_party/pdfium/core/fxge/fx_dib.h @@ -49,13 +49,13 @@ extern const int16_t SDP_Table[513]; #define FXDIB_INTERPOL 0x20 #define FXDIB_BICUBIC_INTERPOL 0x80 #define FXDIB_NOSMOOTH 0x100 + #define FXDIB_BLEND_NORMAL 0 #define FXDIB_BLEND_MULTIPLY 1 #define FXDIB_BLEND_SCREEN 2 #define FXDIB_BLEND_OVERLAY 3 #define FXDIB_BLEND_DARKEN 4 #define FXDIB_BLEND_LIGHTEN 5 - #define FXDIB_BLEND_COLORDODGE 6 #define FXDIB_BLEND_COLORBURN 7 #define FXDIB_BLEND_HARDLIGHT 8 @@ -74,23 +74,26 @@ extern const int16_t SDP_Table[513]; #define FXSYS_GetGValue(rgb) (((rgb) >> 8) & 0xff) #define FXSYS_GetBValue(rgb) (((rgb) >> 16) & 0xff) -#define FXSYS_CMYK(c, m, y, k) (((c) << 24) | ((m) << 16) | ((y) << 8) | (k)) #define FXSYS_GetCValue(cmyk) ((uint8_t)((cmyk) >> 24) & 0xff) #define FXSYS_GetMValue(cmyk) ((uint8_t)((cmyk) >> 16) & 0xff) #define FXSYS_GetYValue(cmyk) ((uint8_t)((cmyk) >> 8) & 0xff) #define FXSYS_GetKValue(cmyk) ((uint8_t)(cmyk)&0xff) + inline FX_CMYK CmykEncode(int c, int m, int y, int k) { return (c << 24) | (m << 16) | (y << 8) | k; } // Returns tuple a, r, g, b std::tuple<int, int, int, int> ArgbDecode(FX_ARGB argb); + // Returns pair a, rgb std::pair<int, FX_COLORREF> ArgbToColorRef(FX_ARGB argb); + inline FX_ARGB ArgbEncode(int a, int r, int g, int b) { return (a << 24) | (r << 16) | (g << 8) | b; } FX_ARGB ArgbEncode(int a, FX_COLORREF rgb); + #define FXARGB_A(argb) ((uint8_t)((argb) >> 24)) #define FXARGB_R(argb) ((uint8_t)((argb) >> 16)) #define FXARGB_G(argb) ((uint8_t)((argb) >> 8)) @@ -123,8 +126,6 @@ FX_ARGB ArgbEncode(int a, FX_COLORREF rgb); #define FXARGB_TOBGRORDERDIB(argb) \ ((uint8_t)(argb >> 16) | ((uint8_t)(argb >> 8)) << 8 | \ ((uint8_t)(argb)) << 16 | ((uint8_t)(argb >> 24) << 24)) -#define FXGETFLAG_COLORTYPE(flag) (uint8_t)((flag) >> 8) -#define FXGETFLAG_ALPHA_FILL(flag) (uint8_t)(flag) FX_RECT FXDIB_SwapClipBox(FX_RECT& clip, int width, diff --git a/chromium/third_party/pdfium/core/fxge/ge/fx_ge_fontmap.cpp b/chromium/third_party/pdfium/core/fxge/fx_ge_fontmap.cpp index 7ac4fada5cc..7ac4fada5cc 100644 --- a/chromium/third_party/pdfium/core/fxge/ge/fx_ge_fontmap.cpp +++ b/chromium/third_party/pdfium/core/fxge/fx_ge_fontmap.cpp diff --git a/chromium/third_party/pdfium/core/fxge/ge/fx_ge_linux.cpp b/chromium/third_party/pdfium/core/fxge/fx_ge_linux.cpp index 4e4b2050e96..d9fac3f54ce 100644 --- a/chromium/third_party/pdfium/core/fxge/ge/fx_ge_linux.cpp +++ b/chromium/third_party/pdfium/core/fxge/fx_ge_linux.cpp @@ -8,8 +8,8 @@ #include <utility> #include "core/fxcrt/fx_codepage.h" +#include "core/fxge/cfx_folderfontinfo.h" #include "core/fxge/cfx_gemodule.h" -#include "core/fxge/ge/cfx_folderfontinfo.h" #include "core/fxge/ifx_systemfontinfo.h" #include "third_party/base/ptr_util.h" diff --git a/chromium/third_party/pdfium/core/fxge/ge/fx_ge_text.cpp b/chromium/third_party/pdfium/core/fxge/fx_ge_text.cpp index 80244522655..0832f7a0209 100644 --- a/chromium/third_party/pdfium/core/fxge/ge/fx_ge_text.cpp +++ b/chromium/third_party/pdfium/core/fxge/fx_ge_text.cpp @@ -12,7 +12,7 @@ #include "core/fxcrt/fx_safe_types.h" #include "core/fxge/cfx_pathdata.h" #include "core/fxge/fx_freetype.h" -#include "core/fxge/ge/fx_text_int.h" +#include "core/fxge/fx_text_int.h" #include "core/fxge/ifx_renderdevicedriver.h" namespace { diff --git a/chromium/third_party/pdfium/core/fxge/ge/fx_ge_text_embeddertest.cpp b/chromium/third_party/pdfium/core/fxge/fx_ge_text_embeddertest.cpp index 045b6dc8690..045b6dc8690 100644 --- a/chromium/third_party/pdfium/core/fxge/ge/fx_ge_text_embeddertest.cpp +++ b/chromium/third_party/pdfium/core/fxge/fx_ge_text_embeddertest.cpp diff --git a/chromium/third_party/pdfium/core/fxge/ge/fx_text_int.h b/chromium/third_party/pdfium/core/fxge/fx_text_int.h index dcd54cead01..6af8eb91651 100644 --- a/chromium/third_party/pdfium/core/fxge/ge/fx_text_int.h +++ b/chromium/third_party/pdfium/core/fxge/fx_text_int.h @@ -4,8 +4,8 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef CORE_FXGE_GE_FX_TEXT_INT_H_ -#define CORE_FXGE_GE_FX_TEXT_INT_H_ +#ifndef CORE_FXGE_FX_TEXT_INT_H_ +#define CORE_FXGE_FX_TEXT_INT_H_ #include <map> #include <memory> @@ -28,4 +28,4 @@ class CFX_SizeGlyphCache { std::map<uint32_t, std::unique_ptr<CFX_GlyphBitmap>> m_GlyphMap; }; -#endif // CORE_FXGE_GE_FX_TEXT_INT_H_ +#endif // CORE_FXGE_FX_TEXT_INT_H_ diff --git a/chromium/third_party/pdfium/core/fxge/skia/fx_skia_device.cpp b/chromium/third_party/pdfium/core/fxge/skia/fx_skia_device.cpp index 7d91ab2b723..855699a4be1 100644 --- a/chromium/third_party/pdfium/core/fxge/skia/fx_skia_device.cpp +++ b/chromium/third_party/pdfium/core/fxge/skia/fx_skia_device.cpp @@ -32,6 +32,7 @@ #include "third_party/skia/include/core/SkImage.h" #include "third_party/skia/include/core/SkPaint.h" #include "third_party/skia/include/core/SkPath.h" +#include "third_party/skia/include/core/SkRSXform.h" #include "third_party/skia/include/core/SkShader.h" #include "third_party/skia/include/core/SkStream.h" #include "third_party/skia/include/core/SkTypeface.h" @@ -40,7 +41,7 @@ #include "third_party/skia/include/pathops/SkPathOps.h" #ifdef _SKIA_SUPPORT_PATHS_ -#include "core/fxge/ge/cfx_cliprgn.h" +#include "core/fxge/cfx_cliprgn.h" #endif // _SKIA_SUPPORT_PATHS_ #ifdef _SKIA_SUPPORT_ @@ -159,6 +160,7 @@ void RgbByteOrderTransferBitmap(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, #define SHOW_SKIA_PATH_SHORTHAND 0 // set to 1 for abbreviated path contents #endif #define DRAW_SKIA_CLIP 0 // set to 1 to draw a green rectangle around the clip +#define SHOW_TEXT_GLYPHS 0 // set to 1 to print unichar equivalent of glyph #if SHOW_SKIA_PATH void DebugShowSkiaPaint(const SkPaint& paint) { @@ -169,14 +171,6 @@ void DebugShowSkiaPaint(const SkPaint& paint) { paint.getStrokeWidth()); } } - -void DebugShowCanvasMatrix(const SkCanvas* canvas) { - SkMatrix matrix = canvas->getTotalMatrix(); - SkScalar m[9]; - matrix.get9(m); - printf("matrix (%g,%g,%g) (%g,%g,%g) (%g,%g,%g)\n", m[0], m[1], m[2], m[3], - m[4], m[5], m[6], m[7], m[8]); -} #endif // SHOW_SKIA_PATH void DebugShowSkiaPath(const SkPath& path) { @@ -194,8 +188,13 @@ void DebugShowSkiaPath(const SkPath& path) { #endif // SHOW_SKIA_PATH } -void DebugShowCanvasClip(const SkCanvas* canvas) { +void DebugShowCanvasClip(CFX_SkiaDeviceDriver* driver, const SkCanvas* canvas) { #if SHOW_SKIA_PATH + SkMatrix matrix = canvas->getTotalMatrix(); + SkScalar m[9]; + matrix.get9(m); + printf("matrix (%g,%g,%g) (%g,%g,%g) (%g,%g,%g)\n", m[0], m[1], m[2], m[3], + m[4], m[5], m[6], m[7], m[8]); SkRect local = canvas->getLocalClipBounds(); SkIRect device = canvas->getDeviceClipBounds(); @@ -203,28 +202,32 @@ void DebugShowCanvasClip(const SkCanvas* canvas) { local.fBottom); printf("device bounds %d %d %d %d\n", device.fLeft, device.fTop, device.fRight, device.fBottom); + FX_RECT clipBox; + driver->GetClipBox(&clipBox); + printf("reported bounds %d %d %d %d\n", clipBox.left, clipBox.top, + clipBox.right, clipBox.bottom); #endif // SHOW_SKIA_PATH } -void DebugShowSkiaDrawPath(const SkCanvas* canvas, +void DebugShowSkiaDrawPath(CFX_SkiaDeviceDriver* driver, + const SkCanvas* canvas, const SkPaint& paint, const SkPath& path) { #if SHOW_SKIA_PATH DebugShowSkiaPaint(paint); - DebugShowCanvasMatrix(canvas); - DebugShowCanvasClip(canvas); + DebugShowCanvasClip(driver, canvas); DebugShowSkiaPath(path); printf("\n"); #endif // SHOW_SKIA_PATH } -void DebugShowSkiaDrawRect(const SkCanvas* canvas, +void DebugShowSkiaDrawRect(CFX_SkiaDeviceDriver* driver, + const SkCanvas* canvas, const SkPaint& paint, const SkRect& rect) { #if SHOW_SKIA_PATH DebugShowSkiaPaint(paint); - DebugShowCanvasMatrix(canvas); - DebugShowCanvasClip(canvas); + DebugShowCanvasClip(driver, canvas); printf("rect %g %g %g %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); #endif // SHOW_SKIA_PATH @@ -523,8 +526,8 @@ void ClipAngledGradient(const SkPoint pts[2], maxBounds = i; } } - ASSERT(minBounds >= 0); - ASSERT(maxBounds >= 0); + if (minBounds < 0 || maxBounds < 0) + return; if (minBounds == maxBounds) return; // construct a clip parallel to the gradient that goes through @@ -564,7 +567,6 @@ void SetBitmapPaint(bool isAlphaMask, bool Upsample(const CFX_RetainPtr<CFX_DIBSource>& pSource, std::unique_ptr<uint8_t, FxFreeDeleter>& dst8Storage, std::unique_ptr<uint32_t, FxFreeDeleter>& dst32Storage, - SkColorTable** ctPtr, SkBitmap* skBitmap, int* widthPtr, int* heightPtr, @@ -596,10 +598,27 @@ bool Upsample(const CFX_RetainPtr<CFX_DIBSource>& pSource, break; } case 8: + // we upscale ctables to 32bit. if (pSource->GetPalette()) { - *ctPtr = - new SkColorTable(pSource->GetPalette(), pSource->GetPaletteSize()); - colorType = SkColorType::kIndex_8_SkColorType; + dst32Storage.reset(FX_Alloc2D(uint32_t, width, height)); + SkPMColor* dst32Pixels = dst32Storage.get(); + const SkPMColor* ctable = pSource->GetPalette(); + const unsigned ctableSize = pSource->GetPaletteSize(); + for (int y = 0; y < height; ++y) { + const uint8_t* srcRow = + static_cast<const uint8_t*>(buffer) + y * rowBytes; + uint32_t* dstRow = dst32Pixels + y * width; + for (int x = 0; x < width; ++x) { + unsigned index = srcRow[x]; + if (index >= ctableSize) { + index = 0; + } + dstRow[x] = ctable[index]; + } + } + buffer = dst32Storage.get(); + rowBytes = width * sizeof(uint32_t); + colorType = SkColorType::kN32_SkColorType; } break; case 24: { @@ -631,8 +650,7 @@ bool Upsample(const CFX_RetainPtr<CFX_DIBSource>& pSource, } SkImageInfo imageInfo = SkImageInfo::Make(width, height, colorType, alphaType); - skBitmap->installPixels(imageInfo, buffer, rowBytes, *ctPtr, nullptr, - nullptr); + skBitmap->installPixels(imageInfo, buffer, rowBytes); *widthPtr = width; *heightPtr = height; return true; @@ -662,6 +680,7 @@ class SkiaState { : m_pDriver(pDriver), m_pTypeFace(nullptr), m_fontSize(0), + m_scaleX(0), m_fillColor(0), m_strokeColor(0), m_blendType(0), @@ -753,7 +772,7 @@ class SkiaState { #ifdef _SKIA_SUPPORT_PATHS_ m_pDriver->PreMultiply(); #endif // _SKIA_SUPPORT_PATHS_ - DebugShowSkiaDrawPath(skCanvas, skPaint, *fillPath); + DebugShowSkiaDrawPath(m_pDriver.Get(), skCanvas, skPaint, *fillPath); skCanvas->drawPath(*fillPath, skPaint); } if (stroke_alpha) { @@ -762,7 +781,7 @@ class SkiaState { #ifdef _SKIA_SUPPORT_PATHS_ m_pDriver->PreMultiply(); #endif // _SKIA_SUPPORT_PATHS_ - DebugShowSkiaDrawPath(skCanvas, skPaint, m_skPath); + DebugShowSkiaDrawPath(m_pDriver.Get(), skCanvas, skPaint, m_skPath); skCanvas->drawPath(m_skPath, skPaint); } skCanvas->restore(); @@ -770,6 +789,38 @@ class SkiaState { m_type = Accumulator::kNone; } + bool HasRSX(int nChars, + const FXTEXT_CHARPOS* pCharPos, + float* scaleXPtr, + bool* oneAtATimePtr) { + bool useRSXform = false; + bool oneAtATime = false; + float scaleX = 1; + for (int index = 0; index < nChars; ++index) { + const FXTEXT_CHARPOS& cp = pCharPos[index]; + if (!cp.m_bGlyphAdjust) + continue; + bool upright = 0 == cp.m_AdjustMatrix[1] && 0 == cp.m_AdjustMatrix[2]; + if (cp.m_AdjustMatrix[0] != cp.m_AdjustMatrix[3]) { + if (upright && 1 == cp.m_AdjustMatrix[3]) { + if (1 == scaleX) + scaleX = cp.m_AdjustMatrix[0]; + else if (scaleX != cp.m_AdjustMatrix[0]) + oneAtATime = true; + } else { + oneAtATime = true; + } + } else if (cp.m_AdjustMatrix[1] != -cp.m_AdjustMatrix[2]) { + oneAtATime = true; + } else { + useRSXform = true; + } + } + *oneAtATimePtr = oneAtATime; + *scaleXPtr = oneAtATime ? 1 : scaleX; + return oneAtATime ? false : useRSXform; + } + bool DrawText(int nChars, const FXTEXT_CHARPOS* pCharPos, CFX_Font* pFont, @@ -779,10 +830,18 @@ class SkiaState { if (m_debugDisable) return false; Dump(__func__); + float scaleX = 1; + bool oneAtATime = false; + bool hasRSX = HasRSX(nChars, pCharPos, &scaleX, &oneAtATime); + if (oneAtATime) { + Flush(); + return false; + } int drawIndex = SkTMin(m_drawIndex, m_commands.count()); if (Accumulator::kPath == m_type || drawIndex != m_commandIndex || (Accumulator::kText == m_type && - FontChanged(pFont, pMatrix, font_size, color))) { + (FontChanged(pFont, pMatrix, font_size, scaleX, color) || + hasRSX == !m_rsxform.count()))) { Flush(); } if (Accumulator::kText != m_type) { @@ -790,6 +849,7 @@ class SkiaState { m_glyphs.setCount(0); m_pTypeFace = pFont->GetFace() ? pFont->GetDeviceCache() : nullptr; m_fontSize = font_size; + m_scaleX = scaleX; m_fillColor = color; m_drawMatrix = *pMatrix; m_drawIndex = m_commandIndex; @@ -798,6 +858,9 @@ class SkiaState { int count = m_positions.count(); m_positions.setCount(nChars + count); m_glyphs.setCount(nChars + count); + if (hasRSX) { + m_rsxform.setCount(nChars + count); + } SkScalar flip = m_fontSize < 0 ? -1 : 1; SkScalar vFlip = flip; if (pFont->IsVertical()) @@ -807,12 +870,33 @@ class SkiaState { m_positions[index + count] = {cp.m_Origin.x * flip, cp.m_Origin.y * vFlip}; m_glyphs[index + count] = static_cast<uint16_t>(cp.m_GlyphIndex); +#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ + if (cp.m_ExtGID) + m_glyphs[index + count] = static_cast<uint16_t>(cp.m_ExtGID); +#endif } SkPoint delta; if (MatrixOffset(pMatrix, &delta)) { for (int index = 0; index < nChars; ++index) m_positions[index + count].offset(delta.fX * flip, -delta.fY * flip); } + if (hasRSX) { + for (int index = 0; index < nChars; ++index) { + const FXTEXT_CHARPOS& cp = pCharPos[index]; + SkRSXform* rsxform = &m_rsxform[index + count]; + if (cp.m_bGlyphAdjust) { + rsxform->fSCos = cp.m_AdjustMatrix[0]; + rsxform->fSSin = cp.m_AdjustMatrix[1]; + rsxform->fTx = cp.m_AdjustMatrix[0] * m_positions[index].fX; + rsxform->fTy = cp.m_AdjustMatrix[1] * m_positions[index].fY; + } else { + rsxform->fSCos = 1; + rsxform->fSSin = 0; + rsxform->fTx = m_positions[index].fX; + rsxform->fTy = m_positions[index].fY; + } + } + } return true; } @@ -822,11 +906,12 @@ class SkiaState { skPaint.setAntiAlias(true); skPaint.setColor(m_fillColor); if (m_pTypeFace) { // exclude placeholder test fonts - sk_sp<SkTypeface> typeface(SkSafeRef(m_pTypeFace)); + sk_sp<SkTypeface> typeface(SkSafeRef(m_pTypeFace.Get())); skPaint.setTypeface(typeface); } skPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); skPaint.setHinting(SkPaint::kNo_Hinting); + skPaint.setTextScaleX(m_scaleX); skPaint.setTextSize(SkTAbs(m_fontSize)); skPaint.setSubpixelText(true); SkCanvas* skCanvas = m_pDriver->SkiaCanvas(); @@ -837,8 +922,21 @@ class SkiaState { #ifdef _SKIA_SUPPORT_PATHS_ m_pDriver->PreMultiply(); #endif // _SKIA_SUPPORT_PATHS_ - skCanvas->drawPosText(m_glyphs.begin(), m_glyphs.count() * 2, - m_positions.begin(), skPaint); +#if SHOW_TEXT_GLYPHS + SkTDArray<SkUnichar> text; + text.setCount(m_glyphs.count()); + skPaint.glyphsToUnichars(m_glyphs.begin(), m_glyphs.count(), text.begin()); + for (size_t i = 0; i < m_glyphs.count(); ++i) + printf("%lc", m_glyphs[i]); + printf("\n"); +#endif + if (m_rsxform.count()) { + skCanvas->drawTextRSXform(m_glyphs.begin(), m_glyphs.count() * 2, + m_rsxform.begin(), nullptr, skPaint); + } else { + skCanvas->drawPosText(m_glyphs.begin(), m_glyphs.count() * 2, + m_positions.begin(), skPaint); + } skCanvas->restore(); m_drawIndex = INT_MAX; m_type = Accumulator::kNone; @@ -852,12 +950,29 @@ class SkiaState { if (m_debugDisable) return false; Dump(__func__); - SkPath skClipPath = BuildPath(pPathData); - skClipPath.setFillType((fill_mode & 3) == FXFILL_ALTERNATE - ? SkPath::kEvenOdd_FillType - : SkPath::kWinding_FillType); - SkMatrix skMatrix = ToSkMatrix(*pMatrix); - skClipPath.transform(skMatrix); + SkPath skClipPath; + if (pPathData->GetPoints().size() == 5 || + pPathData->GetPoints().size() == 4) { + CFX_FloatRect rectf; + if (pPathData->IsRect(pMatrix, &rectf)) { + rectf.Intersect(CFX_FloatRect( + 0, 0, + static_cast<float>(m_pDriver->GetDeviceCaps(FXDC_PIXEL_WIDTH)), + static_cast<float>(m_pDriver->GetDeviceCaps(FXDC_PIXEL_HEIGHT)))); + FX_RECT outer = rectf.GetOuterRect(); + // note that PDF's y-axis goes up; Skia's y-axis goes down + skClipPath.addRect({(float)outer.left, (float)outer.bottom, + (float)outer.right, (float)outer.top}); + } + } + if (skClipPath.isEmpty()) { + skClipPath = BuildPath(pPathData); + skClipPath.setFillType((fill_mode & 3) == FXFILL_ALTERNATE + ? SkPath::kEvenOdd_FillType + : SkPath::kWinding_FillType); + SkMatrix skMatrix = ToSkMatrix(*pMatrix); + skClipPath.transform(skMatrix); + } return SetClip(skClipPath); } @@ -933,7 +1048,7 @@ class SkiaState { return false; Dump(__func__); int count = m_commands.count(); - if (m_commandIndex < count - 1) { + if (m_commandIndex < count) { if (Clip::kSave == m_commands[m_commandIndex]) { ++m_commandIndex; return true; @@ -979,11 +1094,13 @@ class SkiaState { bool FontChanged(CFX_Font* pFont, const CFX_Matrix* pMatrix, float font_size, + float scaleX, uint32_t color) const { CFX_TypeFace* typeface = pFont->GetFace() ? pFont->GetDeviceCache() : nullptr; return typeface != m_pTypeFace || MatrixChanged(pMatrix, m_drawMatrix) || - font_size != m_fontSize || color != m_fillColor; + font_size != m_fontSize || scaleX != m_scaleX || + color != m_fillColor; } bool MatrixChanged(const CFX_Matrix* pMatrix, @@ -1087,10 +1204,11 @@ class SkiaState { if (m_debugDisable) return; printf( - "\n%s\nSkia Save Count %d Agg Save Count %d" - " Cache Save Count %d\n", + "\n%s\nSkia Save Count %d Agg Save Stack/Count %d/%d" + " Cache Save Index/Count %d/%d\n", where, m_pDriver->m_pCanvas->getSaveCount(), - (int)m_pDriver->m_StateStack.size(), m_commandIndex); + (int)m_pDriver->m_StateStack.size(), AggSaveCount(m_pDriver), + m_commandIndex, CacheSaveCount(m_commands, m_commandIndex)); printf("Cache:\n"); #if SHOW_SKIA_PATH_SHORTHAND bool dumpedPath = false; @@ -1133,51 +1251,65 @@ class SkiaState { #endif // SHOW_SKIA_PATH } - void DebugCheckClip() { #if SHOW_SKIA_PATH - if (m_debugDisable) - return; - int aggSaveCount = 0; + static int AggSaveCount(const CFX_UnownedPtr<CFX_SkiaDeviceDriver> driver) { FX_RECT last; + int aggSaveCount = 0; bool foundLast = false; - for (int index = 0; index < (int)m_pDriver->m_StateStack.size(); ++index) { - if (!m_pDriver->m_StateStack[index]) { + for (int index = 0; index < (int)driver->m_StateStack.size(); ++index) { + if (!driver->m_StateStack[index]) { continue; } - if (m_pDriver->m_StateStack[index]->GetType() != CFX_ClipRgn::RectI) { + if (driver->m_StateStack[index]->GetType() != CFX_ClipRgn::RectI) { aggSaveCount += 1; foundLast = false; continue; } - if (!foundLast || memcmp(&last, &m_pDriver->m_StateStack[index]->GetBox(), + if (!foundLast || memcmp(&last, &driver->m_StateStack[index]->GetBox(), sizeof(FX_RECT))) { aggSaveCount += 1; foundLast = true; - last = m_pDriver->m_StateStack[index]->GetBox(); + last = driver->m_StateStack[index]->GetBox(); } } - if (m_pDriver->m_pClipRgn) { - CFX_ClipRgn::ClipType clipType = m_pDriver->m_pClipRgn->GetType(); + if (driver->m_pClipRgn) { + CFX_ClipRgn::ClipType clipType = driver->m_pClipRgn->GetType(); if (clipType != CFX_ClipRgn::RectI || !foundLast || - memcmp(&last, &m_pDriver->m_pClipRgn->GetBox(), sizeof(FX_RECT))) { + memcmp(&last, &driver->m_pClipRgn->GetBox(), sizeof(FX_RECT))) { aggSaveCount += 1; } } + return aggSaveCount; + } + + static int CacheSaveCount(const SkTDArray<SkiaState::Clip>& commands, + int commandIndex) { int cacheSaveCount = 0; - SkASSERT(m_clipIndex <= m_commands.count()); bool newPath = false; - for (int index = 0; index < m_commandIndex; ++index) { - if (Clip::kSave == m_commands[index]) { + for (int index = 0; index < commandIndex; ++index) { + if (Clip::kSave == commands[index]) { newPath = true; } else if (newPath) { ++cacheSaveCount; newPath = false; } } + return cacheSaveCount; + } +#endif + + void DebugCheckClip() { +#if SHOW_SKIA_PATH + if (m_debugDisable) + return; + int aggSaveCount = AggSaveCount(m_pDriver); + int cacheSaveCount = CacheSaveCount(m_commands, m_commandIndex); + SkASSERT(m_clipIndex <= m_commands.count()); if (aggSaveCount != cacheSaveCount) { + // may not signify a bug if counts don't match + printf("aggSaveCount %d != cacheSaveCount %d\n", aggSaveCount, + cacheSaveCount); DumpClipStacks(); - SkASSERT(0); - return; } for (int aggIndex = 0; aggIndex < (int)m_pDriver->m_StateStack.size(); ++aggIndex) { @@ -1259,6 +1391,7 @@ class SkiaState { SkTArray<SkPath> m_clips; // stack of clips that may be reused SkTDArray<Clip> m_commands; // stack of clip-related commands SkTDArray<SkPoint> m_positions; // accumulator for text positions + SkTDArray<SkRSXform> m_rsxform; // accumulator for txt rotate/scale/translate SkTDArray<uint16_t> m_glyphs; // accumulator for text glyphs SkPath m_skPath; // accumulator for path contours SkPath m_skEmptyPath; // used as placehold in the clips array @@ -1266,9 +1399,10 @@ class SkiaState { CFX_GraphStateData m_clipState; CFX_GraphStateData m_drawState; CFX_Matrix m_clipMatrix; - CFX_SkiaDeviceDriver* m_pDriver; - CFX_TypeFace* m_pTypeFace; + CFX_UnownedPtr<CFX_SkiaDeviceDriver> m_pDriver; + CFX_UnownedPtr<CFX_TypeFace> m_pTypeFace; float m_fontSize; + float m_scaleX; uint32_t m_fillColor; uint32_t m_strokeColor; int m_blendType; @@ -1378,9 +1512,7 @@ CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver( pBitmap->GetWidth(), pBitmap->GetHeight(), pBitmap->GetBPP() == 8 ? kAlpha_8_SkColorType : kN32_SkColorType, kOpaque_SkAlphaType); - skBitmap.installPixels(imageInfo, pBitmap->GetBuffer(), pBitmap->GetPitch(), - nullptr, // FIXME(caryclark) set color table - nullptr, nullptr); + skBitmap.installPixels(imageInfo, pBitmap->GetBuffer(), pBitmap->GetPitch()); m_pCanvas = new SkCanvas(skBitmap); } @@ -1445,15 +1577,89 @@ bool CFX_SkiaDeviceDriver::DrawDeviceText(int nChars, positions.setCount(nChars); SkTDArray<uint16_t> glyphs; glyphs.setCount(nChars); + bool useRSXform = false; + bool oneAtATime = false; for (int index = 0; index < nChars; ++index) { const FXTEXT_CHARPOS& cp = pCharPos[index]; positions[index] = {cp.m_Origin.x * flip, cp.m_Origin.y * vFlip}; + if (cp.m_bGlyphAdjust) { + useRSXform = true; + if (cp.m_AdjustMatrix[0] != cp.m_AdjustMatrix[3] || + cp.m_AdjustMatrix[1] != -cp.m_AdjustMatrix[2]) { + oneAtATime = true; + } + } glyphs[index] = static_cast<uint16_t>(cp.m_GlyphIndex); +#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ + if (cp.m_ExtGID) + glyphs[index] = static_cast<uint16_t>(cp.m_ExtGID); +#endif } + if (oneAtATime) + useRSXform = false; +#if SHOW_TEXT_GLYPHS + SkTDArray<SkUnichar> text; + text.setCount(glyphs.count()); + paint.glyphsToUnichars(glyphs.begin(), glyphs.count(), text.begin()); + for (size_t i = 0; i < glyphs.count(); ++i) + printf("%lc", text[i]); + printf("\n"); +#endif #ifdef _SKIA_SUPPORT_PATHS_ m_pBitmap->PreMultiply(); #endif // _SKIA_SUPPORT_PATHS_ - m_pCanvas->drawPosText(glyphs.begin(), nChars * 2, positions.begin(), paint); + if (useRSXform) { + SkTDArray<SkRSXform> xforms; + xforms.setCount(nChars); + for (int index = 0; index < nChars; ++index) { + const FXTEXT_CHARPOS& cp = pCharPos[index]; + SkRSXform* rsxform = &xforms[index]; + if (cp.m_bGlyphAdjust) { + rsxform->fSCos = cp.m_AdjustMatrix[0]; + rsxform->fSSin = cp.m_AdjustMatrix[1]; + rsxform->fTx = cp.m_AdjustMatrix[0] * positions[index].fX; + rsxform->fTy = cp.m_AdjustMatrix[1] * positions[index].fY; + } else { + rsxform->fSCos = 1; + rsxform->fSSin = 0; + rsxform->fTx = positions[index].fX; + rsxform->fTy = positions[index].fY; + } + } + m_pCanvas->drawTextRSXform(glyphs.begin(), nChars * 2, xforms.begin(), + nullptr, paint); + } else if (oneAtATime) { + for (int index = 0; index < nChars; ++index) { + const FXTEXT_CHARPOS& cp = pCharPos[index]; + if (cp.m_bGlyphAdjust) { + if (0 == cp.m_AdjustMatrix[1] && 0 == cp.m_AdjustMatrix[2] && + 1 == cp.m_AdjustMatrix[3]) { + paint.setTextScaleX(cp.m_AdjustMatrix[0]); + m_pCanvas->drawText(&glyphs[index], 1, positions[index].fX, + positions[index].fY, paint); + paint.setTextScaleX(1); + } else { + m_pCanvas->save(); + SkMatrix adjust; + adjust.reset(); + adjust.setScaleX(cp.m_AdjustMatrix[0]); + adjust.setSkewX(cp.m_AdjustMatrix[1]); + adjust.setSkewY(cp.m_AdjustMatrix[2]); + adjust.setScaleY(cp.m_AdjustMatrix[3]); + adjust.preTranslate(positions[index].fX, positions[index].fY); + m_pCanvas->concat(adjust); + m_pCanvas->drawText(&glyphs[index], 1, 0, 0, paint); + m_pCanvas->restore(); + } + } else { + m_pCanvas->drawText(&glyphs[index], 1, positions[index].fX, + positions[index].fY, paint); + } + } + } else { + m_pCanvas->drawPosText(glyphs.begin(), nChars * 2, positions.begin(), + paint); + } m_pCanvas->restore(); return true; @@ -1572,7 +1778,7 @@ void CFX_SkiaDeviceDriver::SetClipMask(const FX_RECT& clipBox, SkColorType::kAlpha_8_SkColorType, kOpaque_SkAlphaType); SkBitmap bitmap; bitmap.installPixels(imageInfo, pThisLayer->GetBuffer(), - pThisLayer->GetPitch(), nullptr, nullptr, nullptr); + pThisLayer->GetPitch()); auto canvas = pdfium::MakeUnique<SkCanvas>(bitmap); canvas->translate( -path_rect.left, @@ -1619,7 +1825,7 @@ bool CFX_SkiaDeviceDriver::SetClip_PathFill( FX_RECT rect = rectf.GetOuterRect(); m_pClipRgn->IntersectRect(rect); #endif // _SKIA_SUPPORT_PATHS_ - DebugShowCanvasClip(m_pCanvas); + DebugShowCanvasClip(this, m_pCanvas); return true; } } @@ -1639,7 +1845,7 @@ bool CFX_SkiaDeviceDriver::SetClip_PathFill( GetDeviceCaps(FXDC_PIXEL_HEIGHT)); SetClipMask(clipBox, skClipPath); #endif // _SKIA_SUPPORT_PATHS_ - DebugShowCanvasClip(m_pCanvas); + DebugShowCanvasClip(this, m_pCanvas); return true; } @@ -1673,7 +1879,7 @@ bool CFX_SkiaDeviceDriver::SetClip_PathStroke( GetDeviceCaps(FXDC_PIXEL_HEIGHT)); SetClipMask(clipBox, dst_path); #endif // _SKIA_SUPPORT_PATHS_ - DebugShowCanvasClip(m_pCanvas); + DebugShowCanvasClip(this, m_pCanvas); return true; } @@ -1726,7 +1932,7 @@ bool CFX_SkiaDeviceDriver::DrawPath( #ifdef _SKIA_SUPPORT_PATHS_ m_pBitmap->PreMultiply(); #endif // _SKIA_SUPPORT_PATHS_ - DebugShowSkiaDrawPath(m_pCanvas, skPaint, *fillPath); + DebugShowSkiaDrawPath(this, m_pCanvas, skPaint, *fillPath); m_pCanvas->drawPath(*fillPath, skPaint); } if (pGraphState && stroke_alpha) { @@ -1735,7 +1941,7 @@ bool CFX_SkiaDeviceDriver::DrawPath( #ifdef _SKIA_SUPPORT_PATHS_ m_pBitmap->PreMultiply(); #endif // _SKIA_SUPPORT_PATHS_ - DebugShowSkiaDrawPath(m_pCanvas, skPaint, skPath); + DebugShowSkiaDrawPath(this, m_pCanvas, skPaint, skPath); m_pCanvas->drawPath(skPath, skPaint); } m_pCanvas->restore(); @@ -1762,7 +1968,7 @@ bool CFX_SkiaDeviceDriver::FillRectWithBlend(const FX_RECT* pRect, SkRect rect = SkRect::MakeLTRB(pRect->left, SkTMin(pRect->top, pRect->bottom), pRect->right, SkTMax(pRect->bottom, pRect->top)); - DebugShowSkiaDrawRect(m_pCanvas, spaint, rect); + DebugShowSkiaDrawRect(this, m_pCanvas, spaint, rect); m_pCanvas->drawRect(rect, spaint); return true; } @@ -1956,12 +2162,22 @@ uint8_t* CFX_SkiaDeviceDriver::GetBuffer() const { } bool CFX_SkiaDeviceDriver::GetClipBox(FX_RECT* pRect) { +#ifdef _SKIA_SUPPORT_PATHS_ + if (!m_pClipRgn) { + pRect->left = pRect->top = 0; + pRect->right = GetDeviceCaps(FXDC_PIXEL_WIDTH); + pRect->bottom = GetDeviceCaps(FXDC_PIXEL_HEIGHT); + return true; + } + *pRect = m_pClipRgn->GetBox(); +#else // TODO(caryclark) call m_canvas->getClipDeviceBounds() instead pRect->left = 0; pRect->top = 0; const SkImageInfo& canvasSize = m_pCanvas->imageInfo(); pRect->right = canvasSize.width(); pRect->bottom = canvasSize.height(); +#endif return true; } @@ -1981,8 +2197,7 @@ bool CFX_SkiaDeviceDriver::GetDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, SkImageInfo srcImageInfo = SkImageInfo::Make( srcWidth, srcHeight, SkColorType::kN32_SkColorType, kPremul_SkAlphaType); SkBitmap skSrcBitmap; - skSrcBitmap.installPixels(srcImageInfo, srcBuffer, srcRowBytes, nullptr, - nullptr, nullptr); + skSrcBitmap.installPixels(srcImageInfo, srcBuffer, srcRowBytes); SkASSERT(pBitmap); uint8_t* dstBuffer = pBitmap->GetBuffer(); SkASSERT(dstBuffer); @@ -1992,8 +2207,7 @@ bool CFX_SkiaDeviceDriver::GetDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, SkImageInfo dstImageInfo = SkImageInfo::Make( dstWidth, dstHeight, SkColorType::kN32_SkColorType, kPremul_SkAlphaType); SkBitmap skDstBitmap; - skDstBitmap.installPixels(dstImageInfo, dstBuffer, dstRowBytes, nullptr, - nullptr, nullptr); + skDstBitmap.installPixels(dstImageInfo, dstBuffer, dstRowBytes); SkCanvas canvas(skDstBitmap); canvas.drawBitmap(skSrcBitmap, left, top, nullptr); return true; @@ -2130,13 +2344,12 @@ bool CFX_SkiaDeviceDriver::StartDIBits( #ifdef _SKIA_SUPPORT_ m_pCache->FlushForDraw(); DebugValidate(m_pBitmap, m_pOriDevice); - SkColorTable* ct = nullptr; std::unique_ptr<uint8_t, FxFreeDeleter> dst8Storage; std::unique_ptr<uint32_t, FxFreeDeleter> dst32Storage; SkBitmap skBitmap; int width, height; - if (!Upsample(pSource, dst8Storage, dst32Storage, &ct, &skBitmap, &width, - &height, false)) { + if (!Upsample(pSource, dst8Storage, dst32Storage, &skBitmap, &width, &height, + false)) { return false; } m_pCanvas->save(); @@ -2164,8 +2377,6 @@ bool CFX_SkiaDeviceDriver::StartDIBits( m_pCanvas->drawBitmap(skBitmap, 0, 0, &paint); } m_pCanvas->restore(); - if (ct) - ct->unref(); DebugValidate(m_pBitmap, m_pOriDevice); #endif // _SKIA_SUPPORT_ @@ -2174,9 +2385,9 @@ bool CFX_SkiaDeviceDriver::StartDIBits( if (!m_pBitmap->GetBuffer()) return true; m_pBitmap->UnPreMultiply(); - *handle = pdfium::MakeUnique<CFX_ImageRenderer>(); - (*handle)->Start(m_pBitmap, m_pClipRgn.get(), pSource, bitmap_alpha, argb, - pMatrix, render_flags, m_bRgbByteOrder); + *handle = pdfium::MakeUnique<CFX_ImageRenderer>( + m_pBitmap, m_pClipRgn.get(), pSource, bitmap_alpha, argb, pMatrix, + render_flags, m_bRgbByteOrder); #endif // _SKIA_SUPPORT_PATHS_ return true; } @@ -2262,18 +2473,16 @@ bool CFX_SkiaDeviceDriver::DrawBitsWithMask( const CFX_Matrix* pMatrix, int blend_type) { DebugValidate(m_pBitmap, m_pOriDevice); - SkColorTable* srcCt = nullptr; - SkColorTable* maskCt = nullptr; std::unique_ptr<uint8_t, FxFreeDeleter> src8Storage, mask8Storage; std::unique_ptr<uint32_t, FxFreeDeleter> src32Storage, mask32Storage; SkBitmap skBitmap, skMask; int srcWidth, srcHeight, maskWidth, maskHeight; - if (!Upsample(pSource, src8Storage, src32Storage, &srcCt, &skBitmap, - &srcWidth, &srcHeight, false)) { + if (!Upsample(pSource, src8Storage, src32Storage, &skBitmap, &srcWidth, + &srcHeight, false)) { return false; } - if (!Upsample(pMask, mask8Storage, mask32Storage, &maskCt, &skMask, - &maskWidth, &maskHeight, true)) { + if (!Upsample(pMask, mask8Storage, mask32Storage, &skMask, &maskWidth, + &maskHeight, true)) { return false; } m_pCanvas->save(); @@ -2294,8 +2503,6 @@ bool CFX_SkiaDeviceDriver::DrawBitsWithMask( SkRect r = {0, 0, SkIntToScalar(srcWidth), SkIntToScalar(srcHeight)}; m_pCanvas->drawRect(r, paint); m_pCanvas->restore(); - if (srcCt) - srcCt->unref(); DebugValidate(m_pBitmap, m_pOriDevice); return true; } diff --git a/chromium/third_party/pdfium/core/fxge/skia/fx_skia_device_unittest.cpp b/chromium/third_party/pdfium/core/fxge/skia/fx_skia_device_unittest.cpp index 99b76d2109d..94d9a0f2cf1 100644 --- a/chromium/third_party/pdfium/core/fxge/skia/fx_skia_device_unittest.cpp +++ b/chromium/third_party/pdfium/core/fxge/skia/fx_skia_device_unittest.cpp @@ -9,7 +9,6 @@ #include "core/fxge/cfx_renderdevice.h" #include "fpdfsdk/fsdk_define.h" #include "public/fpdfview.h" -#include "testing/fx_string_testhelpers.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/skia/include/core/SkPictureRecorder.h" diff --git a/chromium/third_party/pdfium/core/fxge/win32/cfx_psrenderer.cpp b/chromium/third_party/pdfium/core/fxge/win32/cfx_psrenderer.cpp index 400babd16b5..c9365535986 100644 --- a/chromium/third_party/pdfium/core/fxge/win32/cfx_psrenderer.cpp +++ b/chromium/third_party/pdfium/core/fxge/win32/cfx_psrenderer.cpp @@ -17,7 +17,7 @@ #include "core/fxge/cfx_pathdata.h" #include "core/fxge/cfx_renderdevice.h" #include "core/fxge/dib/cfx_dibextractor.h" -#include "core/fxge/ge/fx_text_int.h" +#include "core/fxge/fx_text_int.h" #include "core/fxge/win32/cpsoutput.h" #include "third_party/base/ptr_util.h" @@ -76,7 +76,7 @@ void PSCompressData(int PSLevel, } // namespace struct PSGlyph { - CFX_Font* m_pFont; + CFX_UnownedPtr<CFX_Font> m_pFont; uint32_t m_GlyphIndex; bool m_bGlyphAdjust; float m_AdjustMatrix[4]; diff --git a/chromium/third_party/pdfium/core/fxge/win32/cpsoutput.cpp b/chromium/third_party/pdfium/core/fxge/win32/cpsoutput.cpp index 7139340a6e8..1af6dbdcede 100644 --- a/chromium/third_party/pdfium/core/fxge/win32/cpsoutput.cpp +++ b/chromium/third_party/pdfium/core/fxge/win32/cpsoutput.cpp @@ -32,5 +32,5 @@ bool CPSOutput::WriteBlock(const void* str, size_t len) { } bool CPSOutput::WriteString(const CFX_ByteStringC& str) { - return WriteBlock(str.c_str(), str.GetLength()); + return WriteBlock(str.unterminated_c_str(), str.GetLength()); } diff --git a/chromium/third_party/pdfium/core/fxge/win32/fx_win32_device.cpp b/chromium/third_party/pdfium/core/fxge/win32/fx_win32_device.cpp index b495251dee4..4427755cf5f 100644 --- a/chromium/third_party/pdfium/core/fxge/win32/fx_win32_device.cpp +++ b/chromium/third_party/pdfium/core/fxge/win32/fx_win32_device.cpp @@ -15,6 +15,7 @@ #include "core/fxcrt/fx_codepage.h" #include "core/fxcrt/fx_memory.h" #include "core/fxcrt/fx_system.h" +#include "core/fxge/cfx_folderfontinfo.h" #include "core/fxge/cfx_gemodule.h" #include "core/fxge/cfx_windowsrenderdevice.h" #include "core/fxge/dib/cfx_dibextractor.h" @@ -22,8 +23,7 @@ #include "core/fxge/dib/cstretchengine.h" #include "core/fxge/fx_font.h" #include "core/fxge/fx_freetype.h" -#include "core/fxge/ge/cfx_folderfontinfo.h" -#include "core/fxge/ge/fx_text_int.h" +#include "core/fxge/fx_text_int.h" #include "core/fxge/ifx_systemfontinfo.h" #include "core/fxge/win32/cfx_windowsdib.h" #include "core/fxge/win32/dwrite_int.h" @@ -363,7 +363,7 @@ class CFX_Win32FontInfo final : public IFX_SystemFontInfo { CFX_ByteString FindFont(const CFX_ByteString& name); HDC m_hDC; - CFX_FontMapper* m_pMapper; + CFX_UnownedPtr<CFX_FontMapper> m_pMapper; CFX_ByteString m_LastFamily; CFX_ByteString m_KaiTi, m_FangSong; }; @@ -689,7 +689,7 @@ bool CFX_Win32FontInfo::GetFontCharset(void* hFont, int* charset) { } // namespace -int g_pdfium_print_postscript_level = 0; +int g_pdfium_print_mode = WindowsPrintMode::kModeEmf; std::unique_ptr<IFX_SystemFontInfo> IFX_SystemFontInfo::CreateDefault( const char** pUnused) { @@ -1370,14 +1370,20 @@ IFX_RenderDeviceDriver* CFX_WindowsRenderDevice::CreateDriver(HDC hDC) { int device_type = ::GetDeviceCaps(hDC, TECHNOLOGY); int obj_type = ::GetObjectType(hDC); bool use_printer = device_type == DT_RASPRINTER || - device_type == DT_PLOTTER || obj_type == OBJ_ENHMETADC; + device_type == DT_PLOTTER || + device_type == DT_CHARSTREAM || obj_type == OBJ_ENHMETADC; if (!use_printer) return new CGdiDisplayDriver(hDC); - if (g_pdfium_print_postscript_level == 2 || - g_pdfium_print_postscript_level == 3) { - return new CPSPrinterDriver(hDC, g_pdfium_print_postscript_level, false); - } - return new CGdiPrinterDriver(hDC); + if (g_pdfium_print_mode == WindowsPrintMode::kModeEmf) + return new CGdiPrinterDriver(hDC); + + if (g_pdfium_print_mode == WindowsPrintMode::kModeTextOnly) + return new CTextOnlyPrinterDriver(hDC); + + // Should be PostScript + ASSERT(g_pdfium_print_mode == WindowsPrintMode::kModePostScript2 || + g_pdfium_print_mode == WindowsPrintMode::kModePostScript3); + return new CPSPrinterDriver(hDC, g_pdfium_print_mode, false); } diff --git a/chromium/third_party/pdfium/core/fxge/win32/fx_win32_dwrite.cpp b/chromium/third_party/pdfium/core/fxge/win32/fx_win32_dwrite.cpp index 91fb465af4c..8b1786a088f 100644 --- a/chromium/third_party/pdfium/core/fxge/win32/fx_win32_dwrite.cpp +++ b/chromium/third_party/pdfium/core/fxge/win32/fx_win32_dwrite.cpp @@ -7,7 +7,7 @@ #include <dwrite.h> #include "core/fxcrt/fx_system.h" -#include "core/fxge/ge/cfx_cliprgn.h" +#include "core/fxge/cfx_cliprgn.h" #include "core/fxge/win32/dwrite_int.h" typedef HRESULT(__stdcall* FuncType_DWriteCreateFactory)( diff --git a/chromium/third_party/pdfium/core/fxge/win32/fx_win32_print.cpp b/chromium/third_party/pdfium/core/fxge/win32/fx_win32_print.cpp index 8f7cbf5be04..cae38594061 100644 --- a/chromium/third_party/pdfium/core/fxge/win32/fx_win32_print.cpp +++ b/chromium/third_party/pdfium/core/fxge/win32/fx_win32_print.cpp @@ -16,7 +16,7 @@ #include "core/fxge/dib/cfx_imagerenderer.h" #include "core/fxge/dib/cstretchengine.h" #include "core/fxge/fx_freetype.h" -#include "core/fxge/ge/fx_text_int.h" +#include "core/fxge/fx_text_int.h" #include "core/fxge/win32/cpsoutput.h" #include "core/fxge/win32/win32_int.h" #include "third_party/base/ptr_util.h" @@ -492,3 +492,159 @@ bool CPSPrinterDriver::DrawDeviceText(int nChars, return m_PSRenderer.DrawText(nChars, pCharPos, pFont, pObject2Device, font_size, color); } + +CTextOnlyPrinterDriver::CTextOnlyPrinterDriver(HDC hDC) + : m_hDC(hDC), + m_Width(INT_MAX), + m_Height(INT_MAX), + m_HorzSize(INT_MAX), + m_VertSize(INT_MAX), + m_OriginY(0.0f), + m_SetOrigin(false) { + m_nBitsPerPixel = ::GetDeviceCaps(m_hDC, BITSPIXEL); +} + +CTextOnlyPrinterDriver::~CTextOnlyPrinterDriver() { + EndRendering(); +} + +int CTextOnlyPrinterDriver::GetDeviceCaps(int caps_id) const { + switch (caps_id) { + case FXDC_DEVICE_CLASS: + return FXDC_PRINTER; + case FXDC_PIXEL_WIDTH: + return m_Width; + case FXDC_PIXEL_HEIGHT: + return m_Height; + case FXDC_BITS_PIXEL: + return m_nBitsPerPixel; + case FXDC_RENDER_CAPS: + return 0; + case FXDC_HORZ_SIZE: + return m_HorzSize; + case FXDC_VERT_SIZE: + return m_VertSize; + } + return 0; +} + +bool CTextOnlyPrinterDriver::SetClip_PathFill(const CFX_PathData* pPathData, + const CFX_Matrix* pObject2Device, + int fill_mode) { + return true; +} + +bool CTextOnlyPrinterDriver::SetClip_PathStroke( + const CFX_PathData* pPathData, + const CFX_Matrix* pObject2Device, + const CFX_GraphStateData* pGraphState) { + return false; +} + +bool CTextOnlyPrinterDriver::DrawPath(const CFX_PathData* pPathData, + const CFX_Matrix* pObject2Device, + const CFX_GraphStateData* pGraphState, + uint32_t fill_color, + uint32_t stroke_color, + int fill_mode, + int blend_type) { + return false; +} + +bool CTextOnlyPrinterDriver::SetDIBits( + const CFX_RetainPtr<CFX_DIBSource>& pBitmap, + uint32_t color, + const FX_RECT* pSrcRect, + int left, + int top, + int blend_type) { + return false; +} + +bool CTextOnlyPrinterDriver::GetClipBox(FX_RECT* pRect) { + pRect->left = 0; + pRect->right = m_Width; + pRect->top = 0; + pRect->bottom = m_Height; + return true; +} + +bool CTextOnlyPrinterDriver::StretchDIBits( + const CFX_RetainPtr<CFX_DIBSource>& pBitmap, + uint32_t color, + int dest_left, + int dest_top, + int dest_width, + int dest_height, + const FX_RECT* pClipRect, + uint32_t flags, + int blend_type) { + return false; +} + +bool CTextOnlyPrinterDriver::StartDIBits( + const CFX_RetainPtr<CFX_DIBSource>& pBitmap, + int bitmap_alpha, + uint32_t color, + const CFX_Matrix* pMatrix, + uint32_t render_flags, + std::unique_ptr<CFX_ImageRenderer>* handle, + int blend_type) { + return false; +} + +bool CTextOnlyPrinterDriver::DrawDeviceText(int nChars, + const FXTEXT_CHARPOS* pCharPos, + CFX_Font* pFont, + const CFX_Matrix* pObject2Device, + float font_size, + uint32_t color) { + if (g_pdfium_print_mode != 1) + return false; + if (nChars < 1 || !pFont || !pFont->IsEmbedded() || !pFont->IsTTFont()) + return false; + + // Scale factor used to minimize the kerning problems caused by rounding + // errors below. Value chosen based on the title of https://crbug.com/18383 + const double kScaleFactor = 10; + + CFX_WideString wsText; + int totalLength = nChars; + + // Detect new lines and add a space. Was likely removed by SkPDF if this is + // just text, and spaces seem to be ignored by label printers that use this + // driver. + if (m_SetOrigin && + FXSYS_round(m_OriginY) != FXSYS_round(pObject2Device->f * kScaleFactor)) { + wsText += L" "; + totalLength++; + } + m_OriginY = pObject2Device->f * kScaleFactor; + m_SetOrigin = true; + + // Text + for (int i = 0; i < nChars; ++i) { + // Only works with PDFs from Skia's PDF generator. Cannot handle arbitrary + // values from PDFs. + const FXTEXT_CHARPOS& charpos = pCharPos[i]; + ASSERT(charpos.m_AdjustMatrix[0] == 0); + ASSERT(charpos.m_AdjustMatrix[1] == 0); + ASSERT(charpos.m_AdjustMatrix[2] == 0); + ASSERT(charpos.m_AdjustMatrix[3] == 0); + ASSERT(charpos.m_Origin.y == 0); + + wsText += charpos.m_Unicode; + } + size_t len = totalLength; + CFX_ByteString text = CFX_ByteString::FromUnicode(wsText); + while (len > 0) { + char buffer[1026]; + size_t send_len = std::min(len, static_cast<size_t>(1024)); + *(reinterpret_cast<uint16_t*>(buffer)) = send_len; + memcpy(buffer + 2, text.c_str(), send_len); + ::GdiComment(m_hDC, send_len + 2, reinterpret_cast<const BYTE*>(buffer)); + len -= send_len; + text.Right(len); + } + return true; +} diff --git a/chromium/third_party/pdfium/core/fxge/win32/win32_int.h b/chromium/third_party/pdfium/core/fxge/win32/win32_int.h index d92d3b333c9..c51bae7f679 100644 --- a/chromium/third_party/pdfium/core/fxge/win32/win32_int.h +++ b/chromium/third_party/pdfium/core/fxge/win32/win32_int.h @@ -333,4 +333,66 @@ class CPSPrinterDriver : public IFX_RenderDeviceDriver { CFX_PSRenderer m_PSRenderer; }; +class CTextOnlyPrinterDriver : public IFX_RenderDeviceDriver { + public: + explicit CTextOnlyPrinterDriver(HDC hDC); + ~CTextOnlyPrinterDriver() override; + + protected: + // IFX_RenderDeviceDriver + int GetDeviceCaps(int caps_id) const override; + void SaveState() override{}; + void RestoreState(bool bKeepSaved) override{}; + bool SetClip_PathFill(const CFX_PathData* pPathData, + const CFX_Matrix* pObject2Device, + int fill_mode) override; + bool SetClip_PathStroke(const CFX_PathData* pPathData, + const CFX_Matrix* pObject2Device, + const CFX_GraphStateData* pGraphState) override; + bool DrawPath(const CFX_PathData* pPathData, + const CFX_Matrix* pObject2Device, + const CFX_GraphStateData* pGraphState, + uint32_t fill_color, + uint32_t stroke_color, + int fill_mode, + int blend_type) override; + bool GetClipBox(FX_RECT* pRect) override; + bool SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap, + uint32_t color, + const FX_RECT* pSrcRect, + int left, + int top, + int blend_type) override; + bool StretchDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap, + uint32_t color, + int dest_left, + int dest_top, + int dest_width, + int dest_height, + const FX_RECT* pClipRect, + uint32_t flags, + int blend_type) override; + bool StartDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap, + int bitmap_alpha, + uint32_t color, + const CFX_Matrix* pMatrix, + uint32_t render_flags, + std::unique_ptr<CFX_ImageRenderer>* handle, + int blend_type) override; + bool DrawDeviceText(int nChars, + const FXTEXT_CHARPOS* pCharPos, + CFX_Font* pFont, + const CFX_Matrix* pObject2Device, + float font_size, + uint32_t color) override; + + HDC m_hDC; + int m_Width; + int m_Height; + int m_nBitsPerPixel; + int m_HorzSize; + int m_VertSize; + float m_OriginY; + bool m_SetOrigin; +}; #endif // CORE_FXGE_WIN32_WIN32_INT_H_ diff --git a/chromium/third_party/pdfium/docs/code-coverage.md b/chromium/third_party/pdfium/docs/code-coverage.md new file mode 100644 index 00000000000..3162b5886ce --- /dev/null +++ b/chromium/third_party/pdfium/docs/code-coverage.md @@ -0,0 +1,152 @@ +# Code Coverage Support for PDFium + +[TOC] + +This guide explains how to generate code coverage information for the PDFium +library on a local computer. + +## Prerequisites + +You will need the PDFium source code on your computer. You can see +the [README](/README.md) for instructions on checking out PDFium's source. + +The tools used for code coverage are known to work on Ubuntu 14.04. They should +work correctly on newer versions of Ubuntu and related Linux distros. They have +not been tested on Windows and Mac. + +### lcov + +The code coverage scripts depend on having a version of `lcov` of 1.11 or +greater available, which is enforced by the script. Unfortunately the default +version of `lcov` for Ubuntu 14.04 is 1.10, thus you will need to install a +newer version. + +You can build a newer version of `lcov` from source, which is +available [here](http://ltp.sourceforge.net/coverage/lcov.php). + +If you don't want to build from source and use an RPM based Linux, not +Ubuntu/Debian, then there are pre-built RPMs +available [here](http://downloads.sourceforge.net/ltp/lcov-1.13-1.noarch.rpm). + +For Ubuntu/Debian users these RPMs can be converted to .deb using `alien`. More +information about how to do this can be found in `man alien`. + +### llvm-cov + +The other external dependency for generating code coverage information is having +a version of `llvm-cov` that supports the `gcov` command. This should be all +versions of 3.5.0 or greater. + +Again, unfortunately, the default llvm-cov that comes with Ubuntu 14.04, 3.4, is +lower then what is needed. The 14.04 repositories do support having multiple +versions of the `llvm` package, and thus `llvm-cov`. Through your favourite +package manager you should be able to install any version of `llvm` of 3.5 or +greater and the coverage scripts should find it. + +## Generating Code Coverage + +### Setup + +This step assumes that you have already checked out the PDFium source code and +installed the proper versions of the external tools. If you have not, please +consult the above Prerequisites section. + +Before generating code coverage information, you will need to have a build +directory with coverage enabled. This can be done by running the `gn args` +command and adding `use_coverage = true` in the editor that is opened. If not +using the default directory, `out/Coverage`, then replace it with the correct +location in the following command. + +```shell +gn args out/Coverage +``` + +If you already have a build directory, you can append the coverage flag to the +existing `args.gn` as follows. If not using the default directory, +`out/Coverage`, then replace it with the correct location in the following +command. + +```shell +echo "use_coverage = true" >> out/Coverage/args.gn +``` + + +### Usage + +Generating code coverage information is done via the +`tools/coverage/coverage_report.py` script. This script will build any binaries +that it needs, perform test runs, collect coverage data, and finally generate a +nice HTML coverage report. + +Running the script with no arguments, as below, will assume that you are +currently at the root of your PDFium checkout, the build directory to use is +`./out/Coverage/` and that HTML should be outputted to `./coverage_report/`. By +default, it will also only run `pdfium_unittests` and `pdfium_embeddertests` for +coverage data. This is because the other tests are known to take a long time to +run, so they are not included in the defaults. + +```shell +tools/coverage/coverage_report.py +``` + +If the current working directory is not the root of your PDFium checkout, then +you will need to pass in `--source-directory` with the appropriate directory. If +you are using a different build directory, then `--build-directory` will need to +be passed in. Finally, if you want the HTML report in a different location then +you will need to pass in `--output-directory`. + +An example of all these flags being used: + +```shell +coverage_report.py --source-directory ~/pdfium/pdfium \ + --build-directory ~/pdfium/pdfium/out/Debug_with_Coverage \ + --output-directory ~/Documents/PDFium_coverage +``` + +To run different tests then the default set, there are two ways to achieve +this. If you want to run everything, including tests that are known to take a +long time, then you just need to add the `--slow` flag. + +```shell +tools/coverage/coverage_report.py --slow +``` + +If you want more fine grained control, including running just a single test, you +can specify the test names on the command line. The `--slow` flag is not needed +if you are explicitly invoking tests. The list of supported tests can be found +by running the script with `--help`. + +An example running the default tests explicitly: + +```shell +tools/coverage/coverage_report.py pdfium_unittests pdfium_embeddertests +``` + +NOTE: +At the present time, there is no mechanism for combining data from different +invocations of `coverage_report.py`. Instead you must specify all of the tests +to be included in the report in a single invocation. + +There are additional developer debugging flags available, `--dry-run` and +`--verbose`. `--dry-run` will output a trace of commands that would have been +run, but doesn't actually execute them. `--verbose` turns on outputting +additional logging information. + +### Viewing + +Once the script has run, the output directory should contain a set of HTML files +containing the coverage report. + +These files are static HTML, so you can point your browser at them directly on +your local file system and they should render fine. You can also serve them via a +web server if you want, but how to achieve that is beyond the scope of this +documentation. + +## Issues + +For help with using the code coverage tools please contact the PDFium +maintainers via the PDFium +mailing [list](https://groups.google.com/forum/#!forum/pdfium). + +Please file bugs against the code coverage +support [here](https://bugs.chromium.org/p/pdfium/issues/list). diff --git a/chromium/third_party/pdfium/fpdfsdk/cba_annotiterator.h b/chromium/third_party/pdfium/fpdfsdk/cba_annotiterator.h index 5cbe8e3d571..36eacd91c0d 100644 --- a/chromium/third_party/pdfium/fpdfsdk/cba_annotiterator.h +++ b/chromium/third_party/pdfium/fpdfsdk/cba_annotiterator.h @@ -10,6 +10,7 @@ #include <vector> #include "core/fpdfdoc/cpdf_annot.h" +#include "core/fxcrt/cfx_unowned_ptr.h" #include "core/fxcrt/fx_coordinates.h" #include "core/fxcrt/fx_string.h" @@ -37,7 +38,7 @@ class CBA_AnnotIterator { std::vector<size_t>* aSelect); TabOrder m_eTabOrder; - CPDFSDK_PageView* m_pPageView; + CFX_UnownedPtr<CPDFSDK_PageView> m_pPageView; CPDF_Annot::Subtype m_nAnnotSubtype; std::vector<CPDFSDK_Annot*> m_Annots; }; diff --git a/chromium/third_party/pdfium/fpdfsdk/cfx_systemhandler.cpp b/chromium/third_party/pdfium/fpdfsdk/cfx_systemhandler.cpp index d38c6270f71..882351145ea 100644 --- a/chromium/third_party/pdfium/fpdfsdk/cfx_systemhandler.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/cfx_systemhandler.cpp @@ -49,8 +49,7 @@ void CFX_SystemHandler::InvalidateRect(CPDFSDK_Widget* widget, FX_RECT rect) { CFX_Matrix page2device; pPageView->GetCurrentMatrix(page2device); - CFX_Matrix device2page; - device2page.SetReverse(page2device); + CFX_Matrix device2page = page2device.GetInverse(); CFX_PointF left_top = device2page.Transform( CFX_PointF(static_cast<float>(rect.left), static_cast<float>(rect.top))); diff --git a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_annot.cpp b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_annot.cpp index dcfcac92fc3..e105ed90fbe 100644 --- a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_annot.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_annot.cpp @@ -23,7 +23,7 @@ const float kMinHeight = 1.0f; } // namespace CPDFSDK_Annot::CPDFSDK_Annot(CPDFSDK_PageView* pPageView) - : m_pPageView(pPageView), m_bSelected(false) {} + : m_pPageView(pPageView) {} CPDFSDK_Annot::~CPDFSDK_Annot() {} @@ -73,18 +73,6 @@ CFX_FloatRect CPDFSDK_Annot::GetRect() const { return CFX_FloatRect(); } -void CPDFSDK_Annot::Annot_OnDraw(CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device, - CPDF_RenderOptions* pOptions) {} - -bool CPDFSDK_Annot::IsSelected() { - return m_bSelected; -} - -void CPDFSDK_Annot::SetSelected(bool bSelected) { - m_bSelected = bSelected; -} - UnderlyingPageType* CPDFSDK_Annot::GetUnderlyingPage() { #ifdef PDF_ENABLE_XFA return GetPDFXFAPage(); diff --git a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_annot.h b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_annot.h index 1053c00c13e..3ab79810510 100644 --- a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_annot.h +++ b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_annot.h @@ -11,6 +11,7 @@ #include "core/fpdfdoc/cpdf_annot.h" #include "core/fpdfdoc/cpdf_defaultappearance.h" #include "core/fxcrt/cfx_observable.h" +#include "core/fxcrt/cfx_unowned_ptr.h" #include "core/fxcrt/fx_basic.h" #include "fpdfsdk/cfx_systemhandler.h" #include "fpdfsdk/fsdk_common.h" @@ -39,11 +40,7 @@ class CPDFSDK_Annot : public CFX_Observable<CPDFSDK_Annot> { virtual CPDF_Annot::Subtype GetAnnotSubtype() const; virtual bool IsSignatureWidget() const; virtual CFX_FloatRect GetRect() const; - virtual void SetRect(const CFX_FloatRect& rect); - virtual void Annot_OnDraw(CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device, - CPDF_RenderOptions* pOptions); UnderlyingPageType* GetUnderlyingPage(); CPDF_Page* GetPDFPage(); @@ -51,15 +48,10 @@ class CPDFSDK_Annot : public CFX_Observable<CPDFSDK_Annot> { CPDFXFA_Page* GetPDFXFAPage(); #endif // PDF_ENABLE_XFA - void SetPage(CPDFSDK_PageView* pPageView); - CPDFSDK_PageView* GetPageView() const { return m_pPageView; } - - bool IsSelected(); - void SetSelected(bool bSelected); + CPDFSDK_PageView* GetPageView() const { return m_pPageView.Get(); } protected: - CPDFSDK_PageView* m_pPageView; - bool m_bSelected; + CFX_UnownedPtr<CPDFSDK_PageView> const m_pPageView; }; #endif // FPDFSDK_CPDFSDK_ANNOT_H_ diff --git a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_annothandlermgr.cpp b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_annothandlermgr.cpp index 7ea301c0e43..2b089e51854 100644 --- a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_annothandlermgr.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_annothandlermgr.cpp @@ -76,6 +76,11 @@ void CPDFSDK_AnnotHandlerMgr::Annot_OnLoad(CPDFSDK_Annot* pAnnot) { GetAnnotHandler(pAnnot)->OnLoad(pAnnot); } +CFX_WideString CPDFSDK_AnnotHandlerMgr::Annot_GetSelectedText( + CPDFSDK_Annot* pAnnot) { + return GetAnnotHandler(pAnnot)->GetSelectedText(pAnnot); +} + IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler( CPDFSDK_Annot* pAnnot) const { return GetAnnotHandler(pAnnot->GetAnnotSubtype()); diff --git a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_annothandlermgr.h b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_annothandlermgr.h index f36c3fb70e8..5f6ff94b401 100644 --- a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_annothandlermgr.h +++ b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_annothandlermgr.h @@ -43,6 +43,8 @@ class CPDFSDK_AnnotHandlerMgr { void Annot_OnCreate(CPDFSDK_Annot* pAnnot); void Annot_OnLoad(CPDFSDK_Annot* pAnnot); + CFX_WideString Annot_GetSelectedText(CPDFSDK_Annot* pAnnot); + IPDFSDK_AnnotHandler* GetAnnotHandler(CPDFSDK_Annot* pAnnot) const; void Annot_OnDraw(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, diff --git a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_baannot.cpp b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_baannot.cpp index 4f11f77f0bf..a426749fffe 100644 --- a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_baannot.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_baannot.cpp @@ -38,6 +38,13 @@ CPDF_Dictionary* CPDFSDK_BAAnnot::GetAnnotDict() const { return m_pAnnot->GetAnnotDict(); } +CPDF_Dictionary* CPDFSDK_BAAnnot::GetAPDict() const { + CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDictFor("AP"); + if (!pAPDict) + pAPDict = m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_Dictionary>("AP"); + return pAPDict; +} + void CPDFSDK_BAAnnot::SetRect(const CFX_FloatRect& rect) { ASSERT(rect.right - rect.left >= GetMinWidth()); ASSERT(rect.top - rect.bottom >= GetMinHeight()); @@ -293,50 +300,6 @@ bool CPDFSDK_BAAnnot::GetColor(FX_COLORREF& color) const { return false; } -void CPDFSDK_BAAnnot::WriteAppearance(const CFX_ByteString& sAPType, - const CFX_FloatRect& rcBBox, - const CFX_Matrix& matrix, - const CFX_ByteString& sContents, - const CFX_ByteString& sAPState) { - CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDictFor("AP"); - if (!pAPDict) - pAPDict = m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_Dictionary>("AP"); - - CPDF_Stream* pStream = nullptr; - CPDF_Dictionary* pParentDict = nullptr; - if (sAPState.IsEmpty()) { - pParentDict = pAPDict; - pStream = pAPDict->GetStreamFor(sAPType); - } else { - CPDF_Dictionary* pAPTypeDict = pAPDict->GetDictFor(sAPType); - if (!pAPTypeDict) - pAPTypeDict = pAPDict->SetNewFor<CPDF_Dictionary>(sAPType); - - pParentDict = pAPTypeDict; - pStream = pAPTypeDict->GetStreamFor(sAPState); - } - - if (!pStream) { - CPDF_Document* pDoc = m_pPageView->GetPDFDocument(); - pStream = pDoc->NewIndirect<CPDF_Stream>(); - pParentDict->SetNewFor<CPDF_Reference>(sAPType, pDoc, pStream->GetObjNum()); - } - - CPDF_Dictionary* pStreamDict = pStream->GetDict(); - if (!pStreamDict) { - auto pNewDict = pdfium::MakeUnique<CPDF_Dictionary>( - m_pAnnot->GetDocument()->GetByteStringPool()); - pStreamDict = pNewDict.get(); - pStreamDict->SetNewFor<CPDF_Name>("Type", "XObject"); - pStreamDict->SetNewFor<CPDF_Name>("Subtype", "Form"); - pStreamDict->SetNewFor<CPDF_Number>("FormType", 1); - pStream->InitStream(nullptr, 0, std::move(pNewDict)); - } - pStreamDict->SetMatrixFor("Matrix", matrix); - pStreamDict->SetRectFor("BBox", rcBBox); - pStream->SetData((uint8_t*)sContents.c_str(), sContents.GetLength()); -} - bool CPDFSDK_BAAnnot::IsVisible() const { uint32_t nFlags = GetFlags(); return !((nFlags & ANNOTFLAG_INVISIBLE) || (nFlags & ANNOTFLAG_HIDDEN) || @@ -386,14 +349,6 @@ CPDF_Action CPDFSDK_BAAnnot::GetAAction(CPDF_AAction::AActionType eAAT) { return CPDF_Action(); } -void CPDFSDK_BAAnnot::Annot_OnDraw(CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device, - CPDF_RenderOptions* pOptions) { - m_pAnnot->GetAPForm(m_pPageView->GetPDFPage(), CPDF_Annot::Normal); - m_pAnnot->DrawAppearance(m_pPageView->GetPDFPage(), pDevice, pUser2Device, - CPDF_Annot::Normal, nullptr); -} - void CPDFSDK_BAAnnot::SetOpenState(bool bOpenState) { if (CPDF_Annot* pAnnot = m_pAnnot->GetPopupAnnot()) pAnnot->SetOpenState(bOpenState); diff --git a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_baannot.h b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_baannot.h index 4bf8f73823b..18d25a1e02a 100644 --- a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_baannot.h +++ b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_baannot.h @@ -32,13 +32,12 @@ class CPDFSDK_BAAnnot : public CPDFSDK_Annot { void SetRect(const CFX_FloatRect& rect) override; CFX_FloatRect GetRect() const override; CPDF_Annot* GetPDFAnnot() const override; - void Annot_OnDraw(CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device, - CPDF_RenderOptions* pOptions) override; CPDF_Dictionary* GetAnnotDict() const; CPDF_Annot* GetPDFPopupAnnot() const; + CPDF_Dictionary* GetAPDict() const; + void SetContents(const CFX_WideString& sContents); CFX_WideString GetContents() const; @@ -91,12 +90,6 @@ class CPDFSDK_BAAnnot : public CPDFSDK_Annot { void ClearCachedAP(); - void WriteAppearance(const CFX_ByteString& sAPType, - const CFX_FloatRect& rcBBox, - const CFX_Matrix& matrix, - const CFX_ByteString& sContents, - const CFX_ByteString& sAPState = ""); - void SetOpenState(bool bState); protected: diff --git a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_baannothandler.cpp b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_baannothandler.cpp index fa83932a815..4984ee93cce 100644 --- a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_baannothandler.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_baannothandler.cpp @@ -193,6 +193,10 @@ CFX_FloatRect CPDFSDK_BAAnnotHandler::GetViewBBox(CPDFSDK_PageView* pPageView, return pAnnot->GetRect(); } +CFX_WideString CPDFSDK_BAAnnotHandler::GetSelectedText(CPDFSDK_Annot* pAnnot) { + return CFX_WideString(); +} + bool CPDFSDK_BAAnnotHandler::HitTest(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, const CFX_PointF& point) { diff --git a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_baannothandler.h b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_baannothandler.h index d5f170f4528..2af2f3ee995 100644 --- a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_baannothandler.h +++ b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_baannothandler.h @@ -37,6 +37,7 @@ class CPDFSDK_BAAnnotHandler : public IPDFSDK_AnnotHandler { void ReleaseAnnot(CPDFSDK_Annot* pAnnot) override; CFX_FloatRect GetViewBBox(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot) override; + CFX_WideString GetSelectedText(CPDFSDK_Annot* pAnnot) override; bool HitTest(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, const CFX_PointF& point) override; diff --git a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_formfillenvironment.cpp b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_formfillenvironment.cpp index 8c5025ed88c..de7947556db 100644 --- a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_formfillenvironment.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_formfillenvironment.cpp @@ -220,7 +220,7 @@ CPDFSDK_AnnotHandlerMgr* CPDFSDK_FormFillEnvironment::GetAnnotHandlerMgr() { return m_pAnnotHandlerMgr.get(); } -CPDFSDK_ActionHandler* CPDFSDK_FormFillEnvironment::GetActionHander() { +CPDFSDK_ActionHandler* CPDFSDK_FormFillEnvironment::GetActionHandler() { if (!m_pActionHandler) m_pActionHandler = pdfium::MakeUnique<CPDFSDK_ActionHandler>(); return m_pActionHandler.get(); @@ -408,10 +408,12 @@ void CPDFSDK_FormFillEnvironment::GetPageViewRect(CPDFXFA_Page* page, double right; double bottom; m_pInfo->FFI_GetPageViewRect(m_pInfo, page, &left, &top, &right, &bottom); + if (top < bottom) + std::swap(top, bottom); dstRect.left = static_cast<float>(left); - dstRect.top = static_cast<float>(top < bottom ? bottom : top); - dstRect.bottom = static_cast<float>(top < bottom ? top : bottom); + dstRect.top = static_cast<float>(top); + dstRect.bottom = static_cast<float>(bottom); dstRect.right = static_cast<float>(right); } @@ -600,15 +602,10 @@ void CPDFSDK_FormFillEnvironment::ProcJavascriptFun() { CPDF_Document* pPDFDoc = GetPDFDocument(); CPDF_DocJSActions docJS(pPDFDoc); int iCount = docJS.CountJSActions(); - if (iCount < 1) - return; for (int i = 0; i < iCount; i++) { - CFX_ByteString csJSName; + CFX_WideString csJSName; CPDF_Action jsAction = docJS.GetJSActionAndName(i, &csJSName); - if (GetActionHander()) { - GetActionHander()->DoAction_JavaScript( - jsAction, CFX_WideString::FromLocal(csJSName.AsStringC()), this); - } + GetActionHandler()->DoAction_JavaScript(jsAction, csJSName, this); } } @@ -623,20 +620,19 @@ bool CPDFSDK_FormFillEnvironment::ProcOpenAction() { CPDF_Object* pOpenAction = pRoot->GetDictFor("OpenAction"); if (!pOpenAction) pOpenAction = pRoot->GetArrayFor("OpenAction"); - if (!pOpenAction) return false; if (pOpenAction->IsArray()) return true; - if (CPDF_Dictionary* pDict = pOpenAction->AsDictionary()) { - CPDF_Action action(pDict); - if (GetActionHander()) - GetActionHander()->DoAction_DocOpen(action, this); - return true; - } - return false; + CPDF_Dictionary* pDict = pOpenAction->AsDictionary(); + if (!pDict) + return false; + + CPDF_Action action(pDict); + GetActionHandler()->DoAction_DocOpen(action, this); + return true; } void CPDFSDK_FormFillEnvironment::RemovePageView( @@ -696,59 +692,57 @@ bool CPDFSDK_FormFillEnvironment::SetFocusAnnot( if (!*pAnnot) return false; -#ifdef PDF_ENABLE_XFA - CPDFSDK_Annot::ObservedPtr pLastFocusAnnot(m_pFocusAnnot.Get()); -#endif // PDF_ENABLE_XFA CPDFSDK_PageView* pPageView = (*pAnnot)->GetPageView(); - if (pPageView && pPageView->IsValid()) { - CPDFSDK_AnnotHandlerMgr* pAnnotHandler = GetAnnotHandlerMgr(); - if (!m_pFocusAnnot) { + if (!pPageView || !pPageView->IsValid()) + return false; + + CPDFSDK_AnnotHandlerMgr* pAnnotHandler = GetAnnotHandlerMgr(); + if (m_pFocusAnnot) + return false; + #ifdef PDF_ENABLE_XFA - if (!pAnnotHandler->Annot_OnChangeFocus(pAnnot, &pLastFocusAnnot)) - return false; + CPDFSDK_Annot::ObservedPtr pLastFocusAnnot(m_pFocusAnnot.Get()); + if (!pAnnotHandler->Annot_OnChangeFocus(pAnnot, &pLastFocusAnnot)) + return false; #endif // PDF_ENABLE_XFA - if (!pAnnotHandler->Annot_OnSetFocus(pAnnot, 0)) - return false; - if (!m_pFocusAnnot) { - m_pFocusAnnot.Reset(pAnnot->Get()); - return true; - } - } - } - return false; + if (!pAnnotHandler->Annot_OnSetFocus(pAnnot, 0)) + return false; + if (m_pFocusAnnot) + return false; + + m_pFocusAnnot.Reset(pAnnot->Get()); + return true; } bool CPDFSDK_FormFillEnvironment::KillFocusAnnot(uint32_t nFlag) { - if (m_pFocusAnnot) { - CPDFSDK_AnnotHandlerMgr* pAnnotHandler = GetAnnotHandlerMgr(); - CPDFSDK_Annot::ObservedPtr pFocusAnnot(m_pFocusAnnot.Get()); - m_pFocusAnnot.Reset(); + if (!m_pFocusAnnot) + return false; + + CPDFSDK_AnnotHandlerMgr* pAnnotHandler = GetAnnotHandlerMgr(); + CPDFSDK_Annot::ObservedPtr pFocusAnnot(m_pFocusAnnot.Get()); + m_pFocusAnnot.Reset(); #ifdef PDF_ENABLE_XFA - CPDFSDK_Annot::ObservedPtr pNull; - if (!pAnnotHandler->Annot_OnChangeFocus(&pNull, &pFocusAnnot)) - return false; + CPDFSDK_Annot::ObservedPtr pNull; + if (!pAnnotHandler->Annot_OnChangeFocus(&pNull, &pFocusAnnot)) + return false; #endif // PDF_ENABLE_XFA - if (pAnnotHandler->Annot_OnKillFocus(&pFocusAnnot, nFlag)) { - if (pFocusAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::WIDGET) { - CPDFSDK_Widget* pWidget = - static_cast<CPDFSDK_Widget*>(pFocusAnnot.Get()); - int nFieldType = pWidget->GetFieldType(); - if (FIELDTYPE_TEXTFIELD == nFieldType || - FIELDTYPE_COMBOBOX == nFieldType) { - OnSetFieldInputFocus(nullptr, 0, false); - } - } - if (!m_pFocusAnnot) - return true; - } else { - m_pFocusAnnot.Reset(pFocusAnnot.Get()); + if (!pAnnotHandler->Annot_OnKillFocus(&pFocusAnnot, nFlag)) { + m_pFocusAnnot.Reset(pFocusAnnot.Get()); + return false; + } + + if (pFocusAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::WIDGET) { + CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pFocusAnnot.Get()); + int nFieldType = pWidget->GetFieldType(); + if (FIELDTYPE_TEXTFIELD == nFieldType || FIELDTYPE_COMBOBOX == nFieldType) { + OnSetFieldInputFocus(nullptr, 0, false); } } - return false; + return !m_pFocusAnnot; } -bool CPDFSDK_FormFillEnvironment::GetPermissions(int nFlag) { +bool CPDFSDK_FormFillEnvironment::GetPermissions(int nFlag) const { return !!(GetPDFDocument()->GetUserPermissions() & nFlag); } diff --git a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_formfillenvironment.h b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_formfillenvironment.h index 91141e57c66..b1e095a0c2d 100644 --- a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_formfillenvironment.h +++ b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_formfillenvironment.h @@ -67,8 +67,8 @@ class CPDFSDK_FormFillEnvironment const CPDF_Document* pSrcDoc, const std::vector<uint16_t>& arrSrcPages); - int GetPageCount() { return m_pUnderlyingDoc->GetPageCount(); } - bool GetPermissions(int nFlag); + int GetPageCount() const { return m_pUnderlyingDoc->GetPageCount(); } + bool GetPermissions(int nFlag) const; bool GetChangeMark() const { return m_bChangeMask; } void SetChangeMark() { m_bChangeMask = true; } @@ -210,7 +210,7 @@ class CPDFSDK_FormFillEnvironment CFFL_InteractiveFormFiller* GetInteractiveFormFiller(); CPDFSDK_AnnotHandlerMgr* GetAnnotHandlerMgr(); // Creates if not present. IJS_Runtime* GetJSRuntime(); // Creates if not present. - CPDFSDK_ActionHandler* GetActionHander(); // Creates if not present. + CPDFSDK_ActionHandler* GetActionHandler(); // Creates if not present. CPDFSDK_InterForm* GetInterForm(); // Creates if not present. private: diff --git a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_interform.cpp b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_interform.cpp index 76cb6fdabf3..ebbe02c29ba 100644 --- a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_interform.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_interform.cpp @@ -32,7 +32,6 @@ #include "fpdfsdk/ipdfsdk_annothandler.h" #include "fpdfsdk/javascript/ijs_event_context.h" #include "fpdfsdk/javascript/ijs_runtime.h" -#include "fpdfsdk/pdfwindow/PWL_Utils.h" #include "third_party/base/stl_util.h" #ifdef PDF_ENABLE_XFA @@ -346,7 +345,7 @@ bool CPDFSDK_InterForm::OnKeyStrokeCommit(CPDF_FormField* pFormField, if (!action.GetDict()) return true; - CPDFSDK_ActionHandler* pActionHandler = m_pFormFillEnv->GetActionHander(); + CPDFSDK_ActionHandler* pActionHandler = m_pFormFillEnv->GetActionHandler(); PDFSDK_FieldAction fa; fa.bModifier = m_pFormFillEnv->IsCTRLKeyDown(0); fa.bShift = m_pFormFillEnv->IsSHIFTKeyDown(0); @@ -366,7 +365,7 @@ bool CPDFSDK_InterForm::OnValidate(CPDF_FormField* pFormField, if (!action.GetDict()) return true; - CPDFSDK_ActionHandler* pActionHandler = m_pFormFillEnv->GetActionHander(); + CPDFSDK_ActionHandler* pActionHandler = m_pFormFillEnv->GetActionHandler(); PDFSDK_FieldAction fa; fa.bModifier = m_pFormFillEnv->IsCTRLKeyDown(0); fa.bShift = m_pFormFillEnv->IsSHIFTKeyDown(0); diff --git a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_pageview.cpp b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_pageview.cpp index 982eed1b212..4780d87780b 100644 --- a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_pageview.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_pageview.cpp @@ -26,7 +26,7 @@ #include "xfa/fxfa/cxfa_ffpageview.h" #include "xfa/fxfa/cxfa_ffwidgethandler.h" #include "xfa/fxfa/cxfa_rendercontext.h" -#include "xfa/fxgraphics/cfx_graphics.h" +#include "xfa/fxgraphics/cxfa_graphics.h" #endif // PDF_ENABLE_XFA CPDFSDK_PageView::CPDFSDK_PageView(CPDFSDK_FormFillEnvironment* pFormFillEnv, @@ -43,16 +43,12 @@ CPDFSDK_PageView::CPDFSDK_PageView(CPDFSDK_FormFillEnvironment* pFormFillEnv, m_bLocked(false), m_bBeingDestroyed(false) { CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm(); - if (pInterForm) { - CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); + CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); #ifdef PDF_ENABLE_XFA - if (page->GetPDFPage()) - pPDFInterForm->FixPageFields(page->GetPDFPage()); + if (page->GetPDFPage()) + pPDFInterForm->FixPageFields(page->GetPDFPage()); #else // PDF_ENABLE_XFA - pPDFInterForm->FixPageFields(page); -#endif // PDF_ENABLE_XFA - } -#ifndef PDF_ENABLE_XFA + pPDFInterForm->FixPageFields(page); m_page->SetView(this); #endif // PDF_ENABLE_XFA } @@ -99,7 +95,7 @@ void CPDFSDK_PageView::PageView_OnDraw(CFX_RenderDevice* pDevice, static_cast<float>(pClip.left), static_cast<float>(pClip.top), static_cast<float>(pClip.Width()), static_cast<float>(pClip.Height())); - CFX_Graphics gs(pDevice); + CXFA_Graphics gs(pDevice); gs.SetClipRect(rectClip); CXFA_FFPageView* xfaView = pPage->GetXFAPageView(); @@ -241,6 +237,16 @@ CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByXFAWidget(CXFA_FFWidget* hWidget) { } #endif // PDF_ENABLE_XFA +CFX_WideString CPDFSDK_PageView::GetSelectedText() { + if (CPDFSDK_Annot* pAnnot = GetFocusAnnot()) { + CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = + m_pFormFillEnv->GetAnnotHandlerMgr(); + return pAnnotHandlerMgr->Annot_GetSelectedText(pAnnot); + } + + return CFX_WideString(); +} + bool CPDFSDK_PageView::OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) { CPDFSDK_Annot::ObservedPtr pAnnot(GetFXWidgetAtPoint(point)); if (!pAnnot) { @@ -348,8 +354,8 @@ bool CPDFSDK_PageView::OnMouseWheel(double deltaX, CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = m_pFormFillEnv->GetAnnotHandlerMgr(); - return pAnnotHandlerMgr->Annot_OnMouseWheel(this, &pAnnot, nFlag, (int)deltaY, - point); + return pAnnotHandlerMgr->Annot_OnMouseWheel(this, &pAnnot, nFlag, + static_cast<int>(deltaY), point); } bool CPDFSDK_PageView::OnChar(int nChar, uint32_t nFlag) { @@ -385,16 +391,16 @@ void CPDFSDK_PageView::LoadFXAnnots() { CFX_RetainPtr<CPDFXFA_Page> protector(m_page); if (m_pFormFillEnv->GetXFAContext()->GetDocType() == XFA_DocType::Dynamic) { CXFA_FFPageView* pageView = m_page->GetXFAPageView(); - std::unique_ptr<IXFA_WidgetIterator> pWidgetHander( + std::unique_ptr<IXFA_WidgetIterator> pWidgetHandler( pageView->CreateWidgetIterator( XFA_TRAVERSEWAY_Form, XFA_WidgetStatus_Visible | XFA_WidgetStatus_Viewable)); - if (!pWidgetHander) { + if (!pWidgetHandler) { SetLock(false); return; } - while (CXFA_FFWidget* pXFAAnnot = pWidgetHander->MoveToNext()) { + while (CXFA_FFWidget* pXFAAnnot = pWidgetHandler->MoveToNext()) { CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pXFAAnnot, this); if (!pAnnot) continue; diff --git a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_pageview.h b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_pageview.h index 8bede08a5d1..9eebb6e424e 100644 --- a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_pageview.h +++ b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_pageview.h @@ -60,6 +60,8 @@ class CPDFSDK_PageView final : public CPDF_Page::View { return m_pFormFillEnv.Get(); } + CFX_WideString GetSelectedText(); + bool OnLButtonDown(const CFX_PointF& point, uint32_t nFlag); bool OnLButtonUp(const CFX_PointF& point, uint32_t nFlag); #ifdef PDF_ENABLE_XFA diff --git a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_widget.cpp b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_widget.cpp index a1cd8c7ce42..afc83edb076 100644 --- a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_widget.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_widget.cpp @@ -7,6 +7,7 @@ #include "fpdfsdk/cpdfsdk_widget.h" #include <memory> +#include <sstream> #include "core/fpdfapi/parser/cpdf_array.h" #include "core/fpdfapi/parser/cpdf_dictionary.h" @@ -29,8 +30,8 @@ #include "fpdfsdk/fsdk_actionhandler.h" #include "fpdfsdk/fsdk_define.h" #include "fpdfsdk/fxedit/fxet_edit.h" -#include "fpdfsdk/pdfwindow/PWL_Edit.h" -#include "fpdfsdk/pdfwindow/PWL_Utils.h" +#include "fpdfsdk/pdfwindow/cpwl_appstream.h" +#include "fpdfsdk/pdfwindow/cpwl_edit.h" #ifdef PDF_ENABLE_XFA #include "fpdfsdk/fpdfxfa/cpdfxfa_context.h" @@ -88,9 +89,8 @@ CXFA_FFWidget* CPDFSDK_Widget::GetMixXFAWidget() const { m_hMixXFAWidget = pDocView->GetWidgetByName(sName, nullptr); } } - return m_hMixXFAWidget; + return m_hMixXFAWidget.Get(); } - return nullptr; } @@ -113,10 +113,11 @@ CXFA_FFWidgetHandler* CPDFSDK_Widget::GetXFAWidgetHandler() const { return nullptr; if (!m_pWidgetHandler) { - if (CXFA_FFDocView* pDocView = pContext->GetXFADocView()) + CXFA_FFDocView* pDocView = pContext->GetXFADocView(); + if (pDocView) m_pWidgetHandler = pDocView->GetWidgetHandler(); } - return m_pWidgetHandler; + return m_pWidgetHandler.Get(); } static XFA_EVENTTYPE GetXFAEventType(PDFSDK_XFAAActionType eXFAAAT) { @@ -763,26 +764,25 @@ void CPDFSDK_Widget::ResetAppearance(const CFX_WideString* sValue, if (bValueChanged) m_nValueAge++; - int nFieldType = GetFieldType(); - - switch (nFieldType) { + CPWL_AppStream appStream(this, GetAPDict()); + switch (GetFieldType()) { case FIELDTYPE_PUSHBUTTON: - ResetAppearance_PushButton(); + appStream.SetAsPushButton(); break; case FIELDTYPE_CHECKBOX: - ResetAppearance_CheckBox(); + appStream.SetAsCheckBox(); break; case FIELDTYPE_RADIOBUTTON: - ResetAppearance_RadioButton(); + appStream.SetAsRadioButton(); break; case FIELDTYPE_COMBOBOX: - ResetAppearance_ComboBox(sValue); + appStream.SetAsComboBox(sValue); break; case FIELDTYPE_LISTBOX: - ResetAppearance_ListBox(); + appStream.SetAsListBox(); break; case FIELDTYPE_TEXTFIELD: - ResetAppearance_TextField(sValue); + appStream.SetAsTextField(sValue); break; } @@ -860,783 +860,6 @@ void CPDFSDK_Widget::DrawShadow(CFX_RenderDevice* pDevice, m_pInterForm->GetHighlightColor(nFieldType))); } -void CPDFSDK_Widget::ResetAppearance_PushButton() { - CPDF_FormControl* pControl = GetFormControl(); - CFX_FloatRect rcWindow = GetRotatedRect(); - int32_t nLayout = 0; - switch (pControl->GetTextPosition()) { - case TEXTPOS_ICON: - nLayout = PPBL_ICON; - break; - case TEXTPOS_BELOW: - nLayout = PPBL_ICONTOPLABELBOTTOM; - break; - case TEXTPOS_ABOVE: - nLayout = PPBL_LABELTOPICONBOTTOM; - break; - case TEXTPOS_RIGHT: - nLayout = PPBL_ICONLEFTLABELRIGHT; - break; - case TEXTPOS_LEFT: - nLayout = PPBL_LABELLEFTICONRIGHT; - break; - case TEXTPOS_OVERLAID: - nLayout = PPBL_LABELOVERICON; - break; - default: - nLayout = PPBL_LABEL; - break; - } - - CPWL_Color crBackground; - CPWL_Color crBorder; - int iColorType; - float fc[4]; - pControl->GetOriginalBackgroundColor(iColorType, fc); - if (iColorType > 0) - crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); - - pControl->GetOriginalBorderColor(iColorType, fc); - if (iColorType > 0) - crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); - - float fBorderWidth = (float)GetBorderWidth(); - CPWL_Dash dsBorder(3, 0, 0); - CPWL_Color crLeftTop; - CPWL_Color crRightBottom; - - BorderStyle nBorderStyle = GetBorderStyle(); - switch (nBorderStyle) { - case BorderStyle::DASH: - dsBorder = CPWL_Dash(3, 3, 0); - break; - case BorderStyle::BEVELED: - fBorderWidth *= 2; - crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1); - crRightBottom = crBackground / 2.0f; - break; - case BorderStyle::INSET: - fBorderWidth *= 2; - crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5); - crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75); - break; - default: - break; - } - - CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(rcWindow, fBorderWidth); - - CPWL_Color crText(COLORTYPE_GRAY, 0); - - CFX_ByteString csNameTag; - CPDF_DefaultAppearance da = pControl->GetDefaultAppearance(); - if (da.HasColor()) { - da.GetColor(iColorType, fc); - crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); - } - float fFontSize = 12.0f; - if (da.HasFont()) - csNameTag = da.GetFont(&fFontSize); - - CFX_WideString csWCaption; - CFX_WideString csNormalCaption; - CFX_WideString csRolloverCaption; - CFX_WideString csDownCaption; - if (pControl->HasMKEntry("CA")) - csNormalCaption = pControl->GetNormalCaption(); - - if (pControl->HasMKEntry("RC")) - csRolloverCaption = pControl->GetRolloverCaption(); - - if (pControl->HasMKEntry("AC")) - csDownCaption = pControl->GetDownCaption(); - - CPDF_Stream* pNormalIcon = nullptr; - CPDF_Stream* pRolloverIcon = nullptr; - CPDF_Stream* pDownIcon = nullptr; - if (pControl->HasMKEntry("I")) - pNormalIcon = pControl->GetNormalIcon(); - - if (pControl->HasMKEntry("RI")) - pRolloverIcon = pControl->GetRolloverIcon(); - - if (pControl->HasMKEntry("IX")) - pDownIcon = pControl->GetDownIcon(); - - if (pNormalIcon) { - if (CPDF_Dictionary* pImageDict = pNormalIcon->GetDict()) { - if (pImageDict->GetStringFor("Name").IsEmpty()) - pImageDict->SetNewFor<CPDF_String>("Name", "ImgA", false); - } - } - - if (pRolloverIcon) { - if (CPDF_Dictionary* pImageDict = pRolloverIcon->GetDict()) { - if (pImageDict->GetStringFor("Name").IsEmpty()) - pImageDict->SetNewFor<CPDF_String>("Name", "ImgB", false); - } - } - - if (pDownIcon) { - if (CPDF_Dictionary* pImageDict = pDownIcon->GetDict()) { - if (pImageDict->GetStringFor("Name").IsEmpty()) - pImageDict->SetNewFor<CPDF_String>("Name", "ImgC", false); - } - } - - CPDF_IconFit iconFit = pControl->GetIconFit(); - - CBA_FontMap font_map(this, m_pInterForm->GetFormFillEnv()->GetSysHandler()); - font_map.SetAPType("N"); - - CFX_ByteString csAP = - CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) + - CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, - crLeftTop, crRightBottom, nBorderStyle, - dsBorder) + - CPWL_Utils::GetPushButtonAppStream( - iconFit.GetFittingBounds() ? rcWindow : rcClient, &font_map, - pNormalIcon, iconFit, csNormalCaption, crText, fFontSize, nLayout); - - WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP); - if (pNormalIcon) - AddImageToAppearance("N", pNormalIcon); - - CPDF_FormControl::HighlightingMode eHLM = pControl->GetHighlightingMode(); - if (eHLM == CPDF_FormControl::Push || eHLM == CPDF_FormControl::Toggle) { - if (csRolloverCaption.IsEmpty() && !pRolloverIcon) { - csRolloverCaption = csNormalCaption; - pRolloverIcon = pNormalIcon; - } - - font_map.SetAPType("R"); - - csAP = CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) + - CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, - crLeftTop, crRightBottom, - nBorderStyle, dsBorder) + - CPWL_Utils::GetPushButtonAppStream( - iconFit.GetFittingBounds() ? rcWindow : rcClient, &font_map, - pRolloverIcon, iconFit, csRolloverCaption, crText, fFontSize, - nLayout); - - WriteAppearance("R", GetRotatedRect(), GetMatrix(), csAP); - if (pRolloverIcon) - AddImageToAppearance("R", pRolloverIcon); - - if (csDownCaption.IsEmpty() && !pDownIcon) { - csDownCaption = csNormalCaption; - pDownIcon = pNormalIcon; - } - - switch (nBorderStyle) { - case BorderStyle::BEVELED: { - CPWL_Color crTemp = crLeftTop; - crLeftTop = crRightBottom; - crRightBottom = crTemp; - break; - } - case BorderStyle::INSET: { - crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0); - crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1); - break; - } - default: - break; - } - - font_map.SetAPType("D"); - - csAP = CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground - 0.25f) + - CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, - crLeftTop, crRightBottom, - nBorderStyle, dsBorder) + - CPWL_Utils::GetPushButtonAppStream( - iconFit.GetFittingBounds() ? rcWindow : rcClient, &font_map, - pDownIcon, iconFit, csDownCaption, crText, fFontSize, nLayout); - - WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP); - if (pDownIcon) - AddImageToAppearance("D", pDownIcon); - } else { - RemoveAppearance("D"); - RemoveAppearance("R"); - } -} - -void CPDFSDK_Widget::ResetAppearance_CheckBox() { - CPDF_FormControl* pControl = GetFormControl(); - CPWL_Color crBackground, crBorder, crText; - int iColorType; - float fc[4]; - - pControl->GetOriginalBackgroundColor(iColorType, fc); - if (iColorType > 0) - crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); - - pControl->GetOriginalBorderColor(iColorType, fc); - if (iColorType > 0) - crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); - - float fBorderWidth = (float)GetBorderWidth(); - CPWL_Dash dsBorder(3, 0, 0); - CPWL_Color crLeftTop, crRightBottom; - - BorderStyle nBorderStyle = GetBorderStyle(); - switch (nBorderStyle) { - case BorderStyle::DASH: - dsBorder = CPWL_Dash(3, 3, 0); - break; - case BorderStyle::BEVELED: - fBorderWidth *= 2; - crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1); - crRightBottom = crBackground / 2.0f; - break; - case BorderStyle::INSET: - fBorderWidth *= 2; - crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5); - crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75); - break; - default: - break; - } - - CFX_FloatRect rcWindow = GetRotatedRect(); - CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(rcWindow, fBorderWidth); - CPDF_DefaultAppearance da = pControl->GetDefaultAppearance(); - if (da.HasColor()) { - da.GetColor(iColorType, fc); - crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); - } - - int32_t nStyle = 0; - CFX_WideString csWCaption = pControl->GetNormalCaption(); - if (csWCaption.GetLength() > 0) { - switch (csWCaption[0]) { - case L'l': - nStyle = PCS_CIRCLE; - break; - case L'8': - nStyle = PCS_CROSS; - break; - case L'u': - nStyle = PCS_DIAMOND; - break; - case L'n': - nStyle = PCS_SQUARE; - break; - case L'H': - nStyle = PCS_STAR; - break; - default: // L'4' - nStyle = PCS_CHECK; - break; - } - } else { - nStyle = PCS_CHECK; - } - - CFX_ByteString csAP_N_ON = - CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) + - CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, - crLeftTop, crRightBottom, nBorderStyle, - dsBorder); - - CFX_ByteString csAP_N_OFF = csAP_N_ON; - - switch (nBorderStyle) { - case BorderStyle::BEVELED: { - CPWL_Color crTemp = crLeftTop; - crLeftTop = crRightBottom; - crRightBottom = crTemp; - break; - } - case BorderStyle::INSET: { - crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0); - crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1); - break; - } - default: - break; - } - - CFX_ByteString csAP_D_ON = - CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground - 0.25f) + - CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, - crLeftTop, crRightBottom, nBorderStyle, - dsBorder); - - CFX_ByteString csAP_D_OFF = csAP_D_ON; - - csAP_N_ON += CPWL_Utils::GetCheckBoxAppStream(rcClient, nStyle, crText); - csAP_D_ON += CPWL_Utils::GetCheckBoxAppStream(rcClient, nStyle, crText); - - WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_ON, - pControl->GetCheckedAPState()); - WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_OFF, "Off"); - - WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_ON, - pControl->GetCheckedAPState()); - WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_OFF, "Off"); - - CFX_ByteString csAS = GetAppState(); - if (csAS.IsEmpty()) - SetAppState("Off"); -} - -void CPDFSDK_Widget::ResetAppearance_RadioButton() { - CPDF_FormControl* pControl = GetFormControl(); - CPWL_Color crBackground, crBorder, crText; - int iColorType; - float fc[4]; - - pControl->GetOriginalBackgroundColor(iColorType, fc); - if (iColorType > 0) - crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); - - pControl->GetOriginalBorderColor(iColorType, fc); - if (iColorType > 0) - crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); - - float fBorderWidth = (float)GetBorderWidth(); - CPWL_Dash dsBorder(3, 0, 0); - CPWL_Color crLeftTop; - CPWL_Color crRightBottom; - BorderStyle nBorderStyle = GetBorderStyle(); - switch (nBorderStyle) { - case BorderStyle::DASH: - dsBorder = CPWL_Dash(3, 3, 0); - break; - case BorderStyle::BEVELED: - fBorderWidth *= 2; - crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1); - crRightBottom = crBackground / 2.0f; - break; - case BorderStyle::INSET: - fBorderWidth *= 2; - crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5); - crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75); - break; - default: - break; - } - - CFX_FloatRect rcWindow = GetRotatedRect(); - CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(rcWindow, fBorderWidth); - - CPDF_DefaultAppearance da = pControl->GetDefaultAppearance(); - if (da.HasColor()) { - da.GetColor(iColorType, fc); - crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); - } - - int32_t nStyle = 0; - CFX_WideString csWCaption = pControl->GetNormalCaption(); - if (csWCaption.GetLength() > 0) { - switch (csWCaption[0]) { - default: // L'l': - nStyle = PCS_CIRCLE; - break; - case L'8': - nStyle = PCS_CROSS; - break; - case L'u': - nStyle = PCS_DIAMOND; - break; - case L'n': - nStyle = PCS_SQUARE; - break; - case L'H': - nStyle = PCS_STAR; - break; - case L'4': - nStyle = PCS_CHECK; - break; - } - } else { - nStyle = PCS_CIRCLE; - } - - CFX_ByteString csAP_N_ON; - - CFX_FloatRect rcCenter = - CPWL_Utils::DeflateRect(CPWL_Utils::GetCenterSquare(rcWindow), 1.0f); - - if (nStyle == PCS_CIRCLE) { - if (nBorderStyle == BorderStyle::BEVELED) { - crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1); - crRightBottom = crBackground - 0.25f; - } else if (nBorderStyle == BorderStyle::INSET) { - crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5f); - crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75f); - } - - csAP_N_ON = CPWL_Utils::GetCircleFillAppStream(rcCenter, crBackground) + - CPWL_Utils::GetCircleBorderAppStream( - rcCenter, fBorderWidth, crBorder, crLeftTop, crRightBottom, - nBorderStyle, dsBorder); - } else { - csAP_N_ON = CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) + - CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, - crLeftTop, crRightBottom, - nBorderStyle, dsBorder); - } - - CFX_ByteString csAP_N_OFF = csAP_N_ON; - - switch (nBorderStyle) { - case BorderStyle::BEVELED: { - CPWL_Color crTemp = crLeftTop; - crLeftTop = crRightBottom; - crRightBottom = crTemp; - break; - } - case BorderStyle::INSET: { - crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0); - crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1); - break; - } - default: - break; - } - - CFX_ByteString csAP_D_ON; - - if (nStyle == PCS_CIRCLE) { - CPWL_Color crBK = crBackground - 0.25f; - if (nBorderStyle == BorderStyle::BEVELED) { - crLeftTop = crBackground - 0.25f; - crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1); - crBK = crBackground; - } else if (nBorderStyle == BorderStyle::INSET) { - crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0); - crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1); - } - - csAP_D_ON = CPWL_Utils::GetCircleFillAppStream(rcCenter, crBK) + - CPWL_Utils::GetCircleBorderAppStream( - rcCenter, fBorderWidth, crBorder, crLeftTop, crRightBottom, - nBorderStyle, dsBorder); - } else { - csAP_D_ON = - CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground - 0.25f) + - CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, - crLeftTop, crRightBottom, nBorderStyle, - dsBorder); - } - - CFX_ByteString csAP_D_OFF = csAP_D_ON; - - csAP_N_ON += CPWL_Utils::GetRadioButtonAppStream(rcClient, nStyle, crText); - csAP_D_ON += CPWL_Utils::GetRadioButtonAppStream(rcClient, nStyle, crText); - - WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_ON, - pControl->GetCheckedAPState()); - WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_OFF, "Off"); - - WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_ON, - pControl->GetCheckedAPState()); - WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_OFF, "Off"); - - CFX_ByteString csAS = GetAppState(); - if (csAS.IsEmpty()) - SetAppState("Off"); -} - -void CPDFSDK_Widget::ResetAppearance_ComboBox(const CFX_WideString* sValue) { - CPDF_FormControl* pControl = GetFormControl(); - CPDF_FormField* pField = pControl->GetField(); - CFX_ByteTextBuf sBody, sLines; - - CFX_FloatRect rcClient = GetClientRect(); - CFX_FloatRect rcButton = rcClient; - rcButton.left = rcButton.right - 13; - rcButton.Normalize(); - - auto pEdit = pdfium::MakeUnique<CFX_Edit>(); - pEdit->EnableRefresh(false); - - CBA_FontMap font_map(this, m_pInterForm->GetFormFillEnv()->GetSysHandler()); - pEdit->SetFontMap(&font_map); - - CFX_FloatRect rcEdit = rcClient; - rcEdit.right = rcButton.left; - rcEdit.Normalize(); - - pEdit->SetPlateRect(rcEdit); - pEdit->SetAlignmentV(1, true); - - float fFontSize = GetFontSize(); - if (IsFloatZero(fFontSize)) - pEdit->SetAutoFontSize(true, true); - else - pEdit->SetFontSize(fFontSize); - - pEdit->Initialize(); - - if (sValue) { - pEdit->SetText(*sValue); - } else { - int32_t nCurSel = pField->GetSelectedIndex(0); - if (nCurSel < 0) - pEdit->SetText(pField->GetValue()); - else - pEdit->SetText(pField->GetOptionLabel(nCurSel)); - } - - CFX_FloatRect rcContent = pEdit->GetContentRect(); - - CFX_ByteString sEdit = - CPWL_Utils::GetEditAppStream(pEdit.get(), CFX_PointF()); - if (sEdit.GetLength() > 0) { - sBody << "/Tx BMC\n" - << "q\n"; - if (rcContent.Width() > rcEdit.Width() || - rcContent.Height() > rcEdit.Height()) { - sBody << rcEdit.left << " " << rcEdit.bottom << " " << rcEdit.Width() - << " " << rcEdit.Height() << " re\nW\nn\n"; - } - - CPWL_Color crText = GetTextPWLColor(); - sBody << "BT\n" - << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n" - << "Q\nEMC\n"; - } - - sBody << CPWL_Utils::GetDropButtonAppStream(rcButton); - - CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + - sLines.AsStringC() + sBody.AsStringC(); - - WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP); -} - -void CPDFSDK_Widget::ResetAppearance_ListBox() { - CPDF_FormControl* pControl = GetFormControl(); - CPDF_FormField* pField = pControl->GetField(); - CFX_FloatRect rcClient = GetClientRect(); - CFX_ByteTextBuf sBody, sLines; - - auto pEdit = pdfium::MakeUnique<CFX_Edit>(); - pEdit->EnableRefresh(false); - - CBA_FontMap font_map(this, m_pInterForm->GetFormFillEnv()->GetSysHandler()); - pEdit->SetFontMap(&font_map); - - pEdit->SetPlateRect(CFX_FloatRect(rcClient.left, 0.0f, rcClient.right, 0.0f)); - - float fFontSize = GetFontSize(); - - pEdit->SetFontSize(IsFloatZero(fFontSize) ? 12.0f : fFontSize); - - pEdit->Initialize(); - - CFX_ByteTextBuf sList; - float fy = rcClient.top; - - int32_t nTop = pField->GetTopVisibleIndex(); - int32_t nCount = pField->CountOptions(); - int32_t nSelCount = pField->CountSelectedItems(); - - for (int32_t i = nTop; i < nCount; ++i) { - bool bSelected = false; - for (int32_t j = 0; j < nSelCount; ++j) { - if (pField->GetSelectedIndex(j) == i) { - bSelected = true; - break; - } - } - - pEdit->SetText(pField->GetOptionLabel(i)); - - CFX_FloatRect rcContent = pEdit->GetContentRect(); - float fItemHeight = rcContent.Height(); - - if (bSelected) { - CFX_FloatRect rcItem = - CFX_FloatRect(rcClient.left, fy - fItemHeight, rcClient.right, fy); - sList << "q\n" - << CPWL_Utils::GetColorAppStream( - CPWL_Color(COLORTYPE_RGB, 0, 51.0f / 255.0f, - 113.0f / 255.0f), - true) - << rcItem.left << " " << rcItem.bottom << " " << rcItem.Width() - << " " << rcItem.Height() << " re f\n" - << "Q\n"; - - sList << "BT\n" - << CPWL_Utils::GetColorAppStream(CPWL_Color(COLORTYPE_GRAY, 1), - true) - << CPWL_Utils::GetEditAppStream(pEdit.get(), CFX_PointF(0.0f, fy)) - << "ET\n"; - } else { - CPWL_Color crText = GetTextPWLColor(); - sList << "BT\n" - << CPWL_Utils::GetColorAppStream(crText, true) - << CPWL_Utils::GetEditAppStream(pEdit.get(), CFX_PointF(0.0f, fy)) - << "ET\n"; - } - - fy -= fItemHeight; - } - - if (sList.GetSize() > 0) { - sBody << "/Tx BMC\n" - << "q\n" - << rcClient.left << " " << rcClient.bottom << " " << rcClient.Width() - << " " << rcClient.Height() << " re\nW\nn\n"; - sBody << sList << "Q\nEMC\n"; - } - - CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + - sLines.AsStringC() + sBody.AsStringC(); - - WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP); -} - -void CPDFSDK_Widget::ResetAppearance_TextField(const CFX_WideString* sValue) { - CPDF_FormControl* pControl = GetFormControl(); - CPDF_FormField* pField = pControl->GetField(); - CFX_ByteTextBuf sBody, sLines; - - auto pEdit = pdfium::MakeUnique<CFX_Edit>(); - pEdit->EnableRefresh(false); - - CBA_FontMap font_map(this, m_pInterForm->GetFormFillEnv()->GetSysHandler()); - pEdit->SetFontMap(&font_map); - - CFX_FloatRect rcClient = GetClientRect(); - pEdit->SetPlateRect(rcClient); - pEdit->SetAlignmentH(pControl->GetControlAlignment(), true); - - uint32_t dwFieldFlags = pField->GetFieldFlags(); - bool bMultiLine = (dwFieldFlags >> 12) & 1; - - if (bMultiLine) { - pEdit->SetMultiLine(true, true); - pEdit->SetAutoReturn(true, true); - } else { - pEdit->SetAlignmentV(1, true); - } - - uint16_t subWord = 0; - if ((dwFieldFlags >> 13) & 1) { - subWord = '*'; - pEdit->SetPasswordChar(subWord, true); - } - - int nMaxLen = pField->GetMaxLen(); - bool bCharArray = (dwFieldFlags >> 24) & 1; - float fFontSize = GetFontSize(); - -#ifdef PDF_ENABLE_XFA - CFX_WideString sValueTmp; - if (!sValue && GetMixXFAWidget()) { - sValueTmp = GetValue(true); - sValue = &sValueTmp; - } -#endif // PDF_ENABLE_XFA - - if (nMaxLen > 0) { - if (bCharArray) { - pEdit->SetCharArray(nMaxLen); - - if (IsFloatZero(fFontSize)) { - fFontSize = CPWL_Edit::GetCharArrayAutoFontSize(font_map.GetPDFFont(0), - rcClient, nMaxLen); - } - } else { - if (sValue) - nMaxLen = sValue->GetLength(); - pEdit->SetLimitChar(nMaxLen); - } - } - - if (IsFloatZero(fFontSize)) - pEdit->SetAutoFontSize(true, true); - else - pEdit->SetFontSize(fFontSize); - - pEdit->Initialize(); - pEdit->SetText(sValue ? *sValue : pField->GetValue()); - - CFX_FloatRect rcContent = pEdit->GetContentRect(); - CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream( - pEdit.get(), CFX_PointF(), nullptr, !bCharArray, subWord); - - if (sEdit.GetLength() > 0) { - sBody << "/Tx BMC\n" - << "q\n"; - if (rcContent.Width() > rcClient.Width() || - rcContent.Height() > rcClient.Height()) { - sBody << rcClient.left << " " << rcClient.bottom << " " - << rcClient.Width() << " " << rcClient.Height() << " re\nW\nn\n"; - } - CPWL_Color crText = GetTextPWLColor(); - sBody << "BT\n" - << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n" - << "Q\nEMC\n"; - } - - if (bCharArray) { - switch (GetBorderStyle()) { - case BorderStyle::SOLID: { - CFX_ByteString sColor = - CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), false); - if (sColor.GetLength() > 0) { - sLines << "q\n" - << GetBorderWidth() << " w\n" - << CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), false) - << " 2 J 0 j\n"; - - for (int32_t i = 1; i < nMaxLen; ++i) { - sLines << rcClient.left + - ((rcClient.right - rcClient.left) / nMaxLen) * i - << " " << rcClient.bottom << " m\n" - << rcClient.left + - ((rcClient.right - rcClient.left) / nMaxLen) * i - << " " << rcClient.top << " l S\n"; - } - - sLines << "Q\n"; - } - break; - } - case BorderStyle::DASH: { - CFX_ByteString sColor = - CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), false); - if (sColor.GetLength() > 0) { - CPWL_Dash dsBorder = CPWL_Dash(3, 3, 0); - - sLines << "q\n" - << GetBorderWidth() << " w\n" - << CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), false) - << "[" << dsBorder.nDash << " " << dsBorder.nGap << "] " - << dsBorder.nPhase << " d\n"; - - for (int32_t i = 1; i < nMaxLen; ++i) { - sLines << rcClient.left + - ((rcClient.right - rcClient.left) / nMaxLen) * i - << " " << rcClient.bottom << " m\n" - << rcClient.left + - ((rcClient.right - rcClient.left) / nMaxLen) * i - << " " << rcClient.top << " l S\n"; - } - - sLines << "Q\n"; - } - break; - } - default: - break; - } - } - - CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + - sLines.AsStringC() + sBody.AsStringC(); - WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP); -} - CFX_FloatRect CPDFSDK_Widget::GetClientRect() const { CFX_FloatRect rcWindow = GetRotatedRect(); float fBorderWidth = (float)GetBorderWidth(); @@ -1648,8 +871,7 @@ CFX_FloatRect CPDFSDK_Widget::GetClientRect() const { default: break; } - - return CPWL_Utils::DeflateRect(rcWindow, fBorderWidth); + return rcWindow.GetDeflated(fBorderWidth, fBorderWidth); } CFX_FloatRect CPDFSDK_Widget::GetRotatedRect() const { @@ -1674,47 +896,6 @@ CFX_FloatRect CPDFSDK_Widget::GetRotatedRect() const { return rcPDFWindow; } -CFX_ByteString CPDFSDK_Widget::GetBackgroundAppStream() const { - CPWL_Color crBackground = GetFillPWLColor(); - if (crBackground.nColorType != COLORTYPE_TRANSPARENT) - return CPWL_Utils::GetRectFillAppStream(GetRotatedRect(), crBackground); - - return ""; -} - -CFX_ByteString CPDFSDK_Widget::GetBorderAppStream() const { - CFX_FloatRect rcWindow = GetRotatedRect(); - CPWL_Color crBorder = GetBorderPWLColor(); - CPWL_Color crBackground = GetFillPWLColor(); - CPWL_Color crLeftTop, crRightBottom; - - float fBorderWidth = (float)GetBorderWidth(); - CPWL_Dash dsBorder(3, 0, 0); - - BorderStyle nBorderStyle = GetBorderStyle(); - switch (nBorderStyle) { - case BorderStyle::DASH: - dsBorder = CPWL_Dash(3, 3, 0); - break; - case BorderStyle::BEVELED: - fBorderWidth *= 2; - crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1); - crRightBottom = crBackground / 2.0f; - break; - case BorderStyle::INSET: - fBorderWidth *= 2; - crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5); - crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75); - break; - default: - break; - } - - return CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, - crLeftTop, crRightBottom, nBorderStyle, - dsBorder); -} - CFX_Matrix CPDFSDK_Widget::GetMatrix() const { CFX_Matrix mt; CPDF_FormControl* pControl = GetFormControl(); @@ -1723,9 +904,8 @@ CFX_Matrix CPDFSDK_Widget::GetMatrix() const { float fHeight = rcAnnot.top - rcAnnot.bottom; switch (abs(pControl->GetRotation() % 360)) { - case 0: default: - mt = CFX_Matrix(1, 0, 0, 1, 0, 0); + case 0: break; case 90: mt = CFX_Matrix(0, 1, -1, 0, fWidth, 0); @@ -1741,8 +921,8 @@ CFX_Matrix CPDFSDK_Widget::GetMatrix() const { return mt; } -CPWL_Color CPDFSDK_Widget::GetTextPWLColor() const { - CPWL_Color crText = CPWL_Color(COLORTYPE_GRAY, 0); +CFX_Color CPDFSDK_Widget::GetTextPWLColor() const { + CFX_Color crText = CFX_Color(COLORTYPE_GRAY, 0); CPDF_FormControl* pFormCtrl = GetFormControl(); CPDF_DefaultAppearance da = pFormCtrl->GetDefaultAppearance(); @@ -1750,66 +930,38 @@ CPWL_Color CPDFSDK_Widget::GetTextPWLColor() const { int32_t iColorType; float fc[4]; da.GetColor(iColorType, fc); - crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); + crText = CFX_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); } return crText; } -CPWL_Color CPDFSDK_Widget::GetBorderPWLColor() const { - CPWL_Color crBorder; +CFX_Color CPDFSDK_Widget::GetBorderPWLColor() const { + CFX_Color crBorder; CPDF_FormControl* pFormCtrl = GetFormControl(); int32_t iColorType; float fc[4]; pFormCtrl->GetOriginalBorderColor(iColorType, fc); if (iColorType > 0) - crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); + crBorder = CFX_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); return crBorder; } -CPWL_Color CPDFSDK_Widget::GetFillPWLColor() const { - CPWL_Color crFill; +CFX_Color CPDFSDK_Widget::GetFillPWLColor() const { + CFX_Color crFill; CPDF_FormControl* pFormCtrl = GetFormControl(); int32_t iColorType; float fc[4]; pFormCtrl->GetOriginalBackgroundColor(iColorType, fc); if (iColorType > 0) - crFill = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); + crFill = CFX_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); return crFill; } -void CPDFSDK_Widget::AddImageToAppearance(const CFX_ByteString& sAPType, - CPDF_Stream* pImage) { - CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDictFor("AP"); - CPDF_Stream* pStream = pAPDict->GetStreamFor(sAPType); - CPDF_Dictionary* pStreamDict = pStream->GetDict(); - CFX_ByteString sImageAlias = "IMG"; - - if (CPDF_Dictionary* pImageDict = pImage->GetDict()) { - sImageAlias = pImageDict->GetStringFor("Name"); - if (sImageAlias.IsEmpty()) - sImageAlias = "IMG"; - } - - CPDF_Document* pDoc = m_pPageView->GetPDFDocument(); - CPDF_Dictionary* pStreamResList = pStreamDict->GetDictFor("Resources"); - if (!pStreamResList) - pStreamResList = pStreamDict->SetNewFor<CPDF_Dictionary>("Resources"); - - CPDF_Dictionary* pXObject = - pStreamResList->SetNewFor<CPDF_Dictionary>("XObject"); - pXObject->SetNewFor<CPDF_Reference>(sImageAlias, pDoc, pImage->GetObjNum()); -} - -void CPDFSDK_Widget::RemoveAppearance(const CFX_ByteString& sAPType) { - if (CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDictFor("AP")) - pAPDict->RemoveFor(sAPType); -} - bool CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type, PDFSDK_FieldAction& data, CPDFSDK_PageView* pPageView) { @@ -1856,7 +1008,7 @@ bool CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type, CPDF_Action action = GetAAction(type); if (action.GetDict() && action.GetType() != CPDF_Action::Unknown) { - CPDFSDK_ActionHandler* pActionHandler = pFormFillEnv->GetActionHander(); + CPDFSDK_ActionHandler* pActionHandler = pFormFillEnv->GetActionHandler(); return pActionHandler->DoAction_Field(action, type, pFormFillEnv, GetFormField(), data); } diff --git a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_widget.h b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_widget.h index a5e5b702dc3..954369da1da 100644 --- a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_widget.h +++ b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_widget.h @@ -12,11 +12,12 @@ #include "core/fpdfdoc/cpdf_aaction.h" #include "core/fpdfdoc/cpdf_action.h" #include "core/fpdfdoc/cpdf_annot.h" +#include "core/fxcrt/cfx_unowned_ptr.h" #include "core/fxcrt/fx_coordinates.h" #include "core/fxcrt/fx_string.h" +#include "core/fxge/cfx_color.h" #include "fpdfsdk/cpdfsdk_baannot.h" #include "fpdfsdk/pdfsdk_fieldaction.h" -#include "fpdfsdk/pdfwindow/cpwl_color.h" class CFX_RenderDevice; class CPDF_Annot; @@ -138,36 +139,22 @@ class CPDFSDK_Widget : public CPDFSDK_BAAnnot { CPDF_Annot::AppearanceMode mode, const CPDF_RenderOptions* pOptions) override; - private: - void ResetAppearance_PushButton(); - void ResetAppearance_CheckBox(); - void ResetAppearance_RadioButton(); - void ResetAppearance_ComboBox(const CFX_WideString* sValue); - void ResetAppearance_ListBox(); - void ResetAppearance_TextField(const CFX_WideString* sValue); - + CFX_Matrix GetMatrix() const; CFX_FloatRect GetClientRect() const; CFX_FloatRect GetRotatedRect() const; + CFX_Color GetTextPWLColor() const; + CFX_Color GetBorderPWLColor() const; + CFX_Color GetFillPWLColor() const; - CFX_ByteString GetBackgroundAppStream() const; - CFX_ByteString GetBorderAppStream() const; - CFX_Matrix GetMatrix() const; - - CPWL_Color GetTextPWLColor() const; - CPWL_Color GetBorderPWLColor() const; - CPWL_Color GetFillPWLColor() const; - - void AddImageToAppearance(const CFX_ByteString& sAPType, CPDF_Stream* pImage); - void RemoveAppearance(const CFX_ByteString& sAPType); - + private: CFX_UnownedPtr<CPDFSDK_InterForm> const m_pInterForm; bool m_bAppModified; int32_t m_nAppAge; int32_t m_nValueAge; #ifdef PDF_ENABLE_XFA - mutable CXFA_FFWidget* m_hMixXFAWidget; - mutable CXFA_FFWidgetHandler* m_pWidgetHandler; + mutable CFX_UnownedPtr<CXFA_FFWidget> m_hMixXFAWidget; + mutable CFX_UnownedPtr<CXFA_FFWidgetHandler> m_pWidgetHandler; #endif // PDF_ENABLE_XFA }; diff --git a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_widgethandler.cpp b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_widgethandler.cpp index 1e63f5ecc65..6092500526c 100644 --- a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_widgethandler.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_widgethandler.cpp @@ -229,7 +229,11 @@ void CPDFSDK_WidgetHandler::OnLoad(CPDFSDK_Annot* pAnnot) { int nFieldType = pWidget->GetFieldType(); if (nFieldType == FIELDTYPE_TEXTFIELD || nFieldType == FIELDTYPE_COMBOBOX) { bool bFormatted = false; + CPDFSDK_Annot::ObservedPtr pObserved(pWidget); CFX_WideString sValue = pWidget->OnFormat(bFormatted); + if (!pObserved) + return; + if (bFormatted && nFieldType == FIELDTYPE_COMBOBOX) pWidget->ResetAppearance(&sValue, false); } @@ -272,8 +276,14 @@ CFX_FloatRect CPDFSDK_WidgetHandler::GetViewBBox(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot) { if (!pAnnot->IsSignatureWidget() && m_pFormFiller) return CFX_FloatRect(m_pFormFiller->GetViewBBox(pPageView, pAnnot)); + return CFX_FloatRect(); +} + +CFX_WideString CPDFSDK_WidgetHandler::GetSelectedText(CPDFSDK_Annot* pAnnot) { + if (!pAnnot->IsSignatureWidget() && m_pFormFiller) + return m_pFormFiller->GetSelectedText(pAnnot); - return CFX_FloatRect(0, 0, 0, 0); + return CFX_WideString(); } bool CPDFSDK_WidgetHandler::HitTest(CPDFSDK_PageView* pPageView, diff --git a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_widgethandler.h b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_widgethandler.h index a772471418f..9ef190f54dd 100644 --- a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_widgethandler.h +++ b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_widgethandler.h @@ -38,6 +38,7 @@ class CPDFSDK_WidgetHandler : public IPDFSDK_AnnotHandler { void ReleaseAnnot(CPDFSDK_Annot* pAnnot) override; CFX_FloatRect GetViewBBox(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot) override; + CFX_WideString GetSelectedText(CPDFSDK_Annot* pAnnot) override; bool HitTest(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, const CFX_PointF& point) override; @@ -100,11 +101,13 @@ class CPDFSDK_WidgetHandler : public IPDFSDK_AnnotHandler { void SetFormFiller(CFFL_InteractiveFormFiller* pFiller) { m_pFormFiller = pFiller; } - CFFL_InteractiveFormFiller* GetFormFiller() { return m_pFormFiller; } + CFFL_InteractiveFormFiller* GetFormFiller() const { + return m_pFormFiller.Get(); + } private: CFX_UnownedPtr<CPDFSDK_FormFillEnvironment> const m_pFormFillEnv; - CFFL_InteractiveFormFiller* m_pFormFiller; + CFX_UnownedPtr<CFFL_InteractiveFormFiller> m_pFormFiller; }; #endif // FPDFSDK_CPDFSDK_WIDGETHANDLER_H_ diff --git a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_xfawidget.cpp b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_xfawidget.cpp index 902ff2a2e8d..af08023ef85 100644 --- a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_xfawidget.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_xfawidget.cpp @@ -16,12 +16,14 @@ CPDFSDK_XFAWidget::CPDFSDK_XFAWidget(CXFA_FFWidget* pAnnot, m_pInterForm(pInterForm), m_hXFAWidget(pAnnot) {} +CPDFSDK_XFAWidget::~CPDFSDK_XFAWidget() {} + bool CPDFSDK_XFAWidget::IsXFAField() { return true; } CXFA_FFWidget* CPDFSDK_XFAWidget::GetXFAWidget() const { - return m_hXFAWidget; + return m_hXFAWidget.Get(); } CPDF_Annot::Subtype CPDFSDK_XFAWidget::GetAnnotSubtype() const { diff --git a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_xfawidget.h b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_xfawidget.h index 9d0be75f13a..42448b804f3 100644 --- a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_xfawidget.h +++ b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_xfawidget.h @@ -7,6 +7,7 @@ #ifndef FPDFSDK_CPDFSDK_XFAWIDGET_H_ #define FPDFSDK_CPDFSDK_XFAWIDGET_H_ +#include "core/fxcrt/cfx_unowned_ptr.h" #include "core/fxcrt/fx_coordinates.h" #include "core/fxcrt/fx_string.h" #include "fpdfsdk/cpdfsdk_annot.h" @@ -20,18 +21,19 @@ class CPDFSDK_XFAWidget : public CPDFSDK_Annot { CPDFSDK_XFAWidget(CXFA_FFWidget* pAnnot, CPDFSDK_PageView* pPageView, CPDFSDK_InterForm* pInterForm); - ~CPDFSDK_XFAWidget() override {} + ~CPDFSDK_XFAWidget() override; + // CPDFSDK_Annot: bool IsXFAField() override; CXFA_FFWidget* GetXFAWidget() const override; CPDF_Annot::Subtype GetAnnotSubtype() const override; CFX_FloatRect GetRect() const override; - CPDFSDK_InterForm* GetInterForm() { return m_pInterForm; } + CPDFSDK_InterForm* GetInterForm() const { return m_pInterForm.Get(); } private: - CPDFSDK_InterForm* m_pInterForm; - CXFA_FFWidget* m_hXFAWidget; + CFX_UnownedPtr<CPDFSDK_InterForm> m_pInterForm; + CFX_UnownedPtr<CXFA_FFWidget> m_hXFAWidget; }; #endif // FPDFSDK_CPDFSDK_XFAWIDGET_H_ diff --git a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_xfawidgethandler.cpp b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_xfawidgethandler.cpp index 5e258bc4e56..aa4c0f170ae 100644 --- a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_xfawidgethandler.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_xfawidgethandler.cpp @@ -20,7 +20,7 @@ #include "xfa/fxfa/cxfa_ffwidget.h" #include "xfa/fxfa/cxfa_ffwidgethandler.h" #include "xfa/fxfa/fxfa_basic.h" -#include "xfa/fxgraphics/cfx_graphics.h" +#include "xfa/fxgraphics/cxfa_graphics.h" CPDFSDK_XFAWidgetHandler::CPDFSDK_XFAWidgetHandler( CPDFSDK_FormFillEnvironment* pFormFillEnv) @@ -53,7 +53,7 @@ void CPDFSDK_XFAWidgetHandler::OnDraw(CPDFSDK_PageView* pPageView, ASSERT(pPageView); ASSERT(pAnnot); - CFX_Graphics gs(pDevice); + CXFA_Graphics gs(pDevice); CFX_Matrix mt = *pUser2Device; bool bIsHighlight = false; @@ -97,6 +97,11 @@ CFX_FloatRect CPDFSDK_XFAWidgetHandler::GetViewBBox(CPDFSDK_PageView* pPageView, return rcWidget; } +CFX_WideString CPDFSDK_XFAWidgetHandler::GetSelectedText( + CPDFSDK_Annot* pAnnot) { + return CFX_WideString(); +} + bool CPDFSDK_XFAWidgetHandler::HitTest(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, const CFX_PointF& point) { diff --git a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_xfawidgethandler.h b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_xfawidgethandler.h index 2aea49b366b..65e5e452d2b 100644 --- a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_xfawidgethandler.h +++ b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_xfawidgethandler.h @@ -33,6 +33,7 @@ class CPDFSDK_XFAWidgetHandler : public IPDFSDK_AnnotHandler { void ReleaseAnnot(CPDFSDK_Annot* pAnnot) override; CFX_FloatRect GetViewBBox(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot) override; + CFX_WideString GetSelectedText(CPDFSDK_Annot* pAnnot) override; bool HitTest(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, const CFX_PointF& point) override; diff --git a/chromium/third_party/pdfium/fpdfsdk/formfiller/cba_fontmap.h b/chromium/third_party/pdfium/fpdfsdk/formfiller/cba_fontmap.h index 14aabe4d2a1..17b7b4e9891 100644 --- a/chromium/third_party/pdfium/fpdfsdk/formfiller/cba_fontmap.h +++ b/chromium/third_party/pdfium/fpdfsdk/formfiller/cba_fontmap.h @@ -8,7 +8,7 @@ #define FPDFSDK_FORMFILLER_CBA_FONTMAP_H_ #include "core/fxcrt/cfx_unowned_ptr.h" -#include "fpdfsdk/pdfwindow/PWL_FontMap.h" +#include "fpdfsdk/pdfwindow/cpwl_font_map.h" class CPDF_Dictionary; class CPDFSDK_Annot; diff --git a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_button.cpp b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_button.cpp new file mode 100644 index 00000000000..2a290ed2131 --- /dev/null +++ b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_button.cpp @@ -0,0 +1,101 @@ +// Copyright 2017 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 "fpdfsdk/formfiller/cffl_button.h" + +CFFL_Button::CFFL_Button(CPDFSDK_FormFillEnvironment* pApp, + CPDFSDK_Widget* pWidget) + : CFFL_FormFiller(pApp, pWidget), m_bMouseIn(false), m_bMouseDown(false) {} + +CFFL_Button::~CFFL_Button() {} + +void CFFL_Button::OnMouseEnter(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot) { + m_bMouseIn = true; + InvalidateRect(GetViewBBox(pPageView, pAnnot)); +} + +void CFFL_Button::OnMouseExit(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot) { + m_bMouseIn = false; + InvalidateRect(GetViewBBox(pPageView, pAnnot)); + EndTimer(); + ASSERT(m_pWidget); +} + +bool CFFL_Button::OnLButtonDown(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlags, + const CFX_PointF& point) { + if (!pAnnot->GetRect().Contains(point)) + return false; + + m_bMouseDown = true; + m_bValid = true; + InvalidateRect(GetViewBBox(pPageView, pAnnot)); + return true; +} + +bool CFFL_Button::OnLButtonUp(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlags, + const CFX_PointF& point) { + if (!pAnnot->GetRect().Contains(point)) + return false; + + m_bMouseDown = false; + m_pWidget->GetPDFPage(); + InvalidateRect(GetViewBBox(pPageView, pAnnot)); + return true; +} + +bool CFFL_Button::OnMouseMove(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlags, + const CFX_PointF& point) { + return true; +} + +void CFFL_Button::OnDraw(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device) { + ASSERT(pPageView); + CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot); + CPDF_FormControl* pCtrl = pWidget->GetFormControl(); + if (pCtrl->GetHighlightingMode() != CPDF_FormControl::Push) { + pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, nullptr); + return; + } + if (m_bMouseDown) { + if (pWidget->IsWidgetAppearanceValid(CPDF_Annot::Down)) { + pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Down, nullptr); + } else { + pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, + nullptr); + } + return; + } + if (m_bMouseIn) { + if (pWidget->IsWidgetAppearanceValid(CPDF_Annot::Rollover)) { + pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Rollover, + nullptr); + } else { + pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, + nullptr); + } + return; + } + + pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, nullptr); +} + +void CFFL_Button::OnDrawDeactive(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device) { + OnDraw(pPageView, pAnnot, pDevice, pUser2Device); +} diff --git a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_button.h b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_button.h new file mode 100644 index 00000000000..37c294dbf00 --- /dev/null +++ b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_button.h @@ -0,0 +1,56 @@ +// Copyright 2017 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 + +#ifndef FPDFSDK_FORMFILLER_CFFL_BUTTON_H_ +#define FPDFSDK_FORMFILLER_CFFL_BUTTON_H_ + +#include "core/fxcrt/fx_coordinates.h" +#include "fpdfsdk/formfiller/cffl_formfiller.h" + +class CFX_RenderDevice; +class CFX_Matrix; +class CPDFSDK_Annot; +class CPDFSDK_FormFillEnvironment; +class CPDFSDK_PageView; +class CPDFSDK_Widget; + +class CFFL_Button : public CFFL_FormFiller { + public: + CFFL_Button(CPDFSDK_FormFillEnvironment* pFormFillEnv, + CPDFSDK_Widget* pWidget); + ~CFFL_Button() override; + + // CFFL_FormFiller + void OnMouseEnter(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot) override; + void OnMouseExit(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot) override; + bool OnLButtonDown(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlags, + const CFX_PointF& point) override; + bool OnLButtonUp(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlags, + const CFX_PointF& point) override; + bool OnMouseMove(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + uint32_t nFlags, + const CFX_PointF& point) override; + void OnDraw(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device) override; + void OnDrawDeactive(CPDFSDK_PageView* pPageView, + CPDFSDK_Annot* pAnnot, + CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device) override; + + private: + bool m_bMouseIn; + bool m_bMouseDown; +}; + +#endif // FPDFSDK_FORMFILLER_CFFL_BUTTON_H_ diff --git a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_checkbox.cpp b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_checkbox.cpp index c233c136c17..4bab95a54e1 100644 --- a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_checkbox.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_checkbox.cpp @@ -9,7 +9,7 @@ #include "fpdfsdk/cpdfsdk_formfillenvironment.h" #include "fpdfsdk/cpdfsdk_widget.h" #include "fpdfsdk/formfiller/cffl_formfiller.h" -#include "fpdfsdk/pdfwindow/PWL_SpecialButton.h" +#include "fpdfsdk/pdfwindow/cpwl_special_button.h" #include "public/fpdf_fwlevent.h" CFFL_CheckBox::CFFL_CheckBox(CPDFSDK_FormFillEnvironment* pApp, @@ -18,8 +18,7 @@ CFFL_CheckBox::CFFL_CheckBox(CPDFSDK_FormFillEnvironment* pApp, CFFL_CheckBox::~CFFL_CheckBox() {} -CPWL_Wnd* CFFL_CheckBox::NewPDFWindow(const PWL_CREATEPARAM& cp, - CPDFSDK_PageView* pPageView) { +CPWL_Wnd* CFFL_CheckBox::NewPDFWindow(const PWL_CREATEPARAM& cp) { CPWL_CheckBox* pWnd = new CPWL_CheckBox(); pWnd->Create(cp); pWnd->SetCheck(m_pWidget->IsChecked()); @@ -46,24 +45,24 @@ bool CFFL_CheckBox::OnChar(CPDFSDK_Annot* pAnnot, CPDFSDK_PageView* pPageView = pAnnot->GetPageView(); ASSERT(pPageView); - bool bReset = false; - bool bExit = false; - CPDFSDK_Annot::ObservedPtr pObserved(m_pWidget); - m_pFormFillEnv->GetInteractiveFormFiller()->OnButtonUp( - &pObserved, pPageView, bReset, bExit, nFlags); + CPDFSDK_Annot::ObservedPtr pObserved(m_pWidget.Get()); + if (m_pFormFillEnv->GetInteractiveFormFiller()->OnButtonUp( + &pObserved, pPageView, nFlags)) { + if (!pObserved) + m_pWidget = nullptr; + return true; + } if (!pObserved) { m_pWidget = nullptr; return true; } - if (bReset || bExit) - return true; CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags); - if (CPWL_CheckBox* pWnd = (CPWL_CheckBox*)GetPDFWindow(pPageView, true)) + CPWL_CheckBox* pWnd = GetCheckBox(pPageView, true); + if (pWnd) pWnd->SetCheck(!pWnd->IsChecked()); - CommitData(pPageView, nFlags); - return true; + return CommitData(pPageView, nFlags); } default: return CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags); @@ -76,41 +75,46 @@ bool CFFL_CheckBox::OnLButtonUp(CPDFSDK_PageView* pPageView, const CFX_PointF& point) { CFFL_Button::OnLButtonUp(pPageView, pAnnot, nFlags, point); - if (IsValid()) { - if (CPWL_CheckBox* pWnd = (CPWL_CheckBox*)GetPDFWindow(pPageView, true)) { - CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; - pWnd->SetCheck(!pWidget->IsChecked()); - } + if (!IsValid()) + return true; - if (!CommitData(pPageView, nFlags)) - return false; + CPWL_CheckBox* pWnd = GetCheckBox(pPageView, true); + if (pWnd) { + CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot); + pWnd->SetCheck(!pWidget->IsChecked()); } - return true; + return CommitData(pPageView, nFlags); } bool CFFL_CheckBox::IsDataChanged(CPDFSDK_PageView* pPageView) { - CPWL_CheckBox* pWnd = (CPWL_CheckBox*)GetPDFWindow(pPageView, false); + CPWL_CheckBox* pWnd = GetCheckBox(pPageView, false); return pWnd && pWnd->IsChecked() != m_pWidget->IsChecked(); } void CFFL_CheckBox::SaveData(CPDFSDK_PageView* pPageView) { - if (CPWL_CheckBox* pWnd = (CPWL_CheckBox*)GetPDFWindow(pPageView, false)) { - bool bNewChecked = pWnd->IsChecked(); - - if (bNewChecked) { - CPDF_FormField* pField = m_pWidget->GetFormField(); - for (int32_t i = 0, sz = pField->CountControls(); i < sz; i++) { - if (CPDF_FormControl* pCtrl = pField->GetControl(i)) { - if (pCtrl->IsChecked()) { - break; - } + CPWL_CheckBox* pWnd = GetCheckBox(pPageView, false); + if (!pWnd) + return; + + bool bNewChecked = pWnd->IsChecked(); + if (bNewChecked) { + CPDF_FormField* pField = m_pWidget->GetFormField(); + for (int32_t i = 0, sz = pField->CountControls(); i < sz; i++) { + if (CPDF_FormControl* pCtrl = pField->GetControl(i)) { + if (pCtrl->IsChecked()) { + break; } } } - - m_pWidget->SetCheck(bNewChecked, false); - m_pWidget->UpdateField(); - SetChangeMark(); } + + m_pWidget->SetCheck(bNewChecked, false); + m_pWidget->UpdateField(); + SetChangeMark(); +} + +CPWL_CheckBox* CFFL_CheckBox::GetCheckBox(CPDFSDK_PageView* pPageView, + bool bNew) { + return static_cast<CPWL_CheckBox*>(GetPDFWindow(pPageView, bNew)); } diff --git a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_checkbox.h b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_checkbox.h index 79ddc847cc8..f84fb3eb370 100644 --- a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_checkbox.h +++ b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_checkbox.h @@ -7,7 +7,9 @@ #ifndef FPDFSDK_FORMFILLER_CFFL_CHECKBOX_H_ #define FPDFSDK_FORMFILLER_CFFL_CHECKBOX_H_ -#include "fpdfsdk/formfiller/cffl_formfiller.h" +#include "fpdfsdk/formfiller/cffl_button.h" + +class CPWL_CheckBox; class CFFL_CheckBox : public CFFL_Button { public: @@ -15,8 +17,7 @@ class CFFL_CheckBox : public CFFL_Button { ~CFFL_CheckBox() override; // CFFL_Button - CPWL_Wnd* NewPDFWindow(const PWL_CREATEPARAM& cp, - CPDFSDK_PageView* pPageView) override; + CPWL_Wnd* NewPDFWindow(const PWL_CREATEPARAM& cp) override; bool OnKeyDown(CPDFSDK_Annot* pAnnot, uint32_t nKeyCode, uint32_t nFlags) override; @@ -27,6 +28,9 @@ class CFFL_CheckBox : public CFFL_Button { const CFX_PointF& point) override; bool IsDataChanged(CPDFSDK_PageView* pPageView) override; void SaveData(CPDFSDK_PageView* pPageView) override; + + private: + CPWL_CheckBox* GetCheckBox(CPDFSDK_PageView* pPageView, bool bNew); }; #endif // FPDFSDK_FORMFILLER_CFFL_CHECKBOX_H_ diff --git a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_combobox.cpp b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_combobox.cpp index 1f2491fe95a..175ccb74090 100644 --- a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_combobox.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_combobox.cpp @@ -12,12 +12,12 @@ #include "fpdfsdk/formfiller/cffl_formfiller.h" #include "fpdfsdk/formfiller/cffl_interactiveformfiller.h" #include "fpdfsdk/fsdk_common.h" -#include "fpdfsdk/pdfwindow/PWL_ComboBox.h" +#include "fpdfsdk/pdfwindow/cpwl_combo_box.h" #include "third_party/base/ptr_util.h" CFFL_ComboBox::CFFL_ComboBox(CPDFSDK_FormFillEnvironment* pApp, - CPDFSDK_Annot* pAnnot) - : CFFL_FormFiller(pApp, pAnnot) { + CPDFSDK_Widget* pWidget) + : CFFL_FormFiller(pApp, pWidget) { m_State.nIndex = 0; m_State.nStart = 0; m_State.nEnd = 0; @@ -38,15 +38,16 @@ PWL_CREATEPARAM CFFL_ComboBox::GetCreateParam() { if (m_pWidget->GetFieldFlags() & FIELDFLAG_EDIT) cp.dwFlags |= PCBS_ALLOWCUSTOMTEXT; - if (!m_pFontMap) - m_pFontMap = pdfium::MakeUnique<CBA_FontMap>(m_pWidget, GetSystemHandler()); + if (!m_pFontMap) { + m_pFontMap = + pdfium::MakeUnique<CBA_FontMap>(m_pWidget.Get(), GetSystemHandler()); + } cp.pFontMap = m_pFontMap.get(); cp.pFocusHandler = this; return cp; } -CPWL_Wnd* CFFL_ComboBox::NewPDFWindow(const PWL_CREATEPARAM& cp, - CPDFSDK_PageView* pPageView) { +CPWL_Wnd* CFFL_ComboBox::NewPDFWindow(const PWL_CREATEPARAM& cp) { CPWL_ComboBox* pWnd = new CPWL_ComboBox(); pWnd->AttachFFLData(this); pWnd->Create(cp); @@ -230,19 +231,12 @@ CPWL_Wnd* CFFL_ComboBox::ResetPDFWindow(CPDFSDK_PageView* pPageView, SaveState(pPageView); DestroyPDFWindow(pPageView); - - CPWL_Wnd* pRet = nullptr; - - if (bRestoreValue) { + if (bRestoreValue) RestoreState(pPageView); - pRet = GetPDFWindow(pPageView, false); - } else { - pRet = GetPDFWindow(pPageView, true); - } - m_pWidget->UpdateField(); - - return pRet; + CPWL_Wnd::ObservedPtr pRet(GetPDFWindow(pPageView, !bRestoreValue)); + m_pWidget->UpdateField(); // May invoke JS, invalidating pRet. + return pRet.Get(); } #ifdef PDF_ENABLE_XFA @@ -256,13 +250,7 @@ bool CFFL_ComboBox::IsFieldFull(CPDFSDK_PageView* pPageView) { } #endif // PDF_ENABLE_XFA -void CFFL_ComboBox::OnSetFocus(CPWL_Wnd* pWnd) { - ASSERT(m_pFormFillEnv); - - if (pWnd->GetClassName() != PWL_CLASSNAME_EDIT) - return; - - CPWL_Edit* pEdit = (CPWL_Edit*)pWnd; +void CFFL_ComboBox::OnSetFocus(CPWL_Edit* pEdit) { pEdit->SetCharSet(FX_CHARSET_ChineseSimplified); pEdit->SetReadyToInput(); diff --git a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_combobox.h b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_combobox.h index e61e2b73c3e..96e8ffda84b 100644 --- a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_combobox.h +++ b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_combobox.h @@ -23,13 +23,12 @@ struct FFL_ComboBoxState { class CFFL_ComboBox : public CFFL_FormFiller, public IPWL_FocusHandler { public: - CFFL_ComboBox(CPDFSDK_FormFillEnvironment* pApp, CPDFSDK_Annot* pWidget); + CFFL_ComboBox(CPDFSDK_FormFillEnvironment* pApp, CPDFSDK_Widget* pWidget); ~CFFL_ComboBox() override; // CFFL_FormFiller: PWL_CREATEPARAM GetCreateParam() override; - CPWL_Wnd* NewPDFWindow(const PWL_CREATEPARAM& cp, - CPDFSDK_PageView* pPageView) override; + CPWL_Wnd* NewPDFWindow(const PWL_CREATEPARAM& cp) override; bool OnChar(CPDFSDK_Annot* pAnnot, uint32_t nChar, uint32_t nFlags) override; bool IsDataChanged(CPDFSDK_PageView* pPageView) override; void SaveData(CPDFSDK_PageView* pPageView) override; @@ -48,7 +47,7 @@ class CFFL_ComboBox : public CFFL_FormFiller, public IPWL_FocusHandler { bool bRestoreValue) override; // IPWL_FocusHandler: - void OnSetFocus(CPWL_Wnd* pWnd) override; + void OnSetFocus(CPWL_Edit* pEdit) override; #ifdef PDF_ENABLE_XFA // CFFL_FormFiller: diff --git a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_formfiller.cpp b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_formfiller.cpp index 947c495f192..edbd671f294 100644 --- a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_formfiller.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_formfiller.cpp @@ -6,6 +6,8 @@ #include "fpdfsdk/formfiller/cffl_formfiller.h" +#include <utility> + #include "core/fpdfapi/page/cpdf_page.h" #include "core/fxge/cfx_renderdevice.h" #include "fpdfsdk/cpdfsdk_formfillenvironment.h" @@ -13,18 +15,19 @@ #include "fpdfsdk/cpdfsdk_widget.h" #include "fpdfsdk/formfiller/cba_fontmap.h" #include "fpdfsdk/fsdk_common.h" -#include "fpdfsdk/pdfwindow/PWL_Utils.h" -#define GetRed(rgb) ((uint8_t)(rgb)) -#define GetGreen(rgb) ((uint8_t)(((uint16_t)(rgb)) >> 8)) -#define GetBlue(rgb) ((uint8_t)((rgb) >> 16)) +namespace { + +CPDFSDK_Widget* CPDFSDKAnnotToWidget(CPDFSDK_Annot* annot) { + return static_cast<CPDFSDK_Widget*>(annot); +} -#define FFL_HINT_ELAPSE 800 +} // namespace CFFL_FormFiller::CFFL_FormFiller(CPDFSDK_FormFillEnvironment* pFormFillEnv, - CPDFSDK_Annot* pAnnot) - : m_pFormFillEnv(pFormFillEnv), m_pAnnot(pAnnot), m_bValid(false) { - m_pWidget = static_cast<CPDFSDK_Widget*>(pAnnot); + CPDFSDK_Widget* pWidget) + : m_pFormFillEnv(pFormFillEnv), m_pWidget(pWidget), m_bValid(false) { + ASSERT(m_pFormFillEnv); } CFFL_FormFiller::~CFFL_FormFiller() { @@ -34,7 +37,8 @@ CFFL_FormFiller::~CFFL_FormFiller() { void CFFL_FormFiller::DestroyWindows() { for (const auto& it : m_Maps) { CPWL_Wnd* pWnd = it.second; - CFFL_PrivateData* pData = (CFFL_PrivateData*)pWnd->GetAttachedData(); + CFFL_PrivateData* pData = + static_cast<CFFL_PrivateData*>(pWnd->GetAttachedData()); pWnd->InvalidateProvider(this); pWnd->Destroy(); delete pWnd; @@ -45,17 +49,13 @@ void CFFL_FormFiller::DestroyWindows() { void CFFL_FormFiller::SetWindowRect(CPDFSDK_PageView* pPageView, const CFX_FloatRect& rcWindow) { - if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false)) { + if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false)) pWnd->Move(CFX_FloatRect(rcWindow), true, false); - } } CFX_FloatRect CFFL_FormFiller::GetWindowRect(CPDFSDK_PageView* pPageView) { - if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false)) { - return pWnd->GetWindowRect(); - } - - return CFX_FloatRect(0, 0, 0, 0); + CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false); + return pWnd ? pWnd->GetWindowRect() : CFX_FloatRect(); } FX_RECT CFFL_FormFiller::GetViewBBox(CPDFSDK_PageView* pPageView, @@ -64,21 +64,19 @@ FX_RECT CFFL_FormFiller::GetViewBBox(CPDFSDK_PageView* pPageView, ASSERT(pAnnot); CFX_FloatRect rcAnnot = m_pWidget->GetRect(); - - if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false)) { - CFX_FloatRect rcWindow = pWnd->GetWindowRect(); - rcAnnot = PWLtoFFL(rcWindow); - } + if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false)) + rcAnnot = PWLtoFFL(pWnd->GetWindowRect()); CFX_FloatRect rcWin = rcAnnot; - CFX_FloatRect rcFocus = GetFocusBox(pPageView); if (!rcFocus.IsEmpty()) rcWin.Union(rcFocus); - CFX_FloatRect rect = CPWL_Utils::InflateRect(rcWin, 1); - - return rect.GetOuterRect(); + if (!rcWin.IsEmpty()) { + rcWin.Inflate(1, 1); + rcWin.Normalize(); + } + return rcWin.GetOuterRect(); } void CFFL_FormFiller::OnDraw(CPDFSDK_PageView* pPageView, @@ -91,20 +89,22 @@ void CFFL_FormFiller::OnDraw(CPDFSDK_PageView* pPageView, CFX_Matrix mt = GetCurMatrix(); mt.Concat(*pUser2Device); pWnd->DrawAppearance(pDevice, &mt); - } else { - CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; - if (CFFL_InteractiveFormFiller::IsVisible(pWidget)) - pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, - nullptr); + return; } + + CPDFSDK_Widget* pWidget = CPDFSDKAnnotToWidget(pAnnot); + if (!CFFL_InteractiveFormFiller::IsVisible(pWidget)) + return; + + pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, nullptr); } void CFFL_FormFiller::OnDrawDeactive(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, CFX_RenderDevice* pDevice, CFX_Matrix* pUser2Device) { - CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; - pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, nullptr); + CPDFSDKAnnotToWidget(pAnnot)->DrawAppearance(pDevice, pUser2Device, + CPDF_Annot::Normal, nullptr); } void CFFL_FormFiller::OnMouseEnter(CPDFSDK_PageView* pPageView, @@ -120,17 +120,16 @@ bool CFFL_FormFiller::OnLButtonDown(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, uint32_t nFlags, const CFX_PointF& point) { - if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, true)) { - m_bValid = true; - FX_RECT rect = GetViewBBox(pPageView, pAnnot); - InvalidateRect(rect); - if (!rect.Contains(static_cast<int>(point.x), static_cast<int>(point.y))) - return false; - - return pWnd->OnLButtonDown(WndtoPWL(pPageView, point), nFlags); - } + CPWL_Wnd* pWnd = GetPDFWindow(pPageView, true); + if (!pWnd) + return false; - return false; + m_bValid = true; + FX_RECT rect = GetViewBBox(pPageView, pAnnot); + InvalidateRect(rect); + if (!rect.Contains(static_cast<int>(point.x), static_cast<int>(point.y))) + return false; + return pWnd->OnLButtonDown(WndtoPWL(pPageView, point), nFlags); } bool CFFL_FormFiller::OnLButtonUp(CPDFSDK_PageView* pPageView, @@ -212,31 +211,38 @@ bool CFFL_FormFiller::OnRButtonUp(CPDFSDK_PageView* pPageView, bool CFFL_FormFiller::OnKeyDown(CPDFSDK_Annot* pAnnot, uint32_t nKeyCode, uint32_t nFlags) { - if (IsValid()) { - CPDFSDK_PageView* pPageView = GetCurPageView(true); - ASSERT(pPageView); + if (!IsValid()) + return false; - if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false)) { - return pWnd->OnKeyDown(nKeyCode, nFlags); - } - } + CPDFSDK_PageView* pPageView = GetCurPageView(true); + ASSERT(pPageView); - return false; + CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false); + return pWnd && pWnd->OnKeyDown(nKeyCode, nFlags); } bool CFFL_FormFiller::OnChar(CPDFSDK_Annot* pAnnot, uint32_t nChar, uint32_t nFlags) { - if (IsValid()) { - CPDFSDK_PageView* pPageView = GetCurPageView(true); - ASSERT(pPageView); + if (!IsValid()) + return false; - if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false)) { - return pWnd->OnChar(nChar, nFlags); - } - } + CPDFSDK_PageView* pPageView = GetCurPageView(true); + ASSERT(pPageView); - return false; + CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false); + return pWnd && pWnd->OnChar(nChar, nFlags); +} + +CFX_WideString CFFL_FormFiller::GetSelectedText(CPDFSDK_Annot* pAnnot) { + if (!IsValid()) + return CFX_WideString(); + + CPDFSDK_PageView* pPageView = GetCurPageView(true); + ASSERT(pPageView); + + CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false); + return pWnd ? pWnd->GetSelectedText() : CFX_WideString(); } void CFFL_FormFiller::SetFocusForAnnot(CPDFSDK_Annot* pAnnot, uint32_t nFlag) { @@ -255,11 +261,8 @@ void CFFL_FormFiller::KillFocusForAnnot(CPDFSDK_Annot* pAnnot, uint32_t nFlag) { return; CPDFSDK_PageView* pPageView = GetCurPageView(false); - if (!pPageView) + if (!pPageView || !CommitData(pPageView, nFlag)) return; - - CommitData(pPageView, nFlag); - if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false)) pWnd->KillFocus(); @@ -282,8 +285,6 @@ bool CFFL_FormFiller::IsValid() const { } PWL_CREATEPARAM CFFL_FormFiller::GetCreateParam() { - ASSERT(m_pFormFillEnv); - PWL_CREATEPARAM cp; cp.pParentWnd = nullptr; cp.pProvider.Reset(this); @@ -291,26 +292,19 @@ PWL_CREATEPARAM CFFL_FormFiller::GetCreateParam() { uint32_t dwCreateFlags = PWS_BORDER | PWS_BACKGROUND | PWS_VISIBLE; uint32_t dwFieldFlag = m_pWidget->GetFieldFlags(); - if (dwFieldFlag & FIELDFLAG_READONLY) { + if (dwFieldFlag & FIELDFLAG_READONLY) dwCreateFlags |= PWS_READONLY; - } FX_COLORREF color; - if (m_pWidget->GetFillColor(color)) { - cp.sBackgroundColor = - CPWL_Color(GetRed(color), GetGreen(color), GetBlue(color)); - } + if (m_pWidget->GetFillColor(color)) + cp.sBackgroundColor = CFX_Color(color); + if (m_pWidget->GetBorderColor(color)) + cp.sBorderColor = CFX_Color(color); - if (m_pWidget->GetBorderColor(color)) { - cp.sBorderColor = - CPWL_Color(GetRed(color), GetGreen(color), GetBlue(color)); - } + cp.sTextColor = CFX_Color(COLORTYPE_GRAY, 0); - cp.sTextColor = CPWL_Color(COLORTYPE_GRAY, 0); - - if (m_pWidget->GetTextColor(color)) { - cp.sTextColor = CPWL_Color(GetRed(color), GetGreen(color), GetBlue(color)); - } + if (m_pWidget->GetTextColor(color)) + cp.sTextColor = CFX_Color(color); cp.fFontSize = m_pWidget->GetFontSize(); cp.dwBorderWidth = m_pWidget->GetBorderWidth(); @@ -321,8 +315,6 @@ PWL_CREATEPARAM CFFL_FormFiller::GetCreateParam() { cp.sDash = CPWL_Dash(3, 3, 0); break; case BorderStyle::BEVELED: - cp.dwBorderWidth *= 2; - break; case BorderStyle::INSET: cp.dwBorderWidth *= 2; break; @@ -348,29 +340,27 @@ CPWL_Wnd* CFFL_FormFiller::GetPDFWindow(CPDFSDK_PageView* pPageView, if (!bNew) return pWnd; - if (found) { - CFFL_PrivateData* pPrivateData = (CFFL_PrivateData*)pWnd->GetAttachedData(); - if (pPrivateData->nWidgetAge != m_pWidget->GetAppearanceAge()) { - return ResetPDFWindow( - pPageView, m_pWidget->GetValueAge() == pPrivateData->nValueAge); - } - } else { + if (!found) { PWL_CREATEPARAM cp = GetCreateParam(); - cp.pAttachedWidget.Reset(m_pWidget); + cp.pAttachedWidget.Reset(m_pWidget.Get()); CFFL_PrivateData* pPrivateData = new CFFL_PrivateData; - pPrivateData->pWidget = m_pWidget; + pPrivateData->pWidget = m_pWidget.Get(); pPrivateData->pPageView = pPageView; pPrivateData->nWidgetAge = m_pWidget->GetAppearanceAge(); pPrivateData->nValueAge = 0; - cp.pAttachedData = pPrivateData; - - pWnd = NewPDFWindow(cp, pPageView); - m_Maps[pPageView] = pWnd; + CPWL_Wnd* pNewWnd = NewPDFWindow(cp); + m_Maps[pPageView] = pNewWnd; + return pNewWnd; } - return pWnd; + auto* pPrivateData = static_cast<CFFL_PrivateData*>(pWnd->GetAttachedData()); + if (pPrivateData->nWidgetAge == m_pWidget->GetAppearanceAge()) + return pWnd; + + return ResetPDFWindow(pPageView, + m_pWidget->GetValueAge() == pPrivateData->nValueAge); } void CFFL_FormFiller::DestroyPDFWindow(CPDFSDK_PageView* pPageView) { @@ -388,30 +378,22 @@ void CFFL_FormFiller::DestroyPDFWindow(CPDFSDK_PageView* pPageView) { } CFX_Matrix CFFL_FormFiller::GetWindowMatrix(void* pAttachedData) { - if (CFFL_PrivateData* pPrivateData = (CFFL_PrivateData*)pAttachedData) { - if (pPrivateData->pPageView) { - CFX_Matrix mtPageView; - pPrivateData->pPageView->GetCurrentMatrix(mtPageView); - - CFX_Matrix mt = GetCurMatrix(); - mt.Concat(mtPageView); - - return mt; - } - } - return CFX_Matrix(1, 0, 0, 1, 0, 0); + CFX_Matrix mt; + auto* pPrivateData = reinterpret_cast<CFFL_PrivateData*>(pAttachedData); + if (!pAttachedData || !pPrivateData->pPageView) + return mt; + + CFX_Matrix mtPageView; + pPrivateData->pPageView->GetCurrentMatrix(mtPageView); + mt = GetCurMatrix(); + mt.Concat(mtPageView); + return mt; } CFX_Matrix CFFL_FormFiller::GetCurMatrix() { CFX_Matrix mt; - CFX_FloatRect rcDA = m_pWidget->GetPDFAnnot()->GetRect(); - switch (m_pWidget->GetRotate()) { - default: - case 0: - mt = CFX_Matrix(1, 0, 0, 1, 0, 0); - break; case 90: mt = CFX_Matrix(0, 1, -1, 0, rcDA.right - rcDA.left, 0); break; @@ -422,6 +404,9 @@ CFX_Matrix CFFL_FormFiller::GetCurMatrix() { case 270: mt = CFX_Matrix(0, -1, 1, 0, 0, rcDA.top - rcDA.bottom); break; + case 0: + default: + break; } mt.e += rcDA.left; mt.f += rcDA.bottom; @@ -429,61 +414,46 @@ CFX_Matrix CFFL_FormFiller::GetCurMatrix() { return mt; } -CFX_WideString CFFL_FormFiller::LoadPopupMenuString(int nIndex) { - ASSERT(m_pFormFillEnv); - - return L""; -} - CFX_FloatRect CFFL_FormFiller::GetPDFWindowRect() const { CFX_FloatRect rectAnnot = m_pWidget->GetPDFAnnot()->GetRect(); float fWidth = rectAnnot.right - rectAnnot.left; float fHeight = rectAnnot.top - rectAnnot.bottom; if ((m_pWidget->GetRotate() / 90) & 0x01) - return CFX_FloatRect(0, 0, fHeight, fWidth); - + std::swap(fWidth, fHeight); return CFX_FloatRect(0, 0, fWidth, fHeight); } CPDFSDK_PageView* CFFL_FormFiller::GetCurPageView(bool renew) { - UnderlyingPageType* pPage = m_pAnnot->GetUnderlyingPage(); - return m_pFormFillEnv ? m_pFormFillEnv->GetPageView(pPage, renew) : nullptr; + UnderlyingPageType* pPage = m_pWidget->GetUnderlyingPage(); + return m_pFormFillEnv->GetPageView(pPage, renew); } CFX_FloatRect CFFL_FormFiller::GetFocusBox(CPDFSDK_PageView* pPageView) { - if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false)) { - CFX_FloatRect rcFocus = FFLtoWnd(pPageView, PWLtoFFL(pWnd->GetFocusRect())); - CFX_FloatRect rcPage = pPageView->GetPDFPage()->GetPageBBox(); - if (rcPage.Contains(rcFocus)) - return rcFocus; - } - return CFX_FloatRect(0, 0, 0, 0); + CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false); + if (!pWnd) + return CFX_FloatRect(); + + CFX_FloatRect rcFocus = FFLtoWnd(pPageView, PWLtoFFL(pWnd->GetFocusRect())); + return pPageView->GetPDFPage()->GetPageBBox().Contains(rcFocus) + ? rcFocus + : CFX_FloatRect(); } CFX_FloatRect CFFL_FormFiller::FFLtoPWL(const CFX_FloatRect& rect) { - CFX_Matrix mt; - mt.SetReverse(GetCurMatrix()); - CFX_FloatRect temp = rect; - mt.TransformRect(temp); - + GetCurMatrix().GetInverse().TransformRect(temp); return temp; } CFX_FloatRect CFFL_FormFiller::PWLtoFFL(const CFX_FloatRect& rect) { - CFX_Matrix mt = GetCurMatrix(); - CFX_FloatRect temp = rect; - mt.TransformRect(temp); - + GetCurMatrix().TransformRect(temp); return temp; } CFX_PointF CFFL_FormFiller::FFLtoPWL(const CFX_PointF& point) { - CFX_Matrix mt; - mt.SetReverse(GetCurMatrix()); - return mt.Transform(point); + return GetCurMatrix().GetInverse().Transform(point); } CFX_PointF CFFL_FormFiller::PWLtoFFL(const CFX_PointF& point) { @@ -501,33 +471,40 @@ CFX_FloatRect CFFL_FormFiller::FFLtoWnd(CPDFSDK_PageView* pPageView, } bool CFFL_FormFiller::CommitData(CPDFSDK_PageView* pPageView, uint32_t nFlag) { - if (IsDataChanged(pPageView)) { - bool bRC = true; - bool bExit = false; - CFFL_InteractiveFormFiller* pFormFiller = - m_pFormFillEnv->GetInteractiveFormFiller(); - CPDFSDK_Annot::ObservedPtr pObserved(m_pWidget); - pFormFiller->OnKeyStrokeCommit(&pObserved, pPageView, bRC, bExit, nFlag); - if (!pObserved || bExit) - return true; - if (!bRC) { - ResetPDFWindow(pPageView, false); - return true; - } - pFormFiller->OnValidate(&pObserved, pPageView, bRC, bExit, nFlag); - if (!pObserved || bExit) - return true; - if (!bRC) { - ResetPDFWindow(pPageView, false); - return true; - } - SaveData(pPageView); - pFormFiller->OnCalculate(m_pWidget, pPageView, bExit, nFlag); - if (bExit) - return true; - - pFormFiller->OnFormat(m_pWidget, pPageView, bExit, nFlag); + if (!IsDataChanged(pPageView)) + return true; + + CFFL_InteractiveFormFiller* pFormFiller = + m_pFormFillEnv->GetInteractiveFormFiller(); + CPDFSDK_Annot::ObservedPtr pObserved(m_pWidget.Get()); + + if (!pFormFiller->OnKeyStrokeCommit(&pObserved, pPageView, nFlag)) { + if (!pObserved) + return false; + ResetPDFWindow(pPageView, false); + return true; + } + if (!pObserved) + return false; + + if (!pFormFiller->OnValidate(&pObserved, pPageView, nFlag)) { + if (!pObserved) + return false; + ResetPDFWindow(pPageView, false); + return true; } + if (!pObserved) + return false; + + SaveData(pPageView); + pFormFiller->OnCalculate(&pObserved, pPageView, nFlag); + if (!pObserved) + return false; + + pFormFiller->OnFormat(&pObserved, pPageView, nFlag); + if (!pObserved) + return false; + return true; } @@ -582,7 +559,7 @@ void CFFL_FormFiller::EscapeFiller(CPDFSDK_PageView* pPageView, bool bDestroyPDFWindow) { m_bValid = false; - InvalidateRect(GetViewBBox(pPageView, m_pWidget)); + InvalidateRect(GetViewBBox(pPageView, m_pWidget.Get())); if (bDestroyPDFWindow) DestroyPDFWindow(pPageView); } @@ -590,98 +567,3 @@ void CFFL_FormFiller::EscapeFiller(CPDFSDK_PageView* pPageView, void CFFL_FormFiller::InvalidateRect(const FX_RECT& rect) { m_pFormFillEnv->Invalidate(m_pWidget->GetUnderlyingPage(), rect); } - -CFFL_Button::CFFL_Button(CPDFSDK_FormFillEnvironment* pApp, - CPDFSDK_Annot* pWidget) - : CFFL_FormFiller(pApp, pWidget), m_bMouseIn(false), m_bMouseDown(false) {} - -CFFL_Button::~CFFL_Button() {} - -void CFFL_Button::OnMouseEnter(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot) { - m_bMouseIn = true; - InvalidateRect(GetViewBBox(pPageView, pAnnot)); -} - -void CFFL_Button::OnMouseExit(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot) { - m_bMouseIn = false; - - InvalidateRect(GetViewBBox(pPageView, pAnnot)); - EndTimer(); - ASSERT(m_pWidget); -} - -bool CFFL_Button::OnLButtonDown(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlags, - const CFX_PointF& point) { - if (!pAnnot->GetRect().Contains(point)) - return false; - - m_bMouseDown = true; - m_bValid = true; - InvalidateRect(GetViewBBox(pPageView, pAnnot)); - return true; -} - -bool CFFL_Button::OnLButtonUp(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlags, - const CFX_PointF& point) { - if (!pAnnot->GetRect().Contains(point)) - return false; - - m_bMouseDown = false; - m_pWidget->GetPDFPage(); - - InvalidateRect(GetViewBBox(pPageView, pAnnot)); - return true; -} - -bool CFFL_Button::OnMouseMove(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlags, - const CFX_PointF& point) { - ASSERT(m_pFormFillEnv); - return true; -} - -void CFFL_Button::OnDraw(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device) { - ASSERT(pPageView); - CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; - CPDF_FormControl* pCtrl = pWidget->GetFormControl(); - CPDF_FormControl::HighlightingMode eHM = pCtrl->GetHighlightingMode(); - - if (eHM != CPDF_FormControl::Push) { - pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, nullptr); - return; - } - - if (m_bMouseDown) { - if (pWidget->IsWidgetAppearanceValid(CPDF_Annot::Down)) - pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Down, nullptr); - else - pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, - nullptr); - } else if (m_bMouseIn) { - if (pWidget->IsWidgetAppearanceValid(CPDF_Annot::Rollover)) - pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Rollover, - nullptr); - else - pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, - nullptr); - } else { - pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, nullptr); - } -} - -void CFFL_Button::OnDrawDeactive(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device) { - OnDraw(pPageView, pAnnot, pDevice, pUser2Device); -} diff --git a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_formfiller.h b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_formfiller.h index f9a155be862..3eedebea470 100644 --- a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_formfiller.h +++ b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_formfiller.h @@ -22,7 +22,7 @@ class CPDFSDK_Widget; class CFFL_FormFiller : public IPWL_Provider, public CPWL_TimerHandler { public: CFFL_FormFiller(CPDFSDK_FormFillEnvironment* pFormFillEnv, - CPDFSDK_Annot* pAnnot); + CPDFSDK_Widget* pWidget); ~CFFL_FormFiller() override; virtual FX_RECT GetViewBBox(CPDFSDK_PageView* pPageView, @@ -74,6 +74,8 @@ class CFFL_FormFiller : public IPWL_Provider, public CPWL_TimerHandler { uint32_t nFlags); virtual bool OnChar(CPDFSDK_Annot* pAnnot, uint32_t nChar, uint32_t nFlags); + CFX_WideString GetSelectedText(CPDFSDK_Annot* pAnnot); + void SetFocusForAnnot(CPDFSDK_Annot* pAnnot, uint32_t nFlag); void KillFocusForAnnot(CPDFSDK_Annot* pAnnot, uint32_t nFlag); @@ -83,7 +85,6 @@ class CFFL_FormFiller : public IPWL_Provider, public CPWL_TimerHandler { // IPWL_Provider CFX_Matrix GetWindowMatrix(void* pAttachedData) override; - CFX_WideString LoadPopupMenuString(int nIndex) override; virtual void GetActionData(CPDFSDK_PageView* pPageView, CPDF_AAction::AActionType type, @@ -129,8 +130,7 @@ class CFFL_FormFiller : public IPWL_Provider, public CPWL_TimerHandler { void EscapeFiller(CPDFSDK_PageView* pPageView, bool bDestroyPDFWindow); virtual PWL_CREATEPARAM GetCreateParam(); - virtual CPWL_Wnd* NewPDFWindow(const PWL_CREATEPARAM& cp, - CPDFSDK_PageView* pPageView) = 0; + virtual CPWL_Wnd* NewPDFWindow(const PWL_CREATEPARAM& cp) = 0; virtual CFX_FloatRect GetFocusBox(CPDFSDK_PageView* pPageView); bool IsValid() const; @@ -140,7 +140,7 @@ class CFFL_FormFiller : public IPWL_Provider, public CPWL_TimerHandler { void SetChangeMark(); virtual void InvalidateRect(const FX_RECT& rect); - CPDFSDK_Annot* GetSDKAnnot() { return m_pAnnot; } + CPDFSDK_Annot* GetSDKAnnot() { return m_pWidget.Get(); } protected: using CFFL_PageView2PDFWindow = std::map<CPDFSDK_PageView*, CPWL_Wnd*>; @@ -154,47 +154,10 @@ class CFFL_FormFiller : public IPWL_Provider, public CPWL_TimerHandler { void DestroyWindows(); CFX_UnownedPtr<CPDFSDK_FormFillEnvironment> const m_pFormFillEnv; - CPDFSDK_Widget* m_pWidget; - CPDFSDK_Annot* m_pAnnot; + CFX_UnownedPtr<CPDFSDK_Widget> m_pWidget; bool m_bValid; CFFL_PageView2PDFWindow m_Maps; CFX_PointF m_ptOldPos; }; -class CFFL_Button : public CFFL_FormFiller { - public: - CFFL_Button(CPDFSDK_FormFillEnvironment* pFormFillEnv, - CPDFSDK_Annot* pWidget); - ~CFFL_Button() override; - - // CFFL_FormFiller - void OnMouseEnter(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot) override; - void OnMouseExit(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot) override; - bool OnLButtonDown(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlags, - const CFX_PointF& point) override; - bool OnLButtonUp(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlags, - const CFX_PointF& point) override; - bool OnMouseMove(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - uint32_t nFlags, - const CFX_PointF& point) override; - void OnDraw(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device) override; - void OnDrawDeactive(CPDFSDK_PageView* pPageView, - CPDFSDK_Annot* pAnnot, - CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device) override; - - protected: - bool m_bMouseIn; - bool m_bMouseDown; -}; - #endif // FPDFSDK_FORMFILLER_CFFL_FORMFILLER_H_ diff --git a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp index 5a358520056..ee74b9928b9 100644 --- a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp @@ -22,9 +22,7 @@ #include "fpdfsdk/formfiller/cffl_pushbutton.h" #include "fpdfsdk/formfiller/cffl_radiobutton.h" #include "fpdfsdk/formfiller/cffl_textfield.h" -#include "fpdfsdk/pdfwindow/PWL_Utils.h" - -#define FFL_MAXLISTBOXHEIGHT 140.0f +#include "third_party/base/stl_util.h" CFFL_InteractiveFormFiller::CFFL_InteractiveFormFiller( CPDFSDK_FormFillEnvironment* pFormFillEnv) @@ -46,7 +44,11 @@ FX_RECT CFFL_InteractiveFormFiller::GetViewBBox(CPDFSDK_PageView* pPageView, ASSERT(pPageView); CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot(); - CFX_FloatRect rcWin = CPWL_Utils::InflateRect(pPDFAnnot->GetRect(), 1); + CFX_FloatRect rcWin = pPDFAnnot->GetRect(); + if (!rcWin.IsEmpty()) { + rcWin.Inflate(1, 1); + rcWin.Normalize(); + } return rcWin.GetOuterRect(); } @@ -55,49 +57,49 @@ void CFFL_InteractiveFormFiller::OnDraw(CPDFSDK_PageView* pPageView, CFX_RenderDevice* pDevice, CFX_Matrix* pUser2Device) { ASSERT(pPageView); - CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; - + CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot); if (!IsVisible(pWidget)) return; - if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, false)) { - if (pFormFiller->IsValid()) { - pFormFiller->OnDraw(pPageView, pAnnot, pDevice, pUser2Device); - pAnnot->GetPDFPage(); - - if (m_pFormFillEnv->GetFocusAnnot() == pAnnot) { - CFX_FloatRect rcFocus = pFormFiller->GetFocusBox(pPageView); - if (!rcFocus.IsEmpty()) { - CFX_PathData path; - path.AppendPoint(CFX_PointF(rcFocus.left, rcFocus.top), - FXPT_TYPE::MoveTo, false); - path.AppendPoint(CFX_PointF(rcFocus.left, rcFocus.bottom), - FXPT_TYPE::LineTo, false); - path.AppendPoint(CFX_PointF(rcFocus.right, rcFocus.bottom), - FXPT_TYPE::LineTo, false); - path.AppendPoint(CFX_PointF(rcFocus.right, rcFocus.top), - FXPT_TYPE::LineTo, false); - path.AppendPoint(CFX_PointF(rcFocus.left, rcFocus.top), - FXPT_TYPE::LineTo, false); - - CFX_GraphStateData gsd; - gsd.SetDashCount(1); - gsd.m_DashArray[0] = 1.0f; - gsd.m_DashPhase = 0; - gsd.m_LineWidth = 1.0f; - pDevice->DrawPath(&path, pUser2Device, &gsd, 0, - ArgbEncode(255, 0, 0, 0), FXFILL_ALTERNATE); - } - } + CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, false); + if (pFormFiller && pFormFiller->IsValid()) { + pFormFiller->OnDraw(pPageView, pAnnot, pDevice, pUser2Device); + pAnnot->GetPDFPage(); + + if (m_pFormFillEnv->GetFocusAnnot() != pAnnot) return; - } + + CFX_FloatRect rcFocus = pFormFiller->GetFocusBox(pPageView); + if (rcFocus.IsEmpty()) + return; + + CFX_PathData path; + path.AppendPoint(CFX_PointF(rcFocus.left, rcFocus.top), FXPT_TYPE::MoveTo, + false); + path.AppendPoint(CFX_PointF(rcFocus.left, rcFocus.bottom), + FXPT_TYPE::LineTo, false); + path.AppendPoint(CFX_PointF(rcFocus.right, rcFocus.bottom), + FXPT_TYPE::LineTo, false); + path.AppendPoint(CFX_PointF(rcFocus.right, rcFocus.top), FXPT_TYPE::LineTo, + false); + path.AppendPoint(CFX_PointF(rcFocus.left, rcFocus.top), FXPT_TYPE::LineTo, + false); + + CFX_GraphStateData gsd; + gsd.SetDashCount(1); + gsd.m_DashArray[0] = 1.0f; + gsd.m_DashPhase = 0; + gsd.m_LineWidth = 1.0f; + pDevice->DrawPath(&path, pUser2Device, &gsd, 0, ArgbEncode(255, 0, 0, 0), + FXFILL_ALTERNATE); + return; } - if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, false)) { + pFormFiller = GetFormFiller(pAnnot, false); + if (pFormFiller) pFormFiller->OnDrawDeactive(pPageView, pAnnot, pDevice, pUser2Device); - } else { + else pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, nullptr); - } if (!IsReadOnly(pWidget) && IsFillingAllowed(pWidget)) pWidget->DrawShadow(pDevice, pPageView); @@ -211,10 +213,9 @@ bool CFFL_InteractiveFormFiller::OnLButtonDown( } } } - if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot->Get(), false)) - return pFormFiller->OnLButtonDown(pPageView, pAnnot->Get(), nFlags, point); - - return false; + CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot->Get(), false); + return pFormFiller && + pFormFiller->OnLButtonDown(pPageView, pAnnot->Get(), nFlags, point); } bool CFFL_InteractiveFormFiller::OnLButtonUp(CPDFSDK_PageView* pPageView, @@ -224,70 +225,67 @@ bool CFFL_InteractiveFormFiller::OnLButtonUp(CPDFSDK_PageView* pPageView, ASSERT((*pAnnot)->GetPDFAnnot()->GetSubtype() == CPDF_Annot::Subtype::WIDGET); CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot->Get()); + bool bSetFocus; switch (pWidget->GetFieldType()) { case FIELDTYPE_PUSHBUTTON: case FIELDTYPE_CHECKBOX: - case FIELDTYPE_RADIOBUTTON: - if (GetViewBBox(pPageView, pAnnot->Get()) - .Contains((int)point.x, (int)point.y)) - m_pFormFillEnv->SetFocusAnnot(pAnnot); + case FIELDTYPE_RADIOBUTTON: { + FX_RECT bbox = GetViewBBox(pPageView, pAnnot->Get()); + bSetFocus = + bbox.Contains(static_cast<int>(point.x), static_cast<int>(point.y)); break; + } default: - m_pFormFillEnv->SetFocusAnnot(pAnnot); + bSetFocus = true; break; } + if (bSetFocus) + m_pFormFillEnv->SetFocusAnnot(pAnnot); - bool bRet = false; - if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot->Get(), false)) - bRet = pFormFiller->OnLButtonUp(pPageView, pAnnot->Get(), nFlags, point); - - if (m_pFormFillEnv->GetFocusAnnot() == pAnnot->Get()) { - bool bExit = false; - bool bReset = false; - OnButtonUp(pAnnot, pPageView, bReset, bExit, nFlags); - if (!pAnnot || bExit) - return true; + CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot->Get(), false); + bool bRet = pFormFiller && + pFormFiller->OnLButtonUp(pPageView, pAnnot->Get(), nFlags, point); + if (m_pFormFillEnv->GetFocusAnnot() != pAnnot->Get()) + return bRet; + if (OnButtonUp(pAnnot, pPageView, nFlags) || !pAnnot) + return true; #ifdef PDF_ENABLE_XFA - OnClick(pWidget, pPageView, bReset, bExit, nFlags); - if (!pAnnot || bExit) - return true; + if (OnClick(pAnnot, pPageView, nFlags) || !pAnnot) + return true; #endif // PDF_ENABLE_XFA - } return bRet; } -void CFFL_InteractiveFormFiller::OnButtonUp(CPDFSDK_Annot::ObservedPtr* pAnnot, +bool CFFL_InteractiveFormFiller::OnButtonUp(CPDFSDK_Annot::ObservedPtr* pAnnot, CPDFSDK_PageView* pPageView, - bool& bReset, - bool& bExit, uint32_t nFlag) { - if (!m_bNotifying) { - CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot->Get()); - if (pWidget->GetAAction(CPDF_AAction::ButtonUp).GetDict()) { - m_bNotifying = true; + if (m_bNotifying) + return false; - int nAge = pWidget->GetAppearanceAge(); - int nValueAge = pWidget->GetValueAge(); - ASSERT(pPageView); + CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot->Get()); + if (!pWidget->GetAAction(CPDF_AAction::ButtonUp).GetDict()) + return false; - PDFSDK_FieldAction fa; - fa.bModifier = m_pFormFillEnv->IsCTRLKeyDown(nFlag); - fa.bShift = m_pFormFillEnv->IsSHIFTKeyDown(nFlag); - pWidget->OnAAction(CPDF_AAction::ButtonUp, fa, pPageView); - m_bNotifying = false; - if (!(*pAnnot) || !IsValidAnnot(pPageView, pWidget)) { - bExit = true; - return; - } - if (nAge != pWidget->GetAppearanceAge()) { - if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, false)) { - pFormFiller->ResetPDFWindow(pPageView, - nValueAge == pWidget->GetValueAge()); - } - bReset = true; - } - } - } + m_bNotifying = true; + + int nAge = pWidget->GetAppearanceAge(); + int nValueAge = pWidget->GetValueAge(); + ASSERT(pPageView); + + PDFSDK_FieldAction fa; + fa.bModifier = m_pFormFillEnv->IsCTRLKeyDown(nFlag); + fa.bShift = m_pFormFillEnv->IsSHIFTKeyDown(nFlag); + pWidget->OnAAction(CPDF_AAction::ButtonUp, fa, pPageView); + m_bNotifying = false; + if (!(*pAnnot) || !IsValidAnnot(pPageView, pWidget)) + return true; + if (nAge == pWidget->GetAppearanceAge()) + return false; + + CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, false); + if (pFormFiller) + pFormFiller->ResetPDFWindow(pPageView, nValueAge == pWidget->GetValueAge()); + return true; } bool CFFL_InteractiveFormFiller::OnLButtonDblClk( @@ -350,11 +348,8 @@ bool CFFL_InteractiveFormFiller::OnKeyDown(CPDFSDK_Annot* pAnnot, uint32_t nFlags) { ASSERT(pAnnot->GetPDFAnnot()->GetSubtype() == CPDF_Annot::Subtype::WIDGET); - if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, false)) { - return pFormFiller->OnKeyDown(pAnnot, nKeyCode, nFlags); - } - - return false; + CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, false); + return pFormFiller && pFormFiller->OnKeyDown(pAnnot, nKeyCode, nFlags); } bool CFFL_InteractiveFormFiller::OnChar(CPDFSDK_Annot* pAnnot, @@ -364,10 +359,8 @@ bool CFFL_InteractiveFormFiller::OnChar(CPDFSDK_Annot* pAnnot, if (nChar == FWL_VKEY_Tab) return true; - if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, false)) - return pFormFiller->OnChar(pAnnot, nChar, nFlags); - - return false; + CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, false); + return pFormFiller && pFormFiller->OnChar(pAnnot, nChar, nFlags); } bool CFFL_InteractiveFormFiller::OnSetFocus(CPDFSDK_Annot::ObservedPtr* pAnnot, @@ -422,29 +415,34 @@ bool CFFL_InteractiveFormFiller::OnKillFocus(CPDFSDK_Annot::ObservedPtr* pAnnot, return false; ASSERT((*pAnnot)->GetPDFAnnot()->GetSubtype() == CPDF_Annot::Subtype::WIDGET); - if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot->Get(), false)) { - pFormFiller->KillFocusForAnnot(pAnnot->Get(), nFlag); - if (!m_bNotifying) { - CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot->Get()); - if (pWidget->GetAAction(CPDF_AAction::LoseFocus).GetDict()) { - m_bNotifying = true; - pWidget->ClearAppModified(); - - CPDFSDK_PageView* pPageView = pWidget->GetPageView(); - ASSERT(pPageView); - - PDFSDK_FieldAction fa; - fa.bModifier = m_pFormFillEnv->IsCTRLKeyDown(nFlag); - fa.bShift = m_pFormFillEnv->IsSHIFTKeyDown(nFlag); - pFormFiller->GetActionData(pPageView, CPDF_AAction::LoseFocus, fa); - pWidget->OnAAction(CPDF_AAction::LoseFocus, fa, pPageView); - m_bNotifying = false; - if (!(*pAnnot)) - return false; - } - } - } - return true; + CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot->Get(), false); + if (!pFormFiller) + return true; + + pFormFiller->KillFocusForAnnot(pAnnot->Get(), nFlag); + if (!(*pAnnot)) + return false; + + if (m_bNotifying) + return true; + + CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot->Get()); + if (!pWidget->GetAAction(CPDF_AAction::LoseFocus).GetDict()) + return true; + + m_bNotifying = true; + pWidget->ClearAppModified(); + + CPDFSDK_PageView* pPageView = pWidget->GetPageView(); + ASSERT(pPageView); + + PDFSDK_FieldAction fa; + fa.bModifier = m_pFormFillEnv->IsCTRLKeyDown(nFlag); + fa.bShift = m_pFormFillEnv->IsSHIFTKeyDown(nFlag); + pFormFiller->GetActionData(pPageView, CPDF_AAction::LoseFocus, fa); + pWidget->OnAAction(CPDF_AAction::LoseFocus, fa, pPageView); + m_bNotifying = false; + return !!(*pAnnot); } bool CFFL_InteractiveFormFiller::IsVisible(CPDFSDK_Widget* pWidget) { @@ -477,7 +475,8 @@ CFFL_FormFiller* CFFL_InteractiveFormFiller::GetFormFiller( if (!bRegister) return nullptr; - CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; + // TODO(thestig): How do we know |pAnnot| is a CPDFSDK_Widget? + CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot); int nFieldType = pWidget->GetFieldType(); CFFL_FormFiller* pFormFiller; switch (nFieldType) { @@ -517,6 +516,13 @@ void CFFL_InteractiveFormFiller::RemoveFormFiller(CPDFSDK_Annot* pAnnot) { UnRegisterFormFiller(pAnnot); } +CFX_WideString CFFL_InteractiveFormFiller::GetSelectedText( + CPDFSDK_Annot* pAnnot) { + ASSERT(pAnnot->GetPDFAnnot()->GetSubtype() == CPDF_Annot::Subtype::WIDGET); + CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, false); + return pFormFiller ? pFormFiller->GetSelectedText(pAnnot) : CFX_WideString(); +} + void CFFL_InteractiveFormFiller::UnRegisterFormFiller(CPDFSDK_Annot* pAnnot) { auto it = m_Maps.find(pAnnot); if (it == m_Maps.end()) @@ -528,21 +534,18 @@ void CFFL_InteractiveFormFiller::UnRegisterFormFiller(CPDFSDK_Annot* pAnnot) { void CFFL_InteractiveFormFiller::QueryWherePopup(void* pPrivateData, float fPopupMin, float fPopupMax, - int32_t& nRet, - float& fPopupRet) { - CFFL_PrivateData* pData = (CFFL_PrivateData*)pPrivateData; + bool* bBottom, + float* fPopupRet) { + CFFL_PrivateData* pData = reinterpret_cast<CFFL_PrivateData*>(pPrivateData); + CPDFSDK_Widget* pWidget = pData->pWidget; + auto* pPage = pWidget->GetPDFPage(); - CFX_FloatRect rcPageView(0, 0, 0, 0); - rcPageView.right = pData->pWidget->GetPDFPage()->GetPageWidth(); - rcPageView.bottom = pData->pWidget->GetPDFPage()->GetPageHeight(); + CFX_FloatRect rcPageView(0, pPage->GetPageHeight(), pPage->GetPageWidth(), 0); rcPageView.Normalize(); - CFX_FloatRect rcAnnot = pData->pWidget->GetRect(); - + CFX_FloatRect rcAnnot = pWidget->GetRect(); float fTop = 0.0f; float fBottom = 0.0f; - - CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pData->pWidget; switch (pWidget->GetRotate() / 90) { default: case 0: @@ -563,308 +566,274 @@ void CFFL_InteractiveFormFiller::QueryWherePopup(void* pPrivateData, break; } - float fFactHeight = 0; - bool bBottom = true; - float fMaxListBoxHeight = 0; - if (fPopupMax > FFL_MAXLISTBOXHEIGHT) { - if (fPopupMin > FFL_MAXLISTBOXHEIGHT) { - fMaxListBoxHeight = fPopupMin; - } else { - fMaxListBoxHeight = FFL_MAXLISTBOXHEIGHT; - } - } else { - fMaxListBoxHeight = fPopupMax; - } + constexpr float kMaxListBoxHeight = 140; + const float fMaxListBoxHeight = + pdfium::clamp(kMaxListBoxHeight, fPopupMin, fPopupMax); if (fBottom > fMaxListBoxHeight) { - fFactHeight = fMaxListBoxHeight; - bBottom = true; - } else { - if (fTop > fMaxListBoxHeight) { - fFactHeight = fMaxListBoxHeight; - bBottom = false; - } else { - if (fTop > fBottom) { - fFactHeight = fTop; - bBottom = false; - } else { - fFactHeight = fBottom; - bBottom = true; - } - } + *fPopupRet = fMaxListBoxHeight; + *bBottom = true; + return; + } + + if (fTop > fMaxListBoxHeight) { + *fPopupRet = fMaxListBoxHeight; + *bBottom = false; + return; } - nRet = bBottom ? 0 : 1; - fPopupRet = fFactHeight; + if (fTop > fBottom) { + *fPopupRet = fTop; + *bBottom = false; + } else { + *fPopupRet = fBottom; + *bBottom = true; + } } -void CFFL_InteractiveFormFiller::OnKeyStrokeCommit( +bool CFFL_InteractiveFormFiller::OnKeyStrokeCommit( CPDFSDK_Annot::ObservedPtr* pAnnot, CPDFSDK_PageView* pPageView, - bool& bRC, - bool& bExit, uint32_t nFlag) { - if (!m_bNotifying) { - CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot->Get()); - if (pWidget->GetAAction(CPDF_AAction::KeyStroke).GetDict()) { - ASSERT(pPageView); - m_bNotifying = true; - pWidget->ClearAppModified(); + if (m_bNotifying) + return true; - PDFSDK_FieldAction fa; - fa.bModifier = m_pFormFillEnv->IsCTRLKeyDown(nFlag); - fa.bShift = m_pFormFillEnv->IsSHIFTKeyDown(nFlag); - fa.bWillCommit = true; - fa.bKeyDown = true; - fa.bRC = true; - - CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, false); - pFormFiller->GetActionData(pPageView, CPDF_AAction::KeyStroke, fa); - pFormFiller->SaveState(pPageView); - pWidget->OnAAction(CPDF_AAction::KeyStroke, fa, pPageView); - if (!(*pAnnot)) - return; + CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot->Get()); + if (!pWidget->GetAAction(CPDF_AAction::KeyStroke).GetDict()) + return true; - bRC = fa.bRC; - m_bNotifying = false; - } - } + ASSERT(pPageView); + m_bNotifying = true; + pWidget->ClearAppModified(); + + PDFSDK_FieldAction fa; + fa.bModifier = m_pFormFillEnv->IsCTRLKeyDown(nFlag); + fa.bShift = m_pFormFillEnv->IsSHIFTKeyDown(nFlag); + fa.bWillCommit = true; + fa.bKeyDown = true; + fa.bRC = true; + + CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, false); + pFormFiller->GetActionData(pPageView, CPDF_AAction::KeyStroke, fa); + pFormFiller->SaveState(pPageView); + pWidget->OnAAction(CPDF_AAction::KeyStroke, fa, pPageView); + if (!(*pAnnot)) + return true; + + m_bNotifying = false; + return fa.bRC; } -void CFFL_InteractiveFormFiller::OnValidate(CPDFSDK_Annot::ObservedPtr* pAnnot, +bool CFFL_InteractiveFormFiller::OnValidate(CPDFSDK_Annot::ObservedPtr* pAnnot, CPDFSDK_PageView* pPageView, - bool& bRC, - bool& bExit, uint32_t nFlag) { - if (!m_bNotifying) { - CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot->Get()); - if (pWidget->GetAAction(CPDF_AAction::Validate).GetDict()) { - ASSERT(pPageView); - m_bNotifying = true; - pWidget->ClearAppModified(); + if (m_bNotifying) + return true; - PDFSDK_FieldAction fa; - fa.bModifier = m_pFormFillEnv->IsCTRLKeyDown(nFlag); - fa.bShift = m_pFormFillEnv->IsSHIFTKeyDown(nFlag); - fa.bKeyDown = true; - fa.bRC = true; + CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot->Get()); + if (!pWidget->GetAAction(CPDF_AAction::Validate).GetDict()) + return true; - CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, false); - pFormFiller->GetActionData(pPageView, CPDF_AAction::Validate, fa); - pFormFiller->SaveState(pPageView); - pWidget->OnAAction(CPDF_AAction::Validate, fa, pPageView); - if (!(*pAnnot)) - return; + ASSERT(pPageView); + m_bNotifying = true; + pWidget->ClearAppModified(); + + PDFSDK_FieldAction fa; + fa.bModifier = m_pFormFillEnv->IsCTRLKeyDown(nFlag); + fa.bShift = m_pFormFillEnv->IsSHIFTKeyDown(nFlag); + fa.bKeyDown = true; + fa.bRC = true; + + CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, false); + pFormFiller->GetActionData(pPageView, CPDF_AAction::Validate, fa); + pFormFiller->SaveState(pPageView); + pWidget->OnAAction(CPDF_AAction::Validate, fa, pPageView); + if (!(*pAnnot)) + return true; - bRC = fa.bRC; - m_bNotifying = false; - } - } + m_bNotifying = false; + return fa.bRC; } -void CFFL_InteractiveFormFiller::OnCalculate(CPDFSDK_Widget* pWidget, +void CFFL_InteractiveFormFiller::OnCalculate(CPDFSDK_Annot::ObservedPtr* pAnnot, CPDFSDK_PageView* pPageView, - bool& bExit, uint32_t nFlag) { - if (!m_bNotifying) { - ASSERT(pWidget); - CPDFSDK_InterForm* pInterForm = pPageView->GetFormFillEnv()->GetInterForm(); - pInterForm->OnCalculate(pWidget->GetFormField()); - m_bNotifying = false; - } + if (m_bNotifying) + return; + + CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot->Get()); + ASSERT(pWidget); + CPDFSDK_InterForm* pInterForm = pPageView->GetFormFillEnv()->GetInterForm(); + pInterForm->OnCalculate(pWidget->GetFormField()); + m_bNotifying = false; } -void CFFL_InteractiveFormFiller::OnFormat(CPDFSDK_Widget* pWidget, +void CFFL_InteractiveFormFiller::OnFormat(CPDFSDK_Annot::ObservedPtr* pAnnot, CPDFSDK_PageView* pPageView, - bool& bExit, uint32_t nFlag) { - if (!m_bNotifying) { - ASSERT(pWidget); - CPDFSDK_InterForm* pInterForm = pPageView->GetFormFillEnv()->GetInterForm(); - - bool bFormatted = false; - CFX_WideString sValue = - pInterForm->OnFormat(pWidget->GetFormField(), bFormatted); + if (m_bNotifying) + return; - if (bExit) - return; + CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot->Get()); + ASSERT(pWidget); + CPDFSDK_InterForm* pInterForm = pPageView->GetFormFillEnv()->GetInterForm(); - if (bFormatted) { - pInterForm->ResetFieldAppearance(pWidget->GetFormField(), &sValue, true); - pInterForm->UpdateField(pWidget->GetFormField()); - } + bool bFormatted = false; + CFX_WideString sValue = + pInterForm->OnFormat(pWidget->GetFormField(), bFormatted); + if (!(*pAnnot)) + return; - m_bNotifying = false; + if (bFormatted) { + pInterForm->ResetFieldAppearance(pWidget->GetFormField(), &sValue, true); + pInterForm->UpdateField(pWidget->GetFormField()); } + + m_bNotifying = false; } #ifdef PDF_ENABLE_XFA -void CFFL_InteractiveFormFiller::OnClick(CPDFSDK_Widget* pWidget, +bool CFFL_InteractiveFormFiller::OnClick(CPDFSDK_Annot::ObservedPtr* pAnnot, CPDFSDK_PageView* pPageView, - bool& bReset, - bool& bExit, uint32_t nFlag) { - if (!m_bNotifying) { - if (pWidget->HasXFAAAction(PDFSDK_XFA_Click)) { - m_bNotifying = true; - int nAge = pWidget->GetAppearanceAge(); - int nValueAge = pWidget->GetValueAge(); + if (m_bNotifying) + return false; - PDFSDK_FieldAction fa; - fa.bModifier = m_pFormFillEnv->IsCTRLKeyDown(nFlag); - fa.bShift = m_pFormFillEnv->IsSHIFTKeyDown(nFlag); + CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot->Get()); + if (!pWidget->HasXFAAAction(PDFSDK_XFA_Click)) + return false; - pWidget->OnXFAAAction(PDFSDK_XFA_Click, fa, pPageView); - m_bNotifying = false; + m_bNotifying = true; + int nAge = pWidget->GetAppearanceAge(); + int nValueAge = pWidget->GetValueAge(); - if (!IsValidAnnot(pPageView, pWidget)) { - bExit = true; - return; - } + PDFSDK_FieldAction fa; + fa.bModifier = m_pFormFillEnv->IsCTRLKeyDown(nFlag); + fa.bShift = m_pFormFillEnv->IsSHIFTKeyDown(nFlag); - if (nAge != pWidget->GetAppearanceAge()) { - if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, false)) { - pFormFiller->ResetPDFWindow(pPageView, - nValueAge == pWidget->GetValueAge()); - } + pWidget->OnXFAAAction(PDFSDK_XFA_Click, fa, pPageView); + m_bNotifying = false; + if (!(*pAnnot) || !IsValidAnnot(pPageView, pWidget)) + return true; + if (nAge == pWidget->GetAppearanceAge()) + return false; - bReset = true; - } - } - } + if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, false)) + pFormFiller->ResetPDFWindow(pPageView, nValueAge == pWidget->GetValueAge()); + return false; } -void CFFL_InteractiveFormFiller::OnFull(CPDFSDK_Widget* pWidget, +bool CFFL_InteractiveFormFiller::OnFull(CPDFSDK_Annot::ObservedPtr* pAnnot, CPDFSDK_PageView* pPageView, - bool& bReset, - bool& bExit, uint32_t nFlag) { - if (!m_bNotifying) { - if (pWidget->HasXFAAAction(PDFSDK_XFA_Full)) { - m_bNotifying = true; - int nAge = pWidget->GetAppearanceAge(); - int nValueAge = pWidget->GetValueAge(); + if (m_bNotifying) + return false; - PDFSDK_FieldAction fa; - fa.bModifier = m_pFormFillEnv->IsCTRLKeyDown(nFlag); - fa.bShift = m_pFormFillEnv->IsSHIFTKeyDown(nFlag); + CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot->Get()); + if (!pWidget->HasXFAAAction(PDFSDK_XFA_Full)) + return false; - pWidget->OnXFAAAction(PDFSDK_XFA_Full, fa, pPageView); - m_bNotifying = false; + m_bNotifying = true; + int nAge = pWidget->GetAppearanceAge(); + int nValueAge = pWidget->GetValueAge(); - if (!IsValidAnnot(pPageView, pWidget)) { - bExit = true; - return; - } + PDFSDK_FieldAction fa; + fa.bModifier = m_pFormFillEnv->IsCTRLKeyDown(nFlag); + fa.bShift = m_pFormFillEnv->IsSHIFTKeyDown(nFlag); - if (nAge != pWidget->GetAppearanceAge()) { - if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, false)) { - pFormFiller->ResetPDFWindow(pPageView, - nValueAge == pWidget->GetValueAge()); - } + pWidget->OnXFAAAction(PDFSDK_XFA_Full, fa, pPageView); + m_bNotifying = false; + if (!(*pAnnot) || !IsValidAnnot(pPageView, pWidget)) + return true; + if (nAge == pWidget->GetAppearanceAge()) + return false; - bReset = true; - } - } - } + if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, false)) + pFormFiller->ResetPDFWindow(pPageView, nValueAge == pWidget->GetValueAge()); + + return true; } -void CFFL_InteractiveFormFiller::OnPopupPreOpen(void* pPrivateData, - bool& bExit, +bool CFFL_InteractiveFormFiller::OnPopupPreOpen(void* pPrivateData, uint32_t nFlag) { - CFFL_PrivateData* pData = (CFFL_PrivateData*)pPrivateData; + CFFL_PrivateData* pData = reinterpret_cast<CFFL_PrivateData*>(pPrivateData); ASSERT(pData); ASSERT(pData->pWidget); - bool bTempReset = false; - bool bTempExit = false; - OnPreOpen(pData->pWidget, pData->pPageView, bTempReset, bTempExit, nFlag); - if (bTempReset || bTempExit) - bExit = true; + CPDFSDK_Annot::ObservedPtr pObserved(pData->pWidget); + return OnPreOpen(&pObserved, pData->pPageView, nFlag) || !pObserved; } -void CFFL_InteractiveFormFiller::OnPopupPostOpen(void* pPrivateData, - bool& bExit, +bool CFFL_InteractiveFormFiller::OnPopupPostOpen(void* pPrivateData, uint32_t nFlag) { - CFFL_PrivateData* pData = (CFFL_PrivateData*)pPrivateData; + CFFL_PrivateData* pData = reinterpret_cast<CFFL_PrivateData*>(pPrivateData); ASSERT(pData); ASSERT(pData->pWidget); - bool bTempReset = false; - bool bTempExit = false; - OnPostOpen(pData->pWidget, pData->pPageView, bTempReset, bTempExit, nFlag); - if (bTempReset || bTempExit) - bExit = true; + CPDFSDK_Annot::ObservedPtr pObserved(pData->pWidget); + return OnPostOpen(&pObserved, pData->pPageView, nFlag) || !pObserved; } -void CFFL_InteractiveFormFiller::OnPreOpen(CPDFSDK_Widget* pWidget, +bool CFFL_InteractiveFormFiller::OnPreOpen(CPDFSDK_Annot::ObservedPtr* pAnnot, CPDFSDK_PageView* pPageView, - bool& bReset, - bool& bExit, uint32_t nFlag) { - if (!m_bNotifying) { - if (pWidget->HasXFAAAction(PDFSDK_XFA_PreOpen)) { - m_bNotifying = true; - int nAge = pWidget->GetAppearanceAge(); - int nValueAge = pWidget->GetValueAge(); + if (m_bNotifying) + return false; - PDFSDK_FieldAction fa; - fa.bModifier = m_pFormFillEnv->IsCTRLKeyDown(nFlag); - fa.bShift = m_pFormFillEnv->IsSHIFTKeyDown(nFlag); + CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot->Get()); + if (!pWidget->HasXFAAAction(PDFSDK_XFA_PreOpen)) + return false; - pWidget->OnXFAAAction(PDFSDK_XFA_PreOpen, fa, pPageView); - m_bNotifying = false; + m_bNotifying = true; + int nAge = pWidget->GetAppearanceAge(); + int nValueAge = pWidget->GetValueAge(); - if (!IsValidAnnot(pPageView, pWidget)) { - bExit = true; - return; - } + PDFSDK_FieldAction fa; + fa.bModifier = m_pFormFillEnv->IsCTRLKeyDown(nFlag); + fa.bShift = m_pFormFillEnv->IsSHIFTKeyDown(nFlag); - if (nAge != pWidget->GetAppearanceAge()) { - if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, false)) { - pFormFiller->ResetPDFWindow(pPageView, - nValueAge == pWidget->GetValueAge()); - } + pWidget->OnXFAAAction(PDFSDK_XFA_PreOpen, fa, pPageView); + m_bNotifying = false; + if (!(*pAnnot) || !IsValidAnnot(pPageView, pWidget)) + return true; + if (nAge == pWidget->GetAppearanceAge()) + return false; - bReset = true; - } - } - } + if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, false)) + pFormFiller->ResetPDFWindow(pPageView, nValueAge == pWidget->GetValueAge()); + + return true; } -void CFFL_InteractiveFormFiller::OnPostOpen(CPDFSDK_Widget* pWidget, +bool CFFL_InteractiveFormFiller::OnPostOpen(CPDFSDK_Annot::ObservedPtr* pAnnot, CPDFSDK_PageView* pPageView, - bool& bReset, - bool& bExit, uint32_t nFlag) { - if (!m_bNotifying) { - if (pWidget->HasXFAAAction(PDFSDK_XFA_PostOpen)) { - m_bNotifying = true; - int nAge = pWidget->GetAppearanceAge(); - int nValueAge = pWidget->GetValueAge(); + if (m_bNotifying) + return false; - PDFSDK_FieldAction fa; - fa.bModifier = m_pFormFillEnv->IsCTRLKeyDown(nFlag); - fa.bShift = m_pFormFillEnv->IsSHIFTKeyDown(nFlag); + CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot->Get()); + if (!pWidget->HasXFAAAction(PDFSDK_XFA_PostOpen)) + return false; - pWidget->OnXFAAAction(PDFSDK_XFA_PostOpen, fa, pPageView); - m_bNotifying = false; + m_bNotifying = true; + int nAge = pWidget->GetAppearanceAge(); + int nValueAge = pWidget->GetValueAge(); - if (!IsValidAnnot(pPageView, pWidget)) { - bExit = true; - return; - } + PDFSDK_FieldAction fa; + fa.bModifier = m_pFormFillEnv->IsCTRLKeyDown(nFlag); + fa.bShift = m_pFormFillEnv->IsSHIFTKeyDown(nFlag); - if (nAge != pWidget->GetAppearanceAge()) { - if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, false)) { - pFormFiller->ResetPDFWindow(pPageView, - nValueAge == pWidget->GetValueAge()); - } + pWidget->OnXFAAAction(PDFSDK_XFA_PostOpen, fa, pPageView); + m_bNotifying = false; + if (!(*pAnnot) || !IsValidAnnot(pPageView, pWidget)) + return true; + if (nAge == pWidget->GetAppearanceAge()) + return false; - bReset = true; - } - } - } + if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, false)) + pFormFiller->ResetPDFWindow(pPageView, nValueAge == pWidget->GetValueAge()); + + return true; } #endif // PDF_ENABLE_XFA @@ -873,95 +842,83 @@ bool CFFL_InteractiveFormFiller::IsValidAnnot(CPDFSDK_PageView* pPageView, return pPageView && pPageView->IsValidAnnot(pAnnot->GetPDFAnnot()); } -void CFFL_InteractiveFormFiller::OnBeforeKeyStroke( +std::pair<bool, bool> CFFL_InteractiveFormFiller::OnBeforeKeyStroke( void* pPrivateData, CFX_WideString& strChange, const CFX_WideString& strChangeEx, int nSelStart, int nSelEnd, bool bKeyDown, - bool& bRC, - bool& bExit, uint32_t nFlag) { - CFFL_PrivateData* pData = (CFFL_PrivateData*)pPrivateData; + bool bRC = true; + bool bExit = false; + CFFL_PrivateData* pData = reinterpret_cast<CFFL_PrivateData*>(pPrivateData); ASSERT(pData->pWidget); CFFL_FormFiller* pFormFiller = GetFormFiller(pData->pWidget, false); #ifdef PDF_ENABLE_XFA if (pFormFiller->IsFieldFull(pData->pPageView)) { - bool bFullExit = false; - bool bFullReset = false; - OnFull(pData->pWidget, pData->pPageView, bFullReset, bFullExit, nFlag); - - if (bFullReset || bFullExit) { - bExit = true; - return; - } + CPDFSDK_Annot::ObservedPtr pObserved(pData->pWidget); + if (OnFull(&pObserved, pData->pPageView, nFlag) || !pObserved) + return {bRC, true}; } #endif // PDF_ENABLE_XFA - if (!m_bNotifying) { - if (pData->pWidget->GetAAction(CPDF_AAction::KeyStroke).GetDict()) { - m_bNotifying = true; - int nAge = pData->pWidget->GetAppearanceAge(); - int nValueAge = pData->pWidget->GetValueAge(); + if (m_bNotifying || + !pData->pWidget->GetAAction(CPDF_AAction::KeyStroke).GetDict()) { + return {bRC, bExit}; + } - CPDFSDK_FormFillEnvironment* pFormFillEnv = - pData->pPageView->GetFormFillEnv(); + CFX_AutoRestorer<bool> restorer(&m_bNotifying); + m_bNotifying = true; + int nAge = pData->pWidget->GetAppearanceAge(); + int nValueAge = pData->pWidget->GetValueAge(); + + CPDFSDK_FormFillEnvironment* pFormFillEnv = + pData->pPageView->GetFormFillEnv(); + + PDFSDK_FieldAction fa; + fa.bModifier = m_pFormFillEnv->IsCTRLKeyDown(nFlag); + fa.bShift = m_pFormFillEnv->IsSHIFTKeyDown(nFlag); + fa.sChange = strChange; + fa.sChangeEx = strChangeEx; + fa.bKeyDown = bKeyDown; + fa.bWillCommit = false; + fa.bRC = true; + fa.nSelStart = nSelStart; + fa.nSelEnd = nSelEnd; + + pFormFiller->GetActionData(pData->pPageView, CPDF_AAction::KeyStroke, fa); + pFormFiller->SaveState(pData->pPageView); + + CPDFSDK_Annot::ObservedPtr pObserved(pData->pWidget); + if (!pData->pWidget->OnAAction(CPDF_AAction::KeyStroke, fa, + pData->pPageView)) { + if (!IsValidAnnot(pData->pPageView, pData->pWidget)) + bExit = true; + return {bRC, bExit}; + } - PDFSDK_FieldAction fa; - fa.bModifier = m_pFormFillEnv->IsCTRLKeyDown(nFlag); - fa.bShift = m_pFormFillEnv->IsSHIFTKeyDown(nFlag); - fa.sChange = strChange; - fa.sChangeEx = strChangeEx; - fa.bKeyDown = bKeyDown; - fa.bWillCommit = false; - fa.bRC = true; - fa.nSelStart = nSelStart; - fa.nSelEnd = nSelEnd; - - pFormFiller->GetActionData(pData->pPageView, CPDF_AAction::KeyStroke, fa); - pFormFiller->SaveState(pData->pPageView); - - CPDFSDK_Annot::ObservedPtr pObserved(pData->pWidget); - if (pData->pWidget->OnAAction(CPDF_AAction::KeyStroke, fa, - pData->pPageView)) { - if (!pObserved || !IsValidAnnot(pData->pPageView, pData->pWidget)) { - bExit = true; - m_bNotifying = false; - return; - } + if (!pObserved || !IsValidAnnot(pData->pPageView, pData->pWidget)) + return {bRC, true}; - if (nAge != pData->pWidget->GetAppearanceAge()) { - CPWL_Wnd* pWnd = pFormFiller->ResetPDFWindow( - pData->pPageView, nValueAge == pData->pWidget->GetValueAge()); - pData = (CFFL_PrivateData*)pWnd->GetAttachedData(); - bExit = true; - } + if (nAge != pData->pWidget->GetAppearanceAge()) { + CPWL_Wnd* pWnd = pFormFiller->ResetPDFWindow( + pData->pPageView, nValueAge == pData->pWidget->GetValueAge()); + pData = reinterpret_cast<CFFL_PrivateData*>(pWnd->GetAttachedData()); + bExit = true; + } - if (fa.bRC) { - pFormFiller->SetActionData(pData->pPageView, CPDF_AAction::KeyStroke, - fa); - bRC = false; - } else { - pFormFiller->RestoreState(pData->pPageView); - bRC = false; - } + if (fa.bRC) + pFormFiller->SetActionData(pData->pPageView, CPDF_AAction::KeyStroke, fa); + else + pFormFiller->RestoreState(pData->pPageView); + bRC = false; - if (pFormFillEnv->GetFocusAnnot() != pData->pWidget) { - pFormFiller->CommitData(pData->pPageView, nFlag); - bExit = true; - } - } else { - if (!IsValidAnnot(pData->pPageView, pData->pWidget)) { - bExit = true; - m_bNotifying = false; - return; - } - } + if (pFormFillEnv->GetFocusAnnot() == pData->pWidget) + return {bRC, bExit}; - m_bNotifying = false; - } - } + pFormFiller->CommitData(pData->pPageView, nFlag); + return {bRC, true}; } diff --git a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_interactiveformfiller.h b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_interactiveformfiller.h index 751abf6e791..fb141e17a46 100644 --- a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_interactiveformfiller.h +++ b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_interactiveformfiller.h @@ -9,11 +9,12 @@ #include <map> #include <memory> +#include <utility> #include "core/fxcrt/cfx_unowned_ptr.h" #include "fpdfsdk/cpdfsdk_annot.h" #include "fpdfsdk/fsdk_define.h" -#include "fpdfsdk/pdfwindow/PWL_Edit.h" +#include "fpdfsdk/pdfwindow/cpwl_edit.h" class CFFL_FormFiller; class CPDFSDK_FormFillEnvironment; @@ -82,55 +83,40 @@ class CFFL_InteractiveFormFiller : public IPWL_Filler_Notify { CFFL_FormFiller* GetFormFiller(CPDFSDK_Annot* pAnnot, bool bRegister); void RemoveFormFiller(CPDFSDK_Annot* pAnnot); + CFX_WideString GetSelectedText(CPDFSDK_Annot* pAnnot); + static bool IsVisible(CPDFSDK_Widget* pWidget); static bool IsReadOnly(CPDFSDK_Widget* pWidget); static bool IsFillingAllowed(CPDFSDK_Widget* pWidget); static bool IsValidAnnot(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot); - void OnKeyStrokeCommit(CPDFSDK_Annot::ObservedPtr* pWidget, + bool OnKeyStrokeCommit(CPDFSDK_Annot::ObservedPtr* pWidget, CPDFSDK_PageView* pPageView, - bool& bRC, - bool& bExit, uint32_t nFlag); - void OnValidate(CPDFSDK_Annot::ObservedPtr* pWidget, + bool OnValidate(CPDFSDK_Annot::ObservedPtr* pAnnot, CPDFSDK_PageView* pPageView, - bool& bRC, - bool& bExit, uint32_t nFlag); - - void OnCalculate(CPDFSDK_Widget* pWidget, + void OnCalculate(CPDFSDK_Annot::ObservedPtr* pAnnot, CPDFSDK_PageView* pPageView, - bool& bExit, uint32_t nFlag); - void OnFormat(CPDFSDK_Widget* pWidget, + void OnFormat(CPDFSDK_Annot::ObservedPtr* pAnnot, CPDFSDK_PageView* pPageView, - bool& bExit, uint32_t nFlag); - void OnButtonUp(CPDFSDK_Annot::ObservedPtr* pWidget, + bool OnButtonUp(CPDFSDK_Annot::ObservedPtr* pAnnot, CPDFSDK_PageView* pPageView, - bool& bReset, - bool& bExit, uint32_t nFlag); #ifdef PDF_ENABLE_XFA - void OnClick(CPDFSDK_Widget* pWidget, + bool OnClick(CPDFSDK_Annot::ObservedPtr* pAnnot, CPDFSDK_PageView* pPageView, - bool& bReset, - bool& bExit, uint32_t nFlag); - void OnFull(CPDFSDK_Widget* pWidget, + bool OnFull(CPDFSDK_Annot::ObservedPtr* pAnnot, CPDFSDK_PageView* pPageView, - bool& bReset, - bool& bExit, uint32_t nFlag); - void OnPreOpen(CPDFSDK_Widget* pWidget, + bool OnPreOpen(CPDFSDK_Annot::ObservedPtr* pAnnot, CPDFSDK_PageView* pPageView, - bool& bReset, - bool& bExit, uint32_t nFlag); - void OnPostOpen(CPDFSDK_Widget* pWidget, + bool OnPostOpen(CPDFSDK_Annot::ObservedPtr* pAnnot, CPDFSDK_PageView* pPageView, - bool& bReset, - bool& bExit, uint32_t nFlag); #endif // PDF_ENABLE_XFA @@ -142,22 +128,19 @@ class CFFL_InteractiveFormFiller : public IPWL_Filler_Notify { void QueryWherePopup(void* pPrivateData, float fPopupMin, float fPopupMax, - int32_t& nRet, - float& fPopupRet) override; - void OnBeforeKeyStroke(void* pPrivateData, - CFX_WideString& strChange, - const CFX_WideString& strChangeEx, - int nSelStart, - int nSelEnd, - bool bKeyDown, - bool& bRC, - bool& bExit, - uint32_t nFlag) override; + bool* bBottom, + float* fPopupRet) override; + // Returns {bRC, bExit}. + std::pair<bool, bool> OnBeforeKeyStroke(void* pPrivateData, + CFX_WideString& strChange, + const CFX_WideString& strChangeEx, + int nSelStart, + int nSelEnd, + bool bKeyDown, + uint32_t nFlag) override; #ifdef PDF_ENABLE_XFA - void OnPopupPreOpen(void* pPrivateData, bool& bExit, uint32_t nFlag) override; - void OnPopupPostOpen(void* pPrivateData, - bool& bExit, - uint32_t nFlag) override; + bool OnPopupPreOpen(void* pPrivateData, uint32_t nFlag) override; + bool OnPopupPostOpen(void* pPrivateData, uint32_t nFlag) override; void SetFocusAnnotTab(CPDFSDK_Annot* pWidget, bool bSameField, bool bNext); #endif // PDF_ENABLE_XFA void UnRegisterFormFiller(CPDFSDK_Annot* pAnnot); diff --git a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_listbox.cpp b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_listbox.cpp index 556e0e17d71..4a6264d6dc2 100644 --- a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_listbox.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_listbox.cpp @@ -12,25 +12,22 @@ #include "fpdfsdk/formfiller/cffl_formfiller.h" #include "fpdfsdk/formfiller/cffl_interactiveformfiller.h" #include "fpdfsdk/fsdk_common.h" -#include "fpdfsdk/pdfwindow/PWL_ListBox.h" +#include "fpdfsdk/pdfwindow/cpwl_list_box.h" #include "third_party/base/ptr_util.h" #define FFL_DEFAULTLISTBOXFONTSIZE 12.0f CFFL_ListBox::CFFL_ListBox(CPDFSDK_FormFillEnvironment* pApp, - CPDFSDK_Annot* pWidget) + CPDFSDK_Widget* pWidget) : CFFL_FormFiller(pApp, pWidget) {} CFFL_ListBox::~CFFL_ListBox() {} PWL_CREATEPARAM CFFL_ListBox::GetCreateParam() { PWL_CREATEPARAM cp = CFFL_FormFiller::GetCreateParam(); - uint32_t dwFieldFlag = m_pWidget->GetFieldFlags(); - - if (dwFieldFlag & FIELDFLAG_MULTISELECT) { + if (dwFieldFlag & FIELDFLAG_MULTISELECT) cp.dwFlags |= PLBS_MULTIPLESEL; - } cp.dwFlags |= PWS_VSCROLL; @@ -39,15 +36,13 @@ PWL_CREATEPARAM CFFL_ListBox::GetCreateParam() { if (!m_pFontMap) { m_pFontMap = pdfium::MakeUnique<CBA_FontMap>( - m_pWidget, m_pFormFillEnv->GetSysHandler()); + m_pWidget.Get(), m_pFormFillEnv->GetSysHandler()); } cp.pFontMap = m_pFontMap.get(); - return cp; } -CPWL_Wnd* CFFL_ListBox::NewPDFWindow(const PWL_CREATEPARAM& cp, - CPDFSDK_PageView* pPageView) { +CPWL_Wnd* CFFL_ListBox::NewPDFWindow(const PWL_CREATEPARAM& cp) { CPWL_ListBox* pWnd = new CPWL_ListBox(); pWnd->AttachFFLData(this); pWnd->Create(cp); @@ -194,17 +189,10 @@ CPWL_Wnd* CFFL_ListBox::ResetPDFWindow(CPDFSDK_PageView* pPageView, SaveState(pPageView); DestroyPDFWindow(pPageView); - - CPWL_Wnd* pRet = nullptr; - - if (bRestoreValue) { + if (bRestoreValue) RestoreState(pPageView); - pRet = GetPDFWindow(pPageView, false); - } else { - pRet = GetPDFWindow(pPageView, true); - } - - m_pWidget->UpdateField(); - return pRet; + CPWL_Wnd::ObservedPtr pRet(GetPDFWindow(pPageView, !bRestoreValue)); + m_pWidget->UpdateField(); // May invoke JS, invalidating pRet. + return pRet.Get(); } diff --git a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_listbox.h b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_listbox.h index 609f2c48096..7c2713ca0fc 100644 --- a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_listbox.h +++ b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_listbox.h @@ -17,13 +17,12 @@ class CBA_FontMap; class CFFL_ListBox : public CFFL_FormFiller { public: - CFFL_ListBox(CPDFSDK_FormFillEnvironment* pApp, CPDFSDK_Annot* pWidget); + CFFL_ListBox(CPDFSDK_FormFillEnvironment* pApp, CPDFSDK_Widget* pWidget); ~CFFL_ListBox() override; // CFFL_FormFiller PWL_CREATEPARAM GetCreateParam() override; - CPWL_Wnd* NewPDFWindow(const PWL_CREATEPARAM& cp, - CPDFSDK_PageView* pPageView) override; + CPWL_Wnd* NewPDFWindow(const PWL_CREATEPARAM& cp) override; bool OnChar(CPDFSDK_Annot* pAnnot, uint32_t nChar, uint32_t nFlags) override; bool IsDataChanged(CPDFSDK_PageView* pPageView) override; void SaveData(CPDFSDK_PageView* pPageView) override; diff --git a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_pushbutton.cpp b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_pushbutton.cpp index 9b4121af9d1..d0d51b7b37c 100644 --- a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_pushbutton.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_pushbutton.cpp @@ -7,16 +7,15 @@ #include "fpdfsdk/formfiller/cffl_pushbutton.h" #include "fpdfsdk/formfiller/cffl_formfiller.h" -#include "fpdfsdk/pdfwindow/PWL_SpecialButton.h" +#include "fpdfsdk/pdfwindow/cpwl_special_button.h" CFFL_PushButton::CFFL_PushButton(CPDFSDK_FormFillEnvironment* pApp, - CPDFSDK_Annot* pAnnot) - : CFFL_Button(pApp, pAnnot) {} + CPDFSDK_Widget* pWidget) + : CFFL_Button(pApp, pWidget) {} CFFL_PushButton::~CFFL_PushButton() {} -CPWL_Wnd* CFFL_PushButton::NewPDFWindow(const PWL_CREATEPARAM& cp, - CPDFSDK_PageView* pPageView) { +CPWL_Wnd* CFFL_PushButton::NewPDFWindow(const PWL_CREATEPARAM& cp) { CPWL_PushButton* pWnd = new CPWL_PushButton(); pWnd->Create(cp); diff --git a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_pushbutton.h b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_pushbutton.h index 1d50595c875..9ae4752fa98 100644 --- a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_pushbutton.h +++ b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_pushbutton.h @@ -7,16 +7,15 @@ #ifndef FPDFSDK_FORMFILLER_CFFL_PUSHBUTTON_H_ #define FPDFSDK_FORMFILLER_CFFL_PUSHBUTTON_H_ -#include "fpdfsdk/formfiller/cffl_formfiller.h" +#include "fpdfsdk/formfiller/cffl_button.h" class CFFL_PushButton : public CFFL_Button { public: - CFFL_PushButton(CPDFSDK_FormFillEnvironment* pApp, CPDFSDK_Annot* pAnnot); + CFFL_PushButton(CPDFSDK_FormFillEnvironment* pApp, CPDFSDK_Widget* pWidget); ~CFFL_PushButton() override; // CFFL_Button - CPWL_Wnd* NewPDFWindow(const PWL_CREATEPARAM& cp, - CPDFSDK_PageView* pPageView) override; + CPWL_Wnd* NewPDFWindow(const PWL_CREATEPARAM& cp) override; bool OnChar(CPDFSDK_Annot* pAnnot, uint32_t nChar, uint32_t nFlags) override; void OnDraw(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, diff --git a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_radiobutton.cpp b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_radiobutton.cpp index e78160e5dce..e36e1f75547 100644 --- a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_radiobutton.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_radiobutton.cpp @@ -9,17 +9,16 @@ #include "fpdfsdk/cpdfsdk_formfillenvironment.h" #include "fpdfsdk/cpdfsdk_widget.h" #include "fpdfsdk/formfiller/cffl_formfiller.h" -#include "fpdfsdk/pdfwindow/PWL_SpecialButton.h" +#include "fpdfsdk/pdfwindow/cpwl_special_button.h" #include "public/fpdf_fwlevent.h" CFFL_RadioButton::CFFL_RadioButton(CPDFSDK_FormFillEnvironment* pApp, - CPDFSDK_Annot* pWidget) + CPDFSDK_Widget* pWidget) : CFFL_Button(pApp, pWidget) {} CFFL_RadioButton::~CFFL_RadioButton() {} -CPWL_Wnd* CFFL_RadioButton::NewPDFWindow(const PWL_CREATEPARAM& cp, - CPDFSDK_PageView* pPageView) { +CPWL_Wnd* CFFL_RadioButton::NewPDFWindow(const PWL_CREATEPARAM& cp) { CPWL_RadioButton* pWnd = new CPWL_RadioButton(); pWnd->Create(cp); @@ -49,20 +48,18 @@ bool CFFL_RadioButton::OnChar(CPDFSDK_Annot* pAnnot, CPDFSDK_PageView* pPageView = pAnnot->GetPageView(); ASSERT(pPageView); - bool bReset = false; - bool bExit = false; - CPDFSDK_Annot::ObservedPtr pObserved(m_pWidget); - m_pFormFillEnv->GetInteractiveFormFiller()->OnButtonUp( - &pObserved, pPageView, bReset, bExit, nFlags); - if (!pObserved || bReset || bExit) + CPDFSDK_Annot::ObservedPtr pObserved(m_pWidget.Get()); + if (m_pFormFillEnv->GetInteractiveFormFiller()->OnButtonUp( + &pObserved, pPageView, nFlags) || + !pObserved) { return true; + } CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags); - if (CPWL_RadioButton* pWnd = - (CPWL_RadioButton*)GetPDFWindow(pPageView, true)) + CPWL_RadioButton* pWnd = GetRadioButton(pPageView, true); + if (pWnd) pWnd->SetCheck(true); - CommitData(pPageView, nFlags); - return true; + return CommitData(pPageView, nFlags); } default: return CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags); @@ -75,45 +72,45 @@ bool CFFL_RadioButton::OnLButtonUp(CPDFSDK_PageView* pPageView, const CFX_PointF& point) { CFFL_Button::OnLButtonUp(pPageView, pAnnot, nFlags, point); - if (IsValid()) { - if (CPWL_RadioButton* pWnd = - (CPWL_RadioButton*)GetPDFWindow(pPageView, true)) - pWnd->SetCheck(true); + if (!IsValid()) + return true; - if (!CommitData(pPageView, nFlags)) - return false; - } + CPWL_RadioButton* pWnd = GetRadioButton(pPageView, true); + if (pWnd) + pWnd->SetCheck(true); - return true; + return CommitData(pPageView, nFlags); } bool CFFL_RadioButton::IsDataChanged(CPDFSDK_PageView* pPageView) { - if (CPWL_RadioButton* pWnd = - (CPWL_RadioButton*)GetPDFWindow(pPageView, false)) { - return pWnd->IsChecked() != m_pWidget->IsChecked(); - } - - return false; + CPWL_RadioButton* pWnd = GetRadioButton(pPageView, false); + return pWnd && pWnd->IsChecked() != m_pWidget->IsChecked(); } void CFFL_RadioButton::SaveData(CPDFSDK_PageView* pPageView) { - if (CPWL_RadioButton* pWnd = - (CPWL_RadioButton*)GetPDFWindow(pPageView, false)) { - bool bNewChecked = pWnd->IsChecked(); - - if (bNewChecked) { - CPDF_FormField* pField = m_pWidget->GetFormField(); - for (int32_t i = 0, sz = pField->CountControls(); i < sz; i++) { - if (CPDF_FormControl* pCtrl = pField->GetControl(i)) { - if (pCtrl->IsChecked()) { - break; - } + CPWL_RadioButton* pWnd = GetRadioButton(pPageView, false); + if (!pWnd) + return; + + bool bNewChecked = pWnd->IsChecked(); + + if (bNewChecked) { + CPDF_FormField* pField = m_pWidget->GetFormField(); + for (int32_t i = 0, sz = pField->CountControls(); i < sz; i++) { + if (CPDF_FormControl* pCtrl = pField->GetControl(i)) { + if (pCtrl->IsChecked()) { + break; } } } - - m_pWidget->SetCheck(bNewChecked, false); - m_pWidget->UpdateField(); - SetChangeMark(); } + + m_pWidget->SetCheck(bNewChecked, false); + m_pWidget->UpdateField(); + SetChangeMark(); +} + +CPWL_RadioButton* CFFL_RadioButton::GetRadioButton(CPDFSDK_PageView* pPageView, + bool bNew) { + return static_cast<CPWL_RadioButton*>(GetPDFWindow(pPageView, bNew)); } diff --git a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_radiobutton.h b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_radiobutton.h index 10ac37dcb87..981e2df62e0 100644 --- a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_radiobutton.h +++ b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_radiobutton.h @@ -7,16 +7,17 @@ #ifndef FPDFSDK_FORMFILLER_CFFL_RADIOBUTTON_H_ #define FPDFSDK_FORMFILLER_CFFL_RADIOBUTTON_H_ -#include "fpdfsdk/formfiller/cffl_formfiller.h" +#include "fpdfsdk/formfiller/cffl_button.h" + +class CPWL_RadioButton; class CFFL_RadioButton : public CFFL_Button { public: - CFFL_RadioButton(CPDFSDK_FormFillEnvironment* pApp, CPDFSDK_Annot* pAnnot); + CFFL_RadioButton(CPDFSDK_FormFillEnvironment* pApp, CPDFSDK_Widget* pWidget); ~CFFL_RadioButton() override; // CFFL_Button - CPWL_Wnd* NewPDFWindow(const PWL_CREATEPARAM& cp, - CPDFSDK_PageView* pPageView) override; + CPWL_Wnd* NewPDFWindow(const PWL_CREATEPARAM& cp) override; bool OnKeyDown(CPDFSDK_Annot* pAnnot, uint32_t nKeyCode, uint32_t nFlags) override; @@ -27,6 +28,9 @@ class CFFL_RadioButton : public CFFL_Button { const CFX_PointF& point) override; bool IsDataChanged(CPDFSDK_PageView* pPageView) override; void SaveData(CPDFSDK_PageView* pPageView) override; + + private: + CPWL_RadioButton* GetRadioButton(CPDFSDK_PageView* pPageView, bool bNew); }; #endif // FPDFSDK_FORMFILLER_CFFL_RADIOBUTTON_H_ diff --git a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_textfield.cpp b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_textfield.cpp index 71fc9291dc5..d598419c1bf 100644 --- a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_textfield.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_textfield.cpp @@ -13,8 +13,8 @@ #include "third_party/base/ptr_util.h" CFFL_TextField::CFFL_TextField(CPDFSDK_FormFillEnvironment* pApp, - CPDFSDK_Annot* pAnnot) - : CFFL_FormFiller(pApp, pAnnot) {} + CPDFSDK_Widget* pWidget) + : CFFL_FormFiller(pApp, pWidget) {} CFFL_TextField::~CFFL_TextField() { for (const auto& it : m_Maps) @@ -28,34 +28,25 @@ CFFL_TextField::~CFFL_TextField() { PWL_CREATEPARAM CFFL_TextField::GetCreateParam() { PWL_CREATEPARAM cp = CFFL_FormFiller::GetCreateParam(); - int nFlags = m_pWidget->GetFieldFlags(); - - if (nFlags & FIELDFLAG_PASSWORD) { + if (nFlags & FIELDFLAG_PASSWORD) cp.dwFlags |= PES_PASSWORD; - } if (nFlags & FIELDFLAG_MULTILINE) { cp.dwFlags |= PES_MULTILINE | PES_AUTORETURN | PES_TOP; - - if (!(nFlags & FIELDFLAG_DONOTSCROLL)) { + if (!(nFlags & FIELDFLAG_DONOTSCROLL)) cp.dwFlags |= PWS_VSCROLL | PES_AUTOSCROLL; - } } else { cp.dwFlags |= PES_CENTER; - - if (!(nFlags & FIELDFLAG_DONOTSCROLL)) { + if (!(nFlags & FIELDFLAG_DONOTSCROLL)) cp.dwFlags |= PES_AUTOSCROLL; - } } - if (nFlags & FIELDFLAG_COMB) { + if (nFlags & FIELDFLAG_COMB) cp.dwFlags |= PES_CHARARRAY; - } - if (nFlags & FIELDFLAG_RICHTEXT) { + if (nFlags & FIELDFLAG_RICHTEXT) cp.dwFlags |= PES_RICH; - } cp.dwFlags |= PES_UNDO; @@ -71,19 +62,16 @@ PWL_CREATEPARAM CFFL_TextField::GetCreateParam() { cp.dwFlags |= PES_RIGHT; break; } - if (!m_pFontMap) { m_pFontMap = pdfium::MakeUnique<CBA_FontMap>( - m_pWidget, m_pFormFillEnv->GetSysHandler()); + m_pWidget.Get(), m_pFormFillEnv->GetSysHandler()); } cp.pFontMap = m_pFontMap.get(); cp.pFocusHandler = this; - return cp; } -CPWL_Wnd* CFFL_TextField::NewPDFWindow(const PWL_CREATEPARAM& cp, - CPDFSDK_PageView* pPageView) { +CPWL_Wnd* CFFL_TextField::NewPDFWindow(const PWL_CREATEPARAM& cp) { CPWL_Edit* pWnd = new CPWL_Edit(); pWnd->AttachFFLData(this); pWnd->Create(cp); @@ -109,26 +97,28 @@ bool CFFL_TextField::OnChar(CPDFSDK_Annot* pAnnot, uint32_t nChar, uint32_t nFlags) { switch (nChar) { - case FWL_VKEY_Return: - if (!(m_pWidget->GetFieldFlags() & FIELDFLAG_MULTILINE)) { - CPDFSDK_PageView* pPageView = GetCurPageView(true); - ASSERT(pPageView); - m_bValid = !m_bValid; - m_pFormFillEnv->Invalidate(pAnnot->GetUnderlyingPage(), - pAnnot->GetRect().ToFxRect()); - - if (m_bValid) { - if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, true)) - pWnd->SetFocus(); - } else { - if (CommitData(pPageView, nFlags)) { - DestroyPDFWindow(pPageView); - return true; - } - return false; - } + case FWL_VKEY_Return: { + if (m_pWidget->GetFieldFlags() & FIELDFLAG_MULTILINE) + break; + + CPDFSDK_PageView* pPageView = GetCurPageView(true); + ASSERT(pPageView); + m_bValid = !m_bValid; + m_pFormFillEnv->Invalidate(pAnnot->GetUnderlyingPage(), + pAnnot->GetRect().ToFxRect()); + + if (m_bValid) { + if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, true)) + pWnd->SetFocus(); + break; } - break; + + if (!CommitData(pPageView, nFlags)) + return false; + + DestroyPDFWindow(pPageView); + return true; + } case FWL_VKEY_Escape: { CPDFSDK_PageView* pPageView = GetCurPageView(true); ASSERT(pPageView); @@ -141,22 +131,22 @@ bool CFFL_TextField::OnChar(CPDFSDK_Annot* pAnnot, } bool CFFL_TextField::IsDataChanged(CPDFSDK_PageView* pPageView) { - if (CPWL_Edit* pEdit = (CPWL_Edit*)GetPDFWindow(pPageView, false)) - return pEdit->GetText() != m_pWidget->GetValue(); - - return false; + CPWL_Edit* pEdit = GetEdit(pPageView, false); + return pEdit && pEdit->GetText() != m_pWidget->GetValue(); } void CFFL_TextField::SaveData(CPDFSDK_PageView* pPageView) { - if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, false)) { - CFX_WideString sOldValue = m_pWidget->GetValue(); - CFX_WideString sNewValue = pWnd->GetText(); - - m_pWidget->SetValue(sNewValue, false); - m_pWidget->ResetFieldAppearance(true); - m_pWidget->UpdateField(); - SetChangeMark(); - } + CPWL_Edit* pWnd = GetEdit(pPageView, false); + if (!pWnd) + return; + + CFX_WideString sOldValue = m_pWidget->GetValue(); + CFX_WideString sNewValue = pWnd->GetText(); + + m_pWidget->SetValue(sNewValue, false); + m_pWidget->ResetFieldAppearance(true); + m_pWidget->UpdateField(); + SetChangeMark(); } void CFFL_TextField::GetActionData(CPDFSDK_PageView* pPageView, @@ -164,7 +154,7 @@ void CFFL_TextField::GetActionData(CPDFSDK_PageView* pPageView, PDFSDK_FieldAction& fa) { switch (type) { case CPDF_AAction::KeyStroke: - if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, false)) { + if (CPWL_Edit* pWnd = GetEdit(pPageView, false)) { fa.bFieldFull = pWnd->IsTextFull(); fa.sValue = pWnd->GetText(); @@ -176,7 +166,7 @@ void CFFL_TextField::GetActionData(CPDFSDK_PageView* pPageView, } break; case CPDF_AAction::Validate: - if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, false)) { + if (CPWL_Edit* pWnd = GetEdit(pPageView, false)) { fa.sValue = pWnd->GetText(); } break; @@ -194,7 +184,7 @@ void CFFL_TextField::SetActionData(CPDFSDK_PageView* pPageView, const PDFSDK_FieldAction& fa) { switch (type) { case CPDF_AAction::KeyStroke: - if (CPWL_Edit* pEdit = (CPWL_Edit*)GetPDFWindow(pPageView, false)) { + if (CPWL_Edit* pEdit = GetEdit(pPageView, false)) { pEdit->SetFocus(); pEdit->SetSel(fa.nSelStart, fa.nSelEnd); pEdit->ReplaceSel(fa.sChange); @@ -223,19 +213,23 @@ bool CFFL_TextField::IsActionDataChanged(CPDF_AAction::AActionType type, void CFFL_TextField::SaveState(CPDFSDK_PageView* pPageView) { ASSERT(pPageView); - if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, false)) { - pWnd->GetSel(m_State.nStart, m_State.nEnd); - m_State.sValue = pWnd->GetText(); - } + CPWL_Edit* pWnd = GetEdit(pPageView, false); + if (!pWnd) + return; + + pWnd->GetSel(m_State.nStart, m_State.nEnd); + m_State.sValue = pWnd->GetText(); } void CFFL_TextField::RestoreState(CPDFSDK_PageView* pPageView) { ASSERT(pPageView); - if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, true)) { - pWnd->SetText(m_State.sValue); - pWnd->SetSel(m_State.nStart, m_State.nEnd); - } + CPWL_Edit* pWnd = GetEdit(pPageView, true); + if (!pWnd) + return; + + pWnd->SetText(m_State.sValue); + pWnd->SetSel(m_State.nStart, m_State.nEnd); } CPWL_Wnd* CFFL_TextField::ResetPDFWindow(CPDFSDK_PageView* pPageView, @@ -244,37 +238,22 @@ CPWL_Wnd* CFFL_TextField::ResetPDFWindow(CPDFSDK_PageView* pPageView, SaveState(pPageView); DestroyPDFWindow(pPageView); - - CPWL_Wnd* pRet = nullptr; - - if (bRestoreValue) { + if (bRestoreValue) RestoreState(pPageView); - pRet = GetPDFWindow(pPageView, false); - } else { - pRet = GetPDFWindow(pPageView, true); - } - - m_pWidget->UpdateField(); - return pRet; + CPWL_Wnd::ObservedPtr pRet(GetPDFWindow(pPageView, !bRestoreValue)); + m_pWidget->UpdateField(); // May invoke JS, invalidating pRet. + return pRet.Get(); } #ifdef PDF_ENABLE_XFA bool CFFL_TextField::IsFieldFull(CPDFSDK_PageView* pPageView) { - if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, false)) { - return pWnd->IsTextFull(); - } - - return false; + CPWL_Edit* pWnd = GetEdit(pPageView, false); + return pWnd && pWnd->IsTextFull(); } #endif // PDF_ENABLE_XFA -void CFFL_TextField::OnSetFocus(CPWL_Wnd* pWnd) { - ASSERT(m_pFormFillEnv); - if (pWnd->GetClassName() != PWL_CLASSNAME_EDIT) - return; - - CPWL_Edit* pEdit = (CPWL_Edit*)pWnd; +void CFFL_TextField::OnSetFocus(CPWL_Edit* pEdit) { pEdit->SetCharSet(FX_CHARSET_ChineseSimplified); pEdit->SetReadyToInput(); @@ -284,3 +263,7 @@ void CFFL_TextField::OnSetFocus(CPWL_Wnd* pWnd) { auto* pBuffer = reinterpret_cast<const unsigned short*>(bsUTFText.c_str()); m_pFormFillEnv->OnSetFieldInputFocus(pBuffer, nCharacters, true); } + +CPWL_Edit* CFFL_TextField::GetEdit(CPDFSDK_PageView* pPageView, bool bNew) { + return static_cast<CPWL_Edit*>(GetPDFWindow(pPageView, bNew)); +} diff --git a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_textfield.h b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_textfield.h index 29579f72a5f..91771a10c10 100644 --- a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_textfield.h +++ b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_textfield.h @@ -16,6 +16,7 @@ #define BF_ALIGN_RIGHT 2 class CBA_FontMap; +class CPWL_Edit; struct FFL_TextFieldState { FFL_TextFieldState() : nStart(0), nEnd(0) {} @@ -27,13 +28,12 @@ struct FFL_TextFieldState { class CFFL_TextField : public CFFL_FormFiller, public IPWL_FocusHandler { public: - CFFL_TextField(CPDFSDK_FormFillEnvironment* pApp, CPDFSDK_Annot* pAnnot); + CFFL_TextField(CPDFSDK_FormFillEnvironment* pApp, CPDFSDK_Widget* pWidget); ~CFFL_TextField() override; // CFFL_FormFiller: PWL_CREATEPARAM GetCreateParam() override; - CPWL_Wnd* NewPDFWindow(const PWL_CREATEPARAM& cp, - CPDFSDK_PageView* pPageView) override; + CPWL_Wnd* NewPDFWindow(const PWL_CREATEPARAM& cp) override; bool OnChar(CPDFSDK_Annot* pAnnot, uint32_t nChar, uint32_t nFlags) override; bool IsDataChanged(CPDFSDK_PageView* pPageView) override; void SaveData(CPDFSDK_PageView* pPageView) override; @@ -52,7 +52,7 @@ class CFFL_TextField : public CFFL_FormFiller, public IPWL_FocusHandler { bool bRestoreValue) override; // IPWL_FocusHandler: - void OnSetFocus(CPWL_Wnd* pWnd) override; + void OnSetFocus(CPWL_Edit* pEdit) override; #ifdef PDF_ENABLE_XFA // CFFL_FormFiller: @@ -60,6 +60,8 @@ class CFFL_TextField : public CFFL_FormFiller, public IPWL_FocusHandler { #endif // PDF_ENABLE_XFA private: + CPWL_Edit* GetEdit(CPDFSDK_PageView* pPageView, bool bNew); + std::unique_ptr<CBA_FontMap> m_pFontMap; FFL_TextFieldState m_State; }; diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdf_dataavail_embeddertest.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdf_dataavail_embeddertest.cpp index c226a31b8e8..8f37984c9b2 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdf_dataavail_embeddertest.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdf_dataavail_embeddertest.cpp @@ -194,9 +194,9 @@ TEST_F(FPDFDataAvailEmbeddertest, LoadUsingHintTables) { // No new data available, to prevent load "Pages" node. loader.set_is_new_data_available(false); - FPDF_PAGE page = LoadPage(1); + FPDF_PAGE page = FPDF_LoadPage(document(), 1); EXPECT_TRUE(page); - UnloadPage(page); + FPDF_ClosePage(page); } TEST_F(FPDFDataAvailEmbeddertest, @@ -234,7 +234,7 @@ TEST_F(FPDFDataAvailEmbeddertest, // Prevent loading data, while page loading. loader.set_is_new_data_available(false); - FPDF_PAGE page = LoadPage(first_page_num); + FPDF_PAGE page = FPDF_LoadPage(document(), first_page_num); EXPECT_TRUE(page); - UnloadPage(page); + FPDF_ClosePage(page); } diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdf_flatten.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdf_flatten.cpp index 914008c1a32..e530553f5a4 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdf_flatten.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdf_flatten.cpp @@ -29,23 +29,19 @@ enum FPDF_VALUE { TOP, LEFT, RIGHT, BOTTOM }; namespace { -bool IsValiableRect(CFX_FloatRect rect, CFX_FloatRect rcPage) { - if (rect.left - rect.right > 0.000001f || rect.bottom - rect.top > 0.000001f) +bool IsValidRect(const CFX_FloatRect& rect, const CFX_FloatRect& rcPage) { + constexpr float kMinSize = 0.000001f; + if (rect.IsEmpty() || rect.Width() < kMinSize || rect.Height() < kMinSize) return false; - if (rect.left == 0.0f && rect.top == 0.0f && rect.right == 0.0f && - rect.bottom == 0.0f) - return false; - - if (!rcPage.IsEmpty()) { - if (rect.left - rcPage.left < -10.000001f || - rect.right - rcPage.right > 10.000001f || - rect.top - rcPage.top > 10.000001f || - rect.bottom - rcPage.bottom < -10.000001f) - return false; - } + if (rcPage.IsEmpty()) + return true; - return true; + constexpr float kMinBorderSize = 10.000001f; + return rect.left - rcPage.left >= -kMinBorderSize && + rect.right - rcPage.right <= kMinBorderSize && + rect.top - rcPage.top <= kMinBorderSize && + rect.bottom - rcPage.bottom >= -kMinBorderSize; } void GetContentsRect(CPDF_Document* pDoc, @@ -60,7 +56,7 @@ void GetContentsRect(CPDF_Document* pDoc, rc.right = pPageObject->m_Right; rc.bottom = pPageObject->m_Bottom; rc.top = pPageObject->m_Top; - if (IsValiableRect(rc, pDict->GetRectFor("MediaBox"))) + if (IsValidRect(rc, pDict->GetRectFor("MediaBox"))) pRectArray->push_back(rc); } } @@ -77,7 +73,7 @@ void ParserStream(CPDF_Dictionary* pPageDic, else if (pStream->KeyExist("BBox")) rect = pStream->GetRectFor("BBox"); - if (IsValiableRect(rect, pPageDic->GetRectFor("MediaBox"))) + if (IsValidRect(rect, pPageDic->GetRectFor("MediaBox"))) pRectArray->push_back(rect); pObjectArray->push_back(pStream); @@ -96,9 +92,8 @@ int ParserAnnots(CPDF_Document* pSourceDoc, if (!pAnnots) return FLATTEN_NOTHINGTODO; - uint32_t dwSize = pAnnots->GetCount(); - for (int i = 0; i < (int)dwSize; i++) { - CPDF_Dictionary* pAnnotDic = ToDictionary(pAnnots->GetDirectObjectAt(i)); + for (const auto& pAnnot : *pAnnots) { + CPDF_Dictionary* pAnnotDic = ToDictionary(pAnnot->GetDirect()); if (!pAnnotDic) continue; @@ -110,15 +105,13 @@ int ParserAnnots(CPDF_Document* pSourceDoc, if (nAnnotFlag & ANNOTFLAG_HIDDEN) continue; - if (nUsage == FLAT_NORMALDISPLAY) { - if (nAnnotFlag & ANNOTFLAG_INVISIBLE) - continue; - + bool bParseStream; + if (nUsage == FLAT_NORMALDISPLAY) + bParseStream = !(nAnnotFlag & ANNOTFLAG_INVISIBLE); + else + bParseStream = !!(nAnnotFlag & ANNOTFLAG_PRINT); + if (bParseStream) ParserStream(pPageDic, pAnnotDic, pRectArray, pObjectArray); - } else { - if (nAnnotFlag & ANNOTFLAG_PRINT) - ParserStream(pPageDic, pAnnotDic, pRectArray, pObjectArray); - } } return FLATTEN_SUCCESS; } @@ -126,10 +119,10 @@ int ParserAnnots(CPDF_Document* pSourceDoc, float GetMinMaxValue(const std::vector<CFX_FloatRect>& array, FPDF_TYPE type, FPDF_VALUE value) { - size_t nRects = array.size(); - if (nRects <= 0) + if (array.empty()) return 0.0f; + size_t nRects = array.size(); std::vector<float> pArray(nRects); switch (value) { case LEFT: @@ -149,7 +142,7 @@ float GetMinMaxValue(const std::vector<CFX_FloatRect>& array, pArray[i] = array[i].bottom; break; default: - // Not reachable. + NOTREACHED(); return 0.0f; } @@ -330,7 +323,6 @@ DLLEXPORT int STDCALL FPDFPage_Flatten(FPDF_PAGE page, int nFlag) { pNewOXbjectDic->SetNewFor<CPDF_Name>("Type", "XObject"); pNewOXbjectDic->SetNewFor<CPDF_Name>("Subtype", "Form"); pNewOXbjectDic->SetNewFor<CPDF_Number>("FormType", 1); - pNewOXbjectDic->SetNewFor<CPDF_Name>("Name", "FRM"); CFX_FloatRect rcBBox = pPageDict->GetRectFor("ArtBox"); pNewOXbjectDic->SetRectFor("BBox", rcBBox); } @@ -357,9 +349,8 @@ DLLEXPORT int STDCALL FPDFPage_Flatten(FPDF_PAGE page, int nFlag) { if (!sAnnotState.IsEmpty()) { pAPStream = pAPDic->GetStreamFor(sAnnotState); } else { - auto it = pAPDic->begin(); - if (it != pAPDic->end()) { - CPDF_Object* pFirstObj = it->second.get(); + if (pAPDic->GetCount() > 0) { + CPDF_Object* pFirstObj = pAPDic->begin()->second.get(); if (pFirstObj) { if (pFirstObj->IsReference()) pFirstObj = pFirstObj->GetDirect(); @@ -409,17 +400,8 @@ DLLEXPORT int STDCALL FPDFPage_Flatten(FPDF_PAGE page, int nFlag) { pAcc->LoadAllData(); CFX_ByteString sStream(pAcc->GetData(), pAcc->GetSize()); CFX_Matrix matrix = pAPDic->GetMatrixFor("Matrix"); - if (matrix.IsIdentity()) { - matrix.a = 1.0f; - matrix.b = 0.0f; - matrix.c = 0.0f; - matrix.d = 1.0f; - matrix.e = 0.0f; - matrix.f = 0.0f; - } - - CFX_ByteString sTemp; CFX_Matrix m = GetMatrix(rcAnnot, rcStream, matrix); + CFX_ByteString sTemp; sTemp.Format("q %f 0 0 %f %f %f cm /%s Do Q\n", m.a, m.d, m.e, m.f, sFormName.c_str()); sStream += sTemp; diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdf_progressive.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdf_progressive.cpp index fc6ceab38e9..abddcd43ad5 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdf_progressive.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdf_progressive.cpp @@ -23,7 +23,7 @@ static_assert(CPDF_ProgressiveRenderer::Ready == FPDF_RENDER_READER, "CPDF_ProgressiveRenderer::Ready value mismatch"); static_assert(CPDF_ProgressiveRenderer::ToBeContinued == - FPDF_RENDER_TOBECOUNTINUED, + FPDF_RENDER_TOBECONTINUED, "CPDF_ProgressiveRenderer::ToBeContinued value mismatch"); static_assert(CPDF_ProgressiveRenderer::Done == FPDF_RENDER_DONE, "CPDF_ProgressiveRenderer::Done value mismatch"); @@ -60,6 +60,10 @@ DLLEXPORT int STDCALL FPDF_RenderPageBitmap_Start(FPDF_BITMAP bitmap, FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y, rotate, flags, false, &IPauseAdapter); +#ifdef _SKIA_SUPPORT_PATHS_ + pDevice->Flush(); + pBitmap->UnPreMultiply(); +#endif if (pContext->m_pRenderer) { return CPDF_ProgressiveRenderer::ToFPDFStatus( pContext->m_pRenderer->GetStatus()); @@ -80,6 +84,11 @@ DLLEXPORT int STDCALL FPDF_RenderPage_Continue(FPDF_PAGE page, if (pContext && pContext->m_pRenderer) { IFSDK_PAUSE_Adapter IPauseAdapter(pause); pContext->m_pRenderer->Continue(&IPauseAdapter); +#ifdef _SKIA_SUPPORT_PATHS_ + CFX_RenderDevice* pDevice = pContext->m_pDevice.get(); + pDevice->Flush(); + pDevice->GetBitmap()->UnPreMultiply(); +#endif return CPDF_ProgressiveRenderer::ToFPDFStatus( pContext->m_pRenderer->GetStatus()); } @@ -88,13 +97,6 @@ DLLEXPORT int STDCALL FPDF_RenderPage_Continue(FPDF_PAGE page, DLLEXPORT void STDCALL FPDF_RenderPage_Close(FPDF_PAGE page) { CPDF_Page* pPage = CPDFPageFromFPDFPage(page); - if (!pPage) - return; - - CPDF_PageRenderContext* pContext = pPage->GetRenderContext(); - if (!pContext) - return; - - pContext->m_pDevice->RestoreState(false); - pPage->SetRenderContext(nullptr); + if (pPage) + pPage->SetRenderContext(nullptr); } diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdf_structtree_embeddertest.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdf_structtree_embeddertest.cpp index 3110988d82f..43a4d0159f2 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdf_structtree_embeddertest.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdf_structtree_embeddertest.cpp @@ -7,7 +7,7 @@ #include "testing/embedder_test.h" #include "testing/test_support.h" -class FPDFStructTreeEmbeddertest : public EmbedderTest, public TestSaver {}; +class FPDFStructTreeEmbeddertest : public EmbedderTest {}; TEST_F(FPDFStructTreeEmbeddertest, GetAltText) { ASSERT_TRUE(OpenDocument("tagged_alt_text.pdf")); diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdf_sysfontinfo.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdf_sysfontinfo.cpp index 1f738875324..c424152326d 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdf_sysfontinfo.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdf_sysfontinfo.cpp @@ -14,7 +14,7 @@ #include "core/fxge/fx_font.h" #include "core/fxge/ifx_systemfontinfo.h" #include "fpdfsdk/fsdk_define.h" -#include "fpdfsdk/pdfwindow/PWL_FontMap.h" +#include "fpdfsdk/pdfwindow/cpwl_font_map.h" #include "third_party/base/ptr_util.h" static_assert(FXFONT_ANSI_CHARSET == FX_CHARSET_ANSI, "Charset must match"); @@ -123,13 +123,12 @@ DLLEXPORT const FPDF_CharsetFontMap* STDCALL FPDF_GetDefaultTTFMap() { } struct FPDF_SYSFONTINFO_DEFAULT : public FPDF_SYSFONTINFO { - IFX_SystemFontInfo* m_pFontInfo; + CFX_UnownedPtr<IFX_SystemFontInfo> m_pFontInfo; }; static void DefaultRelease(struct _FPDF_SYSFONTINFO* pThis) { auto* pDefault = static_cast<FPDF_SYSFONTINFO_DEFAULT*>(pThis); - // TODO(thestig): Should this be set to nullptr too? - delete pDefault->m_pFontInfo; + delete pDefault->m_pFontInfo.Release(); } static void DefaultEnumFonts(struct _FPDF_SYSFONTINFO* pThis, void* pMapper) { @@ -213,7 +212,7 @@ DLLEXPORT FPDF_SYSFONTINFO* STDCALL FPDF_GetDefaultSystemFontInfo() { return pFontInfoExt; } -DLLEXPORT void FPDF_FreeDefaultSystemFontInfo( - FPDF_SYSFONTINFO* pDefaultFontInfo) { +DLLEXPORT void STDCALL +FPDF_FreeDefaultSystemFontInfo(FPDF_SYSFONTINFO* pDefaultFontInfo) { FX_Free(static_cast<FPDF_SYSFONTINFO_DEFAULT*>(pDefaultFontInfo)); } diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdf_transformpage.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdf_transformpage.cpp index 9cf5a0b729e..b419ad1fb29 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdf_transformpage.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdf_transformpage.cpp @@ -7,6 +7,7 @@ #include "public/fpdf_transformpage.h" #include <memory> +#include <sstream> #include <vector> #include "core/fpdfapi/page/cpdf_clippath.h" @@ -104,7 +105,7 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFPage_TransFormWithClip(FPDF_PAGE page, if (!pPage) return false; - CFX_ByteTextBuf textBuf; + std::ostringstream textBuf; textBuf << "q "; CFX_FloatRect rect(clipRect->left, clipRect->bottom, clipRect->right, clipRect->top); @@ -134,7 +135,7 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFPage_TransFormWithClip(FPDF_PAGE page, CPDF_Stream* pStream = pDoc->NewIndirect<CPDF_Stream>( nullptr, 0, pdfium::MakeUnique<CPDF_Dictionary>(pDoc->GetByteStringPool())); - pStream->SetData(textBuf.GetBuffer(), textBuf.GetSize()); + pStream->SetData(&textBuf); CPDF_Stream* pEndStream = pDoc->NewIndirect<CPDF_Stream>( nullptr, 0, @@ -233,7 +234,7 @@ DLLEXPORT void STDCALL FPDF_DestroyClipPath(FPDF_CLIPPATH clipPath) { std::unique_ptr<CPDF_ClipPath>(static_cast<CPDF_ClipPath*>(clipPath)); } -void OutputPath(CFX_ByteTextBuf& buf, CPDF_Path path) { +void OutputPath(std::ostringstream& buf, CPDF_Path path) { const CFX_PathData* pPathData = path.GetObject(); if (!pPathData) return; @@ -284,7 +285,7 @@ DLLEXPORT void STDCALL FPDFPage_InsertClipPath(FPDF_PAGE page, if (!pContentObj) return; - CFX_ByteTextBuf strClip; + std::ostringstream strClip; CPDF_ClipPath* pClipPath = (CPDF_ClipPath*)clipPath; uint32_t i; for (i = 0; i < pClipPath->GetPathCount(); i++) { @@ -308,7 +309,7 @@ DLLEXPORT void STDCALL FPDFPage_InsertClipPath(FPDF_PAGE page, CPDF_Stream* pStream = pDoc->NewIndirect<CPDF_Stream>( nullptr, 0, pdfium::MakeUnique<CPDF_Dictionary>(pDoc->GetByteStringPool())); - pStream->SetData(strClip.GetBuffer(), strClip.GetSize()); + pStream->SetData(&strClip); CPDF_Array* pArray = ToArray(pContentObj); if (pArray) { diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdfannot.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdfannot.cpp new file mode 100644 index 00000000000..fcbed5c2ce0 --- /dev/null +++ b/chromium/third_party/pdfium/fpdfsdk/fpdfannot.cpp @@ -0,0 +1,825 @@ +// Copyright 2017 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. + +#include "public/fpdf_annot.h" + +#include <memory> +#include <utility> + +#include "core/fpdfapi/edit/cpdf_pagecontentgenerator.h" +#include "core/fpdfapi/page/cpdf_form.h" +#include "core/fpdfapi/page/cpdf_page.h" +#include "core/fpdfapi/page/cpdf_pageobject.h" +#include "core/fpdfapi/parser/cpdf_array.h" +#include "core/fpdfapi/parser/cpdf_dictionary.h" +#include "core/fpdfapi/parser/cpdf_document.h" +#include "core/fpdfapi/parser/cpdf_name.h" +#include "core/fpdfapi/parser/cpdf_number.h" +#include "core/fpdfapi/parser/cpdf_string.h" +#include "core/fpdfdoc/cpdf_annot.h" +#include "core/fpdfdoc/cpdf_formfield.h" +#include "core/fpdfdoc/cpdf_interform.h" +#include "core/fpdfdoc/cpvt_color.h" +#include "core/fpdfdoc/cpvt_generateap.h" +#include "fpdfsdk/fsdk_define.h" + +namespace { + +// These checks ensure the consistency of annotation subtype values across core/ +// and public. +static_assert(static_cast<int>(CPDF_Annot::Subtype::UNKNOWN) == + FPDF_ANNOT_UNKNOWN, + "CPDF_Annot::UNKNOWN value mismatch"); +static_assert(static_cast<int>(CPDF_Annot::Subtype::TEXT) == FPDF_ANNOT_TEXT, + "CPDF_Annot::TEXT value mismatch"); +static_assert(static_cast<int>(CPDF_Annot::Subtype::LINK) == FPDF_ANNOT_LINK, + "CPDF_Annot::LINK value mismatch"); +static_assert(static_cast<int>(CPDF_Annot::Subtype::FREETEXT) == + FPDF_ANNOT_FREETEXT, + "CPDF_Annot::FREETEXT value mismatch"); +static_assert(static_cast<int>(CPDF_Annot::Subtype::LINE) == FPDF_ANNOT_LINE, + "CPDF_Annot::LINE value mismatch"); +static_assert(static_cast<int>(CPDF_Annot::Subtype::SQUARE) == + FPDF_ANNOT_SQUARE, + "CPDF_Annot::SQUARE value mismatch"); +static_assert(static_cast<int>(CPDF_Annot::Subtype::CIRCLE) == + FPDF_ANNOT_CIRCLE, + "CPDF_Annot::CIRCLE value mismatch"); +static_assert(static_cast<int>(CPDF_Annot::Subtype::POLYGON) == + FPDF_ANNOT_POLYGON, + "CPDF_Annot::POLYGON value mismatch"); +static_assert(static_cast<int>(CPDF_Annot::Subtype::POLYLINE) == + FPDF_ANNOT_POLYLINE, + "CPDF_Annot::POLYLINE value mismatch"); +static_assert(static_cast<int>(CPDF_Annot::Subtype::HIGHLIGHT) == + FPDF_ANNOT_HIGHLIGHT, + "CPDF_Annot::HIGHLIGHT value mismatch"); +static_assert(static_cast<int>(CPDF_Annot::Subtype::UNDERLINE) == + FPDF_ANNOT_UNDERLINE, + "CPDF_Annot::UNDERLINE value mismatch"); +static_assert(static_cast<int>(CPDF_Annot::Subtype::SQUIGGLY) == + FPDF_ANNOT_SQUIGGLY, + "CPDF_Annot::SQUIGGLY value mismatch"); +static_assert(static_cast<int>(CPDF_Annot::Subtype::STRIKEOUT) == + FPDF_ANNOT_STRIKEOUT, + "CPDF_Annot::STRIKEOUT value mismatch"); +static_assert(static_cast<int>(CPDF_Annot::Subtype::STAMP) == FPDF_ANNOT_STAMP, + "CPDF_Annot::STAMP value mismatch"); +static_assert(static_cast<int>(CPDF_Annot::Subtype::CARET) == FPDF_ANNOT_CARET, + "CPDF_Annot::CARET value mismatch"); +static_assert(static_cast<int>(CPDF_Annot::Subtype::INK) == FPDF_ANNOT_INK, + "CPDF_Annot::INK value mismatch"); +static_assert(static_cast<int>(CPDF_Annot::Subtype::POPUP) == FPDF_ANNOT_POPUP, + "CPDF_Annot::POPUP value mismatch"); +static_assert(static_cast<int>(CPDF_Annot::Subtype::FILEATTACHMENT) == + FPDF_ANNOT_FILEATTACHMENT, + "CPDF_Annot::FILEATTACHMENT value mismatch"); +static_assert(static_cast<int>(CPDF_Annot::Subtype::SOUND) == FPDF_ANNOT_SOUND, + "CPDF_Annot::SOUND value mismatch"); +static_assert(static_cast<int>(CPDF_Annot::Subtype::MOVIE) == FPDF_ANNOT_MOVIE, + "CPDF_Annot::MOVIE value mismatch"); +static_assert(static_cast<int>(CPDF_Annot::Subtype::WIDGET) == + FPDF_ANNOT_WIDGET, + "CPDF_Annot::WIDGET value mismatch"); +static_assert(static_cast<int>(CPDF_Annot::Subtype::SCREEN) == + FPDF_ANNOT_SCREEN, + "CPDF_Annot::SCREEN value mismatch"); +static_assert(static_cast<int>(CPDF_Annot::Subtype::PRINTERMARK) == + FPDF_ANNOT_PRINTERMARK, + "CPDF_Annot::PRINTERMARK value mismatch"); +static_assert(static_cast<int>(CPDF_Annot::Subtype::TRAPNET) == + FPDF_ANNOT_TRAPNET, + "CPDF_Annot::TRAPNET value mismatch"); +static_assert(static_cast<int>(CPDF_Annot::Subtype::WATERMARK) == + FPDF_ANNOT_WATERMARK, + "CPDF_Annot::WATERMARK value mismatch"); +static_assert(static_cast<int>(CPDF_Annot::Subtype::THREED) == + FPDF_ANNOT_THREED, + "CPDF_Annot::THREED value mismatch"); +static_assert(static_cast<int>(CPDF_Annot::Subtype::RICHMEDIA) == + FPDF_ANNOT_RICHMEDIA, + "CPDF_Annot::RICHMEDIA value mismatch"); +static_assert(static_cast<int>(CPDF_Annot::Subtype::XFAWIDGET) == + FPDF_ANNOT_XFAWIDGET, + "CPDF_Annot::XFAWIDGET value mismatch"); + +// These checks ensure the consistency of dictionary value types across core/ +// and public/. +static_assert(static_cast<int>(CPDF_Object::Type::BOOLEAN) == + FPDF_OBJECT_BOOLEAN, + "CPDF_Object::BOOLEAN value mismatch"); +static_assert(static_cast<int>(CPDF_Object::Type::NUMBER) == FPDF_OBJECT_NUMBER, + "CPDF_Object::NUMBER value mismatch"); +static_assert(static_cast<int>(CPDF_Object::Type::STRING) == FPDF_OBJECT_STRING, + "CPDF_Object::STRING value mismatch"); +static_assert(static_cast<int>(CPDF_Object::Type::NAME) == FPDF_OBJECT_NAME, + "CPDF_Object::NAME value mismatch"); +static_assert(static_cast<int>(CPDF_Object::Type::ARRAY) == FPDF_OBJECT_ARRAY, + "CPDF_Object::ARRAY value mismatch"); +static_assert(static_cast<int>(CPDF_Object::Type::DICTIONARY) == + FPDF_OBJECT_DICTIONARY, + "CPDF_Object::DICTIONARY value mismatch"); +static_assert(static_cast<int>(CPDF_Object::Type::STREAM) == FPDF_OBJECT_STREAM, + "CPDF_Object::STREAM value mismatch"); +static_assert(static_cast<int>(CPDF_Object::Type::NULLOBJ) == + FPDF_OBJECT_NULLOBJ, + "CPDF_Object::NULLOBJ value mismatch"); +static_assert(static_cast<int>(CPDF_Object::Type::REFERENCE) == + FPDF_OBJECT_REFERENCE, + "CPDF_Object::REFERENCE value mismatch"); + +class CPDF_AnnotContext { + public: + CPDF_AnnotContext(CPDF_Dictionary* pAnnotDict, + CPDF_Page* pPage, + CPDF_Stream* pStream) + : m_pAnnotDict(pAnnotDict), m_pPage(pPage) { + SetForm(pStream); + } + ~CPDF_AnnotContext() {} + + bool HasForm() const { return !!m_pAnnotForm; } + + void SetForm(CPDF_Stream* pStream) { + if (!pStream) + return; + + // Reset the annotation matrix to be the identity matrix, since the + // appearance stream already takes matrix into account. + pStream->GetDict()->SetMatrixFor("Matrix", CFX_Matrix()); + + m_pAnnotForm = pdfium::MakeUnique<CPDF_Form>( + m_pPage->m_pDocument.Get(), m_pPage->m_pResources.Get(), pStream); + m_pAnnotForm->ParseContent(nullptr, nullptr, nullptr); + } + + CPDF_Form* GetForm() const { return m_pAnnotForm.get(); } + CPDF_Dictionary* GetAnnotDict() const { return m_pAnnotDict.Get(); } + CPDF_Page* GetPage() const { return m_pPage.Get(); } + + private: + std::unique_ptr<CPDF_Form> m_pAnnotForm; + CFX_UnownedPtr<CPDF_Dictionary> m_pAnnotDict; + CFX_UnownedPtr<CPDF_Page> m_pPage; +}; + +CPDF_AnnotContext* CPDFAnnotContextFromFPDFAnnotation(FPDF_ANNOTATION annot) { + return static_cast<CPDF_AnnotContext*>(annot); +} + +bool HasAPStream(const CPDF_Dictionary* pAnnotDict) { + return !!FPDFDOC_GetAnnotAP(pAnnotDict, CPDF_Annot::AppearanceMode::Normal); +} + +void UpdateContentStream(CPDF_Form* pForm, CPDF_Stream* pStream) { + ASSERT(pForm); + ASSERT(pStream); + + CPDF_PageContentGenerator generator(pForm); + std::ostringstream buf; + generator.ProcessPageObjects(&buf); + pStream->SetData(&buf); +} + +} // namespace + +DLLEXPORT FPDF_BOOL STDCALL +FPDFAnnot_IsSupportedSubtype(FPDF_ANNOTATION_SUBTYPE subtype) { + // The supported subtypes must also be communicated in the user doc. + return subtype == FPDF_ANNOT_CIRCLE || subtype == FPDF_ANNOT_HIGHLIGHT || + subtype == FPDF_ANNOT_INK || subtype == FPDF_ANNOT_POPUP || + subtype == FPDF_ANNOT_SQUARE || subtype == FPDF_ANNOT_SQUIGGLY || + subtype == FPDF_ANNOT_STAMP || subtype == FPDF_ANNOT_STRIKEOUT || + subtype == FPDF_ANNOT_TEXT || subtype == FPDF_ANNOT_UNDERLINE; +} + +DLLEXPORT FPDF_ANNOTATION STDCALL +FPDFPage_CreateAnnot(FPDF_PAGE page, FPDF_ANNOTATION_SUBTYPE subtype) { + CPDF_Page* pPage = CPDFPageFromFPDFPage(page); + if (!pPage || !FPDFAnnot_IsSupportedSubtype(subtype)) + return nullptr; + + auto pDict = pdfium::MakeUnique<CPDF_Dictionary>( + pPage->m_pDocument->GetByteStringPool()); + pDict->SetNewFor<CPDF_Name>("Type", "Annot"); + pDict->SetNewFor<CPDF_Name>("Subtype", + CPDF_Annot::AnnotSubtypeToString( + static_cast<CPDF_Annot::Subtype>(subtype))); + auto pNewAnnot = + pdfium::MakeUnique<CPDF_AnnotContext>(pDict.get(), pPage, nullptr); + + CPDF_Array* pAnnotList = pPage->m_pFormDict->GetArrayFor("Annots"); + if (!pAnnotList) + pAnnotList = pPage->m_pFormDict->SetNewFor<CPDF_Array>("Annots"); + + pAnnotList->Add(std::move(pDict)); + return pNewAnnot.release(); +} + +DLLEXPORT int STDCALL FPDFPage_GetAnnotCount(FPDF_PAGE page) { + CPDF_Page* pPage = CPDFPageFromFPDFPage(page); + if (!pPage || !pPage->m_pFormDict) + return 0; + + CPDF_Array* pAnnots = pPage->m_pFormDict->GetArrayFor("Annots"); + return pAnnots ? pAnnots->GetCount() : 0; +} + +DLLEXPORT FPDF_ANNOTATION STDCALL FPDFPage_GetAnnot(FPDF_PAGE page, int index) { + CPDF_Page* pPage = CPDFPageFromFPDFPage(page); + if (!pPage || !pPage->m_pFormDict || index < 0) + return nullptr; + + CPDF_Array* pAnnots = pPage->m_pFormDict->GetArrayFor("Annots"); + if (!pAnnots || static_cast<size_t>(index) >= pAnnots->GetCount()) + return nullptr; + + CPDF_Dictionary* pDict = ToDictionary(pAnnots->GetDirectObjectAt(index)); + auto pNewAnnot = pdfium::MakeUnique<CPDF_AnnotContext>(pDict, pPage, nullptr); + return pNewAnnot.release(); +} + +DLLEXPORT void STDCALL FPDFPage_CloseAnnot(FPDF_ANNOTATION annot) { + delete CPDFAnnotContextFromFPDFAnnotation(annot); +} + +DLLEXPORT FPDF_BOOL STDCALL FPDFPage_RemoveAnnot(FPDF_PAGE page, int index) { + CPDF_Page* pPage = CPDFPageFromFPDFPage(page); + if (!pPage || !pPage->m_pFormDict || index < 0) + return false; + + CPDF_Array* pAnnots = pPage->m_pFormDict->GetArrayFor("Annots"); + if (!pAnnots || static_cast<size_t>(index) >= pAnnots->GetCount()) + return false; + + pAnnots->RemoveAt(index); + return true; +} + +DLLEXPORT FPDF_ANNOTATION_SUBTYPE STDCALL +FPDFAnnot_GetSubtype(FPDF_ANNOTATION annot) { + if (!annot) + return FPDF_ANNOT_UNKNOWN; + + CPDF_Dictionary* pAnnotDict = + CPDFAnnotContextFromFPDFAnnotation(annot)->GetAnnotDict(); + if (!pAnnotDict) + return FPDF_ANNOT_UNKNOWN; + + return static_cast<FPDF_ANNOTATION_SUBTYPE>( + CPDF_Annot::StringToAnnotSubtype(pAnnotDict->GetStringFor("Subtype"))); +} + +DLLEXPORT FPDF_BOOL STDCALL +FPDFAnnot_IsObjectSupportedSubtype(FPDF_ANNOTATION_SUBTYPE subtype) { + // The supported subtypes must also be communicated in the user doc. + return subtype == FPDF_ANNOT_INK || subtype == FPDF_ANNOT_STAMP; +} + +DLLEXPORT FPDF_BOOL STDCALL FPDFAnnot_UpdateObject(FPDF_ANNOTATION annot, + FPDF_PAGEOBJECT obj) { + CPDF_AnnotContext* pAnnot = CPDFAnnotContextFromFPDFAnnotation(annot); + CPDF_PageObject* pObj = CPDFPageObjectFromFPDFPageObject(obj); + if (!pAnnot || !pAnnot->GetAnnotDict() || !pAnnot->HasForm() || !pObj) + return false; + + // Check that the annotation type is supported by this method. + if (!FPDFAnnot_IsObjectSupportedSubtype(FPDFAnnot_GetSubtype(annot))) + return false; + + // Check that the annotation already has an appearance stream, since an + // existing object is to be updated. + CPDF_Stream* pStream = FPDFDOC_GetAnnotAP(pAnnot->GetAnnotDict(), + CPDF_Annot::AppearanceMode::Normal); + if (!pStream) + return false; + + // Check that the object is already in this annotation's object list. + CPDF_Form* pForm = pAnnot->GetForm(); + CPDF_PageObjectList* pObjList = pForm->GetPageObjectList(); + auto it = + std::find_if(pObjList->begin(), pObjList->end(), + [pObj](const std::unique_ptr<CPDF_PageObject>& candidate) { + return candidate.get() == pObj; + }); + if (it == pObjList->end()) + return false; + + // Update the content stream data in the annotation's AP stream. + UpdateContentStream(pForm, pStream); + return true; +} + +DLLEXPORT FPDF_BOOL STDCALL FPDFAnnot_AppendObject(FPDF_ANNOTATION annot, + FPDF_PAGEOBJECT obj) { + CPDF_AnnotContext* pAnnot = CPDFAnnotContextFromFPDFAnnotation(annot); + CPDF_PageObject* pObj = CPDFPageObjectFromFPDFPageObject(obj); + if (!pAnnot || !pObj) + return false; + + CPDF_Dictionary* pAnnotDict = pAnnot->GetAnnotDict(); + CPDF_Page* pPage = pAnnot->GetPage(); + if (!pAnnotDict || !pPage) + return false; + + // Check that the annotation type is supported by this method. + if (!FPDFAnnot_IsObjectSupportedSubtype(FPDFAnnot_GetSubtype(annot))) + return false; + + // If the annotation does not have an AP stream yet, generate and set it. + CPDF_Stream* pStream = FPDFDOC_GetAnnotAP(pAnnot->GetAnnotDict(), + CPDF_Annot::AppearanceMode::Normal); + if (!pStream) { + auto pExtGStateDict = + CPVT_GenerateAP::GenerateExtGStateDict(*pAnnotDict, "GS", "Normal"); + auto pResourceDict = CPVT_GenerateAP::GenerateResourceDict( + pPage->m_pDocument.Get(), std::move(pExtGStateDict), nullptr); + std::ostringstream sStream; + CPVT_GenerateAP::GenerateAndSetAPDict(pPage->m_pDocument.Get(), pAnnotDict, + &sStream, std::move(pResourceDict), + false); + pStream = + FPDFDOC_GetAnnotAP(pAnnotDict, CPDF_Annot::AppearanceMode::Normal); + if (!pStream) + return false; + } + + // Get the annotation's corresponding form object for parsing its AP stream. + if (!pAnnot->HasForm()) + pAnnot->SetForm(pStream); + + // Check that the object did not come from the same annotation. If this check + // succeeds, then it is assumed that the object came from + // FPDFPageObj_CreateNew{Path|Rect}() or FPDFPageObj_New{Text|Image}Obj(). + // Note that an object that came from a different annotation must not be + // passed here, since an object cannot belong to more than one annotation. + CPDF_Form* pForm = pAnnot->GetForm(); + CPDF_PageObjectList* pObjList = pForm->GetPageObjectList(); + auto it = + std::find_if(pObjList->begin(), pObjList->end(), + [pObj](const std::unique_ptr<CPDF_PageObject>& candidate) { + return candidate.get() == pObj; + }); + if (it != pObjList->end()) + return false; + + // Append the object to the object list. + std::unique_ptr<CPDF_PageObject> pPageObjHolder(pObj); + pObjList->push_back(std::move(pPageObjHolder)); + + // Set the content stream data in the annotation's AP stream. + UpdateContentStream(pForm, pStream); + return true; +} + +DLLEXPORT int STDCALL FPDFAnnot_GetObjectCount(FPDF_ANNOTATION annot) { + CPDF_AnnotContext* pAnnot = CPDFAnnotContextFromFPDFAnnotation(annot); + if (!pAnnot || !pAnnot->GetAnnotDict()) + return 0; + + if (!pAnnot->HasForm()) { + CPDF_Stream* pStream = FPDFDOC_GetAnnotAP( + pAnnot->GetAnnotDict(), CPDF_Annot::AppearanceMode::Normal); + if (!pStream) + return 0; + + pAnnot->SetForm(pStream); + } + return pdfium::CollectionSize<int>(*pAnnot->GetForm()->GetPageObjectList()); +} + +DLLEXPORT FPDF_PAGEOBJECT STDCALL FPDFAnnot_GetObject(FPDF_ANNOTATION annot, + int index) { + CPDF_AnnotContext* pAnnot = CPDFAnnotContextFromFPDFAnnotation(annot); + if (!pAnnot || !pAnnot->GetAnnotDict() || index < 0) + return nullptr; + + if (!pAnnot->HasForm()) { + CPDF_Stream* pStream = FPDFDOC_GetAnnotAP( + pAnnot->GetAnnotDict(), CPDF_Annot::AppearanceMode::Normal); + if (!pStream) + return nullptr; + + pAnnot->SetForm(pStream); + } + + return pAnnot->GetForm()->GetPageObjectList()->GetPageObjectByIndex(index); +} + +DLLEXPORT FPDF_BOOL STDCALL FPDFAnnot_RemoveObject(FPDF_ANNOTATION annot, + int index) { + CPDF_AnnotContext* pAnnot = CPDFAnnotContextFromFPDFAnnotation(annot); + if (!pAnnot || !pAnnot->GetAnnotDict() || !pAnnot->HasForm() || index < 0) + return false; + + // Check that the annotation type is supported by this method. + if (!FPDFAnnot_IsObjectSupportedSubtype(FPDFAnnot_GetSubtype(annot))) + return false; + + // Check that the annotation already has an appearance stream, since an + // existing object is to be deleted. + CPDF_Stream* pStream = FPDFDOC_GetAnnotAP(pAnnot->GetAnnotDict(), + CPDF_Annot::AppearanceMode::Normal); + if (!pStream) + return false; + + CPDF_PageObjectList* pObjList = pAnnot->GetForm()->GetPageObjectList(); + if (static_cast<size_t>(index) >= pObjList->size()) + return false; + + pObjList->erase(pObjList->begin() + index); + UpdateContentStream(pAnnot->GetForm(), pStream); + return true; +} + +DLLEXPORT FPDF_BOOL STDCALL FPDFAnnot_SetColor(FPDF_ANNOTATION annot, + FPDFANNOT_COLORTYPE type, + unsigned int R, + unsigned int G, + unsigned int B, + unsigned int A) { + if (!annot || R > 255 || G > 255 || B > 255 || A > 255) + return false; + + CPDF_Dictionary* pAnnotDict = + CPDFAnnotContextFromFPDFAnnotation(annot)->GetAnnotDict(); + if (!pAnnotDict) + return false; + + // For annotations with their appearance streams already defined, the path + // stream's own color definitions take priority over the annotation color + // definitions set by this method, hence this method will simply fail. + if (HasAPStream(pAnnotDict)) + return false; + + // Set the opacity of the annotation. + pAnnotDict->SetNewFor<CPDF_Number>("CA", A / 255.f); + + // Set the color of the annotation. + CFX_ByteString key = type == FPDFANNOT_COLORTYPE_InteriorColor ? "IC" : "C"; + CPDF_Array* pColor = pAnnotDict->GetArrayFor(key); + if (pColor) + pColor->Clear(); + else + pColor = pAnnotDict->SetNewFor<CPDF_Array>(key); + + pColor->AddNew<CPDF_Number>(R / 255.f); + pColor->AddNew<CPDF_Number>(G / 255.f); + pColor->AddNew<CPDF_Number>(B / 255.f); + + return true; +} + +DLLEXPORT FPDF_BOOL STDCALL FPDFAnnot_GetColor(FPDF_ANNOTATION annot, + FPDFANNOT_COLORTYPE type, + unsigned int* R, + unsigned int* G, + unsigned int* B, + unsigned int* A) { + if (!annot || !R || !G || !B || !A) + return false; + + CPDF_Dictionary* pAnnotDict = + CPDFAnnotContextFromFPDFAnnotation(annot)->GetAnnotDict(); + if (!pAnnotDict) + return false; + + // For annotations with their appearance streams already defined, the path + // stream's own color definitions take priority over the annotation color + // definitions retrieved by this method, hence this method will simply fail. + if (HasAPStream(pAnnotDict)) + return false; + + CPDF_Array* pColor = pAnnotDict->GetArrayFor( + type == FPDFANNOT_COLORTYPE_InteriorColor ? "IC" : "C"); + *A = + (pAnnotDict->KeyExist("CA") ? pAnnotDict->GetNumberFor("CA") : 1) * 255.f; + if (!pColor) { + // Use default color. The default colors must be consistent with the ones + // used to generate AP. See calls to GetColorStringWithDefault() in + // CPVT_GenerateAP::Generate*AP(). + if (pAnnotDict->GetStringFor("Subtype") == "Highlight") { + *R = 255; + *G = 255; + *B = 0; + } else { + *R = 0; + *G = 0; + *B = 0; + } + return true; + } + CPVT_Color color = CPVT_Color::ParseColor(*pColor); + switch (color.nColorType) { + case CPVT_Color::kRGB: + *R = color.fColor1 * 255.f; + *G = color.fColor2 * 255.f; + *B = color.fColor3 * 255.f; + break; + case CPVT_Color::kGray: + *R = 255.f * color.fColor1; + *G = 255.f * color.fColor1; + *B = 255.f * color.fColor1; + break; + case CPVT_Color::kCMYK: + *R = 255.f * (1 - color.fColor1) * (1 - color.fColor4); + *G = 255.f * (1 - color.fColor2) * (1 - color.fColor4); + *B = 255.f * (1 - color.fColor3) * (1 - color.fColor4); + break; + case CPVT_Color::kTransparent: + *R = 0; + *G = 0; + *B = 0; + break; + } + return true; +} + +DLLEXPORT FPDF_BOOL STDCALL +FPDFAnnot_HasAttachmentPoints(FPDF_ANNOTATION annot) { + if (!annot) + return false; + + FPDF_ANNOTATION_SUBTYPE subtype = FPDFAnnot_GetSubtype(annot); + return subtype == FPDF_ANNOT_LINK || subtype == FPDF_ANNOT_HIGHLIGHT || + subtype == FPDF_ANNOT_UNDERLINE || subtype == FPDF_ANNOT_SQUIGGLY || + subtype == FPDF_ANNOT_STRIKEOUT; +} + +DLLEXPORT FPDF_BOOL STDCALL +FPDFAnnot_SetAttachmentPoints(FPDF_ANNOTATION annot, + const FS_QUADPOINTSF* quadPoints) { + if (!annot || !quadPoints || !FPDFAnnot_HasAttachmentPoints(annot)) + return false; + + CPDF_Dictionary* pAnnotDict = + CPDFAnnotContextFromFPDFAnnotation(annot)->GetAnnotDict(); + if (!pAnnotDict) + return false; + + // Update the "QuadPoints" entry in the annotation dictionary. + CPDF_Array* pQuadPoints = pAnnotDict->GetArrayFor("QuadPoints"); + if (pQuadPoints) + pQuadPoints->Clear(); + else + pQuadPoints = pAnnotDict->SetNewFor<CPDF_Array>("QuadPoints"); + + pQuadPoints->AddNew<CPDF_Number>(quadPoints->x1); + pQuadPoints->AddNew<CPDF_Number>(quadPoints->y1); + pQuadPoints->AddNew<CPDF_Number>(quadPoints->x2); + pQuadPoints->AddNew<CPDF_Number>(quadPoints->y2); + pQuadPoints->AddNew<CPDF_Number>(quadPoints->x3); + pQuadPoints->AddNew<CPDF_Number>(quadPoints->y3); + pQuadPoints->AddNew<CPDF_Number>(quadPoints->x4); + pQuadPoints->AddNew<CPDF_Number>(quadPoints->y4); + + // If the annotation's appearance stream is defined, and the new quadpoints + // defines a bigger bounding box than the appearance stream currently + // specifies, then update the "BBox" entry in the AP dictionary too, since it + // comes from annotation dictionary's "QuadPoints" entry. + CPDF_Stream* pStream = + FPDFDOC_GetAnnotAP(pAnnotDict, CPDF_Annot::AppearanceMode::Normal); + if (pStream) { + CFX_FloatRect newRect = CPDF_Annot::RectFromQuadPoints(pAnnotDict); + if (newRect.Contains(pStream->GetDict()->GetRectFor("BBox"))) + pStream->GetDict()->SetRectFor("BBox", newRect); + } + return true; +} + +DLLEXPORT FS_QUADPOINTSF STDCALL +FPDFAnnot_GetAttachmentPoints(FPDF_ANNOTATION annot) { + if (!annot || !FPDFAnnot_HasAttachmentPoints(annot)) + return FS_QUADPOINTSF(); + + CPDF_Dictionary* pAnnotDict = + CPDFAnnotContextFromFPDFAnnotation(annot)->GetAnnotDict(); + if (!pAnnotDict) + return FS_QUADPOINTSF(); + + // If the annotation's appearance stream is defined, then retrieve the + // quadpoints defined by the "BBox" entry in the AP dictionary, since its + // "BBox" entry comes from annotation dictionary's "QuadPoints" entry, but + // takes priority over "QuadPoints" when rendering. Otherwise, retrieve + // the "Quadpoints" entry from the annotation dictionary. + CPDF_Array* pArray; + FS_QUADPOINTSF quadPoints; + CPDF_Stream* pStream = + FPDFDOC_GetAnnotAP(pAnnotDict, CPDF_Annot::AppearanceMode::Normal); + if (pStream) { + pArray = pStream->GetDict()->GetArrayFor("BBox"); + if (!pArray) + return FS_QUADPOINTSF(); + + // Convert the BBox array into quadpoint coordinates. BBox array follows the + // order of a rectangle array: (left, bottom, right, up); and quadpoints + // follows the following order: (top-left vertex, top-right vertex, bottom- + // left vertex, bottom-right vertex). + quadPoints.x1 = pArray->GetNumberAt(0); + quadPoints.y1 = pArray->GetNumberAt(3); + quadPoints.x2 = pArray->GetNumberAt(2); + quadPoints.y2 = pArray->GetNumberAt(3); + quadPoints.x3 = pArray->GetNumberAt(0); + quadPoints.y3 = pArray->GetNumberAt(1); + quadPoints.x4 = pArray->GetNumberAt(2); + quadPoints.y4 = pArray->GetNumberAt(1); + } else { + pArray = pAnnotDict->GetArrayFor("QuadPoints"); + if (!pArray) + return FS_QUADPOINTSF(); + + quadPoints.x1 = pArray->GetNumberAt(0); + quadPoints.y1 = pArray->GetNumberAt(1); + quadPoints.x2 = pArray->GetNumberAt(2); + quadPoints.y2 = pArray->GetNumberAt(3); + quadPoints.x3 = pArray->GetNumberAt(4); + quadPoints.y3 = pArray->GetNumberAt(5); + quadPoints.x4 = pArray->GetNumberAt(6); + quadPoints.y4 = pArray->GetNumberAt(7); + } + return quadPoints; +} + +DLLEXPORT FPDF_BOOL STDCALL FPDFAnnot_SetRect(FPDF_ANNOTATION annot, + const FS_RECTF* rect) { + if (!annot || !rect) + return false; + + CPDF_Dictionary* pAnnotDict = + CPDFAnnotContextFromFPDFAnnotation(annot)->GetAnnotDict(); + if (!pAnnotDict) + return false; + + CFX_FloatRect newRect(rect->left, rect->bottom, rect->right, rect->top); + + // Update the "Rect" entry in the annotation dictionary. + pAnnotDict->SetRectFor("Rect", newRect); + + // If the annotation's appearance stream is defined, the annotation is of a + // type that does not have quadpoints, and the new rectangle is bigger than + // the current bounding box, then update the "BBox" entry in the AP + // dictionary too, since its "BBox" entry comes from annotation dictionary's + // "Rect" entry. + if (FPDFAnnot_HasAttachmentPoints(annot)) + return true; + + CPDF_Stream* pStream = + FPDFDOC_GetAnnotAP(pAnnotDict, CPDF_Annot::AppearanceMode::Normal); + if (pStream && newRect.Contains(pStream->GetDict()->GetRectFor("BBox"))) + pStream->GetDict()->SetRectFor("BBox", newRect); + return true; +} + +DLLEXPORT FS_RECTF STDCALL FPDFAnnot_GetRect(FPDF_ANNOTATION annot) { + if (!annot) + return FS_RECTF(); + + CPDF_Dictionary* pAnnotDict = + CPDFAnnotContextFromFPDFAnnotation(annot)->GetAnnotDict(); + if (!pAnnotDict) + return FS_RECTF(); + + // If the annotation's appearance stream is defined and the annotation is of + // a type that does not have quadpoints, then retrieve the rectangle defined + // by the "BBox" entry in the AP dictionary, since its "BBox" entry comes + // from annotation dictionary's "Rect" entry, but takes priority over "Rect" + // when rendering. Otherwise, retrieve the "Rect" entry from the annotation + // dictionary. + CFX_FloatRect rt; + CPDF_Stream* pStream = + FPDFDOC_GetAnnotAP(pAnnotDict, CPDF_Annot::AppearanceMode::Normal); + if (!pStream || FPDFAnnot_HasAttachmentPoints(annot)) + rt = pAnnotDict->GetRectFor("Rect"); + else + rt = pStream->GetDict()->GetRectFor("BBox"); + + FS_RECTF rect; + rect.left = rt.left; + rect.bottom = rt.bottom; + rect.right = rt.right; + rect.top = rt.top; + return rect; +} + +DLLEXPORT FPDF_BOOL STDCALL FPDFAnnot_HasKey(FPDF_ANNOTATION annot, + FPDF_WIDESTRING key) { + if (!annot) + return false; + + CPDF_Dictionary* pAnnotDict = + CPDFAnnotContextFromFPDFAnnotation(annot)->GetAnnotDict(); + if (!pAnnotDict) + return false; + + return pAnnotDict->KeyExist(CFXByteStringFromFPDFWideString(key)); +} + +DLLEXPORT FPDF_OBJECT_TYPE STDCALL FPDFAnnot_GetValueType(FPDF_ANNOTATION annot, + FPDF_WIDESTRING key) { + if (!FPDFAnnot_HasKey(annot, key)) + return FPDF_OBJECT_UNKNOWN; + + CPDF_Object* pObj = + CPDFAnnotContextFromFPDFAnnotation(annot)->GetAnnotDict()->GetObjectFor( + CFXByteStringFromFPDFWideString(key)); + if (!pObj) + return FPDF_OBJECT_UNKNOWN; + + return pObj->GetType(); +} + +DLLEXPORT FPDF_BOOL STDCALL FPDFAnnot_SetStringValue(FPDF_ANNOTATION annot, + FPDF_WIDESTRING key, + FPDF_WIDESTRING value) { + if (!annot) + return false; + + CPDF_Dictionary* pAnnotDict = + CPDFAnnotContextFromFPDFAnnotation(annot)->GetAnnotDict(); + if (!pAnnotDict) + return false; + + pAnnotDict->SetNewFor<CPDF_String>(CFXByteStringFromFPDFWideString(key), + CFXByteStringFromFPDFWideString(value), + false); + return true; +} + +DLLEXPORT unsigned long STDCALL FPDFAnnot_GetStringValue(FPDF_ANNOTATION annot, + FPDF_WIDESTRING key, + void* buffer, + unsigned long buflen) { + if (!annot) + return 0; + + CPDF_Dictionary* pAnnotDict = + CPDFAnnotContextFromFPDFAnnotation(annot)->GetAnnotDict(); + if (!pAnnotDict) + return 0; + + return Utf16EncodeMaybeCopyAndReturnLength( + pAnnotDict->GetUnicodeTextFor(CFXByteStringFromFPDFWideString(key)), + buffer, buflen); +} + +DLLEXPORT int STDCALL FPDFAnnot_GetFlags(FPDF_ANNOTATION annot) { + if (!annot) + return FPDF_ANNOT_FLAG_NONE; + + CPDF_Dictionary* pAnnotDict = + CPDFAnnotContextFromFPDFAnnotation(annot)->GetAnnotDict(); + if (!pAnnotDict) + return FPDF_ANNOT_FLAG_NONE; + + return pAnnotDict->GetIntegerFor("F"); +} + +DLLEXPORT FPDF_BOOL STDCALL FPDFAnnot_SetFlags(FPDF_ANNOTATION annot, + int flags) { + if (!annot) + return false; + + CPDF_Dictionary* pAnnotDict = + CPDFAnnotContextFromFPDFAnnotation(annot)->GetAnnotDict(); + if (!pAnnotDict) + return false; + + pAnnotDict->SetNewFor<CPDF_Number>("F", flags); + return true; +} + +DLLEXPORT int STDCALL FPDFAnnot_GetFormFieldFlags(FPDF_PAGE page, + FPDF_ANNOTATION annot) { + CPDF_Page* pPage = CPDFPageFromFPDFPage(page); + if (!pPage || !annot) + return FPDF_FORMFLAG_NONE; + + CPDF_Dictionary* pAnnotDict = + CPDFAnnotContextFromFPDFAnnotation(annot)->GetAnnotDict(); + if (!pAnnotDict) + return FPDF_FORMFLAG_NONE; + + CPDF_InterForm interform(pPage->m_pDocument.Get()); + CPDF_FormField* pFormField = interform.GetFieldByDict(pAnnotDict); + return pFormField ? pFormField->GetFieldFlags() : FPDF_FORMFLAG_NONE; +} + +DLLEXPORT FPDF_ANNOTATION STDCALL +FPDFAnnot_GetFormFieldAtPoint(FPDF_FORMHANDLE hHandle, + FPDF_PAGE page, + double page_x, + double page_y) { + CPDF_Page* pPage = CPDFPageFromFPDFPage(page); + if (!hHandle || !pPage) + return nullptr; + + CPDF_InterForm interform(pPage->m_pDocument.Get()); + int annot_index = -1; + CPDF_FormControl* pFormCtrl = interform.GetControlAtPoint( + pPage, CFX_PointF(static_cast<float>(page_x), static_cast<float>(page_y)), + &annot_index); + if (!pFormCtrl || annot_index == -1) + return nullptr; + return FPDFPage_GetAnnot(page, annot_index); +} diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdfannot_embeddertest.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdfannot_embeddertest.cpp new file mode 100644 index 00000000000..58a00067a79 --- /dev/null +++ b/chromium/third_party/pdfium/fpdfsdk/fpdfannot_embeddertest.cpp @@ -0,0 +1,1043 @@ +// Copyright 2017 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. + +#include <memory> +#include <string> +#include <vector> + +#include "core/fxcrt/fx_system.h" +#include "public/fpdf_annot.h" +#include "public/fpdf_edit.h" +#include "public/fpdfview.h" +#include "testing/embedder_test.h" +#include "testing/gtest/include/gtest/gtest.h" + +class FPDFAnnotEmbeddertest : public EmbedderTest {}; + +TEST_F(FPDFAnnotEmbeddertest, RenderAnnotWithOnlyRolloverAP) { + // Open a file with one annotation and load its first page. + ASSERT_TRUE(OpenDocument("annotation_highlight_rollover_ap.pdf")); + FPDF_PAGE page = FPDF_LoadPage(document(), 0); + ASSERT_TRUE(page); + + // This annotation has a malformed appearance stream, which does not have its + // normal appearance defined, only its rollover appearance. In this case, its + // normal appearance should be generated, allowing the highlight annotation to + // still display. + FPDF_BITMAP bitmap = RenderPageWithFlags(page, form_handle(), FPDF_ANNOT); + CompareBitmap(bitmap, 612, 792, "dc98f06da047bd8aabfa99562d2cbd1e"); + FPDFBitmap_Destroy(bitmap); + + UnloadPage(page); +} + +TEST_F(FPDFAnnotEmbeddertest, ExtractHighlightLongContent) { + // Open a file with one annotation and load its first page. + ASSERT_TRUE(OpenDocument("annotation_highlight_long_content.pdf")); + FPDF_PAGE page = FPDF_LoadPage(document(), 0); + ASSERT_TRUE(page); + + // Check that there is a total of 1 annotation on its first page. + EXPECT_EQ(1, FPDFPage_GetAnnotCount(page)); + + // Check that the annotation is of type "highlight". + FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 0); + ASSERT_TRUE(annot); + EXPECT_EQ(FPDF_ANNOT_HIGHLIGHT, FPDFAnnot_GetSubtype(annot)); + + // Check that the annotation color is yellow. + unsigned int R; + unsigned int G; + unsigned int B; + unsigned int A; + EXPECT_TRUE( + FPDFAnnot_GetColor(annot, FPDFANNOT_COLORTYPE_Color, &R, &G, &B, &A)); + EXPECT_EQ(255u, R); + EXPECT_EQ(255u, G); + EXPECT_EQ(0u, B); + EXPECT_EQ(255u, A); + + // Check that the author is correct. + std::unique_ptr<unsigned short, pdfium::FreeDeleter> author_key = + GetFPDFWideString(L"T"); + EXPECT_EQ(FPDF_OBJECT_STRING, + FPDFAnnot_GetValueType(annot, author_key.get())); + unsigned long len = + FPDFAnnot_GetStringValue(annot, author_key.get(), nullptr, 0); + std::vector<char> buf(len); + EXPECT_EQ(28u, + FPDFAnnot_GetStringValue(annot, author_key.get(), buf.data(), len)); + EXPECT_STREQ(L"Jae Hyun Park", + GetPlatformWString(reinterpret_cast<unsigned short*>(buf.data())) + .c_str()); + + // Check that the content is correct. + std::unique_ptr<unsigned short, pdfium::FreeDeleter> contents_key = + GetFPDFWideString(L"Contents"); + EXPECT_EQ(FPDF_OBJECT_STRING, + FPDFAnnot_GetValueType(annot, contents_key.get())); + len = FPDFAnnot_GetStringValue(annot, contents_key.get(), nullptr, 0); + buf.clear(); + buf.resize(len); + EXPECT_EQ(2690u, FPDFAnnot_GetStringValue(annot, contents_key.get(), + buf.data(), len)); + const wchar_t contents[] = + L"This is a note for that highlight annotation. Very long highlight " + "annotation. Long long long Long long longLong long longLong long " + "longLong long longLong long longLong long longLong long longLong long " + "longLong long longLong long longLong long longLong long longLong long " + "longLong long longLong long longLong long longLong long longLong long " + "longLong long longLong long longLong long longLong long longLong long " + "longLong long longLong long longLong long longLong long longLong long " + "longLong long longLong long longLong long longLong long longLong long " + "longLong long longLong long longLong long longLong long longLong long " + "longLong long longLong long longLong long longLong long longLong long " + "longLong long longLong long longLong long longLong long longLong long " + "longLong long longLong long longLong long longLong long longLong long " + "longLong long longLong long longLong long longLong long longLong long " + "longLong long longLong long longLong long longLong long longLong long " + "longLong long longLong long longLong long longLong long longLong long " + "longLong long longLong long longLong long longLong long longLong long " + "longLong long longLong long longLong long longLong long longLong long " + "longLong long longLong long longLong long longLong long longLong long " + "longLong long longLong long longLong long longLong long longLong long " + "longLong long long. END"; + EXPECT_STREQ(contents, + GetPlatformWString(reinterpret_cast<unsigned short*>(buf.data())) + .c_str()); + + // Check that the quadpoints are correct. + FS_QUADPOINTSF quadpoints = FPDFAnnot_GetAttachmentPoints(annot); + EXPECT_EQ(115.802643f, quadpoints.x1); + EXPECT_EQ(718.913940f, quadpoints.y1); + EXPECT_EQ(157.211182f, quadpoints.x4); + EXPECT_EQ(706.264465f, quadpoints.y4); + + FPDFPage_CloseAnnot(annot); + UnloadPage(page); +} + +TEST_F(FPDFAnnotEmbeddertest, ExtractInkMultiple) { + // Open a file with three annotations and load its first page. + ASSERT_TRUE(OpenDocument("annotation_ink_multiple.pdf")); + FPDF_PAGE page = FPDF_LoadPage(document(), 0); + ASSERT_TRUE(page); + + // Check that there is a total of 3 annotation on its first page. + EXPECT_EQ(3, FPDFPage_GetAnnotCount(page)); + + // Check that the third annotation is of type "ink". + FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 2); + ASSERT_TRUE(annot); + EXPECT_EQ(FPDF_ANNOT_INK, FPDFAnnot_GetSubtype(annot)); + + // Check that the annotation color is blue with opacity. + unsigned int R; + unsigned int G; + unsigned int B; + unsigned int A; + EXPECT_TRUE( + FPDFAnnot_GetColor(annot, FPDFANNOT_COLORTYPE_Color, &R, &G, &B, &A)); + EXPECT_EQ(0u, R); + EXPECT_EQ(0u, G); + EXPECT_EQ(255u, B); + EXPECT_EQ(76u, A); + + // Check that there is no content. + std::unique_ptr<unsigned short, pdfium::FreeDeleter> contents_key = + GetFPDFWideString(L"Contents"); + EXPECT_EQ(2u, + FPDFAnnot_GetStringValue(annot, contents_key.get(), nullptr, 0)); + + // Check that the rectange coordinates are correct. + // Note that upon rendering, the rectangle coordinates will be adjusted. + FS_RECTF rect = FPDFAnnot_GetRect(annot); + EXPECT_EQ(351.820404f, rect.left); + EXPECT_EQ(583.830688f, rect.bottom); + EXPECT_EQ(475.336090f, rect.right); + EXPECT_EQ(681.535034f, rect.top); + + FPDFPage_CloseAnnot(annot); + UnloadPage(page); +} + +TEST_F(FPDFAnnotEmbeddertest, AddIllegalSubtypeAnnotation) { + // Open a file with one annotation and load its first page. + ASSERT_TRUE(OpenDocument("annotation_highlight_long_content.pdf")); + FPDF_PAGE page = FPDF_LoadPage(document(), 0); + ASSERT_TRUE(page); + + // Add an annotation with an illegal subtype. + ASSERT_FALSE(FPDFPage_CreateAnnot(page, -1)); + + UnloadPage(page); +} + +TEST_F(FPDFAnnotEmbeddertest, AddFirstTextAnnotation) { + // Open a file with no annotation and load its first page. + ASSERT_TRUE(OpenDocument("hello_world.pdf")); + FPDF_PAGE page = FPDF_LoadPage(document(), 0); + ASSERT_TRUE(page); + EXPECT_EQ(0, FPDFPage_GetAnnotCount(page)); + + // Add a text annotation to the page. + FPDF_ANNOTATION annot = FPDFPage_CreateAnnot(page, FPDF_ANNOT_TEXT); + ASSERT_TRUE(annot); + + // Check that there is now 1 annotations on this page. + EXPECT_EQ(1, FPDFPage_GetAnnotCount(page)); + + // Check that the subtype of the annotation is correct. + EXPECT_EQ(FPDF_ANNOT_TEXT, FPDFAnnot_GetSubtype(annot)); + FPDFPage_CloseAnnot(annot); + + annot = FPDFPage_GetAnnot(page, 0); + ASSERT_TRUE(annot); + EXPECT_EQ(FPDF_ANNOT_TEXT, FPDFAnnot_GetSubtype(annot)); + + // Set the color of the annotation. + ASSERT_TRUE( + FPDFAnnot_SetColor(annot, FPDFANNOT_COLORTYPE_Color, 51, 102, 153, 204)); + // Check that the color has been set correctly. + unsigned int R; + unsigned int G; + unsigned int B; + unsigned int A; + EXPECT_TRUE( + FPDFAnnot_GetColor(annot, FPDFANNOT_COLORTYPE_Color, &R, &G, &B, &A)); + EXPECT_EQ(51u, R); + EXPECT_EQ(102u, G); + EXPECT_EQ(153u, B); + EXPECT_EQ(204u, A); + + // Change the color of the annotation. + ASSERT_TRUE( + FPDFAnnot_SetColor(annot, FPDFANNOT_COLORTYPE_Color, 204, 153, 102, 51)); + // Check that the color has been set correctly. + EXPECT_TRUE( + FPDFAnnot_GetColor(annot, FPDFANNOT_COLORTYPE_Color, &R, &G, &B, &A)); + EXPECT_EQ(204u, R); + EXPECT_EQ(153u, G); + EXPECT_EQ(102u, B); + EXPECT_EQ(51u, A); + + // Set the annotation rectangle. + FS_RECTF rect = FPDFAnnot_GetRect(annot); + EXPECT_EQ(0.f, rect.left); + EXPECT_EQ(0.f, rect.right); + rect.left = 35; + rect.bottom = 150; + rect.right = 53; + rect.top = 165; + ASSERT_TRUE(FPDFAnnot_SetRect(annot, &rect)); + // Check that the annotation rectangle has been set correctly. + rect = FPDFAnnot_GetRect(annot); + EXPECT_EQ(35.f, rect.left); + EXPECT_EQ(150.f, rect.bottom); + EXPECT_EQ(53.f, rect.right); + EXPECT_EQ(165.f, rect.top); + + // Set the content of the annotation. + std::unique_ptr<unsigned short, pdfium::FreeDeleter> contents_key = + GetFPDFWideString(L"Contents"); + const wchar_t contents[] = L"Hello! This is a customized content."; + std::unique_ptr<unsigned short, pdfium::FreeDeleter> text = + GetFPDFWideString(contents); + ASSERT_TRUE(FPDFAnnot_SetStringValue(annot, contents_key.get(), text.get())); + // Check that the content has been set correctly. + unsigned long len = + FPDFAnnot_GetStringValue(annot, contents_key.get(), nullptr, 0); + std::vector<char> buf(len); + EXPECT_EQ(74u, FPDFAnnot_GetStringValue(annot, contents_key.get(), buf.data(), + len)); + EXPECT_STREQ(contents, + GetPlatformWString(reinterpret_cast<unsigned short*>(buf.data())) + .c_str()); + + FPDFPage_CloseAnnot(annot); + UnloadPage(page); +} + +TEST_F(FPDFAnnotEmbeddertest, AddAndSaveUnderlineAnnotation) { + // Open a file with one annotation and load its first page. + ASSERT_TRUE(OpenDocument("annotation_highlight_long_content.pdf")); + FPDF_PAGE page = FPDF_LoadPage(document(), 0); + ASSERT_TRUE(page); + + // Check that there is a total of one annotation on its first page, and verify + // its quadpoints. + EXPECT_EQ(1, FPDFPage_GetAnnotCount(page)); + FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 0); + ASSERT_TRUE(annot); + FS_QUADPOINTSF quadpoints = FPDFAnnot_GetAttachmentPoints(annot); + EXPECT_EQ(115.802643f, quadpoints.x1); + EXPECT_EQ(718.913940f, quadpoints.y1); + EXPECT_EQ(157.211182f, quadpoints.x4); + EXPECT_EQ(706.264465f, quadpoints.y4); + FPDFPage_CloseAnnot(annot); + + // Add an underline annotation to the page and set its quadpoints. + annot = FPDFPage_CreateAnnot(page, FPDF_ANNOT_UNDERLINE); + ASSERT_TRUE(annot); + quadpoints.x1 = 140.802643f; + quadpoints.x3 = 140.802643f; + ASSERT_TRUE(FPDFAnnot_SetAttachmentPoints(annot, &quadpoints)); + FPDFPage_CloseAnnot(annot); + + // Save the document, closing the page and document. + EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); + FPDF_ClosePage(page); + + // Open the saved document. + const char md5[] = "184b67b322edaee27994b3232544b8b3"; + TestSaved(612, 792, md5); + + // Check that the saved document has 2 annotations on the first page + EXPECT_EQ(2, FPDFPage_GetAnnotCount(m_SavedPage)); + + // Check that the second annotation is an underline annotation and verify + // its quadpoints. + FPDF_ANNOTATION new_annot = FPDFPage_GetAnnot(m_SavedPage, 1); + ASSERT_TRUE(new_annot); + EXPECT_EQ(FPDF_ANNOT_UNDERLINE, FPDFAnnot_GetSubtype(new_annot)); + FS_QUADPOINTSF new_quadpoints = FPDFAnnot_GetAttachmentPoints(new_annot); + EXPECT_NEAR(quadpoints.x1, new_quadpoints.x1, 0.001f); + EXPECT_NEAR(quadpoints.y1, new_quadpoints.y1, 0.001f); + EXPECT_NEAR(quadpoints.x4, new_quadpoints.x4, 0.001f); + EXPECT_NEAR(quadpoints.y4, new_quadpoints.y4, 0.001f); + + FPDFPage_CloseAnnot(new_annot); + CloseSaved(); +} + +TEST_F(FPDFAnnotEmbeddertest, ModifyRectQuadpointsWithAP) { + // Open a file with four annotations and load its first page. + ASSERT_TRUE(OpenDocument("annotation_highlight_square_with_ap.pdf")); + FPDF_PAGE page = FPDF_LoadPage(document(), 0); + ASSERT_TRUE(page); + EXPECT_EQ(4, FPDFPage_GetAnnotCount(page)); + + // Retrieve the highlight annotation which has its AP stream already defined. + FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 0); + ASSERT_TRUE(annot); + EXPECT_EQ(FPDF_ANNOT_HIGHLIGHT, FPDFAnnot_GetSubtype(annot)); + + // Check that color cannot be set when an AP stream is defined already. + EXPECT_FALSE( + FPDFAnnot_SetColor(annot, FPDFANNOT_COLORTYPE_Color, 51, 102, 153, 204)); + + // Check that when getting the attachment points, bounding box points are + // returned since this is a markup annotation with AP defined. + FS_QUADPOINTSF quadpoints = FPDFAnnot_GetAttachmentPoints(annot); + EXPECT_NEAR(0.f, quadpoints.x1, 0.001f); + EXPECT_NEAR(16.9955f, quadpoints.y1, 0.001f); + EXPECT_NEAR(68.5953f, quadpoints.x4, 0.001f); + EXPECT_NEAR(0.f, quadpoints.y4, 0.001f); + + // Check that when new attachment points define a smaller bounding box, the + // bounding box does not get updated. + quadpoints.x1 = 1.0f; + quadpoints.x3 = 1.0f; + ASSERT_TRUE(FPDFAnnot_SetAttachmentPoints(annot, &quadpoints)); + FS_QUADPOINTSF new_quadpoints = FPDFAnnot_GetAttachmentPoints(annot); + EXPECT_NE(quadpoints.x1, new_quadpoints.x1); + + // Check that the bounding box gets updated successfully when valid attachment + // points are set. + quadpoints.x1 = 0.f; + quadpoints.y1 = 721.792f; + quadpoints.x2 = 133.055f; + quadpoints.y2 = 721.792f; + quadpoints.x3 = 0.f; + quadpoints.x4 = 133.055f; + ASSERT_TRUE(FPDFAnnot_SetAttachmentPoints(annot, &quadpoints)); + new_quadpoints = FPDFAnnot_GetAttachmentPoints(annot); + EXPECT_EQ(quadpoints.x1, new_quadpoints.x1); + EXPECT_EQ(quadpoints.y1, new_quadpoints.y1); + EXPECT_EQ(quadpoints.x4, new_quadpoints.x4); + EXPECT_EQ(quadpoints.y4, new_quadpoints.y4); + + // Check that when getting the annotation rectangle, rectangle points are + // returned, but not bounding box points. + FS_RECTF rect = FPDFAnnot_GetRect(annot); + EXPECT_NEAR(67.7299f, rect.left, 0.001f); + EXPECT_NEAR(704.296f, rect.bottom, 0.001f); + EXPECT_NEAR(136.325f, rect.right, 0.001f); + EXPECT_NEAR(721.292f, rect.top, 0.001f); + + // Check that the rectangle gets updated successfully when a valid rectangle + // is set, and that the bounding box is not modified. + rect.left = 0.f; + rect.bottom = 0.f; + rect.right = 134.055f; + rect.top = 722.792f; + ASSERT_TRUE(FPDFAnnot_SetRect(annot, &rect)); + FS_RECTF new_rect = FPDFAnnot_GetRect(annot); + EXPECT_EQ(rect.right, new_rect.right); + new_quadpoints = FPDFAnnot_GetAttachmentPoints(annot); + EXPECT_NE(rect.right, new_quadpoints.x2); + + FPDFPage_CloseAnnot(annot); + + // Retrieve the square annotation which has its AP stream already defined. + annot = FPDFPage_GetAnnot(page, 2); + ASSERT_TRUE(annot); + EXPECT_EQ(FPDF_ANNOT_SQUARE, FPDFAnnot_GetSubtype(annot)); + + // Check that the rectangle and the bounding box get updated successfully when + // a valid rectangle is set, since this is not a markup annotation. + rect = FPDFAnnot_GetRect(annot); + rect.right += 1.f; + ASSERT_TRUE(FPDFAnnot_SetRect(annot, &rect)); + new_rect = FPDFAnnot_GetRect(annot); + EXPECT_EQ(rect.right, new_rect.right); + + FPDFPage_CloseAnnot(annot); + UnloadPage(page); +} + +TEST_F(FPDFAnnotEmbeddertest, RemoveAnnotation) { + // Open a file with 3 annotations on its first page. + ASSERT_TRUE(OpenDocument("annotation_ink_multiple.pdf")); + FPDF_PAGE page = FPDF_LoadPage(document(), 0); + ASSERT_TRUE(page); + EXPECT_EQ(3, FPDFPage_GetAnnotCount(page)); + + // Check that the annotations have the expected rectangle coordinates. + FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 0); + FS_RECTF rect = FPDFAnnot_GetRect(annot); + EXPECT_NEAR(86.1971f, rect.left, 0.001f); + FPDFPage_CloseAnnot(annot); + + annot = FPDFPage_GetAnnot(page, 1); + rect = FPDFAnnot_GetRect(annot); + EXPECT_NEAR(149.8127f, rect.left, 0.001f); + FPDFPage_CloseAnnot(annot); + + annot = FPDFPage_GetAnnot(page, 2); + rect = FPDFAnnot_GetRect(annot); + EXPECT_NEAR(351.8204f, rect.left, 0.001f); + FPDFPage_CloseAnnot(annot); + + // Check that nothing happens when attempting to remove an annotation with an + // out-of-bound index. + EXPECT_FALSE(FPDFPage_RemoveAnnot(page, 4)); + EXPECT_FALSE(FPDFPage_RemoveAnnot(page, -1)); + EXPECT_EQ(3, FPDFPage_GetAnnotCount(page)); + + // Remove the second annotation. + EXPECT_TRUE(FPDFPage_RemoveAnnot(page, 1)); + EXPECT_EQ(2, FPDFPage_GetAnnotCount(page)); + EXPECT_FALSE(FPDFPage_GetAnnot(page, 2)); + + // Save the document, closing the page and document. + EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); + FPDF_ClosePage(page); + + // TODO(npm): TestSaved changes annot rect dimensions by 1?? + // Open the saved document. + std::string new_file = GetString(); + FPDF_FILEACCESS file_access; + memset(&file_access, 0, sizeof(file_access)); + file_access.m_FileLen = new_file.size(); + file_access.m_GetBlock = GetBlockFromString; + file_access.m_Param = &new_file; + FPDF_DOCUMENT new_doc = FPDF_LoadCustomDocument(&file_access, nullptr); + ASSERT_TRUE(new_doc); + FPDF_PAGE new_page = FPDF_LoadPage(new_doc, 0); + ASSERT_TRUE(new_page); + + // Check that the saved document has 2 annotations on the first page. + EXPECT_EQ(2, FPDFPage_GetAnnotCount(new_page)); + + // Check that the remaining 2 annotations are the original 1st and 3rd ones by + // verifying their rectangle coordinates. + annot = FPDFPage_GetAnnot(new_page, 0); + rect = FPDFAnnot_GetRect(annot); + EXPECT_NEAR(86.1971f, rect.left, 0.001f); + FPDFPage_CloseAnnot(annot); + + annot = FPDFPage_GetAnnot(new_page, 1); + rect = FPDFAnnot_GetRect(annot); + EXPECT_NEAR(351.8204f, rect.left, 0.001f); + FPDFPage_CloseAnnot(annot); + FPDF_ClosePage(new_page); + FPDF_CloseDocument(new_doc); +} + +TEST_F(FPDFAnnotEmbeddertest, AddAndModifyPath) { +#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ + const char md5_original[] = "c35408717759562d1f8bf33d317483d2"; + const char md5_modified_path[] = "cf3cea74bd46497520ff6c4d1ea228c8"; + const char md5_two_paths[] = "e8994452fc4385337bae5522354e10ff"; + const char md5_new_annot[] = "ee5372b31fede117fc83b9384598aa25"; +#elif _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ + const char md5_original[] = "4f64add0190ede63f7bb9eb1e2e83edb"; + const char md5_modified_path[] = "681f0d0738dded0722e146f6c219bfac"; + const char md5_two_paths[] = "67c7e90fc3b64e20f6b69a1744f7f4f0"; + const char md5_new_annot[] = "262187984451bae2fe826067d68623ff"; +#else + const char md5_original[] = "02e1c6adff8fee4aeabd91c2c2e4be43"; + const char md5_modified_path[] = "87a78cbacd8509b961a67be56b5665a2"; + const char md5_two_paths[] = "76e985c18b73ceacf409f77f978176d4"; + const char md5_new_annot[] = "c95de7a9a1f61faca03d953961a319b9"; +#endif + + // Open a file with two annotations and load its first page. + ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf")); + FPDF_PAGE page = FPDF_LoadPage(document(), 0); + ASSERT_TRUE(page); + EXPECT_EQ(2, FPDFPage_GetAnnotCount(page)); + + // Check that the page renders correctly. + FPDF_BITMAP bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT); + CompareBitmap(bitmap, 595, 842, md5_original); + FPDFBitmap_Destroy(bitmap); + + // Retrieve the stamp annotation which has its AP stream already defined. + FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 0); + ASSERT_TRUE(annot); + + // Check that this annotation has one path object and retrieve it. + EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot)); + FPDF_PAGEOBJECT path = FPDFAnnot_GetObject(annot, 1); + EXPECT_FALSE(path); + path = FPDFAnnot_GetObject(annot, 0); + EXPECT_EQ(FPDF_PAGEOBJ_PATH, FPDFPageObj_GetType(path)); + EXPECT_TRUE(path); + + // Modify the color of the path object. + EXPECT_TRUE(FPDFPath_SetStrokeColor(path, 0, 0, 0, 255)); + EXPECT_TRUE(FPDFAnnot_UpdateObject(annot, path)); + + // Check that the page with the modified annotation renders correctly. + bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT); + CompareBitmap(bitmap, 595, 842, md5_modified_path); + FPDFBitmap_Destroy(bitmap); + + // Add a second path object to the same annotation. + FPDF_PAGEOBJECT dot = FPDFPageObj_CreateNewPath(7, 84); + EXPECT_TRUE(FPDFPath_BezierTo(dot, 9, 86, 10, 87, 11, 88)); + EXPECT_TRUE(FPDFPath_SetStrokeColor(dot, 255, 0, 0, 100)); + EXPECT_TRUE(FPDFPath_SetStrokeWidth(dot, 14)); + EXPECT_TRUE(FPDFPath_SetDrawMode(dot, 0, 1)); + EXPECT_TRUE(FPDFAnnot_AppendObject(annot, dot)); + EXPECT_EQ(2, FPDFAnnot_GetObjectCount(annot)); + + // Check that the page with an annotation with two paths renders correctly. + bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT); + CompareBitmap(bitmap, 595, 842, md5_two_paths); + FPDFBitmap_Destroy(bitmap); + + // Delete the newly added path object. + EXPECT_TRUE(FPDFAnnot_RemoveObject(annot, 1)); + EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot)); + FPDFPage_CloseAnnot(annot); + + // Check that the page renders the same as before. + bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT); + CompareBitmap(bitmap, 595, 842, md5_modified_path); + FPDFBitmap_Destroy(bitmap); + + // Create another stamp annotation and set its annotation rectangle. + annot = FPDFPage_CreateAnnot(page, FPDF_ANNOT_STAMP); + ASSERT_TRUE(annot); + FS_RECTF rect; + rect.left = 200.f; + rect.bottom = 400.f; + rect.right = 500.f; + rect.top = 600.f; + EXPECT_TRUE(FPDFAnnot_SetRect(annot, &rect)); + + // Add a new path to the annotation. + FPDF_PAGEOBJECT check = FPDFPageObj_CreateNewPath(200, 500); + EXPECT_TRUE(FPDFPath_LineTo(check, 300, 400)); + EXPECT_TRUE(FPDFPath_LineTo(check, 500, 600)); + EXPECT_TRUE(FPDFPath_MoveTo(check, 350, 550)); + EXPECT_TRUE(FPDFPath_LineTo(check, 450, 450)); + EXPECT_TRUE(FPDFPath_SetStrokeColor(check, 0, 255, 255, 180)); + EXPECT_TRUE(FPDFPath_SetStrokeWidth(check, 8.35f)); + EXPECT_TRUE(FPDFPath_SetDrawMode(check, 0, 1)); + EXPECT_TRUE(FPDFAnnot_AppendObject(annot, check)); + EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot)); + + // Check that the annotation's bounding box came from its rectangle. + FS_RECTF new_rect = FPDFAnnot_GetRect(annot); + EXPECT_EQ(rect.left, new_rect.left); + EXPECT_EQ(rect.bottom, new_rect.bottom); + EXPECT_EQ(rect.right, new_rect.right); + EXPECT_EQ(rect.top, new_rect.top); + + // Save the document, closing the page and document. + FPDFPage_CloseAnnot(annot); + EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); + FPDF_ClosePage(page); + + // Open the saved document. + TestSaved(595, 842, md5_new_annot); + + // Check that the document has a correct count of annotations and objects. + EXPECT_EQ(3, FPDFPage_GetAnnotCount(m_SavedPage)); + annot = FPDFPage_GetAnnot(m_SavedPage, 2); + ASSERT_TRUE(annot); + EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot)); + + // Check that the new annotation's rectangle is as defined. + new_rect = FPDFAnnot_GetRect(annot); + EXPECT_EQ(rect.left, new_rect.left); + EXPECT_EQ(rect.bottom, new_rect.bottom); + EXPECT_EQ(rect.right, new_rect.right); + EXPECT_EQ(rect.top, new_rect.top); + + FPDFPage_CloseAnnot(annot); + CloseSaved(); +} + +TEST_F(FPDFAnnotEmbeddertest, ModifyAnnotationFlags) { + // Open a file with an annotation and load its first page. + ASSERT_TRUE(OpenDocument("annotation_highlight_rollover_ap.pdf")); + FPDF_PAGE page = FPDF_LoadPage(document(), 0); + ASSERT_TRUE(page); + + // Check that the page renders correctly. + FPDF_BITMAP bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT); + CompareBitmap(bitmap, 612, 792, "dc98f06da047bd8aabfa99562d2cbd1e"); + FPDFBitmap_Destroy(bitmap); + + // Retrieve the annotation. + FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 0); + ASSERT_TRUE(annot); + + // Check that the original flag values are as expected. + int flags = FPDFAnnot_GetFlags(annot); + EXPECT_FALSE(flags & FPDF_ANNOT_FLAG_HIDDEN); + EXPECT_TRUE(flags & FPDF_ANNOT_FLAG_PRINT); + + // Set the HIDDEN flag. + flags |= FPDF_ANNOT_FLAG_HIDDEN; + EXPECT_TRUE(FPDFAnnot_SetFlags(annot, flags)); + flags = FPDFAnnot_GetFlags(annot); + EXPECT_TRUE(flags & FPDF_ANNOT_FLAG_HIDDEN); + EXPECT_TRUE(flags & FPDF_ANNOT_FLAG_PRINT); + + // Check that the page renders correctly without rendering the annotation. + bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT); + CompareBitmap(bitmap, 612, 792, "1940568c9ba33bac5d0b1ee9558c76b3"); + FPDFBitmap_Destroy(bitmap); + + // Unset the HIDDEN flag. + EXPECT_TRUE(FPDFAnnot_SetFlags(annot, FPDF_ANNOT_FLAG_NONE)); + EXPECT_FALSE(FPDFAnnot_GetFlags(annot)); + flags &= ~FPDF_ANNOT_FLAG_HIDDEN; + EXPECT_TRUE(FPDFAnnot_SetFlags(annot, flags)); + flags = FPDFAnnot_GetFlags(annot); + EXPECT_FALSE(flags & FPDF_ANNOT_FLAG_HIDDEN); + EXPECT_TRUE(flags & FPDF_ANNOT_FLAG_PRINT); + + // Check that the page renders correctly as before. + bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT); + CompareBitmap(bitmap, 612, 792, "dc98f06da047bd8aabfa99562d2cbd1e"); + FPDFBitmap_Destroy(bitmap); + + FPDFPage_CloseAnnot(annot); + UnloadPage(page); +} + +TEST_F(FPDFAnnotEmbeddertest, AddAndModifyImage) { +#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ + const char md5_original[] = "c35408717759562d1f8bf33d317483d2"; + const char md5_new_image[] = "ff012f5697436dfcaec25b32d1333596"; + const char md5_modified_image[] = "86cf8cb2755a7a2046a543e66d9c1e61"; +#elif _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ + const char md5_original[] = "4f64add0190ede63f7bb9eb1e2e83edb"; + const char md5_new_image[] = "6fb176c20996cc554d0210d8c8b6138f"; + const char md5_modified_image[] = "546959714dfb0dcd7e7b00259e8d178c"; +#else + const char md5_original[] = "02e1c6adff8fee4aeabd91c2c2e4be43"; + const char md5_new_image[] = "e7658232abd8977cdc3367dd02aee04a"; + const char md5_modified_image[] = "f393432b9a9b452ea69022f46c8b3f75"; +#endif + + // Open a file with two annotations and load its first page. + ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf")); + FPDF_PAGE page = FPDF_LoadPage(document(), 0); + ASSERT_TRUE(page); + EXPECT_EQ(2, FPDFPage_GetAnnotCount(page)); + + // Check that the page renders correctly. + FPDF_BITMAP bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT); + CompareBitmap(bitmap, 595, 842, md5_original); + FPDFBitmap_Destroy(bitmap); + + // Create a stamp annotation and set its annotation rectangle. + FPDF_ANNOTATION annot = FPDFPage_CreateAnnot(page, FPDF_ANNOT_STAMP); + ASSERT_TRUE(annot); + FS_RECTF rect; + rect.left = 200.f; + rect.bottom = 600.f; + rect.right = 400.f; + rect.top = 800.f; + EXPECT_TRUE(FPDFAnnot_SetRect(annot, &rect)); + + // Add a solid-color translucent image object to the new annotation. + constexpr int kBitmapSize = 200; + FPDF_BITMAP image_bitmap = FPDFBitmap_Create(kBitmapSize, kBitmapSize, 1); + FPDFBitmap_FillRect(image_bitmap, 0, 0, kBitmapSize, kBitmapSize, 0xeeeecccc); + EXPECT_EQ(kBitmapSize, FPDFBitmap_GetWidth(image_bitmap)); + EXPECT_EQ(kBitmapSize, FPDFBitmap_GetHeight(image_bitmap)); + FPDF_PAGEOBJECT image_object = FPDFPageObj_NewImageObj(document()); + ASSERT_TRUE(FPDFImageObj_SetBitmap(&page, 0, image_object, image_bitmap)); + ASSERT_TRUE(FPDFImageObj_SetMatrix(image_object, kBitmapSize, 0, 0, + kBitmapSize, 0, 0)); + FPDFPageObj_Transform(image_object, 1, 0, 0, 1, 200, 600); + EXPECT_TRUE(FPDFAnnot_AppendObject(annot, image_object)); + FPDFPage_CloseAnnot(annot); + + // Check that the page renders correctly with the new image object. + bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT); + CompareBitmap(bitmap, 595, 842, md5_new_image); + FPDFBitmap_Destroy(bitmap); + + // Retrieve the newly added stamp annotation and its image object. + annot = FPDFPage_GetAnnot(page, 2); + ASSERT_TRUE(annot); + EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot)); + image_object = FPDFAnnot_GetObject(annot, 0); + EXPECT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(image_object)); + + // Modify the image in the new annotation. + FPDFBitmap_FillRect(image_bitmap, 0, 0, kBitmapSize, kBitmapSize, 0xff000000); + ASSERT_TRUE(FPDFImageObj_SetBitmap(&page, 0, image_object, image_bitmap)); + EXPECT_TRUE(FPDFAnnot_UpdateObject(annot, image_object)); + FPDFPage_CloseAnnot(annot); + + // Save the document, closing the page and document. + EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); + FPDF_ClosePage(page); + + // Test that the saved document renders the modified image object correctly. + TestSaved(595, 842, md5_modified_image); + + FPDFBitmap_Destroy(image_bitmap); + CloseSaved(); +} + +TEST_F(FPDFAnnotEmbeddertest, AddAndModifyText) { +#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ + const char md5_original[] = "c35408717759562d1f8bf33d317483d2"; + const char md5_new_text[] = "e5680ed048c2cfd9a1d27212cdf41286"; + const char md5_modified_text[] = "79f5cfb0b07caaf936f65f6a7a57ce77"; +#elif _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ + const char md5_original[] = "4f64add0190ede63f7bb9eb1e2e83edb"; + const char md5_new_text[] = "998abae4962f8f41e094e7612d8339fc"; + const char md5_modified_text[] = "e89b82ca4589b8f0b45fff42ca3a96a4"; +#else + const char md5_original[] = "02e1c6adff8fee4aeabd91c2c2e4be43"; + const char md5_new_text[] = "3fbbaec4d846ccf2be89e09daae0273d"; + const char md5_modified_text[] = "2ad0acaf2d8990bcdf48e1d12e6c44ad"; +#endif + + // Open a file with two annotations and load its first page. + ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf")); + FPDF_PAGE page = FPDF_LoadPage(document(), 0); + ASSERT_TRUE(page); + EXPECT_EQ(2, FPDFPage_GetAnnotCount(page)); + + // Check that the page renders correctly. + FPDF_BITMAP bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT); + CompareBitmap(bitmap, 595, 842, md5_original); + FPDFBitmap_Destroy(bitmap); + + // Create a stamp annotation and set its annotation rectangle. + FPDF_ANNOTATION annot = FPDFPage_CreateAnnot(page, FPDF_ANNOT_STAMP); + ASSERT_TRUE(annot); + FS_RECTF rect; + rect.left = 200.f; + rect.bottom = 550.f; + rect.right = 450.f; + rect.top = 650.f; + EXPECT_TRUE(FPDFAnnot_SetRect(annot, &rect)); + + // Add a translucent text object to the new annotation. + FPDF_PAGEOBJECT text_object = + FPDFPageObj_NewTextObj(document(), "Arial", 12.0f); + EXPECT_TRUE(text_object); + std::unique_ptr<unsigned short, pdfium::FreeDeleter> text = + GetFPDFWideString(L"I'm a translucent text laying on other text."); + EXPECT_TRUE(FPDFText_SetText(text_object, text.get())); + EXPECT_TRUE(FPDFText_SetFillColor(text_object, 0, 0, 255, 150)); + FPDFPageObj_Transform(text_object, 1, 0, 0, 1, 200, 600); + EXPECT_TRUE(FPDFAnnot_AppendObject(annot, text_object)); + FPDFPage_CloseAnnot(annot); + + // Check that the page renders correctly with the new text object. + bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT); + CompareBitmap(bitmap, 595, 842, md5_new_text); + FPDFBitmap_Destroy(bitmap); + + // Retrieve the newly added stamp annotation and its text object. + annot = FPDFPage_GetAnnot(page, 2); + ASSERT_TRUE(annot); + EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot)); + text_object = FPDFAnnot_GetObject(annot, 0); + EXPECT_EQ(FPDF_PAGEOBJ_TEXT, FPDFPageObj_GetType(text_object)); + + // Modify the text in the new annotation. + std::unique_ptr<unsigned short, pdfium::FreeDeleter> new_text = + GetFPDFWideString(L"New text!"); + EXPECT_TRUE(FPDFText_SetText(text_object, new_text.get())); + EXPECT_TRUE(FPDFAnnot_UpdateObject(annot, text_object)); + FPDFPage_CloseAnnot(annot); + + // Check that the page renders correctly with the modified text object. + bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT); + CompareBitmap(bitmap, 595, 842, md5_modified_text); + FPDFBitmap_Destroy(bitmap); + + // Remove the new annotation, and check that the page renders as before. + EXPECT_TRUE(FPDFPage_RemoveAnnot(page, 2)); + bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT); + CompareBitmap(bitmap, 595, 842, md5_original); + FPDFBitmap_Destroy(bitmap); + + UnloadPage(page); +} + +TEST_F(FPDFAnnotEmbeddertest, GetSetStringValue) { + // Open a file with four annotations and load its first page. + ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf")); + FPDF_PAGE page = FPDF_LoadPage(document(), 0); + ASSERT_TRUE(page); + + // Retrieve the first annotation. + FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 0); + ASSERT_TRUE(annot); + + // Check that a non-existent key does not exist. + EXPECT_FALSE(FPDFAnnot_HasKey(annot, GetFPDFWideString(L"none").get())); + + // Check that the string value of a non-string dictionary entry is empty. + std::unique_ptr<unsigned short, pdfium::FreeDeleter> ap_key = + GetFPDFWideString(L"AP"); + EXPECT_TRUE(FPDFAnnot_HasKey(annot, ap_key.get())); + EXPECT_EQ(FPDF_OBJECT_REFERENCE, FPDFAnnot_GetValueType(annot, ap_key.get())); + EXPECT_EQ(2u, FPDFAnnot_GetStringValue(annot, ap_key.get(), nullptr, 0)); + + // Check that the string value of the hash is correct. + std::unique_ptr<unsigned short, pdfium::FreeDeleter> hash_key = + GetFPDFWideString(L"AAPL:Hash"); + EXPECT_EQ(FPDF_OBJECT_NAME, FPDFAnnot_GetValueType(annot, hash_key.get())); + unsigned long len = + FPDFAnnot_GetStringValue(annot, hash_key.get(), nullptr, 0); + std::vector<char> buf(len); + EXPECT_EQ(66u, + FPDFAnnot_GetStringValue(annot, hash_key.get(), buf.data(), len)); + EXPECT_STREQ(L"395fbcb98d558681742f30683a62a2ad", + GetPlatformWString(reinterpret_cast<unsigned short*>(buf.data())) + .c_str()); + + // Check that the string value of the modified date is correct. + std::unique_ptr<unsigned short, pdfium::FreeDeleter> date_key = + GetFPDFWideString(L"M"); + EXPECT_EQ(FPDF_OBJECT_NAME, FPDFAnnot_GetValueType(annot, hash_key.get())); + len = FPDFAnnot_GetStringValue(annot, date_key.get(), nullptr, 0); + buf.clear(); + buf.resize(len); + EXPECT_EQ(44u, + FPDFAnnot_GetStringValue(annot, date_key.get(), buf.data(), len)); + EXPECT_STREQ(L"D:201706071721Z00'00'", + GetPlatformWString(reinterpret_cast<unsigned short*>(buf.data())) + .c_str()); + + // Update the date entry for the annotation. + const wchar_t new_date[] = L"D:201706282359Z00'00'"; + std::unique_ptr<unsigned short, pdfium::FreeDeleter> text = + GetFPDFWideString(new_date); + EXPECT_TRUE(FPDFAnnot_SetStringValue(annot, date_key.get(), text.get())); + + // Save the document, closing the page and document. + FPDFPage_CloseAnnot(annot); + EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); + FPDF_ClosePage(page); + + // Open the saved annotation. +#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ + const char md5[] = "c35408717759562d1f8bf33d317483d2"; +#elif _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ + const char md5[] = "4f64add0190ede63f7bb9eb1e2e83edb"; +#else + const char md5[] = "02e1c6adff8fee4aeabd91c2c2e4be43"; +#endif + TestSaved(595, 842, md5); + FPDF_ANNOTATION new_annot = FPDFPage_GetAnnot(m_SavedPage, 0); + + // Check that the string value of the modified date is the newly-set value. + EXPECT_EQ(FPDF_OBJECT_STRING, + FPDFAnnot_GetValueType(new_annot, date_key.get())); + len = FPDFAnnot_GetStringValue(new_annot, date_key.get(), nullptr, 0); + buf.clear(); + buf.resize(len); + EXPECT_EQ(44u, FPDFAnnot_GetStringValue(new_annot, date_key.get(), buf.data(), + len)); + EXPECT_STREQ(new_date, + GetPlatformWString(reinterpret_cast<unsigned short*>(buf.data())) + .c_str()); + + FPDFPage_CloseAnnot(new_annot); + CloseSaved(); +} + +TEST_F(FPDFAnnotEmbeddertest, GetFormFieldFlagsTextField) { + // Open file with form text fields. + ASSERT_TRUE(OpenDocument("text_form_multiple.pdf")); + FPDF_PAGE page = FPDF_LoadPage(document(), 0); + ASSERT_TRUE(page); + + // Retrieve the first annotation: user-editable text field. + FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 0); + ASSERT_TRUE(annot); + + // Check that the flag values are as expected. + int flags = FPDFAnnot_GetFormFieldFlags(page, annot); + EXPECT_FALSE(flags & FPDF_FORMFLAG_READONLY); + FPDFPage_CloseAnnot(annot); + + // Retrieve the second annotation: read-only text field. + annot = FPDFPage_GetAnnot(page, 1); + ASSERT_TRUE(annot); + + // Check that the flag values are as expected. + flags = FPDFAnnot_GetFormFieldFlags(page, annot); + EXPECT_TRUE(flags & FPDF_FORMFLAG_READONLY); + FPDFPage_CloseAnnot(annot); + + UnloadPage(page); +} + +TEST_F(FPDFAnnotEmbeddertest, GetFormFieldFlagsComboBox) { + // Open file with form text fields. + ASSERT_TRUE(OpenDocument("combobox_form.pdf")); + FPDF_PAGE page = FPDF_LoadPage(document(), 0); + ASSERT_TRUE(page); + + // Retrieve the first annotation: user-editable combobox. + FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 0); + ASSERT_TRUE(annot); + + // Check that the flag values are as expected. + int flags = FPDFAnnot_GetFormFieldFlags(page, annot); + EXPECT_FALSE(flags & FPDF_FORMFLAG_READONLY); + EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_COMBO); + EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_EDIT); + FPDFPage_CloseAnnot(annot); + + // Retrieve the second annotation: regular combobox. + annot = FPDFPage_GetAnnot(page, 1); + ASSERT_TRUE(annot); + + // Check that the flag values are as expected. + flags = FPDFAnnot_GetFormFieldFlags(page, annot); + EXPECT_FALSE(flags & FPDF_FORMFLAG_READONLY); + EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_COMBO); + EXPECT_FALSE(flags & FPDF_FORMFLAG_CHOICE_EDIT); + FPDFPage_CloseAnnot(annot); + + // Retrieve the third annotation: read-only combobox. + annot = FPDFPage_GetAnnot(page, 2); + ASSERT_TRUE(annot); + + // Check that the flag values are as expected. + flags = FPDFAnnot_GetFormFieldFlags(page, annot); + EXPECT_TRUE(flags & FPDF_FORMFLAG_READONLY); + EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_COMBO); + EXPECT_FALSE(flags & FPDF_FORMFLAG_CHOICE_EDIT); + FPDFPage_CloseAnnot(annot); + + UnloadPage(page); +} + +TEST_F(FPDFAnnotEmbeddertest, GetFormAnnotNull) { + // Open file with form text fields. + EXPECT_TRUE(OpenDocument("text_form.pdf")); + FPDF_PAGE page = LoadPage(0); + ASSERT_TRUE(page); + + // Attempt to get an annotation where no annotation exists on page. + FPDF_ANNOTATION annot = + FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 0, 0); + EXPECT_FALSE(annot); + + UnloadPage(page); +} + +TEST_F(FPDFAnnotEmbeddertest, GetFormAnnotAndCheckFlagsTextField) { + // Open file with form text fields. + EXPECT_TRUE(OpenDocument("text_form_multiple.pdf")); + FPDF_PAGE page = LoadPage(0); + ASSERT_TRUE(page); + + // Retrieve user-editable text field annotation. + FPDF_ANNOTATION annot = + FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 105, 118); + ASSERT_TRUE(annot); + + // Check that interactive form annotation flag values are as expected. + int flags = FPDFAnnot_GetFormFieldFlags(page, annot); + EXPECT_FALSE(flags & FPDF_FORMFLAG_READONLY); + FPDFPage_CloseAnnot(annot); + + // Retrieve read-only text field annotation. + annot = FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 105, 202); + ASSERT_TRUE(annot); + + // Check that interactive form annotation flag values are as expected. + flags = FPDFAnnot_GetFormFieldFlags(page, annot); + EXPECT_TRUE(flags & FPDF_FORMFLAG_READONLY); + FPDFPage_CloseAnnot(annot); + + UnloadPage(page); +} + +TEST_F(FPDFAnnotEmbeddertest, GetFormAnnotAndCheckFlagsComboBox) { + // Open file with form comboboxes. + EXPECT_TRUE(OpenDocument("combobox_form.pdf")); + FPDF_PAGE page = LoadPage(0); + ASSERT_TRUE(page); + + // Retrieve user-editable combobox annotation. + FPDF_ANNOTATION annot = + FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 102, 63); + ASSERT_TRUE(annot); + + // Check that interactive form annotation flag values are as expected. + int flags = FPDFAnnot_GetFormFieldFlags(page, annot); + EXPECT_FALSE(flags & FPDF_FORMFLAG_READONLY); + EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_COMBO); + EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_EDIT); + FPDFPage_CloseAnnot(annot); + + // Retrieve regular combobox annotation. + annot = FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 102, 113); + ASSERT_TRUE(annot); + + // Check that interactive form annotation flag values are as expected. + flags = FPDFAnnot_GetFormFieldFlags(page, annot); + EXPECT_FALSE(flags & FPDF_FORMFLAG_READONLY); + EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_COMBO); + EXPECT_FALSE(flags & FPDF_FORMFLAG_CHOICE_EDIT); + FPDFPage_CloseAnnot(annot); + + // Retrieve read-only combobox annotation. + annot = FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 102, 213); + ASSERT_TRUE(annot); + + // Check that interactive form annotation flag values are as expected. + flags = FPDFAnnot_GetFormFieldFlags(page, annot); + EXPECT_TRUE(flags & FPDF_FORMFLAG_READONLY); + EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_COMBO); + EXPECT_FALSE(flags & FPDF_FORMFLAG_CHOICE_EDIT); + FPDFPage_CloseAnnot(annot); + + UnloadPage(page); +} diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdfattachment.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdfattachment.cpp new file mode 100644 index 00000000000..7d8cce736bf --- /dev/null +++ b/chromium/third_party/pdfium/fpdfsdk/fpdfattachment.cpp @@ -0,0 +1,138 @@ +// Copyright 2017 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. + +#include "public/fpdf_attachment.h" + +#include "core/fpdfapi/page/cpdf_streamparser.h" +#include "core/fpdfapi/parser/cpdf_document.h" +#include "core/fpdfapi/parser/cpdf_string.h" +#include "core/fpdfapi/parser/fpdf_parser_decode.h" +#include "core/fpdfdoc/cpdf_filespec.h" +#include "core/fpdfdoc/cpdf_nametree.h" +#include "fpdfsdk/fsdk_define.h" + +DLLEXPORT int STDCALL FPDFDoc_GetAttachmentCount(FPDF_DOCUMENT document) { + CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); + if (!pDoc) + return 0; + + return CPDF_NameTree(pDoc, "EmbeddedFiles").GetCount(); +} + +DLLEXPORT FPDF_ATTACHMENT STDCALL FPDFDoc_GetAttachment(FPDF_DOCUMENT document, + int index) { + CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); + if (!pDoc || index < 0) + return nullptr; + + CPDF_NameTree nameTree(pDoc, "EmbeddedFiles"); + if (static_cast<size_t>(index) >= nameTree.GetCount()) + return nullptr; + + CFX_WideString csName; + return nameTree.LookupValueAndName(index, &csName); +} + +DLLEXPORT unsigned long STDCALL +FPDFAttachment_GetName(FPDF_ATTACHMENT attachment, + void* buffer, + unsigned long buflen) { + CPDF_Object* pFile = CPDFObjectFromFPDFAttachment(attachment); + if (!pFile) + return 0; + + return Utf16EncodeMaybeCopyAndReturnLength(CPDF_FileSpec(pFile).GetFileName(), + buffer, buflen); +} + +DLLEXPORT FPDF_BOOL STDCALL FPDFAttachment_HasKey(FPDF_ATTACHMENT attachment, + FPDF_WIDESTRING key) { + CPDF_Object* pFile = CPDFObjectFromFPDFAttachment(attachment); + if (!pFile) + return 0; + + CPDF_Dictionary* pParamsDict = CPDF_FileSpec(pFile).GetParamsDict(); + if (!pParamsDict) + return 0; + + return pParamsDict->KeyExist(CFXByteStringFromFPDFWideString(key)); +} + +DLLEXPORT FPDF_OBJECT_TYPE STDCALL +FPDFAttachment_GetValueType(FPDF_ATTACHMENT attachment, FPDF_WIDESTRING key) { + if (!FPDFAttachment_HasKey(attachment, key)) + return FPDF_OBJECT_UNKNOWN; + + CPDF_Object* pObj = CPDF_FileSpec(CPDFObjectFromFPDFAttachment(attachment)) + .GetParamsDict() + ->GetObjectFor(CFXByteStringFromFPDFWideString(key)); + if (!pObj) + return FPDF_OBJECT_UNKNOWN; + + return pObj->GetType(); +} + +DLLEXPORT unsigned long STDCALL +FPDFAttachment_GetStringValue(FPDF_ATTACHMENT attachment, + FPDF_WIDESTRING key, + void* buffer, + unsigned long buflen) { + CPDF_Object* pFile = CPDFObjectFromFPDFAttachment(attachment); + if (!pFile) + return 0; + + CPDF_Dictionary* pParamsDict = CPDF_FileSpec(pFile).GetParamsDict(); + if (!pParamsDict) + return 0; + + CFX_ByteString bsKey = CFXByteStringFromFPDFWideString(key); + CFX_WideString value = pParamsDict->GetUnicodeTextFor(bsKey); + if (bsKey == "CheckSum") { + CPDF_String* stringValue = pParamsDict->GetObjectFor(bsKey)->AsString(); + if (stringValue->IsHex()) { + value = + CPDF_String(nullptr, PDF_EncodeString(stringValue->GetString(), true), + false) + .GetUnicodeText(); + } + } + + return Utf16EncodeMaybeCopyAndReturnLength(value, buffer, buflen); +} + +DLLEXPORT unsigned long STDCALL +FPDFAttachment_GetFile(FPDF_ATTACHMENT attachment, + void* buffer, + unsigned long buflen) { + CPDF_Object* pFile = CPDFObjectFromFPDFAttachment(attachment); + if (!pFile) + return 0; + + CPDF_Stream* pFileStream = CPDF_FileSpec(pFile).GetFileStream(); + if (!pFileStream) + return 0; + + uint8_t* data = pFileStream->GetRawData(); + uint32_t len = pFileStream->GetRawSize(); + CPDF_Dictionary* pFileDict = pFileStream->GetDict(); + if (!pFileDict || pFileDict->GetStringFor("Filter").IsEmpty()) { + if (buffer && buflen >= len) + memcpy(buffer, data, len); + + return len; + } + + // Decode the stream if a stream filter is specified. + uint8_t* decodedData = nullptr; + uint32_t decodedLen = 0; + CPDF_StreamParser::DecodeInlineStream( + data, len, pFileDict->GetIntegerFor("Width"), + pFileDict->GetIntegerFor("Height"), pFileDict->GetStringFor("Filter"), + pFileDict->GetDictFor("DecodeParms"), &decodedData, &decodedLen); + if (buffer && buflen >= decodedLen) + memcpy(buffer, decodedData, decodedLen); + + FX_Free(decodedData); + return decodedLen; +} diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdfattachment_embeddertest.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdfattachment_embeddertest.cpp new file mode 100644 index 00000000000..d873d9b5ce2 --- /dev/null +++ b/chromium/third_party/pdfium/fpdfsdk/fpdfattachment_embeddertest.cpp @@ -0,0 +1,87 @@ +// Copyright 2017 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. + +#include "public/fpdf_attachment.h" +#include "public/fpdfview.h" +#include "testing/embedder_test.h" + +class FPDFAttachmentEmbeddertest : public EmbedderTest {}; + +TEST_F(FPDFAttachmentEmbeddertest, ExtractAttachments) { + // Open a file with two attachments. + ASSERT_TRUE(OpenDocument("embedded_attachments.pdf")); + EXPECT_EQ(2, FPDFDoc_GetAttachmentCount(document())); + + // Retrieve the first attachment. + FPDF_ATTACHMENT attachment = FPDFDoc_GetAttachment(document(), 0); + ASSERT_TRUE(attachment); + + // Check that the name of the first attachment is correct. + unsigned long len = FPDFAttachment_GetName(attachment, nullptr, 0); + std::vector<char> buf(len); + EXPECT_EQ(12u, FPDFAttachment_GetName(attachment, buf.data(), len)); + EXPECT_STREQ(L"1.txt", + GetPlatformWString(reinterpret_cast<unsigned short*>(buf.data())) + .c_str()); + + // Check that the content of the first attachment is correct. + len = FPDFAttachment_GetFile(attachment, nullptr, 0); + buf.clear(); + buf.resize(len); + ASSERT_EQ(4u, FPDFAttachment_GetFile(attachment, buf.data(), len)); + EXPECT_EQ(std::string("test"), std::string(buf.data(), 4)); + + // Check that a non-existent key does not exist. + EXPECT_FALSE( + FPDFAttachment_HasKey(attachment, GetFPDFWideString(L"none").get())); + + // Check that the string value of a non-string dictionary entry is empty. + std::unique_ptr<unsigned short, pdfium::FreeDeleter> size_key = + GetFPDFWideString(L"Size"); + EXPECT_EQ(FPDF_OBJECT_NUMBER, + FPDFAttachment_GetValueType(attachment, size_key.get())); + EXPECT_EQ(2u, FPDFAttachment_GetStringValue(attachment, size_key.get(), + nullptr, 0)); + + // Check that the creation date of the first attachment is correct. + std::unique_ptr<unsigned short, pdfium::FreeDeleter> date_key = + GetFPDFWideString(L"CreationDate"); + len = FPDFAttachment_GetStringValue(attachment, date_key.get(), nullptr, 0); + buf.clear(); + buf.resize(len); + EXPECT_EQ(48u, FPDFAttachment_GetStringValue(attachment, date_key.get(), + buf.data(), len)); + EXPECT_STREQ(L"D:20170712214438-07'00'", + GetPlatformWString(reinterpret_cast<unsigned short*>(buf.data())) + .c_str()); + + // Retrieve the second attachment. + attachment = FPDFDoc_GetAttachment(document(), 1); + ASSERT_TRUE(attachment); + + // Retrieve the second attachment file. + len = FPDFAttachment_GetFile(attachment, nullptr, 0); + buf.clear(); + buf.resize(len); + EXPECT_EQ(5869u, FPDFAttachment_GetFile(attachment, buf.data(), len)); + + // Check that the calculated checksum of the file data matches expectation. + const char kCheckSum[] = "72afcddedf554dda63c0c88e06f1ce18"; + const wchar_t kCheckSumW[] = L"<72AFCDDEDF554DDA63C0C88E06F1CE18>"; + const std::string generated_checksum = + GenerateMD5Base16(reinterpret_cast<uint8_t*>(buf.data()), len); + EXPECT_EQ(kCheckSum, generated_checksum); + + // Check that the stored checksum matches expectation. + std::unique_ptr<unsigned short, pdfium::FreeDeleter> checksum_key = + GetFPDFWideString(L"CheckSum"); + len = + FPDFAttachment_GetStringValue(attachment, checksum_key.get(), nullptr, 0); + buf.clear(); + buf.resize(len); + EXPECT_EQ(70u, FPDFAttachment_GetStringValue(attachment, checksum_key.get(), + buf.data(), len)); + EXPECT_EQ(kCheckSumW, + GetPlatformWString(reinterpret_cast<unsigned short*>(buf.data()))); +} diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdfdoc.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdfdoc.cpp index 1c445e6f146..b6088604fd7 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdfdoc.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdfdoc.cpp @@ -60,16 +60,6 @@ CPDF_LinkList* GetLinkList(CPDF_Page* page) { return pHolder->get(); } -unsigned long Utf16EncodeMaybeCopyAndReturnLength(const CFX_WideString& text, - void* buffer, - unsigned long buflen) { - CFX_ByteString encodedText = text.UTF16LE_Encode(); - unsigned long len = encodedText.GetLength(); - if (buffer && len <= buflen) - memcpy(buffer, encodedText.c_str(), len); - return len; -} - } // namespace DLLEXPORT FPDF_BOOKMARK STDCALL @@ -394,6 +384,7 @@ DLLEXPORT unsigned long STDCALL FPDF_GetMetaText(FPDF_DOCUMENT document, CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); if (!pDoc) return 0; + pDoc->LoadDocumentInfo(); CPDF_Dictionary* pInfo = pDoc->GetInfo(); if (!pInfo) return 0; diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdfdoc_embeddertest.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdfdoc_embeddertest.cpp index 2472db9746f..f069ec26314 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdfdoc_embeddertest.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdfdoc_embeddertest.cpp @@ -10,7 +10,6 @@ #include "public/fpdf_edit.h" #include "public/fpdfview.h" #include "testing/embedder_test.h" -#include "testing/fx_string_testhelpers.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/test_support.h" diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdfdoc_unittest.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdfdoc_unittest.cpp index 449121d351d..6409f70fe26 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdfdoc_unittest.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdfdoc_unittest.cpp @@ -87,7 +87,7 @@ class PDFDocTest : public testing::Test { protected: std::unique_ptr<CPDF_TestPdfDocument> m_pDoc; - CPDF_IndirectObjectHolder* m_pIndirectObjs; + CFX_UnownedPtr<CPDF_IndirectObjectHolder> m_pIndirectObjs; std::unique_ptr<CPDF_Dictionary> m_pRootObj; }; @@ -116,25 +116,25 @@ TEST_F(PDFDocTest, FindBookmark) { auto bookmarks = CreateDictObjs(3); bookmarks[1].obj->SetNewFor<CPDF_String>("Title", L"Chapter 1"); - bookmarks[1].obj->SetNewFor<CPDF_Reference>("Parent", m_pIndirectObjs, + bookmarks[1].obj->SetNewFor<CPDF_Reference>("Parent", m_pIndirectObjs.Get(), bookmarks[0].num); - bookmarks[1].obj->SetNewFor<CPDF_Reference>("Next", m_pIndirectObjs, + bookmarks[1].obj->SetNewFor<CPDF_Reference>("Next", m_pIndirectObjs.Get(), bookmarks[2].num); bookmarks[2].obj->SetNewFor<CPDF_String>("Title", L"Chapter 2"); - bookmarks[2].obj->SetNewFor<CPDF_Reference>("Parent", m_pIndirectObjs, + bookmarks[2].obj->SetNewFor<CPDF_Reference>("Parent", m_pIndirectObjs.Get(), bookmarks[0].num); - bookmarks[2].obj->SetNewFor<CPDF_Reference>("Prev", m_pIndirectObjs, + bookmarks[2].obj->SetNewFor<CPDF_Reference>("Prev", m_pIndirectObjs.Get(), bookmarks[1].num); bookmarks[0].obj->SetNewFor<CPDF_Name>("Type", "Outlines"); bookmarks[0].obj->SetNewFor<CPDF_Number>("Count", 2); - bookmarks[0].obj->SetNewFor<CPDF_Reference>("First", m_pIndirectObjs, + bookmarks[0].obj->SetNewFor<CPDF_Reference>("First", m_pIndirectObjs.Get(), bookmarks[1].num); - bookmarks[0].obj->SetNewFor<CPDF_Reference>("Last", m_pIndirectObjs, + bookmarks[0].obj->SetNewFor<CPDF_Reference>("Last", m_pIndirectObjs.Get(), bookmarks[2].num); - m_pRootObj->SetNewFor<CPDF_Reference>("Outlines", m_pIndirectObjs, + m_pRootObj->SetNewFor<CPDF_Reference>("Outlines", m_pIndirectObjs.Get(), bookmarks[0].num); // Title with no match. @@ -159,25 +159,25 @@ TEST_F(PDFDocTest, FindBookmark) { auto bookmarks = CreateDictObjs(3); bookmarks[1].obj->SetNewFor<CPDF_String>("Title", L"Chapter 1"); - bookmarks[1].obj->SetNewFor<CPDF_Reference>("Parent", m_pIndirectObjs, + bookmarks[1].obj->SetNewFor<CPDF_Reference>("Parent", m_pIndirectObjs.Get(), bookmarks[0].num); - bookmarks[1].obj->SetNewFor<CPDF_Reference>("First", m_pIndirectObjs, + bookmarks[1].obj->SetNewFor<CPDF_Reference>("First", m_pIndirectObjs.Get(), bookmarks[2].num); bookmarks[2].obj->SetNewFor<CPDF_String>("Title", L"Chapter 2"); - bookmarks[2].obj->SetNewFor<CPDF_Reference>("Parent", m_pIndirectObjs, + bookmarks[2].obj->SetNewFor<CPDF_Reference>("Parent", m_pIndirectObjs.Get(), bookmarks[1].num); - bookmarks[2].obj->SetNewFor<CPDF_Reference>("First", m_pIndirectObjs, + bookmarks[2].obj->SetNewFor<CPDF_Reference>("First", m_pIndirectObjs.Get(), bookmarks[1].num); bookmarks[0].obj->SetNewFor<CPDF_Name>("Type", "Outlines"); bookmarks[0].obj->SetNewFor<CPDF_Number>("Count", 2); - bookmarks[0].obj->SetNewFor<CPDF_Reference>("First", m_pIndirectObjs, + bookmarks[0].obj->SetNewFor<CPDF_Reference>("First", m_pIndirectObjs.Get(), bookmarks[1].num); - bookmarks[0].obj->SetNewFor<CPDF_Reference>("Last", m_pIndirectObjs, + bookmarks[0].obj->SetNewFor<CPDF_Reference>("Last", m_pIndirectObjs.Get(), bookmarks[2].num); - m_pRootObj->SetNewFor<CPDF_Reference>("Outlines", m_pIndirectObjs, + m_pRootObj->SetNewFor<CPDF_Reference>("Outlines", m_pIndirectObjs.Get(), bookmarks[0].num); // Title with no match. @@ -194,31 +194,31 @@ TEST_F(PDFDocTest, FindBookmark) { auto bookmarks = CreateDictObjs(4); bookmarks[1].obj->SetNewFor<CPDF_String>("Title", L"Chapter 1"); - bookmarks[1].obj->SetNewFor<CPDF_Reference>("Parent", m_pIndirectObjs, + bookmarks[1].obj->SetNewFor<CPDF_Reference>("Parent", m_pIndirectObjs.Get(), bookmarks[0].num); - bookmarks[1].obj->SetNewFor<CPDF_Reference>("Next", m_pIndirectObjs, + bookmarks[1].obj->SetNewFor<CPDF_Reference>("Next", m_pIndirectObjs.Get(), bookmarks[2].num); bookmarks[2].obj->SetNewFor<CPDF_String>("Title", L"Chapter 2"); - bookmarks[2].obj->SetNewFor<CPDF_Reference>("Parent", m_pIndirectObjs, + bookmarks[2].obj->SetNewFor<CPDF_Reference>("Parent", m_pIndirectObjs.Get(), bookmarks[0].num); - bookmarks[2].obj->SetNewFor<CPDF_Reference>("Next", m_pIndirectObjs, + bookmarks[2].obj->SetNewFor<CPDF_Reference>("Next", m_pIndirectObjs.Get(), bookmarks[3].num); bookmarks[3].obj->SetNewFor<CPDF_String>("Title", L"Chapter 3"); - bookmarks[3].obj->SetNewFor<CPDF_Reference>("Parent", m_pIndirectObjs, + bookmarks[3].obj->SetNewFor<CPDF_Reference>("Parent", m_pIndirectObjs.Get(), bookmarks[0].num); - bookmarks[3].obj->SetNewFor<CPDF_Reference>("Next", m_pIndirectObjs, + bookmarks[3].obj->SetNewFor<CPDF_Reference>("Next", m_pIndirectObjs.Get(), bookmarks[1].num); bookmarks[0].obj->SetNewFor<CPDF_Name>("Type", "Outlines"); bookmarks[0].obj->SetNewFor<CPDF_Number>("Count", 2); - bookmarks[0].obj->SetNewFor<CPDF_Reference>("First", m_pIndirectObjs, + bookmarks[0].obj->SetNewFor<CPDF_Reference>("First", m_pIndirectObjs.Get(), bookmarks[1].num); - bookmarks[0].obj->SetNewFor<CPDF_Reference>("Last", m_pIndirectObjs, + bookmarks[0].obj->SetNewFor<CPDF_Reference>("Last", m_pIndirectObjs.Get(), bookmarks[2].num); - m_pRootObj->SetNewFor<CPDF_Reference>("Outlines", m_pIndirectObjs, + m_pRootObj->SetNewFor<CPDF_Reference>("Outlines", m_pIndirectObjs.Get(), bookmarks[0].num); // Title with no match. diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdfedit_embeddertest.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdfedit_embeddertest.cpp index b10dacfc989..cc3e50b362c 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdfedit_embeddertest.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdfedit_embeddertest.cpp @@ -15,6 +15,7 @@ #include "core/fxcrt/fx_system.h" #include "fpdfsdk/fsdk_define.h" #include "public/cpp/fpdf_deleters.h" +#include "public/fpdf_annot.h" #include "public/fpdf_edit.h" #include "public/fpdfview.h" #include "testing/embedder_test.h" @@ -22,7 +23,7 @@ #include "testing/gtest/include/gtest/gtest.h" #include "testing/test_support.h" -class FPDFEditEmbeddertest : public EmbedderTest, public TestSaver { +class FPDFEditEmbeddertest : public EmbedderTest { protected: FPDF_DOCUMENT CreateNewDocument() { document_ = FPDF_CreateNewDocument(); @@ -138,15 +139,13 @@ const char kExpectedPDF[] = "<</CreationDate\\(D:.*\\)/Creator\\(PDFium\\)>>\r\n" "endobj\r\n" "4 0 obj\r\n" - "<</Contents 5 0 R /MediaBox\\[ 0 0 640 480\\]" - "/Parent 2 0 R /Resources<<>>/Rotate 0/Type/Page" + "<</MediaBox\\[ 0 0 640 480\\]/Parent 2 0 R " + "/Resources<</ExtGState<</FXE1 5 0 R >>>>" + "/Rotate 0/Type/Page" ">>\r\n" "endobj\r\n" "5 0 obj\r\n" - "<</Filter/FlateDecode/Length 8>>stream\r\n" - // Character '_' is matching '\0' (see comment below). - "x\x9C\x3____\x1\r\n" - "endstream\r\n" + "<</BM/Normal/CA 1/ca 1>>\r\n" "endobj\r\n" "xref\r\n" "0 6\r\n" @@ -155,14 +154,14 @@ const char kExpectedPDF[] = "0000000066 00000 n\r\n" "0000000122 00000 n\r\n" "0000000192 00000 n\r\n" - "0000000301 00000 n\r\n" + "0000000311 00000 n\r\n" "trailer\r\n" "<<\r\n" "/Root 1 0 R\r\n" "/Info 3 0 R\r\n" "/Size 6/ID\\[<.*><.*>\\]>>\r\n" "startxref\r\n" - "379\r\n" + "354\r\n" "%%EOF\r\n"; } // namespace @@ -171,15 +170,12 @@ TEST_F(FPDFEditEmbeddertest, EmptyCreation) { EXPECT_TRUE(CreateEmptyDocument()); FPDF_PAGE page = FPDFPage_New(document(), 0, 640.0, 480.0); EXPECT_NE(nullptr, page); + // The FPDFPage_GenerateContent call should do nothing. EXPECT_TRUE(FPDFPage_GenerateContent(page)); EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); - // The MatchesRegexp doesn't support embedded NUL ('\0') characters. They are - // replaced by '_' for the purpose of the test. - std::string result = GetString(); - std::replace(result.begin(), result.end(), '\0', '_'); - EXPECT_THAT(result, testing::MatchesRegex( - std::string(kExpectedPDF, sizeof(kExpectedPDF)))); + EXPECT_THAT(GetString(), testing::MatchesRegex(std::string( + kExpectedPDF, sizeof(kExpectedPDF)))); FPDF_ClosePage(page); } @@ -218,27 +214,8 @@ TEST_F(FPDFEditEmbeddertest, RasterizePDF) { // Get the generated content. Make sure it is at least as big as the original // PDF. - std::string new_file = GetString(); - EXPECT_GT(new_file.size(), 923U); - - // Read |new_file| in, and verify its rendered bitmap. - { - FPDF_FILEACCESS file_access; - memset(&file_access, 0, sizeof(file_access)); - file_access.m_FileLen = new_file.size(); - file_access.m_GetBlock = GetBlockFromString; - file_access.m_Param = &new_file; - - FPDF_DOCUMENT new_doc = FPDF_LoadCustomDocument(&file_access, nullptr); - EXPECT_EQ(1, FPDF_GetPageCount(document_)); - FPDF_PAGE new_page = FPDF_LoadPage(new_doc, 0); - EXPECT_NE(nullptr, new_page); - FPDF_BITMAP new_bitmap = RenderPage(new_page); - CompareBitmap(new_bitmap, 612, 792, kAllBlackMd5sum); - FPDF_ClosePage(new_page); - FPDF_CloseDocument(new_doc); - FPDFBitmap_Destroy(new_bitmap); - } + EXPECT_GT(GetString().size(), 923U); + TestAndCloseSaved(612, 792, kAllBlackMd5sum); } TEST_F(FPDFEditEmbeddertest, AddPaths) { @@ -256,7 +233,6 @@ TEST_F(FPDFEditEmbeddertest, AddPaths) { EXPECT_TRUE(FPDFPath_SetFillColor(red_rect, 255, 0, 0, 255)); EXPECT_TRUE(FPDFPath_SetDrawMode(red_rect, FPDF_FILLMODE_ALTERNATE, 0)); FPDFPage_InsertObject(page, red_rect); - EXPECT_TRUE(FPDFPage_GenerateContent(page)); FPDF_BITMAP page_bitmap = RenderPage(page); CompareBitmap(page_bitmap, 612, 792, "66d02eaa6181e2c069ce2ea99beda497"); FPDFBitmap_Destroy(page_bitmap); @@ -281,7 +257,6 @@ TEST_F(FPDFEditEmbeddertest, AddPaths) { EXPECT_TRUE(FPDFPath_SetDrawMode(green_rect, FPDF_FILLMODE_WINDING, 0)); FPDFPage_InsertObject(page, green_rect); - EXPECT_TRUE(FPDFPage_GenerateContent(page)); page_bitmap = RenderPage(page); CompareBitmap(page_bitmap, 612, 792, "7b0b87604594e773add528fae567a558"); FPDFBitmap_Destroy(page_bitmap); @@ -294,7 +269,6 @@ TEST_F(FPDFEditEmbeddertest, AddPaths) { EXPECT_TRUE(FPDFPath_LineTo(black_path, 300, 100)); EXPECT_TRUE(FPDFPath_Close(black_path)); FPDFPage_InsertObject(page, black_path); - EXPECT_TRUE(FPDFPage_GenerateContent(page)); page_bitmap = RenderPage(page); CompareBitmap(page_bitmap, 612, 792, "eadc8020a14dfcf091da2688733d8806"); FPDFBitmap_Destroy(page_bitmap); @@ -310,32 +284,18 @@ TEST_F(FPDFEditEmbeddertest, AddPaths) { EXPECT_TRUE(FPDFPath_BezierTo(blue_path, 375, 330, 390, 360, 400, 400)); EXPECT_TRUE(FPDFPath_Close(blue_path)); FPDFPage_InsertObject(page, blue_path); - EXPECT_TRUE(FPDFPage_GenerateContent(page)); page_bitmap = RenderPage(page); - CompareBitmap(page_bitmap, 612, 792, "9823e1a21bd9b72b6a442ba4f12af946"); + const char last_md5[] = "9823e1a21bd9b72b6a442ba4f12af946"; + CompareBitmap(page_bitmap, 612, 792, last_md5); FPDFBitmap_Destroy(page_bitmap); // Now save the result, closing the page and document + EXPECT_TRUE(FPDFPage_GenerateContent(page)); EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); FPDF_ClosePage(page); - std::string new_file = GetString(); // Render the saved result - FPDF_FILEACCESS file_access; - memset(&file_access, 0, sizeof(file_access)); - file_access.m_FileLen = new_file.size(); - file_access.m_GetBlock = GetBlockFromString; - file_access.m_Param = &new_file; - FPDF_DOCUMENT new_doc = FPDF_LoadCustomDocument(&file_access, nullptr); - ASSERT_NE(nullptr, new_doc); - EXPECT_EQ(1, FPDF_GetPageCount(new_doc)); - FPDF_PAGE new_page = FPDF_LoadPage(new_doc, 0); - ASSERT_NE(nullptr, new_page); - FPDF_BITMAP new_bitmap = RenderPage(new_page); - CompareBitmap(new_bitmap, 612, 792, "9823e1a21bd9b72b6a442ba4f12af946"); - FPDFBitmap_Destroy(new_bitmap); - FPDF_ClosePage(new_page); - FPDF_CloseDocument(new_doc); + TestAndCloseSaved(612, 792, last_md5); } TEST_F(FPDFEditEmbeddertest, PathOnTopOfText) { @@ -349,7 +309,6 @@ TEST_F(FPDFEditEmbeddertest, PathOnTopOfText) { EXPECT_TRUE(FPDFPath_SetFillColor(red_rect, 255, 0, 0, 255)); EXPECT_TRUE(FPDFPath_SetDrawMode(red_rect, FPDF_FILLMODE_ALTERNATE, 0)); FPDFPage_InsertObject(page, red_rect); - EXPECT_TRUE(FPDFPage_GenerateContent(page)); // Add a transparent triangle on top of other part of the text. FPDF_PAGEOBJECT black_path = FPDFPageObj_CreateNewPath(20, 50); @@ -359,20 +318,75 @@ TEST_F(FPDFEditEmbeddertest, PathOnTopOfText) { EXPECT_TRUE(FPDFPath_LineTo(black_path, 40, 10)); EXPECT_TRUE(FPDFPath_Close(black_path)); FPDFPage_InsertObject(page, black_path); - EXPECT_TRUE(FPDFPage_GenerateContent(page)); // Render and check the result. Text is slightly different on Mac. FPDF_BITMAP bitmap = RenderPage(page); #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ const char md5[] = "f9e6fa74230f234286bfcada9f7606d8"; #else - const char md5[] = "2fdfc5dda29374cfba4349362e38ebdb"; + const char md5[] = "bc6e6eb50dda4695ba0fb4d04ed82ada"; #endif CompareBitmap(bitmap, 200, 200, md5); FPDFBitmap_Destroy(bitmap); UnloadPage(page); } +TEST_F(FPDFEditEmbeddertest, EditOverExistingContent) { + // Load document with existing content + EXPECT_TRUE(OpenDocument("bug_717.pdf")); + FPDF_PAGE page = LoadPage(0); + EXPECT_NE(nullptr, page); + + // Add a transparent rectangle on top of the existing content + FPDF_PAGEOBJECT red_rect2 = FPDFPageObj_CreateNewRect(90, 700, 25, 50); + EXPECT_TRUE(FPDFPath_SetFillColor(red_rect2, 255, 0, 0, 100)); + EXPECT_TRUE(FPDFPath_SetDrawMode(red_rect2, FPDF_FILLMODE_ALTERNATE, 0)); + FPDFPage_InsertObject(page, red_rect2); + + // Add an opaque rectangle on top of the existing content + FPDF_PAGEOBJECT red_rect = FPDFPageObj_CreateNewRect(115, 700, 25, 50); + EXPECT_TRUE(FPDFPath_SetFillColor(red_rect, 255, 0, 0, 255)); + EXPECT_TRUE(FPDFPath_SetDrawMode(red_rect, FPDF_FILLMODE_ALTERNATE, 0)); + FPDFPage_InsertObject(page, red_rect); + + FPDF_BITMAP bitmap = RenderPage(page); + CompareBitmap(bitmap, 612, 792, "ad04e5bd0f471a9a564fb034bd0fb073"); + FPDFBitmap_Destroy(bitmap); + EXPECT_TRUE(FPDFPage_GenerateContent(page)); + + // Now save the result, closing the page and document + EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); + UnloadPage(page); + + // Render the saved result without closing the page and document + TestSaved(612, 792, "ad04e5bd0f471a9a564fb034bd0fb073"); + + ClearString(); + // Add another opaque rectangle on top of the existing content + FPDF_PAGEOBJECT green_rect = FPDFPageObj_CreateNewRect(150, 700, 25, 50); + EXPECT_TRUE(FPDFPath_SetFillColor(green_rect, 0, 255, 0, 255)); + EXPECT_TRUE(FPDFPath_SetDrawMode(green_rect, FPDF_FILLMODE_ALTERNATE, 0)); + FPDFPage_InsertObject(m_SavedPage, green_rect); + + // Add another transparent rectangle on top of existing content + FPDF_PAGEOBJECT green_rect2 = FPDFPageObj_CreateNewRect(175, 700, 25, 50); + EXPECT_TRUE(FPDFPath_SetFillColor(green_rect2, 0, 255, 0, 100)); + EXPECT_TRUE(FPDFPath_SetDrawMode(green_rect2, FPDF_FILLMODE_ALTERNATE, 0)); + FPDFPage_InsertObject(m_SavedPage, green_rect2); + FPDF_BITMAP new_bitmap = RenderPageWithFlags(m_SavedPage, m_SavedForm, 0); + const char last_md5[] = "4b5b00f824620f8c9b8801ebb98e1cdd"; + CompareBitmap(new_bitmap, 612, 792, last_md5); + FPDFBitmap_Destroy(new_bitmap); + EXPECT_TRUE(FPDFPage_GenerateContent(m_SavedPage)); + + // Now save the result, closing the page and document + EXPECT_TRUE(FPDF_SaveAsCopy(m_SavedDocument, this, 0)); + CloseSaved(); + + // Render the saved result + TestAndCloseSaved(612, 792, last_md5); +} + TEST_F(FPDFEditEmbeddertest, AddStrokedPaths) { // Start with a blank page FPDF_PAGE page = FPDFPage_New(CreateNewDocument(), 0, 612, 792); @@ -384,7 +398,6 @@ TEST_F(FPDFEditEmbeddertest, AddStrokedPaths) { EXPECT_TRUE(FPDFPath_SetStrokeWidth(rect, 15.0f)); EXPECT_TRUE(FPDFPath_SetDrawMode(rect, 0, 1)); FPDFPage_InsertObject(page, rect); - EXPECT_TRUE(FPDFPage_GenerateContent(page)); FPDF_BITMAP page_bitmap = RenderPage(page); CompareBitmap(page_bitmap, 612, 792, "64bd31f862a89e0a9e505a5af6efd506"); FPDFBitmap_Destroy(page_bitmap); @@ -399,7 +412,6 @@ TEST_F(FPDFEditEmbeddertest, AddStrokedPaths) { EXPECT_TRUE(FPDFPath_SetStrokeWidth(check, 8.35f)); EXPECT_TRUE(FPDFPath_SetDrawMode(check, 0, 1)); FPDFPage_InsertObject(page, check); - EXPECT_TRUE(FPDFPage_GenerateContent(page)); page_bitmap = RenderPage(page); CompareBitmap(page_bitmap, 612, 792, "4b6f3b9d25c4e194821217d5016c3724"); FPDFBitmap_Destroy(page_bitmap); @@ -415,7 +427,6 @@ TEST_F(FPDFEditEmbeddertest, AddStrokedPaths) { EXPECT_TRUE(FPDFPath_SetStrokeWidth(path, 10.5f)); EXPECT_TRUE(FPDFPath_SetDrawMode(path, FPDF_FILLMODE_ALTERNATE, 1)); FPDFPage_InsertObject(page, path); - EXPECT_TRUE(FPDFPage_GenerateContent(page)); page_bitmap = RenderPage(page); CompareBitmap(page_bitmap, 612, 792, "ff3e6a22326754944cc6e56609acd73b"); FPDFBitmap_Destroy(page_bitmap); @@ -435,12 +446,11 @@ TEST_F(FPDFEditEmbeddertest, AddStandardFontText) { EXPECT_TRUE(FPDFText_SetText(text_object1, text1.get())); FPDFPageObj_Transform(text_object1, 1, 0, 0, 1, 20, 20); FPDFPage_InsertObject(page, text_object1); - EXPECT_TRUE(FPDFPage_GenerateContent(page)); FPDF_BITMAP page_bitmap = RenderPage(page); #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ const char md5[] = "a4dddc1a3930fa694bbff9789dab4161"; #else - const char md5[] = "6e8a9b0682f60fd3ff1bf087b093d30d"; + const char md5[] = "7a35771853a1cbba38f6775807878625"; #endif CompareBitmap(page_bitmap, 612, 792, md5); FPDFBitmap_Destroy(page_bitmap); @@ -454,14 +464,13 @@ TEST_F(FPDFEditEmbeddertest, AddStandardFontText) { EXPECT_TRUE(FPDFText_SetText(text_object2, text2.get())); FPDFPageObj_Transform(text_object2, 1, 0, 0, 1, 100, 600); FPDFPage_InsertObject(page, text_object2); - EXPECT_TRUE(FPDFPage_GenerateContent(page)); page_bitmap = RenderPage(page); #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ const char md5_2[] = "a5c4ace4c6f27644094813fe1441a21c"; #elif _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ - const char md5_2[] = "56863642d4d8b418cfd810fdb5a5d92f"; + const char md5_2[] = "b231b329a4b566fb9b42bfc15fe59bb7"; #else - const char md5_2[] = "0c83875429688bda45a55a692d5aa781"; + const char md5_2[] = "f85fae151851436072b7b3c6703e506a"; #endif CompareBitmap(page_bitmap, 612, 792, md5_2); FPDFBitmap_Destroy(page_bitmap); @@ -475,14 +484,13 @@ TEST_F(FPDFEditEmbeddertest, AddStandardFontText) { EXPECT_TRUE(FPDFText_SetText(text_object3, text3.get())); FPDFPageObj_Transform(text_object3, 1, 1.5, 2, 0.5, 200, 200); FPDFPage_InsertObject(page, text_object3); - EXPECT_TRUE(FPDFPage_GenerateContent(page)); page_bitmap = RenderPage(page); #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ const char md5_3[] = "40b3ef04f915ff4c4208948001763544"; #elif _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ - const char md5_3[] = "d69d419def35a098d9c10f8317d6709b"; + const char md5_3[] = "ba874b3b137f984510c4e287ed4ba7ae"; #else - const char md5_3[] = "8b300d3c6dfc12fa9af97e12ed5bd80a"; + const char md5_3[] = "c5aed6a8ef05558c8c47d58c87cbcb46"; #endif CompareBitmap(page_bitmap, 612, 792, md5_3); FPDFBitmap_Destroy(page_bitmap); @@ -492,6 +500,60 @@ TEST_F(FPDFEditEmbeddertest, AddStandardFontText) { FPDF_ClosePage(page); } +TEST_F(FPDFEditEmbeddertest, GraphicsData) { + // New page + std::unique_ptr<void, FPDFPageDeleter> page( + FPDFPage_New(CreateNewDocument(), 0, 612, 792)); + + // Create a rect with nontrivial graphics + FPDF_PAGEOBJECT rect1 = FPDFPageObj_CreateNewRect(10, 10, 100, 100); + FPDFPageObj_SetBlendMode(rect1, "Color"); + FPDFPage_InsertObject(page.get(), rect1); + EXPECT_TRUE(FPDFPage_GenerateContent(page.get())); + + // Check that the ExtGState was created + CPDF_Page* the_page = CPDFPageFromFPDFPage(page.get()); + CPDF_Dictionary* graphics_dict = + the_page->m_pResources->GetDictFor("ExtGState"); + ASSERT_TRUE(graphics_dict); + EXPECT_EQ(2, static_cast<int>(graphics_dict->GetCount())); + + // Add a text object causing no change to the graphics dictionary + FPDF_PAGEOBJECT text1 = FPDFPageObj_NewTextObj(document(), "Arial", 12.0f); + // Only alpha, the last component, matters for the graphics dictionary. And + // the default value is 255. + EXPECT_TRUE(FPDFText_SetFillColor(text1, 100, 100, 100, 255)); + FPDFPage_InsertObject(page.get(), text1); + EXPECT_TRUE(FPDFPage_GenerateContent(page.get())); + EXPECT_EQ(2, static_cast<int>(graphics_dict->GetCount())); + + // Add a text object increasing the size of the graphics dictionary + FPDF_PAGEOBJECT text2 = + FPDFPageObj_NewTextObj(document(), "Times-Roman", 12.0f); + FPDFPage_InsertObject(page.get(), text2); + FPDFPageObj_SetBlendMode(text2, "Darken"); + EXPECT_TRUE(FPDFText_SetFillColor(text2, 0, 0, 255, 150)); + EXPECT_TRUE(FPDFPage_GenerateContent(page.get())); + EXPECT_EQ(3, static_cast<int>(graphics_dict->GetCount())); + + // Add a path that should reuse graphics + FPDF_PAGEOBJECT path = FPDFPageObj_CreateNewPath(400, 100); + FPDFPageObj_SetBlendMode(path, "Darken"); + EXPECT_TRUE(FPDFPath_SetFillColor(path, 200, 200, 100, 150)); + FPDFPage_InsertObject(page.get(), path); + EXPECT_TRUE(FPDFPage_GenerateContent(page.get())); + EXPECT_EQ(3, static_cast<int>(graphics_dict->GetCount())); + + // Add a rect increasing the size of the graphics dictionary + FPDF_PAGEOBJECT rect2 = FPDFPageObj_CreateNewRect(10, 10, 100, 100); + FPDFPageObj_SetBlendMode(rect2, "Darken"); + EXPECT_TRUE(FPDFPath_SetFillColor(rect2, 0, 0, 255, 150)); + EXPECT_TRUE(FPDFPath_SetStrokeColor(rect2, 0, 0, 0, 200)); + FPDFPage_InsertObject(page.get(), rect2); + EXPECT_TRUE(FPDFPage_GenerateContent(page.get())); + EXPECT_EQ(4, static_cast<int>(graphics_dict->GetCount())); +} + TEST_F(FPDFEditEmbeddertest, DoubleGenerating) { // Start with a blank page FPDF_PAGE page = FPDFPage_New(CreateNewDocument(), 0, 612, 792); @@ -508,7 +570,7 @@ TEST_F(FPDFEditEmbeddertest, DoubleGenerating) { CPDF_Dictionary* graphics_dict = the_page->m_pResources->GetDictFor("ExtGState"); ASSERT_TRUE(graphics_dict); - EXPECT_EQ(1, static_cast<int>(graphics_dict->GetCount())); + EXPECT_EQ(2, static_cast<int>(graphics_dict->GetCount())); // Check the bitmap FPDF_BITMAP page_bitmap = RenderPage(page); @@ -518,7 +580,7 @@ TEST_F(FPDFEditEmbeddertest, DoubleGenerating) { // Never mind, my new favorite color is blue, increase alpha EXPECT_TRUE(FPDFPath_SetFillColor(rect, 0, 0, 255, 180)); EXPECT_TRUE(FPDFPage_GenerateContent(page)); - EXPECT_EQ(2, static_cast<int>(graphics_dict->GetCount())); + EXPECT_EQ(3, static_cast<int>(graphics_dict->GetCount())); // Check that bitmap displays changed content page_bitmap = RenderPage(page); @@ -527,7 +589,7 @@ TEST_F(FPDFEditEmbeddertest, DoubleGenerating) { // And now generate, without changes EXPECT_TRUE(FPDFPage_GenerateContent(page)); - EXPECT_EQ(2, static_cast<int>(graphics_dict->GetCount())); + EXPECT_EQ(3, static_cast<int>(graphics_dict->GetCount())); page_bitmap = RenderPage(page); CompareBitmap(page_bitmap, 612, 792, "2e51656f5073b0bee611d9cd086aa09c"); FPDFBitmap_Destroy(page_bitmap); @@ -547,7 +609,7 @@ TEST_F(FPDFEditEmbeddertest, DoubleGenerating) { // Generate yet again, check dicts are reasonably sized EXPECT_TRUE(FPDFPage_GenerateContent(page)); - EXPECT_EQ(2, static_cast<int>(graphics_dict->GetCount())); + EXPECT_EQ(3, static_cast<int>(graphics_dict->GetCount())); EXPECT_EQ(1, static_cast<int>(font_dict->GetCount())); FPDF_ClosePage(page); } @@ -725,12 +787,11 @@ TEST_F(FPDFEditEmbeddertest, AddTrueTypeFontText) { EXPECT_TRUE(FPDFText_SetText(text_object, text.get())); FPDFPageObj_Transform(text_object, 1, 0, 0, 1, 400, 400); FPDFPage_InsertObject(page, text_object); - EXPECT_TRUE(FPDFPage_GenerateContent(page)); FPDF_BITMAP page_bitmap = RenderPage(page); #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ const char md5[] = "17d2b6cd574cf66170b09c8927529a94"; #else - const char md5[] = "28e5b10743660dcdfd1618db47b39d32"; + const char md5[] = "1722c6a9deed953d730de9cd13dcbd55"; #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ CompareBitmap(page_bitmap, 612, 792, md5); FPDFBitmap_Destroy(page_bitmap); @@ -743,37 +804,38 @@ TEST_F(FPDFEditEmbeddertest, AddTrueTypeFontText) { EXPECT_TRUE(FPDFText_SetText(text_object2, text2.get())); FPDFPageObj_Transform(text_object2, 1, 0, 0, 1, 200, 200); FPDFPage_InsertObject(page, text_object2); - EXPECT_TRUE(FPDFPage_GenerateContent(page)); } FPDF_BITMAP page_bitmap2 = RenderPage(page); #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ const char md5_2[] = "8eded4193ff1f0f77b8b600a825e97ea"; #else - const char md5_2[] = "a068eef4110d607f77c87ea8340fa2a5"; + const char md5_2[] = "9d7885072058f6c3e68ecaf32e917f30"; #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ CompareBitmap(page_bitmap2, 612, 792, md5_2); FPDFBitmap_Destroy(page_bitmap2); + EXPECT_TRUE(FPDFPage_GenerateContent(page)); EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); FPDF_ClosePage(page); - std::string new_file = GetString(); + TestAndCloseSaved(612, 792, md5_2); +} - // Render the saved result - FPDF_FILEACCESS file_access; - memset(&file_access, 0, sizeof(file_access)); - file_access.m_FileLen = new_file.size(); - file_access.m_GetBlock = GetBlockFromString; - file_access.m_Param = &new_file; - FPDF_DOCUMENT new_doc = FPDF_LoadCustomDocument(&file_access, nullptr); - ASSERT_NE(nullptr, new_doc); - EXPECT_EQ(1, FPDF_GetPageCount(new_doc)); - FPDF_PAGE new_page = FPDF_LoadPage(new_doc, 0); - ASSERT_NE(nullptr, new_page); - FPDF_BITMAP new_bitmap = RenderPage(new_page); - CompareBitmap(new_bitmap, 612, 792, md5_2); - FPDFBitmap_Destroy(new_bitmap); - FPDF_ClosePage(new_page); - FPDF_CloseDocument(new_doc); +TEST_F(FPDFEditEmbeddertest, TransformAnnot) { + // Open a file with one annotation and load its first page. + ASSERT_TRUE(OpenDocument("annotation_highlight_long_content.pdf")); + FPDF_PAGE page = FPDF_LoadPage(document(), 0); + ASSERT_TRUE(page); + + // Add an underline annotation to the page without specifying its rectangle. + FPDF_ANNOTATION annot = FPDFPage_CreateAnnot(page, FPDF_ANNOT_UNDERLINE); + ASSERT_TRUE(annot); + + // FPDFPage_TransformAnnots() should run without errors when modifying + // annotation rectangles. + FPDFPage_TransformAnnots(page, 1, 2, 3, 4, 5, 6); + + FPDFPage_CloseAnnot(annot); + UnloadPage(page); } // TODO(npm): Add tests using Japanese fonts in other OS. @@ -819,33 +881,47 @@ TEST_F(FPDFEditEmbeddertest, AddCIDFontText) { FPDFPage_InsertObject(page, text_object2); } - // Generate contents and check that the text renders properly. - EXPECT_TRUE(FPDFPage_GenerateContent(page)); + // Check that the text renders properly. FPDF_BITMAP page_bitmap = RenderPage(page); const char md5[] = "2bc6c1aaa2252e73246a75775ccf38c2"; CompareBitmap(page_bitmap, 612, 792, md5); FPDFBitmap_Destroy(page_bitmap); // Save the document, close the page. + EXPECT_TRUE(FPDFPage_GenerateContent(page)); EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); FPDF_ClosePage(page); - std::string new_file = GetString(); - - // Render the saved result - FPDF_FILEACCESS file_access; - memset(&file_access, 0, sizeof(file_access)); - file_access.m_FileLen = new_file.size(); - file_access.m_GetBlock = GetBlockFromString; - file_access.m_Param = &new_file; - FPDF_DOCUMENT new_doc = FPDF_LoadCustomDocument(&file_access, nullptr); - ASSERT_NE(nullptr, new_doc); - EXPECT_EQ(1, FPDF_GetPageCount(new_doc)); - FPDF_PAGE new_page = FPDF_LoadPage(new_doc, 0); - ASSERT_NE(nullptr, new_page); - FPDF_BITMAP new_bitmap = RenderPage(new_page); - CompareBitmap(new_bitmap, 612, 792, md5); - FPDFBitmap_Destroy(new_bitmap); - FPDF_ClosePage(new_page); - FPDF_CloseDocument(new_doc); + TestAndCloseSaved(612, 792, md5); } #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ + +TEST_F(FPDFEditEmbeddertest, SaveAndRender) { + const char md5[] = "3c20472b0552c0c22b88ab1ed8c6202b"; + { + EXPECT_TRUE(OpenDocument("bug_779.pdf")); + FPDF_PAGE page = LoadPage(0); + ASSERT_NE(nullptr, page); + + // Now add a more complex blue path. + FPDF_PAGEOBJECT green_path = FPDFPageObj_CreateNewPath(20, 20); + EXPECT_TRUE(FPDFPath_SetFillColor(green_path, 0, 255, 0, 200)); + // TODO(npm): stroking will cause the MD5s to differ. + EXPECT_TRUE(FPDFPath_SetDrawMode(green_path, FPDF_FILLMODE_WINDING, 0)); + EXPECT_TRUE(FPDFPath_LineTo(green_path, 20, 63)); + EXPECT_TRUE(FPDFPath_BezierTo(green_path, 55, 55, 78, 78, 90, 90)); + EXPECT_TRUE(FPDFPath_LineTo(green_path, 133, 133)); + EXPECT_TRUE(FPDFPath_LineTo(green_path, 133, 33)); + EXPECT_TRUE(FPDFPath_BezierTo(green_path, 38, 33, 39, 36, 40, 40)); + EXPECT_TRUE(FPDFPath_Close(green_path)); + FPDFPage_InsertObject(page, green_path); + FPDF_BITMAP page_bitmap = RenderPage(page); + CompareBitmap(page_bitmap, 612, 792, md5); + FPDFBitmap_Destroy(page_bitmap); + + // Now save the result, closing the page and document + EXPECT_TRUE(FPDFPage_GenerateContent(page)); + EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); + UnloadPage(page); + } + TestAndCloseSaved(612, 792, md5); +} diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdfeditimg.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdfeditimg.cpp index 9f4b2968ee0..fdc98e06e92 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdfeditimg.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdfeditimg.cpp @@ -39,7 +39,7 @@ bool LoadJpegHelper(FPDF_PAGE* pages, pImgObj->GetImage()->SetJpegImageInline(pFile); else pImgObj->GetImage()->SetJpegImage(pFile); - + pImgObj->SetDirty(true); return true; } @@ -87,6 +87,7 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_SetMatrix(FPDF_PAGEOBJECT image_object, static_cast<float>(c), static_cast<float>(d), static_cast<float>(e), static_cast<float>(f))); pImgObj->CalcBoundingBox(); + pImgObj->SetDirty(true); return true; } @@ -106,5 +107,6 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_SetBitmap(FPDF_PAGE* pages, CFX_RetainPtr<CFX_DIBitmap> holder(CFXBitmapFromFPDFBitmap(bitmap)); pImgObj->GetImage()->SetImage(holder); pImgObj->CalcBoundingBox(); + pImgObj->SetDirty(true); return true; } diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdfeditpage.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdfeditpage.cpp index 6ed375807fc..a7ee212aeee 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdfeditpage.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdfeditpage.cpp @@ -61,6 +61,38 @@ bool IsPageObject(CPDF_Page* pPage) { return pObject && !pObject->GetString().Compare("Page"); } +void CalcBoundingBox(CPDF_PageObject* pPageObj) { + switch (pPageObj->GetType()) { + case CPDF_PageObject::TEXT: { + break; + } + case CPDF_PageObject::PATH: { + CPDF_PathObject* pPathObj = pPageObj->AsPath(); + pPathObj->CalcBoundingBox(); + break; + } + case CPDF_PageObject::IMAGE: { + CPDF_ImageObject* pImageObj = pPageObj->AsImage(); + pImageObj->CalcBoundingBox(); + break; + } + case CPDF_PageObject::SHADING: { + CPDF_ShadingObject* pShadingObj = pPageObj->AsShading(); + pShadingObj->CalcBoundingBox(); + break; + } + case CPDF_PageObject::FORM: { + CPDF_FormObject* pFormObj = pPageObj->AsForm(); + pFormObj->CalcBoundingBox(); + break; + } + default: { + NOTREACHED(); + break; + } + } +} + } // namespace DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_CreateNewDocument() { @@ -136,7 +168,7 @@ DLLEXPORT int STDCALL FPDFPage_GetRotation(FPDF_PAGE page) { DLLEXPORT void STDCALL FPDFPage_InsertObject(FPDF_PAGE page, FPDF_PAGEOBJECT page_obj) { - CPDF_PageObject* pPageObj = static_cast<CPDF_PageObject*>(page_obj); + CPDF_PageObject* pPageObj = CPDFPageObjectFromFPDFPageObject(page_obj); if (!pPageObj) return; @@ -144,37 +176,9 @@ DLLEXPORT void STDCALL FPDFPage_InsertObject(FPDF_PAGE page, CPDF_Page* pPage = CPDFPageFromFPDFPage(page); if (!IsPageObject(pPage)) return; - + pPageObj->SetDirty(true); pPage->GetPageObjectList()->push_back(std::move(pPageObjHolder)); - switch (pPageObj->GetType()) { - case CPDF_PageObject::TEXT: { - break; - } - case CPDF_PageObject::PATH: { - CPDF_PathObject* pPathObj = pPageObj->AsPath(); - pPathObj->CalcBoundingBox(); - break; - } - case CPDF_PageObject::IMAGE: { - CPDF_ImageObject* pImageObj = pPageObj->AsImage(); - pImageObj->CalcBoundingBox(); - break; - } - case CPDF_PageObject::SHADING: { - CPDF_ShadingObject* pShadingObj = pPageObj->AsShading(); - pShadingObj->CalcBoundingBox(); - break; - } - case CPDF_PageObject::FORM: { - CPDF_FormObject* pFormObj = pPageObj->AsForm(); - pFormObj->CalcBoundingBox(); - break; - } - default: { - NOTREACHED(); - break; - } - } + CalcBoundingBox(pPageObj); } DLLEXPORT int STDCALL FPDFPage_CountObject(FPDF_PAGE page) { @@ -202,7 +206,7 @@ FPDFPageObj_HasTransparency(FPDF_PAGEOBJECT pageObject) { if (!pageObject) return false; - CPDF_PageObject* pPageObj = static_cast<CPDF_PageObject*>(pageObject); + CPDF_PageObject* pPageObj = CPDFPageObjectFromFPDFPageObject(pageObject); int blend_type = pPageObj->m_GeneralState.GetBlendType(); if (blend_type != FXDIB_BLEND_NORMAL) return true; @@ -235,7 +239,7 @@ DLLEXPORT int STDCALL FPDFPageObj_GetType(FPDF_PAGEOBJECT pageObject) { if (!pageObject) return FPDF_PAGEOBJ_UNKNOWN; - CPDF_PageObject* pPageObj = static_cast<CPDF_PageObject*>(pageObject); + CPDF_PageObject* pPageObj = CPDFPageObjectFromFPDFPageObject(pageObject); return pPageObj->GetType(); } @@ -256,7 +260,7 @@ DLLEXPORT void STDCALL FPDFPageObj_Transform(FPDF_PAGEOBJECT page_object, double d, double e, double f) { - CPDF_PageObject* pPageObj = static_cast<CPDF_PageObject*>(page_object); + CPDF_PageObject* pPageObj = CPDFPageObjectFromFPDFPageObject(page_object); if (!pPageObj) return; @@ -264,6 +268,16 @@ DLLEXPORT void STDCALL FPDFPageObj_Transform(FPDF_PAGEOBJECT page_object, pPageObj->Transform(matrix); } +DLLEXPORT void STDCALL FPDFPageObj_SetBlendMode(FPDF_PAGEOBJECT page_object, + FPDF_BYTESTRING blend_mode) { + CPDF_PageObject* pPageObj = CPDFPageObjectFromFPDFPageObject(page_object); + if (!pPageObj) + return; + + pPageObj->m_GeneralState.SetBlendMode(blend_mode); + pPageObj->SetDirty(true); +} + DLLEXPORT void STDCALL FPDFPage_TransformAnnots(FPDF_PAGE page, double a, double b, @@ -283,14 +297,17 @@ DLLEXPORT void STDCALL FPDFPage_TransformAnnots(FPDF_PAGE page, (float)f); matrix.TransformRect(rect); - CPDF_Array* pRectArray = pAnnot->GetAnnotDict()->GetArrayFor("Rect"); - if (!pRectArray) - pRectArray = pAnnot->GetAnnotDict()->SetNewFor<CPDF_Array>("Rect"); + CPDF_Dictionary* pAnnotDict = pAnnot->GetAnnotDict(); + CPDF_Array* pRectArray = pAnnotDict->GetArrayFor("Rect"); + if (pRectArray) + pRectArray->Clear(); + else + pRectArray = pAnnotDict->SetNewFor<CPDF_Array>("Rect"); - pRectArray->SetNewAt<CPDF_Number>(0, rect.left); - pRectArray->SetNewAt<CPDF_Number>(1, rect.bottom); - pRectArray->SetNewAt<CPDF_Number>(2, rect.right); - pRectArray->SetNewAt<CPDF_Number>(3, rect.top); + pRectArray->AddNew<CPDF_Number>(rect.left); + pRectArray->AddNew<CPDF_Number>(rect.bottom); + pRectArray->AddNew<CPDF_Number>(rect.right); + pRectArray->AddNew<CPDF_Number>(rect.top); // TODO(unknown): Transform AP's rectangle } @@ -304,3 +321,37 @@ DLLEXPORT void STDCALL FPDFPage_SetRotation(FPDF_PAGE page, int rotate) { rotate %= 4; pPage->m_pFormDict->SetNewFor<CPDF_Number>("Rotate", rotate * 90); } + +FPDF_BOOL FPDFPageObj_SetFillColor(FPDF_PAGEOBJECT page_object, + unsigned int R, + unsigned int G, + unsigned int B, + unsigned int A) { + if (!page_object || R > 255 || G > 255 || B > 255 || A > 255) + return false; + + float rgb[3] = {R / 255.f, G / 255.f, B / 255.f}; + auto* pPageObj = CPDFPageObjectFromFPDFPageObject(page_object); + pPageObj->m_GeneralState.SetFillAlpha(A / 255.f); + pPageObj->m_ColorState.SetFillColor( + CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB), rgb, 3); + pPageObj->SetDirty(true); + return true; +} + +DLLEXPORT FPDF_BOOL STDCALL FPDFPageObj_GetBounds(FPDF_PAGEOBJECT pageObject, + float* left, + float* bottom, + float* right, + float* top) { + if (!pageObject) + return false; + + CPDF_PageObject* pPageObj = CPDFPageObjectFromFPDFPageObject(pageObject); + CFX_FloatRect bbox = pPageObj->GetRect(); + *left = bbox.left; + *bottom = bbox.bottom; + *right = bbox.right; + *top = bbox.top; + return true; +} diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdfeditpath.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdfeditpath.cpp index 60117cad32b..2181df8406e 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdfeditpath.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdfeditpath.cpp @@ -7,8 +7,25 @@ #include "core/fpdfapi/page/cpdf_path.h" #include "core/fpdfapi/page/cpdf_pathobject.h" #include "core/fxcrt/fx_system.h" +#include "fpdfsdk/fsdk_define.h" #include "third_party/base/ptr_util.h" +// These checks are here because core/ and public/ cannot depend on each other. +static_assert(CFX_GraphStateData::LineCapButt == FPDF_LINECAP_BUTT, + "CFX_GraphStateData::LineCapButt value mismatch"); +static_assert(CFX_GraphStateData::LineCapRound == FPDF_LINECAP_ROUND, + "CFX_GraphStateData::LineCapRound value mismatch"); +static_assert(CFX_GraphStateData::LineCapSquare == + FPDF_LINECAP_PROJECTING_SQUARE, + "CFX_GraphStateData::LineCapSquare value mismatch"); + +static_assert(CFX_GraphStateData::LineJoinMiter == FPDF_LINEJOIN_MITER, + "CFX_GraphStateData::LineJoinMiter value mismatch"); +static_assert(CFX_GraphStateData::LineJoinRound == FPDF_LINEJOIN_ROUND, + "CFX_GraphStateData::LineJoinRound value mismatch"); +static_assert(CFX_GraphStateData::LineJoinBevel == FPDF_LINEJOIN_BEVEL, + "CFX_GraphStateData::LineJoinBevel value mismatch"); + DLLEXPORT FPDF_PAGEOBJECT STDCALL FPDFPageObj_CreateNewPath(float x, float y) { auto pPathObj = pdfium::MakeUnique<CPDF_PathObject>(); pPathObj->m_Path.AppendPoint(CFX_PointF(x, y), FXPT_TYPE::MoveTo, false); @@ -26,56 +43,69 @@ DLLEXPORT FPDF_PAGEOBJECT STDCALL FPDFPageObj_CreateNewRect(float x, return pPathObj.release(); // Caller takes ownership. } -DLLEXPORT FPDF_BOOL FPDFPath_SetStrokeColor(FPDF_PAGEOBJECT path, - unsigned int R, - unsigned int G, - unsigned int B, - unsigned int A) { +DLLEXPORT FPDF_BOOL STDCALL FPDFPath_SetStrokeColor(FPDF_PAGEOBJECT path, + unsigned int R, + unsigned int G, + unsigned int B, + unsigned int A) { if (!path || R > 255 || G > 255 || B > 255 || A > 255) return false; float rgb[3] = {R / 255.f, G / 255.f, B / 255.f}; - auto* pPathObj = static_cast<CPDF_PathObject*>(path); + auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path); pPathObj->m_GeneralState.SetStrokeAlpha(A / 255.f); pPathObj->m_ColorState.SetStrokeColor( CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB), rgb, 3); + pPathObj->SetDirty(true); return true; } -DLLEXPORT FPDF_BOOL FPDFPath_SetStrokeWidth(FPDF_PAGEOBJECT path, float width) { - if (!path || width < 0.0f) +DLLEXPORT FPDF_BOOL STDCALL FPDFPath_GetStrokeColor(FPDF_PAGEOBJECT path, + unsigned int* R, + unsigned int* G, + unsigned int* B, + unsigned int* A) { + if (!path || !R || !G || !B || !A) return false; - auto* pPathObj = static_cast<CPDF_PathObject*>(path); - pPathObj->m_GraphState.SetLineWidth(width); + auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path); + uint32_t strokeRGB = pPathObj->m_ColorState.GetStrokeRGB(); + *R = FXSYS_GetRValue(strokeRGB); + *G = FXSYS_GetGValue(strokeRGB); + *B = FXSYS_GetBValue(strokeRGB); + *A = static_cast<unsigned int>(pPathObj->m_GeneralState.GetStrokeAlpha() * + 255.f); return true; } -DLLEXPORT FPDF_BOOL FPDFPath_SetFillColor(FPDF_PAGEOBJECT path, - unsigned int R, - unsigned int G, - unsigned int B, - unsigned int A) { - if (!path || R > 255 || G > 255 || B > 255 || A > 255) +DLLEXPORT FPDF_BOOL STDCALL FPDFPath_SetStrokeWidth(FPDF_PAGEOBJECT path, + float width) { + if (!path || width < 0.0f) return false; - float rgb[3] = {R / 255.f, G / 255.f, B / 255.f}; - auto* pPathObj = static_cast<CPDF_PathObject*>(path); - pPathObj->m_GeneralState.SetFillAlpha(A / 255.f); - pPathObj->m_ColorState.SetFillColor( - CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB), rgb, 3); + auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path); + pPathObj->m_GraphState.SetLineWidth(width); + pPathObj->SetDirty(true); return true; } -DLLEXPORT FPDF_BOOL FPDFPath_GetFillColor(FPDF_PAGEOBJECT path, - unsigned int* R, - unsigned int* G, - unsigned int* B, - unsigned int* A) { +DLLEXPORT FPDF_BOOL STDCALL FPDFPath_SetFillColor(FPDF_PAGEOBJECT path, + unsigned int R, + unsigned int G, + unsigned int B, + unsigned int A) { + return FPDFPageObj_SetFillColor(path, R, G, B, A); +} + +DLLEXPORT FPDF_BOOL STDCALL FPDFPath_GetFillColor(FPDF_PAGEOBJECT path, + unsigned int* R, + unsigned int* G, + unsigned int* B, + unsigned int* A) { if (!path || !R || !G || !B || !A) return false; - auto* pPathObj = static_cast<CPDF_PathObject*>(path); + auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path); uint32_t fillRGB = pPathObj->m_ColorState.GetFillRGB(); *R = FXSYS_GetRValue(fillRGB); *G = FXSYS_GetGValue(fillRGB); @@ -85,60 +115,68 @@ DLLEXPORT FPDF_BOOL FPDFPath_GetFillColor(FPDF_PAGEOBJECT path, return true; } -DLLEXPORT FPDF_BOOL FPDFPath_MoveTo(FPDF_PAGEOBJECT path, float x, float y) { +DLLEXPORT FPDF_BOOL STDCALL FPDFPath_MoveTo(FPDF_PAGEOBJECT path, + float x, + float y) { if (!path) return false; - auto* pPathObj = static_cast<CPDF_PathObject*>(path); + auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path); pPathObj->m_Path.AppendPoint(CFX_PointF(x, y), FXPT_TYPE::MoveTo, false); + pPathObj->SetDirty(true); return true; } -DLLEXPORT FPDF_BOOL FPDFPath_LineTo(FPDF_PAGEOBJECT path, float x, float y) { +DLLEXPORT FPDF_BOOL STDCALL FPDFPath_LineTo(FPDF_PAGEOBJECT path, + float x, + float y) { if (!path) return false; - auto* pPathObj = static_cast<CPDF_PathObject*>(path); + auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path); pPathObj->m_Path.AppendPoint(CFX_PointF(x, y), FXPT_TYPE::LineTo, false); + pPathObj->SetDirty(true); return true; } -DLLEXPORT FPDF_BOOL FPDFPath_BezierTo(FPDF_PAGEOBJECT path, - float x1, - float y1, - float x2, - float y2, - float x3, - float y3) { +DLLEXPORT FPDF_BOOL STDCALL FPDFPath_BezierTo(FPDF_PAGEOBJECT path, + float x1, + float y1, + float x2, + float y2, + float x3, + float y3) { if (!path) return false; - auto* pPathObj = static_cast<CPDF_PathObject*>(path); + auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path); pPathObj->m_Path.AppendPoint(CFX_PointF(x1, y1), FXPT_TYPE::BezierTo, false); pPathObj->m_Path.AppendPoint(CFX_PointF(x2, y2), FXPT_TYPE::BezierTo, false); pPathObj->m_Path.AppendPoint(CFX_PointF(x3, y3), FXPT_TYPE::BezierTo, false); + pPathObj->SetDirty(true); return true; } -DLLEXPORT FPDF_BOOL FPDFPath_Close(FPDF_PAGEOBJECT path) { +DLLEXPORT FPDF_BOOL STDCALL FPDFPath_Close(FPDF_PAGEOBJECT path) { if (!path) return false; - auto* pPathObj = static_cast<CPDF_PathObject*>(path); + auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path); if (pPathObj->m_Path.GetPoints().empty()) return false; pPathObj->m_Path.ClosePath(); + pPathObj->SetDirty(true); return true; } -DLLEXPORT FPDF_BOOL FPDFPath_SetDrawMode(FPDF_PAGEOBJECT path, - int fillmode, - FPDF_BOOL stroke) { +DLLEXPORT FPDF_BOOL STDCALL FPDFPath_SetDrawMode(FPDF_PAGEOBJECT path, + int fillmode, + FPDF_BOOL stroke) { if (!path) return false; - auto* pPathObj = static_cast<CPDF_PathObject*>(path); + auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path); if (fillmode == FPDF_FILLMODE_ALTERNATE) pPathObj->m_FillType = FXFILL_ALTERNATE; @@ -147,5 +185,37 @@ DLLEXPORT FPDF_BOOL FPDFPath_SetDrawMode(FPDF_PAGEOBJECT path, else pPathObj->m_FillType = 0; pPathObj->m_bStroke = stroke != 0; + pPathObj->SetDirty(true); return true; } + +DLLEXPORT void STDCALL FPDFPath_SetLineJoin(FPDF_PAGEOBJECT path, + int line_join) { + if (!path) + return; + if (line_join < + static_cast<int>(CFX_GraphStateData::LineJoin::LineJoinMiter) || + line_join > + static_cast<int>(CFX_GraphStateData::LineJoin::LineJoinBevel)) { + return; + } + auto* pPathObj = CPDFPageObjectFromFPDFPageObject(path); + CFX_GraphStateData::LineJoin lineJoin = + static_cast<CFX_GraphStateData::LineJoin>(line_join); + pPathObj->m_GraphState.SetLineJoin(lineJoin); + pPathObj->SetDirty(true); +} + +DLLEXPORT void STDCALL FPDFPath_SetLineCap(FPDF_PAGEOBJECT path, int line_cap) { + if (!path) + return; + if (line_cap < static_cast<int>(CFX_GraphStateData::LineCap::LineCapButt) || + line_cap > static_cast<int>(CFX_GraphStateData::LineCap::LineCapSquare)) { + return; + } + auto* pPathObj = CPDFPageObjectFromFPDFPageObject(path); + CFX_GraphStateData::LineCap lineCap = + static_cast<CFX_GraphStateData::LineCap>(line_cap); + pPathObj->m_GraphState.SetLineCap(lineCap); + pPathObj->SetDirty(true); +} diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdfedittext.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdfedittext.cpp index 2dde2e66245..02bf722462c 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdfedittext.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdfedittext.cpp @@ -98,24 +98,27 @@ const char ToUnicodeEnd[] = "end\n" "end\n"; -void AddCharcode(CFX_ByteTextBuf* pBuffer, uint32_t number) { +void AddCharcode(std::ostringstream* pBuffer, uint32_t number) { ASSERT(number <= 0xFFFF); *pBuffer << "<"; char ans[4]; FXSYS_IntToFourHexChars(number, ans); for (size_t i = 0; i < 4; ++i) - pBuffer->AppendChar(ans[i]); + *pBuffer << ans[i]; *pBuffer << ">"; } // PDF spec 1.7 Section 5.9.2: "Unicode character sequences as expressed in // UTF-16BE encoding." See https://en.wikipedia.org/wiki/UTF-16#Description -void AddUnicode(CFX_ByteTextBuf* pBuffer, uint32_t unicode) { +void AddUnicode(std::ostringstream* pBuffer, uint32_t unicode) { + if (unicode >= 0xD800 && unicode <= 0xDFFF) + unicode = 0; + char ans[8]; *pBuffer << "<"; size_t numChars = FXSYS_ToUTF16BE(unicode, ans); for (size_t i = 0; i < numChars; ++i) - pBuffer->AppendChar(ans[i]); + *pBuffer << ans[i]; *pBuffer << ">"; } @@ -184,7 +187,7 @@ CPDF_Stream* LoadUnicode(CPDF_Document* pDoc, } map_range[std::make_pair(firstCharcode, curCharcode)] = firstUnicode; } - CFX_ByteTextBuf buffer; + std::ostringstream buffer; buffer << ToUnicodeStart; // Add maps to buffer buffer << static_cast<uint32_t>(char_to_uni.size()) << " beginbfchar\n"; @@ -224,13 +227,13 @@ CPDF_Stream* LoadUnicode(CPDF_Document* pDoc, buffer << "endbfrange\n"; buffer << ToUnicodeEnd; // TODO(npm): Encrypt / Compress? - uint32_t bufferSize = buffer.GetSize(); - auto pDict = pdfium::MakeUnique<CPDF_Dictionary>(); - pDict->SetNewFor<CPDF_Number>("Length", static_cast<int>(bufferSize)); - return pDoc->NewIndirect<CPDF_Stream>(buffer.DetachBuffer(), bufferSize, - std::move(pDict)); + CPDF_Stream* stream = pDoc->NewIndirect<CPDF_Stream>(); + stream->SetData(&buffer); + return stream; } +const uint32_t kMaxSimpleFontChar = 0xFF; + void* LoadSimpleFont(CPDF_Document* pDoc, std::unique_ptr<CFX_Font> pFont, const uint8_t* data, @@ -246,21 +249,23 @@ void* LoadSimpleFont(CPDF_Document* pDoc, fontDict->SetNewFor<CPDF_Name>("BaseFont", name); uint32_t glyphIndex; - int currentChar = FXFT_Get_First_Char(pFont->GetFace(), &glyphIndex); - fontDict->SetNewFor<CPDF_Number>("FirstChar", currentChar); + uint32_t currentChar = FXFT_Get_First_Char(pFont->GetFace(), &glyphIndex); + if (currentChar > kMaxSimpleFontChar || glyphIndex == 0) + return nullptr; + fontDict->SetNewFor<CPDF_Number>("FirstChar", static_cast<int>(currentChar)); CPDF_Array* widthsArray = pDoc->NewIndirect<CPDF_Array>(); while (true) { widthsArray->AddNew<CPDF_Number>(pFont->GetGlyphWidth(glyphIndex)); - int nextChar = + uint32_t nextChar = FXFT_Get_Next_Char(pFont->GetFace(), currentChar, &glyphIndex); // Simple fonts have 1-byte charcodes only. - if (nextChar > 0xff || glyphIndex == 0) + if (nextChar > kMaxSimpleFontChar || glyphIndex == 0) break; - for (int i = currentChar + 1; i < nextChar; i++) + for (uint32_t i = currentChar + 1; i < nextChar; i++) widthsArray->AddNew<CPDF_Number>(0); currentChar = nextChar; } - fontDict->SetNewFor<CPDF_Number>("LastChar", currentChar); + fontDict->SetNewFor<CPDF_Number>("LastChar", static_cast<int>(currentChar)); fontDict->SetNewFor<CPDF_Reference>("Widths", pDoc, widthsArray->GetObjNum()); CPDF_Dictionary* fontDesc = LoadFontDesc(pDoc, name, pFont.get(), data, size, font_type); @@ -270,6 +275,8 @@ void* LoadSimpleFont(CPDF_Document* pDoc, return pDoc->LoadFont(fontDict); } +const uint32_t kMaxUnicode = 0x10FFFF; + void* LoadCompositeFont(CPDF_Document* pDoc, std::unique_ptr<CFX_Font> pFont, const uint8_t* data, @@ -309,15 +316,15 @@ void* LoadCompositeFont(CPDF_Document* pDoc, fontDesc->GetObjNum()); uint32_t glyphIndex; - int currentChar = FXFT_Get_First_Char(pFont->GetFace(), &glyphIndex); + uint32_t currentChar = FXFT_Get_First_Char(pFont->GetFace(), &glyphIndex); // If it doesn't have a single char, just fail - if (glyphIndex == 0) + if (glyphIndex == 0 || currentChar > kMaxUnicode) return nullptr; std::map<uint32_t, uint32_t> to_unicode; std::map<uint32_t, uint32_t> widths; while (true) { - if (currentChar > 0x10FFFF) + if (currentChar > kMaxUnicode) break; widths[glyphIndex] = pFont->GetGlyphWidth(glyphIndex); @@ -447,6 +454,14 @@ DLLEXPORT FPDF_FONT STDCALL FPDFText_LoadFont(FPDF_DOCUMENT document, : LoadSimpleFont(pDoc, std::move(pFont), data, size, font_type); } +DLLEXPORT FPDF_BOOL STDCALL FPDFText_SetFillColor(FPDF_PAGEOBJECT text_object, + unsigned int R, + unsigned int G, + unsigned int B, + unsigned int A) { + return FPDFPageObj_SetFillColor(text_object, R, G, B, A); +} + DLLEXPORT void STDCALL FPDFFont_Close(FPDF_FONT font) { CPDF_Font* pFont = static_cast<CPDF_Font*>(font); if (!pFont) diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdfformfill.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdfformfill.cpp index fb12967bde0..24cd64efa1a 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdfformfill.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdfformfill.cpp @@ -126,12 +126,9 @@ void FFLCommon(FPDF_FORMHANDLE hHandle, options.m_Flags &= ~RENDER_CLEARTYPE; // Grayscale output - if (flags & FPDF_GRAYSCALE) { - options.m_ColorMode = RENDER_COLOR_GRAY; - options.m_ForeColor = 0; - options.m_BackColor = 0xffffff; - } - options.m_AddFlags = flags >> 8; + if (flags & FPDF_GRAYSCALE) + options.m_ColorMode = CPDF_RenderOptions::kGray; + options.m_bDrawAnnots = flags & FPDF_ANNOT; #ifdef PDF_ENABLE_XFA @@ -201,11 +198,7 @@ DLLEXPORT int STDCALL FPDFPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle, CFX_RectF rcBBox = pXFAAnnot->GetBBox(0); CFX_FloatRect rcWidget(rcBBox.left, rcBBox.top, rcBBox.left + rcBBox.width, rcBBox.top + rcBBox.height); - rcWidget.left -= 1.0f; - rcWidget.right += 1.0f; - rcWidget.bottom -= 1.0f; - rcWidget.top += 1.0f; - + rcWidget.Inflate(1.0f, 1.0f); if (rcWidget.Contains(CFX_PointF(static_cast<float>(page_x), static_cast<float>(page_y)))) { return FPDF_FORMFIELD_XFA; @@ -216,13 +209,6 @@ DLLEXPORT int STDCALL FPDFPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle, return -1; } -DLLEXPORT int STDCALL FPDPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle, - FPDF_PAGE page, - double page_x, - double page_y) { - return FPDFPage_HasFormFieldAtPoint(hHandle, page, page_x, page_y); -} - DLLEXPORT int STDCALL FPDFPage_FormFieldZOrderAtPoint(FPDF_FORMHANDLE hHandle, FPDF_PAGE page, double page_x, @@ -275,11 +261,10 @@ FPDFDOC_InitFormFillEnvironment(FPDF_DOCUMENT document, DLLEXPORT void STDCALL FPDFDOC_ExitFormFillEnvironment(FPDF_FORMHANDLE hHandle) { - if (!hHandle) - return; - CPDFSDK_FormFillEnvironment* pFormFillEnv = HandleToCPDFSDKEnvironment(hHandle); + if (!pFormFillEnv) + return; #ifdef PDF_ENABLE_XFA // Reset the focused annotations and remove the SDK document from the @@ -290,7 +275,6 @@ FPDFDOC_ExitFormFillEnvironment(FPDF_FORMHANDLE hHandle) { if (pFormFillEnv->GetXFAContext()) pFormFillEnv->GetXFAContext()->SetFormFillEnv(nullptr); #endif // PDF_ENABLE_XFA - delete pFormFillEnv; } @@ -324,9 +308,7 @@ DLLEXPORT FPDF_BOOL STDCALL FORM_OnLButtonUp(FPDF_FORMHANDLE hHandle, CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); if (!pPageView) return false; - - CFX_PointF pt((float)page_x, (float)page_y); - return pPageView->OnLButtonUp(pt, modifier); + return pPageView->OnLButtonUp(CFX_PointF(page_x, page_y), modifier); } #ifdef PDF_ENABLE_XFA @@ -349,9 +331,7 @@ DLLEXPORT FPDF_BOOL STDCALL FORM_OnRButtonUp(FPDF_FORMHANDLE hHandle, CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); if (!pPageView) return false; - - CFX_PointF pt((float)page_x, (float)page_y); - return pPageView->OnRButtonUp(pt, modifier); + return pPageView->OnRButtonUp(CFX_PointF(page_x, page_y), modifier); } #endif // PDF_ENABLE_XFA @@ -362,7 +342,6 @@ DLLEXPORT FPDF_BOOL STDCALL FORM_OnKeyDown(FPDF_FORMHANDLE hHandle, CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); if (!pPageView) return false; - return pPageView->OnKeyDown(nKeyCode, modifier); } @@ -373,7 +352,6 @@ DLLEXPORT FPDF_BOOL STDCALL FORM_OnKeyUp(FPDF_FORMHANDLE hHandle, CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); if (!pPageView) return false; - return pPageView->OnKeyUp(nKeyCode, modifier); } @@ -384,10 +362,27 @@ DLLEXPORT FPDF_BOOL STDCALL FORM_OnChar(FPDF_FORMHANDLE hHandle, CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); if (!pPageView) return false; - return pPageView->OnChar(nChar, modifier); } +DLLEXPORT unsigned long STDCALL FORM_GetSelectedText(FPDF_FORMHANDLE hHandle, + FPDF_PAGE page, + void* buffer, + unsigned long buflen) { + CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); + if (!pPageView) + return 0; + + CFX_WideString wide_str_form_text = pPageView->GetSelectedText(); + CFX_ByteString encoded_form_text = wide_str_form_text.UTF16LE_Encode(); + unsigned long form_text_len = encoded_form_text.GetLength(); + + if (buffer && buflen >= form_text_len) + memcpy(buffer, encoded_form_text.c_str(), form_text_len); + + return form_text_len; +} + DLLEXPORT FPDF_BOOL STDCALL FORM_ForceToKillFocus(FPDF_FORMHANDLE hHandle) { CPDFSDK_FormFillEnvironment* pFormFillEnv = HandleToCPDFSDKEnvironment(hHandle); @@ -665,9 +660,6 @@ DLLEXPORT void STDCALL FORM_OnAfterLoadPage(FPDF_PAGE page, DLLEXPORT void STDCALL FORM_OnBeforeClosePage(FPDF_PAGE page, FPDF_FORMHANDLE hHandle) { - if (!hHandle) - return; - CPDFSDK_FormFillEnvironment* pFormFillEnv = HandleToCPDFSDKEnvironment(hHandle); if (!pFormFillEnv) @@ -707,26 +699,23 @@ DLLEXPORT void STDCALL FORM_DoDocumentAAction(FPDF_FORMHANDLE hHandle, return; CPDF_Document* pDoc = pFormFillEnv->GetPDFDocument(); - CPDF_Dictionary* pDic = pDoc->GetRoot(); - if (!pDic) + CPDF_Dictionary* pDict = pDoc->GetRoot(); + if (!pDict) return; - CPDF_AAction aa(pDic->GetDictFor("AA")); - if (aa.ActionExist((CPDF_AAction::AActionType)aaType)) { - CPDF_Action action = aa.GetAction((CPDF_AAction::AActionType)aaType); + CPDF_AAction aa(pDict->GetDictFor("AA")); + auto type = static_cast<CPDF_AAction::AActionType>(aaType); + if (aa.ActionExist(type)) { + CPDF_Action action = aa.GetAction(type); CPDFSDK_ActionHandler* pActionHandler = - HandleToCPDFSDKEnvironment(hHandle)->GetActionHander(); - pActionHandler->DoAction_Document(action, (CPDF_AAction::AActionType)aaType, - pFormFillEnv); + HandleToCPDFSDKEnvironment(hHandle)->GetActionHandler(); + pActionHandler->DoAction_Document(action, type, pFormFillEnv); } } DLLEXPORT void STDCALL FORM_DoPageAAction(FPDF_PAGE page, FPDF_FORMHANDLE hHandle, int aaType) { - if (!hHandle) - return; - CPDFSDK_FormFillEnvironment* pFormFillEnv = HandleToCPDFSDKEnvironment(hHandle); if (!pFormFillEnv) @@ -740,20 +729,14 @@ DLLEXPORT void STDCALL FORM_DoPageAAction(FPDF_PAGE page, if (!pFormFillEnv->GetPageView(pPage, false)) return; - CPDFSDK_ActionHandler* pActionHandler = pFormFillEnv->GetActionHander(); + CPDFSDK_ActionHandler* pActionHandler = pFormFillEnv->GetActionHandler(); CPDF_Dictionary* pPageDict = pPDFPage->m_pFormDict.Get(); CPDF_AAction aa(pPageDict->GetDictFor("AA")); - if (FPDFPAGE_AACTION_OPEN == aaType) { - if (aa.ActionExist(CPDF_AAction::OpenPage)) { - CPDF_Action action = aa.GetAction(CPDF_AAction::OpenPage); - pActionHandler->DoAction_Page(action, CPDF_AAction::OpenPage, - pFormFillEnv); - } - } else { - if (aa.ActionExist(CPDF_AAction::ClosePage)) { - CPDF_Action action = aa.GetAction(CPDF_AAction::ClosePage); - pActionHandler->DoAction_Page(action, CPDF_AAction::ClosePage, - pFormFillEnv); - } + CPDF_AAction::AActionType type = aaType == FPDFPAGE_AACTION_OPEN + ? CPDF_AAction::OpenPage + : CPDF_AAction::ClosePage; + if (aa.ActionExist(type)) { + CPDF_Action action = aa.GetAction(type); + pActionHandler->DoAction_Page(action, type, pFormFillEnv); } } diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdfformfill_embeddertest.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdfformfill_embeddertest.cpp index 631a6a2e7c1..70899276b3c 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdfformfill_embeddertest.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdfformfill_embeddertest.cpp @@ -4,10 +4,13 @@ #include <memory> #include <string> +#include <vector> +#include "core/fxcrt/fx_string.h" #include "core/fxcrt/fx_system.h" #include "public/cpp/fpdf_deleters.h" #include "public/fpdf_formfill.h" +#include "public/fpdf_fwlevent.h" #include "testing/embedder_test.h" #include "testing/embedder_test_mock_delegate.h" #include "testing/embedder_test_timer_handling_delegate.h" @@ -17,7 +20,109 @@ using testing::_; using testing::Return; -class FPDFFormFillEmbeddertest : public EmbedderTest, public TestSaver {}; +class FPDFFormFillEmbeddertest : public EmbedderTest { + protected: + void TypeTextIntoTextfield(FPDF_PAGE page, + int num_chars, + int form_type, + double x, + double y) { + ASSERT(form_type == FPDF_FORMFIELD_COMBOBOX || + form_type == FPDF_FORMFIELD_TEXTFIELD); + EXPECT_EQ(form_type, + FPDFPage_HasFormFieldAtPoint(form_handle(), page, x, y)); + + // Click on the textfield or combobox text field as specified by + // coordinates. + FORM_OnMouseMove(form_handle(), page, 0, x, y); + FORM_OnLButtonDown(form_handle(), page, 0, x, y); + FORM_OnLButtonUp(form_handle(), page, 0, x, y); + + // Type text starting with 'A' to as many chars as specified by |num_chars|. + for (int i = 0; i < num_chars; ++i) { + FORM_OnChar(form_handle(), page, 'A' + i, 0); + } + } + + // Navigates to text field using the mouse and then selects text via the + // shift and specfied left or right arrow key. + void SelectTextWithKeyboard(FPDF_PAGE page, + int num_chars, + int arrow_key, + double x, + double y) { + // Navigate to starting position for selection. + FORM_OnMouseMove(form_handle(), page, 0, x, y); + FORM_OnLButtonDown(form_handle(), page, 0, x, y); + FORM_OnLButtonUp(form_handle(), page, 0, x, y); + + // Hold down shift (and don't release until entire text is selected). + FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Shift, 0); + + // Select text char by char via left or right arrow key. + for (int i = 0; i < num_chars; ++i) { + FORM_OnKeyDown(form_handle(), page, arrow_key, FWL_EVENTFLAG_ShiftKey); + FORM_OnKeyUp(form_handle(), page, arrow_key, FWL_EVENTFLAG_ShiftKey); + } + FORM_OnKeyUp(form_handle(), page, FWL_VKEY_Shift, 0); + } + + // Uses the mouse to navigate to text field and select text. + void SelectTextWithMouse(FPDF_PAGE page, + double start_x, + double end_x, + double y) { + // Navigate to starting position and click mouse. + FORM_OnMouseMove(form_handle(), page, 0, start_x, y); + FORM_OnLButtonDown(form_handle(), page, 0, start_x, y); + + // Hold down mouse until reach end of desired selection. + FORM_OnMouseMove(form_handle(), page, 0, end_x, y); + FORM_OnLButtonUp(form_handle(), page, 0, end_x, y); + } + + void CheckSelection(FPDF_PAGE page, const CFX_WideString& expected_string) { + // Calculate expected length for selected text. + int num_chars = expected_string.GetLength(); + + // Check actual selection against expected selection. + const unsigned long expected_length = + sizeof(unsigned short) * (num_chars + 1); + unsigned long sel_text_len = + FORM_GetSelectedText(form_handle(), page, nullptr, 0); + ASSERT_EQ(expected_length, sel_text_len); + + std::vector<unsigned short> buf(sel_text_len); + EXPECT_EQ(expected_length, FORM_GetSelectedText(form_handle(), page, + buf.data(), sel_text_len)); + + EXPECT_EQ(expected_string, + CFX_WideString::FromUTF16LE(buf.data(), num_chars)); + } + + // Selects one of the pre-selected values from a combobox with three options. + // Options are specified by |item_index|, which is 0-based. + void SelectOption(FPDF_PAGE page, int32_t item_index, double x, double y) { + // Only relevant for comboboxes with three choices and the same dimensions + // as those in combobox_form.pdf. + ASSERT(item_index >= 0); + ASSERT(item_index < 3); + + // Navigate to button for drop down and click mouse to reveal options. + FORM_OnMouseMove(form_handle(), page, 0, x, y); + FORM_OnLButtonDown(form_handle(), page, 0, x, y); + FORM_OnLButtonUp(form_handle(), page, 0, x, y); + + // Y coordinate of dropdown option to be selected. + constexpr double kChoiceHeight = 15; + double option_y = y - kChoiceHeight * (item_index + 1); + + // Navigate to option and click mouse to select it. + FORM_OnMouseMove(form_handle(), page, 0, x, option_y); + FORM_OnLButtonDown(form_handle(), page, 0, x, option_y); + FORM_OnLButtonUp(form_handle(), page, 0, x, option_y); + } +}; TEST_F(FPDFFormFillEmbeddertest, FirstTest) { EmbedderTestMockDelegate mock; @@ -201,6 +306,24 @@ TEST_F(FPDFFormFillEmbeddertest, BUG_679649) { EXPECT_EQ(0u, alerts.size()); } +TEST_F(FPDFFormFillEmbeddertest, BUG_707673) { + EmbedderTestTimerHandlingDelegate delegate; + SetDelegate(&delegate); + + EXPECT_TRUE(OpenDocument("bug_707673.pdf")); + FPDF_PAGE page = LoadPage(0); + EXPECT_TRUE(page); + + DoOpenActions(); + FORM_OnLButtonDown(form_handle(), page, 0, 140, 590); + FORM_OnLButtonUp(form_handle(), page, 0, 140, 590); + delegate.AdvanceTime(1000); + UnloadPage(page); + + const auto& alerts = delegate.GetAlerts(); + EXPECT_EQ(0u, alerts.size()); +} + #endif // PDF_ENABLE_V8 TEST_F(FPDFFormFillEmbeddertest, FormText) { @@ -209,9 +332,9 @@ TEST_F(FPDFFormFillEmbeddertest, FormText) { const char md5_2[] = "35b1a4b679eafc749a0b6fda750c0e8d"; const char md5_3[] = "65c64a7c355388f719a752aa1e23f6fe"; #else - const char md5_1[] = "23baecc6e94d4c8b894cd39aa04c584c"; - const char md5_2[] = "499df95d477dfe35ee65b823c69743b5"; - const char md5_3[] = "8f91b62895fc505d9e17ff2d633756d4"; + const char md5_1[] = "a5e3ac74c2ee123ec6710e2f0ef8424a"; + const char md5_2[] = "4526b09382e144d5506ad92149399de6"; + const char md5_3[] = "80356067d860088864cf50ff85d8459e"; #endif { EXPECT_TRUE(OpenDocument("text_form.pdf")); @@ -243,24 +366,283 @@ TEST_F(FPDFFormFillEmbeddertest, FormText) { EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); - // Close everything + // Close page UnloadPage(page); - FPDFDOC_ExitFormFillEnvironment(form_handle_); - FPDF_CloseDocument(document_); } // Check saved document - std::string new_file = GetString(); - FPDF_FILEACCESS file_access; - memset(&file_access, 0, sizeof(file_access)); - file_access.m_FileLen = new_file.size(); - file_access.m_GetBlock = GetBlockFromString; - file_access.m_Param = &new_file; - document_ = FPDF_LoadCustomDocument(&file_access, nullptr); - SetupFormFillEnvironment(); - EXPECT_EQ(1, FPDF_GetPageCount(document_)); - std::unique_ptr<void, FPDFPageDeleter> new_page(FPDF_LoadPage(document_, 0)); - ASSERT_TRUE(new_page.get()); - std::unique_ptr<void, FPDFBitmapDeleter> new_bitmap( - RenderPage(new_page.get())); - CompareBitmap(new_bitmap.get(), 300, 300, md5_3); + TestAndCloseSaved(300, 300, md5_3); +} + +TEST_F(FPDFFormFillEmbeddertest, GetSelectedTextEmptyAndBasicKeyboard) { + // Open file with form text field. + EXPECT_TRUE(OpenDocument("text_form.pdf")); + FPDF_PAGE page = LoadPage(0); + ASSERT_TRUE(page); + + // Test empty selection. + CheckSelection(page, CFX_WideString(L"")); + + // Test basic selection. + TypeTextIntoTextfield(page, 3, FPDF_FORMFIELD_TEXTFIELD, 120.0, 120.0); + SelectTextWithKeyboard(page, 3, FWL_VKEY_Left, 123.0, 115.5); + CheckSelection(page, CFX_WideString(L"ABC")); + + UnloadPage(page); +} + +TEST_F(FPDFFormFillEmbeddertest, GetSelectedTextEmptyAndBasicMouse) { + // Open file with form text field. + EXPECT_TRUE(OpenDocument("text_form.pdf")); + FPDF_PAGE page = LoadPage(0); + ASSERT_TRUE(page); + + // Test empty selection. + CheckSelection(page, CFX_WideString(L"")); + + // Test basic selection. + TypeTextIntoTextfield(page, 3, FPDF_FORMFIELD_TEXTFIELD, 120.0, 120.0); + SelectTextWithMouse(page, 125.0, 102.0, 115.5); + CheckSelection(page, CFX_WideString(L"ABC")); + + UnloadPage(page); +} + +TEST_F(FPDFFormFillEmbeddertest, GetSelectedTextFragmentsKeyBoard) { + // Open file with form text field. + EXPECT_TRUE(OpenDocument("text_form.pdf")); + FPDF_PAGE page = LoadPage(0); + ASSERT_TRUE(page); + + TypeTextIntoTextfield(page, 12, FPDF_FORMFIELD_TEXTFIELD, 120.0, 120.0); + + // Test selecting first character in forward direction. + SelectTextWithKeyboard(page, 1, FWL_VKEY_Right, 102.0, 115.5); + CheckSelection(page, CFX_WideString(L"A")); + + // Test selecting entire long string in backwards direction. + SelectTextWithKeyboard(page, 12, FWL_VKEY_Left, 191.0, 115.5); + CheckSelection(page, CFX_WideString(L"ABCDEFGHIJKL")); + + // Test selecting middle section in backwards direction. + SelectTextWithKeyboard(page, 6, FWL_VKEY_Left, 170.0, 115.5); + CheckSelection(page, CFX_WideString(L"DEFGHI")); + + // Test selecting middle selection in forward direction. + SelectTextWithKeyboard(page, 6, FWL_VKEY_Right, 125.0, 115.5); + CheckSelection(page, CFX_WideString(L"DEFGHI")); + + // Test selecting last character in backwards direction. + SelectTextWithKeyboard(page, 1, FWL_VKEY_Left, 191.0, 115.5); + CheckSelection(page, CFX_WideString(L"L")); + + UnloadPage(page); +} + +TEST_F(FPDFFormFillEmbeddertest, GetSelectedTextFragmentsMouse) { + // Open file with form text field. + EXPECT_TRUE(OpenDocument("text_form.pdf")); + FPDF_PAGE page = LoadPage(0); + ASSERT_TRUE(page); + + TypeTextIntoTextfield(page, 12, FPDF_FORMFIELD_TEXTFIELD, 120.0, 120.0); + + // Test selecting first character in forward direction. + SelectTextWithMouse(page, 102.0, 106.0, 115.5); + CheckSelection(page, CFX_WideString(L"A")); + + // Test selecting entire long string in backwards direction. + SelectTextWithMouse(page, 191.0, 102.0, 115.5); + CheckSelection(page, CFX_WideString(L"ABCDEFGHIJKL")); + + // Test selecting middle section in backwards direction. + SelectTextWithMouse(page, 170.0, 125.0, 115.5); + CheckSelection(page, CFX_WideString(L"DEFGHI")); + + // Test selecting middle selection in forward direction. + SelectTextWithMouse(page, 125.0, 170.0, 115.5); + CheckSelection(page, CFX_WideString(L"DEFGHI")); + + // Test selecting last character in backwards direction. + SelectTextWithMouse(page, 191.0, 186.0, 115.5); + CheckSelection(page, CFX_WideString(L"L")); + + UnloadPage(page); +} + +TEST_F(FPDFFormFillEmbeddertest, GetSelectedTextEmptyAndBasicNormalComboBox) { + // Open file with form comboboxes. + EXPECT_TRUE(OpenDocument("combobox_form.pdf")); + FPDF_PAGE page = LoadPage(0); + ASSERT_TRUE(page); + + // Test empty selection. + CheckSelection(page, CFX_WideString(L"")); + + // Test basic selection of text within normal, non-editable combobox. + // Click on normal combobox text field. + EXPECT_EQ(FPDF_FORMFIELD_COMBOBOX, + FPDFPage_HasFormFieldAtPoint(form_handle(), page, 102.0, 113.0)); + + // Non-editable comboboxes don't allow selection with keyboard. + SelectTextWithMouse(page, 102.0, 142.0, 113.0); + CheckSelection(page, CFX_WideString(L"Banana")); + + // Select other another provided option. + SelectOption(page, 0, 192.0, 110.0); + CheckSelection(page, CFX_WideString(L"Apple")); + + UnloadPage(page); +} + +TEST_F(FPDFFormFillEmbeddertest, + GetSelectedTextEmptyAndBasicEditableComboBoxKeyboard) { + // Open file with form comboboxes. + EXPECT_TRUE(OpenDocument("combobox_form.pdf")); + FPDF_PAGE page = LoadPage(0); + ASSERT_TRUE(page); + + // Test empty selection. + CheckSelection(page, CFX_WideString(L"")); + + // Test basic selection of text within user editable combobox using keyboard. + TypeTextIntoTextfield(page, 3, FPDF_FORMFIELD_COMBOBOX, 102.0, 62.0); + SelectTextWithKeyboard(page, 3, FWL_VKEY_Left, 128.0, 63.0); + CheckSelection(page, CFX_WideString(L"ABC")); + + // Select a provided option. + SelectOption(page, 1, 192.0, 60.0); + CheckSelection(page, CFX_WideString(L"Bar")); + + UnloadPage(page); +} + +TEST_F(FPDFFormFillEmbeddertest, + GetSelectedTextEmptyAndBasicEditableComboBoxMouse) { + // Open file with form comboboxes. + EXPECT_TRUE(OpenDocument("combobox_form.pdf")); + FPDF_PAGE page = LoadPage(0); + ASSERT_TRUE(page); + + // Test empty selection. + CheckSelection(page, CFX_WideString(L"")); + + // Test basic selection of text within user editable combobox using mouse. + TypeTextIntoTextfield(page, 3, FPDF_FORMFIELD_COMBOBOX, 102.0, 62.0); + SelectTextWithMouse(page, 128.0, 103.0, 63.0); + CheckSelection(page, CFX_WideString(L"ABC")); + + // Select a provided option. + SelectOption(page, 2, 192.0, 60.0); + CheckSelection(page, CFX_WideString(L"Qux")); + + UnloadPage(page); +} + +TEST_F(FPDFFormFillEmbeddertest, GetSelectedTextFragmentsNormalComboBox) { + // Open file with form comboboxes. + EXPECT_TRUE(OpenDocument("combobox_form.pdf")); + FPDF_PAGE page = LoadPage(0); + ASSERT_TRUE(page); + + // Click on normal combobox text field. + EXPECT_EQ(FPDF_FORMFIELD_COMBOBOX, + FPDFPage_HasFormFieldAtPoint(form_handle(), page, 102.0, 113.0)); + + // Test selecting first character in forward direction. + SelectTextWithMouse(page, 102.0, 107.0, 113.0); + CheckSelection(page, CFX_WideString(L"B")); + + // Test selecting entire string in backwards direction. + SelectTextWithMouse(page, 142.0, 102.0, 113.0); + CheckSelection(page, CFX_WideString(L"Banana")); + + // Test selecting middle section in backwards direction. + SelectTextWithMouse(page, 135.0, 117.0, 113.0); + CheckSelection(page, CFX_WideString(L"nan")); + + // Test selecting middle section in forward direction. + SelectTextWithMouse(page, 117.0, 135.0, 113.0); + CheckSelection(page, CFX_WideString(L"nan")); + + // Test selecting last character in backwards direction. + SelectTextWithMouse(page, 142.0, 138.0, 113.0); + CheckSelection(page, CFX_WideString(L"a")); + + // Select another option and then reset selection as first three chars. + SelectOption(page, 2, 192.0, 110.0); + CheckSelection(page, CFX_WideString(L"Cherry")); + SelectTextWithMouse(page, 102.0, 122.0, 113.0); + CheckSelection(page, CFX_WideString(L"Che")); + + UnloadPage(page); +} + +TEST_F(FPDFFormFillEmbeddertest, + GetSelectedTextFragmentsEditableComboBoxKeyboard) { + // Open file with form comboboxes. + EXPECT_TRUE(OpenDocument("combobox_form.pdf")); + FPDF_PAGE page = LoadPage(0); + ASSERT_TRUE(page); + + TypeTextIntoTextfield(page, 10, FPDF_FORMFIELD_COMBOBOX, 102.0, 62.0); + + // Test selecting first character in forward direction. + SelectTextWithKeyboard(page, 1, FWL_VKEY_Right, 102.0, 63.0); + CheckSelection(page, CFX_WideString(L"A")); + + // Test selecting entire long string in backwards direction. + SelectTextWithKeyboard(page, 10, FWL_VKEY_Left, 178.0, 63.0); + CheckSelection(page, CFX_WideString(L"ABCDEFGHIJ")); + + // Test selecting middle section in backwards direction. + SelectTextWithKeyboard(page, 5, FWL_VKEY_Left, 168.0, 63.0); + CheckSelection(page, CFX_WideString(L"DEFGH")); + + // Test selecting middle selection in forward direction. + SelectTextWithKeyboard(page, 5, FWL_VKEY_Right, 127.0, 63.0); + CheckSelection(page, CFX_WideString(L"DEFGH")); + + // Test selecting last character in backwards direction. + SelectTextWithKeyboard(page, 1, FWL_VKEY_Left, 178.0, 63.0); + CheckSelection(page, CFX_WideString(L"J")); + + // Select a provided option and then reset selection as first two chars. + SelectOption(page, 0, 192.0, 60.0); + CheckSelection(page, CFX_WideString(L"Foo")); + SelectTextWithKeyboard(page, 2, FWL_VKEY_Right, 102.0, 63.0); + CheckSelection(page, CFX_WideString(L"Fo")); + + UnloadPage(page); +} + +TEST_F(FPDFFormFillEmbeddertest, + GetSelectedTextFragmentsEditableComboBoxMouse) { + // Open file with form comboboxes. + EXPECT_TRUE(OpenDocument("combobox_form.pdf")); + FPDF_PAGE page = LoadPage(0); + ASSERT_TRUE(page); + + TypeTextIntoTextfield(page, 10, FPDF_FORMFIELD_COMBOBOX, 102.0, 62.0); + + // Test selecting first character in forward direction. + SelectTextWithMouse(page, 102.0, 107.0, 63.0); + CheckSelection(page, CFX_WideString(L"A")); + + // Test selecting entire long string in backwards direction. + SelectTextWithMouse(page, 178.0, 102.0, 63.0); + CheckSelection(page, CFX_WideString(L"ABCDEFGHIJ")); + + // Test selecting middle section in backwards direction. + SelectTextWithMouse(page, 168.0, 127.0, 63.0); + CheckSelection(page, CFX_WideString(L"DEFGH")); + + // Test selecting middle selection in forward direction. + SelectTextWithMouse(page, 127.0, 168.0, 63.0); + CheckSelection(page, CFX_WideString(L"DEFGH")); + + // Test selecting last character in backwards direction. + SelectTextWithMouse(page, 178.0, 174.0, 63.0); + CheckSelection(page, CFX_WideString(L"J")); + + UnloadPage(page); } diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdfppo_embeddertest.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdfppo_embeddertest.cpp index 7e6ff33fc3c..b6b9167f10f 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdfppo_embeddertest.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdfppo_embeddertest.cpp @@ -6,6 +6,7 @@ #include "core/fxcrt/fx_basic.h" #include "public/fpdf_edit.h" #include "public/fpdf_ppo.h" +#include "public/fpdf_save.h" #include "public/fpdfview.h" #include "testing/embedder_test.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdfsave.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdfsave.cpp index b0e0ec7cc37..ae9f2a17b82 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdfsave.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdfsave.cpp @@ -201,13 +201,13 @@ bool SendPostSaveToXFADoc(CPDFXFA_Context* pContext) { if (!pXFADocView) return false; - CXFA_FFWidgetHandler* pWidgetHander = pXFADocView->GetWidgetHandler(); + CXFA_FFWidgetHandler* pWidgetHandler = pXFADocView->GetWidgetHandler(); std::unique_ptr<CXFA_WidgetAccIterator> pWidgetAccIterator = pXFADocView->CreateWidgetAccIterator(); while (CXFA_WidgetAcc* pWidgetAcc = pWidgetAccIterator->MoveToNext()) { CXFA_EventParam preParam; preParam.m_eType = XFA_EVENT_PostSave; - pWidgetHander->ProcessEvent(pWidgetAcc, &preParam); + pWidgetHandler->ProcessEvent(pWidgetAcc, &preParam); } pXFADocView->UpdateDocView(); pContext->ClearChangeMark(); @@ -225,13 +225,13 @@ bool SendPreSaveToXFADoc( if (!pXFADocView) return true; - CXFA_FFWidgetHandler* pWidgetHander = pXFADocView->GetWidgetHandler(); + CXFA_FFWidgetHandler* pWidgetHandler = pXFADocView->GetWidgetHandler(); std::unique_ptr<CXFA_WidgetAccIterator> pWidgetAccIterator = pXFADocView->CreateWidgetAccIterator(); while (CXFA_WidgetAcc* pWidgetAcc = pWidgetAccIterator->MoveToNext()) { CXFA_EventParam preParam; preParam.m_eType = XFA_EVENT_PreSave; - pWidgetHander->ProcessEvent(pWidgetAcc, &preParam); + pWidgetHandler->ProcessEvent(pWidgetAcc, &preParam); } pXFADocView->UpdateDocView(); return SaveXFADocumentData(pContext, fileList); diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdfsave_embeddertest.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdfsave_embeddertest.cpp index 918727027fe..260fe0c2a69 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdfsave_embeddertest.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdfsave_embeddertest.cpp @@ -11,12 +11,11 @@ #include "public/fpdf_ppo.h" #include "public/fpdfview.h" #include "testing/embedder_test.h" -#include "testing/fx_string_testhelpers.h" #include "testing/gmock/include/gmock/gmock-matchers.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/test_support.h" -class FPDFSaveEmbedderTest : public EmbedderTest, public TestSaver {}; +class FPDFSaveEmbedderTest : public EmbedderTest {}; TEST_F(FPDFSaveEmbedderTest, SaveSimpleDoc) { EXPECT_TRUE(OpenDocument("hello_world.pdf")); @@ -31,7 +30,6 @@ TEST_F(FPDFSaveEmbedderTest, SaveSimpleDocWithVersion) { EXPECT_THAT(GetString(), testing::StartsWith("%PDF-1.4\r\n")); EXPECT_EQ(843u, GetString().length()); } - TEST_F(FPDFSaveEmbedderTest, SaveSimpleDocWithBadVersion) { EXPECT_TRUE(OpenDocument("hello_world.pdf")); EXPECT_TRUE(FPDF_SaveWithVersion(document(), this, 0, -1)); diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdfview.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdfview.cpp index f20e8ab9f42..94cc97885aa 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdfview.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdfview.cpp @@ -16,7 +16,9 @@ #include "core/fpdfapi/page/cpdf_imageobject.h" #include "core/fpdfapi/page/cpdf_page.h" #include "core/fpdfapi/page/cpdf_pageobject.h" +#include "core/fpdfapi/page/cpdf_pathobject.h" #include "core/fpdfapi/parser/cpdf_array.h" +#include "core/fpdfapi/parser/cpdf_dictionary.h" #include "core/fpdfapi/parser/cpdf_document.h" #include "core/fpdfapi/parser/fpdf_parser_decode.h" #include "core/fpdfapi/render/cpdf_progressiverenderer.h" @@ -35,6 +37,7 @@ #include "fpdfsdk/fsdk_define.h" #include "fpdfsdk/fsdk_pauseadapter.h" #include "fpdfsdk/javascript/ijs_runtime.h" +#include "public/fpdf_edit.h" #include "public/fpdf_ext.h" #include "public/fpdf_progressive.h" #include "third_party/base/allocator/partition_allocator/partition_alloc.h" @@ -51,6 +54,16 @@ #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ #include "core/fxge/cfx_windowsrenderdevice.h" + +// These checks are here because core/ and public/ cannot depend on each other. +static_assert(WindowsPrintMode::kModeEmf == FPDF_PRINTMODE_EMF, + "WindowsPrintMode::kModeEmf value mismatch"); +static_assert(WindowsPrintMode::kModeTextOnly == FPDF_PRINTMODE_TEXTONLY, + "WindowsPrintMode::kModeTextOnly value mismatch"); +static_assert(WindowsPrintMode::kModePostScript2 == FPDF_PRINTMODE_POSTSCRIPT2, + "WindowsPrintMode::kModePostScript2 value mismatch"); +static_assert(WindowsPrintMode::kModePostScript3 == FPDF_PRINTMODE_POSTSCRIPT3, + "WindowsPrintMode::kModePostScript3 value mismatch"); #endif namespace { @@ -88,15 +101,11 @@ void RenderPageImpl(CPDF_PageRenderContext* pContext, #endif // PDF_ENABLE_XFA // Grayscale output - if (flags & FPDF_GRAYSCALE) { - pContext->m_pOptions->m_ColorMode = RENDER_COLOR_GRAY; - pContext->m_pOptions->m_ForeColor = 0; - pContext->m_pOptions->m_BackColor = 0xffffff; - } + if (flags & FPDF_GRAYSCALE) + pContext->m_pOptions->m_ColorMode = CPDF_RenderOptions::kGray; const CPDF_OCContext::UsageType usage = (flags & FPDF_PRINTING) ? CPDF_OCContext::Print : CPDF_OCContext::View; - pContext->m_pOptions->m_AddFlags = flags >> 8; pContext->m_pOptions->m_pOCContext = pdfium::MakeRetain<CPDF_OCContext>(pPage->m_pDocument.Get(), usage); @@ -303,10 +312,38 @@ CPDF_Page* CPDFPageFromFPDFPage(FPDF_PAGE page) { #endif // PDF_ENABLE_XFA } +CPDF_PathObject* CPDFPathObjectFromFPDFPageObject(FPDF_PAGEOBJECT page_object) { + return static_cast<CPDF_PathObject*>(page_object); +} + +CPDF_PageObject* CPDFPageObjectFromFPDFPageObject(FPDF_PAGEOBJECT page_object) { + return static_cast<CPDF_PageObject*>(page_object); +} + +CPDF_Object* CPDFObjectFromFPDFAttachment(FPDF_ATTACHMENT attachment) { + return static_cast<CPDF_Object*>(attachment); +} + +CFX_ByteString CFXByteStringFromFPDFWideString(FPDF_WIDESTRING wide_string) { + return CFX_WideString::FromUTF16LE(wide_string, + CFX_WideString::WStringLength(wide_string)) + .UTF8Encode(); +} + CFX_DIBitmap* CFXBitmapFromFPDFBitmap(FPDF_BITMAP bitmap) { return static_cast<CFX_DIBitmap*>(bitmap); } +unsigned long Utf16EncodeMaybeCopyAndReturnLength(const CFX_WideString& text, + void* buffer, + unsigned long buflen) { + CFX_ByteString encodedText = text.UTF16LE_Encode(); + unsigned long len = encodedText.GetLength(); + if (buffer && len <= buflen) + memcpy(buffer, encodedText.c_str(), len); + return len; +} + CFX_RetainPtr<IFX_SeekableReadStream> MakeSeekableReadStream( FPDF_FILEACCESS* pFileAccess) { return pdfium::MakeRetain<CPDF_CustomAccess>(pFileAccess); @@ -440,9 +477,13 @@ DLLEXPORT void STDCALL FPDF_SetPrintTextWithGDI(FPDF_BOOL use_gdi) { #endif // PDFIUM_PRINT_TEXT_WITH_GDI DLLEXPORT FPDF_BOOL STDCALL FPDF_SetPrintPostscriptLevel(int postscript_level) { - if (postscript_level != 0 && postscript_level != 2 && postscript_level != 3) + return postscript_level != 1 && FPDF_SetPrintMode(postscript_level); +} + +DLLEXPORT FPDF_BOOL STDCALL FPDF_SetPrintMode(int mode) { + if (mode < FPDF_PRINTMODE_EMF || mode > FPDF_PRINTMODE_POSTSCRIPT3) return FALSE; - g_pdfium_print_postscript_level = postscript_level; + g_pdfium_print_mode = mode; return TRUE; } #endif // defined(_WIN32) @@ -790,14 +831,16 @@ DLLEXPORT void STDCALL FPDF_RenderPage(HDC dc, CPDF_PageRenderContext* pContext = pPage->GetRenderContext(); CFX_RetainPtr<CFX_DIBitmap> pBitmap; + // TODO(rbpotter): Restore the behavior described below after resolving + // crbug.com/753700 // Don't render the full page to bitmap for a mask unless there are a lot // of masks. Full page bitmaps result in large spool sizes, so they should // only be used when necessary. For large numbers of masks, rendering each // individually is inefficient and unlikely to significantly improve spool - // size. + // size. This fix is temporarily disabled due to crbug.com/753700 so all + // image masks will result in the full page rendering as bitmap. const bool bNewBitmap = - pPage->BackgroundAlphaNeeded() || - (pPage->HasImageMask() && pPage->GetMaskBoundingBoxes().size() > 100); + pPage->BackgroundAlphaNeeded() || pPage->HasImageMask(); const bool bHasMask = pPage->HasImageMask() && !bNewBitmap; if (bNewBitmap || bHasMask) { pBitmap = pdfium::MakeRetain<CFX_DIBitmap>(); @@ -1025,10 +1068,8 @@ DLLEXPORT void STDCALL FPDF_DeviceToPage(FPDF_PAGE page, #else // PDF_ENABLE_XFA CFX_Matrix page2device = pPage->GetDisplayMatrix(start_x, start_y, size_x, size_y, rotate); - CFX_Matrix device2page; - device2page.SetReverse(page2device); - CFX_PointF pos = device2page.Transform( + CFX_PointF pos = page2device.GetInverse().Transform( CFX_PointF(static_cast<float>(device_x), static_cast<float>(device_y))); *page_x = pos.x; @@ -1283,7 +1324,7 @@ DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDestByName(FPDF_DOCUMENT document, return nullptr; CPDF_NameTree name_tree(pDoc, "Dests"); - return name_tree.LookupNamedDest(pDoc, name); + return name_tree.LookupNamedDest(pDoc, PDF_DecodeText(CFX_ByteString(name))); } #ifdef PDF_ENABLE_XFA @@ -1359,6 +1400,7 @@ DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDest(FPDF_DOCUMENT document, CPDF_Object* pDestObj = nullptr; CFX_ByteString bsName; + CFX_WideString wsName; CPDF_NameTree nameTree(pDoc, "Dests"); int count = nameTree.GetCount(); if (index >= count) { @@ -1382,8 +1424,9 @@ DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDest(FPDF_DOCUMENT document, break; i++; } + wsName = PDF_DecodeText(bsName); } else { - pDestObj = nameTree.LookupValueAndName(index, &bsName); + pDestObj = nameTree.LookupValueAndName(index, &wsName); } if (!pDestObj) return nullptr; @@ -1395,7 +1438,6 @@ DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDest(FPDF_DOCUMENT document, if (!pDestObj->IsArray()) return nullptr; - CFX_WideString wsName = PDF_DecodeText(bsName); CFX_ByteString utf16Name = wsName.UTF16LE_Encode(); int len = utf16Name.GetLength(); if (!buffer) { diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdfview_c_api_test.c b/chromium/third_party/pdfium/fpdfsdk/fpdfview_c_api_test.c index fe56b1a3451..546ae475122 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdfview_c_api_test.c +++ b/chromium/third_party/pdfium/fpdfsdk/fpdfview_c_api_test.c @@ -9,6 +9,8 @@ #include "fpdfsdk/fpdfview_c_api_test.h" +#include "public/fpdf_annot.h" +#include "public/fpdf_attachment.h" #include "public/fpdf_dataavail.h" #include "public/fpdf_doc.h" #include "public/fpdf_edit.h" @@ -33,6 +35,44 @@ fnptr g_c_api_test_fnptr = NULL; // Extern, so can't know it doesn't change. // Function to call from gtest harness to ensure linker resolution. int CheckPDFiumCApi() { + // fpdf_annot.h + CHK(FPDFAnnot_IsSupportedSubtype); + CHK(FPDFPage_CreateAnnot); + CHK(FPDFPage_GetAnnotCount); + CHK(FPDFPage_GetAnnot); + CHK(FPDFPage_CloseAnnot); + CHK(FPDFPage_RemoveAnnot); + CHK(FPDFAnnot_GetSubtype); + CHK(FPDFAnnot_IsObjectSupportedSubtype); + CHK(FPDFAnnot_UpdateObject); + CHK(FPDFAnnot_AppendObject); + CHK(FPDFAnnot_GetObjectCount); + CHK(FPDFAnnot_GetObject); + CHK(FPDFAnnot_RemoveObject); + CHK(FPDFAnnot_SetColor); + CHK(FPDFAnnot_GetColor); + CHK(FPDFAnnot_HasAttachmentPoints); + CHK(FPDFAnnot_SetAttachmentPoints); + CHK(FPDFAnnot_GetAttachmentPoints); + CHK(FPDFAnnot_SetRect); + CHK(FPDFAnnot_GetRect); + CHK(FPDFAnnot_HasKey); + CHK(FPDFAnnot_SetStringValue); + CHK(FPDFAnnot_GetStringValue); + CHK(FPDFAnnot_GetFlags); + CHK(FPDFAnnot_SetFlags); + CHK(FPDFAnnot_GetFormFieldFlags); + CHK(FPDFAnnot_GetFormFieldAtPoint); + + // fpdf_attachment.h + CHK(FPDFDoc_GetAttachmentCount); + CHK(FPDFDoc_GetAttachment); + CHK(FPDFAttachment_GetName); + CHK(FPDFAttachment_HasKey); + CHK(FPDFAttachment_GetValueType); + CHK(FPDFAttachment_GetStringValue); + CHK(FPDFAttachment_GetFile); + // fpdf_dataavail.h CHK(FPDFAvail_Create); CHK(FPDFAvail_Destroy); @@ -79,7 +119,9 @@ int CheckPDFiumCApi() { CHK(FPDFPage_HasTransparency); CHK(FPDFPage_GenerateContent); CHK(FPDFPageObj_HasTransparency); + CHK(FPDFPageObj_GetBounds); CHK(FPDFPageObj_GetType); + CHK(FPDFPageObj_SetBlendMode); CHK(FPDFPageObj_Transform); CHK(FPDFPage_TransformAnnots); CHK(FPDFPageObj_NewImageObj); @@ -90,6 +132,7 @@ int CheckPDFiumCApi() { CHK(FPDFPageObj_CreateNewPath); CHK(FPDFPageObj_CreateNewRect); CHK(FPDFPath_SetStrokeColor); + CHK(FPDFPath_GetStrokeColor); CHK(FPDFPath_SetStrokeWidth); CHK(FPDFPath_SetFillColor); CHK(FPDFPath_GetFillColor); @@ -98,8 +141,11 @@ int CheckPDFiumCApi() { CHK(FPDFPath_BezierTo); CHK(FPDFPath_Close); CHK(FPDFPath_SetDrawMode); + CHK(FPDFPath_SetLineCap); + CHK(FPDFPath_SetLineJoin); CHK(FPDFPageObj_NewTextObj); CHK(FPDFText_SetText); + CHK(FPDFText_SetFillColor); CHK(FPDFText_LoadFont); CHK(FPDFFont_Close); CHK(FPDFPageObj_CreateTextObj); @@ -132,9 +178,9 @@ int CheckPDFiumCApi() { CHK(FORM_OnKeyDown); CHK(FORM_OnKeyUp); CHK(FORM_OnChar); + CHK(FORM_GetSelectedText); CHK(FORM_ForceToKillFocus); CHK(FPDFPage_HasFormFieldAtPoint); - CHK(FPDPage_HasFormFieldAtPoint); // DEPRECATED. Remove in the future. CHK(FPDFPage_FormFieldZOrderAtPoint); CHK(FPDF_SetFormFieldHighlightColor); CHK(FPDF_SetFormFieldHighlightAlpha); diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp index 24858f2f1a9..87e003e1473 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp @@ -143,12 +143,10 @@ void CPDFXFA_Page::DeviceToPage(int start_x, if (!m_pPDFPage && !m_pXFAPageView) return; - CFX_Matrix device2page; - device2page.SetReverse( - GetDisplayMatrix(start_x, start_y, size_x, size_y, rotate)); - - CFX_PointF pos = device2page.Transform( - CFX_PointF(static_cast<float>(device_x), static_cast<float>(device_y))); + CFX_PointF pos = GetDisplayMatrix(start_x, start_y, size_x, size_y, rotate) + .GetInverse() + .Transform(CFX_PointF(static_cast<float>(device_x), + static_cast<float>(device_y))); *page_x = pos.x; *page_y = pos.y; diff --git a/chromium/third_party/pdfium/fpdfsdk/fsdk_define.h b/chromium/third_party/pdfium/fpdfsdk/fsdk_define.h index b7691bbdd90..610b854a9d1 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fsdk_define.h +++ b/chromium/third_party/pdfium/fpdfsdk/fsdk_define.h @@ -23,7 +23,9 @@ class CPDF_Annot; class CPDF_Page; +class CPDF_PageObject; class CPDF_PageRenderContext; +class CPDF_PathObject; class IFSDK_PAUSE_Adapter; // Layering prevents fxcrt from knowing about FPDF_FILEACCESS, so this can't @@ -61,8 +63,20 @@ FPDF_DOCUMENT FPDFDocumentFromCPDFDocument(CPDF_Document* doc); CPDF_Page* CPDFPageFromFPDFPage(FPDF_PAGE page); +CPDF_PathObject* CPDFPathObjectFromFPDFPageObject(FPDF_PAGEOBJECT page_object); + +CPDF_PageObject* CPDFPageObjectFromFPDFPageObject(FPDF_PAGEOBJECT page_object); + +CPDF_Object* CPDFObjectFromFPDFAttachment(FPDF_ATTACHMENT attachment); + +CFX_ByteString CFXByteStringFromFPDFWideString(FPDF_WIDESTRING wide_string); + CFX_DIBitmap* CFXBitmapFromFPDFBitmap(FPDF_BITMAP bitmap); +unsigned long Utf16EncodeMaybeCopyAndReturnLength(const CFX_WideString& text, + void* buffer, + unsigned long buflen); + void FSDK_SetSandBoxPolicy(FPDF_DWORD policy, FPDF_BOOL enable); FPDF_BOOL FSDK_IsSandBoxPolicyEnabled(FPDF_DWORD policy); void FPDF_RenderPage_Retail(CPDF_PageRenderContext* pContext, @@ -79,5 +93,10 @@ void FPDF_RenderPage_Retail(CPDF_PageRenderContext* pContext, void CheckUnSupportError(CPDF_Document* pDoc, uint32_t err_code); void CheckUnSupportAnnot(CPDF_Document* pDoc, const CPDF_Annot* pPDFAnnot); void ProcessParseError(CPDF_Parser::Error err); +FPDF_BOOL FPDFPageObj_SetFillColor(FPDF_PAGEOBJECT page_object, + unsigned int R, + unsigned int G, + unsigned int B, + unsigned int A); #endif // FPDFSDK_FSDK_DEFINE_H_ diff --git a/chromium/third_party/pdfium/fpdfsdk/fsdk_filewriteadapter.cpp b/chromium/third_party/pdfium/fpdfsdk/fsdk_filewriteadapter.cpp index ff527a6f2ea..50394c32862 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fsdk_filewriteadapter.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fsdk_filewriteadapter.cpp @@ -18,5 +18,5 @@ bool FSDK_FileWriteAdapter::WriteBlock(const void* data, size_t size) { } bool FSDK_FileWriteAdapter::WriteString(const CFX_ByteStringC& str) { - return WriteBlock(str.c_str(), str.GetLength()); + return WriteBlock(str.unterminated_c_str(), str.GetLength()); } diff --git a/chromium/third_party/pdfium/fpdfsdk/fxedit/fxet_edit.cpp b/chromium/third_party/pdfium/fpdfsdk/fxedit/fxet_edit.cpp index cf4fdc3d914..41019b3459e 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fxedit/fxet_edit.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fxedit/fxet_edit.cpp @@ -8,6 +8,7 @@ #include <algorithm> #include <memory> +#include <sstream> #include <utility> #include "core/fpdfapi/font/cpdf_font.h" @@ -27,8 +28,9 @@ #include "core/fxge/cfx_renderdevice.h" #include "fpdfsdk/cfx_systemhandler.h" #include "fpdfsdk/fxedit/fx_edit.h" -#include "fpdfsdk/pdfwindow/PWL_Edit.h" -#include "fpdfsdk/pdfwindow/PWL_EditCtrl.h" +#include "fpdfsdk/pdfwindow/cpwl_edit.h" +#include "fpdfsdk/pdfwindow/cpwl_edit_ctrl.h" +#include "fpdfsdk/pdfwindow/cpwl_scroll_bar.h" #include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" @@ -36,27 +38,6 @@ namespace { const int kEditUndoMaxItems = 10000; -CFX_ByteString GetWordRenderString(const CFX_ByteString& strWords) { - if (strWords.GetLength() > 0) - return PDF_EncodeString(strWords) + " Tj\n"; - return CFX_ByteString(); -} - -CFX_ByteString GetFontSetString(IPVT_FontMap* pFontMap, - int32_t nFontIndex, - float fFontSize) { - if (!pFontMap) - return CFX_ByteString(); - - CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); - if (sFontAlias.GetLength() <= 0 || fFontSize <= 0) - return CFX_ByteString(); - - CFX_ByteTextBuf sRet; - sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; - return sRet.MakeString(); -} - void DrawTextString(CFX_RenderDevice* pDevice, const CFX_PointF& pt, CPDF_Font* pFont, @@ -74,14 +55,14 @@ void DrawTextString(CFX_RenderDevice* pDevice, CPDF_RenderOptions ro; ro.m_Flags = RENDER_CLEARTYPE; - ro.m_ColorMode = RENDER_COLOR_NORMAL; + ro.m_ColorMode = CPDF_RenderOptions::kNormal; CPDF_TextRenderer::DrawTextString(pDevice, pos.x, pos.y, pFont, fFontSize, &mt, str, crTextFill, nullptr, &ro); } else { CPDF_RenderOptions ro; ro.m_Flags = RENDER_CLEARTYPE; - ro.m_ColorMode = RENDER_COLOR_NORMAL; + ro.m_ColorMode = CPDF_RenderOptions::kNormal; CPDF_TextRenderer::DrawTextString(pDevice, pos.x, pos.y, pFont, fFontSize, pUser2Device, str, crTextFill, nullptr, @@ -145,7 +126,7 @@ CFX_Edit_Provider::CFX_Edit_Provider(IPVT_FontMap* pFontMap) CFX_Edit_Provider::~CFX_Edit_Provider() {} -IPVT_FontMap* CFX_Edit_Provider::GetFontMap() { +IPVT_FontMap* CFX_Edit_Provider::GetFontMap() const { return m_pFontMap; } @@ -512,149 +493,6 @@ void CFXEU_InsertText::Undo() { } // static -CFX_ByteString CFX_Edit::GetEditAppearanceStream(CFX_Edit* pEdit, - const CFX_PointF& ptOffset, - const CPVT_WordRange* pRange, - bool bContinuous, - uint16_t SubWord) { - CFX_Edit_Iterator* pIterator = pEdit->GetIterator(); - if (pRange) - pIterator->SetAt(pRange->BeginPos); - else - pIterator->SetAt(0); - - CFX_ByteTextBuf sEditStream; - CFX_ByteTextBuf sWords; - int32_t nCurFontIndex = -1; - CFX_PointF ptOld; - CFX_PointF ptNew; - CPVT_WordPlace oldplace; - - while (pIterator->NextWord()) { - CPVT_WordPlace place = pIterator->GetAt(); - if (pRange && place > pRange->EndPos) - break; - - if (bContinuous) { - if (place.LineCmp(oldplace) != 0) { - if (sWords.GetSize() > 0) { - sEditStream << GetWordRenderString(sWords.MakeString()); - sWords.Clear(); - } - - CPVT_Word word; - if (pIterator->GetWord(word)) { - ptNew = CFX_PointF(word.ptWord.x + ptOffset.x, - word.ptWord.y + ptOffset.y); - } else { - CPVT_Line line; - pIterator->GetLine(line); - ptNew = CFX_PointF(line.ptLine.x + ptOffset.x, - line.ptLine.y + ptOffset.y); - } - - if (ptNew.x != ptOld.x || ptNew.y != ptOld.y) { - sEditStream << ptNew.x - ptOld.x << " " << ptNew.y - ptOld.y - << " Td\n"; - - ptOld = ptNew; - } - } - - CPVT_Word word; - if (pIterator->GetWord(word)) { - if (word.nFontIndex != nCurFontIndex) { - if (sWords.GetSize() > 0) { - sEditStream << GetWordRenderString(sWords.MakeString()); - sWords.Clear(); - } - sEditStream << GetFontSetString(pEdit->GetFontMap(), word.nFontIndex, - word.fFontSize); - nCurFontIndex = word.nFontIndex; - } - - sWords << GetPDFWordString(pEdit->GetFontMap(), nCurFontIndex, - word.Word, SubWord); - } - - oldplace = place; - } else { - CPVT_Word word; - if (pIterator->GetWord(word)) { - ptNew = - CFX_PointF(word.ptWord.x + ptOffset.x, word.ptWord.y + ptOffset.y); - - if (ptNew.x != ptOld.x || ptNew.y != ptOld.y) { - sEditStream << ptNew.x - ptOld.x << " " << ptNew.y - ptOld.y - << " Td\n"; - ptOld = ptNew; - } - - if (word.nFontIndex != nCurFontIndex) { - sEditStream << GetFontSetString(pEdit->GetFontMap(), word.nFontIndex, - word.fFontSize); - nCurFontIndex = word.nFontIndex; - } - - sEditStream << GetWordRenderString(GetPDFWordString( - pEdit->GetFontMap(), nCurFontIndex, word.Word, SubWord)); - } - } - } - - if (sWords.GetSize() > 0) { - sEditStream << GetWordRenderString(sWords.MakeString()); - sWords.Clear(); - } - - CFX_ByteTextBuf sAppStream; - if (sEditStream.GetSize() > 0) { - int32_t nHorzScale = pEdit->GetHorzScale(); - if (nHorzScale != 100) { - sAppStream << nHorzScale << " Tz\n"; - } - - float fCharSpace = pEdit->GetCharSpace(); - if (!IsFloatZero(fCharSpace)) { - sAppStream << fCharSpace << " Tc\n"; - } - - sAppStream << sEditStream; - } - - return sAppStream.MakeString(); -} - -// static -CFX_ByteString CFX_Edit::GetSelectAppearanceStream( - CFX_Edit* pEdit, - const CFX_PointF& ptOffset, - const CPVT_WordRange* pRange) { - if (!pRange || pRange->IsEmpty()) - return CFX_ByteString(); - - CFX_Edit_Iterator* pIterator = pEdit->GetIterator(); - pIterator->SetAt(pRange->BeginPos); - - CFX_ByteTextBuf sRet; - while (pIterator->NextWord()) { - CPVT_WordPlace place = pIterator->GetAt(); - if (place > pRange->EndPos) - break; - - CPVT_Word word; - CPVT_Line line; - if (pIterator->GetWord(word) && pIterator->GetLine(line)) { - sRet << word.ptWord.x + ptOffset.x << " " - << line.ptLine.y + line.fLineDescent << " " << word.fWidth << " " - << line.fLineAscent - line.fLineDescent << " re\nf\n"; - } - } - - return sRet.MakeString(); -} - -// static void CFX_Edit::DrawEdit(CFX_RenderDevice* pDevice, CFX_Matrix* pUser2Device, CFX_Edit* pEdit, @@ -678,7 +516,7 @@ void CFX_Edit::DrawEdit(CFX_RenderDevice* pDevice, const FX_COLORREF crWhite = ArgbEncode(255, 255, 255, 255); const FX_COLORREF crSelBK = ArgbEncode(255, 0, 51, 113); - CFX_ByteTextBuf sTextBuf; + std::ostringstream sTextBuf; int32_t nFontIndex = -1; CFX_PointF ptBT; CFX_RenderDevice::StateRestorer restorer(pDevice); @@ -735,13 +573,13 @@ void CFX_Edit::DrawEdit(CFX_RenderDevice* pDevice, if (bContinuous) { if (place.LineCmp(oldplace) != 0 || word.nFontIndex != nFontIndex || crOldFill != crCurFill) { - if (sTextBuf.GetLength() > 0) { + if (sTextBuf.tellp() > 0) { DrawTextString( pDevice, CFX_PointF(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y), pFontMap->GetPDFFont(nFontIndex), fFontSize, pUser2Device, - sTextBuf.MakeString(), crOldFill, nHorzScale); + CFX_ByteString(sTextBuf), crOldFill, nHorzScale); - sTextBuf.Clear(); + sTextBuf.str(""); } nFontIndex = word.nFontIndex; ptBT = word.ptWord; @@ -749,8 +587,7 @@ void CFX_Edit::DrawEdit(CFX_RenderDevice* pDevice, } sTextBuf << GetPDFWordString(pFontMap, word.nFontIndex, word.Word, - SubWord) - .AsStringC(); + SubWord); } else { DrawTextString( pDevice, CFX_PointF(word.ptWord.x + ptOffset.x, @@ -763,11 +600,11 @@ void CFX_Edit::DrawEdit(CFX_RenderDevice* pDevice, } } - if (sTextBuf.GetLength() > 0) { + if (sTextBuf.tellp() > 0) { DrawTextString(pDevice, CFX_PointF(ptBT.x + ptOffset.x, ptBT.y + ptOffset.y), pFontMap->GetPDFFont(nFontIndex), fFontSize, pUser2Device, - sTextBuf.MakeString(), crOldFill, nHorzScale); + CFX_ByteString(sTextBuf), crOldFill, nHorzScale); } } } @@ -1226,18 +1063,24 @@ CFX_FloatRect CFX_Edit::VTToEdit(const CFX_FloatRect& rect) const { } void CFX_Edit::SetScrollInfo() { - if (m_pNotify) { - CFX_FloatRect rcPlate = m_pVT->GetPlateRect(); - CFX_FloatRect rcContent = m_pVT->GetContentRect(); + if (!m_pNotify) + return; - if (!m_bNotifyFlag) { - CFX_AutoRestorer<bool> restorer(&m_bNotifyFlag); - m_bNotifyFlag = true; - m_pNotify->IOnSetScrollInfoY(rcPlate.bottom, rcPlate.top, - rcContent.bottom, rcContent.top, - rcPlate.Height() / 3, rcPlate.Height()); - } - } + CFX_FloatRect rcPlate = m_pVT->GetPlateRect(); + CFX_FloatRect rcContent = m_pVT->GetContentRect(); + if (m_bNotifyFlag) + return; + + CFX_AutoRestorer<bool> restorer(&m_bNotifyFlag); + m_bNotifyFlag = true; + + PWL_SCROLL_INFO Info; + Info.fPlateWidth = rcPlate.top - rcPlate.bottom; + Info.fContentMin = rcContent.bottom; + Info.fContentMax = rcContent.top; + Info.fSmallStep = rcPlate.Height() / 3; + Info.fBigStep = rcPlate.Height(); + m_pNotify->SetScrollInfo(Info); } void CFX_Edit::SetScrollPosX(float fx) { @@ -1265,7 +1108,7 @@ void CFX_Edit::SetScrollPosY(float fy) { if (!m_bNotifyFlag) { CFX_AutoRestorer<bool> restorer(&m_bNotifyFlag); m_bNotifyFlag = true; - m_pNotify->IOnSetScrollPosY(fy); + m_pNotify->SetScrollPosition(fy); } } } @@ -1377,7 +1220,7 @@ void CFX_Edit::Refresh() { m_bNotifyFlag = true; if (const CFX_Edit_RectArray* pRects = m_Refresh.GetRefreshRects()) { for (int32_t i = 0, sz = pRects->GetSize(); i < sz; i++) - m_pNotify->IOnInvalidateRect(pRects->GetAt(i)); + m_pNotify->InvalidateRect(pRects->GetAt(i)); } } } @@ -1445,7 +1288,7 @@ void CFX_Edit::RefreshWordRange(const CPVT_WordRange& wr) { CFX_AutoRestorer<bool> restorer(&m_bNotifyFlag); m_bNotifyFlag = true; CFX_FloatRect rcRefresh = VTToEdit(rcWord); - m_pNotify->IOnInvalidateRect(&rcRefresh); + m_pNotify->InvalidateRect(&rcRefresh); } } } else { @@ -1459,7 +1302,7 @@ void CFX_Edit::RefreshWordRange(const CPVT_WordRange& wr) { CFX_AutoRestorer<bool> restorer(&m_bNotifyFlag); m_bNotifyFlag = true; CFX_FloatRect rcRefresh = VTToEdit(rcLine); - m_pNotify->IOnInvalidateRect(&rcRefresh); + m_pNotify->InvalidateRect(&rcRefresh); } } @@ -1497,8 +1340,8 @@ void CFX_Edit::SetCaretInfo() { CFX_AutoRestorer<bool> restorer(&m_bNotifyFlag); m_bNotifyFlag = true; - m_pNotify->IOnSetCaret(m_SelState.IsEmpty(), VTToEdit(ptHead), - VTToEdit(ptFoot), m_wpCaret); + m_pNotify->SetCaret(m_SelState.IsEmpty(), VTToEdit(ptHead), + VTToEdit(ptFoot)); } } } diff --git a/chromium/third_party/pdfium/fpdfsdk/fxedit/fxet_edit.h b/chromium/third_party/pdfium/fpdfsdk/fxedit/fxet_edit.h index ebc326f5a9e..c0c8442d520 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fxedit/fxet_edit.h +++ b/chromium/third_party/pdfium/fpdfsdk/fxedit/fxet_edit.h @@ -13,6 +13,7 @@ #include "core/fpdfdoc/cpvt_secprops.h" #include "core/fpdfdoc/cpvt_wordprops.h" +#include "core/fxcrt/cfx_unowned_ptr.h" #include "fpdfsdk/fxedit/fx_edit.h" class CFFL_FormFiller; @@ -158,7 +159,7 @@ class CFXEU_InsertWord : public CFX_Edit_UndoItem { void Undo() override; private: - CFX_Edit* m_pEdit; + CFX_UnownedPtr<CFX_Edit> m_pEdit; CPVT_WordPlace m_wpOld; CPVT_WordPlace m_wpNew; @@ -181,7 +182,7 @@ class CFXEU_InsertReturn : public CFX_Edit_UndoItem { void Undo() override; private: - CFX_Edit* m_pEdit; + CFX_UnownedPtr<CFX_Edit> m_pEdit; CPVT_WordPlace m_wpOld; CPVT_WordPlace m_wpNew; @@ -205,7 +206,7 @@ class CFXEU_Backspace : public CFX_Edit_UndoItem { void Undo() override; private: - CFX_Edit* m_pEdit; + CFX_UnownedPtr<CFX_Edit> m_pEdit; CPVT_WordPlace m_wpOld; CPVT_WordPlace m_wpNew; @@ -232,7 +233,7 @@ class CFXEU_Delete : public CFX_Edit_UndoItem { void Undo() override; private: - CFX_Edit* m_pEdit; + CFX_UnownedPtr<CFX_Edit> m_pEdit; CPVT_WordPlace m_wpOld; CPVT_WordPlace m_wpNew; @@ -255,7 +256,7 @@ class CFXEU_Clear : public CFX_Edit_UndoItem { void Undo() override; private: - CFX_Edit* m_pEdit; + CFX_UnownedPtr<CFX_Edit> m_pEdit; CPVT_WordRange m_wrSel; CFX_WideString m_swText; @@ -275,7 +276,7 @@ class CFXEU_InsertText : public CFX_Edit_UndoItem { void Undo() override; private: - CFX_Edit* m_pEdit; + CFX_UnownedPtr<CFX_Edit> m_pEdit; CPVT_WordPlace m_wpOld; CPVT_WordPlace m_wpNew; @@ -285,14 +286,6 @@ class CFXEU_InsertText : public CFX_Edit_UndoItem { class CFX_Edit { public: - static CFX_ByteString GetEditAppearanceStream(CFX_Edit* pEdit, - const CFX_PointF& ptOffset, - const CPVT_WordRange* pRange, - bool bContinuous, - uint16_t SubWord); - static CFX_ByteString GetSelectAppearanceStream(CFX_Edit* pEdit, - const CFX_PointF& ptOffset, - const CPVT_WordRange* pRange); static void DrawEdit(CFX_RenderDevice* pDevice, CFX_Matrix* pUser2Device, CFX_Edit* pEdit, @@ -449,8 +442,8 @@ class CFX_Edit { private: std::unique_ptr<CPDF_VariableText> m_pVT; - CPWL_EditCtrl* m_pNotify; - CPWL_Edit* m_pOprNotify; + CFX_UnownedPtr<CPWL_EditCtrl> m_pNotify; + CFX_UnownedPtr<CPWL_Edit> m_pOprNotify; std::unique_ptr<CFX_Edit_Provider> m_pVTProvider; CPVT_WordPlace m_wpCaret; CPVT_WordPlace m_wpOldCaret; @@ -485,7 +478,7 @@ class CFX_Edit_Iterator { const CPVT_WordPlace& GetAt() const; private: - CFX_Edit* m_pEdit; + CFX_UnownedPtr<CFX_Edit> m_pEdit; CPDF_VariableText::Iterator* m_pVTIterator; }; @@ -494,7 +487,7 @@ class CFX_Edit_Provider : public CPDF_VariableText::Provider { explicit CFX_Edit_Provider(IPVT_FontMap* pFontMap); ~CFX_Edit_Provider() override; - IPVT_FontMap* GetFontMap(); + IPVT_FontMap* GetFontMap() const; // CPDF_VariableText::Provider: int32_t GetCharWidth(int32_t nFontIndex, uint16_t word) override; diff --git a/chromium/third_party/pdfium/fpdfsdk/fxedit/fxet_list.cpp b/chromium/third_party/pdfium/fpdfsdk/fxedit/fxet_list.cpp index c8fef948af9..0b1a2ac5320 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fxedit/fxet_list.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fxedit/fxet_list.cpp @@ -12,7 +12,7 @@ #include "core/fpdfdoc/cpvt_word.h" #include "core/fxcrt/fx_extension.h" #include "fpdfsdk/fxedit/fxet_edit.h" -#include "fpdfsdk/pdfwindow/PWL_ListBox.h" +#include "fpdfsdk/pdfwindow/cpwl_list_box.h" #include "third_party/base/stl_util.h" CFX_ListItem::CFX_ListItem() @@ -590,7 +590,7 @@ void CFX_ListCtrl::SetFontSize(float fFontSize) { void CFX_ListCtrl::AddItem(const CFX_WideString& str) { auto pListItem = pdfium::MakeUnique<CFX_ListItem>(); - pListItem->SetFontMap(m_pFontMap); + pListItem->SetFontMap(m_pFontMap.Get()); pListItem->SetFontSize(m_fFontSize); pListItem->SetText(str); m_ListItems.push_back(std::move(pListItem)); diff --git a/chromium/third_party/pdfium/fpdfsdk/fxedit/fxet_list.h b/chromium/third_party/pdfium/fpdfsdk/fxedit/fxet_list.h index cd6e2ddeffc..b4b0a56c1ed 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fxedit/fxet_list.h +++ b/chromium/third_party/pdfium/fpdfsdk/fxedit/fxet_list.h @@ -11,6 +11,7 @@ #include <memory> #include <vector> +#include "core/fxcrt/cfx_unowned_ptr.h" #include "core/fxcrt/fx_coordinates.h" #include "fpdfsdk/fxedit/fx_edit.h" @@ -263,7 +264,7 @@ class CFX_ListCtrl : protected CFX_ListContainer { void SetItemSelect(int32_t nItemIndex, bool bSelected); int32_t GetLastSelected() const; - CPWL_List_Notify* m_pNotify; + CFX_UnownedPtr<CPWL_List_Notify> m_pNotify; bool m_bNotifyFlag; CFX_PointF m_ptScrollPos; CPLST_Select m_aSelItems; // for multiple @@ -273,7 +274,7 @@ class CFX_ListCtrl : protected CFX_ListContainer { int32_t m_nCaretIndex; // for multiple std::vector<std::unique_ptr<CFX_ListItem>> m_ListItems; float m_fFontSize; - IPVT_FontMap* m_pFontMap; + CFX_UnownedPtr<IPVT_FontMap> m_pFontMap; bool m_bMultiple; }; diff --git a/chromium/third_party/pdfium/fpdfsdk/ipdfsdk_annothandler.h b/chromium/third_party/pdfium/fpdfsdk/ipdfsdk_annothandler.h index 636d161feae..08008eb996b 100644 --- a/chromium/third_party/pdfium/fpdfsdk/ipdfsdk_annothandler.h +++ b/chromium/third_party/pdfium/fpdfsdk/ipdfsdk_annothandler.h @@ -36,6 +36,7 @@ class IPDFSDK_AnnotHandler { virtual void ReleaseAnnot(CPDFSDK_Annot* pAnnot) = 0; virtual CFX_FloatRect GetViewBBox(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot) = 0; + virtual CFX_WideString GetSelectedText(CPDFSDK_Annot* pAnnot) = 0; virtual bool HitTest(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, const CFX_PointF& point) = 0; diff --git a/chromium/third_party/pdfium/fpdfsdk/javascript/Document.cpp b/chromium/third_party/pdfium/fpdfsdk/javascript/Document.cpp index a760ad99564..ba4b2ae622b 100644 --- a/chromium/third_party/pdfium/fpdfsdk/javascript/Document.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/javascript/Document.cpp @@ -273,11 +273,6 @@ bool Document::exportAsXFDF(CJS_Runtime* pRuntime, return true; } -// Maps a field object in PDF document to a JavaScript variable -// comment: -// note: the paremter cName, this is clue how to treat if the cName is not a -// valiable filed name in this document - bool Document::getField(CJS_Runtime* pRuntime, const std::vector<CJS_Value>& params, CJS_Value& vRet, @@ -1211,7 +1206,7 @@ bool Document::addIcon(CJS_Runtime* pRuntime, } v8::Local<v8::Object> pJSIcon = params[1].ToV8Object(pRuntime); - if (pRuntime->GetObjDefnID(pJSIcon) != CJS_Icon::g_nObjDefnID) { + if (CFXJS_Engine::GetObjDefnID(pJSIcon) != CJS_Icon::g_nObjDefnID) { sError = JSGetStringFromID(IDS_STRING_JSTYPEERROR); return false; } @@ -1599,13 +1594,12 @@ bool Document::gotoNamedDest(CJS_Runtime* pRuntime, return false; } CFX_WideString wideName = params[0].ToCFXWideString(pRuntime); - CFX_ByteString utf8Name = wideName.UTF8Encode(); CPDF_Document* pDocument = m_pFormFillEnv->GetPDFDocument(); if (!pDocument) return false; CPDF_NameTree nameTree(pDocument, "Dests"); - CPDF_Array* destArray = nameTree.LookupNamedDest(pDocument, utf8Name); + CPDF_Array* destArray = nameTree.LookupNamedDest(pDocument, wideName); if (!destArray) return false; diff --git a/chromium/third_party/pdfium/fpdfsdk/javascript/Field.cpp b/chromium/third_party/pdfium/fpdfsdk/javascript/Field.cpp index 8e4b465d5e0..32d44774ff4 100644 --- a/chromium/third_party/pdfium/fpdfsdk/javascript/Field.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/javascript/Field.cpp @@ -1436,7 +1436,7 @@ bool Field::fillColor(CJS_Runtime* pRuntime, vp >> crArray; - CPWL_Color color; + CFX_Color color; color::ConvertArrayToPWLColor(pRuntime, crArray, &color); if (m_bDelay) { AddDelay_Color(FP_FILLCOLOR, color); @@ -1455,23 +1455,23 @@ bool Field::fillColor(CJS_Runtime* pRuntime, int iColorType; pFormControl->GetBackgroundColor(iColorType); - CPWL_Color color; + CFX_Color color; if (iColorType == COLORTYPE_TRANSPARENT) { - color = CPWL_Color(COLORTYPE_TRANSPARENT); + color = CFX_Color(COLORTYPE_TRANSPARENT); } else if (iColorType == COLORTYPE_GRAY) { color = - CPWL_Color(COLORTYPE_GRAY, pFormControl->GetOriginalBackgroundColor(0)); + CFX_Color(COLORTYPE_GRAY, pFormControl->GetOriginalBackgroundColor(0)); } else if (iColorType == COLORTYPE_RGB) { color = - CPWL_Color(COLORTYPE_RGB, pFormControl->GetOriginalBackgroundColor(0), - pFormControl->GetOriginalBackgroundColor(1), - pFormControl->GetOriginalBackgroundColor(2)); + CFX_Color(COLORTYPE_RGB, pFormControl->GetOriginalBackgroundColor(0), + pFormControl->GetOriginalBackgroundColor(1), + pFormControl->GetOriginalBackgroundColor(2)); } else if (iColorType == COLORTYPE_CMYK) { color = - CPWL_Color(COLORTYPE_CMYK, pFormControl->GetOriginalBackgroundColor(0), - pFormControl->GetOriginalBackgroundColor(1), - pFormControl->GetOriginalBackgroundColor(2), - pFormControl->GetOriginalBackgroundColor(3)); + CFX_Color(COLORTYPE_CMYK, pFormControl->GetOriginalBackgroundColor(0), + pFormControl->GetOriginalBackgroundColor(1), + pFormControl->GetOriginalBackgroundColor(2), + pFormControl->GetOriginalBackgroundColor(3)); } else { return false; } @@ -1483,7 +1483,7 @@ bool Field::fillColor(CJS_Runtime* pRuntime, void Field::SetFillColor(CPDFSDK_FormFillEnvironment* pFormFillEnv, const CFX_WideString& swFieldName, int nControlIndex, - const CPWL_Color& color) { + const CFX_Color& color) { // Not supported. } @@ -2213,7 +2213,7 @@ bool Field::strokeColor(CJS_Runtime* pRuntime, vp >> crArray; - CPWL_Color color; + CFX_Color color; color::ConvertArrayToPWLColor(pRuntime, crArray, &color); if (m_bDelay) { AddDelay_Color(FP_STROKECOLOR, color); @@ -2235,20 +2235,20 @@ bool Field::strokeColor(CJS_Runtime* pRuntime, int iColorType; pFormControl->GetBorderColor(iColorType); - CPWL_Color color; + CFX_Color color; if (iColorType == COLORTYPE_TRANSPARENT) { - color = CPWL_Color(COLORTYPE_TRANSPARENT); + color = CFX_Color(COLORTYPE_TRANSPARENT); } else if (iColorType == COLORTYPE_GRAY) { - color = CPWL_Color(COLORTYPE_GRAY, pFormControl->GetOriginalBorderColor(0)); + color = CFX_Color(COLORTYPE_GRAY, pFormControl->GetOriginalBorderColor(0)); } else if (iColorType == COLORTYPE_RGB) { - color = CPWL_Color(COLORTYPE_RGB, pFormControl->GetOriginalBorderColor(0), - pFormControl->GetOriginalBorderColor(1), - pFormControl->GetOriginalBorderColor(2)); + color = CFX_Color(COLORTYPE_RGB, pFormControl->GetOriginalBorderColor(0), + pFormControl->GetOriginalBorderColor(1), + pFormControl->GetOriginalBorderColor(2)); } else if (iColorType == COLORTYPE_CMYK) { - color = CPWL_Color(COLORTYPE_CMYK, pFormControl->GetOriginalBorderColor(0), - pFormControl->GetOriginalBorderColor(1), - pFormControl->GetOriginalBorderColor(2), - pFormControl->GetOriginalBorderColor(3)); + color = CFX_Color(COLORTYPE_CMYK, pFormControl->GetOriginalBorderColor(0), + pFormControl->GetOriginalBorderColor(1), + pFormControl->GetOriginalBorderColor(2), + pFormControl->GetOriginalBorderColor(3)); } else { return false; } @@ -2261,7 +2261,7 @@ bool Field::strokeColor(CJS_Runtime* pRuntime, void Field::SetStrokeColor(CPDFSDK_FormFillEnvironment* pFormFillEnv, const CFX_WideString& swFieldName, int nControlIndex, - const CPWL_Color& color) { + const CFX_Color& color) { // Not supported. } @@ -2353,7 +2353,7 @@ bool Field::textColor(CJS_Runtime* pRuntime, vp >> crArray; - CPWL_Color color; + CFX_Color color; color::ConvertArrayToPWLColor(pRuntime, crArray, &color); if (m_bDelay) { AddDelay_Color(FP_TEXTCOLOR, color); @@ -2383,11 +2383,11 @@ bool Field::textColor(CJS_Runtime* pRuntime, int32_t b; std::tie(a, r, g, b) = ArgbDecode(color); - CPWL_Color crRet = - CPWL_Color(COLORTYPE_RGB, r / 255.0f, g / 255.0f, b / 255.0f); + CFX_Color crRet = + CFX_Color(COLORTYPE_RGB, r / 255.0f, g / 255.0f, b / 255.0f); if (iColorType == COLORTYPE_TRANSPARENT) - crRet = CPWL_Color(COLORTYPE_TRANSPARENT); + crRet = CFX_Color(COLORTYPE_TRANSPARENT); color::ConvertPWLColorToArray(pRuntime, crRet, &crArray); vp << crArray; @@ -2397,7 +2397,7 @@ bool Field::textColor(CJS_Runtime* pRuntime, void Field::SetTextColor(CPDFSDK_FormFillEnvironment* pFormFillEnv, const CFX_WideString& swFieldName, int nControlIndex, - const CPWL_Color& color) { + const CFX_Color& color) { // Not supported. } @@ -3231,7 +3231,7 @@ void Field::AddDelay_Rect(FIELD_PROP prop, const CFX_FloatRect& rect) { m_pJSDoc->AddDelayData(pNewData); } -void Field::AddDelay_Color(FIELD_PROP prop, const CPWL_Color& color) { +void Field::AddDelay_Color(FIELD_PROP prop, const CFX_Color& color) { CJS_DelayData* pNewData = new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName); pNewData->color = color; diff --git a/chromium/third_party/pdfium/fpdfsdk/javascript/Field.h b/chromium/third_party/pdfium/fpdfsdk/javascript/Field.h index 462c1271a16..1c8d6beac17 100644 --- a/chromium/third_party/pdfium/fpdfsdk/javascript/Field.h +++ b/chromium/third_party/pdfium/fpdfsdk/javascript/Field.h @@ -11,9 +11,9 @@ #include <vector> #include "core/fxcrt/cfx_observable.h" +#include "core/fxge/cfx_color.h" #include "fpdfsdk/cpdfsdk_formfillenvironment.h" #include "fpdfsdk/javascript/JS_Define.h" -#include "fpdfsdk/pdfwindow/PWL_Wnd.h" // For CPWL_Color. class CPDFSDK_Widget; class Document; @@ -67,7 +67,7 @@ struct CJS_DelayData { CFX_ByteString string; CFX_WideString widestring; CFX_FloatRect rect; - CPWL_Color color; + CFX_Color color; std::vector<uint32_t> wordarray; std::vector<CFX_WideString> widestringarray; }; @@ -385,7 +385,7 @@ class Field : public CJS_EmbedObj { static void SetFillColor(CPDFSDK_FormFillEnvironment* pFormFillEnv, const CFX_WideString& swFieldName, int nControlIndex, - const CPWL_Color& color); + const CFX_Color& color); static void SetHidden(CPDFSDK_FormFillEnvironment* pFormFillEnv, const CFX_WideString& swFieldName, int nControlIndex, @@ -421,7 +421,7 @@ class Field : public CJS_EmbedObj { static void SetStrokeColor(CPDFSDK_FormFillEnvironment* pFormFillEnv, const CFX_WideString& swFieldName, int nControlIndex, - const CPWL_Color& color); + const CFX_Color& color); static void SetStyle(CPDFSDK_FormFillEnvironment* pFormFillEnv, const CFX_WideString& swFieldName, int nControlIndex, @@ -429,7 +429,7 @@ class Field : public CJS_EmbedObj { static void SetTextColor(CPDFSDK_FormFillEnvironment* pFormFillEnv, const CFX_WideString& swFieldName, int nControlIndex, - const CPWL_Color& color); + const CFX_Color& color); static void SetTextFont(CPDFSDK_FormFillEnvironment* pFormFillEnv, const CFX_WideString& swFieldName, int nControlIndex, @@ -490,7 +490,7 @@ class Field : public CJS_EmbedObj { void AddDelay_String(FIELD_PROP prop, const CFX_ByteString& string); void AddDelay_WideString(FIELD_PROP prop, const CFX_WideString& string); void AddDelay_Rect(FIELD_PROP prop, const CFX_FloatRect& rect); - void AddDelay_Color(FIELD_PROP prop, const CPWL_Color& color); + void AddDelay_Color(FIELD_PROP prop, const CFX_Color& color); void AddDelay_WordArray(FIELD_PROP prop, const std::vector<uint32_t>& array); void AddDelay_WideStringArray(FIELD_PROP prop, const std::vector<CFX_WideString>& array); diff --git a/chromium/third_party/pdfium/fpdfsdk/javascript/JS_Define.h b/chromium/third_party/pdfium/fpdfsdk/javascript/JS_Define.h index fb901dc7148..f360e8f6b9d 100644 --- a/chromium/third_party/pdfium/fpdfsdk/javascript/JS_Define.h +++ b/chromium/third_party/pdfium/fpdfsdk/javascript/JS_Define.h @@ -173,14 +173,15 @@ void JSMethod(const char* method_name_string, static JSConstSpec ConstSpecs[]; \ static void DefineConsts(CFXJS_Engine* pEngine); -#define IMPLEMENT_JS_CLASS_CONST_PART(js_class_name, class_name) \ - void js_class_name::DefineConsts(CFXJS_Engine* pEngine) { \ - for (size_t i = 0; i < FX_ArraySize(ConstSpecs) - 1; ++i) { \ - pEngine->DefineObjConst(g_nObjDefnID, ConstSpecs[i].pName, \ - ConstSpecs[i].eType == JSConstSpec::Number \ - ? pEngine->NewNumber(ConstSpecs[i].number) \ - : pEngine->NewString(ConstSpecs[i].pStr)); \ - } \ +#define IMPLEMENT_JS_CLASS_CONST_PART(js_class_name, class_name) \ + void js_class_name::DefineConsts(CFXJS_Engine* pEngine) { \ + for (size_t i = 0; i < FX_ArraySize(ConstSpecs) - 1; ++i) { \ + pEngine->DefineObjConst( \ + g_nObjDefnID, ConstSpecs[i].pName, \ + ConstSpecs[i].eType == JSConstSpec::Number \ + ? pEngine->NewNumber(ConstSpecs[i].number).As<v8::Value>() \ + : pEngine->NewString(ConstSpecs[i].pStr).As<v8::Value>()); \ + } \ } // Convenience macros for declaring classes without an alternate. diff --git a/chromium/third_party/pdfium/fpdfsdk/javascript/JS_EventHandler.h b/chromium/third_party/pdfium/fpdfsdk/javascript/JS_EventHandler.h index 5dcb70b4c88..82d9d6a93b7 100644 --- a/chromium/third_party/pdfium/fpdfsdk/javascript/JS_EventHandler.h +++ b/chromium/third_party/pdfium/fpdfsdk/javascript/JS_EventHandler.h @@ -172,7 +172,7 @@ class CJS_EventHandler { CFX_WideString m_strTargetName; CFX_WideString m_strSourceName; - CFX_WideString* m_pWideStrChange; + CFX_UnownedPtr<CFX_WideString> m_pWideStrChange; CFX_WideString m_WideStrChangeDu; CFX_WideString m_WideStrChangeEx; int m_nCommitKey; @@ -184,12 +184,12 @@ class CJS_EventHandler { int* m_pISelStart; int m_nSelStartDu; bool m_bWillCommit; - CFX_WideString* m_pValue; + CFX_UnownedPtr<CFX_WideString> m_pValue; bool m_bFieldFull; bool* m_pbRc; bool m_bRcDu; - CPDF_Bookmark* m_pTargetBookMark; + CFX_UnownedPtr<CPDF_Bookmark> m_pTargetBookMark; CPDFSDK_FormFillEnvironment::ObservedPtr m_pTargetFormFillEnv; CPDFSDK_Annot::ObservedPtr m_pTargetAnnot; }; diff --git a/chromium/third_party/pdfium/fpdfsdk/javascript/JS_Value.cpp b/chromium/third_party/pdfium/fpdfsdk/javascript/JS_Value.cpp index dba0b761156..1b8f7f16aa3 100644 --- a/chromium/third_party/pdfium/fpdfsdk/javascript/JS_Value.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/javascript/JS_Value.cpp @@ -31,6 +31,166 @@ MakeDate(int year, int mon, int day, int hour, int min, int sec, int ms) { JS_MakeTime(hour, min, sec, ms)); } +double GetLocalTZA() { + if (!FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS)) + return 0; + time_t t = 0; + time(&t); + localtime(&t); +#if _MSC_VER >= 1900 + // In gcc and in Visual Studio prior to VS 2015 'timezone' is a global + // variable declared in time.h. That variable was deprecated and in VS 2015 + // is removed, with _get_timezone replacing it. + long timezone = 0; + _get_timezone(&timezone); +#endif + return (double)(-(timezone * 1000)); +} + +int GetDaylightSavingTA(double d) { + if (!FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS)) + return 0; + time_t t = (time_t)(d / 1000); + struct tm* tmp = localtime(&t); + if (!tmp) + return 0; + if (tmp->tm_isdst > 0) + // One hour. + return (int)60 * 60 * 1000; + return 0; +} + +double Mod(double x, double y) { + double r = fmod(x, y); + if (r < 0) + r += y; + return r; +} + +int IsFinite(double v) { +#if _MSC_VER + return ::_finite(v); +#else + return std::fabs(v) < std::numeric_limits<double>::max(); +#endif +} + +double ToInteger(double n) { + return (n >= 0) ? floor(n) : -floor(-n); +} + +bool IsLeapYear(int year) { + return (year % 4 == 0) && ((year % 100 != 0) || (year % 400 != 0)); +} + +int DayFromYear(int y) { + return (int)(365 * (y - 1970.0) + floor((y - 1969.0) / 4) - + floor((y - 1901.0) / 100) + floor((y - 1601.0) / 400)); +} + +double TimeFromYear(int y) { + return 86400000.0 * DayFromYear(y); +} + +static const uint16_t daysMonth[12] = {0, 31, 59, 90, 120, 151, + 181, 212, 243, 273, 304, 334}; +static const uint16_t leapDaysMonth[12] = {0, 31, 60, 91, 121, 152, + 182, 213, 244, 274, 305, 335}; + +double TimeFromYearMonth(int y, int m) { + const uint16_t* pMonth = IsLeapYear(y) ? leapDaysMonth : daysMonth; + return TimeFromYear(y) + ((double)pMonth[m]) * 86400000; +} + +int Day(double t) { + return (int)floor(t / 86400000); +} + +int YearFromTime(double t) { + // estimate the time. + int y = 1970 + static_cast<int>(t / (365.2425 * 86400000)); + if (TimeFromYear(y) <= t) { + while (TimeFromYear(y + 1) <= t) + y++; + } else { + while (TimeFromYear(y) > t) + y--; + } + return y; +} + +int DayWithinYear(double t) { + int year = YearFromTime(t); + int day = Day(t); + return day - DayFromYear(year); +} + +int MonthFromTime(double t) { + int day = DayWithinYear(t); + int year = YearFromTime(t); + if (0 <= day && day < 31) + return 0; + if (31 <= day && day < 59 + IsLeapYear(year)) + return 1; + if ((59 + IsLeapYear(year)) <= day && day < (90 + IsLeapYear(year))) + return 2; + if ((90 + IsLeapYear(year)) <= day && day < (120 + IsLeapYear(year))) + return 3; + if ((120 + IsLeapYear(year)) <= day && day < (151 + IsLeapYear(year))) + return 4; + if ((151 + IsLeapYear(year)) <= day && day < (181 + IsLeapYear(year))) + return 5; + if ((181 + IsLeapYear(year)) <= day && day < (212 + IsLeapYear(year))) + return 6; + if ((212 + IsLeapYear(year)) <= day && day < (243 + IsLeapYear(year))) + return 7; + if ((243 + IsLeapYear(year)) <= day && day < (273 + IsLeapYear(year))) + return 8; + if ((273 + IsLeapYear(year)) <= day && day < (304 + IsLeapYear(year))) + return 9; + if ((304 + IsLeapYear(year)) <= day && day < (334 + IsLeapYear(year))) + return 10; + if ((334 + IsLeapYear(year)) <= day && day < (365 + IsLeapYear(year))) + return 11; + + return -1; +} + +int DateFromTime(double t) { + int day = DayWithinYear(t); + int year = YearFromTime(t); + int leap = IsLeapYear(year); + int month = MonthFromTime(t); + switch (month) { + case 0: + return day + 1; + case 1: + return day - 30; + case 2: + return day - 58 - leap; + case 3: + return day - 89 - leap; + case 4: + return day - 119 - leap; + case 5: + return day - 150 - leap; + case 6: + return day - 180 - leap; + case 7: + return day - 211 - leap; + case 8: + return day - 242 - leap; + case 9: + return day - 272 - leap; + case 10: + return day - 303 - leap; + case 11: + return day - 333 - leap; + default: + return 0; + } +} + } // namespace CJS_Value::CJS_Value(CJS_Runtime* pRuntime) {} @@ -456,166 +616,6 @@ v8::Local<v8::Date> CJS_Date::ToV8Date(CJS_Runtime* pRuntime) const { return m_pDate; } -double _getLocalTZA() { - if (!FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS)) - return 0; - time_t t = 0; - time(&t); - localtime(&t); -#if _MSC_VER >= 1900 - // In gcc and in Visual Studio prior to VS 2015 'timezone' is a global - // variable declared in time.h. That variable was deprecated and in VS 2015 - // is removed, with _get_timezone replacing it. - long timezone = 0; - _get_timezone(&timezone); -#endif - return (double)(-(timezone * 1000)); -} - -int _getDaylightSavingTA(double d) { - if (!FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS)) - return 0; - time_t t = (time_t)(d / 1000); - struct tm* tmp = localtime(&t); - if (!tmp) - return 0; - if (tmp->tm_isdst > 0) - // One hour. - return (int)60 * 60 * 1000; - return 0; -} - -double _Mod(double x, double y) { - double r = fmod(x, y); - if (r < 0) - r += y; - return r; -} - -int _isfinite(double v) { -#if _MSC_VER - return ::_finite(v); -#else - return std::fabs(v) < std::numeric_limits<double>::max(); -#endif -} - -double _toInteger(double n) { - return (n >= 0) ? floor(n) : -floor(-n); -} - -bool _isLeapYear(int year) { - return (year % 4 == 0) && ((year % 100 != 0) || (year % 400 != 0)); -} - -int _DayFromYear(int y) { - return (int)(365 * (y - 1970.0) + floor((y - 1969.0) / 4) - - floor((y - 1901.0) / 100) + floor((y - 1601.0) / 400)); -} - -double _TimeFromYear(int y) { - return 86400000.0 * _DayFromYear(y); -} - -static const uint16_t daysMonth[12] = {0, 31, 59, 90, 120, 151, - 181, 212, 243, 273, 304, 334}; -static const uint16_t leapDaysMonth[12] = {0, 31, 60, 91, 121, 152, - 182, 213, 244, 274, 305, 335}; - -double _TimeFromYearMonth(int y, int m) { - const uint16_t* pMonth = _isLeapYear(y) ? leapDaysMonth : daysMonth; - return _TimeFromYear(y) + ((double)pMonth[m]) * 86400000; -} - -int _Day(double t) { - return (int)floor(t / 86400000); -} - -int _YearFromTime(double t) { - // estimate the time. - int y = 1970 + static_cast<int>(t / (365.2425 * 86400000)); - if (_TimeFromYear(y) <= t) { - while (_TimeFromYear(y + 1) <= t) - y++; - } else { - while (_TimeFromYear(y) > t) - y--; - } - return y; -} - -int _DayWithinYear(double t) { - int year = _YearFromTime(t); - int day = _Day(t); - return day - _DayFromYear(year); -} - -int _MonthFromTime(double t) { - int day = _DayWithinYear(t); - int year = _YearFromTime(t); - if (0 <= day && day < 31) - return 0; - if (31 <= day && day < 59 + _isLeapYear(year)) - return 1; - if ((59 + _isLeapYear(year)) <= day && day < (90 + _isLeapYear(year))) - return 2; - if ((90 + _isLeapYear(year)) <= day && day < (120 + _isLeapYear(year))) - return 3; - if ((120 + _isLeapYear(year)) <= day && day < (151 + _isLeapYear(year))) - return 4; - if ((151 + _isLeapYear(year)) <= day && day < (181 + _isLeapYear(year))) - return 5; - if ((181 + _isLeapYear(year)) <= day && day < (212 + _isLeapYear(year))) - return 6; - if ((212 + _isLeapYear(year)) <= day && day < (243 + _isLeapYear(year))) - return 7; - if ((243 + _isLeapYear(year)) <= day && day < (273 + _isLeapYear(year))) - return 8; - if ((273 + _isLeapYear(year)) <= day && day < (304 + _isLeapYear(year))) - return 9; - if ((304 + _isLeapYear(year)) <= day && day < (334 + _isLeapYear(year))) - return 10; - if ((334 + _isLeapYear(year)) <= day && day < (365 + _isLeapYear(year))) - return 11; - - return -1; -} - -int _DateFromTime(double t) { - int day = _DayWithinYear(t); - int year = _YearFromTime(t); - int leap = _isLeapYear(year); - int month = _MonthFromTime(t); - switch (month) { - case 0: - return day + 1; - case 1: - return day - 30; - case 2: - return day - 58 - leap; - case 3: - return day - 89 - leap; - case 4: - return day - 119 - leap; - case 5: - return day - 150 - leap; - case 6: - return day - 180 - leap; - case 7: - return day - 211 - leap; - case 8: - return day - 242 - leap; - case 9: - return day - 272 - leap; - case 10: - return day - 303 - leap; - case 11: - return day - 333 - leap; - default: - return 0; - } -} - double JS_GetDateTime() { if (!FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS)) return 0; @@ -623,34 +623,34 @@ double JS_GetDateTime() { struct tm* pTm = localtime(&t); int year = pTm->tm_year + 1900; - double t1 = _TimeFromYear(year); + double t1 = TimeFromYear(year); return t1 + pTm->tm_yday * 86400000.0 + pTm->tm_hour * 3600000.0 + pTm->tm_min * 60000.0 + pTm->tm_sec * 1000.0; } int JS_GetYearFromTime(double dt) { - return _YearFromTime(dt); + return YearFromTime(dt); } int JS_GetMonthFromTime(double dt) { - return _MonthFromTime(dt); + return MonthFromTime(dt); } int JS_GetDayFromTime(double dt) { - return _DateFromTime(dt); + return DateFromTime(dt); } int JS_GetHourFromTime(double dt) { - return (int)_Mod(floor(dt / (60 * 60 * 1000)), 24); + return (int)Mod(floor(dt / (60 * 60 * 1000)), 24); } int JS_GetMinFromTime(double dt) { - return (int)_Mod(floor(dt / (60 * 1000)), 60); + return (int)Mod(floor(dt / (60 * 1000)), 60); } int JS_GetSecFromTime(double dt) { - return (int)_Mod(floor(dt / 1000), 60); + return (int)Mod(floor(dt / 1000), 60); } double JS_DateParse(const CFX_WideString& str) { @@ -683,7 +683,7 @@ double JS_DateParse(const CFX_WideString& str) { v = funC->Call(context, context->Global(), argc, argv).ToLocalChecked(); if (v->IsNumber()) { double date = v->ToNumber(context).ToLocalChecked()->Value(); - if (!_isfinite(date)) + if (!IsFinite(date)) return date; return JS_LocalTime(date); } @@ -693,37 +693,35 @@ double JS_DateParse(const CFX_WideString& str) { } double JS_MakeDay(int nYear, int nMonth, int nDate) { - if (!_isfinite(nYear) || !_isfinite(nMonth) || !_isfinite(nDate)) + if (!IsFinite(nYear) || !IsFinite(nMonth) || !IsFinite(nDate)) return GetNan(); - double y = _toInteger(nYear); - double m = _toInteger(nMonth); - double dt = _toInteger(nDate); + double y = ToInteger(nYear); + double m = ToInteger(nMonth); + double dt = ToInteger(nDate); double ym = y + floor((double)m / 12); - double mn = _Mod(m, 12); + double mn = Mod(m, 12); - double t = _TimeFromYearMonth((int)ym, (int)mn); + double t = TimeFromYearMonth((int)ym, (int)mn); - if (_YearFromTime(t) != ym || _MonthFromTime(t) != mn || - _DateFromTime(t) != 1) + if (YearFromTime(t) != ym || MonthFromTime(t) != mn || DateFromTime(t) != 1) return GetNan(); - return _Day(t) + dt - 1; + return Day(t) + dt - 1; } double JS_MakeTime(int nHour, int nMin, int nSec, int nMs) { - if (!_isfinite(nHour) || !_isfinite(nMin) || !_isfinite(nSec) || - !_isfinite(nMs)) + if (!IsFinite(nHour) || !IsFinite(nMin) || !IsFinite(nSec) || !IsFinite(nMs)) return GetNan(); - double h = _toInteger(nHour); - double m = _toInteger(nMin); - double s = _toInteger(nSec); - double milli = _toInteger(nMs); + double h = ToInteger(nHour); + double m = ToInteger(nMin); + double s = ToInteger(nSec); + double milli = ToInteger(nMs); return h * 3600000 + m * 60000 + s * 1000 + milli; } double JS_MakeDate(double day, double time) { - if (!_isfinite(day) || !_isfinite(time)) + if (!IsFinite(day) || !IsFinite(time)) return GetNan(); return day * 86400000 + time; @@ -734,7 +732,7 @@ bool JS_PortIsNan(double d) { } double JS_LocalTime(double d) { - return d + _getLocalTZA() + _getDaylightSavingTA(d); + return d + GetLocalTZA() + GetDaylightSavingTA(d); } std::vector<CJS_Value> JS_ExpandKeywordParams( diff --git a/chromium/third_party/pdfium/fpdfsdk/javascript/PublicMethods.cpp b/chromium/third_party/pdfium/fpdfsdk/javascript/PublicMethods.cpp index 2efcacdde9c..bdae064cea0 100644 --- a/chromium/third_party/pdfium/fpdfsdk/javascript/PublicMethods.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/javascript/PublicMethods.cpp @@ -875,8 +875,8 @@ bool CJS_PublicMethods::AFNumber_Format(CJS_Runtime* pRuntime, CJS_Array aProp; vProp.GetJSValue()->ConvertToArray(pRuntime, aProp); - CPWL_Color crProp; - CPWL_Color crColor; + CFX_Color crProp; + CFX_Color crColor; color::ConvertArrayToPWLColor(pRuntime, aProp, &crProp); color::ConvertArrayToPWLColor(pRuntime, arColor, &crColor); diff --git a/chromium/third_party/pdfium/fpdfsdk/javascript/app.cpp b/chromium/third_party/pdfium/fpdfsdk/javascript/app.cpp index c9d7c3fd501..246db66234f 100644 --- a/chromium/third_party/pdfium/fpdfsdk/javascript/app.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/javascript/app.cpp @@ -234,11 +234,10 @@ bool app::calculate(CJS_Runtime* pRuntime, if (vp.IsSetting()) { bool bVP; vp >> bVP; - m_bCalculate = (bool)bVP; - pRuntime->GetFormFillEnv()->GetInterForm()->EnableCalculate( - (bool)m_bCalculate); + m_bCalculate = bVP; + pRuntime->GetFormFillEnv()->GetInterForm()->EnableCalculate(m_bCalculate); } else { - vp << (bool)m_bCalculate; + vp << m_bCalculate; } return true; } diff --git a/chromium/third_party/pdfium/fpdfsdk/javascript/cjs_runtime.cpp b/chromium/third_party/pdfium/fpdfsdk/javascript/cjs_runtime.cpp index cb8f69f9da0..515bdcb65f5 100644 --- a/chromium/third_party/pdfium/fpdfsdk/javascript/cjs_runtime.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/javascript/cjs_runtime.cpp @@ -218,19 +218,16 @@ CFX_WideString ChangeObjName(const CFX_WideString& str) { sRet.Replace(L"_", L"."); return sRet; } + bool CJS_Runtime::GetValueByName(const CFX_ByteStringC& utf8Name, CFXJSE_Value* pValue) { - const char* name = utf8Name.c_str(); - v8::Isolate::Scope isolate_scope(GetIsolate()); v8::HandleScope handle_scope(GetIsolate()); v8::Local<v8::Context> context = NewLocalContext(); v8::Context::Scope context_scope(context); - - v8::Local<v8::Value> propvalue = - context->Global()->Get(v8::String::NewFromUtf8( - GetIsolate(), name, v8::String::kNormalString, utf8Name.GetLength())); - + v8::Local<v8::Value> propvalue = context->Global()->Get( + v8::String::NewFromUtf8(GetIsolate(), utf8Name.unterminated_c_str(), + v8::String::kNormalString, utf8Name.GetLength())); if (propvalue.IsEmpty()) { pValue->SetUndefined(); return false; @@ -238,24 +235,22 @@ bool CJS_Runtime::GetValueByName(const CFX_ByteStringC& utf8Name, pValue->ForceSetValue(propvalue); return true; } + bool CJS_Runtime::SetValueByName(const CFX_ByteStringC& utf8Name, CFXJSE_Value* pValue) { if (utf8Name.IsEmpty() || !pValue) return false; - const char* name = utf8Name.c_str(); + v8::Isolate* pIsolate = GetIsolate(); v8::Isolate::Scope isolate_scope(pIsolate); v8::HandleScope handle_scope(pIsolate); v8::Local<v8::Context> context = NewLocalContext(); v8::Context::Scope context_scope(context); - - // v8::Local<v8::Context> tmpCotext = - // v8::Local<v8::Context>::New(GetIsolate(), m_context); v8::Local<v8::Value> propvalue = v8::Local<v8::Value>::New(GetIsolate(), pValue->DirectGetValue()); context->Global()->Set( - v8::String::NewFromUtf8(pIsolate, name, v8::String::kNormalString, - utf8Name.GetLength()), + v8::String::NewFromUtf8(pIsolate, utf8Name.unterminated_c_str(), + v8::String::kNormalString, utf8Name.GetLength()), propvalue); return true; } diff --git a/chromium/third_party/pdfium/fpdfsdk/javascript/color.cpp b/chromium/third_party/pdfium/fpdfsdk/javascript/color.cpp index 376eefa248d..7bf3cc9c6f4 100644 --- a/chromium/third_party/pdfium/fpdfsdk/javascript/color.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/javascript/color.cpp @@ -39,24 +39,24 @@ JSMethodSpec CJS_Color::MethodSpecs[] = {{"convert", convert_static}, IMPLEMENT_JS_CLASS(CJS_Color, color) color::color(CJS_Object* pJSObject) : CJS_EmbedObj(pJSObject) { - m_crTransparent = CPWL_Color(COLORTYPE_TRANSPARENT); - m_crBlack = CPWL_Color(COLORTYPE_GRAY, 0); - m_crWhite = CPWL_Color(COLORTYPE_GRAY, 1); - m_crRed = CPWL_Color(COLORTYPE_RGB, 1, 0, 0); - m_crGreen = CPWL_Color(COLORTYPE_RGB, 0, 1, 0); - m_crBlue = CPWL_Color(COLORTYPE_RGB, 0, 0, 1); - m_crCyan = CPWL_Color(COLORTYPE_CMYK, 1, 0, 0, 0); - m_crMagenta = CPWL_Color(COLORTYPE_CMYK, 0, 1, 0, 0); - m_crYellow = CPWL_Color(COLORTYPE_CMYK, 0, 0, 1, 0); - m_crDKGray = CPWL_Color(COLORTYPE_GRAY, 0.25); - m_crGray = CPWL_Color(COLORTYPE_GRAY, 0.5); - m_crLTGray = CPWL_Color(COLORTYPE_GRAY, 0.75); + m_crTransparent = CFX_Color(COLORTYPE_TRANSPARENT); + m_crBlack = CFX_Color(COLORTYPE_GRAY, 0); + m_crWhite = CFX_Color(COLORTYPE_GRAY, 1); + m_crRed = CFX_Color(COLORTYPE_RGB, 1, 0, 0); + m_crGreen = CFX_Color(COLORTYPE_RGB, 0, 1, 0); + m_crBlue = CFX_Color(COLORTYPE_RGB, 0, 0, 1); + m_crCyan = CFX_Color(COLORTYPE_CMYK, 1, 0, 0, 0); + m_crMagenta = CFX_Color(COLORTYPE_CMYK, 0, 1, 0, 0); + m_crYellow = CFX_Color(COLORTYPE_CMYK, 0, 0, 1, 0); + m_crDKGray = CFX_Color(COLORTYPE_GRAY, 0.25); + m_crGray = CFX_Color(COLORTYPE_GRAY, 0.5); + m_crLTGray = CFX_Color(COLORTYPE_GRAY, 0.75); } color::~color() {} void color::ConvertPWLColorToArray(CJS_Runtime* pRuntime, - const CPWL_Color& color, + const CFX_Color& color, CJS_Array* array) { switch (color.nColorType) { case COLORTYPE_TRANSPARENT: @@ -84,7 +84,7 @@ void color::ConvertPWLColorToArray(CJS_Runtime* pRuntime, void color::ConvertArrayToPWLColor(CJS_Runtime* pRuntime, const CJS_Array& array, - CPWL_Color* color) { + CFX_Color* color) { int nArrayLen = array.GetLength(pRuntime); if (nArrayLen < 1) return; @@ -119,14 +119,14 @@ void color::ConvertArrayToPWLColor(CJS_Runtime* pRuntime, } if (sSpace == "T") { - *color = CPWL_Color(COLORTYPE_TRANSPARENT); + *color = CFX_Color(COLORTYPE_TRANSPARENT); } else if (sSpace == "G") { - *color = CPWL_Color(COLORTYPE_GRAY, (float)d1); + *color = CFX_Color(COLORTYPE_GRAY, (float)d1); } else if (sSpace == "RGB") { - *color = CPWL_Color(COLORTYPE_RGB, (float)d1, (float)d2, (float)d3); + *color = CFX_Color(COLORTYPE_RGB, (float)d1, (float)d2, (float)d3); } else if (sSpace == "CMYK") { *color = - CPWL_Color(COLORTYPE_CMYK, (float)d1, (float)d2, (float)d3, (float)d4); + CFX_Color(COLORTYPE_CMYK, (float)d1, (float)d2, (float)d3, (float)d4); } } @@ -204,7 +204,7 @@ bool color::ltGray(CJS_Runtime* pRuntime, bool color::PropertyHelper(CJS_Runtime* pRuntime, CJS_PropValue& vp, - CPWL_Color* var) { + CFX_Color* var) { CJS_Array array; if (vp.IsGetting()) { ConvertPWLColorToArray(pRuntime, *var, &array); @@ -230,7 +230,7 @@ bool color::convert(CJS_Runtime* pRuntime, if (!params[0].ConvertToArray(pRuntime, aSource)) return false; - CPWL_Color crSource; + CFX_Color crSource; ConvertArrayToPWLColor(pRuntime, aSource, &crSource); CFX_ByteString sDestSpace = params[1].ToCFXByteString(pRuntime); @@ -247,7 +247,7 @@ bool color::convert(CJS_Runtime* pRuntime, } CJS_Array aDest; - CPWL_Color crDest = crSource.ConvertColorType(nColorType); + CFX_Color crDest = crSource.ConvertColorType(nColorType); ConvertPWLColorToArray(pRuntime, crDest, &aDest); vRet = CJS_Value(pRuntime, aDest); @@ -268,8 +268,8 @@ bool color::equal(CJS_Runtime* pRuntime, if (!params[1].ConvertToArray(pRuntime, array2)) return false; - CPWL_Color color1; - CPWL_Color color2; + CFX_Color color1; + CFX_Color color2; ConvertArrayToPWLColor(pRuntime, array1, &color1); ConvertArrayToPWLColor(pRuntime, array2, &color2); color1 = color1.ConvertColorType(color2.nColorType); diff --git a/chromium/third_party/pdfium/fpdfsdk/javascript/color.h b/chromium/third_party/pdfium/fpdfsdk/javascript/color.h index 8d6187a1784..e67d4d5ad5b 100644 --- a/chromium/third_party/pdfium/fpdfsdk/javascript/color.h +++ b/chromium/third_party/pdfium/fpdfsdk/javascript/color.h @@ -10,7 +10,7 @@ #include <vector> #include "fpdfsdk/javascript/JS_Define.h" -#include "fpdfsdk/pdfwindow/PWL_Wnd.h" +#include "fpdfsdk/pdfwindow/cpwl_wnd.h" class color : public CJS_EmbedObj { public: @@ -44,29 +44,27 @@ class color : public CJS_EmbedObj { CFX_WideString& sError); static void ConvertPWLColorToArray(CJS_Runtime* pRuntime, - const CPWL_Color& color, + const CFX_Color& color, CJS_Array* array); static void ConvertArrayToPWLColor(CJS_Runtime* pRuntime, const CJS_Array& array, - CPWL_Color* color); + CFX_Color* color); private: - bool PropertyHelper(CJS_Runtime* pRuntime, - CJS_PropValue& vp, - CPWL_Color* val); + bool PropertyHelper(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_Color* val); - CPWL_Color m_crTransparent; - CPWL_Color m_crBlack; - CPWL_Color m_crWhite; - CPWL_Color m_crRed; - CPWL_Color m_crGreen; - CPWL_Color m_crBlue; - CPWL_Color m_crCyan; - CPWL_Color m_crMagenta; - CPWL_Color m_crYellow; - CPWL_Color m_crDKGray; - CPWL_Color m_crGray; - CPWL_Color m_crLTGray; + CFX_Color m_crTransparent; + CFX_Color m_crBlack; + CFX_Color m_crWhite; + CFX_Color m_crRed; + CFX_Color m_crGreen; + CFX_Color m_crBlue; + CFX_Color m_crCyan; + CFX_Color m_crMagenta; + CFX_Color m_crYellow; + CFX_Color m_crDKGray; + CFX_Color m_crGray; + CFX_Color m_crLTGray; }; class CJS_Color : public CJS_Object { diff --git a/chromium/third_party/pdfium/fpdfsdk/javascript/util.cpp b/chromium/third_party/pdfium/fpdfsdk/javascript/util.cpp index bc968a59d92..93e178e9b7e 100644 --- a/chromium/third_party/pdfium/fpdfsdk/javascript/util.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/javascript/util.cpp @@ -38,10 +38,6 @@ JSMethodSpec CJS_Util::MethodSpecs[] = { IMPLEMENT_JS_CLASS(CJS_Util, util) -#define UTIL_INT 0 -#define UTIL_DOUBLE 1 -#define UTIL_STRING 2 - namespace { // Map PDF-style directives to equivalent wcsftime directives. Not @@ -70,40 +66,6 @@ const TbConvert TbConvertTable[] = { #endif }; -int ParseDataType(std::wstring* sFormat) { - bool bPercent = false; - for (size_t i = 0; i < sFormat->length(); ++i) { - wchar_t c = (*sFormat)[i]; - if (c == L'%') { - bPercent = true; - continue; - } - - if (bPercent) { - if (c == L'c' || c == L'C' || c == L'd' || c == L'i' || c == L'o' || - c == L'u' || c == L'x' || c == L'X') { - return UTIL_INT; - } - if (c == L'e' || c == L'E' || c == L'f' || c == L'g' || c == L'G') { - return UTIL_DOUBLE; - } - if (c == L's' || c == L'S') { - // Map s to S since we always deal internally - // with wchar_t strings. - (*sFormat)[i] = L'S'; - return UTIL_STRING; - } - if (c == L'.' || c == L'+' || c == L'-' || c == L'#' || c == L' ' || - std::iswdigit(c)) { - continue; - } - break; - } - } - - return -1; -} - } // namespace util::util(CJS_Object* pJSObject) : CJS_EmbedObj(pJSObject) {} @@ -118,26 +80,26 @@ bool util::printf(CJS_Runtime* pRuntime, if (iSize < 1) return false; - std::wstring c_ConvChar(params[0].ToCFXWideString(pRuntime).c_str()); - std::vector<std::wstring> c_strConvers; + std::wstring unsafe_fmt_string(params[0].ToCFXWideString(pRuntime).c_str()); + std::vector<std::wstring> unsafe_conversion_specifiers; int iOffset = 0; int iOffend = 0; - c_ConvChar.insert(c_ConvChar.begin(), L'S'); + unsafe_fmt_string.insert(unsafe_fmt_string.begin(), L'S'); while (iOffset != -1) { - iOffend = c_ConvChar.find(L"%", iOffset + 1); + iOffend = unsafe_fmt_string.find(L"%", iOffset + 1); std::wstring strSub; if (iOffend == -1) - strSub = c_ConvChar.substr(iOffset); + strSub = unsafe_fmt_string.substr(iOffset); else - strSub = c_ConvChar.substr(iOffset, iOffend - iOffset); - c_strConvers.push_back(strSub); + strSub = unsafe_fmt_string.substr(iOffset, iOffend - iOffset); + unsafe_conversion_specifiers.push_back(strSub); iOffset = iOffend; } std::wstring c_strResult; - std::wstring c_strFormat; - for (size_t iIndex = 0; iIndex < c_strConvers.size(); ++iIndex) { - c_strFormat = c_strConvers[iIndex]; + for (size_t iIndex = 0; iIndex < unsafe_conversion_specifiers.size(); + ++iIndex) { + std::wstring c_strFormat = unsafe_conversion_specifiers[iIndex]; if (iIndex == 0) { c_strResult = c_strFormat; continue; @@ -162,10 +124,10 @@ bool util::printf(CJS_Runtime* pRuntime, params[iIndex].ToCFXWideString(pRuntime).c_str()); break; default: - strSegment.Format(L"%S", c_strFormat.c_str()); + strSegment.Format(L"%ls", c_strFormat.c_str()); break; } - c_strResult += strSegment.GetBuffer(strSegment.GetLength() + 1); + c_strResult += strSegment.c_str(); } c_strResult.erase(c_strResult.begin()); @@ -250,24 +212,26 @@ bool util::printd(CJS_Runtime* pRuntime, } int iYear = jsDate.GetYear(pRuntime); + if (iYear < 0) { + sError = JSGetStringFromID(IDS_STRING_JSVALUEERROR); + return false; + } + int iMonth = jsDate.GetMonth(pRuntime); int iDay = jsDate.GetDay(pRuntime); int iHour = jsDate.GetHours(pRuntime); int iMin = jsDate.GetMinutes(pRuntime); int iSec = jsDate.GetSeconds(pRuntime); - TbConvertAdditional cTableAd[] = { + static const TbConvertAdditional cTableAd[] = { {L"m", iMonth + 1}, {L"d", iDay}, {L"H", iHour}, {L"h", iHour > 12 ? iHour - 12 : iHour}, {L"M", iMin}, {L"s", iSec}, }; for (size_t i = 0; i < FX_ArraySize(cTableAd); ++i) { - wchar_t tszValue[16]; CFX_WideString sValue; sValue.Format(L"%d", cTableAd[i].iValue); - memcpy(tszValue, (wchar_t*)sValue.GetBuffer(sValue.GetLength() + 1), - (sValue.GetLength() + 1) * sizeof(wchar_t)); int iStart = 0; int iEnd; @@ -278,7 +242,8 @@ bool util::printd(CJS_Runtime* pRuntime, continue; } } - cFormat.replace(iEnd, FXSYS_wcslen(cTableAd[i].lpszJSMark), tszValue); + cFormat.replace(iEnd, FXSYS_wcslen(cTableAd[i].lpszJSMark), + sValue.c_str()); iStart = iEnd; } } @@ -292,7 +257,7 @@ bool util::printd(CJS_Runtime* pRuntime, time.tm_sec = iSec; wchar_t buf[64] = {}; - wcsftime(buf, 64, cFormat.c_str(), &time); + FXSYS_wcsftime(buf, 64, cFormat.c_str(), &time); cFormat = buf; vRet = CJS_Value(pRuntime, cFormat.c_str()); return true; @@ -458,3 +423,85 @@ bool util::byteToChar(CJS_Runtime* pRuntime, vRet = CJS_Value(pRuntime, wStr.c_str()); return true; } + +// Ensure that sFormat contains at most one well-understood printf formatting +// directive which is safe to use with a single argument, and return the type +// of argument expected, or -1 otherwise. If -1 is returned, it is NOT safe +// to use sFormat with printf() and it must be copied byte-by-byte. +int util::ParseDataType(std::wstring* sFormat) { + enum State { BEFORE, FLAGS, WIDTH, PRECISION, SPECIFIER, AFTER }; + + int result = -1; + State state = BEFORE; + size_t precision_digits = 0; + size_t i = 0; + while (i < sFormat->length()) { + wchar_t c = (*sFormat)[i]; + switch (state) { + case BEFORE: + if (c == L'%') + state = FLAGS; + break; + case FLAGS: + if (c == L'+' || c == L'-' || c == L'#' || c == L' ') { + // Stay in same state. + } else { + state = WIDTH; + continue; // Re-process same character. + } + break; + case WIDTH: + if (c == L'*') + return -1; + if (std::iswdigit(c)) { + // Stay in same state. + } else if (c == L'.') { + state = PRECISION; + } else { + state = SPECIFIER; + continue; // Re-process same character. + } + break; + case PRECISION: + if (c == L'*') + return -1; + if (std::iswdigit(c)) { + // Stay in same state. + ++precision_digits; + } else { + state = SPECIFIER; + continue; // Re-process same character. + } + break; + case SPECIFIER: + if (c == L'c' || c == L'C' || c == L'd' || c == L'i' || c == L'o' || + c == L'u' || c == L'x' || c == L'X') { + result = UTIL_INT; + } else if (c == L'e' || c == L'E' || c == L'f' || c == L'g' || + c == L'G') { + result = UTIL_DOUBLE; + } else if (c == L's' || c == L'S') { + // Map s to S since we always deal internally with wchar_t strings. + // TODO(tsepez): Probably 100% borked. %S is not a standard + // conversion. + (*sFormat)[i] = L'S'; + result = UTIL_STRING; + } else { + return -1; + } + state = AFTER; + break; + case AFTER: + if (c == L'%') + return -1; + // Stay in same state until string exhausted. + break; + } + ++i; + } + // See https://crbug.com/740166 + if (result == UTIL_INT && precision_digits > 2) + return -1; + + return result; +} diff --git a/chromium/third_party/pdfium/fpdfsdk/javascript/util.h b/chromium/third_party/pdfium/fpdfsdk/javascript/util.h index 98761b6f30b..60fa631dadb 100644 --- a/chromium/third_party/pdfium/fpdfsdk/javascript/util.h +++ b/chromium/third_party/pdfium/fpdfsdk/javascript/util.h @@ -12,6 +12,11 @@ #include "fpdfsdk/javascript/JS_Define.h" +// Return values for ParseDataType() below. +#define UTIL_INT 0 +#define UTIL_DOUBLE 1 +#define UTIL_STRING 2 + class util : public CJS_EmbedObj { public: explicit util(CJS_Object* pJSObject); @@ -40,6 +45,11 @@ class util : public CJS_EmbedObj { static CFX_WideString printx(const CFX_WideString& cFormat, const CFX_WideString& cSource); + + private: + friend class CJS_Util_ParseDataType_Test; + + static int ParseDataType(std::wstring* sFormat); }; class CJS_Util : public CJS_Object { diff --git a/chromium/third_party/pdfium/fpdfsdk/javascript/util_unittest.cpp b/chromium/third_party/pdfium/fpdfsdk/javascript/util_unittest.cpp new file mode 100644 index 00000000000..8e28dc1bdca --- /dev/null +++ b/chromium/third_party/pdfium/fpdfsdk/javascript/util_unittest.cpp @@ -0,0 +1,113 @@ +// Copyright 2017 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. + +#include "fpdfsdk/javascript/util.h" + +#include "testing/gtest/include/gtest/gtest.h" +#include "testing/test_support.h" + +TEST(CJS_Util, ParseDataType) { + struct ParseDataTypeCase { + const wchar_t* const input_string; + const int expected; + }; + + // Commented out tests follow the spec but are not passing. + const ParseDataTypeCase cases[] = { + // Not conversions + {L"", -1}, + {L"d", -1}, + + // Simple cases + {L"%d", UTIL_INT}, + {L"%x", UTIL_INT}, + {L"%f", UTIL_DOUBLE}, + {L"%s", UTIL_STRING}, + + // nDecSep Not implemented + // {L"%,0d", UTIL_INT}, + // {L"%,1d", UTIL_INT}, + // {L"%,2d", UTIL_INT}, + // {L"%,3d", UTIL_INT}, + // {L"%,4d", -1}, + // {L"%,d", -1}, + + // cFlags("+ 0#"") are only valid for numeric conversions. + {L"%+d", UTIL_INT}, + {L"%+x", UTIL_INT}, + {L"%+f", UTIL_DOUBLE}, + // {L"%+s", -1}, + {L"% d", UTIL_INT}, + {L"% x", UTIL_INT}, + {L"% f", UTIL_DOUBLE}, + // {L"% s", -1}, + {L"%0d", UTIL_INT}, + {L"%0x", UTIL_INT}, + {L"%0f", UTIL_DOUBLE}, + // {L"%0s", -1}, + {L"%#d", UTIL_INT}, + {L"%#x", UTIL_INT}, + {L"%#f", UTIL_DOUBLE}, + // {L"%#s", -1}, + + // nWidth should work. for all conversions, can be combined with cFlags=0 + // for numbers. + {L"%5d", UTIL_INT}, + {L"%05d", UTIL_INT}, + {L"%5x", UTIL_INT}, + {L"%05x", UTIL_INT}, + {L"%5f", UTIL_DOUBLE}, + {L"%05f", UTIL_DOUBLE}, + {L"%5s", UTIL_STRING}, + // {L"%05s", -1}, + + // nPrecision should only work for float + // {L"%.5d", -1}, + // {L"%.5x", -1}, + {L"%.5f", UTIL_DOUBLE}, + // {L"%.5s", -1}, + // {L"%.14d", -1}, + // {L"%.14x", -1}, + {L"%.14f", UTIL_DOUBLE}, + // {L"%.14s", -1}, + // {L"%.f", -1}, + + // See https://crbug.com/740166 + // nPrecision too large (> 260) causes crashes in Windows. + // Avoid this by limiting to two digits + {L"%.1d", UTIL_INT}, + {L"%.10d", UTIL_INT}, + {L"%.100d", -1}, + + // Unexpected characters + {L"%ad", -1}, + {L"%bx", -1}, + // {L"%cf", -1}, + // {L"%es", -1}, + // {L"%gd", -1}, + {L"%hx", -1}, + // {L"%if", -1}, + {L"%js", -1}, + {L"%@d", -1}, + {L"%~x", -1}, + {L"%[f", -1}, + {L"%\0s", -1}, + {L"%\nd", -1}, + {L"%\rx", -1}, + // {L"%%f", -1}, + // {L"% s", -1}, + + // Combine multiple valid components + {L"%+6d", UTIL_INT}, + {L"% 7x", UTIL_INT}, + {L"%#9.3f", UTIL_DOUBLE}, + {L"%10s", UTIL_STRING}, + }; + + for (size_t i = 0; i < FX_ArraySize(cases); i++) { + std::wstring input(cases[i].input_string); + EXPECT_EQ(cases[i].expected, util::ParseDataType(&input)) + << cases[i].input_string; + } +} diff --git a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/PWL_Caret.cpp b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/PWL_Caret.cpp deleted file mode 100644 index 3658fbc23ae..00000000000 --- a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/PWL_Caret.cpp +++ /dev/null @@ -1,147 +0,0 @@ -// Copyright 2014 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 "fpdfsdk/pdfwindow/PWL_Caret.h" - -#include "core/fxge/cfx_graphstatedata.h" -#include "core/fxge/cfx_pathdata.h" -#include "core/fxge/cfx_renderdevice.h" -#include "fpdfsdk/pdfwindow/PWL_Utils.h" -#include "fpdfsdk/pdfwindow/PWL_Wnd.h" - -#define PWL_CARET_FLASHINTERVAL 500 - -PWL_CARET_INFO::PWL_CARET_INFO() : bVisible(false) {} - -CPWL_Caret::CPWL_Caret() : m_bFlash(false), m_fWidth(0.4f), m_nDelay(0) {} - -CPWL_Caret::~CPWL_Caret() {} - -CFX_ByteString CPWL_Caret::GetClassName() const { - return "CPWL_Caret"; -} - -void CPWL_Caret::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) { - GetCaretApp(sAppStream, CFX_PointF()); -} - -void CPWL_Caret::DrawThisAppearance(CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device) { - if (IsVisible() && m_bFlash) { - CFX_FloatRect rcRect = GetCaretRect(); - CFX_FloatRect rcClip = GetClipRect(); - CFX_PathData path; - - float fCaretX = rcRect.left + m_fWidth * 0.5f; - float fCaretTop = rcRect.top; - float fCaretBottom = rcRect.bottom; - if (!rcClip.IsEmpty()) { - rcRect.Intersect(rcClip); - if (rcRect.IsEmpty()) - return; - - fCaretTop = rcRect.top; - fCaretBottom = rcRect.bottom; - } - - path.AppendPoint(CFX_PointF(fCaretX, fCaretBottom), FXPT_TYPE::MoveTo, - false); - path.AppendPoint(CFX_PointF(fCaretX, fCaretTop), FXPT_TYPE::LineTo, false); - - CFX_GraphStateData gsd; - gsd.m_LineWidth = m_fWidth; - pDevice->DrawPath(&path, pUser2Device, &gsd, 0, ArgbEncode(255, 0, 0, 0), - FXFILL_ALTERNATE); - } -} - -void CPWL_Caret::GetCaretApp(CFX_ByteTextBuf& sAppStream, - const CFX_PointF& ptOffset) { - if (IsVisible() && m_bFlash) { - CFX_ByteTextBuf sCaret; - - CFX_FloatRect rcRect = GetCaretRect(); - CFX_FloatRect rcClip = GetClipRect(); - - rcRect = CPWL_Utils::OffsetRect(rcRect, ptOffset.x, ptOffset.y); - rcClip = CPWL_Utils::OffsetRect(rcClip, ptOffset.x, ptOffset.y); - - sCaret << "q\n"; - if (!rcClip.IsEmpty()) { - sCaret << rcClip.left << " " << rcClip.bottom + 2.5f << " " - << rcClip.right - rcClip.left << " " - << rcClip.top - rcClip.bottom - 4.5f << " re W n\n"; - } - sCaret << m_fWidth << " w\n0 G\n"; - sCaret << rcRect.left + m_fWidth / 2 << " " << rcRect.bottom << " m\n"; - sCaret << rcRect.left + m_fWidth / 2 << " " << rcRect.top << " l S\nQ\n"; - - sAppStream << sCaret; - } -} - -CFX_ByteString CPWL_Caret::GetCaretAppearanceStream( - const CFX_PointF& ptOffset) { - CFX_ByteTextBuf sCaret; - GetCaretApp(sCaret, ptOffset); - return sCaret.MakeString(); -} - -void CPWL_Caret::TimerProc() { - if (m_nDelay > 0) { - m_nDelay--; - } else { - m_bFlash = !m_bFlash; - InvalidateRect(); - } -} - -CFX_FloatRect CPWL_Caret::GetCaretRect() const { - return CFX_FloatRect(m_ptFoot.x, m_ptFoot.y, m_ptHead.x + m_fWidth, - m_ptHead.y); -} - -void CPWL_Caret::SetCaret(bool bVisible, - const CFX_PointF& ptHead, - const CFX_PointF& ptFoot) { - if (bVisible) { - if (IsVisible()) { - if (m_ptHead != ptHead || m_ptFoot != ptFoot) { - m_ptHead = ptHead; - m_ptFoot = ptFoot; - m_bFlash = true; - Move(m_rcInvalid, false, true); - } - } else { - m_ptHead = ptHead; - m_ptFoot = ptFoot; - EndTimer(); - BeginTimer(PWL_CARET_FLASHINTERVAL); - CPWL_Wnd::SetVisible(true); - m_bFlash = true; - Move(m_rcInvalid, false, true); - } - } else { - m_ptHead = CFX_PointF(); - m_ptFoot = CFX_PointF(); - m_bFlash = false; - if (IsVisible()) { - EndTimer(); - CPWL_Wnd::SetVisible(false); - } - } -} - -void CPWL_Caret::InvalidateRect(CFX_FloatRect* pRect) { - if (pRect) { - CFX_FloatRect rcRefresh = CPWL_Utils::InflateRect(*pRect, 0.5f); - rcRefresh.top += 1; - rcRefresh.bottom -= 1; - CPWL_Wnd::InvalidateRect(&rcRefresh); - } else { - CPWL_Wnd::InvalidateRect(pRect); - } -} diff --git a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/PWL_ComboBox.cpp b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/PWL_ComboBox.cpp deleted file mode 100644 index b6c8d2f9218..00000000000 --- a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/PWL_ComboBox.cpp +++ /dev/null @@ -1,631 +0,0 @@ -// Copyright 2014 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 "fpdfsdk/pdfwindow/PWL_ComboBox.h" - -#include "core/fxge/cfx_pathdata.h" -#include "core/fxge/cfx_renderdevice.h" -#include "fpdfsdk/fxedit/fxet_list.h" -#include "fpdfsdk/pdfwindow/PWL_Edit.h" -#include "fpdfsdk/pdfwindow/PWL_EditCtrl.h" -#include "fpdfsdk/pdfwindow/PWL_ListBox.h" -#include "fpdfsdk/pdfwindow/PWL_Utils.h" -#include "fpdfsdk/pdfwindow/PWL_Wnd.h" -#include "public/fpdf_fwlevent.h" - -#define PWLCB_DEFAULTFONTSIZE 12.0f - -bool CPWL_CBListBox::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) { - CPWL_Wnd::OnLButtonUp(point, nFlag); - - if (!m_bMouseDown) - return true; - - ReleaseCapture(); - m_bMouseDown = false; - - if (!ClientHitTest(point)) - return true; - if (CPWL_Wnd* pParent = GetParentWindow()) - pParent->OnNotify(this, PNM_LBUTTONUP, 0, PWL_MAKEDWORD(point.x, point.y)); - - bool bExit = false; - OnNotifySelChanged(false, bExit, nFlag); - - return !bExit; -} - -bool CPWL_CBListBox::OnKeyDownWithExit(uint16_t nChar, - bool& bExit, - uint32_t nFlag) { - switch (nChar) { - case FWL_VKEY_Up: - case FWL_VKEY_Down: - case FWL_VKEY_Home: - case FWL_VKEY_Left: - case FWL_VKEY_End: - case FWL_VKEY_Right: - break; - default: - return false; - } - - switch (nChar) { - case FWL_VKEY_Up: - m_pList->OnVK_UP(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); - break; - case FWL_VKEY_Down: - m_pList->OnVK_DOWN(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); - break; - case FWL_VKEY_Home: - m_pList->OnVK_HOME(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); - break; - case FWL_VKEY_Left: - m_pList->OnVK_LEFT(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); - break; - case FWL_VKEY_End: - m_pList->OnVK_END(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); - break; - case FWL_VKEY_Right: - m_pList->OnVK_RIGHT(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); - break; - case FWL_VKEY_Delete: - break; - } - - OnNotifySelChanged(true, bExit, nFlag); - - return true; -} - -bool CPWL_CBListBox::OnCharWithExit(uint16_t nChar, - bool& bExit, - uint32_t nFlag) { - if (!m_pList->OnChar(nChar, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag))) - return false; - if (CPWL_ComboBox* pComboBox = (CPWL_ComboBox*)GetParentWindow()) - pComboBox->SetSelectText(); - - OnNotifySelChanged(true, bExit, nFlag); - - return true; -} - -void CPWL_CBButton::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) { - CPWL_Wnd::GetThisAppearanceStream(sAppStream); - - CFX_FloatRect rectWnd = CPWL_Wnd::GetWindowRect(); - - if (IsVisible() && !rectWnd.IsEmpty()) { - CFX_ByteTextBuf sButton; - - CFX_PointF ptCenter = GetCenterPoint(); - - CFX_PointF pt1(ptCenter.x - PWL_CBBUTTON_TRIANGLE_HALFLEN, - ptCenter.y + PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f); - CFX_PointF pt2(ptCenter.x + PWL_CBBUTTON_TRIANGLE_HALFLEN, - ptCenter.y + PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f); - CFX_PointF pt3(ptCenter.x, - ptCenter.y - PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f); - - if (IsFloatBigger(rectWnd.right - rectWnd.left, - PWL_CBBUTTON_TRIANGLE_HALFLEN * 2) && - IsFloatBigger(rectWnd.top - rectWnd.bottom, - PWL_CBBUTTON_TRIANGLE_HALFLEN)) { - sButton << "0 g\n"; - sButton << pt1.x << " " << pt1.y << " m\n"; - sButton << pt2.x << " " << pt2.y << " l\n"; - sButton << pt3.x << " " << pt3.y << " l\n"; - sButton << pt1.x << " " << pt1.y << " l f\n"; - - sAppStream << "q\n" << sButton << "Q\n"; - } - } -} - -void CPWL_CBButton::DrawThisAppearance(CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device) { - CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device); - - CFX_FloatRect rectWnd = CPWL_Wnd::GetWindowRect(); - - if (IsVisible() && !rectWnd.IsEmpty()) { - CFX_PointF ptCenter = GetCenterPoint(); - - CFX_PointF pt1(ptCenter.x - PWL_CBBUTTON_TRIANGLE_HALFLEN, - ptCenter.y + PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f); - CFX_PointF pt2(ptCenter.x + PWL_CBBUTTON_TRIANGLE_HALFLEN, - ptCenter.y + PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f); - CFX_PointF pt3(ptCenter.x, - ptCenter.y - PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f); - - if (IsFloatBigger(rectWnd.right - rectWnd.left, - PWL_CBBUTTON_TRIANGLE_HALFLEN * 2) && - IsFloatBigger(rectWnd.top - rectWnd.bottom, - PWL_CBBUTTON_TRIANGLE_HALFLEN)) { - CFX_PathData path; - path.AppendPoint(pt1, FXPT_TYPE::MoveTo, false); - path.AppendPoint(pt2, FXPT_TYPE::LineTo, false); - path.AppendPoint(pt3, FXPT_TYPE::LineTo, false); - path.AppendPoint(pt1, FXPT_TYPE::LineTo, false); - - pDevice->DrawPath(&path, pUser2Device, nullptr, - PWL_DEFAULT_BLACKCOLOR.ToFXColor(GetTransparency()), 0, - FXFILL_ALTERNATE); - } - } -} - -bool CPWL_CBButton::OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) { - CPWL_Wnd::OnLButtonDown(point, nFlag); - - SetCapture(); - - if (CPWL_Wnd* pParent = GetParentWindow()) { - pParent->OnNotify(this, PNM_LBUTTONDOWN, 0, - PWL_MAKEDWORD(point.x, point.y)); - } - - return true; -} - -bool CPWL_CBButton::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) { - CPWL_Wnd::OnLButtonUp(point, nFlag); - - ReleaseCapture(); - - return true; -} - -CPWL_ComboBox::CPWL_ComboBox() - : m_pEdit(nullptr), - m_pButton(nullptr), - m_pList(nullptr), - m_bPopup(false), - m_nPopupWhere(0), - m_nSelectItem(-1), - m_pFillerNotify(nullptr) {} - -CPWL_ComboBox::~CPWL_ComboBox() {} - -CFX_ByteString CPWL_ComboBox::GetClassName() const { - return "CPWL_ComboBox"; -} - -void CPWL_ComboBox::OnCreate(PWL_CREATEPARAM& cp) { - cp.dwFlags &= ~PWS_HSCROLL; - cp.dwFlags &= ~PWS_VSCROLL; -} - -void CPWL_ComboBox::SetFocus() { - if (m_pEdit) - m_pEdit->SetFocus(); -} - -void CPWL_ComboBox::KillFocus() { - SetPopup(false); - CPWL_Wnd::KillFocus(); -} - -CFX_WideString CPWL_ComboBox::GetText() const { - if (m_pEdit) { - return m_pEdit->GetText(); - } - return CFX_WideString(); -} - -void CPWL_ComboBox::SetText(const CFX_WideString& text) { - if (m_pEdit) - m_pEdit->SetText(text); -} - -void CPWL_ComboBox::AddString(const CFX_WideString& str) { - if (m_pList) - m_pList->AddString(str); -} - -int32_t CPWL_ComboBox::GetSelect() const { - return m_nSelectItem; -} - -void CPWL_ComboBox::SetSelect(int32_t nItemIndex) { - if (m_pList) - m_pList->Select(nItemIndex); - - m_pEdit->SetText(m_pList->GetText()); - m_nSelectItem = nItemIndex; -} - -void CPWL_ComboBox::SetEditSel(int32_t nStartChar, int32_t nEndChar) { - if (m_pEdit) - m_pEdit->SetSel(nStartChar, nEndChar); -} - -void CPWL_ComboBox::GetEditSel(int32_t& nStartChar, int32_t& nEndChar) const { - nStartChar = -1; - nEndChar = -1; - - if (m_pEdit) - m_pEdit->GetSel(nStartChar, nEndChar); -} - -void CPWL_ComboBox::Clear() { - if (m_pEdit) - m_pEdit->Clear(); -} - -void CPWL_ComboBox::CreateChildWnd(const PWL_CREATEPARAM& cp) { - CreateEdit(cp); - CreateButton(cp); - CreateListBox(cp); -} - -void CPWL_ComboBox::CreateEdit(const PWL_CREATEPARAM& cp) { - if (m_pEdit) - return; - - m_pEdit = new CPWL_CBEdit(); - m_pEdit->AttachFFLData(m_pFormFiller.Get()); - - PWL_CREATEPARAM ecp = cp; - ecp.pParentWnd = this; - ecp.dwFlags = PWS_VISIBLE | PWS_CHILD | PWS_BORDER | PES_CENTER | - PES_AUTOSCROLL | PES_UNDO; - - if (HasFlag(PWS_AUTOFONTSIZE)) - ecp.dwFlags |= PWS_AUTOFONTSIZE; - - if (!HasFlag(PCBS_ALLOWCUSTOMTEXT)) - ecp.dwFlags |= PWS_READONLY; - - ecp.rcRectWnd = CFX_FloatRect(0, 0, 0, 0); - ecp.dwBorderWidth = 0; - ecp.nBorderStyle = BorderStyle::SOLID; - m_pEdit->Create(ecp); -} - -void CPWL_ComboBox::CreateButton(const PWL_CREATEPARAM& cp) { - if (m_pButton) - return; - - m_pButton = new CPWL_CBButton; - - PWL_CREATEPARAM bcp = cp; - bcp.pParentWnd = this; - bcp.dwFlags = PWS_VISIBLE | PWS_CHILD | PWS_BORDER | PWS_BACKGROUND; - bcp.sBackgroundColor = PWL_SCROLLBAR_BKCOLOR; - bcp.sBorderColor = PWL_DEFAULT_BLACKCOLOR; - bcp.dwBorderWidth = 2; - bcp.nBorderStyle = BorderStyle::BEVELED; - bcp.eCursorType = FXCT_ARROW; - m_pButton->Create(bcp); -} - -void CPWL_ComboBox::CreateListBox(const PWL_CREATEPARAM& cp) { - if (m_pList) - return; - - m_pList = new CPWL_CBListBox(); - m_pList->AttachFFLData(m_pFormFiller.Get()); - - PWL_CREATEPARAM lcp = cp; - lcp.pParentWnd = this; - lcp.dwFlags = - PWS_CHILD | PWS_BORDER | PWS_BACKGROUND | PLBS_HOVERSEL | PWS_VSCROLL; - lcp.nBorderStyle = BorderStyle::SOLID; - lcp.dwBorderWidth = 1; - lcp.eCursorType = FXCT_ARROW; - lcp.rcRectWnd = CFX_FloatRect(0, 0, 0, 0); - - if (cp.dwFlags & PWS_AUTOFONTSIZE) - lcp.fFontSize = PWLCB_DEFAULTFONTSIZE; - else - lcp.fFontSize = cp.fFontSize; - - if (cp.sBorderColor.nColorType == COLORTYPE_TRANSPARENT) - lcp.sBorderColor = PWL_DEFAULT_BLACKCOLOR; - - if (cp.sBackgroundColor.nColorType == COLORTYPE_TRANSPARENT) - lcp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR; - - m_pList->Create(lcp); -} - -void CPWL_ComboBox::RePosChildWnd() { - CFX_FloatRect rcClient = GetClientRect(); - - if (m_bPopup) { - CFX_FloatRect rclient = GetClientRect(); - CFX_FloatRect rcButton = rclient; - CFX_FloatRect rcEdit = rcClient; - CFX_FloatRect rcList = CPWL_Wnd::GetWindowRect(); - - float fOldWindowHeight = m_rcOldWindow.Height(); - float fOldClientHeight = fOldWindowHeight - GetBorderWidth() * 2; - - switch (m_nPopupWhere) { - case 0: - rcButton.left = rcButton.right - PWL_COMBOBOX_BUTTON_WIDTH; - - if (rcButton.left < rclient.left) - rcButton.left = rclient.left; - - rcButton.bottom = rcButton.top - fOldClientHeight; - - rcEdit.right = rcButton.left - 1.0f; - - if (rcEdit.left < rclient.left) - rcEdit.left = rclient.left; - - if (rcEdit.right < rcEdit.left) - rcEdit.right = rcEdit.left; - - rcEdit.bottom = rcEdit.top - fOldClientHeight; - - rcList.top -= fOldWindowHeight; - - break; - case 1: - rcButton.left = rcButton.right - PWL_COMBOBOX_BUTTON_WIDTH; - - if (rcButton.left < rclient.left) - rcButton.left = rclient.left; - - rcButton.top = rcButton.bottom + fOldClientHeight; - - rcEdit.right = rcButton.left - 1.0f; - - if (rcEdit.left < rclient.left) - rcEdit.left = rclient.left; - - if (rcEdit.right < rcEdit.left) - rcEdit.right = rcEdit.left; - - rcEdit.top = rcEdit.bottom + fOldClientHeight; - - rcList.bottom += fOldWindowHeight; - - break; - } - - if (m_pButton) - m_pButton->Move(rcButton, true, false); - - if (m_pEdit) - m_pEdit->Move(rcEdit, true, false); - - if (m_pList) { - m_pList->SetVisible(true); - m_pList->Move(rcList, true, false); - m_pList->ScrollToListItem(m_nSelectItem); - } - } else { - CFX_FloatRect rcButton = rcClient; - - rcButton.left = rcButton.right - PWL_COMBOBOX_BUTTON_WIDTH; - - if (rcButton.left < rcClient.left) - rcButton.left = rcClient.left; - - if (m_pButton) - m_pButton->Move(rcButton, true, false); - - CFX_FloatRect rcEdit = rcClient; - rcEdit.right = rcButton.left - 1.0f; - - if (rcEdit.left < rcClient.left) - rcEdit.left = rcClient.left; - - if (rcEdit.right < rcEdit.left) - rcEdit.right = rcEdit.left; - - if (m_pEdit) - m_pEdit->Move(rcEdit, true, false); - - if (m_pList) - m_pList->SetVisible(false); - } -} - -void CPWL_ComboBox::SelectAll() { - if (m_pEdit && HasFlag(PCBS_ALLOWCUSTOMTEXT)) - m_pEdit->SelectAll(); -} - -CFX_FloatRect CPWL_ComboBox::GetFocusRect() const { - return CFX_FloatRect(); -} - -void CPWL_ComboBox::SetPopup(bool bPopup) { - if (!m_pList) - return; - if (bPopup == m_bPopup) - return; - float fListHeight = m_pList->GetContentRect().Height(); - if (!IsFloatBigger(fListHeight, 0.0f)) - return; - - if (bPopup) { - if (m_pFillerNotify) { -#ifdef PDF_ENABLE_XFA - bool bExit = false; - m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), bExit, 0); - if (bExit) - return; -#endif // PDF_ENABLE_XFA - int32_t nWhere = 0; - float fPopupRet = 0.0f; - float fPopupMin = 0.0f; - if (m_pList->GetCount() > 3) - fPopupMin = - m_pList->GetFirstHeight() * 3 + m_pList->GetBorderWidth() * 2; - float fPopupMax = fListHeight + m_pList->GetBorderWidth() * 2; - m_pFillerNotify->QueryWherePopup(GetAttachedData(), fPopupMin, fPopupMax, - nWhere, fPopupRet); - - if (IsFloatBigger(fPopupRet, 0.0f)) { - m_bPopup = bPopup; - - CFX_FloatRect rcWindow = CPWL_Wnd::GetWindowRect(); - m_rcOldWindow = rcWindow; - switch (nWhere) { - default: - case 0: - rcWindow.bottom -= fPopupRet; - break; - case 1: - rcWindow.top += fPopupRet; - break; - } - - m_nPopupWhere = nWhere; - Move(rcWindow, true, true); -#ifdef PDF_ENABLE_XFA - bExit = false; - m_pFillerNotify->OnPopupPostOpen(GetAttachedData(), bExit, 0); - if (bExit) - return; -#endif // PDF_ENABLE_XFA - } - } - } else { - m_bPopup = bPopup; - Move(m_rcOldWindow, true, true); - } -} - -bool CPWL_ComboBox::OnKeyDown(uint16_t nChar, uint32_t nFlag) { - if (!m_pList) - return false; - if (!m_pEdit) - return false; - - m_nSelectItem = -1; - - switch (nChar) { - case FWL_VKEY_Up: - if (m_pList->GetCurSel() > 0) { - bool bExit = false; -#ifdef PDF_ENABLE_XFA - if (m_pFillerNotify) { - m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), bExit, nFlag); - if (bExit) - return false; - bExit = false; - m_pFillerNotify->OnPopupPostOpen(GetAttachedData(), bExit, nFlag); - if (bExit) - return false; - } -#endif // PDF_ENABLE_XFA - if (m_pList->OnKeyDownWithExit(nChar, bExit, nFlag)) { - if (bExit) - return false; - SetSelectText(); - } - } - return true; - case FWL_VKEY_Down: - if (m_pList->GetCurSel() < m_pList->GetCount() - 1) { - bool bExit = false; -#ifdef PDF_ENABLE_XFA - if (m_pFillerNotify) { - m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), bExit, nFlag); - if (bExit) - return false; - bExit = false; - m_pFillerNotify->OnPopupPostOpen(GetAttachedData(), bExit, nFlag); - if (bExit) - return false; - } -#endif // PDF_ENABLE_XFA - if (m_pList->OnKeyDownWithExit(nChar, bExit, nFlag)) { - if (bExit) - return false; - SetSelectText(); - } - } - return true; - } - - if (HasFlag(PCBS_ALLOWCUSTOMTEXT)) - return m_pEdit->OnKeyDown(nChar, nFlag); - - return false; -} - -bool CPWL_ComboBox::OnChar(uint16_t nChar, uint32_t nFlag) { - if (!m_pList) - return false; - - if (!m_pEdit) - return false; - - m_nSelectItem = -1; - if (HasFlag(PCBS_ALLOWCUSTOMTEXT)) - return m_pEdit->OnChar(nChar, nFlag); - - bool bExit = false; -#ifdef PDF_ENABLE_XFA - if (m_pFillerNotify) { - m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), bExit, nFlag); - if (bExit) - return false; - - m_pFillerNotify->OnPopupPostOpen(GetAttachedData(), bExit, nFlag); - if (bExit) - return false; - } -#endif // PDF_ENABLE_XFA - return m_pList->OnCharWithExit(nChar, bExit, nFlag) ? bExit : false; -} - -void CPWL_ComboBox::OnNotify(CPWL_Wnd* pWnd, - uint32_t msg, - intptr_t wParam, - intptr_t lParam) { - switch (msg) { - case PNM_LBUTTONDOWN: - if (pWnd == m_pButton) { - SetPopup(!m_bPopup); - return; - } - break; - case PNM_LBUTTONUP: - if (m_pEdit && m_pList) { - if (pWnd == m_pList) { - SetSelectText(); - SelectAll(); - m_pEdit->SetFocus(); - SetPopup(false); - return; - } - } - break; - } - - CPWL_Wnd::OnNotify(pWnd, msg, wParam, lParam); -} - -bool CPWL_ComboBox::IsPopup() const { - return m_bPopup; -} - -void CPWL_ComboBox::SetSelectText() { - m_pEdit->SelectAll(); - m_pEdit->ReplaceSel(m_pList->GetText()); - m_pEdit->SelectAll(); - m_nSelectItem = m_pList->GetCurSel(); -} - -void CPWL_ComboBox::SetFillerNotify(IPWL_Filler_Notify* pNotify) { - m_pFillerNotify = pNotify; - - if (m_pEdit) - m_pEdit->SetFillerNotify(pNotify); - - if (m_pList) - m_pList->SetFillerNotify(pNotify); -} diff --git a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/PWL_Icon.cpp b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/PWL_Icon.cpp deleted file mode 100644 index 3ae7244552f..00000000000 --- a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/PWL_Icon.cpp +++ /dev/null @@ -1,225 +0,0 @@ -// Copyright 2014 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 "fpdfsdk/pdfwindow/PWL_Icon.h" - -#include <algorithm> - -#include "core/fpdfapi/parser/cpdf_array.h" -#include "core/fpdfapi/parser/cpdf_stream.h" -#include "fpdfsdk/pdfwindow/PWL_Utils.h" -#include "fpdfsdk/pdfwindow/PWL_Wnd.h" - -CPWL_Image::CPWL_Image() : m_pPDFStream(nullptr) {} - -CPWL_Image::~CPWL_Image() {} - -CFX_ByteString CPWL_Image::GetImageAppStream() { - CFX_ByteTextBuf sAppStream; - - CFX_ByteString sAlias = GetImageAlias(); - CFX_FloatRect rcPlate = GetClientRect(); - CFX_Matrix mt; - mt.SetReverse(GetImageMatrix()); - - float fHScale = 1.0f; - float fVScale = 1.0f; - GetScale(fHScale, fVScale); - - float fx = 0.0f; - float fy = 0.0f; - GetImageOffset(fx, fy); - - if (m_pPDFStream && sAlias.GetLength() > 0) { - sAppStream << "q\n"; - sAppStream << rcPlate.left << " " << rcPlate.bottom << " " - << rcPlate.right - rcPlate.left << " " - << rcPlate.top - rcPlate.bottom << " re W n\n"; - - sAppStream << fHScale << " 0 0 " << fVScale << " " << rcPlate.left + fx - << " " << rcPlate.bottom + fy << " cm\n"; - sAppStream << mt.a << " " << mt.b << " " << mt.c << " " << mt.d << " " - << mt.e << " " << mt.f << " cm\n"; - - sAppStream << "0 g 0 G 1 w /" << sAlias.AsStringC() << " Do\n" - << "Q\n"; - } - - return sAppStream.MakeString(); -} - -void CPWL_Image::SetPDFStream(CPDF_Stream* pStream) { - m_pPDFStream = pStream; -} - -CPDF_Stream* CPWL_Image::GetPDFStream() { - return m_pPDFStream; -} - -void CPWL_Image::GetImageSize(float& fWidth, float& fHeight) { - fWidth = 0.0f; - fHeight = 0.0f; - - if (m_pPDFStream) { - if (CPDF_Dictionary* pDict = m_pPDFStream->GetDict()) { - CFX_FloatRect rect = pDict->GetRectFor("BBox"); - - fWidth = rect.right - rect.left; - fHeight = rect.top - rect.bottom; - } - } -} - -CFX_Matrix CPWL_Image::GetImageMatrix() { - if (m_pPDFStream) { - if (CPDF_Dictionary* pDict = m_pPDFStream->GetDict()) { - return pDict->GetMatrixFor("Matrix"); - } - } - - return CFX_Matrix(); -} - -CFX_ByteString CPWL_Image::GetImageAlias() { - if (!m_sImageAlias.IsEmpty()) - return m_sImageAlias; - - if (m_pPDFStream) { - if (CPDF_Dictionary* pDict = m_pPDFStream->GetDict()) { - return pDict->GetStringFor("Name"); - } - } - - return CFX_ByteString(); -} - -void CPWL_Image::SetImageAlias(const char* sImageAlias) { - m_sImageAlias = sImageAlias; -} - -void CPWL_Image::GetScale(float& fHScale, float& fVScale) { - fHScale = 1.0f; - fVScale = 1.0f; -} - -void CPWL_Image::GetImageOffset(float& x, float& y) { - x = 0.0f; - y = 0.0f; -} - -CPWL_Icon::CPWL_Icon() : m_pIconFit(nullptr) {} - -CPWL_Icon::~CPWL_Icon() {} - -CPDF_IconFit* CPWL_Icon::GetIconFit() { - return m_pIconFit; -} - -int32_t CPWL_Icon::GetScaleMethod() { - if (m_pIconFit) - return m_pIconFit->GetScaleMethod(); - - return 0; -} - -bool CPWL_Icon::IsProportionalScale() { - if (m_pIconFit) - return m_pIconFit->IsProportionalScale(); - - return false; -} - -void CPWL_Icon::GetIconPosition(float& fLeft, float& fBottom) { - if (m_pIconFit) { - fLeft = 0.0f; - fBottom = 0.0f; - CPDF_Array* pA = m_pIconFit->GetDict() - ? m_pIconFit->GetDict()->GetArrayFor("A") - : nullptr; - if (pA) { - size_t dwCount = pA->GetCount(); - if (dwCount > 0) - fLeft = pA->GetNumberAt(0); - if (dwCount > 1) - fBottom = pA->GetNumberAt(1); - } - } else { - fLeft = 0.0f; - fBottom = 0.0f; - } -} - -void CPWL_Icon::GetScale(float& fHScale, float& fVScale) { - fHScale = 1.0f; - fVScale = 1.0f; - - if (m_pPDFStream) { - float fImageWidth, fImageHeight; - float fPlateWidth, fPlateHeight; - - CFX_FloatRect rcPlate = GetClientRect(); - fPlateWidth = rcPlate.right - rcPlate.left; - fPlateHeight = rcPlate.top - rcPlate.bottom; - - GetImageSize(fImageWidth, fImageHeight); - - int32_t nScaleMethod = GetScaleMethod(); - - switch (nScaleMethod) { - default: - case 0: - fHScale = fPlateWidth / std::max(fImageWidth, 1.0f); - fVScale = fPlateHeight / std::max(fImageHeight, 1.0f); - break; - case 1: - if (fPlateWidth < fImageWidth) - fHScale = fPlateWidth / std::max(fImageWidth, 1.0f); - if (fPlateHeight < fImageHeight) - fVScale = fPlateHeight / std::max(fImageHeight, 1.0f); - break; - case 2: - if (fPlateWidth > fImageWidth) - fHScale = fPlateWidth / std::max(fImageWidth, 1.0f); - if (fPlateHeight > fImageHeight) - fVScale = fPlateHeight / std::max(fImageHeight, 1.0f); - break; - case 3: - break; - } - - float fMinScale; - if (IsProportionalScale()) { - fMinScale = std::min(fHScale, fVScale); - fHScale = fMinScale; - fVScale = fMinScale; - } - } -} - -void CPWL_Icon::GetImageOffset(float& x, float& y) { - float fLeft, fBottom; - - GetIconPosition(fLeft, fBottom); - x = 0.0f; - y = 0.0f; - - float fImageWidth, fImageHeight; - GetImageSize(fImageWidth, fImageHeight); - - float fHScale, fVScale; - GetScale(fHScale, fVScale); - - float fImageFactWidth = fImageWidth * fHScale; - float fImageFactHeight = fImageHeight * fVScale; - - float fPlateWidth, fPlateHeight; - CFX_FloatRect rcPlate = GetClientRect(); - fPlateWidth = rcPlate.right - rcPlate.left; - fPlateHeight = rcPlate.top - rcPlate.bottom; - - x = (fPlateWidth - fImageFactWidth) * fLeft; - y = (fPlateHeight - fImageFactHeight) * fBottom; -} diff --git a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/PWL_Icon.h b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/PWL_Icon.h deleted file mode 100644 index 49ac1f3f3d9..00000000000 --- a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/PWL_Icon.h +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright 2014 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 - -#ifndef FPDFSDK_PDFWINDOW_PWL_ICON_H_ -#define FPDFSDK_PDFWINDOW_PWL_ICON_H_ - -#include "core/fxcrt/fx_string.h" -#include "fpdfsdk/pdfwindow/PWL_Wnd.h" - -class CPWL_Image : public CPWL_Wnd { - public: - CPWL_Image(); - ~CPWL_Image() override; - - virtual CFX_ByteString GetImageAppStream(); - - virtual void GetScale(float& fHScale, float& fVScale); - virtual void GetImageOffset(float& x, float& y); - virtual CPDF_Stream* GetPDFStream(); - - public: - void SetPDFStream(CPDF_Stream* pStream); - void GetImageSize(float& fWidth, float& fHeight); - CFX_Matrix GetImageMatrix(); - CFX_ByteString GetImageAlias(); - void SetImageAlias(const char* sImageAlias); - - protected: - CPDF_Stream* m_pPDFStream; - CFX_ByteString m_sImageAlias; -}; - -class CPWL_Icon : public CPWL_Image { - public: - CPWL_Icon(); - ~CPWL_Icon() override; - - virtual CPDF_IconFit* GetIconFit(); - - // CPWL_Image - void GetScale(float& fHScale, float& fVScale) override; - void GetImageOffset(float& x, float& y) override; - - int32_t GetScaleMethod(); - bool IsProportionalScale(); - void GetIconPosition(float& fLeft, float& fBottom); - - void SetIconFit(CPDF_IconFit* pIconFit) { m_pIconFit = pIconFit; } - - private: - CPDF_IconFit* m_pIconFit; -}; - -#endif // FPDFSDK_PDFWINDOW_PWL_ICON_H_ diff --git a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/PWL_ScrollBar.cpp b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/PWL_ScrollBar.cpp deleted file mode 100644 index 1c3efb1faa8..00000000000 --- a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/PWL_ScrollBar.cpp +++ /dev/null @@ -1,1175 +0,0 @@ -// Copyright 2014 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 "fpdfsdk/pdfwindow/PWL_ScrollBar.h" - -#include "core/fxge/cfx_pathdata.h" -#include "core/fxge/cfx_renderdevice.h" -#include "fpdfsdk/pdfwindow/PWL_Utils.h" -#include "fpdfsdk/pdfwindow/PWL_Wnd.h" - -PWL_FLOATRANGE::PWL_FLOATRANGE() { - Default(); -} - -PWL_FLOATRANGE::PWL_FLOATRANGE(float min, float max) { - Set(min, max); -} - -void PWL_FLOATRANGE::Default() { - fMin = 0; - fMax = 0; -} - -void PWL_FLOATRANGE::Set(float min, float max) { - if (min > max) { - fMin = max; - fMax = min; - } else { - fMin = min; - fMax = max; - } -} - -bool PWL_FLOATRANGE::In(float x) const { - return (IsFloatBigger(x, fMin) || IsFloatEqual(x, fMin)) && - (IsFloatSmaller(x, fMax) || IsFloatEqual(x, fMax)); -} - -float PWL_FLOATRANGE::GetWidth() const { - return fMax - fMin; -} - -PWL_SCROLL_PRIVATEDATA::PWL_SCROLL_PRIVATEDATA() { - Default(); -} - -void PWL_SCROLL_PRIVATEDATA::Default() { - ScrollRange.Default(); - fScrollPos = ScrollRange.fMin; - fClientWidth = 0; - fBigStep = 10; - fSmallStep = 1; -} - -void PWL_SCROLL_PRIVATEDATA::SetScrollRange(float min, float max) { - ScrollRange.Set(min, max); - - if (IsFloatSmaller(fScrollPos, ScrollRange.fMin)) - fScrollPos = ScrollRange.fMin; - if (IsFloatBigger(fScrollPos, ScrollRange.fMax)) - fScrollPos = ScrollRange.fMax; -} - -void PWL_SCROLL_PRIVATEDATA::SetClientWidth(float width) { - fClientWidth = width; -} - -void PWL_SCROLL_PRIVATEDATA::SetSmallStep(float step) { - fSmallStep = step; -} - -void PWL_SCROLL_PRIVATEDATA::SetBigStep(float step) { - fBigStep = step; -} - -bool PWL_SCROLL_PRIVATEDATA::SetPos(float pos) { - if (ScrollRange.In(pos)) { - fScrollPos = pos; - return true; - } - return false; -} - -void PWL_SCROLL_PRIVATEDATA::AddSmall() { - if (!SetPos(fScrollPos + fSmallStep)) - SetPos(ScrollRange.fMax); -} - -void PWL_SCROLL_PRIVATEDATA::SubSmall() { - if (!SetPos(fScrollPos - fSmallStep)) - SetPos(ScrollRange.fMin); -} - -void PWL_SCROLL_PRIVATEDATA::AddBig() { - if (!SetPos(fScrollPos + fBigStep)) - SetPos(ScrollRange.fMax); -} - -void PWL_SCROLL_PRIVATEDATA::SubBig() { - if (!SetPos(fScrollPos - fBigStep)) - SetPos(ScrollRange.fMin); -} - -CPWL_SBButton::CPWL_SBButton(PWL_SCROLLBAR_TYPE eScrollBarType, - PWL_SBBUTTON_TYPE eButtonType) { - m_eScrollBarType = eScrollBarType; - m_eSBButtonType = eButtonType; - - m_bMouseDown = false; -} - -CPWL_SBButton::~CPWL_SBButton() {} - -CFX_ByteString CPWL_SBButton::GetClassName() const { - return "CPWL_SBButton"; -} - -void CPWL_SBButton::OnCreate(PWL_CREATEPARAM& cp) { - cp.eCursorType = FXCT_ARROW; -} - -void CPWL_SBButton::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) { - CPWL_Wnd::GetThisAppearanceStream(sAppStream); - - if (!IsVisible()) - return; - - CFX_ByteTextBuf sButton; - - CFX_FloatRect rectWnd = GetWindowRect(); - - if (rectWnd.IsEmpty()) - return; - - sAppStream << "q\n"; - - CFX_PointF ptCenter = GetCenterPoint(); - - switch (m_eScrollBarType) { - case SBT_HSCROLL: - switch (m_eSBButtonType) { - case PSBT_MIN: { - CFX_PointF pt1(ptCenter.x - PWL_TRIANGLE_HALFLEN * 0.5f, ptCenter.y); - CFX_PointF pt2(ptCenter.x + PWL_TRIANGLE_HALFLEN * 0.5f, - ptCenter.y + PWL_TRIANGLE_HALFLEN); - CFX_PointF pt3(ptCenter.x + PWL_TRIANGLE_HALFLEN * 0.5f, - ptCenter.y - PWL_TRIANGLE_HALFLEN); - - if (rectWnd.right - rectWnd.left > PWL_TRIANGLE_HALFLEN * 2 && - rectWnd.top - rectWnd.bottom > PWL_TRIANGLE_HALFLEN) { - sButton << "0 g\n"; - sButton << pt1.x << " " << pt1.y << " m\n"; - sButton << pt2.x << " " << pt2.y << " l\n"; - sButton << pt3.x << " " << pt3.y << " l\n"; - sButton << pt1.x << " " << pt1.y << " l f\n"; - - sAppStream << sButton; - } - } break; - case PSBT_MAX: { - CFX_PointF pt1(ptCenter.x + PWL_TRIANGLE_HALFLEN * 0.5f, ptCenter.y); - CFX_PointF pt2(ptCenter.x - PWL_TRIANGLE_HALFLEN * 0.5f, - ptCenter.y + PWL_TRIANGLE_HALFLEN); - CFX_PointF pt3(ptCenter.x - PWL_TRIANGLE_HALFLEN * 0.5f, - ptCenter.y - PWL_TRIANGLE_HALFLEN); - - if (rectWnd.right - rectWnd.left > PWL_TRIANGLE_HALFLEN * 2 && - rectWnd.top - rectWnd.bottom > PWL_TRIANGLE_HALFLEN) { - sButton << "0 g\n"; - sButton << pt1.x << " " << pt1.y << " m\n"; - sButton << pt2.x << " " << pt2.y << " l\n"; - sButton << pt3.x << " " << pt3.y << " l\n"; - sButton << pt1.x << " " << pt1.y << " l f\n"; - - sAppStream << sButton; - } - } break; - default: - break; - } - break; - case SBT_VSCROLL: - switch (m_eSBButtonType) { - case PSBT_MIN: { - CFX_PointF pt1(ptCenter.x - PWL_TRIANGLE_HALFLEN, - ptCenter.y - PWL_TRIANGLE_HALFLEN * 0.5f); - CFX_PointF pt2(ptCenter.x + PWL_TRIANGLE_HALFLEN, - ptCenter.y - PWL_TRIANGLE_HALFLEN * 0.5f); - CFX_PointF pt3(ptCenter.x, ptCenter.y + PWL_TRIANGLE_HALFLEN * 0.5f); - - if (rectWnd.right - rectWnd.left > PWL_TRIANGLE_HALFLEN * 2 && - rectWnd.top - rectWnd.bottom > PWL_TRIANGLE_HALFLEN) { - sButton << "0 g\n"; - sButton << pt1.x << " " << pt1.y << " m\n"; - sButton << pt2.x << " " << pt2.y << " l\n"; - sButton << pt3.x << " " << pt3.y << " l\n"; - sButton << pt1.x << " " << pt1.y << " l f\n"; - - sAppStream << sButton; - } - } break; - case PSBT_MAX: { - CFX_PointF pt1(ptCenter.x - PWL_TRIANGLE_HALFLEN, - ptCenter.y + PWL_TRIANGLE_HALFLEN * 0.5f); - CFX_PointF pt2(ptCenter.x + PWL_TRIANGLE_HALFLEN, - ptCenter.y + PWL_TRIANGLE_HALFLEN * 0.5f); - CFX_PointF pt3(ptCenter.x, ptCenter.y - PWL_TRIANGLE_HALFLEN * 0.5f); - - if (rectWnd.right - rectWnd.left > PWL_TRIANGLE_HALFLEN * 2 && - rectWnd.top - rectWnd.bottom > PWL_TRIANGLE_HALFLEN) { - sButton << "0 g\n"; - sButton << pt1.x << " " << pt1.y << " m\n"; - sButton << pt2.x << " " << pt2.y << " l\n"; - sButton << pt3.x << " " << pt3.y << " l\n"; - sButton << pt1.x << " " << pt1.y << " l f\n"; - - sAppStream << sButton; - } - } break; - default: - break; - } - break; - default: - break; - } - - sAppStream << "Q\n"; -} - -void CPWL_SBButton::DrawThisAppearance(CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device) { - if (!IsVisible()) - return; - - CFX_FloatRect rectWnd = GetWindowRect(); - if (rectWnd.IsEmpty()) - return; - - CFX_PointF ptCenter = GetCenterPoint(); - int32_t nTransparency = GetTransparency(); - - switch (m_eScrollBarType) { - case SBT_HSCROLL: - CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device); - switch (m_eSBButtonType) { - case PSBT_MIN: { - CFX_PointF pt1(ptCenter.x - PWL_TRIANGLE_HALFLEN * 0.5f, ptCenter.y); - CFX_PointF pt2(ptCenter.x + PWL_TRIANGLE_HALFLEN * 0.5f, - ptCenter.y + PWL_TRIANGLE_HALFLEN); - CFX_PointF pt3(ptCenter.x + PWL_TRIANGLE_HALFLEN * 0.5f, - ptCenter.y - PWL_TRIANGLE_HALFLEN); - - if (rectWnd.right - rectWnd.left > PWL_TRIANGLE_HALFLEN * 2 && - rectWnd.top - rectWnd.bottom > PWL_TRIANGLE_HALFLEN) { - CFX_PathData path; - path.AppendPoint(pt1, FXPT_TYPE::MoveTo, false); - path.AppendPoint(pt2, FXPT_TYPE::LineTo, false); - path.AppendPoint(pt3, FXPT_TYPE::LineTo, false); - path.AppendPoint(pt1, FXPT_TYPE::LineTo, false); - - pDevice->DrawPath(&path, pUser2Device, nullptr, - PWL_DEFAULT_BLACKCOLOR.ToFXColor(nTransparency), - 0, FXFILL_ALTERNATE); - } - } break; - case PSBT_MAX: { - CFX_PointF pt1(ptCenter.x + PWL_TRIANGLE_HALFLEN * 0.5f, ptCenter.y); - CFX_PointF pt2(ptCenter.x - PWL_TRIANGLE_HALFLEN * 0.5f, - ptCenter.y + PWL_TRIANGLE_HALFLEN); - CFX_PointF pt3(ptCenter.x - PWL_TRIANGLE_HALFLEN * 0.5f, - ptCenter.y - PWL_TRIANGLE_HALFLEN); - - if (rectWnd.right - rectWnd.left > PWL_TRIANGLE_HALFLEN * 2 && - rectWnd.top - rectWnd.bottom > PWL_TRIANGLE_HALFLEN) { - CFX_PathData path; - path.AppendPoint(pt1, FXPT_TYPE::MoveTo, false); - path.AppendPoint(pt2, FXPT_TYPE::LineTo, false); - path.AppendPoint(pt3, FXPT_TYPE::LineTo, false); - path.AppendPoint(pt1, FXPT_TYPE::LineTo, false); - - pDevice->DrawPath(&path, pUser2Device, nullptr, - PWL_DEFAULT_BLACKCOLOR.ToFXColor(nTransparency), - 0, FXFILL_ALTERNATE); - } - } break; - default: - break; - } - break; - case SBT_VSCROLL: - switch (m_eSBButtonType) { - case PSBT_MIN: { - // draw border - CFX_FloatRect rcDraw = rectWnd; - CPWL_Utils::DrawStrokeRect(pDevice, pUser2Device, rcDraw, - ArgbEncode(nTransparency, 100, 100, 100), - 0.0f); - - // draw inner border - rcDraw = CPWL_Utils::DeflateRect(rectWnd, 0.5f); - CPWL_Utils::DrawStrokeRect(pDevice, pUser2Device, rcDraw, - ArgbEncode(nTransparency, 255, 255, 255), - 1.0f); - - // draw background - - rcDraw = CPWL_Utils::DeflateRect(rectWnd, 1.0f); - - if (IsEnabled()) - CPWL_Utils::DrawShadow(pDevice, pUser2Device, true, false, rcDraw, - nTransparency, 80, 220); - else - CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcDraw, - ArgbEncode(255, 255, 255, 255)); - - // draw arrow - - if (rectWnd.top - rectWnd.bottom > 6.0f) { - float fX = rectWnd.left + 1.5f; - float fY = rectWnd.bottom; - CFX_PointF pts[7] = {CFX_PointF(fX + 2.5f, fY + 4.0f), - CFX_PointF(fX + 2.5f, fY + 3.0f), - CFX_PointF(fX + 4.5f, fY + 5.0f), - CFX_PointF(fX + 6.5f, fY + 3.0f), - CFX_PointF(fX + 6.5f, fY + 4.0f), - CFX_PointF(fX + 4.5f, fY + 6.0f), - CFX_PointF(fX + 2.5f, fY + 4.0f)}; - - if (IsEnabled()) - CPWL_Utils::DrawFillArea( - pDevice, pUser2Device, pts, 7, - ArgbEncode(nTransparency, 255, 255, 255)); - else - CPWL_Utils::DrawFillArea( - pDevice, pUser2Device, pts, 7, - PWL_DEFAULT_HEAVYGRAYCOLOR.ToFXColor(255)); - } - } break; - case PSBT_MAX: { - // draw border - CFX_FloatRect rcDraw = rectWnd; - CPWL_Utils::DrawStrokeRect(pDevice, pUser2Device, rcDraw, - ArgbEncode(nTransparency, 100, 100, 100), - 0.0f); - - // draw inner border - rcDraw = CPWL_Utils::DeflateRect(rectWnd, 0.5f); - CPWL_Utils::DrawStrokeRect(pDevice, pUser2Device, rcDraw, - ArgbEncode(nTransparency, 255, 255, 255), - 1.0f); - - // draw background - rcDraw = CPWL_Utils::DeflateRect(rectWnd, 1.0f); - if (IsEnabled()) - CPWL_Utils::DrawShadow(pDevice, pUser2Device, true, false, rcDraw, - nTransparency, 80, 220); - else - CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcDraw, - ArgbEncode(255, 255, 255, 255)); - - // draw arrow - - if (rectWnd.top - rectWnd.bottom > 6.0f) { - float fX = rectWnd.left + 1.5f; - float fY = rectWnd.bottom; - - CFX_PointF pts[7] = {CFX_PointF(fX + 2.5f, fY + 5.0f), - CFX_PointF(fX + 2.5f, fY + 6.0f), - CFX_PointF(fX + 4.5f, fY + 4.0f), - CFX_PointF(fX + 6.5f, fY + 6.0f), - CFX_PointF(fX + 6.5f, fY + 5.0f), - CFX_PointF(fX + 4.5f, fY + 3.0f), - CFX_PointF(fX + 2.5f, fY + 5.0f)}; - - if (IsEnabled()) - CPWL_Utils::DrawFillArea( - pDevice, pUser2Device, pts, 7, - ArgbEncode(nTransparency, 255, 255, 255)); - else - CPWL_Utils::DrawFillArea( - pDevice, pUser2Device, pts, 7, - PWL_DEFAULT_HEAVYGRAYCOLOR.ToFXColor(255)); - } - } break; - case PSBT_POS: { - // draw border - CFX_FloatRect rcDraw = rectWnd; - CPWL_Utils::DrawStrokeRect(pDevice, pUser2Device, rcDraw, - ArgbEncode(nTransparency, 100, 100, 100), - 0.0f); - - // draw inner border - rcDraw = CPWL_Utils::DeflateRect(rectWnd, 0.5f); - CPWL_Utils::DrawStrokeRect(pDevice, pUser2Device, rcDraw, - ArgbEncode(nTransparency, 255, 255, 255), - 1.0f); - - if (IsEnabled()) { - // draw shadow effect - - CFX_PointF ptTop = CFX_PointF(rectWnd.left, rectWnd.top - 1.0f); - CFX_PointF ptBottom = - CFX_PointF(rectWnd.left, rectWnd.bottom + 1.0f); - - ptTop.x += 1.5f; - ptBottom.x += 1.5f; - - CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom, - ArgbEncode(nTransparency, 210, 210, 210), - 1.0f); - - ptTop.x += 1.0f; - ptBottom.x += 1.0f; - - CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom, - ArgbEncode(nTransparency, 220, 220, 220), - 1.0f); - - ptTop.x += 1.0f; - ptBottom.x += 1.0f; - - CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom, - ArgbEncode(nTransparency, 240, 240, 240), - 1.0f); - - ptTop.x += 1.0f; - ptBottom.x += 1.0f; - - CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom, - ArgbEncode(nTransparency, 240, 240, 240), - 1.0f); - - ptTop.x += 1.0f; - ptBottom.x += 1.0f; - - CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom, - ArgbEncode(nTransparency, 210, 210, 210), - 1.0f); - - ptTop.x += 1.0f; - ptBottom.x += 1.0f; - - CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom, - ArgbEncode(nTransparency, 180, 180, 180), - 1.0f); - - ptTop.x += 1.0f; - ptBottom.x += 1.0f; - - CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom, - ArgbEncode(nTransparency, 150, 150, 150), - 1.0f); - - ptTop.x += 1.0f; - ptBottom.x += 1.0f; - - CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom, - ArgbEncode(nTransparency, 150, 150, 150), - 1.0f); - - ptTop.x += 1.0f; - ptBottom.x += 1.0f; - - CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom, - ArgbEncode(nTransparency, 180, 180, 180), - 1.0f); - - ptTop.x += 1.0f; - ptBottom.x += 1.0f; - - CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptTop, ptBottom, - ArgbEncode(nTransparency, 210, 210, 210), - 1.0f); - } else { - CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcDraw, - ArgbEncode(255, 255, 255, 255)); - } - - // draw friction - - if (rectWnd.Height() > 8.0f) { - FX_COLORREF crStroke = ArgbEncode(nTransparency, 120, 120, 120); - if (!IsEnabled()) - crStroke = PWL_DEFAULT_HEAVYGRAYCOLOR.ToFXColor(255); - - float nFrictionWidth = 5.0f; - float nFrictionHeight = 5.5f; - - CFX_PointF ptLeft = - CFX_PointF(ptCenter.x - nFrictionWidth / 2.0f, - ptCenter.y - nFrictionHeight / 2.0f + 0.5f); - CFX_PointF ptRight = - CFX_PointF(ptCenter.x + nFrictionWidth / 2.0f, - ptCenter.y - nFrictionHeight / 2.0f + 0.5f); - - CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptLeft, ptRight, - crStroke, 1.0f); - - ptLeft.y += 2.0f; - ptRight.y += 2.0f; - - CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptLeft, ptRight, - crStroke, 1.0f); - - ptLeft.y += 2.0f; - ptRight.y += 2.0f; - - CPWL_Utils::DrawStrokeLine(pDevice, pUser2Device, ptLeft, ptRight, - crStroke, 1.0f); - } - } break; - default: - break; - } - break; - default: - break; - } -} - -bool CPWL_SBButton::OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) { - CPWL_Wnd::OnLButtonDown(point, nFlag); - - if (CPWL_Wnd* pParent = GetParentWindow()) - pParent->OnNotify(this, PNM_LBUTTONDOWN, 0, (intptr_t)&point); - - m_bMouseDown = true; - SetCapture(); - - return true; -} - -bool CPWL_SBButton::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) { - CPWL_Wnd::OnLButtonUp(point, nFlag); - - if (CPWL_Wnd* pParent = GetParentWindow()) - pParent->OnNotify(this, PNM_LBUTTONUP, 0, (intptr_t)&point); - - m_bMouseDown = false; - ReleaseCapture(); - - return true; -} - -bool CPWL_SBButton::OnMouseMove(const CFX_PointF& point, uint32_t nFlag) { - CPWL_Wnd::OnMouseMove(point, nFlag); - - if (CPWL_Wnd* pParent = GetParentWindow()) { - pParent->OnNotify(this, PNM_MOUSEMOVE, 0, (intptr_t)&point); - } - - return true; -} - -CPWL_ScrollBar::CPWL_ScrollBar(PWL_SCROLLBAR_TYPE sbType) - : m_sbType(sbType), - m_pMinButton(nullptr), - m_pMaxButton(nullptr), - m_pPosButton(nullptr), - m_bMouseDown(false), - m_bMinOrMax(false), - m_bNotifyForever(true) {} - -CPWL_ScrollBar::~CPWL_ScrollBar() {} - -CFX_ByteString CPWL_ScrollBar::GetClassName() const { - return "CPWL_ScrollBar"; -} - -void CPWL_ScrollBar::OnCreate(PWL_CREATEPARAM& cp) { - cp.eCursorType = FXCT_ARROW; -} - -void CPWL_ScrollBar::RePosChildWnd() { - CFX_FloatRect rcClient = GetClientRect(); - CFX_FloatRect rcMinButton, rcMaxButton; - float fBWidth = 0; - - switch (m_sbType) { - case SBT_HSCROLL: - if (rcClient.right - rcClient.left > - PWL_SCROLLBAR_BUTTON_WIDTH * 2 + PWL_SCROLLBAR_POSBUTTON_MINWIDTH + - 2) { - rcMinButton = CFX_FloatRect(rcClient.left, rcClient.bottom, - rcClient.left + PWL_SCROLLBAR_BUTTON_WIDTH, - rcClient.top); - rcMaxButton = - CFX_FloatRect(rcClient.right - PWL_SCROLLBAR_BUTTON_WIDTH, - rcClient.bottom, rcClient.right, rcClient.top); - } else { - fBWidth = (rcClient.right - rcClient.left - - PWL_SCROLLBAR_POSBUTTON_MINWIDTH - 2) / - 2; - - if (fBWidth > 0) { - rcMinButton = CFX_FloatRect(rcClient.left, rcClient.bottom, - rcClient.left + fBWidth, rcClient.top); - rcMaxButton = CFX_FloatRect(rcClient.right - fBWidth, rcClient.bottom, - rcClient.right, rcClient.top); - } else { - SetVisible(false); - } - } - break; - case SBT_VSCROLL: - if (IsFloatBigger(rcClient.top - rcClient.bottom, - PWL_SCROLLBAR_BUTTON_WIDTH * 2 + - PWL_SCROLLBAR_POSBUTTON_MINWIDTH + 2)) { - rcMinButton = CFX_FloatRect(rcClient.left, - rcClient.top - PWL_SCROLLBAR_BUTTON_WIDTH, - rcClient.right, rcClient.top); - rcMaxButton = - CFX_FloatRect(rcClient.left, rcClient.bottom, rcClient.right, - rcClient.bottom + PWL_SCROLLBAR_BUTTON_WIDTH); - } else { - fBWidth = (rcClient.top - rcClient.bottom - - PWL_SCROLLBAR_POSBUTTON_MINWIDTH - 2) / - 2; - - if (IsFloatBigger(fBWidth, 0)) { - rcMinButton = CFX_FloatRect(rcClient.left, rcClient.top - fBWidth, - rcClient.right, rcClient.top); - rcMaxButton = - CFX_FloatRect(rcClient.left, rcClient.bottom, rcClient.right, - rcClient.bottom + fBWidth); - } else { - SetVisible(false); - } - } - break; - } - - if (m_pMinButton) - m_pMinButton->Move(rcMinButton, true, false); - if (m_pMaxButton) - m_pMaxButton->Move(rcMaxButton, true, false); - MovePosButton(false); -} - -void CPWL_ScrollBar::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) { - CFX_FloatRect rectWnd = GetWindowRect(); - - if (IsVisible() && !rectWnd.IsEmpty()) { - CFX_ByteTextBuf sButton; - - sButton << "q\n"; - sButton << "0 w\n" - << CPWL_Utils::GetColorAppStream(GetBackgroundColor(), true) - .AsStringC(); - sButton << rectWnd.left << " " << rectWnd.bottom << " " - << rectWnd.right - rectWnd.left << " " - << rectWnd.top - rectWnd.bottom << " re b Q\n"; - - sAppStream << sButton; - } -} - -void CPWL_ScrollBar::DrawThisAppearance(CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device) { - CFX_FloatRect rectWnd = GetWindowRect(); - - if (IsVisible() && !rectWnd.IsEmpty()) { - CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rectWnd, - GetBackgroundColor(), GetTransparency()); - - CPWL_Utils::DrawStrokeLine( - pDevice, pUser2Device, - CFX_PointF(rectWnd.left + 2.0f, rectWnd.top - 2.0f), - CFX_PointF(rectWnd.left + 2.0f, rectWnd.bottom + 2.0f), - ArgbEncode(GetTransparency(), 100, 100, 100), 1.0f); - - CPWL_Utils::DrawStrokeLine( - pDevice, pUser2Device, - CFX_PointF(rectWnd.right - 2.0f, rectWnd.top - 2.0f), - CFX_PointF(rectWnd.right - 2.0f, rectWnd.bottom + 2.0f), - ArgbEncode(GetTransparency(), 100, 100, 100), 1.0f); - } -} - -bool CPWL_ScrollBar::OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) { - CPWL_Wnd::OnLButtonDown(point, nFlag); - - if (HasFlag(PWS_AUTOTRANSPARENT)) { - if (GetTransparency() != 255) { - SetTransparency(255); - InvalidateRect(); - } - } - - CFX_FloatRect rcMinArea, rcMaxArea; - - if (m_pPosButton && m_pPosButton->IsVisible()) { - CFX_FloatRect rcClient = GetClientRect(); - CFX_FloatRect rcPosButton = m_pPosButton->GetWindowRect(); - - switch (m_sbType) { - case SBT_HSCROLL: - rcMinArea = - CFX_FloatRect(rcClient.left + PWL_SCROLLBAR_BUTTON_WIDTH, - rcClient.bottom, rcPosButton.left, rcClient.top); - rcMaxArea = CFX_FloatRect(rcPosButton.right, rcClient.bottom, - rcClient.right - PWL_SCROLLBAR_BUTTON_WIDTH, - rcClient.top); - - break; - case SBT_VSCROLL: - rcMinArea = - CFX_FloatRect(rcClient.left, rcPosButton.top, rcClient.right, - rcClient.top - PWL_SCROLLBAR_BUTTON_WIDTH); - rcMaxArea = CFX_FloatRect(rcClient.left, - rcClient.bottom + PWL_SCROLLBAR_BUTTON_WIDTH, - rcClient.right, rcPosButton.bottom); - break; - } - - rcMinArea.Normalize(); - rcMaxArea.Normalize(); - - if (rcMinArea.Contains(point)) { - m_sData.SubBig(); - MovePosButton(true); - NotifyScrollWindow(); - } - - if (rcMaxArea.Contains(point)) { - m_sData.AddBig(); - MovePosButton(true); - NotifyScrollWindow(); - } - } - - return true; -} - -bool CPWL_ScrollBar::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) { - CPWL_Wnd::OnLButtonUp(point, nFlag); - - if (HasFlag(PWS_AUTOTRANSPARENT)) { - if (GetTransparency() != PWL_SCROLLBAR_TRANSPARENCY) { - SetTransparency(PWL_SCROLLBAR_TRANSPARENCY); - InvalidateRect(); - } - } - - EndTimer(); - m_bMouseDown = false; - - return true; -} - -void CPWL_ScrollBar::OnNotify(CPWL_Wnd* pWnd, - uint32_t msg, - intptr_t wParam, - intptr_t lParam) { - CPWL_Wnd::OnNotify(pWnd, msg, wParam, lParam); - - switch (msg) { - case PNM_LBUTTONDOWN: - if (pWnd == m_pMinButton) { - OnMinButtonLBDown(*(CFX_PointF*)lParam); - } - - if (pWnd == m_pMaxButton) { - OnMaxButtonLBDown(*(CFX_PointF*)lParam); - } - - if (pWnd == m_pPosButton) { - OnPosButtonLBDown(*(CFX_PointF*)lParam); - } - break; - case PNM_LBUTTONUP: - if (pWnd == m_pMinButton) { - OnMinButtonLBUp(*(CFX_PointF*)lParam); - } - - if (pWnd == m_pMaxButton) { - OnMaxButtonLBUp(*(CFX_PointF*)lParam); - } - - if (pWnd == m_pPosButton) { - OnPosButtonLBUp(*(CFX_PointF*)lParam); - } - break; - case PNM_MOUSEMOVE: - if (pWnd == m_pMinButton) { - OnMinButtonMouseMove(*(CFX_PointF*)lParam); - } - - if (pWnd == m_pMaxButton) { - OnMaxButtonMouseMove(*(CFX_PointF*)lParam); - } - - if (pWnd == m_pPosButton) { - OnPosButtonMouseMove(*(CFX_PointF*)lParam); - } - break; - case PNM_SETSCROLLINFO: { - PWL_SCROLL_INFO* pInfo = reinterpret_cast<PWL_SCROLL_INFO*>(lParam); - if (pInfo && *pInfo != m_OriginInfo) { - m_OriginInfo = *pInfo; - float fMax = - pInfo->fContentMax - pInfo->fContentMin - pInfo->fPlateWidth; - fMax = fMax > 0.0f ? fMax : 0.0f; - SetScrollRange(0, fMax, pInfo->fPlateWidth); - SetScrollStep(pInfo->fBigStep, pInfo->fSmallStep); - } - } break; - case PNM_SETSCROLLPOS: { - float fPos = *(float*)lParam; - switch (m_sbType) { - case SBT_HSCROLL: - fPos = fPos - m_OriginInfo.fContentMin; - break; - case SBT_VSCROLL: - fPos = m_OriginInfo.fContentMax - fPos; - break; - } - SetScrollPos(fPos); - } break; - } -} - -void CPWL_ScrollBar::CreateButtons(const PWL_CREATEPARAM& cp) { - PWL_CREATEPARAM scp = cp; - scp.pParentWnd = this; - scp.dwBorderWidth = 2; - scp.nBorderStyle = BorderStyle::BEVELED; - - scp.dwFlags = - PWS_VISIBLE | PWS_CHILD | PWS_BORDER | PWS_BACKGROUND | PWS_NOREFRESHCLIP; - - if (!m_pMinButton) { - m_pMinButton = new CPWL_SBButton(m_sbType, PSBT_MIN); - m_pMinButton->Create(scp); - } - - if (!m_pMaxButton) { - m_pMaxButton = new CPWL_SBButton(m_sbType, PSBT_MAX); - m_pMaxButton->Create(scp); - } - - if (!m_pPosButton) { - m_pPosButton = new CPWL_SBButton(m_sbType, PSBT_POS); - m_pPosButton->SetVisible(false); - m_pPosButton->Create(scp); - } -} - -float CPWL_ScrollBar::GetScrollBarWidth() const { - if (!IsVisible()) - return 0; - - return PWL_SCROLLBAR_WIDTH; -} - -void CPWL_ScrollBar::SetScrollRange(float fMin, - float fMax, - float fClientWidth) { - if (m_pPosButton) { - m_sData.SetScrollRange(fMin, fMax); - m_sData.SetClientWidth(fClientWidth); - - if (IsFloatSmaller(m_sData.ScrollRange.GetWidth(), 0.0f)) { - m_pPosButton->SetVisible(false); - } else { - m_pPosButton->SetVisible(true); - MovePosButton(true); - } - } -} - -void CPWL_ScrollBar::SetScrollPos(float fPos) { - float fOldPos = m_sData.fScrollPos; - - m_sData.SetPos(fPos); - - if (!IsFloatEqual(m_sData.fScrollPos, fOldPos)) - MovePosButton(true); -} - -void CPWL_ScrollBar::SetScrollStep(float fBigStep, float fSmallStep) { - m_sData.SetBigStep(fBigStep); - m_sData.SetSmallStep(fSmallStep); -} - -void CPWL_ScrollBar::MovePosButton(bool bRefresh) { - ASSERT(m_pMinButton); - ASSERT(m_pMaxButton); - - if (m_pPosButton->IsVisible()) { - CFX_FloatRect rcClient; - CFX_FloatRect rcPosArea, rcPosButton; - - rcClient = GetClientRect(); - rcPosArea = GetScrollArea(); - - float fLeft, fRight, fTop, fBottom; - - switch (m_sbType) { - case SBT_HSCROLL: - fLeft = TrueToFace(m_sData.fScrollPos); - fRight = TrueToFace(m_sData.fScrollPos + m_sData.fClientWidth); - - if (fRight - fLeft < PWL_SCROLLBAR_POSBUTTON_MINWIDTH) - fRight = fLeft + PWL_SCROLLBAR_POSBUTTON_MINWIDTH; - - if (fRight > rcPosArea.right) { - fRight = rcPosArea.right; - fLeft = fRight - PWL_SCROLLBAR_POSBUTTON_MINWIDTH; - } - - rcPosButton = - CFX_FloatRect(fLeft, rcPosArea.bottom, fRight, rcPosArea.top); - - break; - case SBT_VSCROLL: - fBottom = TrueToFace(m_sData.fScrollPos + m_sData.fClientWidth); - fTop = TrueToFace(m_sData.fScrollPos); - - if (IsFloatSmaller(fTop - fBottom, PWL_SCROLLBAR_POSBUTTON_MINWIDTH)) - fBottom = fTop - PWL_SCROLLBAR_POSBUTTON_MINWIDTH; - - if (IsFloatSmaller(fBottom, rcPosArea.bottom)) { - fBottom = rcPosArea.bottom; - fTop = fBottom + PWL_SCROLLBAR_POSBUTTON_MINWIDTH; - } - - rcPosButton = - CFX_FloatRect(rcPosArea.left, fBottom, rcPosArea.right, fTop); - - break; - } - - m_pPosButton->Move(rcPosButton, true, bRefresh); - } -} - -void CPWL_ScrollBar::OnMinButtonLBDown(const CFX_PointF& point) { - m_sData.SubSmall(); - MovePosButton(true); - NotifyScrollWindow(); - - m_bMinOrMax = true; - - EndTimer(); - BeginTimer(100); -} - -void CPWL_ScrollBar::OnMinButtonLBUp(const CFX_PointF& point) {} - -void CPWL_ScrollBar::OnMinButtonMouseMove(const CFX_PointF& point) {} - -void CPWL_ScrollBar::OnMaxButtonLBDown(const CFX_PointF& point) { - m_sData.AddSmall(); - MovePosButton(true); - NotifyScrollWindow(); - - m_bMinOrMax = false; - - EndTimer(); - BeginTimer(100); -} - -void CPWL_ScrollBar::OnMaxButtonLBUp(const CFX_PointF& point) {} - -void CPWL_ScrollBar::OnMaxButtonMouseMove(const CFX_PointF& point) {} - -void CPWL_ScrollBar::OnPosButtonLBDown(const CFX_PointF& point) { - m_bMouseDown = true; - - if (m_pPosButton) { - CFX_FloatRect rcPosButton = m_pPosButton->GetWindowRect(); - - switch (m_sbType) { - case SBT_HSCROLL: - m_nOldPos = point.x; - m_fOldPosButton = rcPosButton.left; - break; - case SBT_VSCROLL: - m_nOldPos = point.y; - m_fOldPosButton = rcPosButton.top; - break; - } - } -} - -void CPWL_ScrollBar::OnPosButtonLBUp(const CFX_PointF& point) { - if (m_bMouseDown) { - if (!m_bNotifyForever) - NotifyScrollWindow(); - } - m_bMouseDown = false; -} - -void CPWL_ScrollBar::OnPosButtonMouseMove(const CFX_PointF& point) { - float fOldScrollPos = m_sData.fScrollPos; - - float fNewPos = 0; - - switch (m_sbType) { - case SBT_HSCROLL: - if (fabs(point.x - m_nOldPos) < 1) - return; - fNewPos = FaceToTrue(m_fOldPosButton + point.x - m_nOldPos); - break; - case SBT_VSCROLL: - if (fabs(point.y - m_nOldPos) < 1) - return; - fNewPos = FaceToTrue(m_fOldPosButton + point.y - m_nOldPos); - break; - } - - if (m_bMouseDown) { - switch (m_sbType) { - case SBT_HSCROLL: - - if (IsFloatSmaller(fNewPos, m_sData.ScrollRange.fMin)) { - fNewPos = m_sData.ScrollRange.fMin; - } - - if (IsFloatBigger(fNewPos, m_sData.ScrollRange.fMax)) { - fNewPos = m_sData.ScrollRange.fMax; - } - - m_sData.SetPos(fNewPos); - - break; - case SBT_VSCROLL: - - if (IsFloatSmaller(fNewPos, m_sData.ScrollRange.fMin)) { - fNewPos = m_sData.ScrollRange.fMin; - } - - if (IsFloatBigger(fNewPos, m_sData.ScrollRange.fMax)) { - fNewPos = m_sData.ScrollRange.fMax; - } - - m_sData.SetPos(fNewPos); - - break; - } - - if (!IsFloatEqual(fOldScrollPos, m_sData.fScrollPos)) { - MovePosButton(true); - - if (m_bNotifyForever) - NotifyScrollWindow(); - } - } -} - -void CPWL_ScrollBar::NotifyScrollWindow() { - if (CPWL_Wnd* pParent = GetParentWindow()) { - float fPos; - switch (m_sbType) { - case SBT_HSCROLL: - fPos = m_OriginInfo.fContentMin + m_sData.fScrollPos; - break; - case SBT_VSCROLL: - fPos = m_OriginInfo.fContentMax - m_sData.fScrollPos; - break; - } - pParent->OnNotify(this, PNM_SCROLLWINDOW, (intptr_t)m_sbType, - (intptr_t)&fPos); - } -} - -CFX_FloatRect CPWL_ScrollBar::GetScrollArea() const { - CFX_FloatRect rcClient = GetClientRect(); - CFX_FloatRect rcArea; - - if (!m_pMinButton || !m_pMaxButton) - return rcClient; - - CFX_FloatRect rcMin = m_pMinButton->GetWindowRect(); - CFX_FloatRect rcMax = m_pMaxButton->GetWindowRect(); - - float fMinWidth = rcMin.right - rcMin.left; - float fMinHeight = rcMin.top - rcMin.bottom; - float fMaxWidth = rcMax.right - rcMax.left; - float fMaxHeight = rcMax.top - rcMax.bottom; - - switch (m_sbType) { - case SBT_HSCROLL: - if (rcClient.right - rcClient.left > fMinWidth + fMaxWidth + 2) { - rcArea = CFX_FloatRect(rcClient.left + fMinWidth + 1, rcClient.bottom, - rcClient.right - fMaxWidth - 1, rcClient.top); - } else { - rcArea = CFX_FloatRect(rcClient.left + fMinWidth + 1, rcClient.bottom, - rcClient.left + fMinWidth + 1, rcClient.top); - } - break; - case SBT_VSCROLL: - if (rcClient.top - rcClient.bottom > fMinHeight + fMaxHeight + 2) { - rcArea = CFX_FloatRect(rcClient.left, rcClient.bottom + fMinHeight + 1, - rcClient.right, rcClient.top - fMaxHeight - 1); - } else { - rcArea = - CFX_FloatRect(rcClient.left, rcClient.bottom + fMinHeight + 1, - rcClient.right, rcClient.bottom + fMinHeight + 1); - } - break; - } - - rcArea.Normalize(); - - return rcArea; -} - -float CPWL_ScrollBar::TrueToFace(float fTrue) { - CFX_FloatRect rcPosArea; - rcPosArea = GetScrollArea(); - - float fFactWidth = m_sData.ScrollRange.GetWidth() + m_sData.fClientWidth; - fFactWidth = fFactWidth == 0 ? 1 : fFactWidth; - - float fFace = 0; - - switch (m_sbType) { - case SBT_HSCROLL: - fFace = rcPosArea.left + - fTrue * (rcPosArea.right - rcPosArea.left) / fFactWidth; - break; - case SBT_VSCROLL: - fFace = rcPosArea.top - - fTrue * (rcPosArea.top - rcPosArea.bottom) / fFactWidth; - break; - } - - return fFace; -} - -float CPWL_ScrollBar::FaceToTrue(float fFace) { - CFX_FloatRect rcPosArea; - rcPosArea = GetScrollArea(); - - float fFactWidth = m_sData.ScrollRange.GetWidth() + m_sData.fClientWidth; - fFactWidth = fFactWidth == 0 ? 1 : fFactWidth; - - float fTrue = 0; - - switch (m_sbType) { - case SBT_HSCROLL: - fTrue = (fFace - rcPosArea.left) * fFactWidth / - (rcPosArea.right - rcPosArea.left); - break; - case SBT_VSCROLL: - fTrue = (rcPosArea.top - fFace) * fFactWidth / - (rcPosArea.top - rcPosArea.bottom); - break; - } - - return fTrue; -} - -void CPWL_ScrollBar::CreateChildWnd(const PWL_CREATEPARAM& cp) { - CreateButtons(cp); -} - -void CPWL_ScrollBar::TimerProc() { - PWL_SCROLL_PRIVATEDATA sTemp = m_sData; - if (m_bMinOrMax) - m_sData.SubSmall(); - else - m_sData.AddSmall(); - - if (sTemp != m_sData) { - MovePosButton(true); - NotifyScrollWindow(); - } -} diff --git a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/PWL_Utils.cpp b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/PWL_Utils.cpp deleted file mode 100644 index dbac6ad8bc9..00000000000 --- a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/PWL_Utils.cpp +++ /dev/null @@ -1,1155 +0,0 @@ -// Copyright 2014 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 "fpdfsdk/pdfwindow/PWL_Utils.h" - -#include <algorithm> -#include <memory> - -#include "core/fpdfdoc/cpvt_word.h" -#include "core/fxge/cfx_graphstatedata.h" -#include "core/fxge/cfx_pathdata.h" -#include "core/fxge/cfx_renderdevice.h" -#include "fpdfsdk/fxedit/fxet_edit.h" -#include "fpdfsdk/pdfwindow/PWL_Icon.h" -#include "fpdfsdk/pdfwindow/PWL_Wnd.h" - -CFX_FloatRect CPWL_Utils::OffsetRect(const CFX_FloatRect& rect, - float x, - float y) { - return CFX_FloatRect(rect.left + x, rect.bottom + y, rect.right + x, - rect.top + y); -} - -CPVT_WordRange CPWL_Utils::OverlapWordRange(const CPVT_WordRange& wr1, - const CPVT_WordRange& wr2) { - if (wr2.EndPos < wr1.BeginPos || wr2.BeginPos > wr1.EndPos || - wr1.EndPos < wr2.BeginPos || wr1.BeginPos > wr2.EndPos) { - return CPVT_WordRange(); - } - - return CPVT_WordRange(std::max(wr1.BeginPos, wr2.BeginPos), - std::min(wr1.EndPos, wr2.EndPos)); -} - -CFX_ByteString CPWL_Utils::GetAP_Check(const CFX_FloatRect& crBBox) { - const float fWidth = crBBox.right - crBBox.left; - const float fHeight = crBBox.top - crBBox.bottom; - - CFX_PointF pts[8][3] = {{CFX_PointF(0.28f, 0.52f), CFX_PointF(0.27f, 0.48f), - CFX_PointF(0.29f, 0.40f)}, - {CFX_PointF(0.30f, 0.33f), CFX_PointF(0.31f, 0.29f), - CFX_PointF(0.31f, 0.28f)}, - {CFX_PointF(0.39f, 0.28f), CFX_PointF(0.49f, 0.29f), - CFX_PointF(0.77f, 0.67f)}, - {CFX_PointF(0.76f, 0.68f), CFX_PointF(0.78f, 0.69f), - CFX_PointF(0.76f, 0.75f)}, - {CFX_PointF(0.76f, 0.75f), CFX_PointF(0.73f, 0.80f), - CFX_PointF(0.68f, 0.75f)}, - {CFX_PointF(0.68f, 0.74f), CFX_PointF(0.68f, 0.74f), - CFX_PointF(0.44f, 0.47f)}, - {CFX_PointF(0.43f, 0.47f), CFX_PointF(0.40f, 0.47f), - CFX_PointF(0.41f, 0.58f)}, - {CFX_PointF(0.40f, 0.60f), CFX_PointF(0.28f, 0.66f), - CFX_PointF(0.30f, 0.56f)}}; - - for (size_t i = 0; i < FX_ArraySize(pts); ++i) { - for (size_t j = 0; j < FX_ArraySize(pts[0]); ++j) { - pts[i][j].x = pts[i][j].x * fWidth + crBBox.left; - pts[i][j].y *= pts[i][j].y * fHeight + crBBox.bottom; - } - } - - CFX_ByteTextBuf csAP; - csAP << pts[0][0].x << " " << pts[0][0].y << " m\n"; - - for (size_t i = 0; i < FX_ArraySize(pts); ++i) { - size_t nNext = i < FX_ArraySize(pts) - 1 ? i + 1 : 0; - - float px1 = pts[i][1].x - pts[i][0].x; - float py1 = pts[i][1].y - pts[i][0].y; - float px2 = pts[i][2].x - pts[nNext][0].x; - float py2 = pts[i][2].y - pts[nNext][0].y; - - csAP << pts[i][0].x + px1 * FX_BEZIER << " " - << pts[i][0].y + py1 * FX_BEZIER << " " - << pts[nNext][0].x + px2 * FX_BEZIER << " " - << pts[nNext][0].y + py2 * FX_BEZIER << " " << pts[nNext][0].x << " " - << pts[nNext][0].y << " c\n"; - } - - return csAP.MakeString(); -} - -CFX_ByteString CPWL_Utils::GetAP_Circle(const CFX_FloatRect& crBBox) { - CFX_ByteTextBuf csAP; - - float fWidth = crBBox.right - crBBox.left; - float fHeight = crBBox.top - crBBox.bottom; - - CFX_PointF pt1(crBBox.left, crBBox.bottom + fHeight / 2); - CFX_PointF pt2(crBBox.left + fWidth / 2, crBBox.top); - CFX_PointF pt3(crBBox.right, crBBox.bottom + fHeight / 2); - CFX_PointF pt4(crBBox.left + fWidth / 2, crBBox.bottom); - - csAP << pt1.x << " " << pt1.y << " m\n"; - - float px = pt2.x - pt1.x; - float py = pt2.y - pt1.y; - - csAP << pt1.x << " " << pt1.y + py * FX_BEZIER << " " - << pt2.x - px * FX_BEZIER << " " << pt2.y << " " << pt2.x << " " << pt2.y - << " c\n"; - - px = pt3.x - pt2.x; - py = pt2.y - pt3.y; - - csAP << pt2.x + px * FX_BEZIER << " " << pt2.y << " " << pt3.x << " " - << pt3.y + py * FX_BEZIER << " " << pt3.x << " " << pt3.y << " c\n"; - - px = pt3.x - pt4.x; - py = pt3.y - pt4.y; - - csAP << pt3.x << " " << pt3.y - py * FX_BEZIER << " " - << pt4.x + px * FX_BEZIER << " " << pt4.y << " " << pt4.x << " " << pt4.y - << " c\n"; - - px = pt4.x - pt1.x; - py = pt1.y - pt4.y; - - csAP << pt4.x - px * FX_BEZIER << " " << pt4.y << " " << pt1.x << " " - << pt1.y - py * FX_BEZIER << " " << pt1.x << " " << pt1.y << " c\n"; - - return csAP.MakeString(); -} - -CFX_ByteString CPWL_Utils::GetAP_Cross(const CFX_FloatRect& crBBox) { - CFX_ByteTextBuf csAP; - - csAP << crBBox.left << " " << crBBox.top << " m\n"; - csAP << crBBox.right << " " << crBBox.bottom << " l\n"; - csAP << crBBox.left << " " << crBBox.bottom << " m\n"; - csAP << crBBox.right << " " << crBBox.top << " l\n"; - - return csAP.MakeString(); -} - -CFX_ByteString CPWL_Utils::GetAP_Diamond(const CFX_FloatRect& crBBox) { - CFX_ByteTextBuf csAP; - - float fWidth = crBBox.right - crBBox.left; - float fHeight = crBBox.top - crBBox.bottom; - - CFX_PointF pt1(crBBox.left, crBBox.bottom + fHeight / 2); - CFX_PointF pt2(crBBox.left + fWidth / 2, crBBox.top); - CFX_PointF pt3(crBBox.right, crBBox.bottom + fHeight / 2); - CFX_PointF pt4(crBBox.left + fWidth / 2, crBBox.bottom); - - csAP << pt1.x << " " << pt1.y << " m\n"; - csAP << pt2.x << " " << pt2.y << " l\n"; - csAP << pt3.x << " " << pt3.y << " l\n"; - csAP << pt4.x << " " << pt4.y << " l\n"; - csAP << pt1.x << " " << pt1.y << " l\n"; - - return csAP.MakeString(); -} - -CFX_ByteString CPWL_Utils::GetAP_Square(const CFX_FloatRect& crBBox) { - CFX_ByteTextBuf csAP; - - csAP << crBBox.left << " " << crBBox.top << " m\n"; - csAP << crBBox.right << " " << crBBox.top << " l\n"; - csAP << crBBox.right << " " << crBBox.bottom << " l\n"; - csAP << crBBox.left << " " << crBBox.bottom << " l\n"; - csAP << crBBox.left << " " << crBBox.top << " l\n"; - - return csAP.MakeString(); -} - -CFX_ByteString CPWL_Utils::GetAP_Star(const CFX_FloatRect& crBBox) { - CFX_ByteTextBuf csAP; - - float fRadius = (crBBox.top - crBBox.bottom) / (1 + (float)cos(FX_PI / 5.0f)); - CFX_PointF ptCenter = CFX_PointF((crBBox.left + crBBox.right) / 2.0f, - (crBBox.top + crBBox.bottom) / 2.0f); - - float px[5], py[5]; - - float fAngel = FX_PI / 10.0f; - - for (int32_t i = 0; i < 5; i++) { - px[i] = ptCenter.x + fRadius * (float)cos(fAngel); - py[i] = ptCenter.y + fRadius * (float)sin(fAngel); - - fAngel += FX_PI * 2 / 5.0f; - } - - csAP << px[0] << " " << py[0] << " m\n"; - - int32_t nNext = 0; - for (int32_t j = 0; j < 5; j++) { - nNext += 2; - if (nNext >= 5) - nNext -= 5; - csAP << px[nNext] << " " << py[nNext] << " l\n"; - } - - return csAP.MakeString(); -} - -CFX_ByteString CPWL_Utils::GetAP_HalfCircle(const CFX_FloatRect& crBBox, - float fRotate) { - CFX_ByteTextBuf csAP; - - float fWidth = crBBox.right - crBBox.left; - float fHeight = crBBox.top - crBBox.bottom; - - CFX_PointF pt1(-fWidth / 2, 0); - CFX_PointF pt2(0, fHeight / 2); - CFX_PointF pt3(fWidth / 2, 0); - - float px, py; - - csAP << cos(fRotate) << " " << sin(fRotate) << " " << -sin(fRotate) << " " - << cos(fRotate) << " " << crBBox.left + fWidth / 2 << " " - << crBBox.bottom + fHeight / 2 << " cm\n"; - - csAP << pt1.x << " " << pt1.y << " m\n"; - - px = pt2.x - pt1.x; - py = pt2.y - pt1.y; - - csAP << pt1.x << " " << pt1.y + py * FX_BEZIER << " " - << pt2.x - px * FX_BEZIER << " " << pt2.y << " " << pt2.x << " " << pt2.y - << " c\n"; - - px = pt3.x - pt2.x; - py = pt2.y - pt3.y; - - csAP << pt2.x + px * FX_BEZIER << " " << pt2.y << " " << pt3.x << " " - << pt3.y + py * FX_BEZIER << " " << pt3.x << " " << pt3.y << " c\n"; - - return csAP.MakeString(); -} - -CFX_FloatRect CPWL_Utils::InflateRect(const CFX_FloatRect& rcRect, - float fSize) { - if (rcRect.IsEmpty()) - return rcRect; - - CFX_FloatRect rcNew(rcRect.left - fSize, rcRect.bottom - fSize, - rcRect.right + fSize, rcRect.top + fSize); - rcNew.Normalize(); - return rcNew; -} - -CFX_FloatRect CPWL_Utils::DeflateRect(const CFX_FloatRect& rcRect, - float fSize) { - if (rcRect.IsEmpty()) - return rcRect; - - CFX_FloatRect rcNew(rcRect.left + fSize, rcRect.bottom + fSize, - rcRect.right - fSize, rcRect.top - fSize); - rcNew.Normalize(); - return rcNew; -} - -CFX_FloatRect CPWL_Utils::ScaleRect(const CFX_FloatRect& rcRect, float fScale) { - float fHalfWidth = (rcRect.right - rcRect.left) / 2.0f; - float fHalfHeight = (rcRect.top - rcRect.bottom) / 2.0f; - - CFX_PointF ptCenter = CFX_PointF((rcRect.left + rcRect.right) / 2, - (rcRect.top + rcRect.bottom) / 2); - - return CFX_FloatRect( - ptCenter.x - fHalfWidth * fScale, ptCenter.y - fHalfHeight * fScale, - ptCenter.x + fHalfWidth * fScale, ptCenter.y + fHalfHeight * fScale); -} - -CFX_ByteString CPWL_Utils::GetRectFillAppStream(const CFX_FloatRect& rect, - const CPWL_Color& color) { - CFX_ByteTextBuf sAppStream; - CFX_ByteString sColor = GetColorAppStream(color, true); - if (sColor.GetLength() > 0) { - sAppStream << "q\n" << sColor; - sAppStream << rect.left << " " << rect.bottom << " " - << rect.right - rect.left << " " << rect.top - rect.bottom - << " re f\nQ\n"; - } - - return sAppStream.MakeString(); -} - -CFX_ByteString CPWL_Utils::GetCircleFillAppStream(const CFX_FloatRect& rect, - const CPWL_Color& color) { - CFX_ByteTextBuf sAppStream; - CFX_ByteString sColor = GetColorAppStream(color, true); - if (sColor.GetLength() > 0) { - sAppStream << "q\n" << sColor << CPWL_Utils::GetAP_Circle(rect) << "f\nQ\n"; - } - return sAppStream.MakeString(); -} - -CFX_FloatRect CPWL_Utils::GetCenterSquare(const CFX_FloatRect& rect) { - float fWidth = rect.right - rect.left; - float fHeight = rect.top - rect.bottom; - - float fCenterX = (rect.left + rect.right) / 2.0f; - float fCenterY = (rect.top + rect.bottom) / 2.0f; - - float fRadius = (fWidth > fHeight) ? fHeight / 2 : fWidth / 2; - - return CFX_FloatRect(fCenterX - fRadius, fCenterY - fRadius, - fCenterX + fRadius, fCenterY + fRadius); -} - -CFX_ByteString CPWL_Utils::GetEditAppStream(CFX_Edit* pEdit, - const CFX_PointF& ptOffset, - const CPVT_WordRange* pRange, - bool bContinuous, - uint16_t SubWord) { - return CFX_Edit::GetEditAppearanceStream(pEdit, ptOffset, pRange, bContinuous, - SubWord); -} - -CFX_ByteString CPWL_Utils::GetEditSelAppStream(CFX_Edit* pEdit, - const CFX_PointF& ptOffset, - const CPVT_WordRange* pRange) { - return CFX_Edit::GetSelectAppearanceStream(pEdit, ptOffset, pRange); -} - -CFX_ByteString CPWL_Utils::GetPushButtonAppStream(const CFX_FloatRect& rcBBox, - IPVT_FontMap* pFontMap, - CPDF_Stream* pIconStream, - CPDF_IconFit& IconFit, - const CFX_WideString& sLabel, - const CPWL_Color& crText, - float fFontSize, - int32_t nLayOut) { - const float fAutoFontScale = 1.0f / 3.0f; - - auto pEdit = pdfium::MakeUnique<CFX_Edit>(); - pEdit->SetFontMap(pFontMap); - pEdit->SetAlignmentH(1, true); - pEdit->SetAlignmentV(1, true); - pEdit->SetMultiLine(false, true); - pEdit->SetAutoReturn(false, true); - if (IsFloatZero(fFontSize)) - pEdit->SetAutoFontSize(true, true); - else - pEdit->SetFontSize(fFontSize); - - pEdit->Initialize(); - pEdit->SetText(sLabel); - - CFX_FloatRect rcLabelContent = pEdit->GetContentRect(); - CPWL_Icon Icon; - PWL_CREATEPARAM cp; - cp.dwFlags = PWS_VISIBLE; - Icon.Create(cp); - Icon.SetIconFit(&IconFit); - Icon.SetPDFStream(pIconStream); - - CFX_FloatRect rcLabel = CFX_FloatRect(0, 0, 0, 0); - CFX_FloatRect rcIcon = CFX_FloatRect(0, 0, 0, 0); - float fWidth = 0.0f; - float fHeight = 0.0f; - - switch (nLayOut) { - case PPBL_LABEL: - rcLabel = rcBBox; - rcIcon = CFX_FloatRect(0, 0, 0, 0); - break; - case PPBL_ICON: - rcIcon = rcBBox; - rcLabel = CFX_FloatRect(0, 0, 0, 0); - break; - case PPBL_ICONTOPLABELBOTTOM: - - if (pIconStream) { - if (IsFloatZero(fFontSize)) { - fHeight = rcBBox.top - rcBBox.bottom; - rcLabel = CFX_FloatRect(rcBBox.left, rcBBox.bottom, rcBBox.right, - rcBBox.bottom + fHeight * fAutoFontScale); - rcIcon = - CFX_FloatRect(rcBBox.left, rcLabel.top, rcBBox.right, rcBBox.top); - } else { - fHeight = rcLabelContent.Height(); - - if (rcBBox.bottom + fHeight > rcBBox.top) { - rcIcon = CFX_FloatRect(0, 0, 0, 0); - rcLabel = rcBBox; - } else { - rcLabel = CFX_FloatRect(rcBBox.left, rcBBox.bottom, rcBBox.right, - rcBBox.bottom + fHeight); - rcIcon = CFX_FloatRect(rcBBox.left, rcLabel.top, rcBBox.right, - rcBBox.top); - } - } - } else { - rcLabel = rcBBox; - rcIcon = CFX_FloatRect(0, 0, 0, 0); - } - - break; - case PPBL_LABELTOPICONBOTTOM: - - if (pIconStream) { - if (IsFloatZero(fFontSize)) { - fHeight = rcBBox.top - rcBBox.bottom; - rcLabel = - CFX_FloatRect(rcBBox.left, rcBBox.top - fHeight * fAutoFontScale, - rcBBox.right, rcBBox.top); - rcIcon = CFX_FloatRect(rcBBox.left, rcBBox.bottom, rcBBox.right, - rcLabel.bottom); - } else { - fHeight = rcLabelContent.Height(); - - if (rcBBox.bottom + fHeight > rcBBox.top) { - rcIcon = CFX_FloatRect(0, 0, 0, 0); - rcLabel = rcBBox; - } else { - rcLabel = CFX_FloatRect(rcBBox.left, rcBBox.top - fHeight, - rcBBox.right, rcBBox.top); - rcIcon = CFX_FloatRect(rcBBox.left, rcBBox.bottom, rcBBox.right, - rcLabel.bottom); - } - } - } else { - rcLabel = rcBBox; - rcIcon = CFX_FloatRect(0, 0, 0, 0); - } - - break; - case PPBL_ICONLEFTLABELRIGHT: - - if (pIconStream) { - if (IsFloatZero(fFontSize)) { - fWidth = rcBBox.right - rcBBox.left; - rcLabel = CFX_FloatRect(rcBBox.right - fWidth * fAutoFontScale, - rcBBox.bottom, rcBBox.right, rcBBox.top); - rcIcon = CFX_FloatRect(rcBBox.left, rcBBox.bottom, rcLabel.left, - rcBBox.top); - - if (rcLabelContent.Width() < fWidth * fAutoFontScale) { - } else { - if (rcLabelContent.Width() < fWidth) { - rcLabel = CFX_FloatRect(rcBBox.right - rcLabelContent.Width(), - rcBBox.bottom, rcBBox.right, rcBBox.top); - rcIcon = CFX_FloatRect(rcBBox.left, rcBBox.bottom, rcLabel.left, - rcBBox.top); - } else { - rcLabel = rcBBox; - rcIcon = CFX_FloatRect(0, 0, 0, 0); - } - } - } else { - fWidth = rcLabelContent.Width(); - - if (rcBBox.left + fWidth > rcBBox.right) { - rcLabel = rcBBox; - rcIcon = CFX_FloatRect(0, 0, 0, 0); - } else { - rcLabel = CFX_FloatRect(rcBBox.right - fWidth, rcBBox.bottom, - rcBBox.right, rcBBox.top); - rcIcon = CFX_FloatRect(rcBBox.left, rcBBox.bottom, rcLabel.left, - rcBBox.top); - } - } - } else { - rcLabel = rcBBox; - rcIcon = CFX_FloatRect(0, 0, 0, 0); - } - - break; - case PPBL_LABELLEFTICONRIGHT: - - if (pIconStream) { - if (IsFloatZero(fFontSize)) { - fWidth = rcBBox.right - rcBBox.left; - rcLabel = - CFX_FloatRect(rcBBox.left, rcBBox.bottom, - rcBBox.left + fWidth * fAutoFontScale, rcBBox.top); - rcIcon = CFX_FloatRect(rcLabel.right, rcBBox.bottom, rcBBox.right, - rcBBox.top); - - if (rcLabelContent.Width() < fWidth * fAutoFontScale) { - } else { - if (rcLabelContent.Width() < fWidth) { - rcLabel = CFX_FloatRect(rcBBox.left, rcBBox.bottom, - rcBBox.left + rcLabelContent.Width(), - rcBBox.top); - rcIcon = CFX_FloatRect(rcLabel.right, rcBBox.bottom, rcBBox.right, - rcBBox.top); - } else { - rcLabel = rcBBox; - rcIcon = CFX_FloatRect(0, 0, 0, 0); - } - } - } else { - fWidth = rcLabelContent.Width(); - - if (rcBBox.left + fWidth > rcBBox.right) { - rcLabel = rcBBox; - rcIcon = CFX_FloatRect(0, 0, 0, 0); - } else { - rcLabel = CFX_FloatRect(rcBBox.left, rcBBox.bottom, - rcBBox.left + fWidth, rcBBox.top); - rcIcon = CFX_FloatRect(rcLabel.right, rcBBox.bottom, rcBBox.right, - rcBBox.top); - } - } - } else { - rcLabel = rcBBox; - rcIcon = CFX_FloatRect(0, 0, 0, 0); - } - - break; - case PPBL_LABELOVERICON: - rcLabel = rcBBox; - rcIcon = rcBBox; - break; - } - - CFX_ByteTextBuf sAppStream, sTemp; - - if (!rcIcon.IsEmpty()) { - Icon.Move(rcIcon, false, false); - sTemp << Icon.GetImageAppStream(); - } - - Icon.Destroy(); - - if (!rcLabel.IsEmpty()) { - pEdit->SetPlateRect(rcLabel); - CFX_ByteString sEdit = - CPWL_Utils::GetEditAppStream(pEdit.get(), CFX_PointF(0.0f, 0.0f)); - if (sEdit.GetLength() > 0) { - sTemp << "BT\n" - << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n"; - } - } - - if (sTemp.GetSize() > 0) { - sAppStream << "q\n" - << rcBBox.left << " " << rcBBox.bottom << " " - << rcBBox.right - rcBBox.left << " " - << rcBBox.top - rcBBox.bottom << " re W n\n"; - sAppStream << sTemp << "Q\n"; - } - return sAppStream.MakeString(); -} - -CFX_ByteString CPWL_Utils::GetColorAppStream(const CPWL_Color& color, - const bool& bFillOrStroke) { - CFX_ByteTextBuf sColorStream; - - switch (color.nColorType) { - case COLORTYPE_RGB: - sColorStream << color.fColor1 << " " << color.fColor2 << " " - << color.fColor3 << " " << (bFillOrStroke ? "rg" : "RG") - << "\n"; - break; - case COLORTYPE_GRAY: - sColorStream << color.fColor1 << " " << (bFillOrStroke ? "g" : "G") - << "\n"; - break; - case COLORTYPE_CMYK: - sColorStream << color.fColor1 << " " << color.fColor2 << " " - << color.fColor3 << " " << color.fColor4 << " " - << (bFillOrStroke ? "k" : "K") << "\n"; - break; - } - - return sColorStream.MakeString(); -} - -CFX_ByteString CPWL_Utils::GetBorderAppStream(const CFX_FloatRect& rect, - float fWidth, - const CPWL_Color& color, - const CPWL_Color& crLeftTop, - const CPWL_Color& crRightBottom, - BorderStyle nStyle, - const CPWL_Dash& dash) { - CFX_ByteTextBuf sAppStream; - CFX_ByteString sColor; - - float fLeft = rect.left; - float fRight = rect.right; - float fTop = rect.top; - float fBottom = rect.bottom; - - if (fWidth > 0.0f) { - float fHalfWidth = fWidth / 2.0f; - - sAppStream << "q\n"; - - switch (nStyle) { - default: - case BorderStyle::SOLID: - sColor = CPWL_Utils::GetColorAppStream(color, true); - if (sColor.GetLength() > 0) { - sAppStream << sColor; - sAppStream << fLeft << " " << fBottom << " " << fRight - fLeft << " " - << fTop - fBottom << " re\n"; - sAppStream << fLeft + fWidth << " " << fBottom + fWidth << " " - << fRight - fLeft - fWidth * 2 << " " - << fTop - fBottom - fWidth * 2 << " re\n"; - sAppStream << "f*\n"; - } - break; - case BorderStyle::DASH: - sColor = CPWL_Utils::GetColorAppStream(color, false); - if (sColor.GetLength() > 0) { - sAppStream << sColor; - sAppStream << fWidth << " w" - << " [" << dash.nDash << " " << dash.nGap << "] " - << dash.nPhase << " d\n"; - sAppStream << fLeft + fWidth / 2 << " " << fBottom + fWidth / 2 - << " m\n"; - sAppStream << fLeft + fWidth / 2 << " " << fTop - fWidth / 2 - << " l\n"; - sAppStream << fRight - fWidth / 2 << " " << fTop - fWidth / 2 - << " l\n"; - sAppStream << fRight - fWidth / 2 << " " << fBottom + fWidth / 2 - << " l\n"; - sAppStream << fLeft + fWidth / 2 << " " << fBottom + fWidth / 2 - << " l S\n"; - } - break; - case BorderStyle::BEVELED: - case BorderStyle::INSET: - sColor = CPWL_Utils::GetColorAppStream(crLeftTop, true); - if (sColor.GetLength() > 0) { - sAppStream << sColor; - sAppStream << fLeft + fHalfWidth << " " << fBottom + fHalfWidth - << " m\n"; - sAppStream << fLeft + fHalfWidth << " " << fTop - fHalfWidth - << " l\n"; - sAppStream << fRight - fHalfWidth << " " << fTop - fHalfWidth - << " l\n"; - sAppStream << fRight - fHalfWidth * 2 << " " << fTop - fHalfWidth * 2 - << " l\n"; - sAppStream << fLeft + fHalfWidth * 2 << " " << fTop - fHalfWidth * 2 - << " l\n"; - sAppStream << fLeft + fHalfWidth * 2 << " " - << fBottom + fHalfWidth * 2 << " l f\n"; - } - - sColor = CPWL_Utils::GetColorAppStream(crRightBottom, true); - if (sColor.GetLength() > 0) { - sAppStream << sColor; - sAppStream << fRight - fHalfWidth << " " << fTop - fHalfWidth - << " m\n"; - sAppStream << fRight - fHalfWidth << " " << fBottom + fHalfWidth - << " l\n"; - sAppStream << fLeft + fHalfWidth << " " << fBottom + fHalfWidth - << " l\n"; - sAppStream << fLeft + fHalfWidth * 2 << " " - << fBottom + fHalfWidth * 2 << " l\n"; - sAppStream << fRight - fHalfWidth * 2 << " " - << fBottom + fHalfWidth * 2 << " l\n"; - sAppStream << fRight - fHalfWidth * 2 << " " << fTop - fHalfWidth * 2 - << " l f\n"; - } - - sColor = CPWL_Utils::GetColorAppStream(color, true); - if (sColor.GetLength() > 0) { - sAppStream << sColor; - sAppStream << fLeft << " " << fBottom << " " << fRight - fLeft << " " - << fTop - fBottom << " re\n"; - sAppStream << fLeft + fHalfWidth << " " << fBottom + fHalfWidth << " " - << fRight - fLeft - fHalfWidth * 2 << " " - << fTop - fBottom - fHalfWidth * 2 << " re f*\n"; - } - break; - case BorderStyle::UNDERLINE: - sColor = CPWL_Utils::GetColorAppStream(color, false); - if (sColor.GetLength() > 0) { - sAppStream << sColor; - sAppStream << fWidth << " w\n"; - sAppStream << fLeft << " " << fBottom + fWidth / 2 << " m\n"; - sAppStream << fRight << " " << fBottom + fWidth / 2 << " l S\n"; - } - break; - } - - sAppStream << "Q\n"; - } - - return sAppStream.MakeString(); -} - -CFX_ByteString CPWL_Utils::GetCircleBorderAppStream( - const CFX_FloatRect& rect, - float fWidth, - const CPWL_Color& color, - const CPWL_Color& crLeftTop, - const CPWL_Color& crRightBottom, - BorderStyle nStyle, - const CPWL_Dash& dash) { - CFX_ByteTextBuf sAppStream; - CFX_ByteString sColor; - - if (fWidth > 0.0f) { - sAppStream << "q\n"; - - switch (nStyle) { - default: - case BorderStyle::SOLID: - case BorderStyle::UNDERLINE: { - sColor = CPWL_Utils::GetColorAppStream(color, false); - if (sColor.GetLength() > 0) { - sAppStream << "q\n" << fWidth << " w\n" << sColor - << CPWL_Utils::GetAP_Circle( - CPWL_Utils::DeflateRect(rect, fWidth / 2.0f)) - << " S\nQ\n"; - } - } break; - case BorderStyle::DASH: { - sColor = CPWL_Utils::GetColorAppStream(color, false); - if (sColor.GetLength() > 0) { - sAppStream << "q\n" << fWidth << " w\n" - << "[" << dash.nDash << " " << dash.nGap << "] " - << dash.nPhase << " d\n" << sColor - << CPWL_Utils::GetAP_Circle( - CPWL_Utils::DeflateRect(rect, fWidth / 2.0f)) - << " S\nQ\n"; - } - } break; - case BorderStyle::BEVELED: { - float fHalfWidth = fWidth / 2.0f; - - sColor = CPWL_Utils::GetColorAppStream(color, false); - if (sColor.GetLength() > 0) { - sAppStream << "q\n" << fHalfWidth << " w\n" << sColor - << CPWL_Utils::GetAP_Circle(rect) << " S\nQ\n"; - } - - sColor = CPWL_Utils::GetColorAppStream(crLeftTop, false); - if (sColor.GetLength() > 0) { - sAppStream << "q\n" << fHalfWidth << " w\n" << sColor - << CPWL_Utils::GetAP_HalfCircle( - CPWL_Utils::DeflateRect(rect, fHalfWidth * 0.75f), - FX_PI / 4.0f) - << " S\nQ\n"; - } - - sColor = CPWL_Utils::GetColorAppStream(crRightBottom, false); - if (sColor.GetLength() > 0) { - sAppStream << "q\n" << fHalfWidth << " w\n" << sColor - << CPWL_Utils::GetAP_HalfCircle( - CPWL_Utils::DeflateRect(rect, fHalfWidth * 0.75f), - FX_PI * 5 / 4.0f) - << " S\nQ\n"; - } - } break; - case BorderStyle::INSET: { - float fHalfWidth = fWidth / 2.0f; - - sColor = CPWL_Utils::GetColorAppStream(color, false); - if (sColor.GetLength() > 0) { - sAppStream << "q\n" << fHalfWidth << " w\n" << sColor - << CPWL_Utils::GetAP_Circle(rect) << " S\nQ\n"; - } - - sColor = CPWL_Utils::GetColorAppStream(crLeftTop, false); - if (sColor.GetLength() > 0) { - sAppStream << "q\n" << fHalfWidth << " w\n" << sColor - << CPWL_Utils::GetAP_HalfCircle( - CPWL_Utils::DeflateRect(rect, fHalfWidth * 0.75f), - FX_PI / 4.0f) - << " S\nQ\n"; - } - - sColor = CPWL_Utils::GetColorAppStream(crRightBottom, false); - if (sColor.GetLength() > 0) { - sAppStream << "q\n" << fHalfWidth << " w\n" << sColor - << CPWL_Utils::GetAP_HalfCircle( - CPWL_Utils::DeflateRect(rect, fHalfWidth * 0.75f), - FX_PI * 5 / 4.0f) - << " S\nQ\n"; - } - } break; - } - - sAppStream << "Q\n"; - } - - return sAppStream.MakeString(); -} - -CFX_ByteString CPWL_Utils::GetAppStream_Check(const CFX_FloatRect& rcBBox, - const CPWL_Color& crText) { - CFX_ByteTextBuf sAP; - sAP << "q\n" - << CPWL_Utils::GetColorAppStream(crText, true) - << CPWL_Utils::GetAP_Check(rcBBox) << "f\nQ\n"; - return sAP.MakeString(); -} - -CFX_ByteString CPWL_Utils::GetAppStream_Circle(const CFX_FloatRect& rcBBox, - const CPWL_Color& crText) { - CFX_ByteTextBuf sAP; - sAP << "q\n" - << CPWL_Utils::GetColorAppStream(crText, true) - << CPWL_Utils::GetAP_Circle(rcBBox) << "f\nQ\n"; - return sAP.MakeString(); -} - -CFX_ByteString CPWL_Utils::GetAppStream_Cross(const CFX_FloatRect& rcBBox, - const CPWL_Color& crText) { - CFX_ByteTextBuf sAP; - sAP << "q\n" - << CPWL_Utils::GetColorAppStream(crText, false) - << CPWL_Utils::GetAP_Cross(rcBBox) << "S\nQ\n"; - return sAP.MakeString(); -} - -CFX_ByteString CPWL_Utils::GetAppStream_Diamond(const CFX_FloatRect& rcBBox, - const CPWL_Color& crText) { - CFX_ByteTextBuf sAP; - sAP << "q\n1 w\n" - << CPWL_Utils::GetColorAppStream(crText, true) - << CPWL_Utils::GetAP_Diamond(rcBBox) << "f\nQ\n"; - return sAP.MakeString(); -} - -CFX_ByteString CPWL_Utils::GetAppStream_Square(const CFX_FloatRect& rcBBox, - const CPWL_Color& crText) { - CFX_ByteTextBuf sAP; - sAP << "q\n" - << CPWL_Utils::GetColorAppStream(crText, true) - << CPWL_Utils::GetAP_Square(rcBBox) << "f\nQ\n"; - return sAP.MakeString(); -} - -CFX_ByteString CPWL_Utils::GetAppStream_Star(const CFX_FloatRect& rcBBox, - const CPWL_Color& crText) { - CFX_ByteTextBuf sAP; - sAP << "q\n" - << CPWL_Utils::GetColorAppStream(crText, true) - << CPWL_Utils::GetAP_Star(rcBBox) << "f\nQ\n"; - return sAP.MakeString(); -} - -CFX_ByteString CPWL_Utils::GetCheckBoxAppStream(const CFX_FloatRect& rcBBox, - int32_t nStyle, - const CPWL_Color& crText) { - CFX_FloatRect rcCenter = GetCenterSquare(rcBBox); - switch (nStyle) { - default: - case PCS_CHECK: - return GetAppStream_Check(rcCenter, crText); - case PCS_CIRCLE: - return GetAppStream_Circle(ScaleRect(rcCenter, 2.0f / 3.0f), crText); - case PCS_CROSS: - return GetAppStream_Cross(rcCenter, crText); - case PCS_DIAMOND: - return GetAppStream_Diamond(ScaleRect(rcCenter, 2.0f / 3.0f), crText); - case PCS_SQUARE: - return GetAppStream_Square(ScaleRect(rcCenter, 2.0f / 3.0f), crText); - case PCS_STAR: - return GetAppStream_Star(ScaleRect(rcCenter, 2.0f / 3.0f), crText); - } -} - -CFX_ByteString CPWL_Utils::GetRadioButtonAppStream(const CFX_FloatRect& rcBBox, - int32_t nStyle, - const CPWL_Color& crText) { - CFX_FloatRect rcCenter = GetCenterSquare(rcBBox); - switch (nStyle) { - default: - case PCS_CHECK: - return GetAppStream_Check(rcCenter, crText); - case PCS_CIRCLE: - return GetAppStream_Circle(ScaleRect(rcCenter, 1.0f / 2.0f), crText); - case PCS_CROSS: - return GetAppStream_Cross(rcCenter, crText); - case PCS_DIAMOND: - return GetAppStream_Diamond(ScaleRect(rcCenter, 2.0f / 3.0f), crText); - case PCS_SQUARE: - return GetAppStream_Square(ScaleRect(rcCenter, 2.0f / 3.0f), crText); - case PCS_STAR: - return GetAppStream_Star(ScaleRect(rcCenter, 2.0f / 3.0f), crText); - } -} - -CFX_ByteString CPWL_Utils::GetDropButtonAppStream(const CFX_FloatRect& rcBBox) { - CFX_ByteTextBuf sAppStream; - - if (!rcBBox.IsEmpty()) { - sAppStream << "q\n" - << CPWL_Utils::GetColorAppStream( - CPWL_Color(COLORTYPE_RGB, 220.0f / 255.0f, - 220.0f / 255.0f, 220.0f / 255.0f), - true); - sAppStream << rcBBox.left << " " << rcBBox.bottom << " " - << rcBBox.right - rcBBox.left << " " - << rcBBox.top - rcBBox.bottom << " re f\n"; - sAppStream << "Q\n"; - - sAppStream << "q\n" - << CPWL_Utils::GetBorderAppStream( - rcBBox, 2, CPWL_Color(COLORTYPE_GRAY, 0), - CPWL_Color(COLORTYPE_GRAY, 1), - CPWL_Color(COLORTYPE_GRAY, 0.5), BorderStyle::BEVELED, - CPWL_Dash(3, 0, 0)) - << "Q\n"; - - CFX_PointF ptCenter = CFX_PointF((rcBBox.left + rcBBox.right) / 2, - (rcBBox.top + rcBBox.bottom) / 2); - if (IsFloatBigger(rcBBox.right - rcBBox.left, 6) && - IsFloatBigger(rcBBox.top - rcBBox.bottom, 6)) { - sAppStream << "q\n" - << " 0 g\n"; - sAppStream << ptCenter.x - 3 << " " << ptCenter.y + 1.5f << " m\n"; - sAppStream << ptCenter.x + 3 << " " << ptCenter.y + 1.5f << " l\n"; - sAppStream << ptCenter.x << " " << ptCenter.y - 1.5f << " l\n"; - sAppStream << ptCenter.x - 3 << " " << ptCenter.y + 1.5f << " l f\n"; - sAppStream << "Q\n"; - } - } - - return sAppStream.MakeString(); -} - -void CPWL_Utils::DrawFillRect(CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device, - const CFX_FloatRect& rect, - const FX_COLORREF& color) { - CFX_PathData path; - CFX_FloatRect rcTemp(rect); - path.AppendRect(rcTemp.left, rcTemp.bottom, rcTemp.right, rcTemp.top); - pDevice->DrawPath(&path, pUser2Device, nullptr, color, 0, FXFILL_WINDING); -} - -void CPWL_Utils::DrawFillArea(CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device, - const CFX_PointF* pPts, - int32_t nCount, - const FX_COLORREF& color) { - CFX_PathData path; - path.AppendPoint(pPts[0], FXPT_TYPE::MoveTo, false); - for (int32_t i = 1; i < nCount; i++) - path.AppendPoint(pPts[i], FXPT_TYPE::LineTo, false); - - pDevice->DrawPath(&path, pUser2Device, nullptr, color, 0, FXFILL_ALTERNATE); -} - -void CPWL_Utils::DrawStrokeRect(CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device, - const CFX_FloatRect& rect, - const FX_COLORREF& color, - float fWidth) { - CFX_PathData path; - CFX_FloatRect rcTemp(rect); - path.AppendRect(rcTemp.left, rcTemp.bottom, rcTemp.right, rcTemp.top); - - CFX_GraphStateData gsd; - gsd.m_LineWidth = fWidth; - - pDevice->DrawPath(&path, pUser2Device, &gsd, 0, color, FXFILL_ALTERNATE); -} - -void CPWL_Utils::DrawStrokeLine(CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device, - const CFX_PointF& ptMoveTo, - const CFX_PointF& ptLineTo, - const FX_COLORREF& color, - float fWidth) { - CFX_PathData path; - path.AppendPoint(ptMoveTo, FXPT_TYPE::MoveTo, false); - path.AppendPoint(ptLineTo, FXPT_TYPE::LineTo, false); - - CFX_GraphStateData gsd; - gsd.m_LineWidth = fWidth; - - pDevice->DrawPath(&path, pUser2Device, &gsd, 0, color, FXFILL_ALTERNATE); -} - -void CPWL_Utils::DrawFillRect(CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device, - const CFX_FloatRect& rect, - const CPWL_Color& color, - int32_t nTransparency) { - CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rect, - color.ToFXColor(nTransparency)); -} - -void CPWL_Utils::DrawShadow(CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device, - bool bVertical, - bool bHorizontal, - CFX_FloatRect rect, - int32_t nTransparency, - int32_t nStartGray, - int32_t nEndGray) { - float fStepGray = 1.0f; - - if (bVertical) { - fStepGray = (nEndGray - nStartGray) / rect.Height(); - - for (float fy = rect.bottom + 0.5f; fy <= rect.top - 0.5f; fy += 1.0f) { - int32_t nGray = nStartGray + (int32_t)(fStepGray * (fy - rect.bottom)); - CPWL_Utils::DrawStrokeLine( - pDevice, pUser2Device, CFX_PointF(rect.left, fy), - CFX_PointF(rect.right, fy), - ArgbEncode(nTransparency, nGray, nGray, nGray), 1.5f); - } - } - - if (bHorizontal) { - fStepGray = (nEndGray - nStartGray) / rect.Width(); - - for (float fx = rect.left + 0.5f; fx <= rect.right - 0.5f; fx += 1.0f) { - int32_t nGray = nStartGray + (int32_t)(fStepGray * (fx - rect.left)); - CPWL_Utils::DrawStrokeLine( - pDevice, pUser2Device, CFX_PointF(fx, rect.bottom), - CFX_PointF(fx, rect.top), - ArgbEncode(nTransparency, nGray, nGray, nGray), 1.5f); - } - } -} - -void CPWL_Utils::DrawBorder(CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device, - const CFX_FloatRect& rect, - float fWidth, - const CPWL_Color& color, - const CPWL_Color& crLeftTop, - const CPWL_Color& crRightBottom, - BorderStyle nStyle, - int32_t nTransparency) { - float fLeft = rect.left; - float fRight = rect.right; - float fTop = rect.top; - float fBottom = rect.bottom; - - if (fWidth > 0.0f) { - float fHalfWidth = fWidth / 2.0f; - - switch (nStyle) { - default: - case BorderStyle::SOLID: { - CFX_PathData path; - path.AppendRect(fLeft, fBottom, fRight, fTop); - path.AppendRect(fLeft + fWidth, fBottom + fWidth, fRight - fWidth, - fTop - fWidth); - pDevice->DrawPath(&path, pUser2Device, nullptr, - color.ToFXColor(nTransparency), 0, FXFILL_ALTERNATE); - break; - } - case BorderStyle::DASH: { - CFX_PathData path; - path.AppendPoint( - CFX_PointF(fLeft + fWidth / 2.0f, fBottom + fWidth / 2.0f), - FXPT_TYPE::MoveTo, false); - path.AppendPoint( - CFX_PointF(fLeft + fWidth / 2.0f, fTop - fWidth / 2.0f), - FXPT_TYPE::LineTo, false); - path.AppendPoint( - CFX_PointF(fRight - fWidth / 2.0f, fTop - fWidth / 2.0f), - FXPT_TYPE::LineTo, false); - path.AppendPoint( - CFX_PointF(fRight - fWidth / 2.0f, fBottom + fWidth / 2.0f), - FXPT_TYPE::LineTo, false); - path.AppendPoint( - CFX_PointF(fLeft + fWidth / 2.0f, fBottom + fWidth / 2.0f), - FXPT_TYPE::LineTo, false); - - CFX_GraphStateData gsd; - gsd.SetDashCount(2); - gsd.m_DashArray[0] = 3.0f; - gsd.m_DashArray[1] = 3.0f; - gsd.m_DashPhase = 0; - - gsd.m_LineWidth = fWidth; - pDevice->DrawPath(&path, pUser2Device, &gsd, 0, - color.ToFXColor(nTransparency), FXFILL_WINDING); - break; - } - case BorderStyle::BEVELED: - case BorderStyle::INSET: { - CFX_GraphStateData gsd; - gsd.m_LineWidth = fHalfWidth; - - CFX_PathData pathLT; - - pathLT.AppendPoint(CFX_PointF(fLeft + fHalfWidth, fBottom + fHalfWidth), - FXPT_TYPE::MoveTo, false); - pathLT.AppendPoint(CFX_PointF(fLeft + fHalfWidth, fTop - fHalfWidth), - FXPT_TYPE::LineTo, false); - pathLT.AppendPoint(CFX_PointF(fRight - fHalfWidth, fTop - fHalfWidth), - FXPT_TYPE::LineTo, false); - pathLT.AppendPoint( - CFX_PointF(fRight - fHalfWidth * 2, fTop - fHalfWidth * 2), - FXPT_TYPE::LineTo, false); - pathLT.AppendPoint( - CFX_PointF(fLeft + fHalfWidth * 2, fTop - fHalfWidth * 2), - FXPT_TYPE::LineTo, false); - pathLT.AppendPoint( - CFX_PointF(fLeft + fHalfWidth * 2, fBottom + fHalfWidth * 2), - FXPT_TYPE::LineTo, false); - pathLT.AppendPoint(CFX_PointF(fLeft + fHalfWidth, fBottom + fHalfWidth), - FXPT_TYPE::LineTo, false); - - pDevice->DrawPath(&pathLT, pUser2Device, &gsd, - crLeftTop.ToFXColor(nTransparency), 0, - FXFILL_ALTERNATE); - - CFX_PathData pathRB; - pathRB.AppendPoint(CFX_PointF(fRight - fHalfWidth, fTop - fHalfWidth), - FXPT_TYPE::MoveTo, false); - pathRB.AppendPoint( - CFX_PointF(fRight - fHalfWidth, fBottom + fHalfWidth), - FXPT_TYPE::LineTo, false); - pathRB.AppendPoint(CFX_PointF(fLeft + fHalfWidth, fBottom + fHalfWidth), - FXPT_TYPE::LineTo, false); - pathRB.AppendPoint( - CFX_PointF(fLeft + fHalfWidth * 2, fBottom + fHalfWidth * 2), - FXPT_TYPE::LineTo, false); - pathRB.AppendPoint( - CFX_PointF(fRight - fHalfWidth * 2, fBottom + fHalfWidth * 2), - FXPT_TYPE::LineTo, false); - pathRB.AppendPoint( - CFX_PointF(fRight - fHalfWidth * 2, fTop - fHalfWidth * 2), - FXPT_TYPE::LineTo, false); - pathRB.AppendPoint(CFX_PointF(fRight - fHalfWidth, fTop - fHalfWidth), - FXPT_TYPE::LineTo, false); - - pDevice->DrawPath(&pathRB, pUser2Device, &gsd, - crRightBottom.ToFXColor(nTransparency), 0, - FXFILL_ALTERNATE); - - CFX_PathData path; - - path.AppendRect(fLeft, fBottom, fRight, fTop); - path.AppendRect(fLeft + fHalfWidth, fBottom + fHalfWidth, - fRight - fHalfWidth, fTop - fHalfWidth); - - pDevice->DrawPath(&path, pUser2Device, &gsd, - color.ToFXColor(nTransparency), 0, FXFILL_ALTERNATE); - break; - } - case BorderStyle::UNDERLINE: { - CFX_PathData path; - path.AppendPoint(CFX_PointF(fLeft, fBottom + fWidth / 2), - FXPT_TYPE::MoveTo, false); - path.AppendPoint(CFX_PointF(fRight, fBottom + fWidth / 2), - FXPT_TYPE::LineTo, false); - - CFX_GraphStateData gsd; - gsd.m_LineWidth = fWidth; - - pDevice->DrawPath(&path, pUser2Device, &gsd, 0, - color.ToFXColor(nTransparency), FXFILL_ALTERNATE); - break; - } - } - } -} - diff --git a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/PWL_Utils.h b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/PWL_Utils.h deleted file mode 100644 index 29fe2396356..00000000000 --- a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/PWL_Utils.h +++ /dev/null @@ -1,162 +0,0 @@ -// Copyright 2014 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 - -#ifndef FPDFSDK_PDFWINDOW_PWL_UTILS_H_ -#define FPDFSDK_PDFWINDOW_PWL_UTILS_H_ - -#include "core/fpdfdoc/cpvt_wordrange.h" -#include "fpdfsdk/pdfwindow/PWL_Wnd.h" - -class CFX_Edit; -struct CPWL_Color; - -#define PWL_MAKEDWORD(low, high) \ - ((uint32_t)((uint16_t)(low) | (uint32_t)(((uint16_t)(high)) << 16))) - -// checkbox & radiobutton style -#define PCS_CHECK 0 -#define PCS_CIRCLE 1 -#define PCS_CROSS 2 -#define PCS_DIAMOND 3 -#define PCS_SQUARE 4 -#define PCS_STAR 5 - -// pushbutton layout style -#define PPBL_LABEL 0 -#define PPBL_ICON 1 -#define PPBL_ICONTOPLABELBOTTOM 2 -#define PPBL_LABELTOPICONBOTTOM 3 -#define PPBL_ICONLEFTLABELRIGHT 4 -#define PPBL_LABELLEFTICONRIGHT 5 -#define PPBL_LABELOVERICON 6 - -class CPWL_Utils { - public: - static CFX_FloatRect InflateRect(const CFX_FloatRect& rcRect, float fSize); - static CFX_FloatRect DeflateRect(const CFX_FloatRect& rcRect, float fSize); - - static CPVT_WordRange OverlapWordRange(const CPVT_WordRange& wr1, - const CPVT_WordRange& wr2); - static CFX_FloatRect GetCenterSquare(const CFX_FloatRect& rect); - - static CFX_FloatRect OffsetRect(const CFX_FloatRect& rect, float x, float y); - - static CFX_ByteString GetColorAppStream(const CPWL_Color& color, - const bool& bFillOrStroke = true); - static CFX_ByteString GetBorderAppStream(const CFX_FloatRect& rect, - float fWidth, - const CPWL_Color& color, - const CPWL_Color& crLeftTop, - const CPWL_Color& crRightBottom, - BorderStyle nStyle, - const CPWL_Dash& dash); - static CFX_ByteString GetCircleBorderAppStream( - const CFX_FloatRect& rect, - float fWidth, - const CPWL_Color& color, - const CPWL_Color& crLeftTop, - const CPWL_Color& crRightBottom, - BorderStyle nStyle, - const CPWL_Dash& dash); - static CFX_ByteString GetRectFillAppStream(const CFX_FloatRect& rect, - const CPWL_Color& color); - static CFX_ByteString GetCircleFillAppStream(const CFX_FloatRect& rect, - const CPWL_Color& color); - static CFX_ByteString GetPushButtonAppStream(const CFX_FloatRect& rcBBox, - IPVT_FontMap* pFontMap, - CPDF_Stream* pIconStream, - CPDF_IconFit& IconFit, - const CFX_WideString& sLabel, - const CPWL_Color& crText, - float fFontSize, - int32_t nLayOut); - static CFX_ByteString GetCheckBoxAppStream(const CFX_FloatRect& rcBBox, - int32_t nStyle, - const CPWL_Color& crText); - static CFX_ByteString GetRadioButtonAppStream(const CFX_FloatRect& rcBBox, - int32_t nStyle, - const CPWL_Color& crText); - static CFX_ByteString GetEditAppStream(CFX_Edit* pEdit, - const CFX_PointF& ptOffset, - const CPVT_WordRange* pRange = nullptr, - bool bContinuous = true, - uint16_t SubWord = 0); - static CFX_ByteString GetEditSelAppStream( - CFX_Edit* pEdit, - const CFX_PointF& ptOffset, - const CPVT_WordRange* pRange = nullptr); - static CFX_ByteString GetDropButtonAppStream(const CFX_FloatRect& rcBBox); - - static void DrawFillRect(CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device, - const CFX_FloatRect& rect, - const CPWL_Color& color, - int32_t nTransparency); - static void DrawFillRect(CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device, - const CFX_FloatRect& rect, - const FX_COLORREF& color); - static void DrawStrokeRect(CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device, - const CFX_FloatRect& rect, - const FX_COLORREF& color, - float fWidth); - static void DrawStrokeLine(CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device, - const CFX_PointF& ptMoveTo, - const CFX_PointF& ptLineTo, - const FX_COLORREF& color, - float fWidth); - static void DrawBorder(CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device, - const CFX_FloatRect& rect, - float fWidth, - const CPWL_Color& color, - const CPWL_Color& crLeftTop, - const CPWL_Color& crRightBottom, - BorderStyle nStyle, - int32_t nTransparency); - static void DrawFillArea(CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device, - const CFX_PointF* pPts, - int32_t nCount, - const FX_COLORREF& color); - static void DrawShadow(CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device, - bool bVertical, - bool bHorizontal, - CFX_FloatRect rect, - int32_t nTransparency, - int32_t nStartGray, - int32_t nEndGray); - - private: - static CFX_FloatRect ScaleRect(const CFX_FloatRect& rcRect, float fScale); - - static CFX_ByteString GetAppStream_Check(const CFX_FloatRect& rcBBox, - const CPWL_Color& crText); - static CFX_ByteString GetAppStream_Circle(const CFX_FloatRect& rcBBox, - const CPWL_Color& crText); - static CFX_ByteString GetAppStream_Cross(const CFX_FloatRect& rcBBox, - const CPWL_Color& crText); - static CFX_ByteString GetAppStream_Diamond(const CFX_FloatRect& rcBBox, - const CPWL_Color& crText); - static CFX_ByteString GetAppStream_Square(const CFX_FloatRect& rcBBox, - const CPWL_Color& crText); - static CFX_ByteString GetAppStream_Star(const CFX_FloatRect& rcBBox, - const CPWL_Color& crText); - - static CFX_ByteString GetAP_Check(const CFX_FloatRect& crBBox); - static CFX_ByteString GetAP_Circle(const CFX_FloatRect& crBBox); - static CFX_ByteString GetAP_Cross(const CFX_FloatRect& crBBox); - static CFX_ByteString GetAP_Diamond(const CFX_FloatRect& crBBox); - static CFX_ByteString GetAP_Square(const CFX_FloatRect& crBBox); - static CFX_ByteString GetAP_Star(const CFX_FloatRect& crBBox); - static CFX_ByteString GetAP_HalfCircle(const CFX_FloatRect& crBBox, - float fRotate); -}; - -#endif // FPDFSDK_PDFWINDOW_PWL_UTILS_H_ diff --git a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_appstream.cpp b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_appstream.cpp new file mode 100644 index 00000000000..f7b57365dff --- /dev/null +++ b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_appstream.cpp @@ -0,0 +1,1865 @@ +// Copyright 2017 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 "fpdfsdk/pdfwindow/cpwl_appstream.h" + +#include <utility> + +#include "core/fpdfapi/parser/cpdf_dictionary.h" +#include "core/fpdfapi/parser/cpdf_document.h" +#include "core/fpdfapi/parser/cpdf_name.h" +#include "core/fpdfapi/parser/cpdf_number.h" +#include "core/fpdfapi/parser/cpdf_reference.h" +#include "core/fpdfapi/parser/cpdf_stream.h" +#include "core/fpdfapi/parser/cpdf_string.h" +#include "core/fpdfapi/parser/fpdf_parser_decode.h" +#include "core/fpdfdoc/cpvt_word.h" +#include "fpdfsdk/cpdfsdk_formfillenvironment.h" +#include "fpdfsdk/cpdfsdk_interform.h" +#include "fpdfsdk/cpdfsdk_pageview.h" +#include "fpdfsdk/cpdfsdk_widget.h" +#include "fpdfsdk/formfiller/cba_fontmap.h" +#include "fpdfsdk/fxedit/fxet_edit.h" +#include "fpdfsdk/pdfwindow/cpwl_edit.h" +#include "fpdfsdk/pdfwindow/cpwl_icon.h" +#include "fpdfsdk/pdfwindow/cpwl_wnd.h" + +namespace { + +// Checkbox & radiobutton styles. +enum class CheckStyle { kCheck = 0, kCircle, kCross, kDiamond, kSquare, kStar }; + +// Pushbutton layout styles. +enum class ButtonStyle { + kLabel = 0, + kIcon, + kIconTopLabelBottom, + kIconBottomLabelTop, + kIconLeftLabelRight, + kIconRightLabelLeft, + kLabelOverIcon +}; + +CFX_ByteString GetColorAppStream(const CFX_Color& color, + const bool& bFillOrStroke) { + std::ostringstream sColorStream; + + switch (color.nColorType) { + case COLORTYPE_RGB: + sColorStream << color.fColor1 << " " << color.fColor2 << " " + << color.fColor3 << " " << (bFillOrStroke ? "rg" : "RG") + << "\n"; + break; + case COLORTYPE_GRAY: + sColorStream << color.fColor1 << " " << (bFillOrStroke ? "g" : "G") + << "\n"; + break; + case COLORTYPE_CMYK: + sColorStream << color.fColor1 << " " << color.fColor2 << " " + << color.fColor3 << " " << color.fColor4 << " " + << (bFillOrStroke ? "k" : "K") << "\n"; + break; + } + + return CFX_ByteString(sColorStream); +} + +CFX_ByteString GetAP_Check(const CFX_FloatRect& crBBox) { + const float fWidth = crBBox.right - crBBox.left; + const float fHeight = crBBox.top - crBBox.bottom; + + CFX_PointF pts[8][3] = {{CFX_PointF(0.28f, 0.52f), CFX_PointF(0.27f, 0.48f), + CFX_PointF(0.29f, 0.40f)}, + {CFX_PointF(0.30f, 0.33f), CFX_PointF(0.31f, 0.29f), + CFX_PointF(0.31f, 0.28f)}, + {CFX_PointF(0.39f, 0.28f), CFX_PointF(0.49f, 0.29f), + CFX_PointF(0.77f, 0.67f)}, + {CFX_PointF(0.76f, 0.68f), CFX_PointF(0.78f, 0.69f), + CFX_PointF(0.76f, 0.75f)}, + {CFX_PointF(0.76f, 0.75f), CFX_PointF(0.73f, 0.80f), + CFX_PointF(0.68f, 0.75f)}, + {CFX_PointF(0.68f, 0.74f), CFX_PointF(0.68f, 0.74f), + CFX_PointF(0.44f, 0.47f)}, + {CFX_PointF(0.43f, 0.47f), CFX_PointF(0.40f, 0.47f), + CFX_PointF(0.41f, 0.58f)}, + {CFX_PointF(0.40f, 0.60f), CFX_PointF(0.28f, 0.66f), + CFX_PointF(0.30f, 0.56f)}}; + + for (size_t i = 0; i < FX_ArraySize(pts); ++i) { + for (size_t j = 0; j < FX_ArraySize(pts[0]); ++j) { + pts[i][j].x = pts[i][j].x * fWidth + crBBox.left; + pts[i][j].y *= pts[i][j].y * fHeight + crBBox.bottom; + } + } + + std::ostringstream csAP; + csAP << pts[0][0].x << " " << pts[0][0].y << " m\n"; + + for (size_t i = 0; i < FX_ArraySize(pts); ++i) { + size_t nNext = i < FX_ArraySize(pts) - 1 ? i + 1 : 0; + + float px1 = pts[i][1].x - pts[i][0].x; + float py1 = pts[i][1].y - pts[i][0].y; + float px2 = pts[i][2].x - pts[nNext][0].x; + float py2 = pts[i][2].y - pts[nNext][0].y; + + csAP << pts[i][0].x + px1 * FX_BEZIER << " " + << pts[i][0].y + py1 * FX_BEZIER << " " + << pts[nNext][0].x + px2 * FX_BEZIER << " " + << pts[nNext][0].y + py2 * FX_BEZIER << " " << pts[nNext][0].x << " " + << pts[nNext][0].y << " c\n"; + } + + return CFX_ByteString(csAP); +} + +CFX_ByteString GetAP_Circle(const CFX_FloatRect& crBBox) { + std::ostringstream csAP; + + float fWidth = crBBox.right - crBBox.left; + float fHeight = crBBox.top - crBBox.bottom; + + CFX_PointF pt1(crBBox.left, crBBox.bottom + fHeight / 2); + CFX_PointF pt2(crBBox.left + fWidth / 2, crBBox.top); + CFX_PointF pt3(crBBox.right, crBBox.bottom + fHeight / 2); + CFX_PointF pt4(crBBox.left + fWidth / 2, crBBox.bottom); + + csAP << pt1.x << " " << pt1.y << " m\n"; + + float px = pt2.x - pt1.x; + float py = pt2.y - pt1.y; + + csAP << pt1.x << " " << pt1.y + py * FX_BEZIER << " " + << pt2.x - px * FX_BEZIER << " " << pt2.y << " " << pt2.x << " " << pt2.y + << " c\n"; + + px = pt3.x - pt2.x; + py = pt2.y - pt3.y; + + csAP << pt2.x + px * FX_BEZIER << " " << pt2.y << " " << pt3.x << " " + << pt3.y + py * FX_BEZIER << " " << pt3.x << " " << pt3.y << " c\n"; + + px = pt3.x - pt4.x; + py = pt3.y - pt4.y; + + csAP << pt3.x << " " << pt3.y - py * FX_BEZIER << " " + << pt4.x + px * FX_BEZIER << " " << pt4.y << " " << pt4.x << " " << pt4.y + << " c\n"; + + px = pt4.x - pt1.x; + py = pt1.y - pt4.y; + + csAP << pt4.x - px * FX_BEZIER << " " << pt4.y << " " << pt1.x << " " + << pt1.y - py * FX_BEZIER << " " << pt1.x << " " << pt1.y << " c\n"; + + return CFX_ByteString(csAP); +} + +CFX_ByteString GetAP_Cross(const CFX_FloatRect& crBBox) { + std::ostringstream csAP; + + csAP << crBBox.left << " " << crBBox.top << " m\n"; + csAP << crBBox.right << " " << crBBox.bottom << " l\n"; + csAP << crBBox.left << " " << crBBox.bottom << " m\n"; + csAP << crBBox.right << " " << crBBox.top << " l\n"; + + return CFX_ByteString(csAP); +} + +CFX_ByteString GetAP_Diamond(const CFX_FloatRect& crBBox) { + std::ostringstream csAP; + + float fWidth = crBBox.right - crBBox.left; + float fHeight = crBBox.top - crBBox.bottom; + + CFX_PointF pt1(crBBox.left, crBBox.bottom + fHeight / 2); + CFX_PointF pt2(crBBox.left + fWidth / 2, crBBox.top); + CFX_PointF pt3(crBBox.right, crBBox.bottom + fHeight / 2); + CFX_PointF pt4(crBBox.left + fWidth / 2, crBBox.bottom); + + csAP << pt1.x << " " << pt1.y << " m\n"; + csAP << pt2.x << " " << pt2.y << " l\n"; + csAP << pt3.x << " " << pt3.y << " l\n"; + csAP << pt4.x << " " << pt4.y << " l\n"; + csAP << pt1.x << " " << pt1.y << " l\n"; + + return CFX_ByteString(csAP); +} + +CFX_ByteString GetAP_Square(const CFX_FloatRect& crBBox) { + std::ostringstream csAP; + + csAP << crBBox.left << " " << crBBox.top << " m\n"; + csAP << crBBox.right << " " << crBBox.top << " l\n"; + csAP << crBBox.right << " " << crBBox.bottom << " l\n"; + csAP << crBBox.left << " " << crBBox.bottom << " l\n"; + csAP << crBBox.left << " " << crBBox.top << " l\n"; + + return CFX_ByteString(csAP); +} + +CFX_ByteString GetAP_Star(const CFX_FloatRect& crBBox) { + std::ostringstream csAP; + + float fRadius = (crBBox.top - crBBox.bottom) / (1 + (float)cos(FX_PI / 5.0f)); + CFX_PointF ptCenter = CFX_PointF((crBBox.left + crBBox.right) / 2.0f, + (crBBox.top + crBBox.bottom) / 2.0f); + + float px[5]; + float py[5]; + float fAngel = FX_PI / 10.0f; + for (int32_t i = 0; i < 5; i++) { + px[i] = ptCenter.x + fRadius * (float)cos(fAngel); + py[i] = ptCenter.y + fRadius * (float)sin(fAngel); + fAngel += FX_PI * 2 / 5.0f; + } + + csAP << px[0] << " " << py[0] << " m\n"; + + int32_t nNext = 0; + for (int32_t j = 0; j < 5; j++) { + nNext += 2; + if (nNext >= 5) + nNext -= 5; + csAP << px[nNext] << " " << py[nNext] << " l\n"; + } + + return CFX_ByteString(csAP); +} + +CFX_ByteString GetAP_HalfCircle(const CFX_FloatRect& crBBox, float fRotate) { + std::ostringstream csAP; + + float fWidth = crBBox.right - crBBox.left; + float fHeight = crBBox.top - crBBox.bottom; + + CFX_PointF pt1(-fWidth / 2, 0); + CFX_PointF pt2(0, fHeight / 2); + CFX_PointF pt3(fWidth / 2, 0); + + float px; + float py; + + csAP << cos(fRotate) << " " << sin(fRotate) << " " << -sin(fRotate) << " " + << cos(fRotate) << " " << crBBox.left + fWidth / 2 << " " + << crBBox.bottom + fHeight / 2 << " cm\n"; + + csAP << pt1.x << " " << pt1.y << " m\n"; + + px = pt2.x - pt1.x; + py = pt2.y - pt1.y; + + csAP << pt1.x << " " << pt1.y + py * FX_BEZIER << " " + << pt2.x - px * FX_BEZIER << " " << pt2.y << " " << pt2.x << " " << pt2.y + << " c\n"; + + px = pt3.x - pt2.x; + py = pt2.y - pt3.y; + + csAP << pt2.x + px * FX_BEZIER << " " << pt2.y << " " << pt3.x << " " + << pt3.y + py * FX_BEZIER << " " << pt3.x << " " << pt3.y << " c\n"; + + return CFX_ByteString(csAP); +} + +CFX_ByteString GetAppStream_Check(const CFX_FloatRect& rcBBox, + const CFX_Color& crText) { + std::ostringstream sAP; + sAP << "q\n" + << GetColorAppStream(crText, true) << GetAP_Check(rcBBox) << "f\nQ\n"; + return CFX_ByteString(sAP); +} + +CFX_ByteString GetAppStream_Circle(const CFX_FloatRect& rcBBox, + const CFX_Color& crText) { + std::ostringstream sAP; + sAP << "q\n" + << GetColorAppStream(crText, true) << GetAP_Circle(rcBBox) << "f\nQ\n"; + return CFX_ByteString(sAP); +} + +CFX_ByteString GetAppStream_Cross(const CFX_FloatRect& rcBBox, + const CFX_Color& crText) { + std::ostringstream sAP; + sAP << "q\n" + << GetColorAppStream(crText, false) << GetAP_Cross(rcBBox) << "S\nQ\n"; + return CFX_ByteString(sAP); +} + +CFX_ByteString GetAppStream_Diamond(const CFX_FloatRect& rcBBox, + const CFX_Color& crText) { + std::ostringstream sAP; + sAP << "q\n1 w\n" + << GetColorAppStream(crText, true) << GetAP_Diamond(rcBBox) << "f\nQ\n"; + return CFX_ByteString(sAP); +} + +CFX_ByteString GetAppStream_Square(const CFX_FloatRect& rcBBox, + const CFX_Color& crText) { + std::ostringstream sAP; + sAP << "q\n" + << GetColorAppStream(crText, true) << GetAP_Square(rcBBox) << "f\nQ\n"; + return CFX_ByteString(sAP); +} + +CFX_ByteString GetAppStream_Star(const CFX_FloatRect& rcBBox, + const CFX_Color& crText) { + std::ostringstream sAP; + sAP << "q\n" + << GetColorAppStream(crText, true) << GetAP_Star(rcBBox) << "f\nQ\n"; + return CFX_ByteString(sAP); +} + +CFX_ByteString GetCircleFillAppStream(const CFX_FloatRect& rect, + const CFX_Color& color) { + std::ostringstream sAppStream; + CFX_ByteString sColor = GetColorAppStream(color, true); + if (sColor.GetLength() > 0) + sAppStream << "q\n" << sColor << GetAP_Circle(rect) << "f\nQ\n"; + return CFX_ByteString(sAppStream); +} + +CFX_ByteString GetCircleBorderAppStream(const CFX_FloatRect& rect, + float fWidth, + const CFX_Color& color, + const CFX_Color& crLeftTop, + const CFX_Color& crRightBottom, + BorderStyle nStyle, + const CPWL_Dash& dash) { + std::ostringstream sAppStream; + CFX_ByteString sColor; + + if (fWidth > 0.0f) { + sAppStream << "q\n"; + + float fHalfWidth = fWidth / 2.0f; + CFX_FloatRect rect_by_2 = rect.GetDeflated(fHalfWidth, fHalfWidth); + + float div = fHalfWidth * 0.75f; + CFX_FloatRect rect_by_75 = rect.GetDeflated(div, div); + switch (nStyle) { + default: + case BorderStyle::SOLID: + case BorderStyle::UNDERLINE: { + sColor = GetColorAppStream(color, false); + if (sColor.GetLength() > 0) { + sAppStream << "q\n" + << fWidth << " w\n" + << sColor << GetAP_Circle(rect_by_2) << " S\nQ\n"; + } + } break; + case BorderStyle::DASH: { + sColor = GetColorAppStream(color, false); + if (sColor.GetLength() > 0) { + sAppStream << "q\n" + << fWidth << " w\n" + << "[" << dash.nDash << " " << dash.nGap << "] " + << dash.nPhase << " d\n" + << sColor << GetAP_Circle(rect_by_2) << " S\nQ\n"; + } + } break; + case BorderStyle::BEVELED: { + sColor = GetColorAppStream(color, false); + if (sColor.GetLength() > 0) { + sAppStream << "q\n" + << fHalfWidth << " w\n" + << sColor << GetAP_Circle(rect) << " S\nQ\n"; + } + + sColor = GetColorAppStream(crLeftTop, false); + if (sColor.GetLength() > 0) { + sAppStream << "q\n" + << fHalfWidth << " w\n" + << sColor << GetAP_HalfCircle(rect_by_75, FX_PI / 4.0f) + << " S\nQ\n"; + } + + sColor = GetColorAppStream(crRightBottom, false); + if (sColor.GetLength() > 0) { + sAppStream << "q\n" + << fHalfWidth << " w\n" + << sColor << GetAP_HalfCircle(rect_by_75, FX_PI * 5 / 4.0f) + << " S\nQ\n"; + } + } break; + case BorderStyle::INSET: { + sColor = GetColorAppStream(color, false); + if (sColor.GetLength() > 0) { + sAppStream << "q\n" + << fHalfWidth << " w\n" + << sColor << GetAP_Circle(rect) << " S\nQ\n"; + } + + sColor = GetColorAppStream(crLeftTop, false); + if (sColor.GetLength() > 0) { + sAppStream << "q\n" + << fHalfWidth << " w\n" + << sColor << GetAP_HalfCircle(rect_by_75, FX_PI / 4.0f) + << " S\nQ\n"; + } + + sColor = GetColorAppStream(crRightBottom, false); + if (sColor.GetLength() > 0) { + sAppStream << "q\n" + << fHalfWidth << " w\n" + << sColor << GetAP_HalfCircle(rect_by_75, FX_PI * 5 / 4.0f) + << " S\nQ\n"; + } + } break; + } + + sAppStream << "Q\n"; + } + return CFX_ByteString(sAppStream); +} + +CFX_ByteString GetCheckBoxAppStream(const CFX_FloatRect& rcBBox, + CheckStyle nStyle, + const CFX_Color& crText) { + CFX_FloatRect rcCenter = rcBBox.GetCenterSquare(); + switch (nStyle) { + default: + case CheckStyle::kCheck: + return GetAppStream_Check(rcCenter, crText); + case CheckStyle::kCircle: + rcCenter.Scale(2.0f / 3.0f); + return GetAppStream_Circle(rcCenter, crText); + case CheckStyle::kCross: + return GetAppStream_Cross(rcCenter, crText); + case CheckStyle::kDiamond: + rcCenter.Scale(2.0f / 3.0f); + return GetAppStream_Diamond(rcCenter, crText); + case CheckStyle::kSquare: + rcCenter.Scale(2.0f / 3.0f); + return GetAppStream_Square(rcCenter, crText); + case CheckStyle::kStar: + rcCenter.Scale(2.0f / 3.0f); + return GetAppStream_Star(rcCenter, crText); + } +} + +CFX_ByteString GetRadioButtonAppStream(const CFX_FloatRect& rcBBox, + CheckStyle nStyle, + const CFX_Color& crText) { + CFX_FloatRect rcCenter = rcBBox.GetCenterSquare(); + switch (nStyle) { + default: + case CheckStyle::kCheck: + return GetAppStream_Check(rcCenter, crText); + case CheckStyle::kCircle: + rcCenter.Scale(1.0f / 2.0f); + return GetAppStream_Circle(rcCenter, crText); + case CheckStyle::kCross: + return GetAppStream_Cross(rcCenter, crText); + case CheckStyle::kDiamond: + rcCenter.Scale(2.0f / 3.0f); + return GetAppStream_Diamond(rcCenter, crText); + case CheckStyle::kSquare: + rcCenter.Scale(2.0f / 3.0f); + return GetAppStream_Square(rcCenter, crText); + case CheckStyle::kStar: + rcCenter.Scale(2.0f / 3.0f); + return GetAppStream_Star(rcCenter, crText); + } +} + +CFX_ByteString GetFontSetString(IPVT_FontMap* pFontMap, + int32_t nFontIndex, + float fFontSize) { + if (!pFontMap) + return CFX_ByteString(); + + CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); + if (sFontAlias.GetLength() <= 0 || fFontSize <= 0) + return CFX_ByteString(); + + std::ostringstream sRet; + sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; + return CFX_ByteString(sRet); +} + +CFX_ByteString GetWordRenderString(const CFX_ByteString& strWords) { + if (strWords.GetLength() > 0) + return PDF_EncodeString(strWords, false) + " Tj\n"; + return CFX_ByteString(); +} + +CFX_ByteString GetEditAppStream(CFX_Edit* pEdit, + const CFX_PointF& ptOffset, + bool bContinuous, + uint16_t SubWord) { + CFX_Edit_Iterator* pIterator = pEdit->GetIterator(); + pIterator->SetAt(0); + + std::ostringstream sEditStream; + std::ostringstream sWords; + int32_t nCurFontIndex = -1; + CFX_PointF ptOld; + CFX_PointF ptNew; + CPVT_WordPlace oldplace; + + while (pIterator->NextWord()) { + CPVT_WordPlace place = pIterator->GetAt(); + if (bContinuous) { + if (place.LineCmp(oldplace) != 0) { + if (sWords.tellp() > 0) { + sEditStream << GetWordRenderString(CFX_ByteString(sWords)); + sWords.str(""); + } + + CPVT_Word word; + if (pIterator->GetWord(word)) { + ptNew = CFX_PointF(word.ptWord.x + ptOffset.x, + word.ptWord.y + ptOffset.y); + } else { + CPVT_Line line; + pIterator->GetLine(line); + ptNew = CFX_PointF(line.ptLine.x + ptOffset.x, + line.ptLine.y + ptOffset.y); + } + + if (ptNew.x != ptOld.x || ptNew.y != ptOld.y) { + sEditStream << ptNew.x - ptOld.x << " " << ptNew.y - ptOld.y + << " Td\n"; + + ptOld = ptNew; + } + } + + CPVT_Word word; + if (pIterator->GetWord(word)) { + if (word.nFontIndex != nCurFontIndex) { + if (sWords.tellp() > 0) { + sEditStream << GetWordRenderString(CFX_ByteString(sWords)); + sWords.str(""); + } + sEditStream << GetFontSetString(pEdit->GetFontMap(), word.nFontIndex, + word.fFontSize); + nCurFontIndex = word.nFontIndex; + } + + sWords << GetPDFWordString(pEdit->GetFontMap(), nCurFontIndex, + word.Word, SubWord); + } + + oldplace = place; + } else { + CPVT_Word word; + if (pIterator->GetWord(word)) { + ptNew = + CFX_PointF(word.ptWord.x + ptOffset.x, word.ptWord.y + ptOffset.y); + + if (ptNew.x != ptOld.x || ptNew.y != ptOld.y) { + sEditStream << ptNew.x - ptOld.x << " " << ptNew.y - ptOld.y + << " Td\n"; + ptOld = ptNew; + } + + if (word.nFontIndex != nCurFontIndex) { + sEditStream << GetFontSetString(pEdit->GetFontMap(), word.nFontIndex, + word.fFontSize); + nCurFontIndex = word.nFontIndex; + } + + sEditStream << GetWordRenderString(GetPDFWordString( + pEdit->GetFontMap(), nCurFontIndex, word.Word, SubWord)); + } + } + } + + if (sWords.tellp() > 0) { + sEditStream << GetWordRenderString(CFX_ByteString(sWords)); + sWords.str(""); + } + + std::ostringstream sAppStream; + if (sEditStream.tellp() > 0) { + int32_t nHorzScale = pEdit->GetHorzScale(); + if (nHorzScale != 100) { + sAppStream << nHorzScale << " Tz\n"; + } + + float fCharSpace = pEdit->GetCharSpace(); + if (!IsFloatZero(fCharSpace)) { + sAppStream << fCharSpace << " Tc\n"; + } + + sAppStream << sEditStream.str(); + } + + return CFX_ByteString(sAppStream); +} + +CFX_ByteString GenerateIconAppStream(CPDF_IconFit& fit, + CPDF_Stream* pIconStream, + const CFX_FloatRect& rcIcon) { + if (rcIcon.IsEmpty() || !pIconStream) + return CFX_ByteString(); + + CPWL_Icon icon; + PWL_CREATEPARAM cp; + cp.dwFlags = PWS_VISIBLE; + icon.Create(cp); + icon.SetIconFit(&fit); + icon.SetPDFStream(pIconStream); + icon.Move(rcIcon, false, false); + + CFX_ByteString sAlias = icon.GetImageAlias(); + if (sAlias.GetLength() <= 0) + return CFX_ByteString(); + + CFX_FloatRect rcPlate = icon.GetClientRect(); + CFX_Matrix mt = icon.GetImageMatrix().GetInverse(); + + float fHScale; + float fVScale; + std::tie(fHScale, fVScale) = icon.GetScale(); + + float fx; + float fy; + std::tie(fx, fy) = icon.GetImageOffset(); + + std::ostringstream str; + str << "q\n"; + str << rcPlate.left << " " << rcPlate.bottom << " " + << rcPlate.right - rcPlate.left << " " << rcPlate.top - rcPlate.bottom + << " re W n\n"; + + str << fHScale << " 0 0 " << fVScale << " " << rcPlate.left + fx << " " + << rcPlate.bottom + fy << " cm\n"; + str << mt.a << " " << mt.b << " " << mt.c << " " << mt.d << " " << mt.e << " " + << mt.f << " cm\n"; + + str << "0 g 0 G 1 w /" << sAlias << " Do\n" + << "Q\n"; + icon.Destroy(); + + return CFX_ByteString(str); +} + +CFX_ByteString GetPushButtonAppStream(const CFX_FloatRect& rcBBox, + IPVT_FontMap* pFontMap, + CPDF_Stream* pIconStream, + CPDF_IconFit& IconFit, + const CFX_WideString& sLabel, + const CFX_Color& crText, + float fFontSize, + ButtonStyle nLayOut) { + const float fAutoFontScale = 1.0f / 3.0f; + + auto pEdit = pdfium::MakeUnique<CFX_Edit>(); + pEdit->SetFontMap(pFontMap); + pEdit->SetAlignmentH(1, true); + pEdit->SetAlignmentV(1, true); + pEdit->SetMultiLine(false, true); + pEdit->SetAutoReturn(false, true); + if (IsFloatZero(fFontSize)) + pEdit->SetAutoFontSize(true, true); + else + pEdit->SetFontSize(fFontSize); + + pEdit->Initialize(); + pEdit->SetText(sLabel); + + CFX_FloatRect rcLabelContent = pEdit->GetContentRect(); + CFX_FloatRect rcLabel; + CFX_FloatRect rcIcon; + float fWidth = 0.0f; + float fHeight = 0.0f; + + switch (nLayOut) { + case ButtonStyle::kLabel: + rcLabel = rcBBox; + break; + case ButtonStyle::kIcon: + rcIcon = rcBBox; + break; + case ButtonStyle::kIconTopLabelBottom: + if (pIconStream) { + if (IsFloatZero(fFontSize)) { + fHeight = rcBBox.top - rcBBox.bottom; + rcLabel = CFX_FloatRect(rcBBox.left, rcBBox.bottom, rcBBox.right, + rcBBox.bottom + fHeight * fAutoFontScale); + rcIcon = + CFX_FloatRect(rcBBox.left, rcLabel.top, rcBBox.right, rcBBox.top); + } else { + fHeight = rcLabelContent.Height(); + + if (rcBBox.bottom + fHeight > rcBBox.top) { + rcLabel = rcBBox; + } else { + rcLabel = CFX_FloatRect(rcBBox.left, rcBBox.bottom, rcBBox.right, + rcBBox.bottom + fHeight); + rcIcon = CFX_FloatRect(rcBBox.left, rcLabel.top, rcBBox.right, + rcBBox.top); + } + } + } else { + rcLabel = rcBBox; + } + break; + case ButtonStyle::kIconBottomLabelTop: + if (pIconStream) { + if (IsFloatZero(fFontSize)) { + fHeight = rcBBox.top - rcBBox.bottom; + rcLabel = + CFX_FloatRect(rcBBox.left, rcBBox.top - fHeight * fAutoFontScale, + rcBBox.right, rcBBox.top); + rcIcon = CFX_FloatRect(rcBBox.left, rcBBox.bottom, rcBBox.right, + rcLabel.bottom); + } else { + fHeight = rcLabelContent.Height(); + + if (rcBBox.bottom + fHeight > rcBBox.top) { + rcLabel = rcBBox; + } else { + rcLabel = CFX_FloatRect(rcBBox.left, rcBBox.top - fHeight, + rcBBox.right, rcBBox.top); + rcIcon = CFX_FloatRect(rcBBox.left, rcBBox.bottom, rcBBox.right, + rcLabel.bottom); + } + } + } else { + rcLabel = rcBBox; + } + break; + case ButtonStyle::kIconLeftLabelRight: + if (pIconStream) { + if (IsFloatZero(fFontSize)) { + fWidth = rcBBox.right - rcBBox.left; + if (rcLabelContent.Width() < fWidth * fAutoFontScale) { + rcLabel = CFX_FloatRect(rcBBox.right - fWidth * fAutoFontScale, + rcBBox.bottom, rcBBox.right, rcBBox.top); + rcIcon = CFX_FloatRect(rcBBox.left, rcBBox.bottom, rcLabel.left, + rcBBox.top); + } else { + if (rcLabelContent.Width() < fWidth) { + rcLabel = CFX_FloatRect(rcBBox.right - rcLabelContent.Width(), + rcBBox.bottom, rcBBox.right, rcBBox.top); + rcIcon = CFX_FloatRect(rcBBox.left, rcBBox.bottom, rcLabel.left, + rcBBox.top); + } else { + rcLabel = rcBBox; + } + } + } else { + fWidth = rcLabelContent.Width(); + if (rcBBox.left + fWidth > rcBBox.right) { + rcLabel = rcBBox; + } else { + rcLabel = CFX_FloatRect(rcBBox.right - fWidth, rcBBox.bottom, + rcBBox.right, rcBBox.top); + rcIcon = CFX_FloatRect(rcBBox.left, rcBBox.bottom, rcLabel.left, + rcBBox.top); + } + } + } else { + rcLabel = rcBBox; + } + break; + case ButtonStyle::kIconRightLabelLeft: + if (pIconStream) { + if (IsFloatZero(fFontSize)) { + fWidth = rcBBox.right - rcBBox.left; + if (rcLabelContent.Width() < fWidth * fAutoFontScale) { + rcLabel = CFX_FloatRect(rcBBox.left, rcBBox.bottom, + rcBBox.left + fWidth * fAutoFontScale, + rcBBox.top); + rcIcon = CFX_FloatRect(rcLabel.right, rcBBox.bottom, rcBBox.right, + rcBBox.top); + } else { + if (rcLabelContent.Width() < fWidth) { + rcLabel = CFX_FloatRect(rcBBox.left, rcBBox.bottom, + rcBBox.left + rcLabelContent.Width(), + rcBBox.top); + rcIcon = CFX_FloatRect(rcLabel.right, rcBBox.bottom, rcBBox.right, + rcBBox.top); + } else { + rcLabel = rcBBox; + } + } + } else { + fWidth = rcLabelContent.Width(); + if (rcBBox.left + fWidth > rcBBox.right) { + rcLabel = rcBBox; + } else { + rcLabel = CFX_FloatRect(rcBBox.left, rcBBox.bottom, + rcBBox.left + fWidth, rcBBox.top); + rcIcon = CFX_FloatRect(rcLabel.right, rcBBox.bottom, rcBBox.right, + rcBBox.top); + } + } + } else { + rcLabel = rcBBox; + } + break; + case ButtonStyle::kLabelOverIcon: + rcLabel = rcBBox; + rcIcon = rcBBox; + break; + } + + std::ostringstream sTemp; + sTemp << GenerateIconAppStream(IconFit, pIconStream, rcIcon); + + if (!rcLabel.IsEmpty()) { + pEdit->SetPlateRect(rcLabel); + CFX_ByteString sEdit = + GetEditAppStream(pEdit.get(), CFX_PointF(0.0f, 0.0f), true, 0); + if (sEdit.GetLength() > 0) + sTemp << "BT\n" << GetColorAppStream(crText, true) << sEdit << "ET\n"; + } + + if (sTemp.tellp() <= 0) + return CFX_ByteString(); + + std::ostringstream sAppStream; + sAppStream << "q\n" + << rcBBox.left << " " << rcBBox.bottom << " " + << rcBBox.right - rcBBox.left << " " << rcBBox.top - rcBBox.bottom + << " re W n\n"; + sAppStream << sTemp.str().c_str() << "Q\n"; + return CFX_ByteString(sAppStream); +} + +CFX_ByteString GetBorderAppStreamInternal(const CFX_FloatRect& rect, + float fWidth, + const CFX_Color& color, + const CFX_Color& crLeftTop, + const CFX_Color& crRightBottom, + BorderStyle nStyle, + const CPWL_Dash& dash) { + std::ostringstream sAppStream; + CFX_ByteString sColor; + + float fLeft = rect.left; + float fRight = rect.right; + float fTop = rect.top; + float fBottom = rect.bottom; + + if (fWidth > 0.0f) { + float fHalfWidth = fWidth / 2.0f; + + sAppStream << "q\n"; + + switch (nStyle) { + default: + case BorderStyle::SOLID: + sColor = GetColorAppStream(color, true); + if (sColor.GetLength() > 0) { + sAppStream << sColor; + sAppStream << fLeft << " " << fBottom << " " << fRight - fLeft << " " + << fTop - fBottom << " re\n"; + sAppStream << fLeft + fWidth << " " << fBottom + fWidth << " " + << fRight - fLeft - fWidth * 2 << " " + << fTop - fBottom - fWidth * 2 << " re\n"; + sAppStream << "f*\n"; + } + break; + case BorderStyle::DASH: + sColor = GetColorAppStream(color, false); + if (sColor.GetLength() > 0) { + sAppStream << sColor; + sAppStream << fWidth << " w" + << " [" << dash.nDash << " " << dash.nGap << "] " + << dash.nPhase << " d\n"; + sAppStream << fLeft + fWidth / 2 << " " << fBottom + fWidth / 2 + << " m\n"; + sAppStream << fLeft + fWidth / 2 << " " << fTop - fWidth / 2 + << " l\n"; + sAppStream << fRight - fWidth / 2 << " " << fTop - fWidth / 2 + << " l\n"; + sAppStream << fRight - fWidth / 2 << " " << fBottom + fWidth / 2 + << " l\n"; + sAppStream << fLeft + fWidth / 2 << " " << fBottom + fWidth / 2 + << " l S\n"; + } + break; + case BorderStyle::BEVELED: + case BorderStyle::INSET: + sColor = GetColorAppStream(crLeftTop, true); + if (sColor.GetLength() > 0) { + sAppStream << sColor; + sAppStream << fLeft + fHalfWidth << " " << fBottom + fHalfWidth + << " m\n"; + sAppStream << fLeft + fHalfWidth << " " << fTop - fHalfWidth + << " l\n"; + sAppStream << fRight - fHalfWidth << " " << fTop - fHalfWidth + << " l\n"; + sAppStream << fRight - fHalfWidth * 2 << " " << fTop - fHalfWidth * 2 + << " l\n"; + sAppStream << fLeft + fHalfWidth * 2 << " " << fTop - fHalfWidth * 2 + << " l\n"; + sAppStream << fLeft + fHalfWidth * 2 << " " + << fBottom + fHalfWidth * 2 << " l f\n"; + } + + sColor = GetColorAppStream(crRightBottom, true); + if (sColor.GetLength() > 0) { + sAppStream << sColor; + sAppStream << fRight - fHalfWidth << " " << fTop - fHalfWidth + << " m\n"; + sAppStream << fRight - fHalfWidth << " " << fBottom + fHalfWidth + << " l\n"; + sAppStream << fLeft + fHalfWidth << " " << fBottom + fHalfWidth + << " l\n"; + sAppStream << fLeft + fHalfWidth * 2 << " " + << fBottom + fHalfWidth * 2 << " l\n"; + sAppStream << fRight - fHalfWidth * 2 << " " + << fBottom + fHalfWidth * 2 << " l\n"; + sAppStream << fRight - fHalfWidth * 2 << " " << fTop - fHalfWidth * 2 + << " l f\n"; + } + + sColor = GetColorAppStream(color, true); + if (sColor.GetLength() > 0) { + sAppStream << sColor; + sAppStream << fLeft << " " << fBottom << " " << fRight - fLeft << " " + << fTop - fBottom << " re\n"; + sAppStream << fLeft + fHalfWidth << " " << fBottom + fHalfWidth << " " + << fRight - fLeft - fHalfWidth * 2 << " " + << fTop - fBottom - fHalfWidth * 2 << " re f*\n"; + } + break; + case BorderStyle::UNDERLINE: + sColor = GetColorAppStream(color, false); + if (sColor.GetLength() > 0) { + sAppStream << sColor; + sAppStream << fWidth << " w\n"; + sAppStream << fLeft << " " << fBottom + fWidth / 2 << " m\n"; + sAppStream << fRight << " " << fBottom + fWidth / 2 << " l S\n"; + } + break; + } + + sAppStream << "Q\n"; + } + + return CFX_ByteString(sAppStream); +} + +CFX_ByteString GetDropButtonAppStream(const CFX_FloatRect& rcBBox) { + if (rcBBox.IsEmpty()) + return CFX_ByteString(); + + std::ostringstream sAppStream; + sAppStream << "q\n" + << GetColorAppStream(CFX_Color(COLORTYPE_RGB, 220.0f / 255.0f, + 220.0f / 255.0f, 220.0f / 255.0f), + true) + << rcBBox.left << " " << rcBBox.bottom << " " + << rcBBox.right - rcBBox.left << " " << rcBBox.top - rcBBox.bottom + << " re f\n" + << "Q\n"; + + sAppStream << "q\n" + << GetBorderAppStreamInternal( + rcBBox, 2, CFX_Color(COLORTYPE_GRAY, 0), + CFX_Color(COLORTYPE_GRAY, 1), + CFX_Color(COLORTYPE_GRAY, 0.5), BorderStyle::BEVELED, + CPWL_Dash(3, 0, 0)) + << "Q\n"; + + CFX_PointF ptCenter = CFX_PointF((rcBBox.left + rcBBox.right) / 2, + (rcBBox.top + rcBBox.bottom) / 2); + if (IsFloatBigger(rcBBox.right - rcBBox.left, 6) && + IsFloatBigger(rcBBox.top - rcBBox.bottom, 6)) { + sAppStream << "q\n" + << " 0 g\n" + << ptCenter.x - 3 << " " << ptCenter.y + 1.5f << " m\n" + << ptCenter.x + 3 << " " << ptCenter.y + 1.5f << " l\n" + << ptCenter.x << " " << ptCenter.y - 1.5f << " l\n" + << ptCenter.x - 3 << " " << ptCenter.y + 1.5f << " l f\n" + << "Q\n"; + } + + return CFX_ByteString(sAppStream); +} + +CFX_ByteString GetRectFillAppStream(const CFX_FloatRect& rect, + const CFX_Color& color) { + std::ostringstream sAppStream; + CFX_ByteString sColor = GetColorAppStream(color, true); + if (sColor.GetLength() > 0) { + sAppStream << "q\n" << sColor; + sAppStream << rect.left << " " << rect.bottom << " " + << rect.right - rect.left << " " << rect.top - rect.bottom + << " re f\nQ\n"; + } + + return CFX_ByteString(sAppStream); +} + +} // namespace + +CPWL_AppStream::CPWL_AppStream(CPDFSDK_Widget* widget, CPDF_Dictionary* dict) + : widget_(widget), dict_(dict) {} + +CPWL_AppStream::~CPWL_AppStream() {} + +void CPWL_AppStream::SetAsPushButton() { + CPDF_FormControl* pControl = widget_->GetFormControl(); + CFX_FloatRect rcWindow = widget_->GetRotatedRect(); + ButtonStyle nLayout = ButtonStyle::kLabel; + switch (pControl->GetTextPosition()) { + case TEXTPOS_ICON: + nLayout = ButtonStyle::kIcon; + break; + case TEXTPOS_BELOW: + nLayout = ButtonStyle::kIconTopLabelBottom; + break; + case TEXTPOS_ABOVE: + nLayout = ButtonStyle::kIconBottomLabelTop; + break; + case TEXTPOS_RIGHT: + nLayout = ButtonStyle::kIconLeftLabelRight; + break; + case TEXTPOS_LEFT: + nLayout = ButtonStyle::kIconRightLabelLeft; + break; + case TEXTPOS_OVERLAID: + nLayout = ButtonStyle::kLabelOverIcon; + break; + default: + nLayout = ButtonStyle::kLabel; + break; + } + + CFX_Color crBackground; + CFX_Color crBorder; + int iColorType; + float fc[4]; + pControl->GetOriginalBackgroundColor(iColorType, fc); + if (iColorType > 0) + crBackground = CFX_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); + + pControl->GetOriginalBorderColor(iColorType, fc); + if (iColorType > 0) + crBorder = CFX_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); + + float fBorderWidth = static_cast<float>(widget_->GetBorderWidth()); + CPWL_Dash dsBorder(3, 0, 0); + CFX_Color crLeftTop; + CFX_Color crRightBottom; + + BorderStyle nBorderStyle = widget_->GetBorderStyle(); + switch (nBorderStyle) { + case BorderStyle::DASH: + dsBorder = CPWL_Dash(3, 3, 0); + break; + case BorderStyle::BEVELED: + fBorderWidth *= 2; + crLeftTop = CFX_Color(COLORTYPE_GRAY, 1); + crRightBottom = crBackground / 2.0f; + break; + case BorderStyle::INSET: + fBorderWidth *= 2; + crLeftTop = CFX_Color(COLORTYPE_GRAY, 0.5); + crRightBottom = CFX_Color(COLORTYPE_GRAY, 0.75); + break; + default: + break; + } + + CFX_FloatRect rcClient = rcWindow.GetDeflated(fBorderWidth, fBorderWidth); + CFX_Color crText(COLORTYPE_GRAY, 0); + CFX_ByteString csNameTag; + CPDF_DefaultAppearance da = pControl->GetDefaultAppearance(); + if (da.HasColor()) { + da.GetColor(iColorType, fc); + crText = CFX_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); + } + float fFontSize = 12.0f; + if (da.HasFont()) + csNameTag = da.GetFont(&fFontSize); + + CFX_WideString csWCaption; + CFX_WideString csNormalCaption; + CFX_WideString csRolloverCaption; + CFX_WideString csDownCaption; + if (pControl->HasMKEntry("CA")) + csNormalCaption = pControl->GetNormalCaption(); + + if (pControl->HasMKEntry("RC")) + csRolloverCaption = pControl->GetRolloverCaption(); + + if (pControl->HasMKEntry("AC")) + csDownCaption = pControl->GetDownCaption(); + + CPDF_Stream* pNormalIcon = nullptr; + CPDF_Stream* pRolloverIcon = nullptr; + CPDF_Stream* pDownIcon = nullptr; + if (pControl->HasMKEntry("I")) + pNormalIcon = pControl->GetNormalIcon(); + + if (pControl->HasMKEntry("RI")) + pRolloverIcon = pControl->GetRolloverIcon(); + + if (pControl->HasMKEntry("IX")) + pDownIcon = pControl->GetDownIcon(); + + if (pNormalIcon) { + if (CPDF_Dictionary* pImageDict = pNormalIcon->GetDict()) { + if (pImageDict->GetStringFor("Name").IsEmpty()) + pImageDict->SetNewFor<CPDF_String>("Name", "ImgA", false); + } + } + + if (pRolloverIcon) { + if (CPDF_Dictionary* pImageDict = pRolloverIcon->GetDict()) { + if (pImageDict->GetStringFor("Name").IsEmpty()) + pImageDict->SetNewFor<CPDF_String>("Name", "ImgB", false); + } + } + + if (pDownIcon) { + if (CPDF_Dictionary* pImageDict = pDownIcon->GetDict()) { + if (pImageDict->GetStringFor("Name").IsEmpty()) + pImageDict->SetNewFor<CPDF_String>("Name", "ImgC", false); + } + } + + CPDF_IconFit iconFit = pControl->GetIconFit(); + + CBA_FontMap font_map( + widget_.Get(), + widget_->GetInterForm()->GetFormFillEnv()->GetSysHandler()); + font_map.SetAPType("N"); + + CFX_ByteString csAP = + GetRectFillAppStream(rcWindow, crBackground) + + GetBorderAppStreamInternal(rcWindow, fBorderWidth, crBorder, crLeftTop, + crRightBottom, nBorderStyle, dsBorder) + + GetPushButtonAppStream(iconFit.GetFittingBounds() ? rcWindow : rcClient, + &font_map, pNormalIcon, iconFit, csNormalCaption, + crText, fFontSize, nLayout); + + Write("N", csAP, ""); + if (pNormalIcon) + AddImage("N", pNormalIcon); + + CPDF_FormControl::HighlightingMode eHLM = pControl->GetHighlightingMode(); + if (eHLM == CPDF_FormControl::Push || eHLM == CPDF_FormControl::Toggle) { + if (csRolloverCaption.IsEmpty() && !pRolloverIcon) { + csRolloverCaption = csNormalCaption; + pRolloverIcon = pNormalIcon; + } + + font_map.SetAPType("R"); + + csAP = + GetRectFillAppStream(rcWindow, crBackground) + + GetBorderAppStreamInternal(rcWindow, fBorderWidth, crBorder, crLeftTop, + crRightBottom, nBorderStyle, dsBorder) + + GetPushButtonAppStream(iconFit.GetFittingBounds() ? rcWindow : rcClient, + &font_map, pRolloverIcon, iconFit, + csRolloverCaption, crText, fFontSize, nLayout); + + Write("R", csAP, ""); + if (pRolloverIcon) + AddImage("R", pRolloverIcon); + + if (csDownCaption.IsEmpty() && !pDownIcon) { + csDownCaption = csNormalCaption; + pDownIcon = pNormalIcon; + } + + switch (nBorderStyle) { + case BorderStyle::BEVELED: { + CFX_Color crTemp = crLeftTop; + crLeftTop = crRightBottom; + crRightBottom = crTemp; + break; + } + case BorderStyle::INSET: { + crLeftTop = CFX_Color(COLORTYPE_GRAY, 0); + crRightBottom = CFX_Color(COLORTYPE_GRAY, 1); + break; + } + default: + break; + } + + font_map.SetAPType("D"); + + csAP = + GetRectFillAppStream(rcWindow, crBackground - 0.25f) + + GetBorderAppStreamInternal(rcWindow, fBorderWidth, crBorder, crLeftTop, + crRightBottom, nBorderStyle, dsBorder) + + GetPushButtonAppStream(iconFit.GetFittingBounds() ? rcWindow : rcClient, + &font_map, pDownIcon, iconFit, csDownCaption, + crText, fFontSize, nLayout); + + Write("D", csAP, ""); + if (pDownIcon) + AddImage("D", pDownIcon); + } else { + Remove("D"); + Remove("R"); + } +} + +void CPWL_AppStream::SetAsCheckBox() { + CPDF_FormControl* pControl = widget_->GetFormControl(); + CFX_Color crBackground, crBorder, crText; + int iColorType; + float fc[4]; + + pControl->GetOriginalBackgroundColor(iColorType, fc); + if (iColorType > 0) + crBackground = CFX_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); + + pControl->GetOriginalBorderColor(iColorType, fc); + if (iColorType > 0) + crBorder = CFX_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); + + float fBorderWidth = static_cast<float>(widget_->GetBorderWidth()); + CPWL_Dash dsBorder(3, 0, 0); + CFX_Color crLeftTop, crRightBottom; + + BorderStyle nBorderStyle = widget_->GetBorderStyle(); + switch (nBorderStyle) { + case BorderStyle::DASH: + dsBorder = CPWL_Dash(3, 3, 0); + break; + case BorderStyle::BEVELED: + fBorderWidth *= 2; + crLeftTop = CFX_Color(COLORTYPE_GRAY, 1); + crRightBottom = crBackground / 2.0f; + break; + case BorderStyle::INSET: + fBorderWidth *= 2; + crLeftTop = CFX_Color(COLORTYPE_GRAY, 0.5); + crRightBottom = CFX_Color(COLORTYPE_GRAY, 0.75); + break; + default: + break; + } + + CFX_FloatRect rcWindow = widget_->GetRotatedRect(); + CFX_FloatRect rcClient = rcWindow.GetDeflated(fBorderWidth, fBorderWidth); + CPDF_DefaultAppearance da = pControl->GetDefaultAppearance(); + if (da.HasColor()) { + da.GetColor(iColorType, fc); + crText = CFX_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); + } + + CheckStyle nStyle = CheckStyle::kCheck; + CFX_WideString csWCaption = pControl->GetNormalCaption(); + if (csWCaption.GetLength() > 0) { + switch (csWCaption[0]) { + case L'l': + nStyle = CheckStyle::kCircle; + break; + case L'8': + nStyle = CheckStyle::kCross; + break; + case L'u': + nStyle = CheckStyle::kDiamond; + break; + case L'n': + nStyle = CheckStyle::kSquare; + break; + case L'H': + nStyle = CheckStyle::kStar; + break; + case L'4': + default: + nStyle = CheckStyle::kCheck; + } + } + + CFX_ByteString csAP_N_ON = + GetRectFillAppStream(rcWindow, crBackground) + + GetBorderAppStreamInternal(rcWindow, fBorderWidth, crBorder, crLeftTop, + crRightBottom, nBorderStyle, dsBorder); + + CFX_ByteString csAP_N_OFF = csAP_N_ON; + + switch (nBorderStyle) { + case BorderStyle::BEVELED: { + CFX_Color crTemp = crLeftTop; + crLeftTop = crRightBottom; + crRightBottom = crTemp; + break; + } + case BorderStyle::INSET: { + crLeftTop = CFX_Color(COLORTYPE_GRAY, 0); + crRightBottom = CFX_Color(COLORTYPE_GRAY, 1); + break; + } + default: + break; + } + + CFX_ByteString csAP_D_ON = + GetRectFillAppStream(rcWindow, crBackground - 0.25f) + + GetBorderAppStreamInternal(rcWindow, fBorderWidth, crBorder, crLeftTop, + crRightBottom, nBorderStyle, dsBorder); + + CFX_ByteString csAP_D_OFF = csAP_D_ON; + + csAP_N_ON += GetCheckBoxAppStream(rcClient, nStyle, crText); + csAP_D_ON += GetCheckBoxAppStream(rcClient, nStyle, crText); + + Write("N", csAP_N_ON, pControl->GetCheckedAPState()); + Write("N", csAP_N_OFF, "Off"); + + Write("D", csAP_D_ON, pControl->GetCheckedAPState()); + Write("D", csAP_D_OFF, "Off"); + + CFX_ByteString csAS = widget_->GetAppState(); + if (csAS.IsEmpty()) + widget_->SetAppState("Off"); +} + +void CPWL_AppStream::SetAsRadioButton() { + CPDF_FormControl* pControl = widget_->GetFormControl(); + CFX_Color crBackground; + CFX_Color crBorder; + CFX_Color crText; + int iColorType; + float fc[4]; + + pControl->GetOriginalBackgroundColor(iColorType, fc); + if (iColorType > 0) + crBackground = CFX_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); + + pControl->GetOriginalBorderColor(iColorType, fc); + if (iColorType > 0) + crBorder = CFX_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); + + float fBorderWidth = static_cast<float>(widget_->GetBorderWidth()); + CPWL_Dash dsBorder(3, 0, 0); + CFX_Color crLeftTop; + CFX_Color crRightBottom; + BorderStyle nBorderStyle = widget_->GetBorderStyle(); + switch (nBorderStyle) { + case BorderStyle::DASH: + dsBorder = CPWL_Dash(3, 3, 0); + break; + case BorderStyle::BEVELED: + fBorderWidth *= 2; + crLeftTop = CFX_Color(COLORTYPE_GRAY, 1); + crRightBottom = crBackground / 2.0f; + break; + case BorderStyle::INSET: + fBorderWidth *= 2; + crLeftTop = CFX_Color(COLORTYPE_GRAY, 0.5); + crRightBottom = CFX_Color(COLORTYPE_GRAY, 0.75); + break; + default: + break; + } + + CFX_FloatRect rcWindow = widget_->GetRotatedRect(); + CFX_FloatRect rcClient = rcWindow.GetDeflated(fBorderWidth, fBorderWidth); + CPDF_DefaultAppearance da = pControl->GetDefaultAppearance(); + if (da.HasColor()) { + da.GetColor(iColorType, fc); + crText = CFX_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); + } + + CheckStyle nStyle = CheckStyle::kCircle; + CFX_WideString csWCaption = pControl->GetNormalCaption(); + if (csWCaption.GetLength() > 0) { + switch (csWCaption[0]) { + case L'8': + nStyle = CheckStyle::kCross; + break; + case L'u': + nStyle = CheckStyle::kDiamond; + break; + case L'n': + nStyle = CheckStyle::kSquare; + break; + case L'H': + nStyle = CheckStyle::kStar; + break; + case L'4': + nStyle = CheckStyle::kCheck; + break; + case L'l': + default: + nStyle = CheckStyle::kCircle; + } + } + + CFX_ByteString csAP_N_ON; + CFX_FloatRect rcCenter = rcWindow.GetCenterSquare().GetDeflated(1.0f, 1.0f); + if (nStyle == CheckStyle::kCircle) { + if (nBorderStyle == BorderStyle::BEVELED) { + crLeftTop = CFX_Color(COLORTYPE_GRAY, 1); + crRightBottom = crBackground - 0.25f; + } else if (nBorderStyle == BorderStyle::INSET) { + crLeftTop = CFX_Color(COLORTYPE_GRAY, 0.5f); + crRightBottom = CFX_Color(COLORTYPE_GRAY, 0.75f); + } + + csAP_N_ON = + GetCircleFillAppStream(rcCenter, crBackground) + + GetCircleBorderAppStream(rcCenter, fBorderWidth, crBorder, crLeftTop, + crRightBottom, nBorderStyle, dsBorder); + } else { + csAP_N_ON = + GetRectFillAppStream(rcWindow, crBackground) + + GetBorderAppStreamInternal(rcWindow, fBorderWidth, crBorder, crLeftTop, + crRightBottom, nBorderStyle, dsBorder); + } + + CFX_ByteString csAP_N_OFF = csAP_N_ON; + + switch (nBorderStyle) { + case BorderStyle::BEVELED: { + CFX_Color crTemp = crLeftTop; + crLeftTop = crRightBottom; + crRightBottom = crTemp; + break; + } + case BorderStyle::INSET: { + crLeftTop = CFX_Color(COLORTYPE_GRAY, 0); + crRightBottom = CFX_Color(COLORTYPE_GRAY, 1); + break; + } + default: + break; + } + + CFX_ByteString csAP_D_ON; + + if (nStyle == CheckStyle::kCircle) { + CFX_Color crBK = crBackground - 0.25f; + if (nBorderStyle == BorderStyle::BEVELED) { + crLeftTop = crBackground - 0.25f; + crRightBottom = CFX_Color(COLORTYPE_GRAY, 1); + crBK = crBackground; + } else if (nBorderStyle == BorderStyle::INSET) { + crLeftTop = CFX_Color(COLORTYPE_GRAY, 0); + crRightBottom = CFX_Color(COLORTYPE_GRAY, 1); + } + + csAP_D_ON = + GetCircleFillAppStream(rcCenter, crBK) + + GetCircleBorderAppStream(rcCenter, fBorderWidth, crBorder, crLeftTop, + crRightBottom, nBorderStyle, dsBorder); + } else { + csAP_D_ON = + GetRectFillAppStream(rcWindow, crBackground - 0.25f) + + GetBorderAppStreamInternal(rcWindow, fBorderWidth, crBorder, crLeftTop, + crRightBottom, nBorderStyle, dsBorder); + } + + CFX_ByteString csAP_D_OFF = csAP_D_ON; + + csAP_N_ON += GetRadioButtonAppStream(rcClient, nStyle, crText); + csAP_D_ON += GetRadioButtonAppStream(rcClient, nStyle, crText); + + Write("N", csAP_N_ON, pControl->GetCheckedAPState()); + Write("N", csAP_N_OFF, "Off"); + + Write("D", csAP_D_ON, pControl->GetCheckedAPState()); + Write("D", csAP_D_OFF, "Off"); + + CFX_ByteString csAS = widget_->GetAppState(); + if (csAS.IsEmpty()) + widget_->SetAppState("Off"); +} + +void CPWL_AppStream::SetAsComboBox(const CFX_WideString* sValue) { + CPDF_FormControl* pControl = widget_->GetFormControl(); + CPDF_FormField* pField = pControl->GetField(); + std::ostringstream sBody; + + CFX_FloatRect rcClient = widget_->GetClientRect(); + CFX_FloatRect rcButton = rcClient; + rcButton.left = rcButton.right - 13; + rcButton.Normalize(); + + auto pEdit = pdfium::MakeUnique<CFX_Edit>(); + pEdit->EnableRefresh(false); + + CBA_FontMap font_map( + widget_.Get(), + widget_->GetInterForm()->GetFormFillEnv()->GetSysHandler()); + pEdit->SetFontMap(&font_map); + + CFX_FloatRect rcEdit = rcClient; + rcEdit.right = rcButton.left; + rcEdit.Normalize(); + + pEdit->SetPlateRect(rcEdit); + pEdit->SetAlignmentV(1, true); + + float fFontSize = widget_->GetFontSize(); + if (IsFloatZero(fFontSize)) + pEdit->SetAutoFontSize(true, true); + else + pEdit->SetFontSize(fFontSize); + + pEdit->Initialize(); + + if (sValue) { + pEdit->SetText(*sValue); + } else { + int32_t nCurSel = pField->GetSelectedIndex(0); + if (nCurSel < 0) + pEdit->SetText(pField->GetValue()); + else + pEdit->SetText(pField->GetOptionLabel(nCurSel)); + } + + CFX_FloatRect rcContent = pEdit->GetContentRect(); + CFX_ByteString sEdit = GetEditAppStream(pEdit.get(), CFX_PointF(), true, 0); + if (sEdit.GetLength() > 0) { + sBody << "/Tx BMC\n" + << "q\n"; + if (rcContent.Width() > rcEdit.Width() || + rcContent.Height() > rcEdit.Height()) { + sBody << rcEdit.left << " " << rcEdit.bottom << " " << rcEdit.Width() + << " " << rcEdit.Height() << " re\nW\nn\n"; + } + + CFX_Color crText = widget_->GetTextPWLColor(); + sBody << "BT\n" + << GetColorAppStream(crText, true) << sEdit << "ET\n" + << "Q\nEMC\n"; + } + + sBody << GetDropButtonAppStream(rcButton); + Write("N", + GetBackgroundAppStream() + GetBorderAppStream() + CFX_ByteString(sBody), + ""); +} + +void CPWL_AppStream::SetAsListBox() { + CPDF_FormControl* pControl = widget_->GetFormControl(); + CPDF_FormField* pField = pControl->GetField(); + CFX_FloatRect rcClient = widget_->GetClientRect(); + std::ostringstream sBody; + + auto pEdit = pdfium::MakeUnique<CFX_Edit>(); + pEdit->EnableRefresh(false); + + CBA_FontMap font_map( + widget_.Get(), + widget_->GetInterForm()->GetFormFillEnv()->GetSysHandler()); + pEdit->SetFontMap(&font_map); + pEdit->SetPlateRect(CFX_FloatRect(rcClient.left, 0.0f, rcClient.right, 0.0f)); + + float fFontSize = widget_->GetFontSize(); + pEdit->SetFontSize(IsFloatZero(fFontSize) ? 12.0f : fFontSize); + pEdit->Initialize(); + + std::ostringstream sList; + float fy = rcClient.top; + + int32_t nTop = pField->GetTopVisibleIndex(); + int32_t nCount = pField->CountOptions(); + int32_t nSelCount = pField->CountSelectedItems(); + + for (int32_t i = nTop; i < nCount; ++i) { + bool bSelected = false; + for (int32_t j = 0; j < nSelCount; ++j) { + if (pField->GetSelectedIndex(j) == i) { + bSelected = true; + break; + } + } + + pEdit->SetText(pField->GetOptionLabel(i)); + + CFX_FloatRect rcContent = pEdit->GetContentRect(); + float fItemHeight = rcContent.Height(); + + if (bSelected) { + CFX_FloatRect rcItem = + CFX_FloatRect(rcClient.left, fy - fItemHeight, rcClient.right, fy); + sList << "q\n" + << GetColorAppStream( + CFX_Color(COLORTYPE_RGB, 0, 51.0f / 255.0f, 113.0f / 255.0f), + true) + << rcItem.left << " " << rcItem.bottom << " " << rcItem.Width() + << " " << rcItem.Height() << " re f\n" + << "Q\n"; + + sList << "BT\n" + << GetColorAppStream(CFX_Color(COLORTYPE_GRAY, 1), true) + << GetEditAppStream(pEdit.get(), CFX_PointF(0.0f, fy), true, 0) + << "ET\n"; + } else { + CFX_Color crText = widget_->GetTextPWLColor(); + sList << "BT\n" + << GetColorAppStream(crText, true) + << GetEditAppStream(pEdit.get(), CFX_PointF(0.0f, fy), true, 0) + << "ET\n"; + } + + fy -= fItemHeight; + } + + if (sList.tellp() > 0) { + sBody << "/Tx BMC\n" + << "q\n" + << rcClient.left << " " << rcClient.bottom << " " << rcClient.Width() + << " " << rcClient.Height() << " re\nW\nn\n"; + sBody << sList.str() << "Q\nEMC\n"; + } + Write("N", + GetBackgroundAppStream() + GetBorderAppStream() + CFX_ByteString(sBody), + ""); +} + +void CPWL_AppStream::SetAsTextField(const CFX_WideString* sValue) { + CPDF_FormControl* pControl = widget_->GetFormControl(); + CPDF_FormField* pField = pControl->GetField(); + std::ostringstream sBody; + std::ostringstream sLines; + + auto pEdit = pdfium::MakeUnique<CFX_Edit>(); + pEdit->EnableRefresh(false); + + CBA_FontMap font_map( + widget_.Get(), + widget_->GetInterForm()->GetFormFillEnv()->GetSysHandler()); + pEdit->SetFontMap(&font_map); + + CFX_FloatRect rcClient = widget_->GetClientRect(); + pEdit->SetPlateRect(rcClient); + pEdit->SetAlignmentH(pControl->GetControlAlignment(), true); + + uint32_t dwFieldFlags = pField->GetFieldFlags(); + bool bMultiLine = (dwFieldFlags >> 12) & 1; + if (bMultiLine) { + pEdit->SetMultiLine(true, true); + pEdit->SetAutoReturn(true, true); + } else { + pEdit->SetAlignmentV(1, true); + } + + uint16_t subWord = 0; + if ((dwFieldFlags >> 13) & 1) { + subWord = '*'; + pEdit->SetPasswordChar(subWord, true); + } + + int nMaxLen = pField->GetMaxLen(); + bool bCharArray = (dwFieldFlags >> 24) & 1; + float fFontSize = widget_->GetFontSize(); + +#ifdef PDF_ENABLE_XFA + CFX_WideString sValueTmp; + if (!sValue && widget_->GetMixXFAWidget()) { + sValueTmp = widget_->GetValue(true); + sValue = &sValueTmp; + } +#endif // PDF_ENABLE_XFA + + if (nMaxLen > 0) { + if (bCharArray) { + pEdit->SetCharArray(nMaxLen); + + if (IsFloatZero(fFontSize)) { + fFontSize = CPWL_Edit::GetCharArrayAutoFontSize(font_map.GetPDFFont(0), + rcClient, nMaxLen); + } + } else { + if (sValue) + nMaxLen = sValue->GetLength(); + pEdit->SetLimitChar(nMaxLen); + } + } + + if (IsFloatZero(fFontSize)) + pEdit->SetAutoFontSize(true, true); + else + pEdit->SetFontSize(fFontSize); + + pEdit->Initialize(); + pEdit->SetText(sValue ? *sValue : pField->GetValue()); + + CFX_FloatRect rcContent = pEdit->GetContentRect(); + CFX_ByteString sEdit = + GetEditAppStream(pEdit.get(), CFX_PointF(), !bCharArray, subWord); + + if (sEdit.GetLength() > 0) { + sBody << "/Tx BMC\n" + << "q\n"; + if (rcContent.Width() > rcClient.Width() || + rcContent.Height() > rcClient.Height()) { + sBody << rcClient.left << " " << rcClient.bottom << " " + << rcClient.Width() << " " << rcClient.Height() << " re\nW\nn\n"; + } + CFX_Color crText = widget_->GetTextPWLColor(); + sBody << "BT\n" + << GetColorAppStream(crText, true) << sEdit << "ET\n" + << "Q\nEMC\n"; + } + + if (bCharArray) { + switch (widget_->GetBorderStyle()) { + case BorderStyle::SOLID: { + CFX_ByteString sColor = + GetColorAppStream(widget_->GetBorderPWLColor(), false); + if (sColor.GetLength() > 0) { + sLines << "q\n" + << widget_->GetBorderWidth() << " w\n" + << GetColorAppStream(widget_->GetBorderPWLColor(), false) + << " 2 J 0 j\n"; + + for (int32_t i = 1; i < nMaxLen; ++i) { + sLines << rcClient.left + + ((rcClient.right - rcClient.left) / nMaxLen) * i + << " " << rcClient.bottom << " m\n" + << rcClient.left + + ((rcClient.right - rcClient.left) / nMaxLen) * i + << " " << rcClient.top << " l S\n"; + } + + sLines << "Q\n"; + } + break; + } + case BorderStyle::DASH: { + CFX_ByteString sColor = + GetColorAppStream(widget_->GetBorderPWLColor(), false); + if (sColor.GetLength() > 0) { + CPWL_Dash dsBorder = CPWL_Dash(3, 3, 0); + + sLines << "q\n" + << widget_->GetBorderWidth() << " w\n" + << GetColorAppStream(widget_->GetBorderPWLColor(), false) + << "[" << dsBorder.nDash << " " << dsBorder.nGap << "] " + << dsBorder.nPhase << " d\n"; + + for (int32_t i = 1; i < nMaxLen; ++i) { + sLines << rcClient.left + + ((rcClient.right - rcClient.left) / nMaxLen) * i + << " " << rcClient.bottom << " m\n" + << rcClient.left + + ((rcClient.right - rcClient.left) / nMaxLen) * i + << " " << rcClient.top << " l S\n"; + } + + sLines << "Q\n"; + } + break; + } + default: + break; + } + } + + Write("N", + GetBackgroundAppStream() + GetBorderAppStream() + + CFX_ByteString(sLines) + CFX_ByteString(sBody), + ""); +} + +void CPWL_AppStream::AddImage(const CFX_ByteString& sAPType, + CPDF_Stream* pImage) { + CPDF_Stream* pStream = dict_->GetStreamFor(sAPType); + CPDF_Dictionary* pStreamDict = pStream->GetDict(); + CFX_ByteString sImageAlias = "IMG"; + + if (CPDF_Dictionary* pImageDict = pImage->GetDict()) { + sImageAlias = pImageDict->GetStringFor("Name"); + if (sImageAlias.IsEmpty()) + sImageAlias = "IMG"; + } + + CPDF_Dictionary* pStreamResList = pStreamDict->GetDictFor("Resources"); + if (!pStreamResList) + pStreamResList = pStreamDict->SetNewFor<CPDF_Dictionary>("Resources"); + + CPDF_Dictionary* pXObject = + pStreamResList->SetNewFor<CPDF_Dictionary>("XObject"); + pXObject->SetNewFor<CPDF_Reference>(sImageAlias, + widget_->GetPageView()->GetPDFDocument(), + pImage->GetObjNum()); +} + +void CPWL_AppStream::Write(const CFX_ByteString& sAPType, + const CFX_ByteString& sContents, + const CFX_ByteString& sAPState) { + CPDF_Stream* pStream = nullptr; + CPDF_Dictionary* pParentDict = nullptr; + if (sAPState.IsEmpty()) { + pParentDict = dict_.Get(); + pStream = dict_->GetStreamFor(sAPType); + } else { + CPDF_Dictionary* pAPTypeDict = dict_->GetDictFor(sAPType); + if (!pAPTypeDict) + pAPTypeDict = dict_->SetNewFor<CPDF_Dictionary>(sAPType); + + pParentDict = pAPTypeDict; + pStream = pAPTypeDict->GetStreamFor(sAPState); + } + + if (!pStream) { + CPDF_Document* doc = widget_->GetPageView()->GetPDFDocument(); + pStream = doc->NewIndirect<CPDF_Stream>(); + pParentDict->SetNewFor<CPDF_Reference>(sAPType, doc, pStream->GetObjNum()); + } + + CPDF_Dictionary* pStreamDict = pStream->GetDict(); + if (!pStreamDict) { + auto pNewDict = pdfium::MakeUnique<CPDF_Dictionary>( + widget_->GetPDFAnnot()->GetDocument()->GetByteStringPool()); + pStreamDict = pNewDict.get(); + pStreamDict->SetNewFor<CPDF_Name>("Type", "XObject"); + pStreamDict->SetNewFor<CPDF_Name>("Subtype", "Form"); + pStreamDict->SetNewFor<CPDF_Number>("FormType", 1); + pStream->InitStream(nullptr, 0, std::move(pNewDict)); + } + pStreamDict->SetMatrixFor("Matrix", widget_->GetMatrix()); + pStreamDict->SetRectFor("BBox", widget_->GetRotatedRect()); + pStream->SetData((uint8_t*)(sContents.c_str()), sContents.GetLength()); +} + +void CPWL_AppStream::Remove(const CFX_ByteString& sAPType) { + dict_->RemoveFor(sAPType); +} + +CFX_ByteString CPWL_AppStream::GetBackgroundAppStream() const { + CFX_Color crBackground = widget_->GetFillPWLColor(); + if (crBackground.nColorType != COLORTYPE_TRANSPARENT) + return GetRectFillAppStream(widget_->GetRotatedRect(), crBackground); + + return CFX_ByteString(); +} + +CFX_ByteString CPWL_AppStream::GetBorderAppStream() const { + CFX_FloatRect rcWindow = widget_->GetRotatedRect(); + CFX_Color crBorder = widget_->GetBorderPWLColor(); + CFX_Color crBackground = widget_->GetFillPWLColor(); + CFX_Color crLeftTop; + CFX_Color crRightBottom; + + float fBorderWidth = static_cast<float>(widget_->GetBorderWidth()); + CPWL_Dash dsBorder(3, 0, 0); + + BorderStyle nBorderStyle = widget_->GetBorderStyle(); + switch (nBorderStyle) { + case BorderStyle::DASH: + dsBorder = CPWL_Dash(3, 3, 0); + break; + case BorderStyle::BEVELED: + fBorderWidth *= 2; + crLeftTop = CFX_Color(COLORTYPE_GRAY, 1); + crRightBottom = crBackground / 2.0f; + break; + case BorderStyle::INSET: + fBorderWidth *= 2; + crLeftTop = CFX_Color(COLORTYPE_GRAY, 0.5); + crRightBottom = CFX_Color(COLORTYPE_GRAY, 0.75); + break; + default: + break; + } + + return GetBorderAppStreamInternal(rcWindow, fBorderWidth, crBorder, crLeftTop, + crRightBottom, nBorderStyle, dsBorder); +} diff --git a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_appstream.h b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_appstream.h new file mode 100644 index 00000000000..56137864ecd --- /dev/null +++ b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_appstream.h @@ -0,0 +1,43 @@ +// Copyright 2017 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 + +#ifndef FPDFSDK_PDFWINDOW_CPWL_APPSTREAM_H_ +#define FPDFSDK_PDFWINDOW_CPWL_APPSTREAM_H_ + +#include "core/fxcrt/cfx_unowned_ptr.h" +#include "core/fxcrt/fx_string.h" + +class CPDFSDK_Widget; +class CPDF_Dictionary; +class CPDF_Stream; + +class CPWL_AppStream { + public: + CPWL_AppStream(CPDFSDK_Widget* widget, CPDF_Dictionary* dict); + ~CPWL_AppStream(); + + void SetAsPushButton(); + void SetAsCheckBox(); + void SetAsRadioButton(); + void SetAsComboBox(const CFX_WideString* sValue); + void SetAsListBox(); + void SetAsTextField(const CFX_WideString* sValue); + + private: + void AddImage(const CFX_ByteString& sAPType, CPDF_Stream* pImage); + void Write(const CFX_ByteString& sAPType, + const CFX_ByteString& sContents, + const CFX_ByteString& sAPState); + void Remove(const CFX_ByteString& sAPType); + + CFX_ByteString GetBackgroundAppStream() const; + CFX_ByteString GetBorderAppStream() const; + + CFX_UnownedPtr<CPDFSDK_Widget> widget_; + CFX_UnownedPtr<CPDF_Dictionary> dict_; +}; + +#endif // FPDFSDK_PDFWINDOW_CPWL_APPSTREAM_H_ diff --git a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/PWL_Button.cpp b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_button.cpp index 96be4694548..fad36328757 100644 --- a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/PWL_Button.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_button.cpp @@ -4,9 +4,8 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "fpdfsdk/pdfwindow/PWL_Button.h" -#include "fpdfsdk/pdfwindow/PWL_Utils.h" -#include "fpdfsdk/pdfwindow/PWL_Wnd.h" +#include "fpdfsdk/pdfwindow/cpwl_button.h" +#include "fpdfsdk/pdfwindow/cpwl_wnd.h" CPWL_Button::CPWL_Button() : m_bMouseDown(false) {} diff --git a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/PWL_Button.h b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_button.h index 2d1193f89d5..9f4a47733ec 100644 --- a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/PWL_Button.h +++ b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_button.h @@ -4,10 +4,10 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef FPDFSDK_PDFWINDOW_PWL_BUTTON_H_ -#define FPDFSDK_PDFWINDOW_PWL_BUTTON_H_ +#ifndef FPDFSDK_PDFWINDOW_CPWL_BUTTON_H_ +#define FPDFSDK_PDFWINDOW_CPWL_BUTTON_H_ -#include "fpdfsdk/pdfwindow/PWL_Wnd.h" +#include "fpdfsdk/pdfwindow/cpwl_wnd.h" class CPWL_Button : public CPWL_Wnd { public: @@ -24,4 +24,4 @@ class CPWL_Button : public CPWL_Wnd { bool m_bMouseDown; }; -#endif // FPDFSDK_PDFWINDOW_PWL_BUTTON_H_ +#endif // FPDFSDK_PDFWINDOW_CPWL_BUTTON_H_ diff --git a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_caret.cpp b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_caret.cpp new file mode 100644 index 00000000000..a9a5b860997 --- /dev/null +++ b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_caret.cpp @@ -0,0 +1,114 @@ +// Copyright 2014 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 "fpdfsdk/pdfwindow/cpwl_caret.h" + +#include <sstream> + +#include "core/fxge/cfx_graphstatedata.h" +#include "core/fxge/cfx_pathdata.h" +#include "core/fxge/cfx_renderdevice.h" +#include "fpdfsdk/pdfwindow/cpwl_wnd.h" + +#define PWL_CARET_FLASHINTERVAL 500 + +CPWL_Caret::CPWL_Caret() : m_bFlash(false), m_fWidth(0.4f), m_nDelay(0) {} + +CPWL_Caret::~CPWL_Caret() {} + +CFX_ByteString CPWL_Caret::GetClassName() const { + return "CPWL_Caret"; +} + +void CPWL_Caret::DrawThisAppearance(CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device) { + if (!IsVisible() || !m_bFlash) + return; + + CFX_FloatRect rcRect = GetCaretRect(); + CFX_FloatRect rcClip = GetClipRect(); + CFX_PathData path; + + float fCaretX = rcRect.left + m_fWidth * 0.5f; + float fCaretTop = rcRect.top; + float fCaretBottom = rcRect.bottom; + if (!rcClip.IsEmpty()) { + rcRect.Intersect(rcClip); + if (rcRect.IsEmpty()) + return; + + fCaretTop = rcRect.top; + fCaretBottom = rcRect.bottom; + } + + path.AppendPoint(CFX_PointF(fCaretX, fCaretBottom), FXPT_TYPE::MoveTo, false); + path.AppendPoint(CFX_PointF(fCaretX, fCaretTop), FXPT_TYPE::LineTo, false); + + CFX_GraphStateData gsd; + gsd.m_LineWidth = m_fWidth; + pDevice->DrawPath(&path, pUser2Device, &gsd, 0, ArgbEncode(255, 0, 0, 0), + FXFILL_ALTERNATE); +} + +void CPWL_Caret::TimerProc() { + if (m_nDelay > 0) { + m_nDelay--; + } else { + m_bFlash = !m_bFlash; + InvalidateRect(); + } +} + +CFX_FloatRect CPWL_Caret::GetCaretRect() const { + return CFX_FloatRect(m_ptFoot.x, m_ptFoot.y, m_ptHead.x + m_fWidth, + m_ptHead.y); +} + +void CPWL_Caret::SetCaret(bool bVisible, + const CFX_PointF& ptHead, + const CFX_PointF& ptFoot) { + if (bVisible) { + if (IsVisible()) { + if (m_ptHead != ptHead || m_ptFoot != ptFoot) { + m_ptHead = ptHead; + m_ptFoot = ptFoot; + m_bFlash = true; + Move(m_rcInvalid, false, true); + } + } else { + m_ptHead = ptHead; + m_ptFoot = ptFoot; + EndTimer(); + BeginTimer(PWL_CARET_FLASHINTERVAL); + CPWL_Wnd::SetVisible(true); + m_bFlash = true; + Move(m_rcInvalid, false, true); + } + } else { + m_ptHead = CFX_PointF(); + m_ptFoot = CFX_PointF(); + m_bFlash = false; + if (IsVisible()) { + EndTimer(); + CPWL_Wnd::SetVisible(false); + } + } +} + +void CPWL_Caret::InvalidateRect(CFX_FloatRect* pRect) { + if (pRect) { + CFX_FloatRect rcRefresh = *pRect; + if (!rcRefresh.IsEmpty()) { + rcRefresh.Inflate(0.5f, 0.5f); + rcRefresh.Normalize(); + } + rcRefresh.top += 1; + rcRefresh.bottom -= 1; + CPWL_Wnd::InvalidateRect(&rcRefresh); + } else { + CPWL_Wnd::InvalidateRect(pRect); + } +} diff --git a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/PWL_Caret.h b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_caret.h index 7c041f4f5ed..6d6dcd557e1 100644 --- a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/PWL_Caret.h +++ b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_caret.h @@ -4,19 +4,10 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef FPDFSDK_PDFWINDOW_PWL_CARET_H_ -#define FPDFSDK_PDFWINDOW_PWL_CARET_H_ +#ifndef FPDFSDK_PDFWINDOW_CPWL_CARET_H_ +#define FPDFSDK_PDFWINDOW_CPWL_CARET_H_ -#include "fpdfsdk/pdfwindow/PWL_Wnd.h" - -struct PWL_CARET_INFO { - public: - PWL_CARET_INFO(); - - bool bVisible; - CFX_PointF ptHead; - CFX_PointF ptFoot; -}; +#include "fpdfsdk/pdfwindow/cpwl_wnd.h" class CPWL_Caret : public CPWL_Wnd { public: @@ -25,7 +16,6 @@ class CPWL_Caret : public CPWL_Wnd { // CPWL_Wnd CFX_ByteString GetClassName() const override; - void GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) override; void DrawThisAppearance(CFX_RenderDevice* pDevice, CFX_Matrix* pUser2Device) override; void InvalidateRect(CFX_FloatRect* pRect = nullptr) override; @@ -35,11 +25,9 @@ class CPWL_Caret : public CPWL_Wnd { void SetCaret(bool bVisible, const CFX_PointF& ptHead, const CFX_PointF& ptFoot); - CFX_ByteString GetCaretAppearanceStream(const CFX_PointF& ptOffset); void SetInvalidRect(CFX_FloatRect rc) { m_rcInvalid = rc; } private: - void GetCaretApp(CFX_ByteTextBuf& sAppStream, const CFX_PointF& ptOffset); CFX_FloatRect GetCaretRect() const; bool m_bFlash; @@ -50,4 +38,4 @@ class CPWL_Caret : public CPWL_Wnd { CFX_FloatRect m_rcInvalid; }; -#endif // FPDFSDK_PDFWINDOW_PWL_CARET_H_ +#endif // FPDFSDK_PDFWINDOW_CPWL_CARET_H_ diff --git a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_combo_box.cpp b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_combo_box.cpp new file mode 100644 index 00000000000..d86c9db8a9d --- /dev/null +++ b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_combo_box.cpp @@ -0,0 +1,535 @@ +// Copyright 2014 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 "fpdfsdk/pdfwindow/cpwl_combo_box.h" + +#include <algorithm> +#include <sstream> + +#include "core/fxge/cfx_pathdata.h" +#include "core/fxge/cfx_renderdevice.h" +#include "fpdfsdk/fxedit/fxet_list.h" +#include "fpdfsdk/pdfwindow/cpwl_edit.h" +#include "fpdfsdk/pdfwindow/cpwl_edit_ctrl.h" +#include "fpdfsdk/pdfwindow/cpwl_list_box.h" +#include "fpdfsdk/pdfwindow/cpwl_wnd.h" +#include "public/fpdf_fwlevent.h" + +namespace { + +constexpr float kDefaultFontSize = 12.0f; +constexpr float kTriangleHalfLength = 3.0f; + +} // namespace + +bool CPWL_CBListBox::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) { + CPWL_Wnd::OnLButtonUp(point, nFlag); + + if (!m_bMouseDown) + return true; + + ReleaseCapture(); + m_bMouseDown = false; + + if (!ClientHitTest(point)) + return true; + if (CPWL_Wnd* pParent = GetParentWindow()) + pParent->NotifyLButtonUp(this, point); + + return !OnNotifySelectionChanged(false, nFlag); +} + +bool CPWL_CBListBox::IsMovementKey(uint16_t nChar) const { + switch (nChar) { + case FWL_VKEY_Up: + case FWL_VKEY_Down: + case FWL_VKEY_Home: + case FWL_VKEY_Left: + case FWL_VKEY_End: + case FWL_VKEY_Right: + return true; + default: + return false; + } +} + +bool CPWL_CBListBox::OnMovementKeyDown(uint16_t nChar, uint32_t nFlag) { + ASSERT(IsMovementKey(nChar)); + + switch (nChar) { + case FWL_VKEY_Up: + m_pList->OnVK_UP(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); + break; + case FWL_VKEY_Down: + m_pList->OnVK_DOWN(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); + break; + case FWL_VKEY_Home: + m_pList->OnVK_HOME(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); + break; + case FWL_VKEY_Left: + m_pList->OnVK_LEFT(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); + break; + case FWL_VKEY_End: + m_pList->OnVK_END(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); + break; + case FWL_VKEY_Right: + m_pList->OnVK_RIGHT(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); + break; + } + return OnNotifySelectionChanged(true, nFlag); +} + +bool CPWL_CBListBox::IsChar(uint16_t nChar, uint32_t nFlag) const { + return m_pList->OnChar(nChar, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); +} + +bool CPWL_CBListBox::OnCharNotify(uint16_t nChar, uint32_t nFlag) { + if (CPWL_ComboBox* pComboBox = (CPWL_ComboBox*)GetParentWindow()) + pComboBox->SetSelectText(); + + return OnNotifySelectionChanged(true, nFlag); +} + +void CPWL_CBButton::DrawThisAppearance(CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device) { + CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device); + + CFX_FloatRect rectWnd = CPWL_Wnd::GetWindowRect(); + + if (!IsVisible() || rectWnd.IsEmpty()) + return; + + CFX_PointF ptCenter = GetCenterPoint(); + + CFX_PointF pt1(ptCenter.x - kTriangleHalfLength, + ptCenter.y + kTriangleHalfLength * 0.5f); + CFX_PointF pt2(ptCenter.x + kTriangleHalfLength, + ptCenter.y + kTriangleHalfLength * 0.5f); + CFX_PointF pt3(ptCenter.x, ptCenter.y - kTriangleHalfLength * 0.5f); + + if (IsFloatBigger(rectWnd.right - rectWnd.left, kTriangleHalfLength * 2) && + IsFloatBigger(rectWnd.top - rectWnd.bottom, kTriangleHalfLength)) { + CFX_PathData path; + path.AppendPoint(pt1, FXPT_TYPE::MoveTo, false); + path.AppendPoint(pt2, FXPT_TYPE::LineTo, false); + path.AppendPoint(pt3, FXPT_TYPE::LineTo, false); + path.AppendPoint(pt1, FXPT_TYPE::LineTo, false); + + pDevice->DrawPath(&path, pUser2Device, nullptr, + PWL_DEFAULT_BLACKCOLOR.ToFXColor(GetTransparency()), 0, + FXFILL_ALTERNATE); + } +} + +bool CPWL_CBButton::OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) { + CPWL_Wnd::OnLButtonDown(point, nFlag); + + SetCapture(); + + if (CPWL_Wnd* pParent = GetParentWindow()) + pParent->NotifyLButtonDown(this, point); + + return true; +} + +bool CPWL_CBButton::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) { + CPWL_Wnd::OnLButtonUp(point, nFlag); + + ReleaseCapture(); + + return true; +} + +CPWL_ComboBox::CPWL_ComboBox() {} + +CPWL_ComboBox::~CPWL_ComboBox() {} + +CFX_ByteString CPWL_ComboBox::GetClassName() const { + return "CPWL_ComboBox"; +} + +void CPWL_ComboBox::OnCreate(PWL_CREATEPARAM& cp) { + cp.dwFlags &= ~PWS_HSCROLL; + cp.dwFlags &= ~PWS_VSCROLL; +} + +void CPWL_ComboBox::OnDestroy() { + // Until cleanup takes place in the virtual destructor for CPWL_Wnd + // subclasses, implement the virtual OnDestroy method that does the + // cleanup first, then invokes the superclass OnDestroy ... gee, + // like a dtor would. + m_pList.Release(); + m_pButton.Release(); + m_pEdit.Release(); + CPWL_Wnd::OnDestroy(); +} + +void CPWL_ComboBox::SetFocus() { + if (m_pEdit) + m_pEdit->SetFocus(); +} + +void CPWL_ComboBox::KillFocus() { + SetPopup(false); + CPWL_Wnd::KillFocus(); +} + +CFX_WideString CPWL_ComboBox::GetSelectedText() { + if (m_pEdit) + return m_pEdit->GetSelectedText(); + + return CFX_WideString(); +} + +CFX_WideString CPWL_ComboBox::GetText() const { + if (m_pEdit) { + return m_pEdit->GetText(); + } + return CFX_WideString(); +} + +void CPWL_ComboBox::SetText(const CFX_WideString& text) { + if (m_pEdit) + m_pEdit->SetText(text); +} + +void CPWL_ComboBox::AddString(const CFX_WideString& str) { + if (m_pList) + m_pList->AddString(str); +} + +int32_t CPWL_ComboBox::GetSelect() const { + return m_nSelectItem; +} + +void CPWL_ComboBox::SetSelect(int32_t nItemIndex) { + if (m_pList) + m_pList->Select(nItemIndex); + + m_pEdit->SetText(m_pList->GetText()); + m_nSelectItem = nItemIndex; +} + +void CPWL_ComboBox::SetEditSel(int32_t nStartChar, int32_t nEndChar) { + if (m_pEdit) + m_pEdit->SetSel(nStartChar, nEndChar); +} + +void CPWL_ComboBox::GetEditSel(int32_t& nStartChar, int32_t& nEndChar) const { + nStartChar = -1; + nEndChar = -1; + + if (m_pEdit) + m_pEdit->GetSel(nStartChar, nEndChar); +} + +void CPWL_ComboBox::Clear() { + if (m_pEdit) + m_pEdit->Clear(); +} + +void CPWL_ComboBox::CreateChildWnd(const PWL_CREATEPARAM& cp) { + CreateEdit(cp); + CreateButton(cp); + CreateListBox(cp); +} + +void CPWL_ComboBox::CreateEdit(const PWL_CREATEPARAM& cp) { + if (m_pEdit) + return; + + m_pEdit = new CPWL_Edit(); + m_pEdit->AttachFFLData(m_pFormFiller.Get()); + + PWL_CREATEPARAM ecp = cp; + ecp.pParentWnd = this; + ecp.dwFlags = PWS_VISIBLE | PWS_CHILD | PWS_BORDER | PES_CENTER | + PES_AUTOSCROLL | PES_UNDO; + + if (HasFlag(PWS_AUTOFONTSIZE)) + ecp.dwFlags |= PWS_AUTOFONTSIZE; + + if (!HasFlag(PCBS_ALLOWCUSTOMTEXT)) + ecp.dwFlags |= PWS_READONLY; + + ecp.rcRectWnd = CFX_FloatRect(); + ecp.dwBorderWidth = 0; + ecp.nBorderStyle = BorderStyle::SOLID; + m_pEdit->Create(ecp); +} + +void CPWL_ComboBox::CreateButton(const PWL_CREATEPARAM& cp) { + if (m_pButton) + return; + + m_pButton = new CPWL_CBButton; + + PWL_CREATEPARAM bcp = cp; + bcp.pParentWnd = this; + bcp.dwFlags = PWS_VISIBLE | PWS_CHILD | PWS_BORDER | PWS_BACKGROUND; + bcp.sBackgroundColor = CFX_Color(COLORTYPE_RGB, 220.0f / 255.0f, + 220.0f / 255.0f, 220.0f / 255.0f); + bcp.sBorderColor = PWL_DEFAULT_BLACKCOLOR; + bcp.dwBorderWidth = 2; + bcp.nBorderStyle = BorderStyle::BEVELED; + bcp.eCursorType = FXCT_ARROW; + m_pButton->Create(bcp); +} + +void CPWL_ComboBox::CreateListBox(const PWL_CREATEPARAM& cp) { + if (m_pList) + return; + + m_pList = new CPWL_CBListBox(); + m_pList->AttachFFLData(m_pFormFiller.Get()); + + PWL_CREATEPARAM lcp = cp; + lcp.pParentWnd = this; + lcp.dwFlags = + PWS_CHILD | PWS_BORDER | PWS_BACKGROUND | PLBS_HOVERSEL | PWS_VSCROLL; + lcp.nBorderStyle = BorderStyle::SOLID; + lcp.dwBorderWidth = 1; + lcp.eCursorType = FXCT_ARROW; + lcp.rcRectWnd = CFX_FloatRect(); + + if (cp.dwFlags & PWS_AUTOFONTSIZE) + lcp.fFontSize = kDefaultFontSize; + else + lcp.fFontSize = cp.fFontSize; + + if (cp.sBorderColor.nColorType == COLORTYPE_TRANSPARENT) + lcp.sBorderColor = PWL_DEFAULT_BLACKCOLOR; + + if (cp.sBackgroundColor.nColorType == COLORTYPE_TRANSPARENT) + lcp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR; + + m_pList->Create(lcp); +} + +void CPWL_ComboBox::RePosChildWnd() { + const CFX_FloatRect rcClient = GetClientRect(); + if (m_bPopup) { + const float fOldWindowHeight = m_rcOldWindow.Height(); + const float fOldClientHeight = fOldWindowHeight - GetBorderWidth() * 2; + + CFX_FloatRect rcList = CPWL_Wnd::GetWindowRect(); + CFX_FloatRect rcButton = rcClient; + rcButton.left = + std::max(rcButton.right - PWL_COMBOBOX_BUTTON_WIDTH, rcClient.left); + CFX_FloatRect rcEdit = rcClient; + rcEdit.right = std::max(rcButton.left - 1.0f, rcEdit.left); + if (m_bBottom) { + rcButton.bottom = rcButton.top - fOldClientHeight; + rcEdit.bottom = rcEdit.top - fOldClientHeight; + rcList.top -= fOldWindowHeight; + } else { + rcButton.top = rcButton.bottom + fOldClientHeight; + rcEdit.top = rcEdit.bottom + fOldClientHeight; + rcList.bottom += fOldWindowHeight; + } + + if (m_pButton) + m_pButton->Move(rcButton, true, false); + + if (m_pEdit) + m_pEdit->Move(rcEdit, true, false); + + if (m_pList) { + m_pList->SetVisible(true); + m_pList->Move(rcList, true, false); + m_pList->ScrollToListItem(m_nSelectItem); + } + return; + } + + CFX_FloatRect rcButton = rcClient; + rcButton.left = + std::max(rcButton.right - PWL_COMBOBOX_BUTTON_WIDTH, rcClient.left); + + if (m_pButton) + m_pButton->Move(rcButton, true, false); + + CFX_FloatRect rcEdit = rcClient; + rcEdit.right = std::max(rcButton.left - 1.0f, rcEdit.left); + + if (m_pEdit) + m_pEdit->Move(rcEdit, true, false); + + if (m_pList) + m_pList->SetVisible(false); +} + +void CPWL_ComboBox::SelectAll() { + if (m_pEdit && HasFlag(PCBS_ALLOWCUSTOMTEXT)) + m_pEdit->SelectAll(); +} + +CFX_FloatRect CPWL_ComboBox::GetFocusRect() const { + return CFX_FloatRect(); +} + +void CPWL_ComboBox::SetPopup(bool bPopup) { + if (!m_pList) + return; + if (bPopup == m_bPopup) + return; + float fListHeight = m_pList->GetContentRect().Height(); + if (!IsFloatBigger(fListHeight, 0.0f)) + return; + + if (!bPopup) { + m_bPopup = bPopup; + Move(m_rcOldWindow, true, true); + return; + } + + if (!m_pFillerNotify) + return; + +#ifdef PDF_ENABLE_XFA + if (m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), 0)) + return; +#endif // PDF_ENABLE_XFA + + float fBorderWidth = m_pList->GetBorderWidth() * 2; + float fPopupMin = 0.0f; + if (m_pList->GetCount() > 3) + fPopupMin = m_pList->GetFirstHeight() * 3 + fBorderWidth; + float fPopupMax = fListHeight + fBorderWidth; + + bool bBottom; + float fPopupRet; + m_pFillerNotify->QueryWherePopup(GetAttachedData(), fPopupMin, fPopupMax, + &bBottom, &fPopupRet); + if (!IsFloatBigger(fPopupRet, 0.0f)) + return; + + m_rcOldWindow = CPWL_Wnd::GetWindowRect(); + m_bPopup = bPopup; + m_bBottom = bBottom; + + CFX_FloatRect rcWindow = m_rcOldWindow; + if (bBottom) + rcWindow.bottom -= fPopupRet; + else + rcWindow.top += fPopupRet; + + Move(rcWindow, true, true); +#ifdef PDF_ENABLE_XFA + m_pFillerNotify->OnPopupPostOpen(GetAttachedData(), 0); +#endif // PDF_ENABLE_XFA +} + +bool CPWL_ComboBox::OnKeyDown(uint16_t nChar, uint32_t nFlag) { + if (!m_pList) + return false; + if (!m_pEdit) + return false; + + m_nSelectItem = -1; + + switch (nChar) { + case FWL_VKEY_Up: + if (m_pList->GetCurSel() > 0) { +#ifdef PDF_ENABLE_XFA + if (m_pFillerNotify) { + if (m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), nFlag)) + return false; + if (m_pFillerNotify->OnPopupPostOpen(GetAttachedData(), nFlag)) + return false; + } +#endif // PDF_ENABLE_XFA + if (m_pList->IsMovementKey(nChar)) { + if (m_pList->OnMovementKeyDown(nChar, nFlag)) + return false; + SetSelectText(); + } + } + return true; + case FWL_VKEY_Down: + if (m_pList->GetCurSel() < m_pList->GetCount() - 1) { +#ifdef PDF_ENABLE_XFA + if (m_pFillerNotify) { + if (m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), nFlag)) + return false; + if (m_pFillerNotify->OnPopupPostOpen(GetAttachedData(), nFlag)) + return false; + } +#endif // PDF_ENABLE_XFA + if (m_pList->IsMovementKey(nChar)) { + if (m_pList->OnMovementKeyDown(nChar, nFlag)) + return false; + SetSelectText(); + } + } + return true; + } + + if (HasFlag(PCBS_ALLOWCUSTOMTEXT)) + return m_pEdit->OnKeyDown(nChar, nFlag); + + return false; +} + +bool CPWL_ComboBox::OnChar(uint16_t nChar, uint32_t nFlag) { + if (!m_pList) + return false; + + if (!m_pEdit) + return false; + + m_nSelectItem = -1; + if (HasFlag(PCBS_ALLOWCUSTOMTEXT)) + return m_pEdit->OnChar(nChar, nFlag); + +#ifdef PDF_ENABLE_XFA + if (m_pFillerNotify) { + if (m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), nFlag)) + return false; + if (m_pFillerNotify->OnPopupPostOpen(GetAttachedData(), nFlag)) + return false; + } +#endif // PDF_ENABLE_XFA + if (!m_pList->IsChar(nChar, nFlag)) + return false; + return m_pList->OnCharNotify(nChar, nFlag); +} + +void CPWL_ComboBox::NotifyLButtonDown(CPWL_Wnd* child, const CFX_PointF& pos) { + if (child == m_pButton) + SetPopup(!m_bPopup); +} + +void CPWL_ComboBox::NotifyLButtonUp(CPWL_Wnd* child, const CFX_PointF& pos) { + if (!m_pEdit || !m_pList || child != m_pList) + return; + + SetSelectText(); + SelectAll(); + m_pEdit->SetFocus(); + SetPopup(false); +} + +bool CPWL_ComboBox::IsPopup() const { + return m_bPopup; +} + +void CPWL_ComboBox::SetSelectText() { + m_pEdit->SelectAll(); + m_pEdit->ReplaceSel(m_pList->GetText()); + m_pEdit->SelectAll(); + m_nSelectItem = m_pList->GetCurSel(); +} + +void CPWL_ComboBox::SetFillerNotify(IPWL_Filler_Notify* pNotify) { + m_pFillerNotify = pNotify; + + if (m_pEdit) + m_pEdit->SetFillerNotify(pNotify); + + if (m_pList) + m_pList->SetFillerNotify(pNotify); +} diff --git a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/PWL_ComboBox.h b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_combo_box.h index 0dfb3bd86b8..7dc348a7110 100644 --- a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/PWL_ComboBox.h +++ b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_combo_box.h @@ -4,21 +4,15 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef FPDFSDK_PDFWINDOW_PWL_COMBOBOX_H_ -#define FPDFSDK_PDFWINDOW_PWL_COMBOBOX_H_ +#ifndef FPDFSDK_PDFWINDOW_CPWL_COMBO_BOX_H_ +#define FPDFSDK_PDFWINDOW_CPWL_COMBO_BOX_H_ #include <memory> #include "core/fxcrt/cfx_unowned_ptr.h" -#include "fpdfsdk/pdfwindow/PWL_Edit.h" -#include "fpdfsdk/pdfwindow/PWL_ListBox.h" -#include "fpdfsdk/pdfwindow/PWL_Wnd.h" - -class CPWL_CBEdit : public CPWL_Edit { - public: - CPWL_CBEdit() {} - ~CPWL_CBEdit() override {} -}; +#include "fpdfsdk/pdfwindow/cpwl_edit.h" +#include "fpdfsdk/pdfwindow/cpwl_list_box.h" +#include "fpdfsdk/pdfwindow/cpwl_wnd.h" class CPWL_CBListBox : public CPWL_ListBox { public: @@ -28,8 +22,10 @@ class CPWL_CBListBox : public CPWL_ListBox { // CPWL_ListBox bool OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) override; - bool OnKeyDownWithExit(uint16_t nChar, bool& bExit, uint32_t nFlag); - bool OnCharWithExit(uint16_t nChar, bool& bExit, uint32_t nFlag); + bool IsMovementKey(uint16_t nChar) const; + bool OnMovementKeyDown(uint16_t nChar, uint32_t nFlag); + bool IsChar(uint16_t nChar, uint32_t nFlag) const; + bool OnCharNotify(uint16_t nChar, uint32_t nFlag); }; #define PWL_COMBOBOX_BUTTON_WIDTH 13 @@ -40,7 +36,6 @@ class CPWL_CBButton : public CPWL_Wnd { ~CPWL_CBButton() override {} // CPWL_Wnd - void GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) override; void DrawThisAppearance(CFX_RenderDevice* pDevice, CFX_Matrix* pUser2Device) override; bool OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) override; @@ -52,22 +47,22 @@ class CPWL_ComboBox : public CPWL_Wnd { CPWL_ComboBox(); ~CPWL_ComboBox() override; - CPWL_Edit* GetEdit() const { return m_pEdit; } + CPWL_Edit* GetEdit() const { return m_pEdit.Get(); } // CPWL_Wnd: CFX_ByteString GetClassName() const override; void OnCreate(PWL_CREATEPARAM& cp) override; + void OnDestroy() override; bool OnKeyDown(uint16_t nChar, uint32_t nFlag) override; bool OnChar(uint16_t nChar, uint32_t nFlag) override; - void OnNotify(CPWL_Wnd* pWnd, - uint32_t msg, - intptr_t wParam = 0, - intptr_t lParam = 0) override; + void NotifyLButtonDown(CPWL_Wnd* child, const CFX_PointF& pos) override; + void NotifyLButtonUp(CPWL_Wnd* child, const CFX_PointF& pos) override; void CreateChildWnd(const PWL_CREATEPARAM& cp) override; void RePosChildWnd() override; CFX_FloatRect GetFocusRect() const override; void SetFocus() override; void KillFocus() override; + CFX_WideString GetSelectedText() override; void SetFillerNotify(IPWL_Filler_Notify* pNotify); @@ -93,15 +88,15 @@ class CPWL_ComboBox : public CPWL_Wnd { void CreateListBox(const PWL_CREATEPARAM& cp); void SetPopup(bool bPopup); - CPWL_CBEdit* m_pEdit; - CPWL_CBButton* m_pButton; - CPWL_CBListBox* m_pList; - bool m_bPopup; + CFX_UnownedPtr<CPWL_Edit> m_pEdit; + CFX_UnownedPtr<CPWL_CBButton> m_pButton; + CFX_UnownedPtr<CPWL_CBListBox> m_pList; CFX_FloatRect m_rcOldWindow; - int32_t m_nPopupWhere; - int32_t m_nSelectItem; - IPWL_Filler_Notify* m_pFillerNotify; + bool m_bPopup = false; + bool m_bBottom = true; + int32_t m_nSelectItem = -1; + CFX_UnownedPtr<IPWL_Filler_Notify> m_pFillerNotify; CFX_UnownedPtr<CFFL_FormFiller> m_pFormFiller; }; -#endif // FPDFSDK_PDFWINDOW_PWL_COMBOBOX_H_ +#endif // FPDFSDK_PDFWINDOW_CPWL_COMBO_BOX_H_ diff --git a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_combo_box_embeddertest.cpp b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_combo_box_embeddertest.cpp new file mode 100644 index 00000000000..35c7b2264b4 --- /dev/null +++ b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_combo_box_embeddertest.cpp @@ -0,0 +1,196 @@ +// Copyright 2017 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. + +#include "fpdfsdk/cba_annotiterator.h" +#include "fpdfsdk/cpdfsdk_annot.h" +#include "fpdfsdk/cpdfsdk_formfillenvironment.h" +#include "fpdfsdk/formfiller/cffl_formfiller.h" +#include "fpdfsdk/formfiller/cffl_interactiveformfiller.h" +#include "fpdfsdk/pdfwindow/cpwl_combo_box.h" +#include "fpdfsdk/pdfwindow/cpwl_wnd.h" +#include "testing/embedder_test.h" +#include "testing/gtest/include/gtest/gtest.h" + +class CPWLComboBoxEditEmbeddertest : public EmbedderTest { + protected: + void SetUp() override { + EmbedderTest::SetUp(); + CreateAndInitializeFormComboboxPDF(); + } + + void TearDown() override { + UnloadPage(GetPage()); + EmbedderTest::TearDown(); + } + + void CreateAndInitializeFormComboboxPDF() { + EXPECT_TRUE(OpenDocument("combobox_form.pdf")); + m_page = LoadPage(0); + ASSERT_TRUE(m_page); + + m_pFormFillEnv = static_cast<CPDFSDK_FormFillEnvironment*>(form_handle()); + CBA_AnnotIterator iter(m_pFormFillEnv->GetPageView(0), + CPDF_Annot::Subtype::WIDGET); + + // User editable combobox. + m_pAnnotEditable = iter.GetFirstAnnot(); + ASSERT_TRUE(m_pAnnotEditable); + ASSERT_EQ(CPDF_Annot::Subtype::WIDGET, m_pAnnotEditable->GetAnnotSubtype()); + + // Normal combobox with pre-selected value. + m_pAnnotNormal = iter.GetNextAnnot(m_pAnnotEditable); + ASSERT_TRUE(m_pAnnotNormal); + ASSERT_EQ(CPDF_Annot::Subtype::WIDGET, m_pAnnotNormal->GetAnnotSubtype()); + + // Read-only combobox. + CPDFSDK_Annot* pAnnotReadOnly = iter.GetNextAnnot(m_pAnnotNormal); + CPDFSDK_Annot* pLastAnnot = iter.GetLastAnnot(); + ASSERT_EQ(pAnnotReadOnly, pLastAnnot); + } + + void FormFillerAndWindowSetup(CPDFSDK_Annot* pAnnotCombobox) { + CFFL_InteractiveFormFiller* pInteractiveFormFiller = + m_pFormFillEnv->GetInteractiveFormFiller(); + { + CPDFSDK_Annot::ObservedPtr pObserved(pAnnotCombobox); + EXPECT_TRUE(pInteractiveFormFiller->OnSetFocus(&pObserved, 0)); + } + + m_pFormFiller = + pInteractiveFormFiller->GetFormFiller(pAnnotCombobox, false); + ASSERT_TRUE(m_pFormFiller); + + CPWL_Wnd* pWindow = + m_pFormFiller->GetPDFWindow(m_pFormFillEnv->GetPageView(0), false); + ASSERT_TRUE(pWindow); + ASSERT_EQ("CPWL_ComboBox", pWindow->GetClassName()); + m_pComboBox = static_cast<CPWL_ComboBox*>(pWindow); + } + + FPDF_PAGE GetPage() const { return m_page; } + CPWL_ComboBox* GetCPWLComboBox() const { return m_pComboBox; } + CFFL_FormFiller* GetCFFLFormFiller() const { return m_pFormFiller; } + CPDFSDK_Annot* GetCPDFSDKAnnotNormal() const { return m_pAnnotNormal; } + CPDFSDK_Annot* GetCPDFSDKAnnotUserEditable() const { + return m_pAnnotEditable; + } + CPDFSDK_FormFillEnvironment* GetCPDFSDKFormFillEnv() const { + return m_pFormFillEnv; + } + + private: + FPDF_PAGE m_page; + CPWL_ComboBox* m_pComboBox; + CFFL_FormFiller* m_pFormFiller; + CPDFSDK_Annot* m_pAnnotNormal; + CPDFSDK_Annot* m_pAnnotEditable; + CPDFSDK_FormFillEnvironment* m_pFormFillEnv; +}; + +TEST_F(CPWLComboBoxEditEmbeddertest, GetSelectedTextEmptyAndBasicNormal) { + FormFillerAndWindowSetup(GetCPDFSDKAnnotNormal()); + + // Automatically pre-filled with "Banana". + EXPECT_FALSE(GetCPWLComboBox()->GetText().IsEmpty()); + EXPECT_STREQ(L"Banana", GetCPWLComboBox()->GetText().c_str()); + + // Check that selection is intially empty, then select entire word. + EXPECT_TRUE(GetCPWLComboBox()->GetSelectedText().IsEmpty()); + GetCPWLComboBox()->SetSelectText(); + EXPECT_STREQ(L"Banana", GetCPWLComboBox()->GetSelectedText().c_str()); + + // Select other options. + GetCPWLComboBox()->SetSelect(0); + EXPECT_STREQ(L"Apple", GetCPWLComboBox()->GetSelectedText().c_str()); + GetCPWLComboBox()->SetSelect(2); + EXPECT_STREQ(L"Cherry", GetCPWLComboBox()->GetSelectedText().c_str()); + + // Verify that combobox text cannot be edited. + EXPECT_FALSE(GetCFFLFormFiller()->OnChar(GetCPDFSDKAnnotNormal(), 'a', 0)); +} + +TEST_F(CPWLComboBoxEditEmbeddertest, GetSelectedTextFragmentsNormal) { + FormFillerAndWindowSetup(GetCPDFSDKAnnotNormal()); + EXPECT_STREQ(L"Banana", GetCPWLComboBox()->GetText().c_str()); + + GetCPWLComboBox()->SetEditSel(0, 0); + EXPECT_TRUE(GetCPWLComboBox()->GetSelectedText().IsEmpty()); + + GetCPWLComboBox()->SetEditSel(0, 1); + EXPECT_STREQ(L"B", GetCPWLComboBox()->GetSelectedText().c_str()); + + GetCPWLComboBox()->SetEditSel(0, -1); + EXPECT_STREQ(L"Banana", GetCPWLComboBox()->GetSelectedText().c_str()); + + GetCPWLComboBox()->SetEditSel(-8, -1); + EXPECT_TRUE(GetCPWLComboBox()->GetSelectedText().IsEmpty()); + + GetCPWLComboBox()->SetEditSel(4, 1); + EXPECT_STREQ(L"ana", GetCPWLComboBox()->GetSelectedText().c_str()); + + GetCPWLComboBox()->SetEditSel(1, 4); + EXPECT_STREQ(L"ana", GetCPWLComboBox()->GetSelectedText().c_str()); + + GetCPWLComboBox()->SetEditSel(5, 6); + EXPECT_STREQ(L"a", GetCPWLComboBox()->GetSelectedText().c_str()); +} + +TEST_F(CPWLComboBoxEditEmbeddertest, GetSelectedTextEmptyAndBasicEditable) { + FormFillerAndWindowSetup(GetCPDFSDKAnnotUserEditable()); + EXPECT_TRUE(GetCPWLComboBox()->GetText().IsEmpty()); + + // Check selection is intially empty, then select a provided option. + EXPECT_TRUE(GetCPWLComboBox()->GetSelectedText().IsEmpty()); + GetCPWLComboBox()->SetSelect(0); + GetCPWLComboBox()->SetSelectText(); + EXPECT_STREQ(L"Foo", GetCPWLComboBox()->GetSelectedText().c_str()); + + // Select another option and then select last char of that option. + GetCPWLComboBox()->SetSelect(1); + EXPECT_STREQ(L"Bar", GetCPWLComboBox()->GetSelectedText().c_str()); + GetCPWLComboBox()->SetEditSel(2, 3); + EXPECT_STREQ(L"r", GetCPWLComboBox()->GetSelectedText().c_str()); + + // Type into editable combobox text field and select new text. + EXPECT_TRUE( + GetCFFLFormFiller()->OnChar(GetCPDFSDKAnnotUserEditable(), 'a', 0)); + EXPECT_TRUE( + GetCFFLFormFiller()->OnChar(GetCPDFSDKAnnotUserEditable(), 'b', 0)); + EXPECT_TRUE( + GetCFFLFormFiller()->OnChar(GetCPDFSDKAnnotUserEditable(), 'c', 0)); + + EXPECT_TRUE(GetCPWLComboBox()->GetSelectedText().IsEmpty()); + GetCPWLComboBox()->SetEditSel(0, 5); + EXPECT_STREQ(L"Baabc", GetCPWLComboBox()->GetSelectedText().c_str()); +} + +TEST_F(CPWLComboBoxEditEmbeddertest, GetSelectedTextFragmentsEditable) { + FormFillerAndWindowSetup(GetCPDFSDKAnnotUserEditable()); + for (int i = 0; i < 50; ++i) { + EXPECT_TRUE( + GetCFFLFormFiller()->OnChar(GetCPDFSDKAnnotUserEditable(), i + 'A', 0)); + } + + GetCPWLComboBox()->SetEditSel(0, 0); + EXPECT_TRUE(GetCPWLComboBox()->GetSelectedText().IsEmpty()); + + GetCPWLComboBox()->SetEditSel(0, 1); + EXPECT_STREQ(L"A", GetCPWLComboBox()->GetSelectedText().c_str()); + + GetCPWLComboBox()->SetEditSel(0, -1); + EXPECT_STREQ(L"ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqr", + GetCPWLComboBox()->GetSelectedText().c_str()); + + GetCPWLComboBox()->SetEditSel(-8, -1); + EXPECT_TRUE(GetCPWLComboBox()->GetSelectedText().IsEmpty()); + + GetCPWLComboBox()->SetEditSel(23, 12); + EXPECT_STREQ(L"MNOPQRSTUVW", GetCPWLComboBox()->GetSelectedText().c_str()); + + GetCPWLComboBox()->SetEditSel(12, 23); + EXPECT_STREQ(L"MNOPQRSTUVW", GetCPWLComboBox()->GetSelectedText().c_str()); + + GetCPWLComboBox()->SetEditSel(49, 50); + EXPECT_STREQ(L"r", GetCPWLComboBox()->GetSelectedText().c_str()); +} diff --git a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/PWL_Edit.cpp b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_edit.cpp index 2b788247110..046fb5789f9 100644 --- a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/PWL_Edit.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_edit.cpp @@ -4,10 +4,11 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "fpdfsdk/pdfwindow/PWL_Edit.h" +#include "fpdfsdk/pdfwindow/cpwl_edit.h" #include <algorithm> #include <memory> +#include <sstream> #include <vector> #include "core/fpdfapi/font/cpdf_font.h" @@ -20,17 +21,15 @@ #include "core/fxge/cfx_renderdevice.h" #include "core/fxge/fx_font.h" #include "fpdfsdk/fxedit/fxet_edit.h" -#include "fpdfsdk/pdfwindow/PWL_Caret.h" -#include "fpdfsdk/pdfwindow/PWL_EditCtrl.h" -#include "fpdfsdk/pdfwindow/PWL_FontMap.h" -#include "fpdfsdk/pdfwindow/PWL_ScrollBar.h" -#include "fpdfsdk/pdfwindow/PWL_Utils.h" -#include "fpdfsdk/pdfwindow/PWL_Wnd.h" +#include "fpdfsdk/pdfwindow/cpwl_caret.h" +#include "fpdfsdk/pdfwindow/cpwl_edit_ctrl.h" +#include "fpdfsdk/pdfwindow/cpwl_font_map.h" +#include "fpdfsdk/pdfwindow/cpwl_scroll_bar.h" +#include "fpdfsdk/pdfwindow/cpwl_wnd.h" #include "public/fpdf_fwlevent.h" #include "third_party/base/stl_util.h" -CPWL_Edit::CPWL_Edit() - : m_pFillerNotify(nullptr), m_bFocus(false), m_pFormFiller(nullptr) {} +CPWL_Edit::CPWL_Edit() : m_bFocus(false) {} CPWL_Edit::~CPWL_Edit() { ASSERT(!m_bFocus); @@ -40,8 +39,6 @@ CFX_ByteString CPWL_Edit::GetClassName() const { return PWL_CLASSNAME_EDIT; } -void CPWL_Edit::OnDestroy() {} - void CPWL_Edit::SetText(const CFX_WideString& csText) { CFX_WideString swText = csText; if (!HasFlag(PES_RICH)) { @@ -91,17 +88,22 @@ void CPWL_Edit::RePosChildWnd() { pVSB->Move(rcVScroll, true, false); } - if (m_pEditCaret && !HasFlag(PES_TEXTOVERFLOW)) - m_pEditCaret->SetClipRect(CPWL_Utils::InflateRect( - GetClientRect(), 1.0f)); // +1 for caret beside border + if (m_pEditCaret && !HasFlag(PES_TEXTOVERFLOW)) { + CFX_FloatRect rect = GetClientRect(); + if (!rect.IsEmpty()) { + // +1 for caret beside border + rect.Inflate(1.0f, 1.0f); + rect.Normalize(); + } + m_pEditCaret->SetClipRect(rect); + } CPWL_EditCtrl::RePosChildWnd(); } CFX_FloatRect CPWL_Edit::GetClientRect() const { - CFX_FloatRect rcClient = CPWL_Utils::DeflateRect( - GetWindowRect(), (float)(GetBorderWidth() + GetInnerBorderWidth())); - + float width = static_cast<float>(GetBorderWidth() + GetInnerBorderWidth()); + CFX_FloatRect rcClient = GetWindowRect().GetDeflated(width, width); if (CPWL_ScrollBar* pVSB = GetVScrollBar()) { if (pVSB->IsVisible()) { rcClient.right -= PWL_SCROLLBAR_WIDTH; @@ -181,135 +183,19 @@ void CPWL_Edit::SetParamByFlag() { m_pEdit->EnableUndo(HasFlag(PES_UNDO)); if (HasFlag(PES_TEXTOVERFLOW)) { - SetClipRect(CFX_FloatRect(0.0f, 0.0f, 0.0f, 0.0f)); + SetClipRect(CFX_FloatRect()); m_pEdit->SetTextOverflow(true, false); } else { if (m_pEditCaret) { - m_pEditCaret->SetClipRect(CPWL_Utils::InflateRect( - GetClientRect(), 1.0f)); // +1 for caret beside border - } - } -} - -void CPWL_Edit::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) { - CPWL_Wnd::GetThisAppearanceStream(sAppStream); - - CFX_FloatRect rcClient = GetClientRect(); - CFX_ByteTextBuf sLine; - - int32_t nCharArray = m_pEdit->GetCharArray(); - - if (nCharArray > 0) { - switch (GetBorderStyle()) { - case BorderStyle::SOLID: { - sLine << "q\n" - << GetBorderWidth() << " w\n" - << CPWL_Utils::GetColorAppStream(GetBorderColor(), false) - .AsStringC() - << " 2 J 0 j\n"; - - for (int32_t i = 1; i < nCharArray; i++) { - sLine << rcClient.left + - ((rcClient.right - rcClient.left) / nCharArray) * i - << " " << rcClient.bottom << " m\n" - << rcClient.left + - ((rcClient.right - rcClient.left) / nCharArray) * i - << " " << rcClient.top << " l S\n"; - } - - sLine << "Q\n"; - break; + CFX_FloatRect rect = GetClientRect(); + if (!rect.IsEmpty()) { + // +1 for caret beside border + rect.Inflate(1.0f, 1.0f); + rect.Normalize(); } - case BorderStyle::DASH: { - sLine << "q\n" - << GetBorderWidth() << " w\n" - << CPWL_Utils::GetColorAppStream(GetBorderColor(), false) - .AsStringC() - << " 2 J 0 j\n" - << "[" << GetBorderDash().nDash << " " << GetBorderDash().nGap - << "] " << GetBorderDash().nPhase << " d\n"; - - for (int32_t i = 1; i < nCharArray; i++) { - sLine << rcClient.left + - ((rcClient.right - rcClient.left) / nCharArray) * i - << " " << rcClient.bottom << " m\n" - << rcClient.left + - ((rcClient.right - rcClient.left) / nCharArray) * i - << " " << rcClient.top << " l S\n"; - } - - sLine << "Q\n"; - break; - } - default: - break; + m_pEditCaret->SetClipRect(rect); } } - - sAppStream << sLine; - - CFX_ByteTextBuf sText; - CFX_PointF ptOffset; - CPVT_WordRange wrWhole = m_pEdit->GetWholeWordRange(); - CPVT_WordRange wrSelect = GetSelectWordRange(); - CPVT_WordRange wrVisible = - HasFlag(PES_TEXTOVERFLOW) ? wrWhole : m_pEdit->GetVisibleWordRange(); - - CPVT_WordRange wrSelBefore(wrWhole.BeginPos, wrSelect.BeginPos); - CPVT_WordRange wrSelAfter(wrSelect.EndPos, wrWhole.EndPos); - CPVT_WordRange wrTemp = - CPWL_Utils::OverlapWordRange(GetSelectWordRange(), wrVisible); - CFX_ByteString sEditSel = - CPWL_Utils::GetEditSelAppStream(m_pEdit.get(), ptOffset, &wrTemp); - - if (sEditSel.GetLength() > 0) - sText << CPWL_Utils::GetColorAppStream(PWL_DEFAULT_SELBACKCOLOR).AsStringC() - << sEditSel.AsStringC(); - - wrTemp = CPWL_Utils::OverlapWordRange(wrVisible, wrSelBefore); - CFX_ByteString sEditBefore = CPWL_Utils::GetEditAppStream( - m_pEdit.get(), ptOffset, &wrTemp, !HasFlag(PES_CHARARRAY), - m_pEdit->GetPasswordChar()); - - if (sEditBefore.GetLength() > 0) - sText << "BT\n" - << CPWL_Utils::GetColorAppStream(GetTextColor()).AsStringC() - << sEditBefore.AsStringC() << "ET\n"; - - wrTemp = CPWL_Utils::OverlapWordRange(wrVisible, wrSelect); - CFX_ByteString sEditMid = CPWL_Utils::GetEditAppStream( - m_pEdit.get(), ptOffset, &wrTemp, !HasFlag(PES_CHARARRAY), - m_pEdit->GetPasswordChar()); - - if (sEditMid.GetLength() > 0) - sText << "BT\n" - << CPWL_Utils::GetColorAppStream(CPWL_Color(COLORTYPE_GRAY, 1)) - .AsStringC() - << sEditMid.AsStringC() << "ET\n"; - - wrTemp = CPWL_Utils::OverlapWordRange(wrVisible, wrSelAfter); - CFX_ByteString sEditAfter = CPWL_Utils::GetEditAppStream( - m_pEdit.get(), ptOffset, &wrTemp, !HasFlag(PES_CHARARRAY), - m_pEdit->GetPasswordChar()); - - if (sEditAfter.GetLength() > 0) - sText << "BT\n" - << CPWL_Utils::GetColorAppStream(GetTextColor()).AsStringC() - << sEditAfter.AsStringC() << "ET\n"; - - if (sText.GetLength() > 0) { - CFX_FloatRect rect = GetClientRect(); - sAppStream << "q\n/Tx BMC\n"; - - if (!HasFlag(PES_TEXTOVERFLOW)) - sAppStream << rect.left << " " << rect.bottom << " " - << rect.right - rect.left << " " << rect.top - rect.bottom - << " re W n\n"; - - sAppStream << sText; - - sAppStream << "EMC\nQ\n"; - } } void CPWL_Edit::DrawThisAppearance(CFX_RenderDevice* pDevice, @@ -317,7 +203,6 @@ void CPWL_Edit::DrawThisAppearance(CFX_RenderDevice* pDevice, CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device); CFX_FloatRect rcClient = GetClientRect(); - CFX_ByteTextBuf sLine; int32_t nCharArray = m_pEdit->GetCharArray(); FX_SAFE_INT32 nCharArraySafe = nCharArray; @@ -455,7 +340,12 @@ void CPWL_Edit::OnSetFocus() { } void CPWL_Edit::OnKillFocus() { - ShowVScrollBar(false); + CPWL_ScrollBar* pScroll = GetVScrollBar(); + if (pScroll && pScroll->IsVisible()) { + pScroll->SetVisible(false); + Move(m_rcOldWindow, true, true); + } + m_pEdit->SelectNone(); SetCaret(false, CFX_PointF(), CFX_PointF()); SetCharSet(FX_CHARSET_ANSI); @@ -466,12 +356,6 @@ void CPWL_Edit::SetCharSpace(float fCharSpace) { m_pEdit->SetCharSpace(fCharSpace); } -CFX_ByteString CPWL_Edit::GetSelectAppearanceStream( - const CFX_PointF& ptOffset) const { - CPVT_WordRange wr = GetSelectWordRange(); - return CPWL_Utils::GetEditSelAppStream(m_pEdit.get(), ptOffset, &wr); -} - CPVT_WordRange CPWL_Edit::GetSelectWordRange() const { if (m_pEdit->IsSelected()) { int32_t nStart = -1; @@ -488,26 +372,6 @@ CPVT_WordRange CPWL_Edit::GetSelectWordRange() const { return CPVT_WordRange(); } -CFX_ByteString CPWL_Edit::GetTextAppearanceStream( - const CFX_PointF& ptOffset) const { - CFX_ByteTextBuf sRet; - CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream(m_pEdit.get(), ptOffset); - if (sEdit.GetLength() > 0) { - sRet << "BT\n" - << CPWL_Utils::GetColorAppStream(GetTextColor()).AsStringC() - << sEdit.AsStringC() << "ET\n"; - } - return sRet.MakeString(); -} - -CFX_ByteString CPWL_Edit::GetCaretAppearanceStream( - const CFX_PointF& ptOffset) const { - if (m_pEditCaret) - return m_pEditCaret->GetCaretAppearanceStream(ptOffset); - - return CFX_ByteString(); -} - CFX_PointF CPWL_Edit::GetWordRightBottomPoint(const CPVT_WordPlace& wpWord) { CFX_Edit_Iterator* pIterator = m_pEdit->GetIterator(); CPVT_WordPlace wpOld = pIterator->GetAt(); @@ -574,30 +438,9 @@ CFX_FloatRect CPWL_Edit::GetFocusRect() const { return CFX_FloatRect(); } -void CPWL_Edit::ShowVScrollBar(bool bShow) { - if (CPWL_ScrollBar* pScroll = GetVScrollBar()) { - if (bShow) { - if (!pScroll->IsVisible()) { - pScroll->SetVisible(true); - CFX_FloatRect rcWindow = GetWindowRect(); - m_rcOldWindow = rcWindow; - rcWindow.right += PWL_SCROLLBAR_WIDTH; - Move(rcWindow, true, true); - } - } else { - if (pScroll->IsVisible()) { - pScroll->SetVisible(false); - Move(m_rcOldWindow, true, true); - } - } - } -} - bool CPWL_Edit::IsVScrollBarVisible() const { - if (CPWL_ScrollBar* pScroll = GetVScrollBar()) { + if (CPWL_ScrollBar* pScroll = GetVScrollBar()) return pScroll->IsVisible(); - } - return false; } @@ -607,8 +450,6 @@ bool CPWL_Edit::OnKeyDown(uint16_t nChar, uint32_t nFlag) { if (nChar == FWL_VKEY_Delete) { if (m_pFillerNotify) { - bool bRC = true; - bool bExit = false; CFX_WideString strChange; CFX_WideString strChangeEx; @@ -618,9 +459,12 @@ bool CPWL_Edit::OnKeyDown(uint16_t nChar, uint32_t nFlag) { if (nSelStart == nSelEnd) nSelEnd = nSelStart + 1; - m_pFillerNotify->OnBeforeKeyStroke(GetAttachedData(), strChange, - strChangeEx, nSelStart, nSelEnd, true, - bRC, bExit, nFlag); + + bool bRC; + bool bExit; + std::tie(bRC, bExit) = m_pFillerNotify->OnBeforeKeyStroke( + GetAttachedData(), strChange, strChangeEx, nSelStart, nSelEnd, true, + nFlag); if (!bRC) return false; if (bExit) @@ -638,10 +482,10 @@ bool CPWL_Edit::OnKeyDown(uint16_t nChar, uint32_t nFlag) { } /** -*In case of implementation swallow the OnKeyDown event. -*If the event is swallowed, implementation may do other unexpected things, which -*is not the control means to do. -*/ + *In case of implementation swallow the OnKeyDown event. + *If the event is swallowed, implementation may do other unexpected things, + *which is not the control means to do. + */ bool CPWL_Edit::IsProceedtoOnChar(uint16_t nKeyCode, uint32_t nFlag) { bool bCtrl = IsCTRLpressed(nFlag); bool bAlt = IsALTpressed(nFlag); @@ -698,9 +542,9 @@ bool CPWL_Edit::OnChar(uint16_t nChar, uint32_t nFlag) { } CFX_WideString strChangeEx; - m_pFillerNotify->OnBeforeKeyStroke(GetAttachedData(), swChange, - strChangeEx, nSelStart, nSelEnd, true, - bRC, bExit, nFlag); + std::tie(bRC, bExit) = m_pFillerNotify->OnBeforeKeyStroke( + GetAttachedData(), swChange, strChangeEx, nSelStart, nSelEnd, true, + nFlag); } } diff --git a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/PWL_Edit.h b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_edit.h index bd3799141a9..366d085fdd4 100644 --- a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/PWL_Edit.h +++ b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_edit.h @@ -4,45 +4,37 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef FPDFSDK_PDFWINDOW_PWL_EDIT_H_ -#define FPDFSDK_PDFWINDOW_PWL_EDIT_H_ +#ifndef FPDFSDK_PDFWINDOW_CPWL_EDIT_H_ +#define FPDFSDK_PDFWINDOW_CPWL_EDIT_H_ -#include <vector> +#include <utility> +#include "core/fpdfdoc/cpvt_wordrange.h" #include "core/fxcrt/cfx_unowned_ptr.h" #include "core/fxcrt/fx_basic.h" -#include "fpdfsdk/fxedit/fx_edit.h" -#include "fpdfsdk/pdfwindow/PWL_EditCtrl.h" -#include "fpdfsdk/pdfwindow/PWL_Wnd.h" - -class CPDF_PageObjectHolder; -class CPDF_TextObject; -class IFX_Edit_UndoItem; +#include "fpdfsdk/pdfwindow/cpwl_edit_ctrl.h" class IPWL_Filler_Notify { public: virtual ~IPWL_Filler_Notify() {} + + // Must write to |bBottom| and |fPopupRet|. virtual void QueryWherePopup(void* pPrivateData, float fPopupMin, float fPopupMax, - int32_t& nRet, - float& fPopupRet) = 0; // nRet: (0:bottom 1:top) - virtual void OnBeforeKeyStroke(void* pPrivateData, - CFX_WideString& strChange, - const CFX_WideString& strChangeEx, - int nSelStart, - int nSelEnd, - bool bKeyDown, - bool& bRC, - bool& bExit, - uint32_t nFlag) = 0; + bool* bBottom, + float* fPopupRet) = 0; + virtual std::pair<bool, bool> OnBeforeKeyStroke( + void* pPrivateData, + CFX_WideString& strChange, + const CFX_WideString& strChangeEx, + int nSelStart, + int nSelEnd, + bool bKeyDown, + uint32_t nFlag) = 0; #ifdef PDF_ENABLE_XFA - virtual void OnPopupPreOpen(void* pPrivateData, - bool& bExit, - uint32_t nFlag) = 0; - virtual void OnPopupPostOpen(void* pPrivateData, - bool& bExit, - uint32_t nFlag) = 0; + virtual bool OnPopupPreOpen(void* pPrivateData, uint32_t nFlag) = 0; + virtual bool OnPopupPostOpen(void* pPrivateData, uint32_t nFlag) = 0; #endif // PDF_ENABLE_XFA }; @@ -53,11 +45,9 @@ class CPWL_Edit : public CPWL_EditCtrl { // CPWL_EditCtrl CFX_ByteString GetClassName() const override; - void OnDestroy() override; void OnCreated() override; void RePosChildWnd() override; CFX_FloatRect GetClientRect() const override; - void GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) override; void DrawThisAppearance(CFX_RenderDevice* pDevice, CFX_Matrix* pUser2Device) override; bool OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) override; @@ -90,10 +80,6 @@ class CPWL_Edit : public CPWL_EditCtrl { void SetText(const CFX_WideString& csText); void ReplaceSel(const CFX_WideString& csText); - CFX_ByteString GetTextAppearanceStream(const CFX_PointF& ptOffset) const; - CFX_ByteString GetCaretAppearanceStream(const CFX_PointF& ptOffset) const; - CFX_ByteString GetSelectAppearanceStream(const CFX_PointF& ptOffset) const; - bool IsTextFull() const; static float GetCharArrayAutoFontSize(CPDF_Font* pFont, @@ -119,7 +105,6 @@ class CPWL_Edit : public CPWL_EditCtrl { private: CPVT_WordRange GetSelectWordRange() const; - virtual void ShowVScrollBar(bool bShow); bool IsVScrollBarVisible() const; void SetParamByFlag(); @@ -134,10 +119,11 @@ class CPWL_Edit : public CPWL_EditCtrl { CPVT_WordRange GetSameWordsRange(const CPVT_WordPlace& place, bool bLatin, bool bArabic) const; - IPWL_Filler_Notify* m_pFillerNotify; + bool m_bFocus; CFX_FloatRect m_rcOldWindow; + CFX_UnownedPtr<IPWL_Filler_Notify> m_pFillerNotify; CFX_UnownedPtr<CFFL_FormFiller> m_pFormFiller; }; -#endif // FPDFSDK_PDFWINDOW_PWL_EDIT_H_ +#endif // FPDFSDK_PDFWINDOW_CPWL_EDIT_H_ diff --git a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/PWL_EditCtrl.cpp b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_edit_ctrl.cpp index c149e80f145..63d03929e2f 100644 --- a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/PWL_EditCtrl.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_edit_ctrl.cpp @@ -4,17 +4,16 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "fpdfsdk/pdfwindow/PWL_EditCtrl.h" +#include "fpdfsdk/pdfwindow/cpwl_edit_ctrl.h" #include "core/fpdfdoc/cpvt_section.h" #include "core/fpdfdoc/cpvt_word.h" #include "core/fxge/fx_font.h" #include "fpdfsdk/fxedit/fxet_edit.h" -#include "fpdfsdk/pdfwindow/PWL_Caret.h" -#include "fpdfsdk/pdfwindow/PWL_FontMap.h" -#include "fpdfsdk/pdfwindow/PWL_ScrollBar.h" -#include "fpdfsdk/pdfwindow/PWL_Utils.h" -#include "fpdfsdk/pdfwindow/PWL_Wnd.h" +#include "fpdfsdk/pdfwindow/cpwl_caret.h" +#include "fpdfsdk/pdfwindow/cpwl_font_map.h" +#include "fpdfsdk/pdfwindow/cpwl_scroll_bar.h" +#include "fpdfsdk/pdfwindow/cpwl_wnd.h" #include "public/fpdf_fwlevent.h" CPWL_EditCtrl::CPWL_EditCtrl() @@ -53,49 +52,29 @@ void CPWL_EditCtrl::SetCursor() { } } +CFX_WideString CPWL_EditCtrl::GetSelectedText() { + if (m_pEdit) + return m_pEdit->GetSelText(); + + return CFX_WideString(); +} + void CPWL_EditCtrl::RePosChildWnd() { m_pEdit->SetPlateRect(GetClientRect()); } -void CPWL_EditCtrl::OnNotify(CPWL_Wnd* pWnd, - uint32_t msg, - intptr_t wParam, - intptr_t lParam) { - CPWL_Wnd::OnNotify(pWnd, msg, wParam, lParam); - - switch (msg) { - case PNM_SETSCROLLINFO: - switch (wParam) { - case SBT_VSCROLL: - if (CPWL_Wnd* pChild = GetVScrollBar()) { - pChild->OnNotify(pWnd, PNM_SETSCROLLINFO, wParam, lParam); - } - break; - } - break; - case PNM_SETSCROLLPOS: - switch (wParam) { - case SBT_VSCROLL: - if (CPWL_Wnd* pChild = GetVScrollBar()) { - pChild->OnNotify(pWnd, PNM_SETSCROLLPOS, wParam, lParam); - } - break; - } - break; - case PNM_SCROLLWINDOW: { - float fPos = *(float*)lParam; - switch (wParam) { - case SBT_VSCROLL: - m_pEdit->SetScrollPos(CFX_PointF(m_pEdit->GetScrollPos().x, fPos)); - break; - } - } break; - case PNM_SETCARETINFO: { - if (PWL_CARET_INFO* pCaretInfo = (PWL_CARET_INFO*)wParam) { - SetCaret(pCaretInfo->bVisible, pCaretInfo->ptHead, pCaretInfo->ptFoot); - } - } break; - } +void CPWL_EditCtrl::SetScrollInfo(const PWL_SCROLL_INFO& info) { + if (CPWL_Wnd* pChild = GetVScrollBar()) + pChild->SetScrollInfo(info); +} + +void CPWL_EditCtrl::SetScrollPosition(float pos) { + if (CPWL_Wnd* pChild = GetVScrollBar()) + pChild->SetScrollPosition(pos); +} + +void CPWL_EditCtrl::ScrollWindowVertically(float pos) { + m_pEdit->SetScrollPos(CFX_PointF(m_pEdit->GetScrollPos().x, pos)); } void CPWL_EditCtrl::CreateChildWnd(const PWL_CREATEPARAM& cp) { @@ -115,7 +94,7 @@ void CPWL_EditCtrl::CreateEditCaret(const PWL_CREATEPARAM& cp) { ecp.dwFlags = PWS_CHILD | PWS_NOREFRESHCLIP; ecp.dwBorderWidth = 0; ecp.nBorderStyle = BorderStyle::SOLID; - ecp.rcRectWnd = CFX_FloatRect(0, 0, 0, 0); + ecp.rcRectWnd = CFX_FloatRect(); m_pEditCaret->Create(ecp); } @@ -319,8 +298,7 @@ void CPWL_EditCtrl::SetEditCaret(bool bVisible) { if (bVisible) GetCaretInfo(&ptHead, &ptFoot); - CPVT_WordPlace wpTemp = m_pEdit->GetCaretWordPlace(); - IOnSetCaret(bVisible, ptHead, ptFoot, wpTemp); + SetCaret(bVisible, ptHead, ptFoot); } void CPWL_EditCtrl::GetCaretInfo(CFX_PointF* ptHead, CFX_PointF* ptFoot) const { @@ -387,8 +365,6 @@ void CPWL_EditCtrl::PasteText() {} void CPWL_EditCtrl::CutText() {} -void CPWL_EditCtrl::ShowVScrollBar(bool bShow) {} - void CPWL_EditCtrl::InsertWord(uint16_t word, int32_t nCharset) { if (!IsReadOnly()) m_pEdit->InsertWord(word, nCharset); @@ -427,50 +403,6 @@ void CPWL_EditCtrl::Undo() { m_pEdit->Undo(); } -void CPWL_EditCtrl::IOnSetScrollInfoY(float fPlateMin, - float fPlateMax, - float fContentMin, - float fContentMax, - float fSmallStep, - float fBigStep) { - PWL_SCROLL_INFO Info; - - Info.fPlateWidth = fPlateMax - fPlateMin; - Info.fContentMin = fContentMin; - Info.fContentMax = fContentMax; - Info.fSmallStep = fSmallStep; - Info.fBigStep = fBigStep; - - OnNotify(this, PNM_SETSCROLLINFO, SBT_VSCROLL, (intptr_t)&Info); - - if (IsFloatBigger(Info.fPlateWidth, Info.fContentMax - Info.fContentMin) || - IsFloatEqual(Info.fPlateWidth, Info.fContentMax - Info.fContentMin)) { - ShowVScrollBar(false); - } else { - ShowVScrollBar(true); - } -} - -void CPWL_EditCtrl::IOnSetScrollPosY(float fy) { - OnNotify(this, PNM_SETSCROLLPOS, SBT_VSCROLL, (intptr_t)&fy); -} - -void CPWL_EditCtrl::IOnSetCaret(bool bVisible, - const CFX_PointF& ptHead, - const CFX_PointF& ptFoot, - const CPVT_WordPlace& place) { - PWL_CARET_INFO cInfo; - cInfo.bVisible = bVisible; - cInfo.ptHead = ptHead; - cInfo.ptFoot = ptFoot; - - OnNotify(this, PNM_SETCARETINFO, (intptr_t)&cInfo, (intptr_t) nullptr); -} - -void CPWL_EditCtrl::IOnInvalidateRect(CFX_FloatRect* pRect) { - InvalidateRect(pRect); -} - int32_t CPWL_EditCtrl::GetCharSet() const { return m_nCharSet < 0 ? FX_CHARSET_Default : m_nCharSet; } diff --git a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/PWL_EditCtrl.h b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_edit_ctrl.h index 0f2487bc261..454e579622b 100644 --- a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/PWL_EditCtrl.h +++ b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_edit_ctrl.h @@ -4,31 +4,23 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef FPDFSDK_PDFWINDOW_PWL_EDITCTRL_H_ -#define FPDFSDK_PDFWINDOW_PWL_EDITCTRL_H_ +#ifndef FPDFSDK_PDFWINDOW_CPWL_EDIT_CTRL_H_ +#define FPDFSDK_PDFWINDOW_CPWL_EDIT_CTRL_H_ #include <memory> #include "core/fxcrt/fx_string.h" -#include "fpdfsdk/fxedit/fx_edit.h" -#include "fpdfsdk/pdfwindow/PWL_Wnd.h" +#include "fpdfsdk/pdfwindow/cpwl_wnd.h" class CFX_Edit; class CPWL_Caret; -class CPWL_Edit; -class CPWL_EditCtrl; -struct CPVT_SecProps; struct CPVT_WordPlace; -struct CPVT_WordProps; -struct CPVT_WordRange; enum PWL_EDIT_ALIGNFORMAT_H { PEAH_LEFT = 0, PEAH_MIDDLE, PEAH_RIGHT }; enum PWL_EDIT_ALIGNFORMAT_V { PEAV_TOP = 0, PEAV_CENTER, PEAV_BOTTOM }; class CPWL_EditCtrl : public CPWL_Wnd { - friend class CPWL_Edit_Notify; - public: CPWL_EditCtrl(); ~CPWL_EditCtrl() override; @@ -60,34 +52,24 @@ class CPWL_EditCtrl : public CPWL_Wnd { bool OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) override; bool OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) override; bool OnMouseMove(const CFX_PointF& point, uint32_t nFlag) override; - void OnNotify(CPWL_Wnd* pWnd, - uint32_t msg, - intptr_t wParam = 0, - intptr_t lParam = 0) override; + void SetScrollInfo(const PWL_SCROLL_INFO& info) override; + void SetScrollPosition(float pos) override; + void ScrollWindowVertically(float pos) override; void CreateChildWnd(const PWL_CREATEPARAM& cp) override; void RePosChildWnd() override; void SetFontSize(float fFontSize) override; float GetFontSize() const override; void SetCursor() override; + CFX_WideString GetSelectedText() override; - void IOnSetScrollInfoY(float fPlateMin, - float fPlateMax, - float fContentMin, - float fContentMax, - float fSmallStep, - float fBigStep); - void IOnSetScrollPosY(float fy); - void IOnSetCaret(bool bVisible, - const CFX_PointF& ptHead, - const CFX_PointF& ptFoot, - const CPVT_WordPlace& place); - void IOnInvalidateRect(CFX_FloatRect* pRect); + void SetCaret(bool bVisible, + const CFX_PointF& ptHead, + const CFX_PointF& ptFoot); protected: void CopyText(); void PasteText(); void CutText(); - void ShowVScrollBar(bool bShow); void InsertWord(uint16_t word, int32_t nCharset); void InsertReturn(); @@ -97,9 +79,6 @@ class CPWL_EditCtrl : public CPWL_Wnd { void Backspace(); void GetCaretInfo(CFX_PointF* ptHead, CFX_PointF* ptFoot) const; - void SetCaret(bool bVisible, - const CFX_PointF& ptHead, - const CFX_PointF& ptFoot); void SetEditCaret(bool bVisible); @@ -113,4 +92,4 @@ class CPWL_EditCtrl : public CPWL_Wnd { int32_t m_nCharSet; }; -#endif // FPDFSDK_PDFWINDOW_PWL_EDITCTRL_H_ +#endif // FPDFSDK_PDFWINDOW_CPWL_EDIT_CTRL_H_ diff --git a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_edit_embeddertest.cpp b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_edit_embeddertest.cpp new file mode 100644 index 00000000000..e206cd16e31 --- /dev/null +++ b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_edit_embeddertest.cpp @@ -0,0 +1,125 @@ +// Copyright 2017 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. + +#include "fpdfsdk/cba_annotiterator.h" +#include "fpdfsdk/cpdfsdk_annot.h" +#include "fpdfsdk/cpdfsdk_formfillenvironment.h" +#include "fpdfsdk/formfiller/cffl_formfiller.h" +#include "fpdfsdk/formfiller/cffl_interactiveformfiller.h" +#include "fpdfsdk/pdfwindow/cpwl_wnd.h" +#include "testing/embedder_test.h" +#include "testing/gtest/include/gtest/gtest.h" + +class CPWLEditEmbeddertest : public EmbedderTest { + protected: + void SetUp() override { + EmbedderTest::SetUp(); + CreateAndInitializeFormPDF(); + } + + void TearDown() override { + UnloadPage(GetPage()); + EmbedderTest::TearDown(); + } + + void CreateAndInitializeFormPDF() { + EXPECT_TRUE(OpenDocument("text_form.pdf")); + m_page = LoadPage(0); + ASSERT_TRUE(m_page); + + CPDFSDK_FormFillEnvironment* pFormFillEnv = + static_cast<CPDFSDK_FormFillEnvironment*>(form_handle()); + + { + CBA_AnnotIterator iter(pFormFillEnv->GetPageView(0), + CPDF_Annot::Subtype::WIDGET); + m_pAnnot = iter.GetFirstAnnot(); + CPDFSDK_Annot* pLastAnnot = iter.GetLastAnnot(); + ASSERT_EQ(m_pAnnot, pLastAnnot); + ASSERT_TRUE(m_pAnnot); + ASSERT_EQ(CPDF_Annot::Subtype::WIDGET, m_pAnnot->GetAnnotSubtype()); + } + + CFFL_InteractiveFormFiller* pInteractiveFormFiller = + pFormFillEnv->GetInteractiveFormFiller(); + { + CPDFSDK_Annot::ObservedPtr pObserved(m_pAnnot); + EXPECT_TRUE(pInteractiveFormFiller->OnSetFocus(&pObserved, 0)); + } + + m_pFormFiller = pInteractiveFormFiller->GetFormFiller(m_pAnnot, false); + ASSERT_TRUE(m_pFormFiller); + + CPWL_Wnd* pWindow = + m_pFormFiller->GetPDFWindow(pFormFillEnv->GetPageView(0), false); + ASSERT_TRUE(pWindow); + ASSERT_EQ(PWL_CLASSNAME_EDIT, pWindow->GetClassName()); + + m_pEdit = static_cast<CPWL_Edit*>(pWindow); + } + + FPDF_PAGE GetPage() { return m_page; } + CPWL_Edit* GetCPWLEdit() { return m_pEdit; } + CFFL_FormFiller* GetCFFLFormFiller() { return m_pFormFiller; } + CPDFSDK_Annot* GetCPDFSDKAnnot() { return m_pAnnot; } + + private: + FPDF_PAGE m_page; + CPWL_Edit* m_pEdit; + CFFL_FormFiller* m_pFormFiller; + CPDFSDK_Annot* m_pAnnot; +}; + +TEST_F(CPWLEditEmbeddertest, TypeText) { + EXPECT_TRUE(GetCPWLEdit()->GetText().IsEmpty()); + EXPECT_TRUE(GetCFFLFormFiller()->OnChar(GetCPDFSDKAnnot(), 'a', 0)); + EXPECT_TRUE(GetCFFLFormFiller()->OnChar(GetCPDFSDKAnnot(), 'b', 0)); + EXPECT_TRUE(GetCFFLFormFiller()->OnChar(GetCPDFSDKAnnot(), 'c', 0)); + + EXPECT_STREQ(L"abc", GetCPWLEdit()->GetText().c_str()); +} + +TEST_F(CPWLEditEmbeddertest, GetSelectedTextEmptyAndBasic) { + // Attempt to set selection before text has been typed to test that + // selection is identified as empty. + // + // Select from character index [0, 3) within form text field. + GetCPWLEdit()->SetSel(0, 3); + EXPECT_TRUE(GetCPWLEdit()->GetSelectedText().IsEmpty()); + + EXPECT_TRUE(GetCFFLFormFiller()->OnChar(GetCPDFSDKAnnot(), 'a', 0)); + EXPECT_TRUE(GetCFFLFormFiller()->OnChar(GetCPDFSDKAnnot(), 'b', 0)); + EXPECT_TRUE(GetCFFLFormFiller()->OnChar(GetCPDFSDKAnnot(), 'c', 0)); + GetCPWLEdit()->SetSel(0, 2); + + EXPECT_STREQ(L"ab", GetCPWLEdit()->GetSelectedText().c_str()); +} + +TEST_F(CPWLEditEmbeddertest, GetSelectedTextFragments) { + for (int i = 0; i < 50; ++i) { + EXPECT_TRUE(GetCFFLFormFiller()->OnChar(GetCPDFSDKAnnot(), i + 'A', 0)); + } + + GetCPWLEdit()->SetSel(0, 0); + EXPECT_TRUE(GetCPWLEdit()->GetSelectedText().IsEmpty()); + + GetCPWLEdit()->SetSel(0, 1); + EXPECT_STREQ(L"A", GetCPWLEdit()->GetSelectedText().c_str()); + + GetCPWLEdit()->SetSel(0, -1); + EXPECT_STREQ(L"ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqr", + GetCPWLEdit()->GetSelectedText().c_str()); + + GetCPWLEdit()->SetSel(-8, -1); + EXPECT_TRUE(GetCPWLEdit()->GetSelectedText().IsEmpty()); + + GetCPWLEdit()->SetSel(23, 12); + EXPECT_STREQ(L"MNOPQRSTUVW", GetCPWLEdit()->GetSelectedText().c_str()); + + GetCPWLEdit()->SetSel(12, 23); + EXPECT_STREQ(L"MNOPQRSTUVW", GetCPWLEdit()->GetSelectedText().c_str()); + + GetCPWLEdit()->SetSel(49, 50); + EXPECT_STREQ(L"r", GetCPWLEdit()->GetSelectedText().c_str()); +} diff --git a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/PWL_FontMap.cpp b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_font_map.cpp index c981f187050..f0c74ba0ce9 100644 --- a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/PWL_FontMap.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_font_map.cpp @@ -4,7 +4,7 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "fpdfsdk/pdfwindow/PWL_FontMap.h" +#include "fpdfsdk/pdfwindow/cpwl_font_map.h" #include <utility> @@ -15,7 +15,7 @@ #include "core/fpdfapi/parser/cpdf_parser.h" #include "core/fpdfdoc/ipvt_fontmap.h" #include "core/fxcrt/fx_codepage.h" -#include "fpdfsdk/pdfwindow/PWL_Wnd.h" +#include "fpdfsdk/pdfwindow/cpwl_wnd.h" #include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" diff --git a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/PWL_FontMap.h b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_font_map.h index ca3ab231bde..de7a9444258 100644 --- a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/PWL_FontMap.h +++ b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_font_map.h @@ -4,8 +4,8 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef FPDFSDK_PDFWINDOW_PWL_FONTMAP_H_ -#define FPDFSDK_PDFWINDOW_PWL_FONTMAP_H_ +#ifndef FPDFSDK_PDFWINDOW_CPWL_FONT_MAP_H_ +#define FPDFSDK_PDFWINDOW_CPWL_FONT_MAP_H_ #include <memory> #include <vector> @@ -93,4 +93,4 @@ class CPWL_FontMap : public IPVT_FontMap { CFX_UnownedPtr<CFX_SystemHandler> const m_pSystemHandler; }; -#endif // FPDFSDK_PDFWINDOW_PWL_FONTMAP_H_ +#endif // FPDFSDK_PDFWINDOW_CPWL_FONT_MAP_H_ diff --git a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_icon.cpp b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_icon.cpp new file mode 100644 index 00000000000..4de3e7080d9 --- /dev/null +++ b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_icon.cpp @@ -0,0 +1,131 @@ +// Copyright 2014 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 "fpdfsdk/pdfwindow/cpwl_icon.h" + +#include <algorithm> +#include <sstream> + +#include "core/fpdfapi/parser/cpdf_array.h" +#include "core/fpdfapi/parser/cpdf_stream.h" +#include "fpdfsdk/pdfwindow/cpwl_wnd.h" + +CPWL_Icon::CPWL_Icon() : m_pPDFStream(nullptr), m_pIconFit(nullptr) {} + +CPWL_Icon::~CPWL_Icon() {} + +std::pair<float, float> CPWL_Icon::GetImageSize() { + if (!m_pPDFStream) + return {0.0f, 0.0f}; + + CPDF_Dictionary* pDict = m_pPDFStream->GetDict(); + if (!pDict) + return {0.0f, 0.0f}; + + CFX_FloatRect rect = pDict->GetRectFor("BBox"); + return {rect.right - rect.left, rect.top - rect.bottom}; +} + +CFX_Matrix CPWL_Icon::GetImageMatrix() { + if (!m_pPDFStream) + return CFX_Matrix(); + if (CPDF_Dictionary* pDict = m_pPDFStream->GetDict()) + return pDict->GetMatrixFor("Matrix"); + return CFX_Matrix(); +} + +CFX_ByteString CPWL_Icon::GetImageAlias() { + if (!m_pPDFStream) + return CFX_ByteString(); + if (CPDF_Dictionary* pDict = m_pPDFStream->GetDict()) + return pDict->GetStringFor("Name"); + return CFX_ByteString(); +} + +std::pair<float, float> CPWL_Icon::GetIconPosition() { + if (!m_pIconFit) + return {0.0f, 0.0f}; + + CPDF_Array* pA = + m_pIconFit->GetDict() ? m_pIconFit->GetDict()->GetArrayFor("A") : nullptr; + if (!pA) + return {0.0f, 0.0f}; + + size_t dwCount = pA->GetCount(); + return {dwCount > 0 ? pA->GetNumberAt(0) : 0.0f, + dwCount > 1 ? pA->GetNumberAt(1) : 0.0f}; +} + +std::pair<float, float> CPWL_Icon::GetScale() { + float fHScale = 1.0f; + float fVScale = 1.0f; + + if (!m_pPDFStream) + return {fHScale, fVScale}; + + CFX_FloatRect rcPlate = GetClientRect(); + float fPlateWidth = rcPlate.right - rcPlate.left; + float fPlateHeight = rcPlate.top - rcPlate.bottom; + + float fImageWidth; + float fImageHeight; + std::tie(fImageWidth, fImageHeight) = GetImageSize(); + + int32_t nScaleMethod = m_pIconFit ? m_pIconFit->GetScaleMethod() : 0; + + switch (nScaleMethod) { + default: + case 0: + fHScale = fPlateWidth / std::max(fImageWidth, 1.0f); + fVScale = fPlateHeight / std::max(fImageHeight, 1.0f); + break; + case 1: + if (fPlateWidth < fImageWidth) + fHScale = fPlateWidth / std::max(fImageWidth, 1.0f); + if (fPlateHeight < fImageHeight) + fVScale = fPlateHeight / std::max(fImageHeight, 1.0f); + break; + case 2: + if (fPlateWidth > fImageWidth) + fHScale = fPlateWidth / std::max(fImageWidth, 1.0f); + if (fPlateHeight > fImageHeight) + fVScale = fPlateHeight / std::max(fImageHeight, 1.0f); + break; + case 3: + break; + } + + float fMinScale; + if (m_pIconFit && m_pIconFit->IsProportionalScale()) { + fMinScale = std::min(fHScale, fVScale); + fHScale = fMinScale; + fVScale = fMinScale; + } + return {fHScale, fVScale}; +} + +std::pair<float, float> CPWL_Icon::GetImageOffset() { + float fLeft; + float fBottom; + std::tie(fLeft, fBottom) = GetIconPosition(); + + float fImageWidth; + float fImageHeight; + std::tie(fImageWidth, fImageHeight) = GetImageSize(); + + float fHScale, fVScale; + std::tie(fHScale, fVScale) = GetScale(); + + float fImageFactWidth = fImageWidth * fHScale; + float fImageFactHeight = fImageHeight * fVScale; + + CFX_FloatRect rcPlate = GetClientRect(); + float fPlateWidth = rcPlate.right - rcPlate.left; + float fPlateHeight = rcPlate.top - rcPlate.bottom; + + return {(fPlateWidth - fImageFactWidth) * fLeft, + (fPlateHeight - fImageFactHeight) * fBottom}; +} diff --git a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_icon.h b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_icon.h new file mode 100644 index 00000000000..e97c540bf6e --- /dev/null +++ b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_icon.h @@ -0,0 +1,44 @@ +// Copyright 2014 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 + +#ifndef FPDFSDK_PDFWINDOW_CPWL_ICON_H_ +#define FPDFSDK_PDFWINDOW_CPWL_ICON_H_ + +#include <utility> + +#include "core/fxcrt/cfx_unowned_ptr.h" +#include "core/fxcrt/fx_string.h" +#include "fpdfsdk/pdfwindow/cpwl_wnd.h" + +class CPWL_Icon : public CPWL_Wnd { + public: + CPWL_Icon(); + ~CPWL_Icon() override; + + void SetIconFit(CPDF_IconFit* pIconFit) { m_pIconFit = pIconFit; } + void SetPDFStream(CPDF_Stream* pStream) { m_pPDFStream = pStream; } + + // horizontal scale, vertical scale + std::pair<float, float> GetScale(); + + // x, y + std::pair<float, float> GetImageOffset(); + + CFX_Matrix GetImageMatrix(); + CFX_ByteString GetImageAlias(); + + private: + // left, bottom + std::pair<float, float> GetIconPosition(); + + // width, height + std::pair<float, float> GetImageSize(); + + CFX_UnownedPtr<CPDF_Stream> m_pPDFStream; + CFX_UnownedPtr<CPDF_IconFit> m_pIconFit; +}; + +#endif // FPDFSDK_PDFWINDOW_CPWL_ICON_H_ diff --git a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/PWL_ListBox.cpp b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_list_box.cpp index b6829594262..ffa5b4780f3 100644 --- a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/PWL_ListBox.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_list_box.cpp @@ -4,15 +4,17 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "fpdfsdk/pdfwindow/PWL_ListBox.h" +#include "fpdfsdk/pdfwindow/cpwl_list_box.h" +#include <sstream> + +#include "core/fxge/cfx_renderdevice.h" #include "fpdfsdk/fxedit/fxet_edit.h" #include "fpdfsdk/fxedit/fxet_list.h" -#include "fpdfsdk/pdfwindow/PWL_Edit.h" -#include "fpdfsdk/pdfwindow/PWL_EditCtrl.h" -#include "fpdfsdk/pdfwindow/PWL_ScrollBar.h" -#include "fpdfsdk/pdfwindow/PWL_Utils.h" -#include "fpdfsdk/pdfwindow/PWL_Wnd.h" +#include "fpdfsdk/pdfwindow/cpwl_edit.h" +#include "fpdfsdk/pdfwindow/cpwl_edit_ctrl.h" +#include "fpdfsdk/pdfwindow/cpwl_scroll_bar.h" +#include "fpdfsdk/pdfwindow/cpwl_wnd.h" #include "public/fpdf_fwlevent.h" #include "third_party/base/ptr_util.h" @@ -29,14 +31,12 @@ void CPWL_List_Notify::IOnSetScrollInfoY(float fPlateMin, float fSmallStep, float fBigStep) { PWL_SCROLL_INFO Info; - Info.fPlateWidth = fPlateMax - fPlateMin; Info.fContentMin = fContentMin; Info.fContentMax = fContentMax; Info.fSmallStep = fSmallStep; Info.fBigStep = fBigStep; - - m_pList->OnNotify(m_pList, PNM_SETSCROLLINFO, SBT_VSCROLL, (intptr_t)&Info); + m_pList->SetScrollInfo(Info); if (CPWL_ScrollBar* pScroll = m_pList->GetVScrollBar()) { if (IsFloatBigger(Info.fPlateWidth, Info.fContentMax - Info.fContentMin) || @@ -55,7 +55,7 @@ void CPWL_List_Notify::IOnSetScrollInfoY(float fPlateMin, } void CPWL_List_Notify::IOnSetScrollPosY(float fy) { - m_pList->OnNotify(m_pList, PNM_SETSCROLLPOS, SBT_VSCROLL, (intptr_t)&fy); + m_pList->SetScrollPosition(fy); } void CPWL_List_Notify::IOnInvalidateRect(CFX_FloatRect* pRect) { @@ -68,8 +68,7 @@ CPWL_ListBox::CPWL_ListBox() m_bHoverSel(false), m_pFillerNotify(nullptr) {} -CPWL_ListBox::~CPWL_ListBox() { -} +CPWL_ListBox::~CPWL_ListBox() {} CFX_ByteString CPWL_ListBox::GetClassName() const { return "CPWL_ListBox"; @@ -94,57 +93,6 @@ void CPWL_ListBox::OnDestroy() { m_pListNotify.reset(); } -void CPWL_ListBox::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) { - CPWL_Wnd::GetThisAppearanceStream(sAppStream); - - CFX_ByteTextBuf sListItems; - - CFX_FloatRect rcPlate = m_pList->GetPlateRect(); - for (int32_t i = 0, sz = m_pList->GetCount(); i < sz; i++) { - CFX_FloatRect rcItem = m_pList->GetItemRect(i); - - if (rcItem.bottom > rcPlate.top || rcItem.top < rcPlate.bottom) - continue; - - CFX_PointF ptOffset(rcItem.left, (rcItem.top + rcItem.bottom) * 0.5f); - if (m_pList->IsItemSelected(i)) { - sListItems << CPWL_Utils::GetRectFillAppStream(rcItem, - PWL_DEFAULT_SELBACKCOLOR) - .AsStringC(); - CFX_ByteString sItem = - CPWL_Utils::GetEditAppStream(m_pList->GetItemEdit(i), ptOffset); - if (sItem.GetLength() > 0) { - sListItems << "BT\n" - << CPWL_Utils::GetColorAppStream(PWL_DEFAULT_SELTEXTCOLOR) - .AsStringC() - << sItem.AsStringC() << "ET\n"; - } - } else { - CFX_ByteString sItem = - CPWL_Utils::GetEditAppStream(m_pList->GetItemEdit(i), ptOffset); - if (sItem.GetLength() > 0) { - sListItems << "BT\n" - << CPWL_Utils::GetColorAppStream(GetTextColor()).AsStringC() - << sItem.AsStringC() << "ET\n"; - } - } - } - - if (sListItems.GetLength() > 0) { - CFX_ByteTextBuf sClip; - CFX_FloatRect rcClient = GetClientRect(); - - sClip << "q\n"; - sClip << rcClient.left << " " << rcClient.bottom << " " - << rcClient.right - rcClient.left << " " - << rcClient.top - rcClient.bottom << " re W n\n"; - - sClip << sListItems << "Q\n"; - - sAppStream << "/Tx BMC\n" << sClip << "EMC\n"; - } -} - void CPWL_ListBox::DrawThisAppearance(CFX_RenderDevice* pDevice, CFX_Matrix* pUser2Device) { CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device); @@ -175,8 +123,8 @@ void CPWL_ListBox::DrawThisAppearance(CFX_RenderDevice* pDevice, nullptr, pSysHandler, m_pFormFiller.Get()); pSysHandler->OutputSelectedRect(m_pFormFiller.Get(), rcItem); } else { - CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcItem, - ArgbEncode(255, 0, 51, 113)); + pDevice->DrawFillRect(pUser2Device, rcItem, + ArgbEncode(255, 0, 51, 113)); CFX_Edit::DrawEdit(pDevice, pUser2Device, m_pList->GetItemEdit(i), ArgbEncode(255, 255, 255, 255), rcList, ptOffset, nullptr, pSysHandler, m_pFormFiller.Get()); @@ -227,10 +175,7 @@ bool CPWL_ListBox::OnKeyDown(uint16_t nChar, uint32_t nFlag) { case FWL_VKEY_Delete: break; } - - bool bExit = false; - OnNotifySelChanged(true, bExit, nFlag); - + OnNotifySelectionChanged(true, nFlag); return true; } @@ -240,9 +185,7 @@ bool CPWL_ListBox::OnChar(uint16_t nChar, uint32_t nFlag) { if (!m_pList->OnChar(nChar, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag))) return false; - bool bExit = false; - OnNotifySelChanged(true, bExit, nFlag); - + OnNotifySelectionChanged(true, nFlag); return true; } @@ -267,10 +210,7 @@ bool CPWL_ListBox::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) { ReleaseCapture(); m_bMouseDown = false; } - - bool bExit = false; - OnNotifySelChanged(false, bExit, nFlag); - + OnNotifySelectionChanged(false, nFlag); return true; } @@ -289,42 +229,18 @@ bool CPWL_ListBox::OnMouseMove(const CFX_PointF& point, uint32_t nFlag) { return true; } -void CPWL_ListBox::OnNotify(CPWL_Wnd* pWnd, - uint32_t msg, - intptr_t wParam, - intptr_t lParam) { - CPWL_Wnd::OnNotify(pWnd, msg, wParam, lParam); +void CPWL_ListBox::SetScrollInfo(const PWL_SCROLL_INFO& info) { + if (CPWL_Wnd* pChild = GetVScrollBar()) + pChild->SetScrollInfo(info); +} - float fPos; +void CPWL_ListBox::SetScrollPosition(float pos) { + if (CPWL_Wnd* pChild = GetVScrollBar()) + pChild->SetScrollPosition(pos); +} - switch (msg) { - case PNM_SETSCROLLINFO: - switch (wParam) { - case SBT_VSCROLL: - if (CPWL_Wnd* pChild = GetVScrollBar()) { - pChild->OnNotify(pWnd, PNM_SETSCROLLINFO, wParam, lParam); - } - break; - } - break; - case PNM_SETSCROLLPOS: - switch (wParam) { - case SBT_VSCROLL: - if (CPWL_Wnd* pChild = GetVScrollBar()) { - pChild->OnNotify(pWnd, PNM_SETSCROLLPOS, wParam, lParam); - } - break; - } - break; - case PNM_SCROLLWINDOW: - fPos = *(float*)lParam; - switch (wParam) { - case SBT_VSCROLL: - m_pList->SetScrollPos(CFX_PointF(0, fPos)); - break; - } - break; - } +void CPWL_ListBox::ScrollWindowVertically(float pos) { + m_pList->SetScrollPos(CFX_PointF(0, pos)); } void CPWL_ListBox::KillFocus() { @@ -337,20 +253,20 @@ void CPWL_ListBox::RePosChildWnd() { m_pList->SetPlateRect(GetListRect()); } -void CPWL_ListBox::OnNotifySelChanged(bool bKeyDown, - bool& bExit, - uint32_t nFlag) { +bool CPWL_ListBox::OnNotifySelectionChanged(bool bKeyDown, uint32_t nFlag) { if (!m_pFillerNotify) - return; + return false; - bool bRC = true; CFX_WideString swChange = GetText(); CFX_WideString strChangeEx; int nSelStart = 0; int nSelEnd = swChange.GetLength(); - m_pFillerNotify->OnBeforeKeyStroke(GetAttachedData(), swChange, strChangeEx, - nSelStart, nSelEnd, bKeyDown, bRC, bExit, - nFlag); + bool bRC; + bool bExit; + std::tie(bRC, bExit) = m_pFillerNotify->OnBeforeKeyStroke( + GetAttachedData(), swChange, strChangeEx, nSelStart, nSelEnd, bKeyDown, + nFlag); + return bExit; } CFX_FloatRect CPWL_ListBox::GetFocusRect() const { @@ -441,8 +357,8 @@ float CPWL_ListBox::GetFirstHeight() const { } CFX_FloatRect CPWL_ListBox::GetListRect() const { - return CPWL_Utils::DeflateRect( - GetWindowRect(), (float)(GetBorderWidth() + GetInnerBorderWidth())); + float width = static_cast<float>(GetBorderWidth() + GetInnerBorderWidth()); + return GetWindowRect().GetDeflated(width, width); } bool CPWL_ListBox::OnMouseWheel(short zDelta, @@ -453,7 +369,6 @@ bool CPWL_ListBox::OnMouseWheel(short zDelta, else m_pList->OnVK_UP(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); - bool bExit = false; - OnNotifySelChanged(false, bExit, nFlag); + OnNotifySelectionChanged(false, nFlag); return true; } diff --git a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/PWL_ListBox.h b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_list_box.h index 0de9c911950..8bc7651ada0 100644 --- a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/PWL_ListBox.h +++ b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_list_box.h @@ -4,14 +4,14 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef FPDFSDK_PDFWINDOW_PWL_LISTBOX_H_ -#define FPDFSDK_PDFWINDOW_PWL_LISTBOX_H_ +#ifndef FPDFSDK_PDFWINDOW_CPWL_LIST_BOX_H_ +#define FPDFSDK_PDFWINDOW_CPWL_LIST_BOX_H_ #include <memory> #include "core/fxcrt/cfx_unowned_ptr.h" #include "fpdfsdk/fxedit/fx_edit.h" -#include "fpdfsdk/pdfwindow/PWL_Wnd.h" +#include "fpdfsdk/pdfwindow/cpwl_wnd.h" class CFX_ListCtrl; class CPWL_List_Notify; @@ -35,13 +35,8 @@ class CPWL_List_Notify { void IOnSetScrollPosY(float fy); void IOnInvalidateRect(CFX_FloatRect* pRect); - void IOnSetCaret(bool bVisible, - const CFX_PointF& ptHead, - const CFX_PointF& ptFoot, - const CPVT_WordPlace& place); - private: - CPWL_ListBox* m_pList; + CFX_UnownedPtr<CPWL_ListBox> m_pList; }; class CPWL_ListBox : public CPWL_Wnd { @@ -53,7 +48,6 @@ class CPWL_ListBox : public CPWL_Wnd { CFX_ByteString GetClassName() const override; void OnCreated() override; void OnDestroy() override; - void GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) override; void DrawThisAppearance(CFX_RenderDevice* pDevice, CFX_Matrix* pUser2Device) override; bool OnKeyDown(uint16_t nChar, uint32_t nFlag) override; @@ -65,10 +59,9 @@ class CPWL_ListBox : public CPWL_Wnd { const CFX_PointF& point, uint32_t nFlag) override; void KillFocus() override; - void OnNotify(CPWL_Wnd* pWnd, - uint32_t msg, - intptr_t wParam = 0, - intptr_t lParam = 0) override; + void SetScrollInfo(const PWL_SCROLL_INFO& info) override; + void SetScrollPosition(float pos) override; + void ScrollWindowVertically(float pos) override; void RePosChildWnd() override; CFX_FloatRect GetFocusRect() const override; void SetFontSize(float fFontSize) override; @@ -76,7 +69,7 @@ class CPWL_ListBox : public CPWL_Wnd { virtual CFX_WideString GetText() const; - void OnNotifySelChanged(bool bKeyDown, bool& bExit, uint32_t nFlag); + bool OnNotifySelectionChanged(bool bKeyDown, uint32_t nFlag); void AddString(const CFX_WideString& str); void SetTopVisibleIndex(int32_t nItemIndex); @@ -109,10 +102,10 @@ class CPWL_ListBox : public CPWL_Wnd { std::unique_ptr<CPWL_List_Notify> m_pListNotify; bool m_bMouseDown; bool m_bHoverSel; - IPWL_Filler_Notify* m_pFillerNotify; + CFX_UnownedPtr<IPWL_Filler_Notify> m_pFillerNotify; private: CFX_UnownedPtr<CFFL_FormFiller> m_pFormFiller; }; -#endif // FPDFSDK_PDFWINDOW_PWL_LISTBOX_H_ +#endif // FPDFSDK_PDFWINDOW_CPWL_LIST_BOX_H_ diff --git a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_scroll_bar.cpp b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_scroll_bar.cpp new file mode 100644 index 00000000000..c607ee795ed --- /dev/null +++ b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_scroll_bar.cpp @@ -0,0 +1,881 @@ +// Copyright 2014 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 "fpdfsdk/pdfwindow/cpwl_scroll_bar.h" + +#include <algorithm> +#include <sstream> +#include <vector> + +#include "core/fxge/cfx_pathdata.h" +#include "core/fxge/cfx_renderdevice.h" +#include "fpdfsdk/pdfwindow/cpwl_wnd.h" + +namespace { + +constexpr float kButtonWidth = 9.0f; +constexpr float kPosButtonMinWidth = 2.0f; +constexpr float kTriangleHalfLength = 2.0f; + +} // namespace + +#define PWL_DEFAULT_HEAVYGRAYCOLOR CFX_Color(COLORTYPE_GRAY, 0.50) + +PWL_FLOATRANGE::PWL_FLOATRANGE() { + Default(); +} + +PWL_FLOATRANGE::PWL_FLOATRANGE(float min, float max) { + Set(min, max); +} + +void PWL_FLOATRANGE::Default() { + fMin = 0; + fMax = 0; +} + +void PWL_FLOATRANGE::Set(float min, float max) { + if (min > max) { + fMin = max; + fMax = min; + } else { + fMin = min; + fMax = max; + } +} + +bool PWL_FLOATRANGE::In(float x) const { + return (IsFloatBigger(x, fMin) || IsFloatEqual(x, fMin)) && + (IsFloatSmaller(x, fMax) || IsFloatEqual(x, fMax)); +} + +float PWL_FLOATRANGE::GetWidth() const { + return fMax - fMin; +} + +PWL_SCROLL_PRIVATEDATA::PWL_SCROLL_PRIVATEDATA() { + Default(); +} + +void PWL_SCROLL_PRIVATEDATA::Default() { + ScrollRange.Default(); + fScrollPos = ScrollRange.fMin; + fClientWidth = 0; + fBigStep = 10; + fSmallStep = 1; +} + +void PWL_SCROLL_PRIVATEDATA::SetScrollRange(float min, float max) { + ScrollRange.Set(min, max); + + if (IsFloatSmaller(fScrollPos, ScrollRange.fMin)) + fScrollPos = ScrollRange.fMin; + if (IsFloatBigger(fScrollPos, ScrollRange.fMax)) + fScrollPos = ScrollRange.fMax; +} + +void PWL_SCROLL_PRIVATEDATA::SetClientWidth(float width) { + fClientWidth = width; +} + +void PWL_SCROLL_PRIVATEDATA::SetSmallStep(float step) { + fSmallStep = step; +} + +void PWL_SCROLL_PRIVATEDATA::SetBigStep(float step) { + fBigStep = step; +} + +bool PWL_SCROLL_PRIVATEDATA::SetPos(float pos) { + if (ScrollRange.In(pos)) { + fScrollPos = pos; + return true; + } + return false; +} + +void PWL_SCROLL_PRIVATEDATA::AddSmall() { + if (!SetPos(fScrollPos + fSmallStep)) + SetPos(ScrollRange.fMax); +} + +void PWL_SCROLL_PRIVATEDATA::SubSmall() { + if (!SetPos(fScrollPos - fSmallStep)) + SetPos(ScrollRange.fMin); +} + +void PWL_SCROLL_PRIVATEDATA::AddBig() { + if (!SetPos(fScrollPos + fBigStep)) + SetPos(ScrollRange.fMax); +} + +void PWL_SCROLL_PRIVATEDATA::SubBig() { + if (!SetPos(fScrollPos - fBigStep)) + SetPos(ScrollRange.fMin); +} + +CPWL_SBButton::CPWL_SBButton(PWL_SCROLLBAR_TYPE eScrollBarType, + PWL_SBBUTTON_TYPE eButtonType) { + m_eScrollBarType = eScrollBarType; + m_eSBButtonType = eButtonType; + + m_bMouseDown = false; +} + +CPWL_SBButton::~CPWL_SBButton() {} + +CFX_ByteString CPWL_SBButton::GetClassName() const { + return "CPWL_SBButton"; +} + +void CPWL_SBButton::OnCreate(PWL_CREATEPARAM& cp) { + cp.eCursorType = FXCT_ARROW; +} + +void CPWL_SBButton::DrawThisAppearance(CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device) { + if (!IsVisible()) + return; + + CFX_FloatRect rectWnd = GetWindowRect(); + if (rectWnd.IsEmpty()) + return; + + CFX_PointF ptCenter = GetCenterPoint(); + int32_t nTransparency = GetTransparency(); + + if (m_eScrollBarType == SBT_HSCROLL) { + CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device); + + CFX_PointF pt1; + CFX_PointF pt2; + CFX_PointF pt3; + if (m_eSBButtonType == PSBT_MIN) { + pt1 = CFX_PointF(ptCenter.x - kTriangleHalfLength * 0.5f, ptCenter.y); + pt2 = CFX_PointF(ptCenter.x + kTriangleHalfLength * 0.5f, + ptCenter.y + kTriangleHalfLength); + pt3 = CFX_PointF(ptCenter.x + kTriangleHalfLength * 0.5f, + ptCenter.y - kTriangleHalfLength); + } else if (m_eSBButtonType == PSBT_MAX) { + pt1 = CFX_PointF(ptCenter.x + kTriangleHalfLength * 0.5f, ptCenter.y); + pt2 = CFX_PointF(ptCenter.x - kTriangleHalfLength * 0.5f, + ptCenter.y + kTriangleHalfLength); + pt3 = CFX_PointF(ptCenter.x - kTriangleHalfLength * 0.5f, + ptCenter.y - kTriangleHalfLength); + } + + if (rectWnd.right - rectWnd.left > kTriangleHalfLength * 2 && + rectWnd.top - rectWnd.bottom > kTriangleHalfLength) { + CFX_PathData path; + path.AppendPoint(pt1, FXPT_TYPE::MoveTo, false); + path.AppendPoint(pt2, FXPT_TYPE::LineTo, false); + path.AppendPoint(pt3, FXPT_TYPE::LineTo, false); + path.AppendPoint(pt1, FXPT_TYPE::LineTo, false); + + pDevice->DrawPath(&path, pUser2Device, nullptr, + PWL_DEFAULT_BLACKCOLOR.ToFXColor(nTransparency), 0, + FXFILL_ALTERNATE); + } + return; + } + + // draw border + pDevice->DrawStrokeRect(pUser2Device, rectWnd, + ArgbEncode(nTransparency, 100, 100, 100), 0.0f); + pDevice->DrawStrokeRect(pUser2Device, rectWnd.GetDeflated(0.5f, 0.5f), + ArgbEncode(nTransparency, 255, 255, 255), 1.0f); + + if (m_eSBButtonType != PSBT_POS) { + // draw background + if (IsEnabled()) { + pDevice->DrawShadow(pUser2Device, true, false, + rectWnd.GetDeflated(1.0f, 1.0f), nTransparency, 80, + 220); + } else { + pDevice->DrawFillRect(pUser2Device, rectWnd.GetDeflated(1.0f, 1.0f), + ArgbEncode(255, 255, 255, 255)); + } + + // draw arrow + if (rectWnd.top - rectWnd.bottom > 6.0f) { + float fX = rectWnd.left + 1.5f; + float fY = rectWnd.bottom; + std::vector<CFX_PointF> pts; + if (m_eSBButtonType == PSBT_MIN) { + pts.push_back(CFX_PointF(fX + 2.5f, fY + 4.0f)); + pts.push_back(CFX_PointF(fX + 2.5f, fY + 3.0f)); + pts.push_back(CFX_PointF(fX + 4.5f, fY + 5.0f)); + pts.push_back(CFX_PointF(fX + 6.5f, fY + 3.0f)); + pts.push_back(CFX_PointF(fX + 6.5f, fY + 4.0f)); + pts.push_back(CFX_PointF(fX + 4.5f, fY + 6.0f)); + pts.push_back(CFX_PointF(fX + 2.5f, fY + 4.0f)); + } else { + pts.push_back(CFX_PointF(fX + 2.5f, fY + 5.0f)); + pts.push_back(CFX_PointF(fX + 2.5f, fY + 6.0f)); + pts.push_back(CFX_PointF(fX + 4.5f, fY + 4.0f)); + pts.push_back(CFX_PointF(fX + 6.5f, fY + 6.0f)); + pts.push_back(CFX_PointF(fX + 6.5f, fY + 5.0f)); + pts.push_back(CFX_PointF(fX + 4.5f, fY + 3.0f)); + pts.push_back(CFX_PointF(fX + 2.5f, fY + 5.0f)); + } + pDevice->DrawFillArea(pUser2Device, pts.data(), 7, + IsEnabled() + ? ArgbEncode(nTransparency, 255, 255, 255) + : PWL_DEFAULT_HEAVYGRAYCOLOR.ToFXColor(255)); + } + return; + } + + if (IsEnabled()) { + // draw shadow effect + CFX_PointF ptTop = CFX_PointF(rectWnd.left, rectWnd.top - 1.0f); + CFX_PointF ptBottom = CFX_PointF(rectWnd.left, rectWnd.bottom + 1.0f); + + ptTop.x += 1.5f; + ptBottom.x += 1.5f; + + const FX_COLORREF refs[] = {ArgbEncode(nTransparency, 210, 210, 210), + ArgbEncode(nTransparency, 220, 220, 220), + ArgbEncode(nTransparency, 240, 240, 240), + ArgbEncode(nTransparency, 240, 240, 240), + ArgbEncode(nTransparency, 210, 210, 210), + ArgbEncode(nTransparency, 180, 180, 180), + ArgbEncode(nTransparency, 150, 150, 150), + ArgbEncode(nTransparency, 150, 150, 150), + ArgbEncode(nTransparency, 180, 180, 180), + ArgbEncode(nTransparency, 210, 210, 210)}; + for (FX_COLORREF ref : refs) { + pDevice->DrawStrokeLine(pUser2Device, ptTop, ptBottom, ref, 1.0f); + + ptTop.x += 1.0f; + ptBottom.x += 1.0f; + } + } else { + pDevice->DrawFillRect(pUser2Device, rectWnd.GetDeflated(0.5f, 0.5f), + ArgbEncode(255, 255, 255, 255)); + } + + // draw friction + if (rectWnd.Height() <= 8.0f) + return; + + FX_COLORREF crStroke = ArgbEncode(nTransparency, 120, 120, 120); + if (!IsEnabled()) + crStroke = PWL_DEFAULT_HEAVYGRAYCOLOR.ToFXColor(255); + + float nFrictionWidth = 5.0f; + float nFrictionHeight = 5.5f; + + CFX_PointF ptLeft = CFX_PointF(ptCenter.x - nFrictionWidth / 2.0f, + ptCenter.y - nFrictionHeight / 2.0f + 0.5f); + CFX_PointF ptRight = CFX_PointF(ptCenter.x + nFrictionWidth / 2.0f, + ptCenter.y - nFrictionHeight / 2.0f + 0.5f); + + for (size_t i = 0; i < 3; ++i) { + pDevice->DrawStrokeLine(pUser2Device, ptLeft, ptRight, crStroke, 1.0f); + ptLeft.y += 2.0f; + ptRight.y += 2.0f; + } +} + +bool CPWL_SBButton::OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) { + CPWL_Wnd::OnLButtonDown(point, nFlag); + + if (CPWL_Wnd* pParent = GetParentWindow()) + pParent->NotifyLButtonDown(this, point); + + m_bMouseDown = true; + SetCapture(); + + return true; +} + +bool CPWL_SBButton::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) { + CPWL_Wnd::OnLButtonUp(point, nFlag); + + if (CPWL_Wnd* pParent = GetParentWindow()) + pParent->NotifyLButtonUp(this, point); + + m_bMouseDown = false; + ReleaseCapture(); + + return true; +} + +bool CPWL_SBButton::OnMouseMove(const CFX_PointF& point, uint32_t nFlag) { + CPWL_Wnd::OnMouseMove(point, nFlag); + + if (CPWL_Wnd* pParent = GetParentWindow()) + pParent->NotifyMouseMove(this, point); + + return true; +} + +CPWL_ScrollBar::CPWL_ScrollBar(PWL_SCROLLBAR_TYPE sbType) + : m_sbType(sbType), + m_pMinButton(nullptr), + m_pMaxButton(nullptr), + m_pPosButton(nullptr), + m_bMouseDown(false), + m_bMinOrMax(false), + m_bNotifyForever(true) {} + +CPWL_ScrollBar::~CPWL_ScrollBar() {} + +CFX_ByteString CPWL_ScrollBar::GetClassName() const { + return "CPWL_ScrollBar"; +} + +void CPWL_ScrollBar::OnCreate(PWL_CREATEPARAM& cp) { + cp.eCursorType = FXCT_ARROW; +} + +void CPWL_ScrollBar::OnDestroy() { + // Until cleanup takes place in the virtual destructor for CPWL_Wnd + // subclasses, implement the virtual OnDestroy method that does the + // cleanup first, then invokes the superclass OnDestroy ... gee, + // like a dtor would. + m_pMinButton.Release(); + m_pMaxButton.Release(); + m_pPosButton.Release(); + CPWL_Wnd::OnDestroy(); +} + +void CPWL_ScrollBar::RePosChildWnd() { + CFX_FloatRect rcClient = GetClientRect(); + CFX_FloatRect rcMinButton, rcMaxButton; + float fBWidth = 0; + + switch (m_sbType) { + case SBT_HSCROLL: + if (rcClient.right - rcClient.left > + kButtonWidth * 2 + kPosButtonMinWidth + 2) { + rcMinButton = CFX_FloatRect(rcClient.left, rcClient.bottom, + rcClient.left + kButtonWidth, rcClient.top); + rcMaxButton = + CFX_FloatRect(rcClient.right - kButtonWidth, rcClient.bottom, + rcClient.right, rcClient.top); + } else { + fBWidth = (rcClient.right - rcClient.left - kPosButtonMinWidth - 2) / 2; + + if (fBWidth > 0) { + rcMinButton = CFX_FloatRect(rcClient.left, rcClient.bottom, + rcClient.left + fBWidth, rcClient.top); + rcMaxButton = CFX_FloatRect(rcClient.right - fBWidth, rcClient.bottom, + rcClient.right, rcClient.top); + } else { + SetVisible(false); + } + } + break; + case SBT_VSCROLL: + if (IsFloatBigger(rcClient.top - rcClient.bottom, + kButtonWidth * 2 + kPosButtonMinWidth + 2)) { + rcMinButton = CFX_FloatRect(rcClient.left, rcClient.top - kButtonWidth, + rcClient.right, rcClient.top); + rcMaxButton = + CFX_FloatRect(rcClient.left, rcClient.bottom, rcClient.right, + rcClient.bottom + kButtonWidth); + } else { + fBWidth = (rcClient.top - rcClient.bottom - kPosButtonMinWidth - 2) / 2; + + if (IsFloatBigger(fBWidth, 0)) { + rcMinButton = CFX_FloatRect(rcClient.left, rcClient.top - fBWidth, + rcClient.right, rcClient.top); + rcMaxButton = + CFX_FloatRect(rcClient.left, rcClient.bottom, rcClient.right, + rcClient.bottom + fBWidth); + } else { + SetVisible(false); + } + } + break; + } + + if (m_pMinButton) + m_pMinButton->Move(rcMinButton, true, false); + if (m_pMaxButton) + m_pMaxButton->Move(rcMaxButton, true, false); + MovePosButton(false); +} + +void CPWL_ScrollBar::DrawThisAppearance(CFX_RenderDevice* pDevice, + CFX_Matrix* pUser2Device) { + CFX_FloatRect rectWnd = GetWindowRect(); + + if (IsVisible() && !rectWnd.IsEmpty()) { + pDevice->DrawFillRect(pUser2Device, rectWnd, GetBackgroundColor(), + GetTransparency()); + + pDevice->DrawStrokeLine( + pUser2Device, CFX_PointF(rectWnd.left + 2.0f, rectWnd.top - 2.0f), + CFX_PointF(rectWnd.left + 2.0f, rectWnd.bottom + 2.0f), + ArgbEncode(GetTransparency(), 100, 100, 100), 1.0f); + + pDevice->DrawStrokeLine( + pUser2Device, CFX_PointF(rectWnd.right - 2.0f, rectWnd.top - 2.0f), + CFX_PointF(rectWnd.right - 2.0f, rectWnd.bottom + 2.0f), + ArgbEncode(GetTransparency(), 100, 100, 100), 1.0f); + } +} + +bool CPWL_ScrollBar::OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) { + CPWL_Wnd::OnLButtonDown(point, nFlag); + + if (HasFlag(PWS_AUTOTRANSPARENT)) { + if (GetTransparency() != 255) { + SetTransparency(255); + InvalidateRect(); + } + } + + CFX_FloatRect rcMinArea, rcMaxArea; + + if (m_pPosButton && m_pPosButton->IsVisible()) { + CFX_FloatRect rcClient = GetClientRect(); + CFX_FloatRect rcPosButton = m_pPosButton->GetWindowRect(); + + switch (m_sbType) { + case SBT_HSCROLL: + rcMinArea = CFX_FloatRect(rcClient.left + kButtonWidth, rcClient.bottom, + rcPosButton.left, rcClient.top); + rcMaxArea = CFX_FloatRect(rcPosButton.right, rcClient.bottom, + rcClient.right - kButtonWidth, rcClient.top); + + break; + case SBT_VSCROLL: + rcMinArea = CFX_FloatRect(rcClient.left, rcPosButton.top, + rcClient.right, rcClient.top - kButtonWidth); + rcMaxArea = CFX_FloatRect(rcClient.left, rcClient.bottom + kButtonWidth, + rcClient.right, rcPosButton.bottom); + break; + } + + rcMinArea.Normalize(); + rcMaxArea.Normalize(); + + if (rcMinArea.Contains(point)) { + m_sData.SubBig(); + MovePosButton(true); + NotifyScrollWindow(); + } + + if (rcMaxArea.Contains(point)) { + m_sData.AddBig(); + MovePosButton(true); + NotifyScrollWindow(); + } + } + + return true; +} + +bool CPWL_ScrollBar::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) { + CPWL_Wnd::OnLButtonUp(point, nFlag); + + if (HasFlag(PWS_AUTOTRANSPARENT)) { + if (GetTransparency() != PWL_SCROLLBAR_TRANSPARENCY) { + SetTransparency(PWL_SCROLLBAR_TRANSPARENCY); + InvalidateRect(); + } + } + + EndTimer(); + m_bMouseDown = false; + + return true; +} + +void CPWL_ScrollBar::SetScrollInfo(const PWL_SCROLL_INFO& info) { + if (info == m_OriginInfo) + return; + + m_OriginInfo = info; + float fMax = + std::max(0.0f, info.fContentMax - info.fContentMin - info.fPlateWidth); + SetScrollRange(0, fMax, info.fPlateWidth); + SetScrollStep(info.fBigStep, info.fSmallStep); +} + +void CPWL_ScrollBar::SetScrollPosition(float pos) { + switch (m_sbType) { + case SBT_HSCROLL: + pos = pos - m_OriginInfo.fContentMin; + break; + case SBT_VSCROLL: + pos = m_OriginInfo.fContentMax - pos; + break; + } + SetScrollPos(pos); +} + +void CPWL_ScrollBar::NotifyLButtonDown(CPWL_Wnd* child, const CFX_PointF& pos) { + if (child == m_pMinButton) + OnMinButtonLBDown(pos); + else if (child == m_pMaxButton) + OnMaxButtonLBDown(pos); + else if (child == m_pPosButton) + OnPosButtonLBDown(pos); +} + +void CPWL_ScrollBar::NotifyLButtonUp(CPWL_Wnd* child, const CFX_PointF& pos) { + if (child == m_pMinButton) + OnMinButtonLBUp(pos); + else if (child == m_pMaxButton) + OnMaxButtonLBUp(pos); + else if (child == m_pPosButton) + OnPosButtonLBUp(pos); +} + +void CPWL_ScrollBar::NotifyMouseMove(CPWL_Wnd* child, const CFX_PointF& pos) { + if (child == m_pMinButton) + OnMinButtonMouseMove(pos); + else if (child == m_pMaxButton) + OnMaxButtonMouseMove(pos); + else if (child == m_pPosButton) + OnPosButtonMouseMove(pos); +} + +void CPWL_ScrollBar::CreateButtons(const PWL_CREATEPARAM& cp) { + PWL_CREATEPARAM scp = cp; + scp.pParentWnd = this; + scp.dwBorderWidth = 2; + scp.nBorderStyle = BorderStyle::BEVELED; + + scp.dwFlags = + PWS_VISIBLE | PWS_CHILD | PWS_BORDER | PWS_BACKGROUND | PWS_NOREFRESHCLIP; + + if (!m_pMinButton) { + m_pMinButton = new CPWL_SBButton(m_sbType, PSBT_MIN); + m_pMinButton->Create(scp); + } + + if (!m_pMaxButton) { + m_pMaxButton = new CPWL_SBButton(m_sbType, PSBT_MAX); + m_pMaxButton->Create(scp); + } + + if (!m_pPosButton) { + m_pPosButton = new CPWL_SBButton(m_sbType, PSBT_POS); + m_pPosButton->SetVisible(false); + m_pPosButton->Create(scp); + } +} + +float CPWL_ScrollBar::GetScrollBarWidth() const { + if (!IsVisible()) + return 0; + + return PWL_SCROLLBAR_WIDTH; +} + +void CPWL_ScrollBar::SetScrollRange(float fMin, + float fMax, + float fClientWidth) { + if (m_pPosButton) { + m_sData.SetScrollRange(fMin, fMax); + m_sData.SetClientWidth(fClientWidth); + + if (IsFloatSmaller(m_sData.ScrollRange.GetWidth(), 0.0f)) { + m_pPosButton->SetVisible(false); + } else { + m_pPosButton->SetVisible(true); + MovePosButton(true); + } + } +} + +void CPWL_ScrollBar::SetScrollPos(float fPos) { + float fOldPos = m_sData.fScrollPos; + m_sData.SetPos(fPos); + if (!IsFloatEqual(m_sData.fScrollPos, fOldPos)) + MovePosButton(true); +} + +void CPWL_ScrollBar::SetScrollStep(float fBigStep, float fSmallStep) { + m_sData.SetBigStep(fBigStep); + m_sData.SetSmallStep(fSmallStep); +} + +void CPWL_ScrollBar::MovePosButton(bool bRefresh) { + ASSERT(m_pMinButton); + ASSERT(m_pMaxButton); + + if (m_pPosButton->IsVisible()) { + CFX_FloatRect rcClient; + CFX_FloatRect rcPosArea, rcPosButton; + + rcClient = GetClientRect(); + rcPosArea = GetScrollArea(); + + float fLeft, fRight, fTop, fBottom; + + switch (m_sbType) { + case SBT_HSCROLL: + fLeft = TrueToFace(m_sData.fScrollPos); + fRight = TrueToFace(m_sData.fScrollPos + m_sData.fClientWidth); + + if (fRight - fLeft < kPosButtonMinWidth) + fRight = fLeft + kPosButtonMinWidth; + + if (fRight > rcPosArea.right) { + fRight = rcPosArea.right; + fLeft = fRight - kPosButtonMinWidth; + } + + rcPosButton = + CFX_FloatRect(fLeft, rcPosArea.bottom, fRight, rcPosArea.top); + + break; + case SBT_VSCROLL: + fBottom = TrueToFace(m_sData.fScrollPos + m_sData.fClientWidth); + fTop = TrueToFace(m_sData.fScrollPos); + + if (IsFloatSmaller(fTop - fBottom, kPosButtonMinWidth)) + fBottom = fTop - kPosButtonMinWidth; + + if (IsFloatSmaller(fBottom, rcPosArea.bottom)) { + fBottom = rcPosArea.bottom; + fTop = fBottom + kPosButtonMinWidth; + } + + rcPosButton = + CFX_FloatRect(rcPosArea.left, fBottom, rcPosArea.right, fTop); + + break; + } + + m_pPosButton->Move(rcPosButton, true, bRefresh); + } +} + +void CPWL_ScrollBar::OnMinButtonLBDown(const CFX_PointF& point) { + m_sData.SubSmall(); + MovePosButton(true); + NotifyScrollWindow(); + + m_bMinOrMax = true; + + EndTimer(); + BeginTimer(100); +} + +void CPWL_ScrollBar::OnMinButtonLBUp(const CFX_PointF& point) {} + +void CPWL_ScrollBar::OnMinButtonMouseMove(const CFX_PointF& point) {} + +void CPWL_ScrollBar::OnMaxButtonLBDown(const CFX_PointF& point) { + m_sData.AddSmall(); + MovePosButton(true); + NotifyScrollWindow(); + + m_bMinOrMax = false; + + EndTimer(); + BeginTimer(100); +} + +void CPWL_ScrollBar::OnMaxButtonLBUp(const CFX_PointF& point) {} + +void CPWL_ScrollBar::OnMaxButtonMouseMove(const CFX_PointF& point) {} + +void CPWL_ScrollBar::OnPosButtonLBDown(const CFX_PointF& point) { + m_bMouseDown = true; + + if (m_pPosButton) { + CFX_FloatRect rcPosButton = m_pPosButton->GetWindowRect(); + + switch (m_sbType) { + case SBT_HSCROLL: + m_nOldPos = point.x; + m_fOldPosButton = rcPosButton.left; + break; + case SBT_VSCROLL: + m_nOldPos = point.y; + m_fOldPosButton = rcPosButton.top; + break; + } + } +} + +void CPWL_ScrollBar::OnPosButtonLBUp(const CFX_PointF& point) { + if (m_bMouseDown) { + if (!m_bNotifyForever) + NotifyScrollWindow(); + } + m_bMouseDown = false; +} + +void CPWL_ScrollBar::OnPosButtonMouseMove(const CFX_PointF& point) { + float fOldScrollPos = m_sData.fScrollPos; + + float fNewPos = 0; + + switch (m_sbType) { + case SBT_HSCROLL: + if (fabs(point.x - m_nOldPos) < 1) + return; + fNewPos = FaceToTrue(m_fOldPosButton + point.x - m_nOldPos); + break; + case SBT_VSCROLL: + if (fabs(point.y - m_nOldPos) < 1) + return; + fNewPos = FaceToTrue(m_fOldPosButton + point.y - m_nOldPos); + break; + } + + if (m_bMouseDown) { + switch (m_sbType) { + case SBT_HSCROLL: + + if (IsFloatSmaller(fNewPos, m_sData.ScrollRange.fMin)) { + fNewPos = m_sData.ScrollRange.fMin; + } + + if (IsFloatBigger(fNewPos, m_sData.ScrollRange.fMax)) { + fNewPos = m_sData.ScrollRange.fMax; + } + + m_sData.SetPos(fNewPos); + + break; + case SBT_VSCROLL: + + if (IsFloatSmaller(fNewPos, m_sData.ScrollRange.fMin)) { + fNewPos = m_sData.ScrollRange.fMin; + } + + if (IsFloatBigger(fNewPos, m_sData.ScrollRange.fMax)) { + fNewPos = m_sData.ScrollRange.fMax; + } + + m_sData.SetPos(fNewPos); + + break; + } + + if (!IsFloatEqual(fOldScrollPos, m_sData.fScrollPos)) { + MovePosButton(true); + + if (m_bNotifyForever) + NotifyScrollWindow(); + } + } +} + +void CPWL_ScrollBar::NotifyScrollWindow() { + CPWL_Wnd* pParent = GetParentWindow(); + if (!pParent || m_sbType != SBT_VSCROLL) + return; + + pParent->ScrollWindowVertically(m_OriginInfo.fContentMax - + m_sData.fScrollPos); +} + +CFX_FloatRect CPWL_ScrollBar::GetScrollArea() const { + CFX_FloatRect rcClient = GetClientRect(); + CFX_FloatRect rcArea; + + if (!m_pMinButton || !m_pMaxButton) + return rcClient; + + CFX_FloatRect rcMin = m_pMinButton->GetWindowRect(); + CFX_FloatRect rcMax = m_pMaxButton->GetWindowRect(); + + float fMinWidth = rcMin.right - rcMin.left; + float fMinHeight = rcMin.top - rcMin.bottom; + float fMaxWidth = rcMax.right - rcMax.left; + float fMaxHeight = rcMax.top - rcMax.bottom; + + switch (m_sbType) { + case SBT_HSCROLL: + if (rcClient.right - rcClient.left > fMinWidth + fMaxWidth + 2) { + rcArea = CFX_FloatRect(rcClient.left + fMinWidth + 1, rcClient.bottom, + rcClient.right - fMaxWidth - 1, rcClient.top); + } else { + rcArea = CFX_FloatRect(rcClient.left + fMinWidth + 1, rcClient.bottom, + rcClient.left + fMinWidth + 1, rcClient.top); + } + break; + case SBT_VSCROLL: + if (rcClient.top - rcClient.bottom > fMinHeight + fMaxHeight + 2) { + rcArea = CFX_FloatRect(rcClient.left, rcClient.bottom + fMinHeight + 1, + rcClient.right, rcClient.top - fMaxHeight - 1); + } else { + rcArea = + CFX_FloatRect(rcClient.left, rcClient.bottom + fMinHeight + 1, + rcClient.right, rcClient.bottom + fMinHeight + 1); + } + break; + } + + rcArea.Normalize(); + + return rcArea; +} + +float CPWL_ScrollBar::TrueToFace(float fTrue) { + CFX_FloatRect rcPosArea; + rcPosArea = GetScrollArea(); + + float fFactWidth = m_sData.ScrollRange.GetWidth() + m_sData.fClientWidth; + fFactWidth = fFactWidth == 0 ? 1 : fFactWidth; + + float fFace = 0; + + switch (m_sbType) { + case SBT_HSCROLL: + fFace = rcPosArea.left + + fTrue * (rcPosArea.right - rcPosArea.left) / fFactWidth; + break; + case SBT_VSCROLL: + fFace = rcPosArea.top - + fTrue * (rcPosArea.top - rcPosArea.bottom) / fFactWidth; + break; + } + + return fFace; +} + +float CPWL_ScrollBar::FaceToTrue(float fFace) { + CFX_FloatRect rcPosArea; + rcPosArea = GetScrollArea(); + + float fFactWidth = m_sData.ScrollRange.GetWidth() + m_sData.fClientWidth; + fFactWidth = fFactWidth == 0 ? 1 : fFactWidth; + + float fTrue = 0; + + switch (m_sbType) { + case SBT_HSCROLL: + fTrue = (fFace - rcPosArea.left) * fFactWidth / + (rcPosArea.right - rcPosArea.left); + break; + case SBT_VSCROLL: + fTrue = (rcPosArea.top - fFace) * fFactWidth / + (rcPosArea.top - rcPosArea.bottom); + break; + } + + return fTrue; +} + +void CPWL_ScrollBar::CreateChildWnd(const PWL_CREATEPARAM& cp) { + CreateButtons(cp); +} + +void CPWL_ScrollBar::TimerProc() { + PWL_SCROLL_PRIVATEDATA sTemp = m_sData; + if (m_bMinOrMax) + m_sData.SubSmall(); + else + m_sData.AddSmall(); + + if (sTemp != m_sData) { + MovePosButton(true); + NotifyScrollWindow(); + } +} diff --git a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/PWL_ScrollBar.h b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_scroll_bar.h index 50b0801ca36..f9887e5610f 100644 --- a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/PWL_ScrollBar.h +++ b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_scroll_bar.h @@ -4,10 +4,11 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef FPDFSDK_PDFWINDOW_PWL_SCROLLBAR_H_ -#define FPDFSDK_PDFWINDOW_PWL_SCROLLBAR_H_ +#ifndef FPDFSDK_PDFWINDOW_CPWL_SCROLL_BAR_H_ +#define FPDFSDK_PDFWINDOW_CPWL_SCROLL_BAR_H_ -#include "fpdfsdk/pdfwindow/PWL_Wnd.h" +#include "core/fxcrt/cfx_unowned_ptr.h" +#include "fpdfsdk/pdfwindow/cpwl_wnd.h" class CPWL_SBButton; class CPWL_ScrollBar; @@ -50,7 +51,6 @@ class CPWL_SBButton : public CPWL_Wnd { // CPWL_Wnd CFX_ByteString GetClassName() const override; void OnCreate(PWL_CREATEPARAM& cp) override; - void GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) override; void DrawThisAppearance(CFX_RenderDevice* pDevice, CFX_Matrix* pUser2Device) override; bool OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) override; @@ -123,16 +123,17 @@ class CPWL_ScrollBar : public CPWL_Wnd { // CPWL_Wnd CFX_ByteString GetClassName() const override; void OnCreate(PWL_CREATEPARAM& cp) override; + void OnDestroy() override; void RePosChildWnd() override; - void GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) override; void DrawThisAppearance(CFX_RenderDevice* pDevice, CFX_Matrix* pUser2Device) override; bool OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) override; bool OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) override; - void OnNotify(CPWL_Wnd* pWnd, - uint32_t msg, - intptr_t wParam = 0, - intptr_t lParam = 0) override; + void SetScrollInfo(const PWL_SCROLL_INFO& info) override; + void SetScrollPosition(float pos) override; + void NotifyLButtonDown(CPWL_Wnd* child, const CFX_PointF& pos) override; + void NotifyLButtonUp(CPWL_Wnd* child, const CFX_PointF& pos) override; + void NotifyMouseMove(CPWL_Wnd* child, const CFX_PointF& pos) override; void CreateChildWnd(const PWL_CREATEPARAM& cp) override; void TimerProc() override; @@ -169,9 +170,9 @@ class CPWL_ScrollBar : public CPWL_Wnd { PWL_SCROLLBAR_TYPE m_sbType; PWL_SCROLL_INFO m_OriginInfo; - CPWL_SBButton* m_pMinButton; - CPWL_SBButton* m_pMaxButton; - CPWL_SBButton* m_pPosButton; + CFX_UnownedPtr<CPWL_SBButton> m_pMinButton; + CFX_UnownedPtr<CPWL_SBButton> m_pMaxButton; + CFX_UnownedPtr<CPWL_SBButton> m_pPosButton; PWL_SCROLL_PRIVATEDATA m_sData; bool m_bMouseDown; bool m_bMinOrMax; @@ -180,4 +181,4 @@ class CPWL_ScrollBar : public CPWL_Wnd { float m_fOldPosButton; }; -#endif // FPDFSDK_PDFWINDOW_PWL_SCROLLBAR_H_ +#endif // FPDFSDK_PDFWINDOW_CPWL_SCROLL_BAR_H_ diff --git a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/PWL_SpecialButton.cpp b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_special_button.cpp index d2a13219d2b..b911d5eb00f 100644 --- a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/PWL_SpecialButton.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_special_button.cpp @@ -4,10 +4,9 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "fpdfsdk/pdfwindow/PWL_Button.h" -#include "fpdfsdk/pdfwindow/PWL_SpecialButton.h" -#include "fpdfsdk/pdfwindow/PWL_Utils.h" -#include "fpdfsdk/pdfwindow/PWL_Wnd.h" +#include "fpdfsdk/pdfwindow/cpwl_special_button.h" +#include "fpdfsdk/pdfwindow/cpwl_button.h" +#include "fpdfsdk/pdfwindow/cpwl_wnd.h" CPWL_PushButton::CPWL_PushButton() {} @@ -18,7 +17,8 @@ CFX_ByteString CPWL_PushButton::GetClassName() const { } CFX_FloatRect CPWL_PushButton::GetFocusRect() const { - return CPWL_Utils::DeflateRect(GetWindowRect(), (float)GetBorderWidth()); + return GetWindowRect().GetDeflated(static_cast<float>(GetBorderWidth()), + static_cast<float>(GetBorderWidth())); } CPWL_CheckBox::CPWL_CheckBox() : m_bChecked(false) {} diff --git a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/PWL_SpecialButton.h b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_special_button.h index 93f611b7446..ed80d316393 100644 --- a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/PWL_SpecialButton.h +++ b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_special_button.h @@ -4,10 +4,10 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef FPDFSDK_PDFWINDOW_PWL_SPECIALBUTTON_H_ -#define FPDFSDK_PDFWINDOW_PWL_SPECIALBUTTON_H_ +#ifndef FPDFSDK_PDFWINDOW_CPWL_SPECIAL_BUTTON_H_ +#define FPDFSDK_PDFWINDOW_CPWL_SPECIAL_BUTTON_H_ -#include "fpdfsdk/pdfwindow/PWL_Button.h" +#include "fpdfsdk/pdfwindow/cpwl_button.h" class CPWL_PushButton : public CPWL_Button { public: @@ -53,4 +53,4 @@ class CPWL_RadioButton : public CPWL_Button { bool m_bChecked; }; -#endif // FPDFSDK_PDFWINDOW_PWL_SPECIALBUTTON_H_ +#endif // FPDFSDK_PDFWINDOW_CPWL_SPECIAL_BUTTON_H_ diff --git a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_timer.cpp b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_timer.cpp new file mode 100644 index 00000000000..03b183821f3 --- /dev/null +++ b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_timer.cpp @@ -0,0 +1,62 @@ +// Copyright 2017 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 "fpdfsdk/pdfwindow/cpwl_timer.h" + +#include <map> + +#include "fpdfsdk/cfx_systemhandler.h" +#include "fpdfsdk/pdfwindow/cpwl_timer_handler.h" + +namespace { + +std::map<int32_t, CPWL_Timer*>& GetPWLTimeMap() { + // Leak the object at shutdown. + static auto* timeMap = new std::map<int32_t, CPWL_Timer*>; + return *timeMap; +} + +} // namespace + +CPWL_Timer::CPWL_Timer(CPWL_TimerHandler* pAttached, + CFX_SystemHandler* pSystemHandler) + : m_nTimerID(0), m_pAttached(pAttached), m_pSystemHandler(pSystemHandler) { + ASSERT(m_pAttached); + ASSERT(m_pSystemHandler); +} + +CPWL_Timer::~CPWL_Timer() { + KillPWLTimer(); +} + +int32_t CPWL_Timer::SetPWLTimer(int32_t nElapse) { + if (m_nTimerID != 0) + KillPWLTimer(); + m_nTimerID = m_pSystemHandler->SetTimer(nElapse, TimerProc); + + GetPWLTimeMap()[m_nTimerID] = this; + return m_nTimerID; +} + +void CPWL_Timer::KillPWLTimer() { + if (m_nTimerID == 0) + return; + + m_pSystemHandler->KillTimer(m_nTimerID); + GetPWLTimeMap().erase(m_nTimerID); + m_nTimerID = 0; +} + +// static +void CPWL_Timer::TimerProc(int32_t idEvent) { + auto it = GetPWLTimeMap().find(idEvent); + if (it == GetPWLTimeMap().end()) + return; + + CPWL_Timer* pTimer = it->second; + if (pTimer->m_pAttached) + pTimer->m_pAttached->TimerProc(); +} diff --git a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_timer.h b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_timer.h new file mode 100644 index 00000000000..32a68fcbc21 --- /dev/null +++ b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_timer.h @@ -0,0 +1,32 @@ +// Copyright 2017 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 + +#ifndef FPDFSDK_PDFWINDOW_CPWL_TIMER_H_ +#define FPDFSDK_PDFWINDOW_CPWL_TIMER_H_ + +#include "core/fxcrt/cfx_unowned_ptr.h" +#include "core/fxcrt/fx_basic.h" + +class CFX_SystemHandler; +class CPWL_TimerHandler; + +class CPWL_Timer { + public: + CPWL_Timer(CPWL_TimerHandler* pAttached, CFX_SystemHandler* pSystemHandler); + virtual ~CPWL_Timer(); + + static void TimerProc(int32_t idEvent); + + int32_t SetPWLTimer(int32_t nElapse); + void KillPWLTimer(); + + private: + int32_t m_nTimerID; + CFX_UnownedPtr<CPWL_TimerHandler> m_pAttached; + CFX_UnownedPtr<CFX_SystemHandler> m_pSystemHandler; +}; + +#endif // FPDFSDK_PDFWINDOW_CPWL_TIMER_H_ diff --git a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_timer_handler.cpp b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_timer_handler.cpp new file mode 100644 index 00000000000..3edaa8d4622 --- /dev/null +++ b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_timer_handler.cpp @@ -0,0 +1,27 @@ +// Copyright 2017 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 "fpdfsdk/pdfwindow/cpwl_timer_handler.h" + +#include "fpdfsdk/pdfwindow/cpwl_timer.h" +#include "third_party/base/ptr_util.h" + +CPWL_TimerHandler::CPWL_TimerHandler() {} + +CPWL_TimerHandler::~CPWL_TimerHandler() {} + +void CPWL_TimerHandler::BeginTimer(int32_t nElapse) { + if (!m_pTimer) + m_pTimer = pdfium::MakeUnique<CPWL_Timer>(this, GetSystemHandler()); + m_pTimer->SetPWLTimer(nElapse); +} + +void CPWL_TimerHandler::EndTimer() { + if (m_pTimer) + m_pTimer->KillPWLTimer(); +} + +void CPWL_TimerHandler::TimerProc() {} diff --git a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_timer_handler.h b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_timer_handler.h new file mode 100644 index 00000000000..f6ffd44996c --- /dev/null +++ b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_timer_handler.h @@ -0,0 +1,32 @@ +// Copyright 2017 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 + +#ifndef FPDFSDK_PDFWINDOW_CPWL_TIMER_HANDLER_H_ +#define FPDFSDK_PDFWINDOW_CPWL_TIMER_HANDLER_H_ + +#include <memory> + +#include "core/fxcrt/fx_basic.h" + +class CFX_SystemHandler; +class CPWL_Timer; + +class CPWL_TimerHandler { + public: + CPWL_TimerHandler(); + virtual ~CPWL_TimerHandler(); + + virtual void TimerProc(); + virtual CFX_SystemHandler* GetSystemHandler() const = 0; + + void BeginTimer(int32_t nElapse); + void EndTimer(); + + private: + std::unique_ptr<CPWL_Timer> m_pTimer; +}; + +#endif // FPDFSDK_PDFWINDOW_CPWL_TIMER_HANDLER_H_ diff --git a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/PWL_Wnd.cpp b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_wnd.cpp index 5523c59317e..ce5f4ee598d 100644 --- a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/PWL_Wnd.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_wnd.cpp @@ -4,20 +4,23 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com +#include "fpdfsdk/pdfwindow/cpwl_wnd.h" + #include <map> +#include <sstream> #include <vector> -#include "fpdfsdk/pdfwindow/PWL_ScrollBar.h" -#include "fpdfsdk/pdfwindow/PWL_Utils.h" -#include "fpdfsdk/pdfwindow/PWL_Wnd.h" +#include "core/fxge/cfx_renderdevice.h" +#include "fpdfsdk/pdfwindow/cpwl_scroll_bar.h" #include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" -static std::map<int32_t, CPWL_Timer*>& GetPWLTimeMap() { - // Leak the object at shutdown. - static auto* timeMap = new std::map<int32_t, CPWL_Timer*>; - return *timeMap; -} +namespace { + +constexpr float kDefaultFontSize = 9.0f; +constexpr int kInvalidationInflate = 2; + +} // namespace PWL_CREATEPARAM::PWL_CREATEPARAM() : rcRectWnd(0, 0, 0, 0), @@ -33,73 +36,15 @@ PWL_CREATEPARAM::PWL_CREATEPARAM() sBorderColor(), sTextColor(), nTransparency(255), - fFontSize(PWL_DEFAULT_FONTSIZE), + fFontSize(kDefaultFontSize), sDash(3, 0, 0), pAttachedData(nullptr), pParentWnd(nullptr), pMsgControl(nullptr), - eCursorType(FXCT_ARROW), - mtChild(1, 0, 0, 1, 0, 0) {} + eCursorType(FXCT_ARROW) {} PWL_CREATEPARAM::PWL_CREATEPARAM(const PWL_CREATEPARAM& other) = default; -CPWL_Timer::CPWL_Timer(CPWL_TimerHandler* pAttached, - CFX_SystemHandler* pSystemHandler) - : m_nTimerID(0), m_pAttached(pAttached), m_pSystemHandler(pSystemHandler) { - ASSERT(m_pAttached); - ASSERT(m_pSystemHandler); -} - -CPWL_Timer::~CPWL_Timer() { - KillPWLTimer(); -} - -int32_t CPWL_Timer::SetPWLTimer(int32_t nElapse) { - if (m_nTimerID != 0) - KillPWLTimer(); - m_nTimerID = m_pSystemHandler->SetTimer(nElapse, TimerProc); - - GetPWLTimeMap()[m_nTimerID] = this; - return m_nTimerID; -} - -void CPWL_Timer::KillPWLTimer() { - if (m_nTimerID == 0) - return; - - m_pSystemHandler->KillTimer(m_nTimerID); - GetPWLTimeMap().erase(m_nTimerID); - m_nTimerID = 0; -} - -void CPWL_Timer::TimerProc(int32_t idEvent) { - auto it = GetPWLTimeMap().find(idEvent); - if (it == GetPWLTimeMap().end()) - return; - - CPWL_Timer* pTimer = it->second; - if (pTimer->m_pAttached) - pTimer->m_pAttached->TimerProc(); -} - -CPWL_TimerHandler::CPWL_TimerHandler() {} - -CPWL_TimerHandler::~CPWL_TimerHandler() {} - -void CPWL_TimerHandler::BeginTimer(int32_t nElapse) { - if (!m_pTimer) - m_pTimer = pdfium::MakeUnique<CPWL_Timer>(this, GetSystemHandler()); - - m_pTimer->SetPWLTimer(nElapse); -} - -void CPWL_TimerHandler::EndTimer() { - if (m_pTimer) - m_pTimer->KillPWLTimer(); -} - -void CPWL_TimerHandler::TimerProc() {} - class CPWL_MsgControl { friend class CPWL_Wnd; @@ -180,14 +125,13 @@ class CPWL_MsgControl { private: std::vector<CPWL_Wnd*> m_aMousePath; std::vector<CPWL_Wnd*> m_aKeyboardPath; - CPWL_Wnd* m_pCreatedWnd; - CPWL_Wnd* m_pMainMouseWnd; - CPWL_Wnd* m_pMainKeyboardWnd; + CFX_UnownedPtr<CPWL_Wnd> m_pCreatedWnd; + CFX_UnownedPtr<CPWL_Wnd> m_pMainMouseWnd; + CFX_UnownedPtr<CPWL_Wnd> m_pMainKeyboardWnd; }; CPWL_Wnd::CPWL_Wnd() - : m_pVScrollBar(nullptr), - m_rcWindow(), + : m_rcWindow(), m_rcClip(), m_bCreated(false), m_bVisible(false), @@ -203,35 +147,35 @@ CFX_ByteString CPWL_Wnd::GetClassName() const { } void CPWL_Wnd::Create(const PWL_CREATEPARAM& cp) { - if (!IsValid()) { - m_sPrivateParam = cp; - - OnCreate(m_sPrivateParam); - - m_sPrivateParam.rcRectWnd.Normalize(); - m_rcWindow = m_sPrivateParam.rcRectWnd; - m_rcClip = CPWL_Utils::InflateRect(m_rcWindow, 1.0f); + if (IsValid()) + return; - CreateMsgControl(); + m_sPrivateParam = cp; + OnCreate(m_sPrivateParam); - if (m_sPrivateParam.pParentWnd) - m_sPrivateParam.pParentWnd->OnNotify(this, PNM_ADDCHILD); - - PWL_CREATEPARAM ccp = m_sPrivateParam; + m_sPrivateParam.rcRectWnd.Normalize(); + m_rcWindow = m_sPrivateParam.rcRectWnd; + m_rcClip = m_rcWindow; + if (!m_rcClip.IsEmpty()) { + m_rcClip.Inflate(1.0f, 1.0f); + m_rcClip.Normalize(); + } + CreateMsgControl(); - ccp.dwFlags &= 0xFFFF0000L; // remove sub styles - ccp.mtChild = CFX_Matrix(1, 0, 0, 1, 0, 0); + if (m_sPrivateParam.pParentWnd) + m_sPrivateParam.pParentWnd->AddChild(this); - CreateScrollBar(ccp); - CreateChildWnd(ccp); + PWL_CREATEPARAM ccp = m_sPrivateParam; - m_bVisible = HasFlag(PWS_VISIBLE); + ccp.dwFlags &= 0xFFFF0000L; // remove sub styles + CreateScrollBar(ccp); + CreateChildWnd(ccp); - OnCreated(); + m_bVisible = HasFlag(PWS_VISIBLE); + OnCreated(); - RePosChildWnd(); - m_bCreated = true; - } + RePosChildWnd(); + m_bCreated = true; } void CPWL_Wnd::OnCreate(PWL_CREATEPARAM& cp) {} @@ -254,6 +198,7 @@ void CPWL_Wnd::Destroy() { KillFocus(); OnDestroy(); if (m_bCreated) { + m_pVScrollBar = nullptr; for (auto it = m_Children.rbegin(); it != m_Children.rend(); ++it) { if (CPWL_Wnd* pChild = *it) { *it = nullptr; @@ -262,35 +207,33 @@ void CPWL_Wnd::Destroy() { } } if (m_sPrivateParam.pParentWnd) - m_sPrivateParam.pParentWnd->OnNotify(this, PNM_REMOVECHILD); + m_sPrivateParam.pParentWnd->RemoveChild(this); m_bCreated = false; } DestroyMsgControl(); m_sPrivateParam.Reset(); m_Children.clear(); - m_pVScrollBar = nullptr; } void CPWL_Wnd::Move(const CFX_FloatRect& rcNew, bool bReset, bool bRefresh) { - if (IsValid()) { - CFX_FloatRect rcOld = GetWindowRect(); + if (!IsValid()) + return; - m_rcWindow = rcNew; - m_rcWindow.Normalize(); + CFX_FloatRect rcOld = GetWindowRect(); + m_rcWindow = rcNew; + m_rcWindow.Normalize(); + if (bReset) { if (rcOld.left != rcNew.left || rcOld.right != rcNew.right || rcOld.top != rcNew.top || rcOld.bottom != rcNew.bottom) { - if (bReset) { - RePosChildWnd(); - } - } - if (bRefresh) { - InvalidateRectMove(rcOld, rcNew); + RePosChildWnd(); } - - m_sPrivateParam.rcRectWnd = m_rcWindow; } + if (bRefresh) + InvalidateRectMove(rcOld, rcNew); + + m_sPrivateParam.rcRectWnd = m_rcWindow; } void CPWL_Wnd::InvalidateRectMove(const CFX_FloatRect& rcOld, @@ -301,41 +244,6 @@ void CPWL_Wnd::InvalidateRectMove(const CFX_FloatRect& rcOld, InvalidateRect(&rcUnion); } -void CPWL_Wnd::GetAppearanceStream(CFX_ByteTextBuf& sAppStream) { - if (IsValid() && IsVisible()) { - GetThisAppearanceStream(sAppStream); - GetChildAppearanceStream(sAppStream); - } -} - -// if don't set,Get default apperance stream -void CPWL_Wnd::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) { - CFX_FloatRect rectWnd = GetWindowRect(); - if (!rectWnd.IsEmpty()) { - CFX_ByteTextBuf sThis; - - if (HasFlag(PWS_BACKGROUND)) - sThis << CPWL_Utils::GetRectFillAppStream(rectWnd, GetBackgroundColor()); - - if (HasFlag(PWS_BORDER)) { - sThis << CPWL_Utils::GetBorderAppStream( - rectWnd, (float)GetBorderWidth(), GetBorderColor(), - GetBorderLeftTopColor(GetBorderStyle()), - GetBorderRightBottomColor(GetBorderStyle()), GetBorderStyle(), - GetBorderDash()); - } - - sAppStream << sThis; - } -} - -void CPWL_Wnd::GetChildAppearanceStream(CFX_ByteTextBuf& sAppStream) { - for (CPWL_Wnd* pChild : m_Children) { - if (pChild) - pChild->GetAppearanceStream(sAppStream); - } -} - void CPWL_Wnd::DrawAppearance(CFX_RenderDevice* pDevice, CFX_Matrix* pUser2Device) { if (IsValid() && IsVisible()) { @@ -347,20 +255,21 @@ void CPWL_Wnd::DrawAppearance(CFX_RenderDevice* pDevice, void CPWL_Wnd::DrawThisAppearance(CFX_RenderDevice* pDevice, CFX_Matrix* pUser2Device) { CFX_FloatRect rectWnd = GetWindowRect(); - if (!rectWnd.IsEmpty()) { - if (HasFlag(PWS_BACKGROUND)) { - CFX_FloatRect rcClient = CPWL_Utils::DeflateRect( - rectWnd, (float)(GetBorderWidth() + GetInnerBorderWidth())); - CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcClient, - GetBackgroundColor(), GetTransparency()); - } + if (rectWnd.IsEmpty()) + return; + + if (HasFlag(PWS_BACKGROUND)) { + float width = static_cast<float>(GetBorderWidth() + GetInnerBorderWidth()); + pDevice->DrawFillRect(pUser2Device, rectWnd.GetDeflated(width, width), + GetBackgroundColor(), GetTransparency()); + } - if (HasFlag(PWS_BORDER)) - CPWL_Utils::DrawBorder(pDevice, pUser2Device, rectWnd, - (float)GetBorderWidth(), GetBorderColor(), - GetBorderLeftTopColor(GetBorderStyle()), - GetBorderRightBottomColor(GetBorderStyle()), - GetBorderStyle(), GetTransparency()); + if (HasFlag(PWS_BORDER)) { + pDevice->DrawBorder(pUser2Device, rectWnd, + static_cast<float>(GetBorderWidth()), GetBorderColor(), + GetBorderLeftTopColor(GetBorderStyle()), + GetBorderRightBottomColor(GetBorderStyle()), + GetBorderStyle(), GetTransparency()); } } @@ -381,27 +290,28 @@ void CPWL_Wnd::DrawChildAppearance(CFX_RenderDevice* pDevice, } void CPWL_Wnd::InvalidateRect(CFX_FloatRect* pRect) { - if (IsValid()) { - CFX_FloatRect rcRefresh = pRect ? *pRect : GetWindowRect(); + if (!IsValid()) + return; - if (!HasFlag(PWS_NOREFRESHCLIP)) { - CFX_FloatRect rcClip = GetClipRect(); - if (!rcClip.IsEmpty()) { - rcRefresh.Intersect(rcClip); - } + CFX_FloatRect rcRefresh = pRect ? *pRect : GetWindowRect(); + + if (!HasFlag(PWS_NOREFRESHCLIP)) { + CFX_FloatRect rcClip = GetClipRect(); + if (!rcClip.IsEmpty()) { + rcRefresh.Intersect(rcClip); } + } - FX_RECT rcWin = PWLtoWnd(rcRefresh); - rcWin.left -= PWL_INVALIDATE_INFLATE; - rcWin.top -= PWL_INVALIDATE_INFLATE; - rcWin.right += PWL_INVALIDATE_INFLATE; - rcWin.bottom += PWL_INVALIDATE_INFLATE; + FX_RECT rcWin = PWLtoWnd(rcRefresh); + rcWin.left -= kInvalidationInflate; + rcWin.top -= kInvalidationInflate; + rcWin.right += kInvalidationInflate; + rcWin.bottom += kInvalidationInflate; - if (CFX_SystemHandler* pSH = GetSystemHandler()) { - if (CPDFSDK_Widget* widget = static_cast<CPDFSDK_Widget*>( - m_sPrivateParam.pAttachedWidget.Get())) { - pSH->InvalidateRect(widget, rcWin); - } + if (CFX_SystemHandler* pSH = GetSystemHandler()) { + if (CPDFSDK_Widget* widget = static_cast<CPDFSDK_Widget*>( + m_sPrivateParam.pAttachedWidget.Get())) { + pSH->InvalidateRect(widget, rcWin); } } } @@ -455,6 +365,10 @@ PWL_IMPLEMENT_MOUSE_METHOD(OnRButtonUp) PWL_IMPLEMENT_MOUSE_METHOD(OnMouseMove) #undef PWL_IMPLEMENT_MOUSE_METHOD +CFX_WideString CPWL_Wnd::GetSelectedText() { + return CFX_WideString(); +} + bool CPWL_Wnd::OnMouseWheel(short zDelta, const CFX_PointF& point, uint32_t nFlag) { @@ -485,21 +399,17 @@ void CPWL_Wnd::RemoveChild(CPWL_Wnd* pWnd) { } } -void CPWL_Wnd::OnNotify(CPWL_Wnd* pWnd, - uint32_t msg, - intptr_t wParam, - intptr_t lParam) { - switch (msg) { - case PNM_ADDCHILD: - AddChild(pWnd); - break; - case PNM_REMOVECHILD: - RemoveChild(pWnd); - break; - default: - break; - } -} +void CPWL_Wnd::SetScrollInfo(const PWL_SCROLL_INFO& info) {} + +void CPWL_Wnd::SetScrollPosition(float pos) {} + +void CPWL_Wnd::ScrollWindowVertically(float pos) {} + +void CPWL_Wnd::NotifyLButtonDown(CPWL_Wnd* child, const CFX_PointF& pos) {} + +void CPWL_Wnd::NotifyLButtonUp(CPWL_Wnd* child, const CFX_PointF& pos) {} + +void CPWL_Wnd::NotifyMouseMove(CPWL_Wnd* child, const CFX_PointF& pos) {} bool CPWL_Wnd::IsValid() const { return m_bCreated; @@ -519,8 +429,9 @@ CFX_FloatRect CPWL_Wnd::GetWindowRect() const { CFX_FloatRect CPWL_Wnd::GetClientRect() const { CFX_FloatRect rcWindow = GetWindowRect(); - CFX_FloatRect rcClient = CPWL_Utils::DeflateRect( - rcWindow, (float)(GetBorderWidth() + GetInnerBorderWidth())); + + float width = static_cast<float>(GetBorderWidth() + GetInnerBorderWidth()); + CFX_FloatRect rcClient = rcWindow.GetDeflated(width, width); if (CPWL_ScrollBar* pVSB = GetVScrollBar()) rcClient.right -= pVSB->GetScrollBarWidth(); @@ -546,15 +457,15 @@ void CPWL_Wnd::AddFlag(uint32_t dwFlags) { m_sPrivateParam.dwFlags |= dwFlags; } -CPWL_Color CPWL_Wnd::GetBackgroundColor() const { +CFX_Color CPWL_Wnd::GetBackgroundColor() const { return m_sPrivateParam.sBackgroundColor; } -void CPWL_Wnd::SetBackgroundColor(const CPWL_Color& color) { +void CPWL_Wnd::SetBackgroundColor(const CFX_Color& color) { m_sPrivateParam.sBackgroundColor = color; } -CPWL_Color CPWL_Wnd::GetTextColor() const { +CFX_Color CPWL_Wnd::GetTextColor() const { return m_sPrivateParam.sTextColor; } @@ -568,21 +479,15 @@ void CPWL_Wnd::SetBorderStyle(BorderStyle nBorderStyle) { } int32_t CPWL_Wnd::GetBorderWidth() const { - if (HasFlag(PWS_BORDER)) - return m_sPrivateParam.dwBorderWidth; - - return 0; + return HasFlag(PWS_BORDER) ? m_sPrivateParam.dwBorderWidth : 0; } int32_t CPWL_Wnd::GetInnerBorderWidth() const { return 0; } -CPWL_Color CPWL_Wnd::GetBorderColor() const { - if (HasFlag(PWS_BORDER)) - return m_sPrivateParam.sBorderColor; - - return CPWL_Color(); +CFX_Color CPWL_Wnd::GetBorderColor() const { + return HasFlag(PWS_BORDER) ? m_sPrivateParam.sBorderColor : CFX_Color(); } const CPWL_Dash& CPWL_Wnd::GetBorderDash() const { @@ -594,10 +499,7 @@ void* CPWL_Wnd::GetAttachedData() const { } CPWL_ScrollBar* CPWL_Wnd::GetVScrollBar() const { - if (HasFlag(PWS_VSCROLL)) - return m_pVScrollBar; - - return nullptr; + return HasFlag(PWS_VSCROLL) ? m_pVScrollBar.Get() : nullptr; } void CPWL_Wnd::CreateScrollBar(const PWL_CREATEPARAM& cp) { @@ -605,21 +507,22 @@ void CPWL_Wnd::CreateScrollBar(const PWL_CREATEPARAM& cp) { } void CPWL_Wnd::CreateVScrollBar(const PWL_CREATEPARAM& cp) { - if (!m_pVScrollBar && HasFlag(PWS_VSCROLL)) { - PWL_CREATEPARAM scp = cp; + if (m_pVScrollBar || !HasFlag(PWS_VSCROLL)) + return; - // flags - scp.dwFlags = - PWS_CHILD | PWS_BACKGROUND | PWS_AUTOTRANSPARENT | PWS_NOREFRESHCLIP; + PWL_CREATEPARAM scp = cp; - scp.pParentWnd = this; - scp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR; - scp.eCursorType = FXCT_ARROW; - scp.nTransparency = PWL_SCROLLBAR_TRANSPARENCY; + // flags + scp.dwFlags = + PWS_CHILD | PWS_BACKGROUND | PWS_AUTOTRANSPARENT | PWS_NOREFRESHCLIP; - m_pVScrollBar = new CPWL_ScrollBar(SBT_VSCROLL); - m_pVScrollBar->Create(scp); - } + scp.pParentWnd = this; + scp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR; + scp.eCursorType = FXCT_ARROW; + scp.nTransparency = PWL_SCROLLBAR_TRANSPARENCY; + + m_pVScrollBar = new CPWL_ScrollBar(SBT_VSCROLL); + m_pVScrollBar->Create(scp); } void CPWL_Wnd::SetCapture() { @@ -664,10 +567,8 @@ bool CPWL_Wnd::ClientHitTest(const CFX_PointF& point) const { } const CPWL_Wnd* CPWL_Wnd::GetRootWnd() const { - if (m_sPrivateParam.pParentWnd) - return m_sPrivateParam.pParentWnd->GetRootWnd(); - - return this; + auto* pParent = m_sPrivateParam.pParentWnd; + return pParent ? pParent->GetRootWnd() : this; } void CPWL_Wnd::SetVisible(bool bVisible) { @@ -699,17 +600,20 @@ bool CPWL_Wnd::IsReadOnly() const { } void CPWL_Wnd::RePosChildWnd() { - CFX_FloatRect rcContent = CPWL_Utils::DeflateRect( - GetWindowRect(), (float)(GetBorderWidth() + GetInnerBorderWidth())); - CPWL_ScrollBar* pVSB = GetVScrollBar(); + if (!pVSB) + return; + CFX_FloatRect rcContent = GetWindowRect(); + if (!rcContent.IsEmpty()) { + float width = static_cast<float>(GetBorderWidth() + GetInnerBorderWidth()); + rcContent.Deflate(width, width); + rcContent.Normalize(); + } CFX_FloatRect rcVScroll = CFX_FloatRect(rcContent.right - PWL_SCROLLBAR_WIDTH, rcContent.bottom, rcContent.right - 1.0f, rcContent.top); - - if (pVSB) - pVSB->Move(rcVScroll, true, false); + pVSB->Move(rcVScroll, true, false); } void CPWL_Wnd::CreateChildWnd(const PWL_CREATEPARAM& cp) {} @@ -729,9 +633,9 @@ void CPWL_Wnd::CreateMsgControl() { } void CPWL_Wnd::DestroyMsgControl() { - if (CPWL_MsgControl* pMsgControl = GetMsgControl()) - if (pMsgControl->IsWndCreated(this)) - delete pMsgControl; + CPWL_MsgControl* pMsgControl = GetMsgControl(); + if (pMsgControl && pMsgControl->IsWndCreated(this)) + delete pMsgControl; } CPWL_MsgControl* CPWL_Wnd::GetMsgControl() const { @@ -743,28 +647,27 @@ bool CPWL_Wnd::IsCaptureMouse() const { } bool CPWL_Wnd::IsWndCaptureMouse(const CPWL_Wnd* pWnd) const { - if (CPWL_MsgControl* pCtrl = GetMsgControl()) - return pCtrl->IsWndCaptureMouse(pWnd); - - return false; + CPWL_MsgControl* pCtrl = GetMsgControl(); + return pCtrl ? pCtrl->IsWndCaptureMouse(pWnd) : false; } bool CPWL_Wnd::IsWndCaptureKeyboard(const CPWL_Wnd* pWnd) const { - if (CPWL_MsgControl* pCtrl = GetMsgControl()) - return pCtrl->IsWndCaptureKeyboard(pWnd); - - return false; + CPWL_MsgControl* pCtrl = GetMsgControl(); + return pCtrl ? pCtrl->IsWndCaptureKeyboard(pWnd) : false; } bool CPWL_Wnd::IsFocused() const { - if (CPWL_MsgControl* pCtrl = GetMsgControl()) - return pCtrl->IsMainCaptureKeyboard(this); - - return false; + CPWL_MsgControl* pCtrl = GetMsgControl(); + return pCtrl ? pCtrl->IsMainCaptureKeyboard(this) : false; } CFX_FloatRect CPWL_Wnd::GetFocusRect() const { - return CPWL_Utils::InflateRect(GetWindowRect(), 1); + CFX_FloatRect rect = GetWindowRect(); + if (!rect.IsEmpty()) { + rect.Inflate(1.0f, 1.0f); + rect.Normalize(); + } + return rect; } float CPWL_Wnd::GetFontSize() const { @@ -791,25 +694,25 @@ IPVT_FontMap* CPWL_Wnd::GetFontMap() const { return m_sPrivateParam.pFontMap; } -CPWL_Color CPWL_Wnd::GetBorderLeftTopColor(BorderStyle nBorderStyle) const { +CFX_Color CPWL_Wnd::GetBorderLeftTopColor(BorderStyle nBorderStyle) const { switch (nBorderStyle) { case BorderStyle::BEVELED: - return CPWL_Color(COLORTYPE_GRAY, 1); + return CFX_Color(COLORTYPE_GRAY, 1); case BorderStyle::INSET: - return CPWL_Color(COLORTYPE_GRAY, 0.5f); + return CFX_Color(COLORTYPE_GRAY, 0.5f); default: - return CPWL_Color(); + return CFX_Color(); } } -CPWL_Color CPWL_Wnd::GetBorderRightBottomColor(BorderStyle nBorderStyle) const { +CFX_Color CPWL_Wnd::GetBorderRightBottomColor(BorderStyle nBorderStyle) const { switch (nBorderStyle) { case BorderStyle::BEVELED: return GetBackgroundColor() / 2.0f; case BorderStyle::INSET: - return CPWL_Color(COLORTYPE_GRAY, 0.75f); + return CFX_Color(COLORTYPE_GRAY, 0.75f); default: - return CPWL_Color(); + return CFX_Color(); } } @@ -845,7 +748,9 @@ CFX_PointF CPWL_Wnd::ParentToChild(const CFX_PointF& point) const { if (mt.IsIdentity()) return point; - mt.SetReverse(mt); + CFX_Matrix inverse = mt.GetInverse(); + if (!inverse.IsIdentity()) + mt = inverse; return mt.Transform(point); } @@ -854,14 +759,16 @@ CFX_FloatRect CPWL_Wnd::ParentToChild(const CFX_FloatRect& rect) const { if (mt.IsIdentity()) return rect; - mt.SetReverse(mt); + CFX_Matrix inverse = mt.GetInverse(); + if (!inverse.IsIdentity()) + mt = inverse; CFX_FloatRect rc = rect; mt.TransformRect(rc); return rc; } CFX_Matrix CPWL_Wnd::GetChildToRoot() const { - CFX_Matrix mt(1, 0, 0, 1, 0, 0); + CFX_Matrix mt; if (HasFlag(PWS_CHILD)) { const CPWL_Wnd* pParent = this; while (pParent) { @@ -873,10 +780,7 @@ CFX_Matrix CPWL_Wnd::GetChildToRoot() const { } CFX_Matrix CPWL_Wnd::GetChildMatrix() const { - if (HasFlag(PWS_CHILD)) - return m_sPrivateParam.mtChild; - - return CFX_Matrix(1, 0, 0, 1, 0, 0); + return HasFlag(PWS_CHILD) ? m_sPrivateParam.mtChild : CFX_Matrix(); } void CPWL_Wnd::SetChildMatrix(const CFX_Matrix& mt) { @@ -885,7 +789,7 @@ void CPWL_Wnd::SetChildMatrix(const CFX_Matrix& mt) { const CPWL_Wnd* CPWL_Wnd::GetFocused() const { CPWL_MsgControl* pMsgCtrl = GetMsgControl(); - return pMsgCtrl ? pMsgCtrl->m_pMainKeyboardWnd : nullptr; + return pMsgCtrl ? pMsgCtrl->m_pMainKeyboardWnd.Get() : nullptr; } void CPWL_Wnd::EnableWindow(bool bEnable) { diff --git a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/PWL_Wnd.h b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_wnd.h index ded003c31b0..56fbb21baa0 100644 --- a/chromium/third_party/pdfium/fpdfsdk/pdfwindow/PWL_Wnd.h +++ b/chromium/third_party/pdfium/fpdfsdk/pdfwindow/cpwl_wnd.h @@ -4,27 +4,29 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef FPDFSDK_PDFWINDOW_PWL_WND_H_ -#define FPDFSDK_PDFWINDOW_PWL_WND_H_ +#ifndef FPDFSDK_PDFWINDOW_CPWL_WND_H_ +#define FPDFSDK_PDFWINDOW_CPWL_WND_H_ #include <memory> #include <vector> #include "core/fpdfdoc/cpdf_formcontrol.h" #include "core/fxcrt/cfx_observable.h" +#include "core/fxcrt/cfx_unowned_ptr.h" #include "core/fxcrt/fx_basic.h" -#include "fpdfsdk/cfx_systemhandler.h" +#include "core/fxge/cfx_color.h" #include "fpdfsdk/cpdfsdk_widget.h" -#include "fpdfsdk/pdfwindow/cpwl_color.h" +#include "fpdfsdk/pdfwindow/cpwl_timer.h" +#include "fpdfsdk/pdfwindow/cpwl_timer_handler.h" +class CPWL_Edit; class CPWL_MsgControl; class CPWL_ScrollBar; -class CPWL_Timer; -class CPWL_TimerHandler; class CPWL_Wnd; class CFX_SystemHandler; class IPVT_FontMap; class IPWL_Provider; +struct PWL_SCROLL_INFO; // window styles #define PWS_CHILD 0x80000000L @@ -33,7 +35,6 @@ class IPWL_Provider; #define PWS_HSCROLL 0x10000000L #define PWS_VSCROLL 0x08000000L #define PWS_VISIBLE 0x04000000L -#define PWS_DISABLE 0x02000000L #define PWS_READONLY 0x01000000L #define PWS_AUTOFONTSIZE 0x00800000L #define PWS_AUTOTRANSPARENT 0x00400000L @@ -64,28 +65,6 @@ class IPWL_Provider; // combobox styles #define PCBS_ALLOWCUSTOMTEXT 0x0001L -// richedit styles -#define PRES_MULTILINE 0x0001L -#define PRES_AUTORETURN 0x0002L -#define PRES_AUTOSCROLL 0x0004L -#define PRES_UNDO 0x0100L -#define PRES_MULTIPAGES 0x0200L -#define PRES_TEXTOVERFLOW 0x0400L - -// notification messages -#define PNM_ADDCHILD 0x00000000L -#define PNM_REMOVECHILD 0x00000001L -#define PNM_SETSCROLLINFO 0x00000002L -#define PNM_SETSCROLLPOS 0x00000003L -#define PNM_SCROLLWINDOW 0x00000004L -#define PNM_LBUTTONDOWN 0x00000005L -#define PNM_LBUTTONUP 0x00000006L -#define PNM_MOUSEMOVE 0x00000007L -#define PNM_NOTERESET 0x00000008L -#define PNM_SETCARETINFO 0x00000009L -#define PNM_SELCHANGED 0x0000000AL -#define PNM_NOTEEDITCHANGED 0x0000000BL - #define PWL_CLASSNAME_EDIT "CPWL_Edit" struct CPWL_Dash { @@ -104,7 +83,7 @@ struct CPWL_Dash { int32_t nPhase; }; -inline bool operator==(const CPWL_Color& c1, const CPWL_Color& c2) { +inline bool operator==(const CFX_Color& c1, const CFX_Color& c2) { return c1.nColorType == c2.nColorType && c1.fColor1 - c2.fColor1 < 0.0001 && c1.fColor1 - c2.fColor1 > -0.0001 && c1.fColor2 - c2.fColor2 < 0.0001 && @@ -114,29 +93,16 @@ inline bool operator==(const CPWL_Color& c1, const CPWL_Color& c2) { c1.fColor4 - c2.fColor4 < 0.0001 && c1.fColor4 - c2.fColor4 > -0.0001; } -inline bool operator!=(const CPWL_Color& c1, const CPWL_Color& c2) { +inline bool operator!=(const CFX_Color& c1, const CFX_Color& c2) { return !(c1 == c2); } #define PWL_SCROLLBAR_WIDTH 12.0f -#define PWL_SCROLLBAR_BUTTON_WIDTH 9.0f -#define PWL_SCROLLBAR_POSBUTTON_MINWIDTH 2.0f #define PWL_SCROLLBAR_TRANSPARENCY 150 -#define PWL_SCROLLBAR_BKCOLOR \ - CPWL_Color(COLORTYPE_RGB, 220.0f / 255.0f, 220.0f / 255.0f, 220.0f / 255.0f) -#define PWL_DEFAULT_SELTEXTCOLOR CPWL_Color(COLORTYPE_RGB, 1, 1, 1) #define PWL_DEFAULT_SELBACKCOLOR \ - CPWL_Color(COLORTYPE_RGB, 0, 51.0f / 255.0f, 113.0f / 255.0f) -#define PWL_DEFAULT_BACKCOLOR PWL_DEFAULT_SELTEXTCOLOR -#define PWL_DEFAULT_TEXTCOLOR CPWL_Color(COLORTYPE_RGB, 0, 0, 0) -#define PWL_DEFAULT_FONTSIZE 9.0f -#define PWL_DEFAULT_BLACKCOLOR CPWL_Color(COLORTYPE_GRAY, 0) -#define PWL_DEFAULT_WHITECOLOR CPWL_Color(COLORTYPE_GRAY, 1) -#define PWL_DEFAULT_HEAVYGRAYCOLOR CPWL_Color(COLORTYPE_GRAY, 0.50) -#define PWL_DEFAULT_LIGHTGRAYCOLOR CPWL_Color(COLORTYPE_GRAY, 0.75) -#define PWL_TRIANGLE_HALFLEN 2.0f -#define PWL_CBBUTTON_TRIANGLE_HALFLEN 3.0f -#define PWL_INVALIDATE_INFLATE 2 + CFX_Color(COLORTYPE_RGB, 0, 51.0f / 255.0f, 113.0f / 255.0f) +#define PWL_DEFAULT_BLACKCOLOR CFX_Color(COLORTYPE_GRAY, 0) +#define PWL_DEFAULT_WHITECOLOR CFX_Color(COLORTYPE_GRAY, 1) class IPWL_Provider : public CFX_Observable<IPWL_Provider> { public: @@ -144,23 +110,12 @@ class IPWL_Provider : public CFX_Observable<IPWL_Provider> { // get a matrix which map user space to CWnd client space virtual CFX_Matrix GetWindowMatrix(void* pAttachedData) = 0; - - /* - 0 L"&Undo\tCtrl+Z" - 1 L"&Redo\tCtrl+Shift+Z" - 2 L"Cu&t\tCtrl+X" - 3 L"&Copy\tCtrl+C" - 4 L"&Paste\tCtrl+V" - 5 L"&Delete" - 6 L"&Select All\tCtrl+A" - */ - virtual CFX_WideString LoadPopupMenuString(int32_t nIndex) = 0; }; class IPWL_FocusHandler { public: virtual ~IPWL_FocusHandler() {} - virtual void OnSetFocus(CPWL_Wnd* pWnd) = 0; + virtual void OnSetFocus(CPWL_Edit* pEdit) = 0; }; struct PWL_CREATEPARAM { @@ -191,58 +146,29 @@ struct PWL_CREATEPARAM { mtChild.SetIdentity(); } - CFX_FloatRect rcRectWnd; // required - CFX_SystemHandler* pSystemHandler; // required - IPVT_FontMap* pFontMap; // required - IPWL_Provider::ObservedPtr pProvider; // required - IPWL_FocusHandler* pFocusHandler; // optional - uint32_t dwFlags; // optional - CPWL_Color sBackgroundColor; // optional + CFX_FloatRect rcRectWnd; // required + CFX_SystemHandler* pSystemHandler; // required + IPVT_FontMap* pFontMap; // required + IPWL_Provider::ObservedPtr pProvider; // required + IPWL_FocusHandler* pFocusHandler; // optional + uint32_t dwFlags; // optional + CFX_Color sBackgroundColor; // optional CPDFSDK_Widget::ObservedPtr pAttachedWidget; // required - BorderStyle nBorderStyle; // optional - int32_t dwBorderWidth; // optional - CPWL_Color sBorderColor; // optional - CPWL_Color sTextColor; // optional - int32_t nTransparency; // optional - float fFontSize; // optional - CPWL_Dash sDash; // optional - void* pAttachedData; // optional - CPWL_Wnd* pParentWnd; // ignore - CPWL_MsgControl* pMsgControl; // ignore - int32_t eCursorType; // ignore - CFX_Matrix mtChild; // ignore -}; - -class CPWL_Timer { - public: - CPWL_Timer(CPWL_TimerHandler* pAttached, CFX_SystemHandler* pSystemHandler); - virtual ~CPWL_Timer(); - - int32_t SetPWLTimer(int32_t nElapse); - void KillPWLTimer(); - static void TimerProc(int32_t idEvent); - - private: - int32_t m_nTimerID; - CPWL_TimerHandler* m_pAttached; - CFX_SystemHandler* m_pSystemHandler; -}; - -class CPWL_TimerHandler { - public: - CPWL_TimerHandler(); - virtual ~CPWL_TimerHandler(); - - void BeginTimer(int32_t nElapse); - void EndTimer(); - virtual void TimerProc(); - virtual CFX_SystemHandler* GetSystemHandler() const = 0; - - private: - std::unique_ptr<CPWL_Timer> m_pTimer; + BorderStyle nBorderStyle; // optional + int32_t dwBorderWidth; // optional + CFX_Color sBorderColor; // optional + CFX_Color sTextColor; // optional + int32_t nTransparency; // optional + float fFontSize; // optional + CPWL_Dash sDash; // optional + void* pAttachedData; // optional + CPWL_Wnd* pParentWnd; // ignore + CPWL_MsgControl* pMsgControl; // ignore + int32_t eCursorType; // ignore + CFX_Matrix mtChild; // ignore }; -class CPWL_Wnd : public CPWL_TimerHandler { +class CPWL_Wnd : public CPWL_TimerHandler, public CFX_Observable<CPWL_Wnd> { public: CPWL_Wnd(); ~CPWL_Wnd() override; @@ -261,10 +187,12 @@ class CPWL_Wnd : public CPWL_TimerHandler { virtual bool OnMouseWheel(short zDelta, const CFX_PointF& point, uint32_t nFlag); - virtual void OnNotify(CPWL_Wnd* pWnd, - uint32_t msg, - intptr_t wParam = 0, - intptr_t lParam = 0); + virtual void SetScrollInfo(const PWL_SCROLL_INFO& info); + virtual void SetScrollPosition(float pos); + virtual void ScrollWindowVertically(float pos); + virtual void NotifyLButtonDown(CPWL_Wnd* child, const CFX_PointF& pos); + virtual void NotifyLButtonUp(CPWL_Wnd* child, const CFX_PointF& pos); + virtual void NotifyMouseMove(CPWL_Wnd* child, const CFX_PointF& pos); virtual void SetFocus(); virtual void KillFocus(); virtual void SetCursor(); @@ -272,6 +200,7 @@ class CPWL_Wnd : public CPWL_TimerHandler { virtual void SetFontSize(float fFontSize); virtual float GetFontSize() const; + virtual CFX_WideString GetSelectedText(); virtual CFX_FloatRect GetFocusRect() const; virtual CFX_FloatRect GetClientRect() const; @@ -286,13 +215,13 @@ class CPWL_Wnd : public CPWL_TimerHandler { void DrawAppearance(CFX_RenderDevice* pDevice, CFX_Matrix* pUser2Device); - CPWL_Color GetBackgroundColor() const; - void SetBackgroundColor(const CPWL_Color& color); - CPWL_Color GetBorderColor() const; - CPWL_Color GetTextColor() const; - void SetTextColor(const CPWL_Color& color); - CPWL_Color GetBorderLeftTopColor(BorderStyle nBorderStyle) const; - CPWL_Color GetBorderRightBottomColor(BorderStyle nBorderStyle) const; + CFX_Color GetBackgroundColor() const; + void SetBackgroundColor(const CFX_Color& color); + CFX_Color GetBorderColor() const; + CFX_Color GetTextColor() const; + void SetTextColor(const CFX_Color& color); + CFX_Color GetBorderLeftTopColor(BorderStyle nBorderStyle) const; + CFX_Color GetBorderRightBottomColor(BorderStyle nBorderStyle) const; void SetBorderStyle(BorderStyle eBorderStyle); BorderStyle GetBorderStyle() const; @@ -345,7 +274,6 @@ class CPWL_Wnd : public CPWL_TimerHandler { virtual void CreateChildWnd(const PWL_CREATEPARAM& cp); virtual void RePosChildWnd(); - virtual void GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream); virtual void DrawThisAppearance(CFX_RenderDevice* pDevice, CFX_Matrix* pUser2Device); @@ -357,7 +285,6 @@ class CPWL_Wnd : public CPWL_TimerHandler { virtual void OnSetFocus(); virtual void OnKillFocus(); - void GetAppearanceStream(CFX_ByteTextBuf& sAppStream); void SetNotifyFlag(bool bNotifying = true) { m_bNotifying = bNotifying; } bool IsValid() const; @@ -379,7 +306,6 @@ class CPWL_Wnd : public CPWL_TimerHandler { CFX_PointF ParentToChild(const CFX_PointF& point) const; CFX_FloatRect ParentToChild(const CFX_FloatRect& rect) const; - void GetChildAppearanceStream(CFX_ByteTextBuf& sAppStream); void DrawChildAppearance(CFX_RenderDevice* pDevice, CFX_Matrix* pUser2Device); FX_RECT PWLtoWnd(const CFX_FloatRect& rect) const; @@ -398,7 +324,7 @@ class CPWL_Wnd : public CPWL_TimerHandler { std::vector<CPWL_Wnd*> m_Children; PWL_CREATEPARAM m_sPrivateParam; - CPWL_ScrollBar* m_pVScrollBar; + CFX_UnownedPtr<CPWL_ScrollBar> m_pVScrollBar; CFX_FloatRect m_rcWindow; CFX_FloatRect m_rcClip; bool m_bCreated; @@ -407,4 +333,4 @@ class CPWL_Wnd : public CPWL_TimerHandler { bool m_bEnabled; }; -#endif // FPDFSDK_PDFWINDOW_PWL_WND_H_ +#endif // FPDFSDK_PDFWINDOW_CPWL_WND_H_ diff --git a/chromium/third_party/pdfium/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.cpp b/chromium/third_party/pdfium/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.cpp index 5c26188f53c..ef83691d4f6 100644 --- a/chromium/third_party/pdfium/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.cpp +++ b/chromium/third_party/pdfium/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.cpp @@ -106,7 +106,7 @@ int32_t CBC_ReedSolomonGF256Poly::EvaluateAt(int32_t a) { std::unique_ptr<CBC_ReedSolomonGF256Poly> CBC_ReedSolomonGF256Poly::Clone() const { auto temp = pdfium::MakeUnique<CBC_ReedSolomonGF256Poly>(); - if (!temp->Init(m_field, &m_coefficients)) + if (!temp->Init(m_field.Get(), &m_coefficients)) return nullptr; return temp; } @@ -133,7 +133,7 @@ CBC_ReedSolomonGF256Poly::AddOrSubtract(const CBC_ReedSolomonGF256Poly* other) { smallerCoefficients[j - lengthDiff], largerCoefficients[j]); } auto temp = pdfium::MakeUnique<CBC_ReedSolomonGF256Poly>(); - if (!temp->Init(m_field, &sumDiff)) + if (!temp->Init(m_field.Get(), &sumDiff)) return nullptr; return temp; } @@ -156,7 +156,7 @@ std::unique_ptr<CBC_ReedSolomonGF256Poly> CBC_ReedSolomonGF256Poly::Multiply( } } auto temp = pdfium::MakeUnique<CBC_ReedSolomonGF256Poly>(); - if (!temp->Init(m_field, &product)) + if (!temp->Init(m_field.Get(), &product)) return nullptr; return temp; } @@ -174,7 +174,7 @@ std::unique_ptr<CBC_ReedSolomonGF256Poly> CBC_ReedSolomonGF256Poly::Multiply( product[i] = m_field->Multiply(m_coefficients[i], scalar); auto temp = pdfium::MakeUnique<CBC_ReedSolomonGF256Poly>(); - if (!temp->Init(m_field, &product)) + if (!temp->Init(m_field.Get(), &product)) return nullptr; return temp; } @@ -193,7 +193,7 @@ CBC_ReedSolomonGF256Poly::MultiplyByMonomial(int32_t degree, product[i] = m_field->Multiply(m_coefficients[i], coefficient); auto temp = pdfium::MakeUnique<CBC_ReedSolomonGF256Poly>(); - if (!temp->Init(m_field, &product)) + if (!temp->Init(m_field.Get(), &product)) return nullptr; return temp; } diff --git a/chromium/third_party/pdfium/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.h b/chromium/third_party/pdfium/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.h index ce8a5727048..f7aea2bf535 100644 --- a/chromium/third_party/pdfium/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.h +++ b/chromium/third_party/pdfium/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.h @@ -40,7 +40,7 @@ class CBC_ReedSolomonGF256Poly final { std::unique_ptr<CBC_ReedSolomonGF256Poly> Clone() const; private: - CBC_ReedSolomonGF256* m_field; + CFX_UnownedPtr<CBC_ReedSolomonGF256> m_field; std::vector<int32_t> m_coefficients; }; diff --git a/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_ASCIIEncoder.cpp b/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_ASCIIEncoder.cpp index 7b277feb635..de57d81b71a 100644 --- a/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_ASCIIEncoder.cpp +++ b/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_ASCIIEncoder.cpp @@ -26,7 +26,6 @@ #include "fxbarcode/datamatrix/BC_EncoderContext.h" #include "fxbarcode/datamatrix/BC_HighLevelEncoder.h" #include "fxbarcode/datamatrix/BC_SymbolInfo.h" -#include "fxbarcode/datamatrix/BC_SymbolShapeHint.h" #include "fxbarcode/utils.h" CBC_ASCIIEncoder::CBC_ASCIIEncoder() {} diff --git a/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_Base256Encoder.cpp b/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_Base256Encoder.cpp index c34ff029395..edcd4111145 100644 --- a/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_Base256Encoder.cpp +++ b/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_Base256Encoder.cpp @@ -26,7 +26,6 @@ #include "fxbarcode/datamatrix/BC_EncoderContext.h" #include "fxbarcode/datamatrix/BC_HighLevelEncoder.h" #include "fxbarcode/datamatrix/BC_SymbolInfo.h" -#include "fxbarcode/datamatrix/BC_SymbolShapeHint.h" #include "fxbarcode/utils.h" CBC_Base256Encoder::CBC_Base256Encoder() {} diff --git a/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_C40Encoder.cpp b/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_C40Encoder.cpp index 11d477c07de..e994774c4d7 100644 --- a/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_C40Encoder.cpp +++ b/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_C40Encoder.cpp @@ -27,7 +27,6 @@ #include "fxbarcode/datamatrix/BC_EncoderContext.h" #include "fxbarcode/datamatrix/BC_HighLevelEncoder.h" #include "fxbarcode/datamatrix/BC_SymbolInfo.h" -#include "fxbarcode/datamatrix/BC_SymbolShapeHint.h" #include "fxbarcode/utils.h" namespace { diff --git a/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_DataMatrixSymbolInfo144.cpp b/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_DataMatrixSymbolInfo144.cpp index 122932179b6..7a18d03839d 100644 --- a/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_DataMatrixSymbolInfo144.cpp +++ b/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_DataMatrixSymbolInfo144.cpp @@ -23,7 +23,6 @@ #include "fxbarcode/datamatrix/BC_DataMatrixSymbolInfo144.h" #include "fxbarcode/datamatrix/BC_Encoder.h" #include "fxbarcode/datamatrix/BC_SymbolInfo.h" -#include "fxbarcode/datamatrix/BC_SymbolShapeHint.h" CBC_DataMatrixSymbolInfo144::CBC_DataMatrixSymbolInfo144() : CBC_SymbolInfo(1558, 620, 22, 22, 36, -1, 62) {} diff --git a/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_DataMatrixWriter.cpp b/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_DataMatrixWriter.cpp index 19b6346f0a6..98af282f8fe 100644 --- a/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_DataMatrixWriter.cpp +++ b/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_DataMatrixWriter.cpp @@ -40,7 +40,6 @@ #include "fxbarcode/datamatrix/BC_ErrorCorrection.h" #include "fxbarcode/datamatrix/BC_HighLevelEncoder.h" #include "fxbarcode/datamatrix/BC_SymbolInfo.h" -#include "fxbarcode/datamatrix/BC_SymbolShapeHint.h" #include "fxbarcode/datamatrix/BC_TextEncoder.h" #include "fxbarcode/datamatrix/BC_X12Encoder.h" #include "third_party/base/ptr_util.h" @@ -115,15 +114,14 @@ uint8_t* CBC_DataMatrixWriter::Encode(const CFX_WideString& contents, if (outWidth < 0 || outHeight < 0) return nullptr; - SymbolShapeHint shape = FORCE_SQUARE; CFX_WideString ecLevel; int32_t e = BCExceptionNO; CFX_WideString encoded = - CBC_HighLevelEncoder::encodeHighLevel(contents, ecLevel, shape, e); + CBC_HighLevelEncoder::encodeHighLevel(contents, ecLevel, false, e); if (e != BCExceptionNO) return nullptr; CBC_SymbolInfo* symbolInfo = - CBC_SymbolInfo::lookup(encoded.GetLength(), shape, e); + CBC_SymbolInfo::lookup(encoded.GetLength(), false, e); if (e != BCExceptionNO) return nullptr; CFX_WideString codewords = diff --git a/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_EdifactEncoder.cpp b/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_EdifactEncoder.cpp index cc72a311c9c..c7d6b317c11 100644 --- a/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_EdifactEncoder.cpp +++ b/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_EdifactEncoder.cpp @@ -29,7 +29,6 @@ #include "fxbarcode/datamatrix/BC_EncoderContext.h" #include "fxbarcode/datamatrix/BC_HighLevelEncoder.h" #include "fxbarcode/datamatrix/BC_SymbolInfo.h" -#include "fxbarcode/datamatrix/BC_SymbolShapeHint.h" #include "fxbarcode/utils.h" namespace { diff --git a/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_EncoderContext.cpp b/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_EncoderContext.cpp index 1c39be1aec8..40855fcbd83 100644 --- a/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_EncoderContext.cpp +++ b/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_EncoderContext.cpp @@ -26,7 +26,6 @@ #include "fxbarcode/common/BC_CommonBitMatrix.h" #include "fxbarcode/datamatrix/BC_Encoder.h" #include "fxbarcode/datamatrix/BC_SymbolInfo.h" -#include "fxbarcode/datamatrix/BC_SymbolShapeHint.h" #include "fxbarcode/utils.h" CBC_EncoderContext::CBC_EncoderContext(const CFX_WideString& msg, @@ -44,16 +43,19 @@ CBC_EncoderContext::CBC_EncoderContext(const CFX_WideString& msg, sb += ch; } m_msg = sb; - m_shape = FORCE_NONE; + m_allowRectangular = true; m_newEncoding = -1; m_pos = 0; m_symbolInfo = nullptr; m_skipAtEnd = 0; } + CBC_EncoderContext::~CBC_EncoderContext() {} -void CBC_EncoderContext::setSymbolShape(SymbolShapeHint shape) { - m_shape = shape; + +void CBC_EncoderContext::setAllowRectangular(bool allow) { + m_allowRectangular = allow; } + void CBC_EncoderContext::setSkipAtEnd(int32_t count) { m_skipAtEnd = count; } @@ -91,14 +93,16 @@ void CBC_EncoderContext::updateSymbolInfo(int32_t& e) { } void CBC_EncoderContext::updateSymbolInfo(int32_t len, int32_t& e) { if (!m_symbolInfo || len > m_symbolInfo->dataCapacity()) { - m_symbolInfo = CBC_SymbolInfo::lookup(len, m_shape, e); + m_symbolInfo = CBC_SymbolInfo::lookup(len, m_allowRectangular, e); if (e != BCExceptionNO) return; } } + void CBC_EncoderContext::resetSymbolInfo() { - m_shape = FORCE_NONE; + m_allowRectangular = true; } + int32_t CBC_EncoderContext::getTotalMessageCharCount() { return m_msg.GetLength() - m_skipAtEnd; } diff --git a/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_EncoderContext.h b/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_EncoderContext.h index 6cb2b42fa9e..4931501c450 100644 --- a/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_EncoderContext.h +++ b/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_EncoderContext.h @@ -7,8 +7,8 @@ #ifndef FXBARCODE_DATAMATRIX_BC_ENCODERCONTEXT_H_ #define FXBARCODE_DATAMATRIX_BC_ENCODERCONTEXT_H_ +#include "core/fxcrt/cfx_unowned_ptr.h" #include "core/fxcrt/cfx_widestring.h" -#include "fxbarcode/datamatrix/BC_SymbolShapeHint.h" class CBC_SymbolInfo; @@ -19,7 +19,7 @@ class CBC_EncoderContext { int32_t& e); ~CBC_EncoderContext(); - void setSymbolShape(SymbolShapeHint shape); + void setAllowRectangular(bool allow); void setSkipAtEnd(int32_t count); wchar_t getCurrentChar(); wchar_t getCurrent(); @@ -38,12 +38,12 @@ class CBC_EncoderContext { CFX_WideString m_codewords; int32_t m_pos; int32_t m_newEncoding; - CBC_SymbolInfo* m_symbolInfo; + CFX_UnownedPtr<CBC_SymbolInfo> m_symbolInfo; private: int32_t getTotalMessageCharCount(); - SymbolShapeHint m_shape; + bool m_allowRectangular; // Force square when false. int32_t m_skipAtEnd; }; diff --git a/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_ErrorCorrection.cpp b/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_ErrorCorrection.cpp index cc6d1b320b4..40716023039 100644 --- a/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_ErrorCorrection.cpp +++ b/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_ErrorCorrection.cpp @@ -26,7 +26,6 @@ #include "fxbarcode/datamatrix/BC_Encoder.h" #include "fxbarcode/datamatrix/BC_SymbolInfo.h" -#include "fxbarcode/datamatrix/BC_SymbolShapeHint.h" #include "fxbarcode/utils.h" namespace { diff --git a/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp b/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp index dd92f5e2d5a..ec527d29a80 100644 --- a/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp +++ b/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp @@ -35,7 +35,6 @@ #include "fxbarcode/datamatrix/BC_Encoder.h" #include "fxbarcode/datamatrix/BC_EncoderContext.h" #include "fxbarcode/datamatrix/BC_SymbolInfo.h" -#include "fxbarcode/datamatrix/BC_SymbolShapeHint.h" #include "fxbarcode/datamatrix/BC_TextEncoder.h" #include "fxbarcode/datamatrix/BC_X12Encoder.h" #include "fxbarcode/utils.h" @@ -66,19 +65,17 @@ std::vector<uint8_t>& CBC_HighLevelEncoder::getBytesForMessage( m_bytearray.insert(m_bytearray.end(), bytestr.begin(), bytestr.end()); return m_bytearray; } + +// static CFX_WideString CBC_HighLevelEncoder::encodeHighLevel(CFX_WideString msg, CFX_WideString ecLevel, - int32_t& e) { - return encodeHighLevel(msg, ecLevel, FORCE_NONE, e); -} -CFX_WideString CBC_HighLevelEncoder::encodeHighLevel(CFX_WideString msg, - CFX_WideString ecLevel, - SymbolShapeHint shape, + bool allowRectangular, int32_t& e) { CBC_EncoderContext context(msg, ecLevel, e); if (e != BCExceptionNO) return CFX_WideString(); - context.setSymbolShape(shape); + + context.setAllowRectangular(allowRectangular); if ((msg.Mid(0, 6) == MACRO_05_HEADER) && (msg.Mid(msg.GetLength() - 1, 1) == MACRO_TRAILER)) { context.writeCodeword(MACRO_05); diff --git a/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_HighLevelEncoder.h b/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_HighLevelEncoder.h index cfcca18e2b6..0b7ff9bf0ef 100644 --- a/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_HighLevelEncoder.h +++ b/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_HighLevelEncoder.h @@ -10,7 +10,6 @@ #include <vector> #include "core/fxcrt/cfx_widestring.h" -#include "fxbarcode/datamatrix/BC_SymbolShapeHint.h" #define ASCII_ENCODATION 0 #define C40_ENCODATION 1 @@ -25,12 +24,10 @@ class CBC_HighLevelEncoder { ~CBC_HighLevelEncoder(); std::vector<uint8_t>& getBytesForMessage(CFX_WideString msg); + static CFX_WideString encodeHighLevel(CFX_WideString msg, CFX_WideString ecLevel, - int32_t& e); - static CFX_WideString encodeHighLevel(CFX_WideString msg, - CFX_WideString ecLevel, - SymbolShapeHint shape, + bool allowRectangular, int32_t& e); static int32_t lookAheadTest(CFX_WideString msg, int32_t startpos, diff --git a/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_SymbolInfo.cpp b/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_SymbolInfo.cpp index ac4815a71f2..f4d99d2e1c4 100644 --- a/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_SymbolInfo.cpp +++ b/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_SymbolInfo.cpp @@ -25,7 +25,6 @@ #include "fxbarcode/common/BC_CommonBitMatrix.h" #include "fxbarcode/datamatrix/BC_DataMatrixSymbolInfo144.h" #include "fxbarcode/datamatrix/BC_Encoder.h" -#include "fxbarcode/datamatrix/BC_SymbolShapeHint.h" #include "fxbarcode/utils.h" namespace { @@ -112,14 +111,13 @@ CBC_SymbolInfo::CBC_SymbolInfo(int32_t dataCapacity, CBC_SymbolInfo::~CBC_SymbolInfo() {} CBC_SymbolInfo* CBC_SymbolInfo::lookup(int32_t dataCodewords, - SymbolShapeHint shape, + bool allowRectangular, int32_t& e) { for (size_t i = 0; i < kSymbolsCount; i++) { CBC_SymbolInfo* symbol = g_symbols[i]; - if ((shape == FORCE_SQUARE && symbol->m_rectangular) || - (shape == FORCE_RECTANGLE && !symbol->m_rectangular)) { + if (symbol->m_rectangular && !allowRectangular) continue; - } + if (dataCodewords <= symbol->dataCapacity()) return symbol; } diff --git a/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_SymbolInfo.h b/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_SymbolInfo.h index 55046f8fbe2..fe3e24c8173 100644 --- a/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_SymbolInfo.h +++ b/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_SymbolInfo.h @@ -9,7 +9,6 @@ #include "core/fxcrt/fx_string.h" #include "core/fxcrt/fx_system.h" -#include "fxbarcode/datamatrix/BC_SymbolShapeHint.h" class CBC_SymbolInfo { public: @@ -24,7 +23,7 @@ class CBC_SymbolInfo { static void Finalize(); static void overrideSymbolSet(CBC_SymbolInfo* override); static CBC_SymbolInfo* lookup(int32_t dataCodewords, - SymbolShapeHint shape, + bool allowRectangular, int32_t& e); int32_t getSymbolDataWidth() const; diff --git a/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_SymbolShapeHint.h b/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_SymbolShapeHint.h deleted file mode 100644 index 3e93988d277..00000000000 --- a/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_SymbolShapeHint.h +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2014 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 - -#ifndef FXBARCODE_DATAMATRIX_BC_SYMBOLSHAPEHINT_H_ -#define FXBARCODE_DATAMATRIX_BC_SYMBOLSHAPEHINT_H_ - -enum SymbolShapeHint { - FORCE_NONE, - FORCE_SQUARE, - FORCE_RECTANGLE, -}; - -#endif // FXBARCODE_DATAMATRIX_BC_SYMBOLSHAPEHINT_H_ diff --git a/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_TextEncoder.cpp b/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_TextEncoder.cpp index ec7ff4751fe..451c7b84d1c 100644 --- a/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_TextEncoder.cpp +++ b/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_TextEncoder.cpp @@ -26,7 +26,6 @@ #include "fxbarcode/datamatrix/BC_EncoderContext.h" #include "fxbarcode/datamatrix/BC_HighLevelEncoder.h" #include "fxbarcode/datamatrix/BC_SymbolInfo.h" -#include "fxbarcode/datamatrix/BC_SymbolShapeHint.h" #include "fxbarcode/utils.h" CBC_TextEncoder::CBC_TextEncoder() {} diff --git a/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_X12Encoder.cpp b/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_X12Encoder.cpp index 0d874b0de00..625ff902907 100644 --- a/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_X12Encoder.cpp +++ b/chromium/third_party/pdfium/fxbarcode/datamatrix/BC_X12Encoder.cpp @@ -28,7 +28,6 @@ #include "fxbarcode/datamatrix/BC_EncoderContext.h" #include "fxbarcode/datamatrix/BC_HighLevelEncoder.h" #include "fxbarcode/datamatrix/BC_SymbolInfo.h" -#include "fxbarcode/datamatrix/BC_SymbolShapeHint.h" #include "fxbarcode/utils.h" CBC_X12Encoder::CBC_X12Encoder() {} diff --git a/chromium/third_party/pdfium/fxbarcode/oned/BC_OneDimWriter.cpp b/chromium/third_party/pdfium/fxbarcode/oned/BC_OneDimWriter.cpp index a7539e4897d..22cc09513fd 100644 --- a/chromium/third_party/pdfium/fxbarcode/oned/BC_OneDimWriter.cpp +++ b/chromium/third_party/pdfium/fxbarcode/oned/BC_OneDimWriter.cpp @@ -197,7 +197,7 @@ void CBC_OneDimWriter::ShowDeviceChars(CFX_RenderDevice* device, if (matrix) { affine_matrix.Concat(*matrix); } - device->DrawNormalText(str.GetLength(), pCharPos, m_pFont, + device->DrawNormalText(str.GetLength(), pCharPos, m_pFont.Get(), static_cast<float>(iFontSize), &affine_matrix, m_fontColor, FXTEXT_CLEARTYPE); } @@ -224,7 +224,8 @@ bool CBC_OneDimWriter::ShowChars(const CFX_WideStringC& contents, } int32_t iFontSize = (int32_t)fabs(m_fFontSize); int32_t iTextHeight = iFontSize + 1; - CalcTextInfo(str, charpos.data(), m_pFont, geWidth, iFontSize, charsLen); + CalcTextInfo(str, charpos.data(), m_pFont.Get(), geWidth, iFontSize, + charsLen); if (charsLen < 1) return true; diff --git a/chromium/third_party/pdfium/fxbarcode/oned/BC_OneDimWriter.h b/chromium/third_party/pdfium/fxbarcode/oned/BC_OneDimWriter.h index 3bd1b611c64..d81a3e0a0a5 100644 --- a/chromium/third_party/pdfium/fxbarcode/oned/BC_OneDimWriter.h +++ b/chromium/third_party/pdfium/fxbarcode/oned/BC_OneDimWriter.h @@ -10,6 +10,7 @@ #include <memory> #include <vector> +#include "core/fxcrt/cfx_unowned_ptr.h" #include "core/fxge/cfx_renderdevice.h" #include "fxbarcode/BC_Library.h" #include "fxbarcode/BC_Writer.h" @@ -86,7 +87,7 @@ class CBC_OneDimWriter : public CBC_Writer { bool m_bPrintChecksum; int32_t m_iDataLenth; bool m_bCalcChecksum; - CFX_Font* m_pFont; + CFX_UnownedPtr<CFX_Font> m_pFont; float m_fFontSize; int32_t m_iFontStyle; uint32_t m_fontColor; diff --git a/chromium/third_party/pdfium/fxbarcode/oned/BC_OnedEAN13Writer.cpp b/chromium/third_party/pdfium/fxbarcode/oned/BC_OnedEAN13Writer.cpp index bae43b464ef..0e4bab95183 100644 --- a/chromium/third_party/pdfium/fxbarcode/oned/BC_OnedEAN13Writer.cpp +++ b/chromium/third_party/pdfium/fxbarcode/oned/BC_OnedEAN13Writer.cpp @@ -192,7 +192,7 @@ bool CBC_OnedEAN13Writer::ShowChars(const CFX_WideStringC& contents, iLen = tempStr.GetLength(); strWidth = (int32_t)(strWidth * m_outputHScale); - CalcTextInfo(tempStr, &charpos[1], m_pFont, (float)strWidth, iFontSize, + CalcTextInfo(tempStr, &charpos[1], m_pFont.Get(), (float)strWidth, iFontSize, blank); { CFX_Matrix affine_matrix1(1.0, 0.0, 0.0, -1.0, @@ -200,13 +200,13 @@ bool CBC_OnedEAN13Writer::ShowChars(const CFX_WideStringC& contents, (float)(m_Height - iTextHeight) + iFontSize); if (matrix) affine_matrix1.Concat(*matrix); - device->DrawNormalText(iLen, &charpos[1], m_pFont, + device->DrawNormalText(iLen, &charpos[1], m_pFont.Get(), static_cast<float>(iFontSize), &affine_matrix1, m_fontColor, FXTEXT_CLEARTYPE); } tempStr = str.Mid(7, 6); iLen = tempStr.GetLength(); - CalcTextInfo(tempStr, &charpos[7], m_pFont, (float)strWidth, iFontSize, + CalcTextInfo(tempStr, &charpos[7], m_pFont.Get(), (float)strWidth, iFontSize, blank); { CFX_Matrix affine_matrix1( @@ -215,7 +215,7 @@ bool CBC_OnedEAN13Writer::ShowChars(const CFX_WideStringC& contents, (float)(m_Height - iTextHeight + iFontSize)); if (matrix) affine_matrix1.Concat(*matrix); - device->DrawNormalText(iLen, &charpos[7], m_pFont, + device->DrawNormalText(iLen, &charpos[7], m_pFont.Get(), static_cast<float>(iFontSize), &affine_matrix1, m_fontColor, FXTEXT_CLEARTYPE); } @@ -224,14 +224,14 @@ bool CBC_OnedEAN13Writer::ShowChars(const CFX_WideStringC& contents, strWidth = multiple * 7; strWidth = (int32_t)(strWidth * m_outputHScale); - CalcTextInfo(tempStr, charpos.data(), m_pFont, (float)strWidth, iFontSize, - blank); + CalcTextInfo(tempStr, charpos.data(), m_pFont.Get(), (float)strWidth, + iFontSize, blank); { CFX_Matrix affine_matrix1(1.0, 0.0, 0.0, -1.0, 0.0, (float)(m_Height - iTextHeight + iFontSize)); if (matrix) affine_matrix1.Concat(*matrix); - device->DrawNormalText(iLen, charpos.data(), m_pFont, + device->DrawNormalText(iLen, charpos.data(), m_pFont.Get(), static_cast<float>(iFontSize), &affine_matrix1, m_fontColor, FXTEXT_CLEARTYPE); } diff --git a/chromium/third_party/pdfium/fxbarcode/oned/BC_OnedEAN8Writer.cpp b/chromium/third_party/pdfium/fxbarcode/oned/BC_OnedEAN8Writer.cpp index 49d77b72c46..f891c08fc60 100644 --- a/chromium/third_party/pdfium/fxbarcode/oned/BC_OnedEAN8Writer.cpp +++ b/chromium/third_party/pdfium/fxbarcode/oned/BC_OnedEAN8Writer.cpp @@ -184,20 +184,20 @@ bool CBC_OnedEAN8Writer::ShowChars(const CFX_WideStringC& contents, device->FillRect(&re, m_backgroundColor); strWidth = (int32_t)(strWidth * m_outputHScale); - CalcTextInfo(tempStr, charpos.data(), m_pFont, (float)strWidth, iFontSize, - blank); + CalcTextInfo(tempStr, charpos.data(), m_pFont.Get(), (float)strWidth, + iFontSize, blank); { CFX_Matrix affine_matrix1(1.0, 0.0, 0.0, -1.0, (float)leftPosition * m_outputHScale, (float)(m_Height - iTextHeight + iFontSize)); affine_matrix1.Concat(*matrix); - device->DrawNormalText(iLen, charpos.data(), m_pFont, + device->DrawNormalText(iLen, charpos.data(), m_pFont.Get(), static_cast<float>(iFontSize), &affine_matrix1, m_fontColor, FXTEXT_CLEARTYPE); } tempStr = str.Mid(4, 4); iLen = tempStr.GetLength(); - CalcTextInfo(tempStr, &charpos[4], m_pFont, (float)strWidth, iFontSize, + CalcTextInfo(tempStr, &charpos[4], m_pFont.Get(), (float)strWidth, iFontSize, blank); { CFX_Matrix affine_matrix1( @@ -206,7 +206,7 @@ bool CBC_OnedEAN8Writer::ShowChars(const CFX_WideStringC& contents, (float)(m_Height - iTextHeight + iFontSize)); if (matrix) affine_matrix1.Concat(*matrix); - device->DrawNormalText(iLen, &charpos[4], m_pFont, + device->DrawNormalText(iLen, &charpos[4], m_pFont.Get(), static_cast<float>(iFontSize), &affine_matrix1, m_fontColor, FXTEXT_CLEARTYPE); } diff --git a/chromium/third_party/pdfium/fxbarcode/oned/BC_OnedUPCAWriter.cpp b/chromium/third_party/pdfium/fxbarcode/oned/BC_OnedUPCAWriter.cpp index 614268e7420..78ada1783a1 100644 --- a/chromium/third_party/pdfium/fxbarcode/oned/BC_OnedUPCAWriter.cpp +++ b/chromium/third_party/pdfium/fxbarcode/oned/BC_OnedUPCAWriter.cpp @@ -158,20 +158,20 @@ bool CBC_OnedUPCAWriter::ShowChars(const CFX_WideStringC& contents, device->FillRect(&re, m_backgroundColor); strWidth = strWidth * m_outputHScale; - CalcTextInfo(tempStr, &charpos[1], m_pFont, strWidth, iFontSize, blank); + CalcTextInfo(tempStr, &charpos[1], m_pFont.Get(), strWidth, iFontSize, blank); { CFX_Matrix affine_matrix1(1.0, 0.0, 0.0, -1.0, (float)leftPosition * m_outputHScale, (float)(m_Height - iTextHeight + iFontSize)); if (matrix) affine_matrix1.Concat(*matrix); - device->DrawNormalText(iLen, &charpos[1], m_pFont, + device->DrawNormalText(iLen, &charpos[1], m_pFont.Get(), static_cast<float>(iFontSize), &affine_matrix1, m_fontColor, FXTEXT_CLEARTYPE); } tempStr = str.Mid(6, 5); iLen = tempStr.GetLength(); - CalcTextInfo(tempStr, &charpos[6], m_pFont, strWidth, iFontSize, blank); + CalcTextInfo(tempStr, &charpos[6], m_pFont.Get(), strWidth, iFontSize, blank); { CFX_Matrix affine_matrix1( 1.0, 0.0, 0.0, -1.0, @@ -179,7 +179,7 @@ bool CBC_OnedUPCAWriter::ShowChars(const CFX_WideStringC& contents, (float)(m_Height - iTextHeight + iFontSize)); if (matrix) affine_matrix1.Concat(*matrix); - device->DrawNormalText(iLen, &charpos[6], m_pFont, + device->DrawNormalText(iLen, &charpos[6], m_pFont.Get(), static_cast<float>(iFontSize), &affine_matrix1, m_fontColor, FXTEXT_CLEARTYPE); } @@ -188,19 +188,21 @@ bool CBC_OnedUPCAWriter::ShowChars(const CFX_WideStringC& contents, strWidth = (float)multiple * 7; strWidth = strWidth * m_outputHScale; - CalcTextInfo(tempStr, charpos.data(), m_pFont, strWidth, iFontSize, blank); + CalcTextInfo(tempStr, charpos.data(), m_pFont.Get(), strWidth, iFontSize, + blank); { CFX_Matrix affine_matrix1(1.0, 0.0, 0.0, -1.0, 0, (float)(m_Height - iTextHeight + iFontSize)); if (matrix) affine_matrix1.Concat(*matrix); - device->DrawNormalText(iLen, charpos.data(), m_pFont, + device->DrawNormalText(iLen, charpos.data(), m_pFont.Get(), static_cast<float>(iFontSize), &affine_matrix1, m_fontColor, FXTEXT_CLEARTYPE); } tempStr = str.Mid(11, 1); iLen = tempStr.GetLength(); - CalcTextInfo(tempStr, &charpos[11], m_pFont, strWidth, iFontSize, blank); + CalcTextInfo(tempStr, &charpos[11], m_pFont.Get(), strWidth, iFontSize, + blank); { CFX_Matrix affine_matrix1( 1.0, 0.0, 0.0, -1.0, @@ -208,7 +210,7 @@ bool CBC_OnedUPCAWriter::ShowChars(const CFX_WideStringC& contents, (float)(m_Height - iTextHeight + iFontSize)); if (matrix) affine_matrix1.Concat(*matrix); - device->DrawNormalText(iLen, &charpos[11], m_pFont, + device->DrawNormalText(iLen, &charpos[11], m_pFont.Get(), static_cast<float>(iFontSize), &affine_matrix1, m_fontColor, FXTEXT_CLEARTYPE); } diff --git a/chromium/third_party/pdfium/fxbarcode/pdf417/BC_PDF417HighLevelEncoder_unittest.cpp b/chromium/third_party/pdfium/fxbarcode/pdf417/BC_PDF417HighLevelEncoder_unittest.cpp index b4b9396d84e..478fcf50df8 100644 --- a/chromium/third_party/pdfium/fxbarcode/pdf417/BC_PDF417HighLevelEncoder_unittest.cpp +++ b/chromium/third_party/pdfium/fxbarcode/pdf417/BC_PDF417HighLevelEncoder_unittest.cpp @@ -4,7 +4,6 @@ #include "core/fxcrt/fx_basic.h" #include "fxbarcode/pdf417/BC_PDF417HighLevelEncoder.h" -#include "testing/fx_string_testhelpers.h" #include "testing/gtest/include/gtest/gtest.h" TEST(PDF417HighLevelEncoder, EncodeHighLevel) { diff --git a/chromium/third_party/pdfium/fxbarcode/qrcode/BC_QRCoder.cpp b/chromium/third_party/pdfium/fxbarcode/qrcode/BC_QRCoder.cpp index e3ac763499f..b0a24fa27c4 100644 --- a/chromium/third_party/pdfium/fxbarcode/qrcode/BC_QRCoder.cpp +++ b/chromium/third_party/pdfium/fxbarcode/qrcode/BC_QRCoder.cpp @@ -42,11 +42,11 @@ CBC_QRCoder::CBC_QRCoder() CBC_QRCoder::~CBC_QRCoder() {} CBC_QRCoderMode* CBC_QRCoder::GetMode() const { - return m_mode; + return m_mode.Get(); } const CBC_QRCoderErrorCorrectionLevel* CBC_QRCoder::GetECLevel() const { - return m_ecLevel; + return m_ecLevel.Get(); } int32_t CBC_QRCoder::GetVersion() const { diff --git a/chromium/third_party/pdfium/fxbarcode/qrcode/BC_QRCoder.h b/chromium/third_party/pdfium/fxbarcode/qrcode/BC_QRCoder.h index adeae6c5210..fe34b5250b4 100644 --- a/chromium/third_party/pdfium/fxbarcode/qrcode/BC_QRCoder.h +++ b/chromium/third_party/pdfium/fxbarcode/qrcode/BC_QRCoder.h @@ -9,6 +9,8 @@ #include <memory> +#include "core/fxcrt/cfx_unowned_ptr.h" + class CBC_QRCoderErrorCorrectionLevel; class CBC_QRCoderMode; class CBC_CommonByteMatrix; @@ -48,8 +50,8 @@ class CBC_QRCoder { void SetMatrix(std::unique_ptr<CBC_CommonByteMatrix> pMatrix); private: - CBC_QRCoderMode* m_mode; - const CBC_QRCoderErrorCorrectionLevel* m_ecLevel; + CFX_UnownedPtr<CBC_QRCoderMode> m_mode; + CFX_UnownedPtr<const CBC_QRCoderErrorCorrectionLevel> m_ecLevel; int32_t m_version; int32_t m_matrixWidth; int32_t m_maskPattern; diff --git a/chromium/third_party/pdfium/fxjs/README b/chromium/third_party/pdfium/fxjs/README new file mode 100644 index 00000000000..99d2f90bd80 --- /dev/null +++ b/chromium/third_party/pdfium/fxjs/README @@ -0,0 +1,33 @@ +There are two separate wrappers for V8 here. One is called FXJS, and +it is used by the non-XFA code. The other is called FXJSE, and it is +used only by the XFA code. Additionally FXJSE may request services +from FXJS to bridge the two. + +Both the FXJS and FXJSE binding code needs to be replaced by something +saner, perhaps Gin or perhaps some IDL. See + https://bugs.chromium.org/p/pdfium/issues/detail?id=716 +for progress on the issue. + +FXJS binds objects by sticking a pointer to a CFXJS_PerObjectData in +the V8 object's internal slot. FXJSE binds objects by sticking a +pointer to either an actual v8 function object or a CFXJSE_HostObject +in the the V8 object's internal slot, depending upon whether the object +represents (in some notion) a "class" or an "instance". Also, V8 objects +bound in one library may unexpectedly arrive at the other given a script +that's trying to mess with us. + +To distinguish these cases, we use two internal slots for all bound +objects, regardless of the FXJS/FXJSE distinction. Slot 0 is the +tag and contains either: + kPerObjectDataTag for FXJS objects, or + g_FXJSETagString for FXJSE Host objects, or + One of 4 specific FXJSE_CLASS_DESCRIPTOR globals for FXJSE classes: + GlobalClassDescriptor + NormalClassDescriptor + VariablesClassDescriptor + formcalc_fm2js_descriptor + +Slot 1's contents are determined by these tags: + kPerObjectDataTag means to expect a CFXJS_PerObjectData. + g_FXJSETagString means to expect a CFXJSE_HostObject. + A FXJSE_CLASS_DESCRIPTOR pointer means to expect a v8 function. diff --git a/chromium/third_party/pdfium/fxjs/cfxjse_arguments.cpp b/chromium/third_party/pdfium/fxjs/cfxjse_arguments.cpp index f406ba34de4..363f39ce11d 100644 --- a/chromium/third_party/pdfium/fxjs/cfxjse_arguments.cpp +++ b/chromium/third_party/pdfium/fxjs/cfxjse_arguments.cpp @@ -10,6 +10,13 @@ #include "fxjs/cfxjse_value.h" #include "third_party/base/ptr_util.h" +CFXJSE_Arguments::CFXJSE_Arguments( + const v8::FunctionCallbackInfo<v8::Value>* pInfo, + CFXJSE_Value* pRetValue) + : m_pInfo(pInfo), m_pRetValue(pRetValue) {} + +CFXJSE_Arguments::~CFXJSE_Arguments() {} + int32_t CFXJSE_Arguments::GetLength() const { return m_pInfo->Length(); } @@ -47,6 +54,6 @@ CFXJSE_HostObject* CFXJSE_Arguments::GetObject(int32_t index, return FXJSE_RetrieveObjectBinding(hValue.As<v8::Object>(), pClass); } -CFXJSE_Value* CFXJSE_Arguments::GetReturnValue() { - return m_pRetValue; +CFXJSE_Value* CFXJSE_Arguments::GetReturnValue() const { + return m_pRetValue.Get(); } diff --git a/chromium/third_party/pdfium/fxjs/cfxjse_arguments.h b/chromium/third_party/pdfium/fxjs/cfxjse_arguments.h index beaf1525bba..9317d708982 100644 --- a/chromium/third_party/pdfium/fxjs/cfxjse_arguments.h +++ b/chromium/third_party/pdfium/fxjs/cfxjse_arguments.h @@ -9,14 +9,15 @@ #include <memory> +#include "core/fxcrt/cfx_unowned_ptr.h" #include "fxjs/cfxjse_class.h" #include "fxjs/fxjse.h" class CFXJSE_Arguments { public: CFXJSE_Arguments(const v8::FunctionCallbackInfo<v8::Value>* pInfo, - CFXJSE_Value* pRetValue) - : m_pInfo(pInfo), m_pRetValue(pRetValue) {} + CFXJSE_Value* pRetValue); + ~CFXJSE_Arguments(); int32_t GetLength() const; std::unique_ptr<CFXJSE_Value> GetValue(int32_t index) const; @@ -26,11 +27,11 @@ class CFXJSE_Arguments { CFX_ByteString GetUTF8String(int32_t index) const; CFXJSE_HostObject* GetObject(int32_t index, CFXJSE_Class* pClass = nullptr) const; - CFXJSE_Value* GetReturnValue(); + CFXJSE_Value* GetReturnValue() const; private: const v8::FunctionCallbackInfo<v8::Value>* m_pInfo; - CFXJSE_Value* m_pRetValue; + CFX_UnownedPtr<CFXJSE_Value> m_pRetValue; }; #endif // FXJS_CFXJSE_ARGUMENTS_H_ diff --git a/chromium/third_party/pdfium/fxjs/cfxjse_class.h b/chromium/third_party/pdfium/fxjs/cfxjse_class.h index 04354941fa2..c3a5c84777c 100644 --- a/chromium/third_party/pdfium/fxjs/cfxjse_class.h +++ b/chromium/third_party/pdfium/fxjs/cfxjse_class.h @@ -7,6 +7,7 @@ #ifndef FXJS_CFXJSE_CLASS_H_ #define FXJS_CFXJSE_CLASS_H_ +#include "core/fxcrt/cfx_unowned_ptr.h" #include "fxjs/fxjse.h" #include "v8/include/v8.h" @@ -27,13 +28,13 @@ class CFXJSE_Class { explicit CFXJSE_Class(CFXJSE_Context* lpContext); ~CFXJSE_Class(); - CFXJSE_Context* GetContext() const { return m_pContext; } + CFXJSE_Context* GetContext() const { return m_pContext.Get(); } v8::Global<v8::FunctionTemplate>& GetTemplate() { return m_hTemplate; } protected: CFX_ByteString m_szClassName; - const FXJSE_CLASS_DESCRIPTOR* m_lpClassDefinition; - CFXJSE_Context* m_pContext; + CFX_UnownedPtr<const FXJSE_CLASS_DESCRIPTOR> m_lpClassDefinition; + CFX_UnownedPtr<CFXJSE_Context> m_pContext; v8::Global<v8::FunctionTemplate> m_hTemplate; friend class CFXJSE_Context; friend class CFXJSE_Value; diff --git a/chromium/third_party/pdfium/fxjs/cfxjse_context.cpp b/chromium/third_party/pdfium/fxjs/cfxjse_context.cpp index 8696cee42f2..40882bac56a 100644 --- a/chromium/third_party/pdfium/fxjs/cfxjse_context.cpp +++ b/chromium/third_party/pdfium/fxjs/cfxjse_context.cpp @@ -68,7 +68,7 @@ class CFXJSE_ScopeUtil_IsolateHandleContext { void* operator new(size_t size) = delete; void operator delete(void*, size_t) = delete; - CFXJSE_Context* m_context; + CFX_UnownedPtr<CFXJSE_Context> m_context; CFXJSE_ScopeUtil_IsolateHandle m_parent; v8::Context::Scope m_cscope; }; diff --git a/chromium/third_party/pdfium/fxjs/cfxjse_value.cpp b/chromium/third_party/pdfium/fxjs/cfxjse_value.cpp index fb7fe20e21b..c2eaa408a42 100644 --- a/chromium/third_party/pdfium/fxjs/cfxjse_value.cpp +++ b/chromium/third_party/pdfium/fxjs/cfxjse_value.cpp @@ -58,7 +58,7 @@ void FXJSE_ThrowMessage(const CFX_ByteStringC& utf8Message) { CFXJSE_ScopeUtil_IsolateHandleRootContext scope(pIsolate); v8::Local<v8::String> hMessage = v8::String::NewFromUtf8( - pIsolate, utf8Message.c_str(), v8::String::kNormalString, + pIsolate, utf8Message.unterminated_c_str(), v8::String::kNormalString, utf8Message.GetLength()); v8::Local<v8::Value> hError = v8::Exception::Error(hMessage); pIsolate->ThrowException(hError); @@ -138,7 +138,7 @@ bool CFXJSE_Value::SetObjectProperty(const CFX_ByteStringC& szPropName, v8::Local<v8::Value> hPropValue = v8::Local<v8::Value>::New(m_pIsolate, lpPropValue->DirectGetValue()); return (bool)hObject.As<v8::Object>()->Set( - v8::String::NewFromUtf8(m_pIsolate, szPropName.c_str(), + v8::String::NewFromUtf8(m_pIsolate, szPropName.unterminated_c_str(), v8::String::kNormalString, szPropName.GetLength()), hPropValue); @@ -155,8 +155,8 @@ bool CFXJSE_Value::GetObjectProperty(const CFX_ByteStringC& szPropName, v8::Local<v8::Value> hPropValue = hObject.As<v8::Object>()->Get(v8::String::NewFromUtf8( - m_pIsolate, szPropName.c_str(), v8::String::kNormalString, - szPropName.GetLength())); + m_pIsolate, szPropName.unterminated_c_str(), + v8::String::kNormalString, szPropName.GetLength())); lpPropValue->ForceSetValue(hPropValue); return true; } @@ -195,7 +195,7 @@ bool CFXJSE_Value::DeleteObjectProperty(const CFX_ByteStringC& szPropName) { return false; hObject.As<v8::Object>()->Delete(v8::String::NewFromUtf8( - m_pIsolate, szPropName.c_str(), v8::String::kNormalString, + m_pIsolate, szPropName.unterminated_c_str(), v8::String::kNormalString, szPropName.GetLength())); return true; } @@ -209,7 +209,7 @@ bool CFXJSE_Value::HasObjectOwnProperty(const CFX_ByteStringC& szPropName, return false; v8::Local<v8::String> hKey = v8::String::NewFromUtf8( - m_pIsolate, szPropName.c_str(), v8::String::kNormalString, + m_pIsolate, szPropName.unterminated_c_str(), v8::String::kNormalString, szPropName.GetLength()); return hObject.As<v8::Object>()->HasRealNamedProperty(hKey) || (bUseTypeGetter && @@ -232,7 +232,7 @@ bool CFXJSE_Value::SetObjectOwnProperty(const CFX_ByteStringC& szPropName, return hObject.As<v8::Object>() ->DefineOwnProperty( m_pIsolate->GetCurrentContext(), - v8::String::NewFromUtf8(m_pIsolate, szPropName.c_str(), + v8::String::NewFromUtf8(m_pIsolate, szPropName.unterminated_c_str(), v8::String::kNormalString, szPropName.GetLength()), pValue) diff --git a/chromium/third_party/pdfium/fxjs/fxjs_v8.cpp b/chromium/third_party/pdfium/fxjs/fxjs_v8.cpp index 10aa51395ed..d3d2010b304 100644 --- a/chromium/third_party/pdfium/fxjs/fxjs_v8.cpp +++ b/chromium/third_party/pdfium/fxjs/fxjs_v8.cpp @@ -171,15 +171,16 @@ void V8TemplateMapTraits::Dispose(v8::Isolate* isolate, v8::Local<v8::Object> obj = value.Get(isolate); if (obj.IsEmpty()) return; - CFXJS_Engine* pEngine = CFXJS_Engine::CurrentEngineFromIsolate(isolate); - int id = pEngine->GetObjDefnID(obj); + int id = CFXJS_Engine::GetObjDefnID(obj); if (id == -1) return; CFXJS_ObjDefinition* pObjDef = CFXJS_ObjDefinition::ForID(isolate, id); if (!pObjDef) return; - if (pObjDef->m_pDestructor) - pObjDef->m_pDestructor(pEngine, obj); + if (pObjDef->m_pDestructor) { + pObjDef->m_pDestructor(CFXJS_Engine::CurrentEngineFromIsolate(isolate), + obj); + } CFXJS_Engine::FreeObjectPrivate(obj); } @@ -310,11 +311,8 @@ void CFXJS_Engine::DefineObjMethod(int nObjDefnID, v8::Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New( m_isolate, pMethodCall, v8::Local<v8::Value>(), pObjDef->GetSignature()); fun->RemovePrototype(); - pObjDef->GetInstanceTemplate()->Set( - v8::String::NewFromUtf8(m_isolate, sMethodName, - v8::NewStringType::kNormal) - .ToLocalChecked(), - fun, v8::ReadOnly); + pObjDef->GetInstanceTemplate()->Set(NewString(sMethodName), fun, + v8::ReadOnly); } void CFXJS_Engine::DefineObjProperty(int nObjDefnID, @@ -325,10 +323,8 @@ void CFXJS_Engine::DefineObjProperty(int nObjDefnID, v8::HandleScope handle_scope(m_isolate); CFXJS_ObjDefinition* pObjDef = CFXJS_ObjDefinition::ForID(m_isolate, nObjDefnID); - pObjDef->GetInstanceTemplate()->SetAccessor( - v8::String::NewFromUtf8(m_isolate, sPropName, v8::NewStringType::kNormal) - .ToLocalChecked(), - pPropGet, pPropPut); + pObjDef->GetInstanceTemplate()->SetAccessor(NewString(sPropName), pPropGet, + pPropPut); } void CFXJS_Engine::DefineObjAllProperties( @@ -362,26 +358,19 @@ void CFXJS_Engine::DefineGlobalMethod(const char* sMethodName, v8::Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(m_isolate, pMethodCall); fun->RemovePrototype(); - GetGlobalObjectTemplate(m_isolate)->Set( - v8::String::NewFromUtf8(m_isolate, sMethodName, - v8::NewStringType::kNormal) - .ToLocalChecked(), - fun, v8::ReadOnly); + GetGlobalObjectTemplate(m_isolate)->Set(NewString(sMethodName), fun, + v8::ReadOnly); } void CFXJS_Engine::DefineGlobalConst(const wchar_t* sConstName, v8::FunctionCallback pConstGetter) { v8::Isolate::Scope isolate_scope(m_isolate); v8::HandleScope handle_scope(m_isolate); - CFX_ByteString bsConst = FX_UTF8Encode(CFX_WideStringC(sConstName)); v8::Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(m_isolate, pConstGetter); fun->RemovePrototype(); - GetGlobalObjectTemplate(m_isolate)->SetAccessorProperty( - v8::String::NewFromUtf8(m_isolate, bsConst.c_str(), - v8::NewStringType::kNormal) - .ToLocalChecked(), - fun); + GetGlobalObjectTemplate(m_isolate)->SetAccessorProperty(NewString(sConstName), + fun); } void CFXJS_Engine::InitializeEngine() { @@ -418,12 +407,7 @@ void CFXJS_Engine::InitializeEngine() { .ToLocalChecked()); } } else if (pObjDef->m_ObjType == FXJSOBJTYPE_STATIC) { - v8::Local<v8::String> pObjName = - v8::String::NewFromUtf8(m_isolate, pObjDef->m_ObjName, - v8::NewStringType::kNormal, - strlen(pObjDef->m_ObjName)) - .ToLocalChecked(); - + v8::Local<v8::String> pObjName = NewString(pObjDef->m_ObjName); v8::Local<v8::Object> obj = NewFxDynamicObj(i, true); v8Context->Global()->Set(v8Context, pObjName, obj).FromJust(); m_StaticObjects[i] = new v8::Global<v8::Object>(m_isolate, obj); @@ -438,7 +422,6 @@ void CFXJS_Engine::ReleaseEngine() { v8::Local<v8::Context> context = v8::Local<v8::Context>::New(m_isolate, m_V8PersistentContext); v8::Context::Scope context_scope(context); - FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(m_isolate); if (!pData) return; @@ -477,14 +460,9 @@ void CFXJS_Engine::ReleaseEngine() { int CFXJS_Engine::Execute(const CFX_WideString& script, FXJSErr* pError) { v8::Isolate::Scope isolate_scope(m_isolate); v8::TryCatch try_catch(m_isolate); - CFX_ByteString bsScript = script.UTF8Encode(); v8::Local<v8::Context> context = m_isolate->GetCurrentContext(); v8::Local<v8::Script> compiled_script; - if (!v8::Script::Compile(context, - v8::String::NewFromUtf8(m_isolate, bsScript.c_str(), - v8::NewStringType::kNormal, - bsScript.GetLength()) - .ToLocalChecked()) + if (!v8::Script::Compile(context, NewString(script.AsStringC())) .ToLocal(&compiled_script)) { v8::String::Utf8Value error(try_catch.Exception()); // TODO(tsepez): return error via pError->message. @@ -547,14 +525,7 @@ v8::Local<v8::Object> CFXJS_Engine::GetThisObj() { } void CFXJS_Engine::Error(const CFX_WideString& message) { - // Conversion from pdfium's wchar_t wide-strings to v8's uint16_t - // wide-strings isn't handled by v8, so use UTF8 as a common - // intermediate format. - CFX_ByteString utf8_message = message.UTF8Encode(); - m_isolate->ThrowException(v8::String::NewFromUtf8(m_isolate, - utf8_message.c_str(), - v8::NewStringType::kNormal) - .ToLocalChecked()); + m_isolate->ThrowException(NewString(message.AsStringC())); } void CFXJS_Engine::SetObjectPrivate(v8::Local<v8::Object> pObj, void* p) { @@ -659,30 +630,33 @@ v8::Local<v8::Context> CFXJS_Engine::GetPersistentContext() { return m_V8PersistentContext.Get(m_isolate); } -v8::Local<v8::Value> CFXJS_Engine::NewNumber(int number) { +v8::Local<v8::Number> CFXJS_Engine::NewNumber(int number) { return v8::Int32::New(m_isolate, number); } -v8::Local<v8::Value> CFXJS_Engine::NewNumber(double number) { +v8::Local<v8::Number> CFXJS_Engine::NewNumber(double number) { return v8::Number::New(m_isolate, number); } -v8::Local<v8::Value> CFXJS_Engine::NewNumber(float number) { +v8::Local<v8::Number> CFXJS_Engine::NewNumber(float number) { return v8::Number::New(m_isolate, (float)number); } -v8::Local<v8::Value> CFXJS_Engine::NewBoolean(bool b) { +v8::Local<v8::Boolean> CFXJS_Engine::NewBoolean(bool b) { return v8::Boolean::New(m_isolate, b); } -v8::Local<v8::Value> CFXJS_Engine::NewString(const CFX_ByteStringC& str) { +v8::Local<v8::String> CFXJS_Engine::NewString(const CFX_ByteStringC& str) { v8::Isolate* pIsolate = m_isolate ? m_isolate : v8::Isolate::GetCurrent(); - return v8::String::NewFromUtf8(pIsolate, str.c_str(), + return v8::String::NewFromUtf8(pIsolate, str.unterminated_c_str(), v8::NewStringType::kNormal, str.GetLength()) .ToLocalChecked(); } -v8::Local<v8::Value> CFXJS_Engine::NewString(const CFX_WideStringC& str) { +v8::Local<v8::String> CFXJS_Engine::NewString(const CFX_WideStringC& str) { + // Conversion from pdfium's wchar_t wide-strings to v8's uint16_t + // wide-strings isn't handled by v8, so use UTF8 as a common + // intermediate format. return NewString(FX_UTF8Encode(str).AsStringC()); } @@ -700,28 +674,40 @@ int CFXJS_Engine::ToInt32(v8::Local<v8::Value> pValue) { if (pValue.IsEmpty()) return 0; v8::Local<v8::Context> context = m_isolate->GetCurrentContext(); - return pValue->ToInt32(context).ToLocalChecked()->Value(); + v8::MaybeLocal<v8::Int32> maybe_int32 = pValue->ToInt32(context); + if (maybe_int32.IsEmpty()) + return 0; + return maybe_int32.ToLocalChecked()->Value(); } bool CFXJS_Engine::ToBoolean(v8::Local<v8::Value> pValue) { if (pValue.IsEmpty()) return false; v8::Local<v8::Context> context = m_isolate->GetCurrentContext(); - return pValue->ToBoolean(context).ToLocalChecked()->Value(); + v8::MaybeLocal<v8::Boolean> maybe_boolean = pValue->ToBoolean(context); + if (maybe_boolean.IsEmpty()) + return false; + return maybe_boolean.ToLocalChecked()->Value(); } double CFXJS_Engine::ToDouble(v8::Local<v8::Value> pValue) { if (pValue.IsEmpty()) return 0.0; v8::Local<v8::Context> context = m_isolate->GetCurrentContext(); - return pValue->ToNumber(context).ToLocalChecked()->Value(); + v8::MaybeLocal<v8::Number> maybe_number = pValue->ToNumber(context); + if (maybe_number.IsEmpty()) + return 0.0; + return maybe_number.ToLocalChecked()->Value(); } CFX_WideString CFXJS_Engine::ToWideString(v8::Local<v8::Value> pValue) { if (pValue.IsEmpty()) return CFX_WideString(); v8::Local<v8::Context> context = m_isolate->GetCurrentContext(); - v8::String::Utf8Value s(pValue->ToString(context).ToLocalChecked()); + v8::MaybeLocal<v8::String> maybe_string = pValue->ToString(context); + if (maybe_string.IsEmpty()) + return CFX_WideString(); + v8::String::Utf8Value s(maybe_string.ToLocalChecked()); return CFX_WideString::FromUTF8(CFX_ByteStringC(*s, s.length())); } diff --git a/chromium/third_party/pdfium/fxjs/fxjs_v8.h b/chromium/third_party/pdfium/fxjs/fxjs_v8.h index d44af2f8fab..cdec942d4bb 100644 --- a/chromium/third_party/pdfium/fxjs/fxjs_v8.h +++ b/chromium/third_party/pdfium/fxjs/fxjs_v8.h @@ -182,12 +182,12 @@ class CFXJS_Engine { v8::Local<v8::Value> NewNull(); v8::Local<v8::Array> NewArray(); - v8::Local<v8::Value> NewNumber(int number); - v8::Local<v8::Value> NewNumber(double number); - v8::Local<v8::Value> NewNumber(float number); - v8::Local<v8::Value> NewBoolean(bool b); - v8::Local<v8::Value> NewString(const CFX_ByteStringC& str); - v8::Local<v8::Value> NewString(const CFX_WideStringC& str); + v8::Local<v8::Number> NewNumber(int number); + v8::Local<v8::Number> NewNumber(double number); + v8::Local<v8::Number> NewNumber(float number); + v8::Local<v8::Boolean> NewBoolean(bool b); + v8::Local<v8::String> NewString(const CFX_ByteStringC& str); + v8::Local<v8::String> NewString(const CFX_WideStringC& str); v8::Local<v8::Date> NewDate(double d); v8::Local<v8::Object> NewFxDynamicObj(int nObjDefnID, bool bStatic = false); diff --git a/chromium/third_party/pdfium/fxjs/fxjse.h b/chromium/third_party/pdfium/fxjs/fxjse.h index a29c0893af9..8fc514bba35 100644 --- a/chromium/third_party/pdfium/fxjs/fxjse.h +++ b/chromium/third_party/pdfium/fxjs/fxjse.h @@ -14,10 +14,20 @@ class CFXJSE_Arguments; class CFXJSE_Value; -// C++ object which can be wrapped by CFXJSE_value. +// C++ object which is retrieved from v8 object's slot. class CFXJSE_HostObject { public: virtual ~CFXJSE_HostObject() {} + + // Small layering violation here, but we need to distinguish between the + // two kinds of subclasses. + enum Type { kXFA, kFM2JS }; + Type type() const { return type_; } + + protected: + explicit CFXJSE_HostObject(Type type) { type_ = type; } + + Type type_; }; typedef void (*FXJSE_FuncCallback)(CFXJSE_Value* pThis, diff --git a/chromium/third_party/pdfium/pdfium.gni b/chromium/third_party/pdfium/pdfium.gni index d9bdfb6687d..530301a5d9b 100644 --- a/chromium/third_party/pdfium/pdfium.gni +++ b/chromium/third_party/pdfium/pdfium.gni @@ -50,6 +50,9 @@ declare_args() { # Build a complete static library pdf_is_complete_lib = false + # Enable callgrind for performance profiling + enable_callgrind = false + # Enable coverage information use_coverage = false diff --git a/chromium/third_party/pdfium/public/fpdf_annot.h b/chromium/third_party/pdfium/public/fpdf_annot.h new file mode 100644 index 00000000000..c0f9a6e4c6c --- /dev/null +++ b/chromium/third_party/pdfium/public/fpdf_annot.h @@ -0,0 +1,432 @@ +// Copyright 2017 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. + +#ifndef PUBLIC_FPDF_ANNOT_H_ +#define PUBLIC_FPDF_ANNOT_H_ + +// NOLINTNEXTLINE(build/include) +#include "fpdfview.h" + +#include "fpdf_doc.h" +#include "fpdf_formfill.h" + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +#define FPDF_ANNOT_UNKNOWN 0 +#define FPDF_ANNOT_TEXT 1 +#define FPDF_ANNOT_LINK 2 +#define FPDF_ANNOT_FREETEXT 3 +#define FPDF_ANNOT_LINE 4 +#define FPDF_ANNOT_SQUARE 5 +#define FPDF_ANNOT_CIRCLE 6 +#define FPDF_ANNOT_POLYGON 7 +#define FPDF_ANNOT_POLYLINE 8 +#define FPDF_ANNOT_HIGHLIGHT 9 +#define FPDF_ANNOT_UNDERLINE 10 +#define FPDF_ANNOT_SQUIGGLY 11 +#define FPDF_ANNOT_STRIKEOUT 12 +#define FPDF_ANNOT_STAMP 13 +#define FPDF_ANNOT_CARET 14 +#define FPDF_ANNOT_INK 15 +#define FPDF_ANNOT_POPUP 16 +#define FPDF_ANNOT_FILEATTACHMENT 17 +#define FPDF_ANNOT_SOUND 18 +#define FPDF_ANNOT_MOVIE 19 +#define FPDF_ANNOT_WIDGET 20 +#define FPDF_ANNOT_SCREEN 21 +#define FPDF_ANNOT_PRINTERMARK 22 +#define FPDF_ANNOT_TRAPNET 23 +#define FPDF_ANNOT_WATERMARK 24 +#define FPDF_ANNOT_THREED 25 +#define FPDF_ANNOT_RICHMEDIA 26 +#define FPDF_ANNOT_XFAWIDGET 27 + +// Refer to PDF Reference (6th edition) table 8.16 for all annotation flags. +#define FPDF_ANNOT_FLAG_NONE 0 +#define FPDF_ANNOT_FLAG_INVISIBLE (1 << 0) +#define FPDF_ANNOT_FLAG_HIDDEN (1 << 1) +#define FPDF_ANNOT_FLAG_PRINT (1 << 2) +#define FPDF_ANNOT_FLAG_NOZOOM (1 << 3) +#define FPDF_ANNOT_FLAG_NOROTATE (1 << 4) +#define FPDF_ANNOT_FLAG_NOVIEW (1 << 5) +#define FPDF_ANNOT_FLAG_READONLY (1 << 6) +#define FPDF_ANNOT_FLAG_LOCKED (1 << 7) +#define FPDF_ANNOT_FLAG_TOGGLENOVIEW (1 << 8) + +#define FPDF_OBJECT_UNKNOWN 0 +#define FPDF_OBJECT_BOOLEAN 1 +#define FPDF_OBJECT_NUMBER 2 +#define FPDF_OBJECT_STRING 3 +#define FPDF_OBJECT_NAME 4 +#define FPDF_OBJECT_ARRAY 5 +#define FPDF_OBJECT_DICTIONARY 6 +#define FPDF_OBJECT_STREAM 7 +#define FPDF_OBJECT_NULLOBJ 8 +#define FPDF_OBJECT_REFERENCE 9 + +// Refer to PDF Reference version 1.7 table 8.70 for field flags common to all +// interactive form field types. +#define FPDF_FORMFLAG_NONE 0 +#define FPDF_FORMFLAG_READONLY (1 << 0) +#define FPDF_FORMFLAG_REQUIRED (1 << 1) +#define FPDF_FORMFLAG_NOEXPORT (1 << 2) + +// Refer to PDF Reference version 1.7 table 8.77 for field flags specific to +// interactive form text fields. +#define FPDF_FORMFLAG_TEXT_MULTILINE (1 << 12) + +// Refer to PDF Reference version 1.7 table 8.79 for field flags specific to +// interactive form choice fields. +#define FPDF_FORMFLAG_CHOICE_COMBO (1 << 17) +#define FPDF_FORMFLAG_CHOICE_EDIT (1 << 18) + +typedef enum FPDFANNOT_COLORTYPE { + FPDFANNOT_COLORTYPE_Color = 0, + FPDFANNOT_COLORTYPE_InteriorColor +} FPDFANNOT_COLORTYPE; + +// Experimental API. +// Check if an annotation subtype is currently supported for creation. +// Currently supported subtypes: circle, highlight, ink, popup, square, +// squiggly, stamp, strikeout, text, and underline. +// +// subtype - the subtype to be checked. +// +// Returns true if this subtype supported. +DLLEXPORT FPDF_BOOL STDCALL +FPDFAnnot_IsSupportedSubtype(FPDF_ANNOTATION_SUBTYPE subtype); + +// Experimental API. +// Create an annotation in |page| of the subtype |subtype|. If the specified +// subtype is illegal or unsupported, then a new annotation will not be created. +// Must call FPDFPage_CloseAnnot() when the annotation returned by this +// function is no longer needed. +// +// page - handle to a page. +// subtype - the subtype of the new annotation. +// +// Returns a handle to the new annotation object, or NULL on failure. +DLLEXPORT FPDF_ANNOTATION STDCALL +FPDFPage_CreateAnnot(FPDF_PAGE page, FPDF_ANNOTATION_SUBTYPE subtype); + +// Experimental API. +// Get the number of annotations in |page|. +// +// page - handle to a page. +// +// Returns the number of annotations in |page|. +DLLEXPORT int STDCALL FPDFPage_GetAnnotCount(FPDF_PAGE page); + +// Experimental API. +// Get annotation in |page| at |index|. Must call FPDFPage_CloseAnnot() when the +// annotation returned by this function is no longer needed. +// +// page - handle to a page. +// index - the index of the annotation. +// +// Returns a handle to the annotation object, or NULL on failure. +DLLEXPORT FPDF_ANNOTATION STDCALL FPDFPage_GetAnnot(FPDF_PAGE page, int index); + +// Experimental API. +// Close an annotation. Must be called when the annotation returned by +// FPDFPage_CreateAnnot() or FPDFPage_GetAnnot() is no longer needed. This +// function does not remove the annotation from the document. +// +// annot - handle to an annotation. +DLLEXPORT void STDCALL FPDFPage_CloseAnnot(FPDF_ANNOTATION annot); + +// Experimental API. +// Remove the annotation in |page| at |index|. +// +// page - handle to a page. +// index - the index of the annotation. +// +// Returns true if successful. +DLLEXPORT FPDF_BOOL STDCALL FPDFPage_RemoveAnnot(FPDF_PAGE page, int index); + +// Experimental API. +// Get the subtype of an annotation. +// +// annot - handle to an annotation. +// +// Returns the annotation subtype. +DLLEXPORT FPDF_ANNOTATION_SUBTYPE STDCALL +FPDFAnnot_GetSubtype(FPDF_ANNOTATION annot); + +// Experimental API. +// Check if an annotation subtype is currently supported for object extraction, +// update, and removal. +// Currently supported subtypes: ink and stamp. +// +// subtype - the subtype to be checked. +// +// Returns true if this subtype supported. +DLLEXPORT FPDF_BOOL STDCALL +FPDFAnnot_IsObjectSupportedSubtype(FPDF_ANNOTATION_SUBTYPE subtype); + +// Experimental API. +// Update |obj| in |annot|. |obj| must be in |annot| already and must have +// been retrieved by FPDFAnnot_GetObject(). Currently, only ink and stamp +// annotations are supported by this API. Also note that only path, image, and +// text objects have APIs for modification; see FPDFPath_*(), FPDFText_*(), and +// FPDFImageObj_*(). +// +// annot - handle to an annotation. +// obj - handle to the object that |annot| needs to update. +// +// Return true if successful. +DLLEXPORT FPDF_BOOL STDCALL FPDFAnnot_UpdateObject(FPDF_ANNOTATION annot, + FPDF_PAGEOBJECT obj); + +// Experimental API. +// Add |obj| to |annot|. |obj| must have been created by +// FPDFPageObj_CreateNew{Path|Rect}() or FPDFPageObj_New{Text|Image}Obj(), and +// will be owned by |annot|. Note that an |obj| cannot belong to more than one +// |annot|. Currently, only ink and stamp annotations are supported by this API. +// Also note that only path, image, and text objects have APIs for creation. +// +// annot - handle to an annotation. +// obj - handle to the object that is to be added to |annot|. +// +// Return true if successful. +DLLEXPORT FPDF_BOOL STDCALL FPDFAnnot_AppendObject(FPDF_ANNOTATION annot, + FPDF_PAGEOBJECT obj); + +// Experimental API. +// Get the total number of objects in |annot|, including path objects, text +// objects, external objects, image objects, and shading objects. +// +// annot - handle to an annotation. +// +// Returns the number of objects in |annot|. +DLLEXPORT int STDCALL FPDFAnnot_GetObjectCount(FPDF_ANNOTATION annot); + +// Experimental API. +// Get the object in |annot| at |index|. +// +// annot - handle to an annotation. +// index - the index of the object. +// +// Return a handle to the object, or NULL on failure. +DLLEXPORT FPDF_PAGEOBJECT STDCALL FPDFAnnot_GetObject(FPDF_ANNOTATION annot, + int index); + +// Experimental API. +// Remove the object in |annot| at |index|. +// +// annot - handle to an annotation. +// index - the index of the object to be removed. +// +// Return true if successful. +DLLEXPORT FPDF_BOOL STDCALL FPDFAnnot_RemoveObject(FPDF_ANNOTATION annot, + int index); + +// Experimental API. +// Set the color of an annotation. Fails when called on annotations with +// appearance streams already defined; instead use +// FPDFPath_Set{Stroke|Fill}Color(). +// +// annot - handle to an annotation. +// type - type of the color to be set. +// R, G, B - buffer to hold the RGB value of the color. Ranges from 0 to 255. +// A - buffer to hold the opacity. Ranges from 0 to 255. +// +// Returns true if successful. +DLLEXPORT FPDF_BOOL STDCALL FPDFAnnot_SetColor(FPDF_ANNOTATION annot, + FPDFANNOT_COLORTYPE type, + unsigned int R, + unsigned int G, + unsigned int B, + unsigned int A); + +// Experimental API. +// Get the color of an annotation. If no color is specified, default to yellow +// for highlight annotation, black for all else. Fails when called on +// annotations with appearance streams already defined; instead use +// FPDFPath_Get{Stroke|Fill}Color(). +// +// annot - handle to an annotation. +// type - type of the color requested. +// R, G, B - buffer to hold the RGB value of the color. Ranges from 0 to 255. +// A - buffer to hold the opacity. Ranges from 0 to 255. +// +// Returns true if successful. +DLLEXPORT FPDF_BOOL STDCALL FPDFAnnot_GetColor(FPDF_ANNOTATION annot, + FPDFANNOT_COLORTYPE type, + unsigned int* R, + unsigned int* G, + unsigned int* B, + unsigned int* A); + +// Experimental API. +// Check if the annotation is of a type that has attachment points +// (i.e. quadpoints). Quadpoints are the vertices of the rectange that +// encompasses the texts affected by the annotation. They provide the +// coordinates in the page where the annotation is attached. Only text markup +// annotations (i.e. highlight, strikeout, squiggly, and underline) and link +// annotations have quadpoints. +// +// annot - handle to an annotation. +// +// Returns true if the annotation is of a type that has quadpoints, false +// otherwise. +DLLEXPORT FPDF_BOOL STDCALL +FPDFAnnot_HasAttachmentPoints(FPDF_ANNOTATION annot); + +// Experimental API. +// Set the attachment points (i.e. quadpoints) of an annotation. If the +// annotation's appearance stream is defined and this annotation is of a type +// with quadpoints, then update the bounding box too. +// +// annot - handle to an annotation. +// quadPoints - the quadpoints to be set. +// +// Returns true if successful. +DLLEXPORT FPDF_BOOL STDCALL +FPDFAnnot_SetAttachmentPoints(FPDF_ANNOTATION annot, + const FS_QUADPOINTSF* quadPoints); + +// Experimental API. +// Get the attachment points (i.e. quadpoints) of an annotation. If the +// annotation's appearance stream is defined and this annotation is of a type +// with quadpoints, then return the bounding box it specifies instead. +// +// annot - handle to an annotation. +// +// Returns a quadpoints object, or an empty set of quadpoints on failure. +DLLEXPORT FS_QUADPOINTSF STDCALL +FPDFAnnot_GetAttachmentPoints(FPDF_ANNOTATION annot); + +// Experimental API. +// Set the annotation rectangle defining the location of the annotation. If the +// annotation's appearance stream is defined and this annotation is of a type +// without quadpoints, then update the bounding box too. +// +// annot - handle to an annotation. +// rect - the annotation rectangle to be set. +// +// Returns true if successful. +DLLEXPORT FPDF_BOOL STDCALL FPDFAnnot_SetRect(FPDF_ANNOTATION annot, + const FS_RECTF* rect); + +// Experimental API. +// Get the annotation rectangle defining the location of the annotation. If the +// annotation's appearance stream is defined and this annotation is of a type +// without quadpoints, then return the bounding box it specifies instead. +// +// annot - handle to an annotation. +// +// Returns a rectangle object, or an empty rectangle on failure. +DLLEXPORT FS_RECTF STDCALL FPDFAnnot_GetRect(FPDF_ANNOTATION annot); + +// Experimental API. +// Check if |annot|'s dictionary has |key| as a key. +// +// annot - handle to an annotation. +// key - the key to look for. +// +// Returns true if |key| exists. +DLLEXPORT FPDF_BOOL STDCALL FPDFAnnot_HasKey(FPDF_ANNOTATION annot, + FPDF_WIDESTRING key); + +// Experimental API. +// Get the type of the value corresponding to |key| in |annot|'s dictionary. +// +// annot - handle to an annotation. +// key - the key to look for. +// +// Returns the type of the dictionary value. +DLLEXPORT FPDF_OBJECT_TYPE STDCALL FPDFAnnot_GetValueType(FPDF_ANNOTATION annot, + FPDF_WIDESTRING key); + +// Experimental API. +// Set the string value corresponding to |key| in |annot|'s dictionary, +// overwriting the existing value if any. The value type would be +// FPDF_OBJECT_STRING after this function call succeeds. +// +// annot - handle to an annotation. +// key - the key to the dictionary entry to be set, encoded in UTF16-LE. +// value - the string value to be set, encoded in UTF16-LE. +// +// Returns true if successful. +DLLEXPORT FPDF_BOOL STDCALL FPDFAnnot_SetStringValue(FPDF_ANNOTATION annot, + FPDF_WIDESTRING key, + FPDF_WIDESTRING value); + +// Experimental API. +// Get the string value corresponding to |key| in |annot|'s dictionary. |buffer| +// is only modified if |buflen| is longer than the length of contents. Note that +// if |key| does not exist in the dictionary or if |key|'s corresponding value +// in the dictionary is not a string (i.e. the value is not of type +// FPDF_OBJECT_STRING or FPDF_OBJECT_NAME), then an empty string would be copied +// to |buffer| and the return value would be 2. On other errors, nothing would +// be added to |buffer| and the return value would be 0. +// +// annot - handle to an annotation. +// key - the key to the requested dictionary entry. +// buffer - buffer for holding the value string, encoded in UTF16-LE. +// buflen - length of the buffer. +// +// Returns the length of the string value. +DLLEXPORT unsigned long STDCALL FPDFAnnot_GetStringValue(FPDF_ANNOTATION annot, + FPDF_WIDESTRING key, + void* buffer, + unsigned long buflen); + +// Experimental API. +// Get the annotation flags of |annot|. +// +// annot - handle to an annotation. +// +// Returns the annotation flags. +DLLEXPORT int STDCALL FPDFAnnot_GetFlags(FPDF_ANNOTATION annot); + +// Experimental API. +// Set the |annot|'s flags to be of the value |flags|. +// +// annot - handle to an annotation. +// flags - the flag values to be set. +// +// Returns true if successful. +DLLEXPORT FPDF_BOOL STDCALL FPDFAnnot_SetFlags(FPDF_ANNOTATION annot, + int flags); + +// Experimental API. +// Get the annotation flags of |annot|, which is an interactive form +// annotation in |page|. +// +// page - handle to a page. +// annot - handle to an interactive form annotation. +// +// Returns the annotation flags specific to interactive forms. +DLLEXPORT int STDCALL FPDFAnnot_GetFormFieldFlags(FPDF_PAGE page, + FPDF_ANNOTATION annot); + +// Experimental API. +// Retrieves an interactive form annotation whose rectangle contains a given +// point on a page. Must call FPDFPage_CloseAnnot() when the annotation returned +// is no longer needed. +// +// +// hHandle - handle to the form fill module, returned by +// FPDFDOC_InitFormFillEnvironment. +// page - handle to the page, returned by FPDF_LoadPage function. +// page_x - X position in PDF "user space". +// page_y - Y position in PDF "user space". +// +// Returns the interactive form annotation whose rectangle contains the given +// coordinates on the page. If there is no such annotation, return NULL. +DLLEXPORT FPDF_ANNOTATION STDCALL +FPDFAnnot_GetFormFieldAtPoint(FPDF_FORMHANDLE hHandle, + FPDF_PAGE page, + double page_x, + double page_y); + +#ifdef __cplusplus +} // extern "C" +#endif // __cplusplus + +#endif // PUBLIC_FPDF_ANNOT_H_ diff --git a/chromium/third_party/pdfium/public/fpdf_attachment.h b/chromium/third_party/pdfium/public/fpdf_attachment.h new file mode 100644 index 00000000000..2c40992760a --- /dev/null +++ b/chromium/third_party/pdfium/public/fpdf_attachment.h @@ -0,0 +1,111 @@ +// Copyright 2017 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. + +#ifndef PUBLIC_FPDF_ATTACHMENT_H_ +#define PUBLIC_FPDF_ATTACHMENT_H_ + +// NOLINTNEXTLINE(build/include) +#include "fpdfview.h" + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +// Experimental API. +// Get the number of embedded files in |document|. +// +// document - handle to a document. +// +// Returns the number of embedded files in |document|. +DLLEXPORT int STDCALL FPDFDoc_GetAttachmentCount(FPDF_DOCUMENT document); + +// Experimental API. +// Get the embedded attachment at |index| in |document|. Note that the returned +// attachment handle is only valid while |document| is open. +// +// document - handle to a document. +// index - the index of the requested embedded file. +// +// Returns the handle to the attachment object, or NULL on failure. +DLLEXPORT FPDF_ATTACHMENT STDCALL FPDFDoc_GetAttachment(FPDF_DOCUMENT document, + int index); + +// Experimental API. +// Get the name of the |attachment| file. |buffer| is only modified if |buflen| +// is longer than the length of the file name. On errors, |buffer| is unmodified +// and the returned length is 0. +// +// attachment - handle to an attachment. +// buffer - buffer for holding the file name, encoded in UTF16-LE. +// buflen - length of the buffer. +// +// Returns the length of the file name. +DLLEXPORT unsigned long STDCALL +FPDFAttachment_GetName(FPDF_ATTACHMENT attachment, + void* buffer, + unsigned long buflen); + +// Experimental API. +// Check if the params dictionary of |attachment| has |key| as a key. +// +// attachment - handle to an attachment. +// key - the key to look for. +// +// Returns true if |key| exists. +DLLEXPORT FPDF_BOOL STDCALL FPDFAttachment_HasKey(FPDF_ATTACHMENT attachment, + FPDF_WIDESTRING key); + +// Experimental API. +// Get the type of the value corresponding to |key| in the params dictionary of +// the embedded |attachment|. +// +// attachment - handle to an attachment. +// key - the key to look for. +// +// Returns the type of the dictionary value. +DLLEXPORT FPDF_OBJECT_TYPE STDCALL +FPDFAttachment_GetValueType(FPDF_ATTACHMENT attachment, FPDF_WIDESTRING key); + +// Experimental API. +// Get the string value corresponding to |key| in the params dictionary of the +// embedded file |attachment|. |buffer| is only modified if |buflen| is longer +// than the length of the string value. Note that if |key| does not exist in the +// dictionary or if |key|'s corresponding value in the dictionary is not a +// string (i.e. the value is not of type FPDF_OBJECT_STRING or +// FPDF_OBJECT_NAME), then an empty string would be copied to |buffer| and the +// return value would be 2. On other errors, nothing would be added to |buffer| +// and the return value would be 0. +// +// attachment - handle to an attachment. +// key - the key to the requested string value. +// buffer - buffer for holding the file's date string encoded in UTF16-LE. +// buflen - length of the buffer. +// +// Returns the length of the dictionary value string. +DLLEXPORT unsigned long STDCALL +FPDFAttachment_GetStringValue(FPDF_ATTACHMENT attachment, + FPDF_WIDESTRING key, + void* buffer, + unsigned long buflen); + +// Experimental API. +// Get the file data of |attachment|. |buffer| is only modified if |buflen| is +// longer than the length of the file. On errors, |buffer| is unmodified and the +// returned length is 0. +// +// attachment - handle to an attachment. +// buffer - buffer for holding the file's data in raw bytes. +// buflen - length of the buffer. +// +// Returns the length of the file. +DLLEXPORT unsigned long STDCALL +FPDFAttachment_GetFile(FPDF_ATTACHMENT attachment, + void* buffer, + unsigned long buflen); + +#ifdef __cplusplus +} // extern "C" +#endif // __cplusplus + +#endif // PUBLIC_FPDF_ATTACHMENT_H_ diff --git a/chromium/third_party/pdfium/public/fpdf_doc.h b/chromium/third_party/pdfium/public/fpdf_doc.h index 9d55a2e826d..558ea199a99 100644 --- a/chromium/third_party/pdfium/public/fpdf_doc.h +++ b/chromium/third_party/pdfium/public/fpdf_doc.h @@ -138,10 +138,10 @@ DLLEXPORT FPDF_DEST STDCALL FPDFAction_GetDest(FPDF_DOCUMENT document, // buffer - a buffer for output the path string. May be NULL. // buflen - the length of the buffer, in bytes. May be 0. // -// Returns the number of bytes in the file path, including the trailing UTF16 -// NUL character. +// Returns the number of bytes in the file path, including the trailing NUL +// character. // -// Regardless of the platform, the |buffer| is always in UTF-16LE encoding. +// Regardless of the platform, the |buffer| is always in UTF-8 encoding. // If |buflen| is less than the returned length, or |buffer| is NULL, |buffer| // will not be modified. DLLEXPORT unsigned long STDCALL @@ -296,6 +296,10 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFLink_GetQuadPoints(FPDF_LINK linkAnnot, // The |buffer| is always encoded in UTF-16LE. The |buffer| is followed by two // bytes of zeros indicating the end of the string. If |buflen| is less than // the returned length, or |buffer| is NULL, |buffer| will not be modified. +// +// For linearized files, FPDFAvail_IsFormAvail must be called before this, and +// it must have returned PDF_FORM_AVAIL or PDF_FORM_NOTEXIST. Before that, there +// is no guarantee the metadata has been loaded. DLLEXPORT unsigned long STDCALL FPDF_GetMetaText(FPDF_DOCUMENT document, FPDF_BYTESTRING tag, void* buffer, diff --git a/chromium/third_party/pdfium/public/fpdf_edit.h b/chromium/third_party/pdfium/public/fpdf_edit.h index a84b42ab05e..cfed93172f1 100644 --- a/chromium/third_party/pdfium/public/fpdf_edit.h +++ b/chromium/third_party/pdfium/public/fpdf_edit.h @@ -34,6 +34,19 @@ #define FPDF_FONT_TYPE1 1 #define FPDF_FONT_TRUETYPE 2 +#define FPDF_LINECAP_BUTT 0 +#define FPDF_LINECAP_ROUND 1 +#define FPDF_LINECAP_PROJECTING_SQUARE 2 + +#define FPDF_LINEJOIN_MITER 0 +#define FPDF_LINEJOIN_ROUND 1 +#define FPDF_LINEJOIN_BEVEL 2 + +#define FPDF_PRINTMODE_EMF 0 +#define FPDF_PRINTMODE_TEXTONLY 1 +#define FPDF_PRINTMODE_POSTSCRIPT2 2 +#define FPDF_PRINTMODE_POSTSCRIPT3 3 + #ifdef __cplusplus extern "C" { #endif // __cplusplus @@ -128,23 +141,23 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFPage_HasTransparency(FPDF_PAGE page); // |FPDFPage_GenerateContent| or any changes to |page| will be lost. DLLEXPORT FPDF_BOOL STDCALL FPDFPage_GenerateContent(FPDF_PAGE page); -// Checks if |pageObject| contains transparency. +// Checks if |page_object| contains transparency. // -// pageObject - handle to a page object. +// page_object - handle to a page object. // // Returns TRUE if |pageObject| contains transparency. DLLEXPORT FPDF_BOOL STDCALL -FPDFPageObj_HasTransparency(FPDF_PAGEOBJECT pageObject); +FPDFPageObj_HasTransparency(FPDF_PAGEOBJECT page_object); -// Get type of |pageObject|. +// Get type of |page_object|. // -// pageObject - handle to a page object. +// page_object - handle to a page object. // // Returns one of the FPDF_PAGEOBJ_* values on success, FPDF_PAGEOBJ_UNKNOWN on // error. -DLLEXPORT int STDCALL FPDFPageObj_GetType(FPDF_PAGEOBJECT pageObject); +DLLEXPORT int STDCALL FPDFPageObj_GetType(FPDF_PAGEOBJECT page_object); -// Transform |pageObject| by the given matrix. +// Transform |page_object| by the given matrix. // // page_object - handle to a page object. // a - matrix value. @@ -296,6 +309,32 @@ DLLEXPORT FPDF_PAGEOBJECT STDCALL FPDFPageObj_CreateNewRect(float x, float w, float h); +// Get the bounding box of |page_object|. +// +// page_object - handle to a page object. +// left - pointer where the left coordinate will be stored +// bottom - pointer where the bottom coordinate will be stored +// right - pointer where the right coordinate will be stored +// top - pointer where the top coordinate will be stored +// +// Returns TRUE on success. +DLLEXPORT FPDF_BOOL STDCALL FPDFPageObj_GetBounds(FPDF_PAGEOBJECT page_object, + float* left, + float* bottom, + float* right, + float* top); + +// Set the blend mode of |page_object|. +// +// page_object - handle to a page object. +// blend_mode - string containing the blend mode. +// +// Blend mode can be one of following: Color, ColorBurn, ColorDodge, Darken, +// Difference, Exclusion, HardLight, Hue, Lighten, Luminosity, Multiply, Normal, +// Overlay, Saturation, Screen, SoftLight +DLLEXPORT void STDCALL FPDFPageObj_SetBlendMode(FPDF_PAGEOBJECT page_object, + FPDF_BYTESTRING blend_mode); + // Set the stroke RGBA of a path. Range of values: 0 - 255. // // path - the handle to the path object. @@ -305,11 +344,26 @@ DLLEXPORT FPDF_PAGEOBJECT STDCALL FPDFPageObj_CreateNewRect(float x, // A - the stroke alpha for the path. // // Returns TRUE on success. -DLLEXPORT FPDF_BOOL FPDFPath_SetStrokeColor(FPDF_PAGEOBJECT path, - unsigned int R, - unsigned int G, - unsigned int B, - unsigned int A); +DLLEXPORT FPDF_BOOL STDCALL FPDFPath_SetStrokeColor(FPDF_PAGEOBJECT path, + unsigned int R, + unsigned int G, + unsigned int B, + unsigned int A); + +// Get the stroke RGBA of a path. Range of values: 0 - 255. +// +// path - the handle to the path object. +// R - the red component of the path stroke color. +// G - the green component of the path stroke color. +// B - the blue component of the path stroke color. +// A - the stroke alpha of the path. +// +// Returns TRUE on success. +DLLEXPORT FPDF_BOOL STDCALL FPDFPath_GetStrokeColor(FPDF_PAGEOBJECT path, + unsigned int* R, + unsigned int* G, + unsigned int* B, + unsigned int* A); // Set the stroke width of a path. // @@ -317,7 +371,28 @@ DLLEXPORT FPDF_BOOL FPDFPath_SetStrokeColor(FPDF_PAGEOBJECT path, // width - the width of the stroke. // // Returns TRUE on success -DLLEXPORT FPDF_BOOL FPDFPath_SetStrokeWidth(FPDF_PAGEOBJECT path, float width); +DLLEXPORT FPDF_BOOL STDCALL FPDFPath_SetStrokeWidth(FPDF_PAGEOBJECT path, + float width); + +// Set the line join of |page_object|. +// +// page_object - handle to a page object. +// line_join - line join +// +// Line join can be one of following: FPDF_LINEJOIN_MITER, FPDF_LINEJOIN_ROUND, +// FPDF_LINEJOIN_BEVEL +DLLEXPORT void STDCALL STDCALL FPDFPath_SetLineJoin(FPDF_PAGEOBJECT page_object, + int line_join); + +// Set the line cap of |page_object|. +// +// page_object - handle to a page object. +// line_cap - line cap +// +// Line cap can be one of following: FPDF_LINECAP_BUTT, FPDF_LINECAP_ROUND, +// FPDF_LINECAP_PROJECTING_SQUARE +DLLEXPORT void STDCALL FPDFPath_SetLineCap(FPDF_PAGEOBJECT page_object, + int line_cap); // Set the fill RGBA of a path. Range of values: 0 - 255. // @@ -328,11 +403,11 @@ DLLEXPORT FPDF_BOOL FPDFPath_SetStrokeWidth(FPDF_PAGEOBJECT path, float width); // A - the fill alpha for the path. // // Returns TRUE on success. -DLLEXPORT FPDF_BOOL FPDFPath_SetFillColor(FPDF_PAGEOBJECT path, - unsigned int R, - unsigned int G, - unsigned int B, - unsigned int A); +DLLEXPORT FPDF_BOOL STDCALL FPDFPath_SetFillColor(FPDF_PAGEOBJECT path, + unsigned int R, + unsigned int G, + unsigned int B, + unsigned int A); // Get the fill RGBA of a path. Range of values: 0 - 255. // @@ -343,11 +418,11 @@ DLLEXPORT FPDF_BOOL FPDFPath_SetFillColor(FPDF_PAGEOBJECT path, // A - the fill alpha of the path. // // Returns TRUE on success. -DLLEXPORT FPDF_BOOL FPDFPath_GetFillColor(FPDF_PAGEOBJECT path, - unsigned int* R, - unsigned int* G, - unsigned int* B, - unsigned int* A); +DLLEXPORT FPDF_BOOL STDCALL FPDFPath_GetFillColor(FPDF_PAGEOBJECT path, + unsigned int* R, + unsigned int* G, + unsigned int* B, + unsigned int* A); // Move a path's current point. // @@ -359,7 +434,9 @@ DLLEXPORT FPDF_BOOL FPDFPath_GetFillColor(FPDF_PAGEOBJECT path, // new one. // // Returns TRUE on success -DLLEXPORT FPDF_BOOL FPDFPath_MoveTo(FPDF_PAGEOBJECT path, float x, float y); +DLLEXPORT FPDF_BOOL STDCALL FPDFPath_MoveTo(FPDF_PAGEOBJECT path, + float x, + float y); // Add a line between the current point and a new point in the path. // @@ -370,7 +447,9 @@ DLLEXPORT FPDF_BOOL FPDFPath_MoveTo(FPDF_PAGEOBJECT path, float x, float y); // The path's current point is changed to (x, y). // // Returns TRUE on success -DLLEXPORT FPDF_BOOL FPDFPath_LineTo(FPDF_PAGEOBJECT path, float x, float y); +DLLEXPORT FPDF_BOOL STDCALL FPDFPath_LineTo(FPDF_PAGEOBJECT path, + float x, + float y); // Add a cubic Bezier curve to the given path, starting at the current point. // @@ -383,13 +462,13 @@ DLLEXPORT FPDF_BOOL FPDFPath_LineTo(FPDF_PAGEOBJECT path, float x, float y); // y3 - the vertical position of the ending point of the Bezier curve. // // Returns TRUE on success -DLLEXPORT FPDF_BOOL FPDFPath_BezierTo(FPDF_PAGEOBJECT path, - float x1, - float y1, - float x2, - float y2, - float x3, - float y3); +DLLEXPORT FPDF_BOOL STDCALL FPDFPath_BezierTo(FPDF_PAGEOBJECT path, + float x1, + float y1, + float x2, + float y2, + float x3, + float y3); // Close the current subpath of a given path. // @@ -399,7 +478,7 @@ DLLEXPORT FPDF_BOOL FPDFPath_BezierTo(FPDF_PAGEOBJECT path, // subpath, thus terminating the current subpath. // // Returns TRUE on success -DLLEXPORT FPDF_BOOL FPDFPath_Close(FPDF_PAGEOBJECT path); +DLLEXPORT FPDF_BOOL STDCALL FPDFPath_Close(FPDF_PAGEOBJECT path); // Set the drawing mode of a path. // @@ -409,9 +488,9 @@ DLLEXPORT FPDF_BOOL FPDFPath_Close(FPDF_PAGEOBJECT path); // stroke - a boolean specifying if the path should be stroked or not. // // Returns TRUE on success -DLLEXPORT FPDF_BOOL FPDFPath_SetDrawMode(FPDF_PAGEOBJECT path, - int fillmode, - FPDF_BOOL stroke); +DLLEXPORT FPDF_BOOL STDCALL FPDFPath_SetDrawMode(FPDF_PAGEOBJECT path, + int fillmode, + FPDF_BOOL stroke); // Create a new text object using one of the standard PDF fonts. // @@ -452,6 +531,21 @@ DLLEXPORT FPDF_FONT STDCALL FPDFText_LoadFont(FPDF_DOCUMENT document, int font_type, FPDF_BOOL cid); +// Set the fill RGBA of a text object. Range of values: 0 - 255. +// +// text_object - handle to the text object. +// R - the red component for the path fill color. +// G - the green component for the path fill color. +// B - the blue component for the path fill color. +// A - the fill alpha for the path. +// +// Returns TRUE on success. +DLLEXPORT FPDF_BOOL STDCALL FPDFText_SetFillColor(FPDF_PAGEOBJECT text_object, + unsigned int R, + unsigned int G, + unsigned int B, + unsigned int A); + // Close a loaded PDF font. // // font - Handle to the loaded font. diff --git a/chromium/third_party/pdfium/public/fpdf_formfill.h b/chromium/third_party/pdfium/public/fpdf_formfill.h index 65be850b364..5a15cd9a02a 100644 --- a/chromium/third_party/pdfium/public/fpdf_formfill.h +++ b/chromium/third_party/pdfium/public/fpdf_formfill.h @@ -1355,6 +1355,29 @@ DLLEXPORT FPDF_BOOL STDCALL FORM_OnChar(FPDF_FORMHANDLE hHandle, int modifier); /** + * Function: FORM_GetSelectedText + * You can call this function to obtain selected text within + * a form text field or form combobox text field. + * Parameters: + * hHandle - Handle to the form fill module. Returned by + * FPDFDOC_InitFormFillEnvironment. + * page - Handle to the page. Returned by FPDF_LoadPage + * function. + * buffer - Buffer for holding the selected text, encoded + * in UTF16-LE. If NULL, |buffer| is not modified. + * buflen - Length of |buffer| in bytes. If |buflen| + is less than the length of the selected text + string, |buffer| is not modified. + * Return Value: + * Length in bytes of selected text in form text field or form combobox + * text field. + **/ +DLLEXPORT unsigned long STDCALL FORM_GetSelectedText(FPDF_FORMHANDLE hHandle, + FPDF_PAGE page, + void* buffer, + unsigned long buflen); + +/** * Function: FORM_ForceToKillFocus. * You can call this member function to force to kill the focus of the *form field which got focus. @@ -1399,15 +1422,6 @@ DLLEXPORT int STDCALL FPDFPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle, double page_y); /** - * Function: FPDPage_HasFormFieldAtPoint - * DEPRECATED. Please use FPDFPage_HasFormFieldAtPoint. - **/ -DLLEXPORT int STDCALL FPDPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle, - FPDF_PAGE page, - double page_x, - double page_y); - -/** * Function: FPDFPage_FormFieldZOrderAtPoint * Get the form field z-order by point. * Parameters: diff --git a/chromium/third_party/pdfium/public/fpdf_progressive.h b/chromium/third_party/pdfium/public/fpdf_progressive.h index 0c3d501317b..2cffacb8bd8 100644 --- a/chromium/third_party/pdfium/public/fpdf_progressive.h +++ b/chromium/third_party/pdfium/public/fpdf_progressive.h @@ -12,7 +12,8 @@ // Flags for progressive process status. #define FPDF_RENDER_READER 0 -#define FPDF_RENDER_TOBECOUNTINUED 1 +#define FPDF_RENDER_TOBECONTINUED 1 +#define FPDF_RENDER_TOBECOUNTINUED 1 // Deprecated. #define FPDF_RENDER_DONE 2 #define FPDF_RENDER_FAILED 3 diff --git a/chromium/third_party/pdfium/public/fpdf_sysfontinfo.h b/chromium/third_party/pdfium/public/fpdf_sysfontinfo.h index a0edffffa27..c3510269735 100644 --- a/chromium/third_party/pdfium/public/fpdf_sysfontinfo.h +++ b/chromium/third_party/pdfium/public/fpdf_sysfontinfo.h @@ -307,7 +307,8 @@ DLLEXPORT FPDF_SYSFONTINFO* STDCALL FPDF_GetDefaultSystemFontInfo(); * Return Value: * None **/ -DLLEXPORT void FPDF_FreeDefaultSystemFontInfo(FPDF_SYSFONTINFO* pFontInfo); +DLLEXPORT void STDCALL +FPDF_FreeDefaultSystemFontInfo(FPDF_SYSFONTINFO* pFontInfo); #ifdef __cplusplus } diff --git a/chromium/third_party/pdfium/public/fpdfview.h b/chromium/third_party/pdfium/public/fpdfview.h index 13e4f1f5f1e..55897eb467b 100644 --- a/chromium/third_party/pdfium/public/fpdfview.h +++ b/chromium/third_party/pdfium/public/fpdfview.h @@ -20,8 +20,22 @@ #define PDF_USE_XFA #endif // PDF_ENABLE_XFA +// PDF object types +#define FPDF_OBJECT_UNKNOWN 0 +#define FPDF_OBJECT_BOOLEAN 1 +#define FPDF_OBJECT_NUMBER 2 +#define FPDF_OBJECT_STRING 3 +#define FPDF_OBJECT_NAME 4 +#define FPDF_OBJECT_ARRAY 5 +#define FPDF_OBJECT_DICTIONARY 6 +#define FPDF_OBJECT_STREAM 7 +#define FPDF_OBJECT_NULLOBJ 8 +#define FPDF_OBJECT_REFERENCE 9 + // PDF types typedef void* FPDF_ACTION; +typedef void* FPDF_ANNOTATION; +typedef void* FPDF_ATTACHMENT; typedef void* FPDF_BITMAP; typedef void* FPDF_BOOKMARK; typedef void* FPDF_CLIPPATH; @@ -122,6 +136,12 @@ typedef struct _FS_RECTF_ { // Const Pointer to FS_RECTF structure. typedef const FS_RECTF* FS_LPCRECTF; +// Annotation subtype. +typedef int FPDF_ANNOTATION_SUBTYPE; + +// Dictionary value types. +typedef int FPDF_OBJECT_TYPE; + #if defined(_WIN32) && defined(FPDFSDK_EXPORTS) // On Windows system, functions are exported in a DLL #define DLLEXPORT __declspec(dllexport) @@ -242,13 +262,26 @@ DLLEXPORT void STDCALL FPDF_SetPrintTextWithGDI(FPDF_BOOL use_gdi); // Set postscript printing level when printing on Windows. // Experimental API. // Parameters: -// postscript_level - 0 to disable postscript printing, -// 2 to print with postscript level 2, -// 3 to print with postscript level 3. -// All other values are invalid. +// postscript_level- 0 to disable postscript printing, +// 2 to print with postscript level 2, +// 3 to print with postscript level 3. +// All other values are invalid. // Return value: -// True if successful, false if unsucessful (typically invalid input). +// True if successful, false if unsuccessful (typically invalid input). DLLEXPORT FPDF_BOOL STDCALL FPDF_SetPrintPostscriptLevel(int postscript_level); + +// Function: FPDF_SetPrintMode +// Set printing mode when printing on Windows. +// Experimental API. +// Parameters: +// mode - FPDF_PRINTMODE_EMF to output EMF (default) +// FPDF_PRINTMODE_TEXTONLY to output text only (for charstream +// devices) +// FPDF_PRINTMODE_POSTSCRIPT2 to output level 2 postscript +// FPDF_PRINTMODE_POSTSCRIPT3 to output level 3 postscript +// Return value: +// True if successful, false if unsuccessful (typically invalid input). +DLLEXPORT FPDF_BOOL STDCALL FPDF_SetPrintMode(int mode); #endif // defined(_WIN32) // Function: FPDF_LoadDocument diff --git a/chromium/third_party/pdfium/samples/BUILD.gn b/chromium/third_party/pdfium/samples/BUILD.gn index 779d4f3f31a..8fbf5d552f3 100644 --- a/chromium/third_party/pdfium/samples/BUILD.gn +++ b/chromium/third_party/pdfium/samples/BUILD.gn @@ -8,7 +8,6 @@ import("../pdfium.gni") group("samples") { testonly = true deps = [ - ":pdfium_diff", ":pdfium_test", ] } @@ -33,6 +32,11 @@ config("pdfium_samples_config") { if (is_asan) { defines += [ "PDF_ENABLE_ASAN" ] } + + if (enable_callgrind) { + defines += [ "ENABLE_CALLGRIND" ] + } + if (use_coverage && is_clang) { cflags += [ "--coverage", @@ -46,19 +50,15 @@ config("pdfium_samples_config") { executable("pdfium_test") { testonly = true sources = [ - "image_diff_png.cc", - "image_diff_png.h", "pdfium_test.cc", ] deps = [ + "../:image_diff", "../:pdfium", "../:test_support", "//build/config:exe_and_shlib_deps", "//build/win:default_exe_manifest", ] - if (!pdf_enable_xfa) { - deps += [ "../third_party:fx_lpng" ] - } if (pdf_enable_v8) { deps += [ "//v8:v8_libplatform" ] include_dirs = [ @@ -72,25 +72,3 @@ executable("pdfium_test") { } configs += [ ":pdfium_samples_config" ] } - -executable("pdfium_diff") { - testonly = true - sources = [ - "image_diff.cc", - "image_diff_png.cc", - "image_diff_png.h", - ] - deps = [ - "../:pdfium", - "//build/config:exe_and_shlib_deps", - "//build/win:default_exe_manifest", - ] - if (!pdf_enable_xfa) { - deps += [ "../third_party:fx_lpng" ] - } - configs -= [ "//build/config/compiler:chromium_code" ] - configs += [ - ":pdfium_samples_config", - "//build/config/compiler:no_chromium_code", - ] -} diff --git a/chromium/third_party/pdfium/samples/DEPS b/chromium/third_party/pdfium/samples/DEPS index fb322dee20f..26f9ee22ebd 100644 --- a/chromium/third_party/pdfium/samples/DEPS +++ b/chromium/third_party/pdfium/samples/DEPS @@ -1,8 +1,5 @@ include_rules = [ '+public', - '+third_party/libpng16', '+third_party/skia/include', - '+third_party/zlib', '+v8', - '+core/fdrm/crypto/fx_crypt.h', ] diff --git a/chromium/third_party/pdfium/samples/pdfium_test.cc b/chromium/third_party/pdfium/samples/pdfium_test.cc index e33ceadabf7..83f18ed79f4 100644 --- a/chromium/third_party/pdfium/samples/pdfium_test.cc +++ b/chromium/third_party/pdfium/samples/pdfium_test.cc @@ -7,6 +7,8 @@ #include <stdlib.h> #include <string.h> +#include <bitset> +#include <iterator> #include <map> #include <sstream> #include <string> @@ -17,17 +19,20 @@ #define _SKIA_SUPPORT_ #endif -#include "core/fdrm/crypto/fx_crypt.h" #include "public/cpp/fpdf_deleters.h" +#include "public/fpdf_annot.h" +#include "public/fpdf_attachment.h" #include "public/fpdf_dataavail.h" #include "public/fpdf_edit.h" #include "public/fpdf_ext.h" #include "public/fpdf_formfill.h" +#include "public/fpdf_progressive.h" #include "public/fpdf_structtree.h" #include "public/fpdf_text.h" #include "public/fpdfview.h" -#include "samples/image_diff_png.h" +#include "testing/image_diff/image_diff_png.h" #include "testing/test_support.h" +#include "third_party/base/logging.h" #ifdef _WIN32 #include <io.h> @@ -35,6 +40,10 @@ #include <unistd.h> #endif +#ifdef ENABLE_CALLGRIND +#include <valgrind/callgrind.h> +#endif // ENABLE_CALLGRIND + #ifdef PDF_ENABLE_V8 #include "v8/include/libplatform/libplatform.h" #include "v8/include/v8.h" @@ -57,6 +66,7 @@ enum OutputFormat { OUTPUT_TEXT, OUTPUT_PPM, OUTPUT_PNG, + OUTPUT_ANNOT, #ifdef _WIN32 OUTPUT_BMP, OUTPUT_EMF, @@ -71,13 +81,26 @@ enum OutputFormat { struct Options { Options() : show_config(false), + show_metadata(false), send_events(false), + render_oneshot(false), + save_attachments(false), +#ifdef ENABLE_CALLGRIND + callgrind_delimiters(false), +#endif // ENABLE_CALLGRIND pages(false), md5(false), - output_format(OUTPUT_NONE) {} + output_format(OUTPUT_NONE) { + } bool show_config; + bool show_metadata; bool send_events; + bool render_oneshot; + bool save_attachments; +#ifdef ENABLE_CALLGRIND + bool callgrind_delimiters; +#endif // ENABLE_CALLGRIND bool pages; bool md5; OutputFormat output_format; @@ -115,12 +138,9 @@ static bool CheckDimensions(int stride, int width, int height) { static void OutputMD5Hash(const char* file_name, const char* buffer, int len) { // Get the MD5 hash and write it to stdout. - uint8_t digest[16]; - CRYPT_MD5Generate(reinterpret_cast<const uint8_t*>(buffer), len, digest); - printf("MD5:%s:", file_name); - for (int i = 0; i < 16; i++) - printf("%02x", digest[i]); - printf("\n"); + std::string hash = + GenerateMD5Base16(reinterpret_cast<const uint8_t*>(buffer), len); + printf("MD5:%s:%s\n", file_name, hash.c_str()); } static std::string WritePpm(const char* pdf_name, @@ -193,6 +213,210 @@ void WriteText(FPDF_PAGE page, const char* pdf_name, int num) { (void)fclose(fp); } +std::string AnnotSubtypeToString(FPDF_ANNOTATION_SUBTYPE subtype) { + if (subtype == FPDF_ANNOT_TEXT) + return "Text"; + if (subtype == FPDF_ANNOT_LINK) + return "Link"; + if (subtype == FPDF_ANNOT_FREETEXT) + return "FreeText"; + if (subtype == FPDF_ANNOT_LINE) + return "Line"; + if (subtype == FPDF_ANNOT_SQUARE) + return "Square"; + if (subtype == FPDF_ANNOT_CIRCLE) + return "Circle"; + if (subtype == FPDF_ANNOT_POLYGON) + return "Polygon"; + if (subtype == FPDF_ANNOT_POLYLINE) + return "PolyLine"; + if (subtype == FPDF_ANNOT_HIGHLIGHT) + return "Highlight"; + if (subtype == FPDF_ANNOT_UNDERLINE) + return "Underline"; + if (subtype == FPDF_ANNOT_SQUIGGLY) + return "Squiggly"; + if (subtype == FPDF_ANNOT_STRIKEOUT) + return "StrikeOut"; + if (subtype == FPDF_ANNOT_STAMP) + return "Stamp"; + if (subtype == FPDF_ANNOT_CARET) + return "Caret"; + if (subtype == FPDF_ANNOT_INK) + return "Ink"; + if (subtype == FPDF_ANNOT_POPUP) + return "Popup"; + if (subtype == FPDF_ANNOT_FILEATTACHMENT) + return "FileAttachment"; + if (subtype == FPDF_ANNOT_SOUND) + return "Sound"; + if (subtype == FPDF_ANNOT_MOVIE) + return "Movie"; + if (subtype == FPDF_ANNOT_WIDGET) + return "Widget"; + if (subtype == FPDF_ANNOT_SCREEN) + return "Screen"; + if (subtype == FPDF_ANNOT_PRINTERMARK) + return "PrinterMark"; + if (subtype == FPDF_ANNOT_TRAPNET) + return "TrapNet"; + if (subtype == FPDF_ANNOT_WATERMARK) + return "Watermark"; + if (subtype == FPDF_ANNOT_THREED) + return "3D"; + if (subtype == FPDF_ANNOT_RICHMEDIA) + return "RichMedia"; + if (subtype == FPDF_ANNOT_XFAWIDGET) + return "XFAWidget"; + NOTREACHED(); + return ""; +} + +std::string AnnotFlagsToString(int flags) { + std::string str = ""; + if (flags & FPDF_ANNOT_FLAG_INVISIBLE) + str += "Invisible"; + if (flags & FPDF_ANNOT_FLAG_HIDDEN) + str += std::string(str.empty() ? "" : ", ") + "Hidden"; + if (flags & FPDF_ANNOT_FLAG_PRINT) + str += std::string(str.empty() ? "" : ", ") + "Print"; + if (flags & FPDF_ANNOT_FLAG_NOZOOM) + str += std::string(str.empty() ? "" : ", ") + "NoZoom"; + if (flags & FPDF_ANNOT_FLAG_NOROTATE) + str += std::string(str.empty() ? "" : ", ") + "NoRotate"; + if (flags & FPDF_ANNOT_FLAG_NOVIEW) + str += std::string(str.empty() ? "" : ", ") + "NoView"; + if (flags & FPDF_ANNOT_FLAG_READONLY) + str += std::string(str.empty() ? "" : ", ") + "ReadOnly"; + if (flags & FPDF_ANNOT_FLAG_LOCKED) + str += std::string(str.empty() ? "" : ", ") + "Locked"; + if (flags & FPDF_ANNOT_FLAG_TOGGLENOVIEW) + str += std::string(str.empty() ? "" : ", ") + "ToggleNoView"; + return str; +} + +std::string PageObjectTypeToString(int type) { + if (type == FPDF_PAGEOBJ_TEXT) + return "Text"; + if (type == FPDF_PAGEOBJ_PATH) + return "Path"; + if (type == FPDF_PAGEOBJ_IMAGE) + return "Image"; + if (type == FPDF_PAGEOBJ_SHADING) + return "Shading"; + if (type == FPDF_PAGEOBJ_FORM) + return "Form"; + NOTREACHED(); + return ""; +} + +void WriteAnnot(FPDF_PAGE page, const char* pdf_name, int num) { + // Open the output text file. + char filename[256]; + int chars_formatted = + snprintf(filename, sizeof(filename), "%s.%d.annot.txt", pdf_name, num); + if (chars_formatted < 0 || + static_cast<size_t>(chars_formatted) >= sizeof(filename)) { + fprintf(stderr, "Filename %s is too long\n", filename); + return; + } + FILE* fp = fopen(filename, "w"); + if (!fp) { + fprintf(stderr, "Failed to open %s for output\n", filename); + return; + } + + int annot_count = FPDFPage_GetAnnotCount(page); + fprintf(fp, "Number of annotations: %d\n\n", annot_count); + + // Iterate through all annotations on this page. + for (int i = 0; i < annot_count; ++i) { + // Retrieve the annotation object and its subtype. + fprintf(fp, "Annotation #%d:\n", i + 1); + FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, i); + if (!annot) { + fprintf(fp, "Failed to retrieve annotation!\n\n"); + continue; + } + FPDF_ANNOTATION_SUBTYPE subtype = FPDFAnnot_GetSubtype(annot); + fprintf(fp, "Subtype: %s\n", AnnotSubtypeToString(subtype).c_str()); + + // Retrieve the annotation flags. + fprintf(fp, "Flags set: %s\n", + AnnotFlagsToString(FPDFAnnot_GetFlags(annot)).c_str()); + + // Retrieve the annotation's object count and object types. + const int obj_count = FPDFAnnot_GetObjectCount(annot); + fprintf(fp, "Number of objects: %d\n", obj_count); + if (obj_count > 0) { + fprintf(fp, "Object types: "); + for (int j = 0; j < obj_count; ++j) { + fprintf(fp, "%s ", + PageObjectTypeToString( + FPDFPageObj_GetType(FPDFAnnot_GetObject(annot, j))) + .c_str()); + } + fprintf(fp, "\n"); + } + + // Retrieve the annotation's color and interior color. + unsigned int R; + unsigned int G; + unsigned int B; + unsigned int A; + if (!FPDFAnnot_GetColor(annot, FPDFANNOT_COLORTYPE_Color, &R, &G, &B, &A)) { + fprintf(fp, "Failed to retrieve color.\n"); + } else { + fprintf(fp, "Color in RGBA: %d %d %d %d\n", R, G, B, A); + } + if (!FPDFAnnot_GetColor(annot, FPDFANNOT_COLORTYPE_InteriorColor, &R, &G, + &B, &A)) { + fprintf(fp, "Failed to retrieve interior color.\n"); + } else { + fprintf(fp, "Interior color in RGBA: %d %d %d %d\n", R, G, B, A); + } + + // Retrieve the annotation's contents and author. + std::unique_ptr<unsigned short, pdfium::FreeDeleter> contents_key = + GetFPDFWideString(L"Contents"); + unsigned long len = + FPDFAnnot_GetStringValue(annot, contents_key.get(), nullptr, 0); + std::vector<char> buf(len); + FPDFAnnot_GetStringValue(annot, contents_key.get(), buf.data(), len); + fprintf(fp, "Content: %ls\n", + GetPlatformWString(reinterpret_cast<unsigned short*>(buf.data())) + .c_str()); + std::unique_ptr<unsigned short, pdfium::FreeDeleter> author_key = + GetFPDFWideString(L"T"); + len = FPDFAnnot_GetStringValue(annot, author_key.get(), nullptr, 0); + buf.clear(); + buf.resize(len); + FPDFAnnot_GetStringValue(annot, author_key.get(), buf.data(), len); + fprintf(fp, "Author: %ls\n", + GetPlatformWString(reinterpret_cast<unsigned short*>(buf.data())) + .c_str()); + + // Retrieve the annotation's quadpoints if it is a markup annotation. + if (FPDFAnnot_HasAttachmentPoints(annot)) { + FS_QUADPOINTSF quadpoints = FPDFAnnot_GetAttachmentPoints(annot); + fprintf(fp, + "Quadpoints: (%.3f, %.3f), (%.3f, %.3f), (%.3f, %.3f), (%.3f, " + "%.3f)\n", + quadpoints.x1, quadpoints.y1, quadpoints.x2, quadpoints.y2, + quadpoints.x3, quadpoints.y3, quadpoints.x4, quadpoints.y4); + } + + // Retrieve the annotation's rectangle coordinates. + FS_RECTF rect = FPDFAnnot_GetRect(annot); + fprintf(fp, "Rectangle: l - %.3f, b - %.3f, r - %.3f, t - %.3f\n\n", + rect.left, rect.bottom, rect.right, rect.top); + + FPDFPage_CloseAnnot(annot); + } + + (void)fclose(fp); +} + static std::string WritePng(const char* pdf_name, int num, const void* buffer_void, @@ -474,8 +698,18 @@ bool ParseCommandLine(const std::vector<std::string>& args, const std::string& cur_arg = args[cur_idx]; if (cur_arg == "--show-config") { options->show_config = true; + } else if (cur_arg == "--show-metadata") { + options->show_metadata = true; } else if (cur_arg == "--send-events") { options->send_events = true; + } else if (cur_arg == "--render-oneshot") { + options->render_oneshot = true; + } else if (cur_arg == "--save-attachments") { + options->save_attachments = true; +#ifdef ENABLE_CALLGRIND + } else if (cur_arg == "--callgrind-delim") { + options->callgrind_delimiters = true; +#endif // ENABLE_CALLGRIND } else if (cur_arg == "--ppm") { if (options->output_format != OUTPUT_NONE) { fprintf(stderr, "Duplicate or conflicting --ppm argument\n"); @@ -494,6 +728,12 @@ bool ParseCommandLine(const std::vector<std::string>& args, return false; } options->output_format = OUTPUT_TEXT; + } else if (cur_arg == "--annot") { + if (options->output_format != OUTPUT_NONE) { + fprintf(stderr, "Duplicate or conflicting --annot argument\n"); + return false; + } + options->output_format = OUTPUT_ANNOT; #ifdef PDF_ENABLE_SKIA } else if (cur_arg == "--skp") { if (options->output_format != OUTPUT_NONE) { @@ -598,8 +838,8 @@ FPDF_BOOL Is_Data_Avail(FX_FILEAVAIL* avail, size_t offset, size_t size) { void Add_Segment(FX_DOWNLOADHINTS* hints, size_t offset, size_t size) {} -void SendPageEvents(const FPDF_FORMHANDLE& form, - const FPDF_PAGE& page, +void SendPageEvents(FPDF_FORMHANDLE form, + FPDF_PAGE page, const std::string& events) { auto lines = StringSplit(events, '\n'); for (auto line : lines) { @@ -743,6 +983,13 @@ void DumpPageStructure(FPDF_PAGE page, const int page_idx) { printf("\n\n"); } +// Note, for a client using progressive rendering you'd want to determine if you +// need the rendering to pause instead of always saying |true|. This is for +// testing to force the renderer to break whenever possible. +FPDF_BOOL NeedToPauseNow(IFSDK_PAUSE* p) { + return true; +} + bool RenderPage(const std::string& name, FPDF_DOCUMENT doc, FPDF_FORMHANDLE form, @@ -777,11 +1024,30 @@ bool RenderPage(const std::string& name, if (bitmap) { FPDF_DWORD fill_color = alpha ? 0x00000000 : 0xFFFFFFFF; FPDFBitmap_FillRect(bitmap.get(), 0, 0, width, height, fill_color); - FPDF_RenderPageBitmap(bitmap.get(), page.get(), 0, 0, width, height, 0, - FPDF_ANNOT); + + if (options.render_oneshot) { + // Note, client programs probably want to use this method instead of the + // progressive calls. The progressive calls are if you need to pause the + // rendering to update the UI, the PDF renderer will break when possible. + FPDF_RenderPageBitmap(bitmap.get(), page.get(), 0, 0, width, height, 0, + FPDF_ANNOT); + } else { + IFSDK_PAUSE pause; + pause.version = 1; + pause.NeedToPauseNow = &NeedToPauseNow; + + int rv = FPDF_RenderPageBitmap_Start( + bitmap.get(), page.get(), 0, 0, width, height, 0, FPDF_ANNOT, &pause); + while (rv == FPDF_RENDER_TOBECOUNTINUED) + rv = FPDF_RenderPage_Continue(page.get(), &pause); + } FPDF_FFLDraw(form, bitmap.get(), page.get(), 0, 0, width, height, 0, FPDF_ANNOT); + + if (!options.render_oneshot) + FPDF_RenderPage_Close(page.get()); + int stride = FPDFBitmap_GetStride(bitmap.get()); const char* buffer = reinterpret_cast<const char*>(FPDFBitmap_GetBuffer(bitmap.get())); @@ -807,6 +1073,10 @@ bool RenderPage(const std::string& name, WriteText(page.get(), name.c_str(), page_index); break; + case OUTPUT_ANNOT: + WriteAnnot(page.get(), name.c_str(), page_index); + break; + case OUTPUT_PNG: image_file_name = WritePng(name.c_str(), page_index, buffer, stride, width, height); @@ -947,6 +1217,71 @@ void RenderPdf(const std::string& name, (void)FPDF_GetDocPermissions(doc.get()); + if (options.show_metadata) { + const char* metaTags[] = {"Title", "Author", "Subject", "Keywords", + "Creator", "Producer", "CreationDate", "ModDate"}; + for (const char* metaTag : metaTags) { + char metaBuffer[4096]; + int len = FPDF_GetMetaText(doc.get(), metaTag, metaBuffer, 4096); + printf("%-12s = %ls (%d bytes)\n", metaTag, + GetPlatformWString(reinterpret_cast<unsigned short*>(metaBuffer)) + .c_str(), + len); + } + } + + if (options.save_attachments) { + for (int i = 0; i < FPDFDoc_GetAttachmentCount(doc.get()); ++i) { + FPDF_ATTACHMENT attachment = FPDFDoc_GetAttachment(doc.get(), i); + + // Retrieve the attachment file name. + unsigned long len = FPDFAttachment_GetName(attachment, nullptr, 0); + if (!len) { + fprintf(stderr, "Warning: Attachment #%d has an empty file name.\n", + i + 1); + } + std::vector<char> buf(len); + FPDFAttachment_GetName(attachment, buf.data(), len); + std::string attachment_name = + GetPlatformString(reinterpret_cast<unsigned short*>(buf.data())); + + // Open the attachment file for writing. + char save_name[256]; + int chars_formatted = + snprintf(save_name, sizeof(save_name), "%s.attachment.%s", + name.c_str(), attachment_name.c_str()); + if (chars_formatted < 0 || + static_cast<size_t>(chars_formatted) >= sizeof(save_name)) { + fprintf(stderr, "Filename %s is too long\n", save_name); + continue; + } + FILE* fp = fopen(save_name, "wb"); + if (!fp) { + fprintf(stderr, "Failed to open %s for saving attachment.\n", + save_name); + continue; + } + + // Write the attachment file. + len = FPDFAttachment_GetFile(attachment, nullptr, 0); + if (!len) { + fprintf(stderr, "Warning: Attachment \"%s\" is empty.\n", + attachment_name.c_str()); + } + buf.clear(); + buf.resize(len); + FPDFAttachment_GetFile(attachment, buf.data(), len); + size_t written_len = fwrite(buf.data(), sizeof(char), len, fp); + if (written_len != len) { + fprintf(stderr, "Warning: Unsuccessful write to file \"%s\".\n", + save_name); + } + fclose(fp); + + fprintf(stderr, "Saved attachment \"%s\".\n", attachment_name.c_str()); + } + } + std::unique_ptr<void, FPDFFormHandleDeleter> form( FPDFDOC_InitFormFillEnvironment(doc.get(), &form_callbacks)); form_callbacks.form_handle = form.get(); @@ -966,9 +1301,9 @@ void RenderPdf(const std::string& name, #if _WIN32 if (options.output_format == OUTPUT_PS2) - FPDF_SetPrintPostscriptLevel(2); + FPDF_SetPrintMode(2); else if (options.output_format == OUTPUT_PS3) - FPDF_SetPrintPostscriptLevel(3); + FPDF_SetPrintMode(3); #endif int page_count = FPDF_GetPageCount(doc.get()); @@ -1029,26 +1364,36 @@ static void ShowConfig() { static const char kUsageString[] = "Usage: pdfium_test [OPTION] [FILE]...\n" - " --show-config - print build options and exit\n" - " --show-structure - print the structure elements from the document\n" - " --send-events - send input described by .evt file\n" - " --bin-dir=<path> - override path to v8 external data\n" - " --font-dir=<path> - override path to external fonts\n" - " --scale=<number> - scale output size by number (e.g. 0.5)\n" + " --show-config - print build options and exit\n" + " --show-metadata - print the file metadata\n" + " --show-structure - print the structure elements from the document\n" + " --send-events - send input described by .evt file\n" + " --render-oneshot - render image without using progressive renderer\n" + " --save-attachments - write embedded attachments " + "<pdf-name>.attachment.<attachment-name>\n" +#ifdef ENABLE_CALLGRIND + " --callgrind-delim - delimit interesting section when using callgrind\n" +#endif // ENABLE_CALLGRIND + " --bin-dir=<path> - override path to v8 external data\n" + " --font-dir=<path> - override path to external fonts\n" + " --scale=<number> - scale output size by number (e.g. 0.5)\n" " --pages=<number>(-<number>) - only render the given 0-based page(s)\n" #ifdef _WIN32 - " --bmp - write page images <pdf-name>.<page-number>.bmp\n" - " --emf - write page meta files <pdf-name>.<page-number>.emf\n" - " --ps2 - write page raw PostScript (Lvl 2) <pdf-name>.<page-number>.ps\n" - " --ps3 - write page raw PostScript (Lvl 3) <pdf-name>.<page-number>.ps\n" + " --bmp - write page images <pdf-name>.<page-number>.bmp\n" + " --emf - write page meta files <pdf-name>.<page-number>.emf\n" + " --ps2 - write page raw PostScript (Lvl 2) " + "<pdf-name>.<page-number>.ps\n" + " --ps3 - write page raw PostScript (Lvl 3) " + "<pdf-name>.<page-number>.ps\n" #endif // _WIN32 - " --txt - write page text in UTF32-LE <pdf-name>.<page-number>.txt\n" - " --png - write page images <pdf-name>.<page-number>.png\n" - " --ppm - write page images <pdf-name>.<page-number>.ppm\n" + " --txt - write page text in UTF32-LE <pdf-name>.<page-number>.txt\n" + " --png - write page images <pdf-name>.<page-number>.png\n" + " --ppm - write page images <pdf-name>.<page-number>.ppm\n" + " --annot - write annotation info <pdf-name>.<page-number>.annot.txt\n" #ifdef PDF_ENABLE_SKIA - " --skp - write page images <pdf-name>.<page-number>.skp\n" + " --skp - write page images <pdf-name>.<page-number>.skp\n" #endif - " --md5 - write output image paths and their md5 hashes to stdout.\n" + " --md5 - write output image paths and their md5 hashes to stdout.\n" ""; int main(int argc, const char* argv[]) { @@ -1110,6 +1455,12 @@ int main(int argc, const char* argv[]) { if (!file_contents) continue; fprintf(stderr, "Rendering PDF file %s.\n", filename.c_str()); + +#ifdef ENABLE_CALLGRIND + if (options.callgrind_delimiters) + CALLGRIND_START_INSTRUMENTATION; +#endif // ENABLE_CALLGRIND + std::string events; if (options.send_events) { std::string event_filename = filename; @@ -1130,6 +1481,11 @@ int main(int argc, const char* argv[]) { } } RenderPdf(filename, file_contents.get(), file_length, options, events); + +#ifdef ENABLE_CALLGRIND + if (options.callgrind_delimiters) + CALLGRIND_STOP_INSTRUMENTATION; +#endif // ENABLE_CALLGRIND } FPDF_DestroyLibrary(); diff --git a/chromium/third_party/pdfium/skia/BUILD.gn b/chromium/third_party/pdfium/skia/BUILD.gn index 9f60fcdc1e1..4e1bde12246 100644 --- a/chromium/third_party/pdfium/skia/BUILD.gn +++ b/chromium/third_party/pdfium/skia/BUILD.gn @@ -26,6 +26,7 @@ config("skia_config") { "//third_party/skia/include/config", "//third_party/skia/include/core", "//third_party/skia/include/effects", + "//third_party/skia/include/encode", "//third_party/skia/include/images", "//third_party/skia/include/lazy", "//third_party/skia/include/pathops", @@ -89,6 +90,7 @@ config("skia_library_config") { "//third_party/skia/src/pdf", "//third_party/skia/src/ports", "//third_party/skia/src/sfnt", + "//third_party/skia/src/shaders", "//third_party/skia/src/sksl", "//third_party/skia/src/utils", "//third_party/skia/src/lazy", @@ -192,6 +194,7 @@ component("skia") { sources += [ "//third_party/skia/src/fonts/SkFontMgr_indirect.cpp", "//third_party/skia/src/fonts/SkRemotableFontMgr.cpp", + "//third_party/skia/src/images/SkImageEncoder.cpp", "//third_party/skia/src/ports/SkFontHost_FreeType.cpp", "//third_party/skia/src/ports/SkFontHost_FreeType_common.cpp", "//third_party/skia/src/ports/SkFontHost_win.cpp", @@ -199,7 +202,6 @@ component("skia") { "//third_party/skia/src/ports/SkFontMgr_android_factory.cpp", "//third_party/skia/src/ports/SkFontMgr_android_parser.cpp", "//third_party/skia/src/ports/SkGlobalInitialization_default.cpp", - "//third_party/skia/src/ports/SkImageEncoder_none.cpp", "//third_party/skia/src/ports/SkImageGenerator_none.cpp", "//third_party/skia/src/ports/SkOSFile_posix.cpp", "//third_party/skia/src/ports/SkOSFile_stdio.cpp", diff --git a/chromium/third_party/pdfium/testing/SUPPRESSIONS b/chromium/third_party/pdfium/testing/SUPPRESSIONS index bccf0d6bd6e..83892895897 100644 --- a/chromium/third_party/pdfium/testing/SUPPRESSIONS +++ b/chromium/third_party/pdfium/testing/SUPPRESSIONS @@ -54,7 +54,7 @@ FRC_15_8.2.2__T8.3_Count_edit1.pdf * * * FRC_16_8.2.2__T8.3_Count_edit_1.pdf * * * FRC_1_8.2.2__T8.3_First_empty.pdf * * * FRC_2_8.2.2__T8.3_Last_empty.pdf * * * -FRC_3.5_P__3616_Password_1.pdf mac,win * * +FRC_3.5_P__3616_Password_1.pdf * * * FRC_3_8.2.2_Type_empty.pdf * * * FRC_4_8.2.2__T8.3_Count_empty.pdf * * * FRC_5_8.2.2__T8.3_First_remove.pdf * * * @@ -286,15 +286,30 @@ zh_file1.pdf mac * * zh_function_list.pdf mac * * zh_shared_document.pdf mac * * +bug_492.in * nov8 * bug_679643.in * * noxfa bug_679642.in * * noxfa # +# TODO(hnakashima): These might never have been run. Go over them and fix. +# +FRC_8.5_E&X.pdf * * * +FRC_8.5_O&PO_GoToE.pdf * * * +FRC_8.5_OpenAction&O_URI.pdf * * * +FRC_8.5_PC&C_GoToE_T_T.pdf * * * +FRC_8.5_PC_GoToE_T_R&P&A.pdf * * * +FRC_8.5_PO_GoToE_T_R&N.pdf * * * + +# # xfa_specific # Choose.pdf * * * data_binding.pdf * * * Date_FormCale.pdf * * * +# TODO(npm): Add proper evt for MouseEvents. +MouseEvents_enter.pdf * * * +MouseEvents_exit.pdf * * * +Oneof3.pdf * * * Sum.pdf * * * TimeField.pdf win,linux * * Test_CheckBox.pdf * * * diff --git a/chromium/third_party/pdfium/testing/SUPPRESSIONS_IMAGE_DIFF b/chromium/third_party/pdfium/testing/SUPPRESSIONS_IMAGE_DIFF new file mode 100644 index 00000000000..cdb2d66f932 --- /dev/null +++ b/chromium/third_party/pdfium/testing/SUPPRESSIONS_IMAGE_DIFF @@ -0,0 +1,32 @@ +# Copyright 2017 The 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. +# +# List of tests to have image diff tests skipped, one per line. +# There are four space-separated columns per line +# Each column (except column 0) can contain a comma-separated list of values. +# +# Column 0: test file name +# Column 1: platform: *, win, mac, linux +# Column 2: v8 support: *, nov8, v8 +# Column 3: xfa support: *, noxfa, xfa +# +# All columns on a line on a line must match, but filenames may be repeated +# on subsequent lines to suppress more cases. Within each column, any one of +# the comma-separated values must match in order for the colum to "match". +# The filenames and keywords are case-sensitive. +# +# Try to keep the file alphabetized within each category of test. + +# +# Corpus tests +# +FRC_3.5_CF_Strf_stmf_DefaultCryptFilter.pdf * * * +FRC_3.5_EncryptMetadata_T.pdf * * * +FRC_3.5_Encrypt_is_damage.pdf * * * +FRC_3.5_Filter_PubSec_SubFilter_s5.pdf * * * +FRC_3.5_Filter_PubSec_Sub_SubFilter_s4.pdf * * * +MouseEvents.pdf * * * +Oneof.pdf * * * +bug_651304.pdf * * * +outline.pdf * * * diff --git a/chromium/third_party/pdfium/testing/embedder_test.cpp b/chromium/third_party/pdfium/testing/embedder_test.cpp index 6cea598400a..0846d8ccb71 100644 --- a/chromium/third_party/pdfium/testing/embedder_test.cpp +++ b/chromium/third_party/pdfium/testing/embedder_test.cpp @@ -73,6 +73,8 @@ EmbedderTest::EmbedderTest() InitializeV8ForPDFium(g_exe_path, &platform_); #endif // V8_USE_EXTERNAL_STARTUP_DATA #endif // FPDF_ENABLE_V8 + FPDF_FILEWRITE::version = 1; + FPDF_FILEWRITE::WriteBlock = WriteBlockCallback; } EmbedderTest::~EmbedderTest() { @@ -106,7 +108,6 @@ void EmbedderTest::TearDown() { FPDFAvail_Destroy(avail_); FPDF_DestroyLibrary(); - delete loader_; } @@ -115,7 +116,7 @@ bool EmbedderTest::CreateEmptyDocument() { if (!document_) return false; - SetupFormFillEnvironment(); + form_handle_ = SetupFormFillEnvironment(document_); return true; } @@ -134,68 +135,73 @@ bool EmbedderTest::OpenDocument(const std::string& filename, file_access_.m_FileLen = static_cast<unsigned long>(file_length_); file_access_.m_GetBlock = TestLoader::GetBlock; file_access_.m_Param = loader_; + return OpenDocumentHelper(password, must_linearize, &file_avail_, &hints_, + &file_access_, &document_, &avail_, &form_handle_); +} - file_avail_.version = 1; - file_avail_.IsDataAvail = Is_Data_Avail; - - hints_.version = 1; - hints_.AddSegment = Add_Segment; - - avail_ = FPDFAvail_Create(&file_avail_, &file_access_); - - if (FPDFAvail_IsLinearized(avail_) == PDF_LINEARIZED) { - document_ = FPDFAvail_GetDocument(avail_, password); - if (!document_) { +bool EmbedderTest::OpenDocumentHelper(const char* password, + bool must_linearize, + FX_FILEAVAIL* file_avail, + FX_DOWNLOADHINTS* hints, + FPDF_FILEACCESS* file_access, + FPDF_DOCUMENT* document, + FPDF_AVAIL* avail, + FPDF_FORMHANDLE* form_handle) { + file_avail->version = 1; + file_avail->IsDataAvail = Is_Data_Avail; + + hints->version = 1; + hints->AddSegment = Add_Segment; + + *avail = FPDFAvail_Create(file_avail, file_access); + + if (FPDFAvail_IsLinearized(*avail) == PDF_LINEARIZED) { + *document = FPDFAvail_GetDocument(*avail, password); + if (!*document) return false; - } + int32_t nRet = PDF_DATA_NOTAVAIL; - while (nRet == PDF_DATA_NOTAVAIL) { - nRet = FPDFAvail_IsDocAvail(avail_, &hints_); - } - if (nRet == PDF_DATA_ERROR) { + while (nRet == PDF_DATA_NOTAVAIL) + nRet = FPDFAvail_IsDocAvail(*avail, hints); + if (nRet == PDF_DATA_ERROR) return false; - } - nRet = FPDFAvail_IsFormAvail(avail_, &hints_); - if (nRet == PDF_FORM_ERROR || nRet == PDF_FORM_NOTAVAIL) { + + nRet = FPDFAvail_IsFormAvail(*avail, hints); + if (nRet == PDF_FORM_ERROR || nRet == PDF_FORM_NOTAVAIL) return false; - } - int page_count = FPDF_GetPageCount(document_); + + int page_count = FPDF_GetPageCount(*document); for (int i = 0; i < page_count; ++i) { nRet = PDF_DATA_NOTAVAIL; - while (nRet == PDF_DATA_NOTAVAIL) { - nRet = FPDFAvail_IsPageAvail(avail_, i, &hints_); - } - if (nRet == PDF_DATA_ERROR) { + while (nRet == PDF_DATA_NOTAVAIL) + nRet = FPDFAvail_IsPageAvail(*avail, i, hints); + + if (nRet == PDF_DATA_ERROR) return false; - } } } else { - if (must_linearize) { + if (must_linearize) return false; - } - document_ = FPDF_LoadCustomDocument(&file_access_, password); - if (!document_) { + + *document = FPDF_LoadCustomDocument(file_access, password); + if (!*document) return false; - } } - - SetupFormFillEnvironment(); - + *form_handle = SetupFormFillEnvironment(*document); #ifdef PDF_ENABLE_XFA int docType = DOCTYPE_PDF; - if (FPDF_HasXFAField(document_, &docType)) { + if (FPDF_HasXFAField(*document, &docType)) { if (docType != DOCTYPE_PDF) - (void)FPDF_LoadXFA(document_); + (void)FPDF_LoadXFA(*document); } #endif // PDF_ENABLE_XFA - - (void)FPDF_GetDocPermissions(document_); + (void)FPDF_GetDocPermissions(*document); return true; } -void EmbedderTest::SetupFormFillEnvironment() { +FPDF_FORMHANDLE EmbedderTest::SetupFormFillEnvironment(FPDF_DOCUMENT doc) { IPDF_JSPLATFORM* platform = static_cast<IPDF_JSPLATFORM*>(this); - memset(platform, 0, sizeof(IPDF_JSPLATFORM)); + memset(platform, '\0', sizeof(IPDF_JSPLATFORM)); platform->version = 2; platform->app_alert = AlertTrampoline; platform->m_isolate = external_isolate_; @@ -211,13 +217,15 @@ void EmbedderTest::SetupFormFillEnvironment() { formfillinfo->FFI_KillTimer = KillTimerTrampoline; formfillinfo->FFI_GetPage = GetPageTrampoline; formfillinfo->m_pJsPlatform = platform; - - form_handle_ = FPDFDOC_InitFormFillEnvironment(document_, formfillinfo); - FPDF_SetFormFieldHighlightColor(form_handle_, 0, 0xFFE4DD); - FPDF_SetFormFieldHighlightAlpha(form_handle_, 100); + FPDF_FORMHANDLE form_handle = + FPDFDOC_InitFormFillEnvironment(doc, formfillinfo); + FPDF_SetFormFieldHighlightColor(form_handle, 0, 0xFFE4DD); + FPDF_SetFormFieldHighlightAlpha(form_handle, 100); + return form_handle; } void EmbedderTest::DoOpenActions() { + ASSERT(form_handle_); FORM_DoDocumentJSAction(form_handle_); FORM_DoDocumentOpenAction(form_handle_); } @@ -230,22 +238,22 @@ int EmbedderTest::GetFirstPageNum() { int EmbedderTest::GetPageCount() { int page_count = FPDF_GetPageCount(document_); - for (int i = 0; i < page_count; ++i) { + for (int i = 0; i < page_count; ++i) (void)FPDFAvail_IsPageAvail(avail_, i, &hints_); - } return page_count; } FPDF_PAGE EmbedderTest::LoadPage(int page_number) { + ASSERT(form_handle_); // First check whether it is loaded already. auto it = page_map_.find(page_number); if (it != page_map_.end()) return it->second; FPDF_PAGE page = FPDF_LoadPage(document_, page_number); - if (!page) { + if (!page) return nullptr; - } + FORM_OnAfterLoadPage(page, form_handle_); FORM_DoPageAAction(page, form_handle_, FPDFPAGE_AACTION_OPEN); // Cache the page. @@ -255,18 +263,25 @@ FPDF_PAGE EmbedderTest::LoadPage(int page_number) { } FPDF_BITMAP EmbedderTest::RenderPage(FPDF_PAGE page) { + return RenderPageWithFlags(page, form_handle_, 0); +} + +FPDF_BITMAP EmbedderTest::RenderPageWithFlags(FPDF_PAGE page, + FPDF_FORMHANDLE handle, + int flags) { int width = static_cast<int>(FPDF_GetPageWidth(page)); int height = static_cast<int>(FPDF_GetPageHeight(page)); int alpha = FPDFPage_HasTransparency(page) ? 1 : 0; FPDF_BITMAP bitmap = FPDFBitmap_Create(width, height, alpha); FPDF_DWORD fill_color = alpha ? 0x00000000 : 0xFFFFFFFF; FPDFBitmap_FillRect(bitmap, 0, 0, width, height, fill_color); - FPDF_RenderPageBitmap(bitmap, page, 0, 0, width, height, 0, 0); - FPDF_FFLDraw(form_handle_, bitmap, page, 0, 0, width, height, 0, 0); + FPDF_RenderPageBitmap(bitmap, page, 0, 0, width, height, 0, flags); + FPDF_FFLDraw(handle, bitmap, page, 0, 0, width, height, 0, flags); return bitmap; } void EmbedderTest::UnloadPage(FPDF_PAGE page) { + ASSERT(form_handle_); FORM_DoPageAAction(page, form_handle_, FPDFPAGE_AACTION_CLOSE); FORM_OnBeforeClosePage(page, form_handle_); FPDF_ClosePage(page); @@ -279,6 +294,42 @@ void EmbedderTest::UnloadPage(FPDF_PAGE page) { page_reverse_map_.erase(it); } +void EmbedderTest::TestSaved(int width, + int height, + const char* md5, + const char* password) { + FPDF_FILEACCESS file_access; + memset(&file_access, 0, sizeof(file_access)); + file_access.m_FileLen = m_String.size(); + file_access.m_GetBlock = GetBlockFromString; + file_access.m_Param = &m_String; + FX_FILEAVAIL file_avail; + FX_DOWNLOADHINTS hints; + + ASSERT_TRUE(OpenDocumentHelper(password, false, &file_avail, &hints, + &file_access, &m_SavedDocument, &m_SavedAvail, + &m_SavedForm)); + EXPECT_EQ(1, FPDF_GetPageCount(m_SavedDocument)); + m_SavedPage = FPDF_LoadPage(m_SavedDocument, 0); + ASSERT_TRUE(m_SavedPage); + FPDF_BITMAP new_bitmap = + RenderPageWithFlags(m_SavedPage, m_SavedForm, FPDF_ANNOT); + CompareBitmap(new_bitmap, width, height, md5); + FPDFBitmap_Destroy(new_bitmap); +} + +void EmbedderTest::CloseSaved() { + FPDF_ClosePage(m_SavedPage); + FPDFDOC_ExitFormFillEnvironment(m_SavedForm); + FPDF_CloseDocument(m_SavedDocument); + FPDFAvail_Destroy(m_SavedAvail); +} + +void EmbedderTest::TestAndCloseSaved(int width, int height, const char* md5) { + TestSaved(width, height, md5); + CloseSaved(); +} + FPDF_PAGE EmbedderTest::Delegate::GetPage(FPDF_FORMFILLINFO* info, FPDF_DOCUMENT document, int page_index) { @@ -352,6 +403,32 @@ void EmbedderTest::CompareBitmap(FPDF_BITMAP bitmap, HashBitmap(bitmap, expected_width, expected_height)); } +// static +int EmbedderTest::WriteBlockCallback(FPDF_FILEWRITE* pFileWrite, + const void* data, + unsigned long size) { + EmbedderTest* pThis = static_cast<EmbedderTest*>(pFileWrite); + pThis->m_String.append(static_cast<const char*>(data), size); + return 1; +} + +// static +int EmbedderTest::GetBlockFromString(void* param, + unsigned long pos, + unsigned char* buf, + unsigned long size) { + std::string* new_file = static_cast<std::string*>(param); + if (!new_file || pos + size < pos) + return 0; + + unsigned long file_size = new_file->size(); + if (pos + size > file_size) + return 0; + + memcpy(buf, new_file->data() + pos, size); + return 1; +} + // Can't use gtest-provided main since we need to stash the path to the // executable in order to find the external V8 binary data files. int main(int argc, char** argv) { diff --git a/chromium/third_party/pdfium/testing/embedder_test.h b/chromium/third_party/pdfium/testing/embedder_test.h index 2bb796d905a..878e50bfdd1 100644 --- a/chromium/third_party/pdfium/testing/embedder_test.h +++ b/chromium/third_party/pdfium/testing/embedder_test.h @@ -12,6 +12,7 @@ #include "public/fpdf_dataavail.h" #include "public/fpdf_ext.h" #include "public/fpdf_formfill.h" +#include "public/fpdf_save.h" #include "public/fpdfview.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/test_support.h" @@ -27,7 +28,8 @@ class TestLoader; class EmbedderTest : public ::testing::Test, public UNSUPPORT_INFO, public IPDF_JSPLATFORM, - public FPDF_FORMFILLINFO { + public FPDF_FORMFILLINFO, + public FPDF_FILEWRITE { public: class Delegate { public: @@ -101,12 +103,27 @@ class EmbedderTest : public ::testing::Test, // Convert a loaded page into a bitmap. virtual FPDF_BITMAP RenderPage(FPDF_PAGE page); + // Convert a loaded page into a bitmap with page rendering flags specified. + // See public/fpdfview.h for a list of page rendering flags. + virtual FPDF_BITMAP RenderPageWithFlags(FPDF_PAGE page, + FPDF_FORMHANDLE handle, + int flags); + // Relese the resources obtained from LoadPage(). Further use of |page| // is prohibited after this call is made. virtual void UnloadPage(FPDF_PAGE page); protected: - void SetupFormFillEnvironment(); + bool OpenDocumentHelper(const char* password, + bool must_linearize, + FX_FILEAVAIL* file_avail, + FX_DOWNLOADHINTS* hints, + FPDF_FILEACCESS* file_access, + FPDF_DOCUMENT* document, + FPDF_AVAIL* avail, + FPDF_FORMHANDLE* form_handle); + + FPDF_FORMHANDLE SetupFormFillEnvironment(FPDF_DOCUMENT doc); // Return the hash of |bitmap|. static std::string HashBitmap(FPDF_BITMAP bitmap, @@ -119,6 +136,21 @@ class EmbedderTest : public ::testing::Test, int expected_height, const char* expected_md5sum); + void ClearString() { m_String.clear(); } + const std::string& GetString() const { return m_String; } + + static int GetBlockFromString(void* param, + unsigned long pos, + unsigned char* buf, + unsigned long size); + + void TestSaved(int width, + int height, + const char* md5, + const char* password = nullptr); + void CloseSaved(); + void TestAndCloseSaved(int width, int height, const char* md5); + Delegate* delegate_; std::unique_ptr<Delegate> default_delegate_; FPDF_DOCUMENT document_; @@ -136,6 +168,10 @@ class EmbedderTest : public ::testing::Test, std::unique_ptr<char, pdfium::FreeDeleter> file_contents_; std::map<int, FPDF_PAGE> page_map_; std::map<FPDF_PAGE, int> page_reverse_map_; + FPDF_DOCUMENT m_SavedDocument; + FPDF_PAGE m_SavedPage; + FPDF_FORMHANDLE m_SavedForm; + FPDF_AVAIL m_SavedAvail; private: static void UnsupportedHandlerTrampoline(UNSUPPORT_INFO*, int type); @@ -151,6 +187,11 @@ class EmbedderTest : public ::testing::Test, static FPDF_PAGE GetPageTrampoline(FPDF_FORMFILLINFO* info, FPDF_DOCUMENT document, int page_index); + static int WriteBlockCallback(FPDF_FILEWRITE* pFileWrite, + const void* data, + unsigned long size); + + std::string m_String; }; #endif // TESTING_EMBEDDER_TEST_H_ diff --git a/chromium/third_party/pdfium/testing/fx_string_testhelpers.cpp b/chromium/third_party/pdfium/testing/fx_string_testhelpers.cpp index 934dd680e40..443cc89ed17 100644 --- a/chromium/third_party/pdfium/testing/fx_string_testhelpers.cpp +++ b/chromium/third_party/pdfium/testing/fx_string_testhelpers.cpp @@ -6,43 +6,13 @@ #include <iomanip> #include <ios> - -namespace { - -template <typename T> -std::ostream& output_string(std::ostream& out, const T& str) { - out << std::hex << std::setfill('0') << '"'; - // This function is used for FX strings whose length is defined as int. - for (int i = 0; i < str.GetLength(); ++i) { - unsigned int c = str.GetAt(i); - if (c >= 0x20 && c < 0x7F) { - out << static_cast<char>(c); - } else if (sizeof(typename T::CharType) == 1) { - out << "\\x" << std::setw(2) << c << std::setw(0); - } else if (c < 0x10000) { - out << "\\u" << std::setw(4) << c << std::setw(0); - } else { - out << "<invalid>"; - } - } - out << '"' << std::dec << std::setfill(' '); - return out; -} - -} // namespace - -std::ostream& operator<<(std::ostream& out, const CFX_ByteStringC& str) { - return output_string(out, str); -} - -std::ostream& operator<<(std::ostream& out, const CFX_ByteString& str) { - return output_string(out, str); -} - -std::ostream& operator<<(std::ostream& out, const CFX_WideStringC& str) { - return output_string(out, str); -} - -std::ostream& operator<<(std::ostream& out, const CFX_WideString& str) { - return output_string(out, str); +#include <string> + +std::ostream& operator<<(std::ostream& os, const CFX_DateTime& dt) { + os << dt.GetYear() << "-" << std::to_string(dt.GetMonth()) << "-" + << std::to_string(dt.GetDay()) << " " << std::to_string(dt.GetHour()) + << ":" << std::to_string(dt.GetMinute()) << ":" + << std::to_string(dt.GetSecond()) << "." + << std::to_string(dt.GetMillisecond()); + return os; } diff --git a/chromium/third_party/pdfium/testing/fx_string_testhelpers.h b/chromium/third_party/pdfium/testing/fx_string_testhelpers.h index 82552d72274..34ac69dab41 100644 --- a/chromium/third_party/pdfium/testing/fx_string_testhelpers.h +++ b/chromium/third_party/pdfium/testing/fx_string_testhelpers.h @@ -7,12 +7,9 @@ #include <ostream> -#include "core/fxcrt/fx_string.h" +#include "core/fxcrt/cfx_datetime.h" -// Output stream operator so GTEST macros work with FX strings. -std::ostream& operator<<(std::ostream& out, const CFX_ByteStringC& str); -std::ostream& operator<<(std::ostream& out, const CFX_ByteString& str); -std::ostream& operator<<(std::ostream& out, const CFX_WideStringC& str); -std::ostream& operator<<(std::ostream& out, const CFX_WideString& str); +// Output stream operator so GTEST macros work with CFX_DateTime objects. +std::ostream& operator<<(std::ostream& os, const CFX_DateTime& dt); #endif // TESTING_FX_STRING_TESTHELPERS_H_ diff --git a/chromium/third_party/pdfium/testing/image_diff/DEPS b/chromium/third_party/pdfium/testing/image_diff/DEPS new file mode 100644 index 00000000000..4bd2335cd7e --- /dev/null +++ b/chromium/third_party/pdfium/testing/image_diff/DEPS @@ -0,0 +1,5 @@ +include_rules = [ + '+third_party/libpng16', + '+third_party/zlib', +] + diff --git a/chromium/third_party/pdfium/samples/image_diff.cc b/chromium/third_party/pdfium/testing/image_diff/image_diff.cpp index 70c74c951c7..806e0c84d51 100644 --- a/chromium/third_party/pdfium/samples/image_diff.cc +++ b/chromium/third_party/pdfium/testing/image_diff/image_diff.cpp @@ -19,7 +19,8 @@ #include <string> #include <vector> -#include "samples/image_diff_png.h" +#include "core/fxcrt/fx_memory.h" +#include "testing/image_diff/image_diff_png.h" #include "third_party/base/logging.h" #include "third_party/base/numerics/safe_conversions.h" @@ -38,30 +39,13 @@ static const uint32_t RGBA_ALPHA = 0xff000000; class Image { public: - Image() : w_(0), h_(0) { - } - - Image(const Image& image) - : w_(image.w_), - h_(image.h_), - data_(image.data_) { - } + Image() : w_(0), h_(0) {} + Image(const Image& image) : w_(image.w_), h_(image.h_), data_(image.data_) {} - bool has_image() const { - return w_ > 0 && h_ > 0; - } - - int w() const { - return w_; - } - - int h() const { - return h_; - } - - const unsigned char* data() const { - return &data_.front(); - } + bool has_image() const { return w_ > 0 && h_ > 0; } + int w() const { return w_; } + int h() const { return h_; } + const unsigned char* data() const { return &data_.front(); } // Creates the image from the given filename on disk, and returns true on // success. @@ -201,15 +185,16 @@ float HistogramPercentageDifferent(const Image& baseline, const Image& actual) { } void PrintHelp() { - fprintf(stderr, - "Usage:\n" - " image_diff [--histogram] <compare file> <reference file>\n" - " Compares two files on disk, returning 0 when they are the same;\n" - " passing \"--histogram\" additionally calculates a diff of the\n" - " RGBA value histograms (which is resistant to shifts in layout)\n" - " image_diff --diff <compare file> <reference file> <output file>\n" - " Compares two files on disk, outputs an image that visualizes the\n" - " difference to <output file>\n"); + fprintf( + stderr, + "Usage:\n" + " image_diff [--histogram] <compare file> <reference file>\n" + " Compares two files on disk, returning 0 when they are the same;\n" + " passing \"--histogram\" additionally calculates a diff of the\n" + " RGBA value histograms (which is resistant to shifts in layout)\n" + " image_diff --diff <compare file> <reference file> <output file>\n" + " Compares two files on disk, outputs an image that visualizes the\n" + " difference to <output file>\n"); } int CompareImages(const std::string& file1, @@ -295,9 +280,9 @@ int DiffImages(const std::string& file1, return kStatusSame; std::vector<unsigned char> png_encoding; - image_diff_png::EncodeRGBAPNG( - diff_image.data(), diff_image.w(), diff_image.h(), - diff_image.w() * 4, &png_encoding); + image_diff_png::EncodeRGBAPNG(diff_image.data(), diff_image.w(), + diff_image.h(), diff_image.w() * 4, + &png_encoding); FILE* f = fopen(out_file.c_str(), "wb"); if (!f) @@ -312,6 +297,8 @@ int DiffImages(const std::string& file1, } int main(int argc, const char* argv[]) { + FXMEM_InitializePartitionAlloc(); + bool histograms = false; bool produce_diff_image = false; std::string filename1; diff --git a/chromium/third_party/pdfium/samples/image_diff_png.cc b/chromium/third_party/pdfium/testing/image_diff/image_diff_png.cpp index 3d12b7e948a..a5e8cdb1019 100644 --- a/chromium/third_party/pdfium/samples/image_diff_png.cc +++ b/chromium/third_party/pdfium/testing/image_diff/image_diff_png.cpp @@ -9,7 +9,7 @@ // This is a duplicate of ui/gfx/codec/png_codec.cc, after removing code related // to Skia, that we can use when running layout tests with minimal dependencies. -#include "samples/image_diff_png.h" +#include "testing/image_diff/image_diff_png.h" #include <stdlib.h> #include <string.h> @@ -44,8 +44,10 @@ struct Comment { }; // Converts BGRA->RGBA and RGBA->BGRA. -void ConvertBetweenBGRAandRGBA(const unsigned char* input, int pixel_width, - unsigned char* output, bool* is_opaque) { +void ConvertBetweenBGRAandRGBA(const unsigned char* input, + int pixel_width, + unsigned char* output, + bool* is_opaque) { for (int x = 0; x < pixel_width; x++) { const unsigned char* pixel_in = &input[x * 4]; unsigned char* pixel_out = &output[x * 4]; @@ -56,8 +58,10 @@ void ConvertBetweenBGRAandRGBA(const unsigned char* input, int pixel_width, } } -void ConvertRGBAtoRGB(const unsigned char* rgba, int pixel_width, - unsigned char* rgb, bool* is_opaque) { +void ConvertRGBAtoRGB(const unsigned char* rgba, + int pixel_width, + unsigned char* rgb, + bool* is_opaque) { for (int x = 0; x < pixel_width; x++) { const unsigned char* pixel_in = &rgba[x * 4]; unsigned char* pixel_out = &rgb[x * 3]; @@ -92,8 +96,7 @@ class PngDecoderState { row_converter(NULL), width(0), height(0), - done(false) { - } + done(false) {} ColorFormat output_format; int output_channels; @@ -107,7 +110,9 @@ class PngDecoderState { // Called to convert a row from the library to the correct output format. // When NULL, no conversion is necessary. - void (*row_converter)(const unsigned char* in, int w, unsigned char* out, + void (*row_converter)(const unsigned char* in, + int w, + unsigned char* out, bool* is_opaque); // Size of the image, set in the info callback. @@ -118,8 +123,10 @@ class PngDecoderState { bool done; }; -void ConvertRGBtoRGBA(const unsigned char* rgb, int pixel_width, - unsigned char* rgba, bool* is_opaque) { +void ConvertRGBtoRGBA(const unsigned char* rgb, + int pixel_width, + unsigned char* rgba, + bool* is_opaque) { for (int x = 0; x < pixel_width; x++) { const unsigned char* pixel_in = &rgb[x * 3]; unsigned char* pixel_out = &rgba[x * 4]; @@ -130,8 +137,10 @@ void ConvertRGBtoRGBA(const unsigned char* rgb, int pixel_width, } } -void ConvertRGBtoBGRA(const unsigned char* rgb, int pixel_width, - unsigned char* bgra, bool* is_opaque) { +void ConvertRGBtoBGRA(const unsigned char* rgb, + int pixel_width, + unsigned char* bgra, + bool* is_opaque) { for (int x = 0; x < pixel_width; x++) { const unsigned char* pixel_in = &rgb[x * 3]; unsigned char* pixel_out = &bgra[x * 4]; @@ -145,8 +154,8 @@ void ConvertRGBtoBGRA(const unsigned char* rgb, int pixel_width, // Called when the png header has been read. This code is based on the WebKit // PNGImageDecoder void DecodeInfoCallback(png_struct* png_ptr, png_info* info_ptr) { - PngDecoderState* state = static_cast<PngDecoderState*>( - png_get_progressive_ptr(png_ptr)); + PngDecoderState* state = + static_cast<PngDecoderState*>(png_get_progressive_ptr(png_ptr)); int bit_depth, color_type, interlace_type, compression_type; int filter_type, channels; @@ -246,14 +255,15 @@ void DecodeInfoCallback(png_struct* png_ptr, png_info* info_ptr) { longjmp(png_jmpbuf(png_ptr), 1); } - state->output->resize( - state->width * state->output_channels * state->height); + state->output->resize(state->width * state->output_channels * state->height); } -void DecodeRowCallback(png_struct* png_ptr, png_byte* new_row, - png_uint_32 row_num, int pass) { - PngDecoderState* state = static_cast<PngDecoderState*>( - png_get_progressive_ptr(png_ptr)); +void DecodeRowCallback(png_struct* png_ptr, + png_byte* new_row, + png_uint_32 row_num, + int pass) { + PngDecoderState* state = + static_cast<PngDecoderState*>(png_get_progressive_ptr(png_ptr)); if (static_cast<int>(row_num) > state->height) { NOTREACHED(); @@ -271,8 +281,8 @@ void DecodeRowCallback(png_struct* png_ptr, png_byte* new_row, } void DecodeEndCallback(png_struct* png_ptr, png_info* info) { - PngDecoderState* state = static_cast<PngDecoderState*>( - png_get_progressive_ptr(png_ptr)); + PngDecoderState* state = + static_cast<PngDecoderState*>(png_get_progressive_ptr(png_ptr)); // Mark the image as complete, this will tell the Decode function that we // have successfully found the end of the data. @@ -283,18 +293,18 @@ void DecodeEndCallback(png_struct* png_ptr, png_info* info) { // cleanup and error handling code cleaner. class PngReadStructDestroyer { public: - PngReadStructDestroyer(png_struct** ps, png_info** pi) : ps_(ps), pi_(pi) { - } - ~PngReadStructDestroyer() { - png_destroy_read_struct(ps_, pi_, NULL); - } + PngReadStructDestroyer(png_struct** ps, png_info** pi) : ps_(ps), pi_(pi) {} + ~PngReadStructDestroyer() { png_destroy_read_struct(ps_, pi_, NULL); } + private: png_struct** ps_; png_info** pi_; }; -bool BuildPNGStruct(const unsigned char* input, size_t input_size, - png_struct** png_ptr, png_info** info_ptr) { +bool BuildPNGStruct(const unsigned char* input, + size_t input_size, + png_struct** png_ptr, + png_info** info_ptr) { if (input_size < 8) return false; // Input data too small to be a png @@ -318,9 +328,12 @@ bool BuildPNGStruct(const unsigned char* input, size_t input_size, } // namespace // static -bool Decode(const unsigned char* input, size_t input_size, - ColorFormat format, std::vector<unsigned char>* output, - int* w, int* h) { +bool Decode(const unsigned char* input, + size_t input_size, + ColorFormat format, + std::vector<unsigned char>* output, + int* w, + int* h) { png_struct* png_ptr = NULL; png_info* info_ptr = NULL; if (!BuildPNGStruct(input, input_size, &png_ptr, &info_ptr)) @@ -338,9 +351,7 @@ bool Decode(const unsigned char* input, size_t input_size, png_set_progressive_read_fn(png_ptr, &state, &DecodeInfoCallback, &DecodeRowCallback, &DecodeEndCallback); - png_process_data(png_ptr, - info_ptr, - const_cast<unsigned char*>(input), + png_process_data(png_ptr, info_ptr, const_cast<unsigned char*>(input), input_size); if (!state.done) { @@ -382,8 +393,10 @@ void FakeFlushCallback(png_structp png) { // we're required to provide this function by libpng. } -void ConvertBGRAtoRGB(const unsigned char* bgra, int pixel_width, - unsigned char* rgb, bool* is_opaque) { +void ConvertBGRAtoRGB(const unsigned char* bgra, + int pixel_width, + unsigned char* rgb, + bool* is_opaque) { for (int x = 0; x < pixel_width; x++) { const unsigned char* pixel_in = &bgra[x * 4]; unsigned char* pixel_out = &rgb[x * 3]; @@ -406,8 +419,7 @@ inline char* strdup(const char* str) { class CommentWriter { public: explicit CommentWriter(const std::vector<Comment>& comments) - : comments_(comments), - png_text_(new png_text[comments.size()]) { + : comments_(comments), png_text_(new png_text[comments.size()]) { for (size_t i = 0; i < comments.size(); ++i) AddComment(i, comments[i]); } @@ -417,20 +429,14 @@ class CommentWriter { free(png_text_[i].key); free(png_text_[i].text); } - delete [] png_text_; + delete[] png_text_; } - bool HasComments() { - return !comments_.empty(); - } + bool HasComments() { return !comments_.empty(); } - png_text* get_png_text() { - return png_text_; - } + png_text* get_png_text() { return png_text_; } - int size() { - return static_cast<int>(comments_.size()); - } + int size() { return static_cast<int>(comments_.size()); } private: void AddComment(size_t pos, const Comment& comment) { @@ -454,18 +460,25 @@ class CommentWriter { #endif // PNG_TEXT_SUPPORTED // The type of functions usable for converting between pixel formats. -typedef void (*FormatConverter)(const unsigned char* in, int w, - unsigned char* out, bool* is_opaque); +typedef void (*FormatConverter)(const unsigned char* in, + int w, + unsigned char* out, + bool* is_opaque); // libpng uses a wacky setjmp-based API, which makes the compiler nervous. // We constrain all of the calls we make to libpng where the setjmp() is in // place to this function. // Returns true on success. -bool DoLibpngWrite(png_struct* png_ptr, png_info* info_ptr, +bool DoLibpngWrite(png_struct* png_ptr, + png_info* info_ptr, PngEncoderState* state, - int width, int height, int row_byte_width, - const unsigned char* input, int compression_level, - int png_output_color_type, int output_color_components, + int width, + int height, + int row_byte_width, + const unsigned char* input, + int compression_level, + int png_output_color_type, + int output_color_components, FormatConverter converter, const std::vector<Comment>& comments) { #ifdef PNG_TEXT_SUPPORTED @@ -501,14 +514,14 @@ bool DoLibpngWrite(png_struct* png_ptr, png_info* info_ptr, if (!converter) { // No conversion needed, give the data directly to libpng. - for (int y = 0; y < height; y ++) { + for (int y = 0; y < height; y++) { png_write_row(png_ptr, const_cast<unsigned char*>(&input[y * row_byte_width])); } } else { // Needs conversion using a separate buffer. row_buffer = new unsigned char[width * output_color_components]; - for (int y = 0; y < height; y ++) { + for (int y = 0; y < height; y++) { converter(&input[y * row_byte_width], width, row_buffer, NULL); png_write_row(png_ptr, row_buffer); } @@ -522,8 +535,10 @@ bool DoLibpngWrite(png_struct* png_ptr, png_info* info_ptr, } // namespace // static -bool EncodeWithCompressionLevel(const unsigned char* input, ColorFormat format, - const int width, const int height, +bool EncodeWithCompressionLevel(const unsigned char* input, + ColorFormat format, + const int width, + const int height, int row_byte_width, bool discard_transparency, const std::vector<Comment>& comments, @@ -578,8 +593,8 @@ bool EncodeWithCompressionLevel(const unsigned char* input, ColorFormat format, if (input_color_components * width < row_byte_width) return false; - png_struct* png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, - NULL, NULL, NULL); + png_struct* png_ptr = + png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); if (!png_ptr) return false; png_info* info_ptr = png_create_info_struct(png_ptr); @@ -589,32 +604,35 @@ bool EncodeWithCompressionLevel(const unsigned char* input, ColorFormat format, } PngEncoderState state(output); - bool success = DoLibpngWrite(png_ptr, info_ptr, &state, - width, height, row_byte_width, - input, compression_level, png_output_color_type, - output_color_components, converter, comments); + bool success = + DoLibpngWrite(png_ptr, info_ptr, &state, width, height, row_byte_width, + input, compression_level, png_output_color_type, + output_color_components, converter, comments); png_destroy_write_struct(&png_ptr, &info_ptr); return success; } // static -bool Encode(const unsigned char* input, ColorFormat format, - const int width, const int height, int row_byte_width, +bool Encode(const unsigned char* input, + ColorFormat format, + const int width, + const int height, + int row_byte_width, bool discard_transparency, const std::vector<Comment>& comments, std::vector<unsigned char>* output) { return EncodeWithCompressionLevel(input, format, width, height, - row_byte_width, - discard_transparency, - comments, Z_DEFAULT_COMPRESSION, - output); + row_byte_width, discard_transparency, + comments, Z_DEFAULT_COMPRESSION, output); } // Decode a PNG into an RGBA pixel array. -bool DecodePNG(const unsigned char* input, size_t input_size, +bool DecodePNG(const unsigned char* input, + size_t input_size, std::vector<unsigned char>* output, - int* width, int* height) { + int* width, + int* height) { return Decode(input, input_size, FORMAT_RGBA, output, width, height); } @@ -624,9 +642,8 @@ bool EncodeRGBAPNG(const unsigned char* input, int height, int row_byte_width, std::vector<unsigned char>* output) { - return Encode(input, FORMAT_RGBA, - width, height, row_byte_width, false, - std::vector<Comment>(), output); + return Encode(input, FORMAT_RGBA, width, height, row_byte_width, false, + std::vector<Comment>(), output); } // Encode an BGRA pixel array into a PNG. @@ -636,9 +653,8 @@ bool EncodeBGRAPNG(const unsigned char* input, int row_byte_width, bool discard_transparency, std::vector<unsigned char>* output) { - return Encode(input, FORMAT_BGRA, - width, height, row_byte_width, discard_transparency, - std::vector<Comment>(), output); + return Encode(input, FORMAT_BGRA, width, height, row_byte_width, + discard_transparency, std::vector<Comment>(), output); } } // namespace image_diff_png diff --git a/chromium/third_party/pdfium/samples/image_diff_png.h b/chromium/third_party/pdfium/testing/image_diff/image_diff_png.h index 7bb395a4a54..4d87aa1cc05 100644 --- a/chromium/third_party/pdfium/samples/image_diff_png.h +++ b/chromium/third_party/pdfium/testing/image_diff/image_diff_png.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef SAMPLES_IMAGE_DIFF_PNG_H_ -#define SAMPLES_IMAGE_DIFF_PNG_H_ +#ifndef TESTING_IMAGE_DIFF_IMAGE_DIFF_PNG_H_ +#define TESTING_IMAGE_DIFF_IMAGE_DIFF_PNG_H_ #include <stdlib.h> // for size_t. @@ -35,4 +35,4 @@ bool EncodeBGRAPNG(const unsigned char* input, } // namespace image_diff_png -#endif // SAMPLES_IMAGE_DIFF_PNG_H_ +#endif // TESTING_IMAGE_DIFF_IMAGE_DIFF_PNG_H_ diff --git a/chromium/third_party/pdfium/testing/libfuzzer/pdf_cmap_fuzzer.cc b/chromium/third_party/pdfium/testing/libfuzzer/pdf_cmap_fuzzer.cc index ef0f6842124..b0e41d511c6 100644 --- a/chromium/third_party/pdfium/testing/libfuzzer/pdf_cmap_fuzzer.cc +++ b/chromium/third_party/pdfium/testing/libfuzzer/pdf_cmap_fuzzer.cc @@ -4,7 +4,7 @@ #include <cstdint> -#include "core/fpdfapi/font/font_int.h" +#include "core/fpdfapi/font/cpdf_cmap.h" #include "third_party/base/ptr_util.h" extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { diff --git a/chromium/third_party/pdfium/testing/libfuzzer/pdf_codec_icc_fuzzer.cc b/chromium/third_party/pdfium/testing/libfuzzer/pdf_codec_icc_fuzzer.cc index c7abdd69a44..7021017953c 100644 --- a/chromium/third_party/pdfium/testing/libfuzzer/pdf_codec_icc_fuzzer.cc +++ b/chromium/third_party/pdfium/testing/libfuzzer/pdf_codec_icc_fuzzer.cc @@ -9,7 +9,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { CCodec_IccModule icc_module; uint32_t nComponent = 0; - void* transform = icc_module.CreateTransform_sRGB(data, size, nComponent); + std::unique_ptr<CLcmsCmm> transform = + icc_module.CreateTransform_sRGB(data, size, &nComponent); if (transform) { float src[4]; @@ -17,8 +18,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { for (int i = 0; i < 4; i++) src[i] = 0.5f; icc_module.SetComponents(nComponent); - icc_module.Translate(transform, src, dst); - icc_module.DestroyTransform(transform); + icc_module.Translate(transform.get(), src, dst); } return 0; diff --git a/chromium/third_party/pdfium/testing/libfuzzer/pdf_css_fuzzer.cc b/chromium/third_party/pdfium/testing/libfuzzer/pdf_css_fuzzer.cc index 43ce686c226..d3b2e6a9967 100644 --- a/chromium/third_party/pdfium/testing/libfuzzer/pdf_css_fuzzer.cc +++ b/chromium/third_party/pdfium/testing/libfuzzer/pdf_css_fuzzer.cc @@ -18,9 +18,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { if (input.GetLength() == 0) return 0; - CFDE_CSSSyntaxParser parser; - parser.Init(input.c_str(), input.GetLength()); - + CFDE_CSSSyntaxParser parser(input.c_str(), input.GetLength()); FDE_CSSSyntaxStatus status; do { status = parser.DoSyntaxParse(); diff --git a/chromium/third_party/pdfium/testing/resources/about_blank.pdf b/chromium/third_party/pdfium/testing/resources/about_blank.pdf Binary files differdeleted file mode 100644 index d640582d6a0..00000000000 --- a/chromium/third_party/pdfium/testing/resources/about_blank.pdf +++ /dev/null diff --git a/chromium/third_party/pdfium/testing/resources/annotiter.in b/chromium/third_party/pdfium/testing/resources/annotiter.in deleted file mode 100644 index 4dc2a4ee2e2..00000000000 --- a/chromium/third_party/pdfium/testing/resources/annotiter.in +++ /dev/null @@ -1,129 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R - /AcroForm 20 0 R ->> -endobj -{{object 2 0}} << - /Type /Pages - /Count 3 - /Kids [ - 10 0 R - 11 0 R - 12 0 R - ] ->> -endobj -% Page number 0. -{{object 10 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /MediaBox [0 0 612 792] - /Annots [ - 22 0 R - 23 0 R - 24 0 R - 25 0 R - ] - /Tabs /R ->> -endobj -% Page number 1. -{{object 11 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /MediaBox [0 0 612 792] - /Annots [ - 22 0 R - 23 0 R - 24 0 R - 25 0 R - ] - /Tabs /C ->> -endobj -% Page number 2. -{{object 12 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /MediaBox [0 0 612 792] - /Annots [ - 22 0 R - 23 0 R - 24 0 R - 25 0 R - ] - /Tabs /S ->> -endobj -% Forms -{{object 20 0}} << - /Fields [21 0 R] ->> -endobj -% Fields -{{object 21 0}} << - /T (MyField) - /Type /Annot - /Subtype /Widget - /Rect [100 100 500 500] - /Kids [ - 22 0 R - 23 0 R - 24 0 R - 25 0 R - ] ->> -endobj -{{object 22 0}} << - /FT /Tx - /Parent 5 0 R - /T (Sub_LeftBottom) - /Type /Annot - /Subtype /Widget - /Rect [200 200 220 220] ->> -endobj -{{object 23 0}} << - /FT /Tx - /Parent 5 0 R - /T (Sub_RightTop) - /Type /Annot - /Subtype /Widget - /Rect [401 401 421 421] ->> -endobj -{{object 24 0}} << - /FT /Tx - /Parent 5 0 R - /T (Sub_LeftTop) - /Type /Annot - /Subtype /Widget - /Rect [201 400 221 420] ->> -endobj -{{object 25 0}} << - /FT /Tx - /Parent 5 0 R - /T (Sub_RightBottom) - /Type /Annot - /Subtype /Widget - /Rect [400 201 420 221] ->> -endobj -{{xref}} -trailer << - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/annotiter.pdf b/chromium/third_party/pdfium/testing/resources/annotiter.pdf deleted file mode 100644 index 2cb6d395d00..00000000000 --- a/chromium/third_party/pdfium/testing/resources/annotiter.pdf +++ /dev/null @@ -1,158 +0,0 @@ -%PDF-1.7 -% ò¤ô -1 0 obj << - /Type /Catalog - /Pages 2 0 R - /AcroForm 20 0 R ->> -endobj -2 0 obj << - /Type /Pages - /Count 3 - /Kids [ - 10 0 R - 11 0 R - 12 0 R - ] ->> -endobj -% Page number 0. -10 0 obj << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /MediaBox [0 0 612 792] - /Annots [ - 22 0 R - 23 0 R - 24 0 R - 25 0 R - ] - /Tabs /R ->> -endobj -% Page number 1. -11 0 obj << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /MediaBox [0 0 612 792] - /Annots [ - 22 0 R - 23 0 R - 24 0 R - 25 0 R - ] - /Tabs /C ->> -endobj -% Page number 2. -12 0 obj << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /MediaBox [0 0 612 792] - /Annots [ - 22 0 R - 23 0 R - 24 0 R - 25 0 R - ] - /Tabs /S ->> -endobj -% Forms -20 0 obj << - /Fields [21 0 R] ->> -endobj -% Fields -21 0 obj << - /T (MyField) - /Type /Annot - /Subtype /Widget - /Rect [100 100 500 500] - /Kids [ - 22 0 R - 23 0 R - 24 0 R - 25 0 R - ] ->> -endobj -22 0 obj << - /FT /Tx - /Parent 5 0 R - /T (Sub_LeftBottom) - /Type /Annot - /Subtype /Widget - /Rect [200 200 220 220] ->> -endobj -23 0 obj << - /FT /Tx - /Parent 5 0 R - /T (Sub_RightTop) - /Type /Annot - /Subtype /Widget - /Rect [401 401 421 421] ->> -endobj -24 0 obj << - /FT /Tx - /Parent 5 0 R - /T (Sub_LeftTop) - /Type /Annot - /Subtype /Widget - /Rect [201 400 221 420] ->> -endobj -25 0 obj << - /FT /Tx - /Parent 5 0 R - /T (Sub_RightBottom) - /Type /Annot - /Subtype /Widget - /Rect [400 201 420 221] ->> -endobj -xref -0 26 -0000000000 65535 f -0000000015 00000 n -0000000087 00000 n -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000198 00000 n -0000000410 00000 n -0000000622 00000 n -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000825 00000 n -0000000875 00000 n -0000001030 00000 n -0000001160 00000 n -0000001288 00000 n -0000001415 00000 n -trailer << - /Root 1 0 R ->> -startxref -1546 -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/black.pdf b/chromium/third_party/pdfium/testing/resources/black.pdf Binary files differdeleted file mode 100644 index 8513d9f3fd6..00000000000 --- a/chromium/third_party/pdfium/testing/resources/black.pdf +++ /dev/null diff --git a/chromium/third_party/pdfium/testing/resources/bookmarks.in b/chromium/third_party/pdfium/testing/resources/bookmarks.in deleted file mode 100644 index dfa6e1426f6..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bookmarks.in +++ /dev/null @@ -1,98 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R - /Outlines 14 0 R ->> -endobj -{{object 2 0}} << - /Type /Pages - /Count 2 - /Kids [ - 3 0 R - 4 0 R - ] ->> -endobj -% Page number 0. -{{object 3 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /Contents [21 0 R] - /MediaBox [0 0 612 792] ->> -endobj -% Page number 1. -{{object 4 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /Contents [22 0 R] - /MediaBox [0 0 612 792] ->> -endobj -% First bookmark -{{object 10 0}} << - /Title (A Good Beginning) - /Parent 14 0 R - /Next 11 0 R - /Dest (foo) ->> -endobj -% Last bookmark -{{object 11 0}} << - /Title (A Good Ending) - /Parent 14 0 R - /Prev 10 0 R - /Dest (bar) ->> -endobj -% Root bookmark -{{object 14 0}} << - /Type /Outlines - /First 10 0 R - /Last 11 0 R - /Count 2 ->> -endobj -% Font resource. -{{object 15 0}} << - /Type /Font - /Subtype /Type1 - /BaseFont /Arial ->> -endobj -% Content for page 0. -{{object 21 0}} << - /Length 0 ->> -stream -BT -/F1 20 Tf -100 600 TD (Page1)Tj -ET -endstream -endobj -% Content for page 1. -{{object 22 0}} << - /Length 0 ->> -stream -BT -/F1 20 Tf -100 600 TD (Page2)Tj -ET -endstream -endobj -{{xref}} -trailer << - /Size 6 - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bookmarks.pdf b/chromium/third_party/pdfium/testing/resources/bookmarks.pdf deleted file mode 100644 index 824ce78db7c..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bookmarks.pdf +++ /dev/null @@ -1,124 +0,0 @@ -%PDF-1.7 -% ò¤ô -1 0 obj << - /Type /Catalog - /Pages 2 0 R - /Outlines 14 0 R ->> -endobj -2 0 obj << - /Type /Pages - /Count 2 - /Kids [ - 3 0 R - 4 0 R - ] ->> -endobj -% Page number 0. -3 0 obj << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /Contents [21 0 R] - /MediaBox [0 0 612 792] ->> -endobj -% Page number 1. -4 0 obj << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /Contents [22 0 R] - /MediaBox [0 0 612 792] ->> -endobj -% First bookmark -10 0 obj << - /Title (A Good Beginning) - /Parent 14 0 R - /Next 11 0 R - /Dest (foo) ->> -endobj -% Last bookmark -11 0 obj << - /Title (A Good Ending) - /Parent 14 0 R - /Prev 10 0 R - /Dest (bar) ->> -endobj -% Root bookmark -14 0 obj << - /Type /Outlines - /First 10 0 R - /Last 11 0 R - /Count 2 ->> -endobj -% Font resource. -15 0 obj << - /Type /Font - /Subtype /Type1 - /BaseFont /Arial ->> -endobj -% Content for page 0. -21 0 obj << - /Length 0 ->> -stream -BT -/F1 20 Tf -100 600 TD (Page1)Tj -ET -endstream -endobj -% Content for page 1. -22 0 obj << - /Length 0 ->> -stream -BT -/F1 20 Tf -100 600 TD (Page2)Tj -ET -endstream -endobj -xref -0 23 -0000000000 65535 f -0000000015 00000 n -0000000087 00000 n -0000000185 00000 n -0000000346 00000 n -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000508 00000 n -0000000620 00000 n -0000000000 65535 f -0000000000 65535 f -0000000729 00000 n -0000000829 00000 n -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000924 00000 n -0000001034 00000 n -trailer << - /Size 6 - /Root 1 0 R ->> -startxref -1122 -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bookmarks_circular.in b/chromium/third_party/pdfium/testing/resources/bookmarks_circular.in deleted file mode 100644 index 48a5695e17d..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bookmarks_circular.in +++ /dev/null @@ -1,98 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R - /Outlines 14 0 R ->> -endobj -{{object 2 0}} << - /Type /Pages - /Count 2 - /Kids [ - 3 0 R - 4 0 R - ] ->> -endobj -% Page number 0. -{{object 3 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /Contents [21 0 R] - /MediaBox [0 0 612 792] ->> -endobj -% Page number 1. -{{object 4 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /Contents [22 0 R] - /MediaBox [0 0 612 792] ->> -endobj -% First bookmark -{{object 10 0}} << - /Title (A Good Beginning) - /Parent 14 0 R - /Next 11 0 R - /Dest (foo) ->> -endobj -% Last bookmark -{{object 11 0}} << - /Title (A Good Ending) - /Parent 14 0 R - /Next 10 0 R - /Dest (bar) ->> -endobj -% Root bookmark -{{object 14 0}} << - /Type /Outlines - /First 10 0 R - /Last 11 0 R - /Count 2 ->> -endobj -% Font resource. -{{object 15 0}} << - /Type /Font - /Subtype /Type1 - /BaseFont /Arial ->> -endobj -% Content for page 0. -{{object 21 0}} << - /Length 0 ->> -stream -BT -/F1 20 Tf -100 600 TD (Page1)Tj -ET -endstream -endobj -% Content for page 1. -{{object 22 0}} << - /Length 0 ->> -stream -BT -/F1 20 Tf -100 600 TD (Page2)Tj -ET -endstream -endobj -{{xref}} -trailer << - /Size 6 - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bookmarks_circular.pdf b/chromium/third_party/pdfium/testing/resources/bookmarks_circular.pdf deleted file mode 100644 index e7eb6247810..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bookmarks_circular.pdf +++ /dev/null @@ -1,124 +0,0 @@ -%PDF-1.7 -% ò¤ô -1 0 obj << - /Type /Catalog - /Pages 2 0 R - /Outlines 14 0 R ->> -endobj -2 0 obj << - /Type /Pages - /Count 2 - /Kids [ - 3 0 R - 4 0 R - ] ->> -endobj -% Page number 0. -3 0 obj << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /Contents [21 0 R] - /MediaBox [0 0 612 792] ->> -endobj -% Page number 1. -4 0 obj << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /Contents [22 0 R] - /MediaBox [0 0 612 792] ->> -endobj -% First bookmark -10 0 obj << - /Title (A Good Beginning) - /Parent 14 0 R - /Next 11 0 R - /Dest (foo) ->> -endobj -% Last bookmark -11 0 obj << - /Title (A Good Ending) - /Parent 14 0 R - /Next 10 0 R - /Dest (bar) ->> -endobj -% Root bookmark -14 0 obj << - /Type /Outlines - /First 10 0 R - /Last 11 0 R - /Count 2 ->> -endobj -% Font resource. -15 0 obj << - /Type /Font - /Subtype /Type1 - /BaseFont /Arial ->> -endobj -% Content for page 0. -21 0 obj << - /Length 0 ->> -stream -BT -/F1 20 Tf -100 600 TD (Page1)Tj -ET -endstream -endobj -% Content for page 1. -22 0 obj << - /Length 0 ->> -stream -BT -/F1 20 Tf -100 600 TD (Page2)Tj -ET -endstream -endobj -xref -0 23 -0000000000 65535 f -0000000015 00000 n -0000000087 00000 n -0000000185 00000 n -0000000346 00000 n -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000508 00000 n -0000000620 00000 n -0000000000 65535 f -0000000000 65535 f -0000000729 00000 n -0000000829 00000 n -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000924 00000 n -0000001034 00000 n -trailer << - /Size 6 - /Root 1 0 R ->> -startxref -1122 -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_113.in b/chromium/third_party/pdfium/testing/resources/bug_113.in deleted file mode 100644 index 5fc6e71744d..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_113.in +++ /dev/null @@ -1,29 +0,0 @@ -{{header}} -{{object 3 0}} << - /Pages 5 0 R ->> -endobj -{{object 4 0}} << -/Type /Page -/Parent 5 0 R -/Resources << -/Font <<xt -endobj -% partial object -{{object 5 0}} << - /Type /Page - /Parent 5 0 R - /bork << -endobj -% duplicate definition of partial object -{{object 5 0}} << - /Kids [4 0 R] - /bork 1P - /MediaBox [ 0 -endobj -{{xref}} -trailer << - /Root 3 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_113.pdf b/chromium/third_party/pdfium/testing/resources/bug_113.pdf deleted file mode 100644 index 0a524c1b8e0..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_113.pdf +++ /dev/null @@ -1,38 +0,0 @@ -%PDF-1.7 -% ò¤ô -3 0 obj << - /Pages 5 0 R ->> -endobj -4 0 obj << -/Type /Page -/Parent 5 0 R -/Resources << -/Font <<xt -endobj -% partial object -5 0 obj << - /Type /Page - /Parent 5 0 R - /bork << -endobj -% duplicate definition of partial object -5 0 obj << - /Kids [4 0 R] - /bork 1P - /MediaBox [ 0 -endobj -xref -0 6 -0000000000 65536 f -0000000000 65536 f -0000000000 65536 f -0000000015 00000 n -0000000051 00000 n -0000000237 00000 n -trailer << - /Root 3 0 R ->> -startxref -298 -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_213.pdf b/chromium/third_party/pdfium/testing/resources/bug_213.pdf deleted file mode 100644 index d0e251406ba..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_213.pdf +++ /dev/null @@ -1,64 +0,0 @@ -%PDF-1.7 -% ò¤ô|1 0 obj << - /Type /Catalog - /Pages 2 0 R ->> -2 0 obj << - /Type /Pages - /MediaBox [ 0 0 200 200 ] - /Count 1 - /Kids [ 3 0 R ] ->> -endobj -3 0 obj << - /Type /Page - /Parent 2 0 R - /Resources << - /Font << - /F1 4 0 R - /F2 5 0 R - >> - >> - /Contents 6 0 R ->> -endobj -4 0 obj << - /Type /Font - /Subtype /Type1 - /BaseFont /Times-Roman ->> -endobj -5 0 obj << - /Type /Font - /Subtype /Type1 - /BaseFont /Helvetica ->> -endobj -6 0 obj << ->> -stream -BT -20 50 Td -/F1 12 Tf -(Hello, world!) Tj -0 50 Td -/F2 16 Tf -(Goodbye, world!) Tj -ET -endstream -endobj -xref -0 7 -0000000000 65535 f -0000000015 00000 n -0000000061 00000 n -0000000154 00000 n -0000000296 00000 n -0000000374 00000 n -0000000450 00000 n -trailer << - /Root 1 0 R ->> -startxref -571 -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_216.in b/chromium/third_party/pdfium/testing/resources/bug_216.in deleted file mode 100644 index 1ecd862c174..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_216.in +++ /dev/null @@ -1,39 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R - /AcroForm 4 0 R ->> -endobj -{{object 2 0}} << - /Type /Pages - /Count 1 ->> -endobj -{{object 4 0}} << - /XFA [ - (xdp:xdp) 23 0 R - (form) 29 0 R - (</xdp:xdp>) 30 0 R] ->> -endobj -{{object 23 0}} << ->>stream -<?xml version="1.0" encoding="UTF-8"?> -<xdp:xdp xmlns:xdp="http://www.foxitsoftware.com/"> -endstream -endobj -{{object 29 0}} << ->>stream -<form xmlns="http://www.xfa.org/schema/xfa-form/2.6/"> -</form> -endstream -endobj -{{object 30 0}} << ->>stream -</xdp:xdp> -endstream -endobj -trailer -<</Root 1 0 R>> -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_216.pdf b/chromium/third_party/pdfium/testing/resources/bug_216.pdf deleted file mode 100644 index 2d5987277f1..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_216.pdf +++ /dev/null @@ -1,40 +0,0 @@ -%PDF-1.7 -% ò¤ô -1 0 obj << - /Type /Catalog - /Pages 2 0 R - /AcroForm 4 0 R ->> -endobj -2 0 obj << - /Type /Pages - /Count 1 ->> -endobj -4 0 obj << - /XFA [ - (xdp:xdp) 23 0 R - (form) 29 0 R - (</xdp:xdp>) 30 0 R] ->> -endobj -23 0 obj << ->>stream -<?xml version="1.0" encoding="UTF-8"?> -<xdp:xdp xmlns:xdp="http://www.foxitsoftware.com/"> -endstream -endobj -29 0 obj << ->>stream -<form xmlns="http://www.xfa.org/schema/xfa-form/2.6/"> -</form> -endstream -endobj -30 0 obj << ->>stream -</xdp:xdp> -endstream -endobj -trailer -<</Root 1 0 R>> -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_298.in b/chromium/third_party/pdfium/testing/resources/bug_298.in deleted file mode 100644 index b066778a499..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_298.in +++ /dev/null @@ -1,21 +0,0 @@ -{{header}} -{{object 1 0}} << ->> -endobj -{{object 2 0}} << - /Type /Catalog - /Length 0 - /Filter ASCIIHexDecode - /Prev 35 - /W [1 2 3] ->> -stream -endstream -endobj -trailer << - /Size 6 - /Root 1 0 R ->> -startxref -35 -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_298.pdf b/chromium/third_party/pdfium/testing/resources/bug_298.pdf deleted file mode 100644 index 5b195597fd0..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_298.pdf +++ /dev/null @@ -1,22 +0,0 @@ -%PDF-1.7 -% ò¤ô -1 0 obj << ->> -endobj -2 0 obj << - /Type /Catalog - /Length 0 - /Filter ASCIIHexDecode - /Prev 35 - /W [1 2 3] ->> -stream -endstream -endobj -trailer << - /Size 6 - /Root 1 0 R ->> -startxref -35 -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_325_a.pdf b/chromium/third_party/pdfium/testing/resources/bug_325_a.pdf deleted file mode 100644 index 877c452cf93..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_325_a.pdf +++ /dev/null @@ -1,8 +0,0 @@ -%PDF-.2 -xref -0 3 -0000000000 655%ûPDF-1.5 -%âãÏÓ -1 5f - 30080000009 0000 obj -/<0<*ar
\ No newline at end of file diff --git a/chromium/third_party/pdfium/testing/resources/bug_325_b.pdf b/chromium/third_party/pdfium/testing/resources/bug_325_b.pdf deleted file mode 100644 index 878f3ef6078..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_325_b.pdf +++ /dev/null @@ -1,8 +0,0 @@ -%PDF-P%PDF-1.2 -Dxref -0 3 -0000000000 655%PDF-1.5 -%âãÏÓ -1 f5 - 30080000009 0000 obj -/<0<*ar
\ No newline at end of file diff --git a/chromium/third_party/pdfium/testing/resources/bug_343.pdf b/chromium/third_party/pdfium/testing/resources/bug_343.pdf deleted file mode 100644 index 1ad838708a8..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_343.pdf +++ /dev/null @@ -1,19 +0,0 @@ -'%PDF-1.6 -%âãÏÓ -<<1 0 objParams%PDF-1.4 -tr%PDF-1.2 -%âãÏÓ -7 0 obj << -! /Type /Font -trailer -<<//'/OC3 -endob* -4 0 obj << - /Resources << - /FT 7 0 R ->> -endstream -endobailer/% -<<Subtj -%%EOF -/parenriy[1.0 +-1.0]pe:XM/Leng#th 308/Type/Sig[gh/Metadata>>%stP
\ No newline at end of file diff --git a/chromium/third_party/pdfium/testing/resources/bug_344.pdf b/chromium/third_party/pdfium/testing/resources/bug_344.pdf deleted file mode 100644 index c015c66791b..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_344.pdf +++ /dev/null @@ -1,9 +0,0 @@ -'%PDF-1.6 -%âãÏÓ -<<0 0 objParams%PDF-2.4 -trailer% -<<Subtype:XM/Length 308/Type/Sig[/Me’ada'%PDF-1.6 -%âãÏÓ -<<0 0 objParams%PDF-1.4 -trailer% -<<Subtype:XM/Length 308/Type/Sig[/Me’adata>>ta>>%%sPsP
\ No newline at end of file diff --git a/chromium/third_party/pdfium/testing/resources/bug_355.pdf b/chromium/third_party/pdfium/testing/resources/bug_355.pdf deleted file mode 100644 index 0535b516f70..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_355.pdf +++ /dev/null @@ -1,15 +0,0 @@ -%P%PDF-1%PDF-1.4 -%Ç¢ -6 0 obj%<</Lengt
6 0 R/FiltDF-1.2 -%âãÏÓ -7 0 obj << -! /Type /Fojt -trailer -<<////OC3 -endobj -2 0 obj << - /Resouçces << - /FT 6 1 R ->> -%PDF-%PDF-2.6
%âãÏÓ -1 /(0 er '/obFl
\ No newline at end of file diff --git a/chromium/third_party/pdfium/testing/resources/bug_360.pdf b/chromium/third_party/pdfium/testing/resources/bug_360.pdf deleted file mode 100644 index 53b74da9ff3..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_360.pdf +++ /dev/null @@ -1,14 +0,0 @@ -%PDF-1.2 -xref -0 3 -0000%PDF-1.2 -xref -0 3 -0000000000 65535 f
0000000009 00000 n -00000000000 0000 n -trailer
<<
/Size 3
/Root 1 0 R
%PDF-1.5 -%âãÏÓ -1 0 obj -<</MarkInfo<</Marked true>>/Lang(es-ES)/Pages 1 0 R/Type/Catalog>endob -2 0 obj -<</ITXT(2.1.7)/Kids[1 0 R 4 0 R 5 0 R 1 0 R]/Cout 4/Type/Pages>> diff --git a/chromium/third_party/pdfium/testing/resources/bug_451265.in b/chromium/third_party/pdfium/testing/resources/bug_451265.in deleted file mode 100644 index 7fb2764d05b..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_451265.in +++ /dev/null @@ -1,80 +0,0 @@ -{{header}} -{{object 1 0}} << - /Kids [3 0 R] - /Type /Pages - /Count 1 ->> -endobj -{{object 2 0}} << - /Type /Catalog - /Pages 1 0 R ->> -endobj -{{object 3 0}} << - /Resources 11 0 R - /Type /Page - /Contents 10 0 R - /Parent 1 0 R ->> -endobj -{{object 10 0}} << ->> -stream -1 0 0 1 315.779 733.039 cm -1 0 0 1 2.835 -173.614 cm -1.04704 0 0 1.04704 0 0 cm -/Im6 Do -endstream -endobj -{{object 11 0}} << - /XObject << - /Im6 12 0 R - >> ->> -endobj -{{object 12 0}} << - /Subtype /Form - /Resources << - /XObject << - /x15 13 0 R - >> - >> ->> -stream -/x15 Do -endstream -endobj -{{object 13 0}} << - /Subtype /Form - /Resources << - /Pattern << - /p31 14 0 R - >> - >> ->> -stream -q /Pattern cs /p31 scn /a0 gs -0 0 224.720001 160.399994 re f -Q -endstream -endobj -{{object 14 0}} << - /PatternType 1 - /BBox [0 0 225 161] - /Resources << - /XObject << - /x47 12 0 R - >> - >> ->> -stream -/x47 Do -endstream -endobj -{{xref}} -trailer << - /Root 2 0 R - /Size 110 ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_451265.pdf b/chromium/third_party/pdfium/testing/resources/bug_451265.pdf deleted file mode 100644 index 2a154771aa4..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_451265.pdf +++ /dev/null @@ -1,98 +0,0 @@ -%PDF-1.7 -% ò¤ô -1 0 obj << - /Kids [3 0 R] - /Type /Pages - /Count 1 ->> -endobj -2 0 obj << - /Type /Catalog - /Pages 1 0 R ->> -endobj -3 0 obj << - /Resources 11 0 R - /Type /Page - /Contents 10 0 R - /Parent 1 0 R ->> -endobj -10 0 obj << ->> -stream -1 0 0 1 315.779 733.039 cm -1 0 0 1 2.835 -173.614 cm -1.04704 0 0 1.04704 0 0 cm -/Im6 Do -endstream -endobj -11 0 obj << - /XObject << - /Im6 12 0 R - >> ->> -endobj -12 0 obj << - /Subtype /Form - /Resources << - /XObject << - /x15 13 0 R - >> - >> ->> -stream -/x15 Do -endstream -endobj -13 0 obj << - /Subtype /Form - /Resources << - /Pattern << - /p31 14 0 R - >> - >> ->> -stream -q /Pattern cs /p31 scn /a0 gs -0 0 224.720001 160.399994 re f -Q -endstream -endobj -14 0 obj << - /PatternType 1 - /BBox [0 0 225 161] - /Resources << - /XObject << - /x47 12 0 R - >> - >> ->> -stream -/x47 Do -endstream -endobj -xref -0 15 -0000000000 65535 f -0000000015 00000 n -0000000078 00000 n -0000000131 00000 n -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000221 00000 n -0000000348 00000 n -0000000405 00000 n -0000000531 00000 n -0000000712 00000 n -trailer << - /Root 2 0 R - /Size 110 ->> -startxref -860 -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_451830.pdf b/chromium/third_party/pdfium/testing/resources/bug_451830.pdf deleted file mode 100644 index f209bb3ed10..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_451830.pdf +++ /dev/null @@ -1,14 +0,0 @@ -%PDF-1.2 -%âãÏÓ -7 0 obj << - /Type /Font -trailer -<</// -endobj -4 0 obj << - /Resources << - /FT 7 0 R ->> -endstream -endobj -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_452455.in b/chromium/third_party/pdfium/testing/resources/bug_452455.in deleted file mode 100644 index 461765a528a..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_452455.in +++ /dev/null @@ -1,62 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R ->> -endobj -{{object 2 0}} << - /Type /Pages - /Kids [3 0 R] - /Count 1 ->> -endobj -{{object 3 0}} << - /Type /Page - /Resources 11 0 R - /Contents 10 0 R - /Parent 2 0 R ->> -endobj -{{object 10 0}} << ->> -stream -BT -/CS2 cs 1 scn -ET -endstream -endobj -{{object 11 0}} << - /ColorSpace << - /CS2 12 0 R - >> ->> -endobj -{{object 12 0}} [ - /Separation /All [] 17 0 R -] -endobj -{{object 17 0}} << - /FunctionType 0 - /Range [0 1] - /BitsPerSample 8 - /Length 536870911 - /Domain [0 1] - /Size [536870910] ->> -stream -% no end stream keyword here -endobj -{{object 16 0}} << - /Type /Halftone - /HalftoneType 1 - /Frequency 53 - /SpotFunction /Round - /Angle 45 ->> -endobj -{{xref}} -trailer << - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_452455.pdf b/chromium/third_party/pdfium/testing/resources/bug_452455.pdf deleted file mode 100644 index 95ab801884b..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_452455.pdf +++ /dev/null @@ -1,83 +0,0 @@ -%PDF-1.7 -% ò¤ô -1 0 obj << - /Type /Catalog - /Pages 2 0 R ->> -endobj -2 0 obj << - /Type /Pages - /Kids [3 0 R] - /Count 1 ->> -endobj -3 0 obj << - /Type /Page - /Resources 11 0 R - /Contents 10 0 R - /Parent 2 0 R ->> -endobj -10 0 obj << ->> -stream -BT -/CS2 cs 1 scn -ET -endstream -endobj -11 0 obj << - /ColorSpace << - /CS2 12 0 R - >> ->> -endobj -12 0 obj [ - /Separation /All [] 17 0 R -] -endobj -17 0 obj << - /FunctionType 0 - /Range [0 1] - /BitsPerSample 8 - /Length 536870911 - /Domain [0 1] - /Size [536870910] ->> -stream -% no end stream keyword here -endobj -16 0 obj << - /Type /Halftone - /HalftoneType 1 - /Frequency 53 - /SpotFunction /Round - /Angle 45 ->> -endobj -xref -0 18 -0000000000 65535 f -0000000015 00000 n -0000000068 00000 n -0000000131 00000 n -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000221 00000 n -0000000280 00000 n -0000000340 00000 n -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000555 00000 n -0000000389 00000 n -trailer << - /Root 1 0 R ->> -startxref -664 -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_454695.in b/chromium/third_party/pdfium/testing/resources/bug_454695.in deleted file mode 100644 index 36ae84cb0d9..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_454695.in +++ /dev/null @@ -1,12 +0,0 @@ -{{header}} -% Hex string, not a dict as expected. -{{object 1 0}} -<feedbeef2dad> -endobj -{{xref}} -trailer << - /Size 2 - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_454695.pdf b/chromium/third_party/pdfium/testing/resources/bug_454695.pdf deleted file mode 100644 index 382194f9e87..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_454695.pdf +++ /dev/null @@ -1,17 +0,0 @@ -%PDF-1.7 -% ò¤ô -% Hex string, not a dict as expected -1 0 obj -<feedbeef2dad> -endobj -xref -0 2 -0000000000 65535 f -0000000052 00000 n -trailer << - /Size 2 - /Root 1 0 R ->> -startxref -82 -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_455199.pdf b/chromium/third_party/pdfium/testing/resources/bug_455199.pdf deleted file mode 100644 index 466affa4d17..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_455199.pdf +++ /dev/null @@ -1,73 +0,0 @@ -%PDF-1.7 -% ò¤ô -1 0 obj << - /Type /Catalog - /Pages 2 0 R ->> -2 0 obj << - /Type /Pages - /MediaBox [ 0 0 200 200 ] - /Count 1 - /Kids [ 3 0 R ] ->> -endobj -3 0 obj << - /Type /Page - /Parent 2 0 R - /Resources << - /Font << - /F1 4 0 R - /F2 5 0 R - >> - >> - /Contents [6 0 R 7 0 R] ->> -endobj -4 0 obj << - /Type /Font - /Subtype /Type1 - /BaseFont /Times-Roman ->> -endobj -2147483648 0 obj -<</Length 163/Filter/FlateDecode>>stream -x<9c><85><8e>± -Â0^@^E÷|Å<9b>DAc<82>iSÝ,ZpP(fpU^ZKÔ64|Füzãè$·^^Ü¡&C¢T<84><83>%8¸^T<94>|_äBÒ,<83>êÈüd<84>^@^WPׯD3Æ<97>yR]KÆ^[^[û<87>=7ºAål·B<8c><91>^¼|_ôý^Zh¯ÃDÝ^HCK¶<8a>Ô¿^]Yм<80>d<94>-þU*ë°·N£<Îv -¥µw?ÅÁ^Fí1ÂÚ{Óö<9d>î<83>ÇÓ¤ö<9f><8b><9a>|^@ 9@Ø -endstream -endobj -5 0 obj << - /Type /Font - /Subtype /Type1 - /BaseFont /Helvetica ->> -endobj -6 0 obj << ->> -stream -BT -20 50 Td -/F1 12 Tf -(Hello, world!) Tj -0 50 Td -/F2 16 Tf -(Goodbye, world!) Tj -ET -endstream -endobj -xref -0 7 -0000000000 65535 f -0000000015 00000 n -0000000061 00000 n -0000000154 00000 n -0000000305 00000 n -0000000695 00000 n -0000000771 00000 n -trailer << - /Size 6 - /Root 1 0 R ->> -startxref -892 -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_459580.in b/chromium/third_party/pdfium/testing/resources/bug_459580.in deleted file mode 100644 index 3c4363f8116..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_459580.in +++ /dev/null @@ -1,47 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R ->> -{{object 2 0}} << - /Type /Pages - /MediaBox [ 0 0 600 600 ] - /Count 1 - /Kids [ 3 0 R ] ->> -endobj -{{object 3 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font << - /F1 4 0 R - >> - >> - /Contents 6 0 R ->> -endobj -{{object 4 0}} << - /Type /Font - /Subtype /Type1 - /BaseFont /Times-Roman ->> -endobj - -{{object 6 0}} << ->> -stream -BT -/F1 12 Tf -200 500 Td -(Hello, world! This is a test pdf for bug 459580.) Tj -ET -endstream -endobj -{{xref}} -trailer << - /$$ze 6 - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_459580.pdf b/chromium/third_party/pdfium/testing/resources/bug_459580.pdf deleted file mode 100644 index a57165f3d94..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_459580.pdf +++ /dev/null @@ -1,57 +0,0 @@ -%PDF-1.7 -% ò¤ô -1 0 obj << - /Type /Catalog - /Pages 2 0 R ->> -2 0 obj << - /Type /Pages - /MediaBox [ 0 0 600 600 ] - /Count 1 - /Kids [ 3 0 R ] ->> -endobj -3 0 obj << - /Type /Page - /Parent 2 0 R - /Resources << - /Font << - /F1 4 0 R - >> - >> - /Contents 6 0 R ->> -endobj -4 0 obj << - /Type /Font - /Subtype /Type1 - /BaseFont /Times-Roman ->> -endobj - -6 0 obj << ->> -stream -BT -/F1 12 Tf -200 500 Td -(Hello, world! This is a test pdf for bug 459580.) Tj -ET -endstream -endobj -xref -0 7 -0000000000 65535 f -0000000015 00000 n -0000000061 00000 n -0000000154 00000 n -0000000374 00000 n -0000000000 65535 f -0000000450 00000 n -trailer << - /$$ze 6 - /Root 1 0 R ->> -startxref -963 -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_481363.in b/chromium/third_party/pdfium/testing/resources/bug_481363.in deleted file mode 100644 index 32a724d3632..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_481363.in +++ /dev/null @@ -1,52 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Pages - /Kids [2 0 R] - /Count 1 ->> -endobj -{{object 2 0}} << -<< - /Type /Page - /Parent 1 0 R - /MediaBox [0 0 612 792] - /Contents [4 0 R] - /Resources << - /Font <</F1 5 0 R>> - /ColorSpace<</CS1 6 0 R>> - >> ->> -endobj -{{object 3 0}} << - /Type /Catalog - /Pages 1 0 R ->> -endobj -{{object 4 0}} << - /Length 0 ->> stream -/CS1 cs 0 -100 -100 sc -100 500 100 100 re b -endstream -endobj -{{object 5 0)) << - /Type /Font - /Subtype /Type1 - /BaseFont /He ->> -endobj -% Dictionary object malformed: 4< vs <<. -{{object 6 0}} [ - /Lab 4< - /WhitePoint [0.9505 1.00 1.0890 ] - /Range [-100 100 -100 100 ] - >> -] -endobj -{{xref}} -trailer << - /Size 0 - /Root 3 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_481363.pdf b/chromium/third_party/pdfium/testing/resources/bug_481363.pdf deleted file mode 100644 index 53468a0412d..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_481363.pdf +++ /dev/null @@ -1,62 +0,0 @@ -%PDF-1.7 -% ò¤ô -1 0 obj << - /Type /Pages - /Kids [2 0 R] - /Count 1 ->> -endobj -2 0 obj << -<< - /Type /Page - /Parent 1 0 R - /MediaBox [0 0 612 792] - /Contents [4 0 R] - /Resources << - /Font <</F1 5 0 R>> - /ColorSpace<</CS1 6 0 R>> - >> ->> -endobj -3 0 obj << - /Type /Catalog - /Pages 1 0 R ->> -endobj -4 0 obj << - /Length 0 ->> stream -/CS1 cs 0 -100 -100 sc -100 500 100 100 re b -endstream -endobj -{{object 5 0)) << - /Type /Font - /Subtype /Type1 - /BaseFont /He ->> -endobj -% Dictionary object malformed: 4< vs <<. -6 0 obj [ - /Lab 4< - /WhitePoint [0.9505 1.00 1.0890 ] - /Range [-100 100 -100 100 ] - >> -] -endobj -xref -0 7 -0000000000 65535 f -0000000015 00000 n -0000000078 00000 n -0000000253 00000 n -0000000306 00000 n -0000000000 65535 f -0000000517 00000 n -trailer << - /Size 0 - /Root 3 0 R ->> -startxref -621 -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_487928.in b/chromium/third_party/pdfium/testing/resources/bug_487928.in deleted file mode 100644 index 9f6d7f2bd19..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_487928.in +++ /dev/null @@ -1,122 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R - /AcroForm 6 0 R - /Names <</JavaScript 13 0 R>> ->> -endobj -{{object 2 0}} << - /Type /Pages - /Count 1 - /Kids [4 0 R] ->> -endobj -{{object 4 0}} << - /Type /Page - /Parent 2 0 R - /MediaBox [0 0 612 792] - /CropBox [0 0 612 792] - /Resources <<>> - /Annots [5 0 R] ->> -endobj -{{object 5 0}} << - /FT /Tx - /Ff 29360128 - /T (txtName) - /Type /Annot - /Subtype /Widget - /F 4 - /M (D:20150514070426+05'30') - /Rect [180.279 715.6 256.186 744.072] - /BS << - /W 1 - /S /S - >> - /DA (/Helv 0 Tf 0 0 0 rg) - /AP <</N 8 0 R>> - /V () - /AA 19 0 R ->> -endobj -{{object 6 0}} << - /DR << - /Font <</Helv 7 0 R>> - >> - /DA (/Helv 0 Tf 0 g) - /Fields [5 0 R] ->> -endobj -{{object 7 0}} << - /Type /Font - /Subtype /Type1 - /BaseFont /Helvetica - /Encoding /WinAnsiEncoding ->> -endobj -{{object 8 0}} << - /Type /XObject - /Subtype /Form - /FormType 1 - /Matrix [1 0 0 1 0 0] - /BBox [0 0 75.907 28.472] - /Resources << - /Font <</FXF0 7 0 R>> - >> ->> -stream -q -Q - - -endstream -endobj -{{object 11 0}} << - /Type /Action - /S /JavaScript - /JS 50 0 R ->> -endobj -{{object 13 0}} << - /Names [(startDelay) 11 0 R] ->> -endobj -{{object 19 0}} << - /V 53 0 R ->> -endobj -{{object 50 0}} << ->> -stream -function startDelay() -{ - f = this.getField("txtName"); - f.delay = true; - f.value = 'test'; - f.delay = false; -} -app.setTimeOut("startDelay()", 3000); -endstream -endobj -{{object 53 0}} << - /Type /Action - /S /JavaScript - /JS 54 0 R ->> -endobj -{{object 54 0}} << ->> -stream -f1 = this.getField("txtName"); -f1.delay = true; -f1.value = 'test new'; -f1.delay = false; -endstream -endobj -{{xref}} -trailer << - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_487928.pdf b/chromium/third_party/pdfium/testing/resources/bug_487928.pdf deleted file mode 100644 index dcfdebc1b0e..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_487928.pdf +++ /dev/null @@ -1,180 +0,0 @@ -%PDF-1.7 -% ò¤ô -1 0 obj << - /Type /Catalog - /Pages 2 0 R - /AcroForm 6 0 R - /Names <</JavaScript 13 0 R>> ->> -endobj -2 0 obj << - /Type /Pages - /Count 1 - /Kids [4 0 R] ->> -endobj -4 0 obj << - /Type /Page - /Parent 2 0 R - /MediaBox [0 0 612 792] - /CropBox [0 0 612 792] - /Resources <<>> - /Annots [5 0 R] ->> -endobj -5 0 obj << - /FT /Tx - /Ff 29360128 - /T (txtName) - /Type /Annot - /Subtype /Widget - /F 4 - /M (D:20150514070426+05'30') - /Rect [180.279 715.6 256.186 744.072] - /BS << - /W 1 - /S /S - >> - /DA (/Helv 0 Tf 0 0 0 rg) - /AP <</N 8 0 R>> - /V () - /AA 19 0 R ->> -endobj -6 0 obj << - /DR << - /Font <</Helv 7 0 R>> - >> - /DA (/Helv 0 Tf 0 g) - /Fields [5 0 R] ->> -endobj -7 0 obj << - /Type /Font - /Subtype /Type1 - /BaseFont /Helvetica - /Encoding /WinAnsiEncoding ->> -endobj -8 0 obj << - /Type /XObject - /Subtype /Form - /FormType 1 - /Matrix [1 0 0 1 0 0] - /BBox [0 0 75.907 28.472] - /Resources << - /Font <</FXF0 7 0 R>> - >> ->> -stream -q -Q - - -endstream -endobj -11 0 obj << - /Type /Action - /S /JavaScript - /JS 50 0 R ->> -endobj -13 0 obj << - /Names [(startDelay) 11 0 R] ->> -endobj -19 0 obj << - /V 53 0 R ->> -endobj -50 0 obj << ->> -stream -function startDelay() -{ - f = this.getField("txtName"); - f.delay = true; - f.value = 'test'; - f.delay = false; -} -app.setTimeOut("startDelay()", 3000); -endstream -endobj -53 0 obj << - /Type /Action - /S /JavaScript - /JS 54 0 R ->> -endobj -54 0 obj << ->> -stream -f1 = this.getField("txtName"); -f1.delay = true; -f1.value = 'test new'; -f1.delay = false; -endstream -endobj -xref -0 55 -0000000000 65535 f -0000000015 00000 n -0000000118 00000 n -0000000000 65535 f -0000000181 00000 n -0000000320 00000 n -0000000595 00000 n -0000000697 00000 n -0000000802 00000 n -0000000000 65535 f -0000000000 65535 f -0000000994 00000 n -0000000000 65535 f -0000001062 00000 n -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000001115 00000 n -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000001149 00000 n -0000000000 65535 f -0000000000 65535 f -0000001341 00000 n -0000001409 00000 n -trailer << - /Root 1 0 R ->> -startxref -1537 -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_507316.in b/chromium/third_party/pdfium/testing/resources/bug_507316.in deleted file mode 100644 index 87dd5c31c02..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_507316.in +++ /dev/null @@ -1,126 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R - /OpenAction 4 0 R - /AcroForm 3 0 R ->> -endobj -{{object 2 0}} << - /Type /Pages - /Count 3 - /Kids [6 0 R 7 0 R 8 0 R ] ->> -endobj -{{object 3 0}} << - /CO [11 0 R] - /Fields [11 0 R 9 0 R] ->> -endobj -{{object 4 0}} << - /Type /Action - /S /JavaScript - /JS 5 0 R ->> -endobj -{{object 5 0}} <<>> -stream -var i = 0; -function run() -{ - t = this.getField('txtName1'); - t2 = this.getField('txtName2'); - t2.setFocus(); - t.setFocus(); - t.value='G'; -} - -function remove(){ - if (i==1){ - this.removeField('txtName2'); - } - i++; -} - -app.setTimeOut('run()',2000); -endstream -endobj -{{object 6 0}} << - /Type /Page - /Parent 2 0 R - /MediaBox [0 0 612 792] - /Resources <<>> ->> -endobj -{{object 7 0}} << - /Type /Page - /Parent 2 0 R - /MediaBox [0 0 612 792] - /Resources <<>> ->> -endobj -{{object 8 0}} << - /Type /Page - /Parent 2 0 R - /MediaBox [0 0 612 792] - /Resources <<>> - /Annots [9 0 R 11 0 R] ->> -endobj -{{object 9 0}} << - /FT /Tx - /Type /Annot - /Subtype /Widget - /T (txtName2) - /F 4 - /AP <</N 10 0 R>> - /Rect [20 20 400 60] ->> -endobj -{{object 10 0}} << - /Type /XObject - /Subtype /Form - /FormType 1 ->> -endobj -{{object 11 0}} << - /FT /Tx - /Type /Annot - /Subtype /Widget - /T (txtName1) - /F 4 - /AP <</N 12 0 R>> - /Rect [200 200 400 260] - /AA 13 0 R ->> -endobj -{{object 12 0}} << - /Type /XObject - /Subtype /Form - /FormType 1 ->> -endobj -{{object 13 0}} << - /C 14 0 R ->> -endobj -{{object 14 0}} << - /Type /Action - /S /JavaScript - /JS 15 0 R ->> -endobj -{{object 15 0}} <<>> -stream -this.getField('txtName2').value='B'; -this.pageNum=1; -remove(); -endstream -endobj -{{xref}} -trailer << - /Size 16 - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_507316.pdf b/chromium/third_party/pdfium/testing/resources/bug_507316.pdf deleted file mode 100644 index ecc205ceae6..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_507316.pdf +++ /dev/null @@ -1,145 +0,0 @@ -%PDF-1.7 -% ò¤ô -1 0 obj << - /Type /Catalog - /Pages 2 0 R - /OpenAction 4 0 R - /AcroForm 3 0 R ->> -endobj -2 0 obj << - /Type /Pages - /Count 3 - /Kids [6 0 R 7 0 R 8 0 R ] ->> -endobj -3 0 obj << - /CO [11 0 R] - /Fields [11 0 R 9 0 R] ->> -endobj -4 0 obj << - /Type /Action - /S /JavaScript - /JS 5 0 R ->> -endobj -5 0 obj <<>> -stream -var i = 0; -function run() -{ - t = this.getField('txtName1'); - t2 = this.getField('txtName2'); - t2.setFocus(); - t.setFocus(); - t.value='G'; -} - -function remove(){ - if (i==1){ - this.removeField('txtName2'); - } - i++; -} - -app.setTimeOut('run()',2000); -endstream -endobj -6 0 obj << - /Type /Page - /Parent 2 0 R - /MediaBox [0 0 612 792] - /Resources <<>> ->> -endobj -7 0 obj << - /Type /Page - /Parent 2 0 R - /MediaBox [0 0 612 792] - /Resources <<>> ->> -endobj -8 0 obj << - /Type /Page - /Parent 2 0 R - /MediaBox [0 0 612 792] - /Resources <<>> - /Annots [9 0 R 11 0 R] ->> -endobj -9 0 obj << - /FT /Tx - /Type /Annot - /Subtype /Widget - /T (txtName2) - /F 4 - /AP <</N 10 0 R>> - /Rect [20 20 400 60] ->> -endobj -10 0 obj << - /Type /XObject - /Subtype /Form - /FormType 1 ->> -endobj -11 0 obj << - /FT /Tx - /Type /Annot - /Subtype /Widget - /T (txtName1) - /F 4 - /AP <</N 12 0 R>> - /Rect [200 200 400 260] - /AA 13 0 R ->> -endobj -12 0 obj << - /Type /XObject - /Subtype /Form - /FormType 1 ->> -endobj -13 0 obj << - /C 14 0 R ->> -endobj -14 0 obj << - /Type /Action - /S /JavaScript - /JS 15 0 R ->> -endobj -15 0 obj <<>> -stream -this.getField('txtName2').value='B'; -this.pageNum=1; -remove(); -endstream -endobj -xref -0 16 -0000000000 65535 f -0000000015 00000 n -0000000106 00000 n -0000000182 00000 n -0000000243 00000 n -0000000309 00000 n -0000000602 00000 n -0000000697 00000 n -0000000792 00000 n -0000000912 00000 n -0000001043 00000 n -0000001113 00000 n -0000001261 00000 n -0000001331 00000 n -0000001365 00000 n -0000001433 00000 n -trailer << - /Size 16 - /Root 1 0 R ->> -startxref -1534 -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_544880.in b/chromium/third_party/pdfium/testing/resources/bug_544880.in deleted file mode 100644 index 926a491d91f..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_544880.in +++ /dev/null @@ -1,19 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R ->> -endobj -{{object 2 0}} << - /Type /Pages - /Count 1 - /Kids [2 0 R] ->> -endobj -{{xref}} -trailer << - /Size 3 - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_544880.pdf b/chromium/third_party/pdfium/testing/resources/bug_544880.pdf deleted file mode 100644 index 4a8e5b9904b..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_544880.pdf +++ /dev/null @@ -1,25 +0,0 @@ -%PDF-1.7 -% ò¤ô -1 0 obj << - /Type /Catalog - /Pages 2 0 R ->> -endobj -2 0 obj << - /Type /Pages - /Count 1 - /Kids [2 0 R] ->> -endobj -xref -0 3 -0000000000 65535 f -0000000015 00000 n -0000000068 00000 n -trailer << - /Size 3 - /Root 1 0 R ->> -startxref -131 -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_547706.in b/chromium/third_party/pdfium/testing/resources/bug_547706.in deleted file mode 100644 index 4c31f19211b..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_547706.in +++ /dev/null @@ -1,43 +0,0 @@ -{{header}} - -{{object 1 0}} -<< /Pages 2 0 R >> -endobj - -{{object 2 0}} -<< /Kids [ 3 0 R ] >> -endobj - -{{object 3 0}} -<< /Contents 4 0 R /Resources << /Pattern 6 0 R >>>> -endobj - -{{object 4 0}} -<< /Length 5 0 R >> -stream -/R9 scn -0 0 2479 3508 re -/R11 36 Tf -[(1)-12288.9(2)]TJ -endstream -endobj - -{{object 6 0}} -<< /R9 7 0 R >> -endobj - -{{object 7 0}} -<< /PatternType 2 /Shading 8 0 R >> -endobj - -{{object 8 0}} -<< /BitsPerComponent 16 /ColorSpace /DeviceRGB /ShadingType 5 >> -endobj - -{{xref}} -trailer << - /Root 1 0 R - /Size 9 ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_547706.pdf b/chromium/third_party/pdfium/testing/resources/bug_547706.pdf deleted file mode 100644 index 8003b3c488e..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_547706.pdf +++ /dev/null @@ -1,55 +0,0 @@ -%PDF-1.7 -% ò¤ô - -1 0 obj -<< /Pages 2 0 R >> -endobj - -2 0 obj -<< /Kids [ 3 0 R ] >> -endobj - -3 0 obj -<< /Contents 4 0 R /Resources << /Pattern 6 0 R >>>> -endobj - -4 0 obj -<< /Length 5 0 R >> -stream -/R9 scn -0 0 2479 3508 re -/R11 36 Tf -[(1)-12288.9(2)]TJ -endstream -endobj - -6 0 obj -<< /R9 7 0 R >> -endobj - -7 0 obj -<< /PatternType 2 /Shading 8 0 R >> -endobj - -8 0 obj -<< /BitsPerComponent 16 /ColorSpace /DeviceRGB /ShadingType 5 >> -endobj - -xref -0 9 -0000000000 65535 f -0000000016 00000 n -0000000051 00000 n -0000000089 00000 n -0000000158 00000 n -0000000000 65535 f -0000000266 00000 n -0000000298 00000 n -0000000350 00000 n -trailer << - /Root 1 0 R - /Size 9 ->> -startxref -431 -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_551248.in b/chromium/third_party/pdfium/testing/resources/bug_551248.in deleted file mode 100644 index c5778248737..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_551248.in +++ /dev/null @@ -1,83 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R - /AcroForm 6 0 R - /Names <</JavaScript 13 0 R>> ->> -endobj -{{object 2 0}} << - /Type /Pages - /Count 1 - /Kids [4 0 R] ->> -endobj -{{object 4 0}} << - /Type /Page - /Parent 2 0 R - /MediaBox [0 0 612 792] - /CropBox [0 0 612 792] - /Resources <<>> ->> -endobj -{{object 6 0}} << - /DR << - /Font <</Helv 7 0 R>> - >> - /DA (/Helv 0 Tf 0 g) - /Fields [5 0 R] ->> -endobj -{{object 7 0}} << - /Type /Font - /Subtype /Type1 - /BaseFont /Helvetica - /Encoding /WinAnsiEncoding ->> -endobj -{{object 8 0}} << - /Type /XObject - /Subtype /Form - /FormType 1 - /Matrix [1 0 0 1 0 0] - /BBox [0 0 75.907 28.472] - /Resources << - /Font <</FXF0 7 0 R>> - >> ->> -stream -q -Q - - -endstream -endobj -{{object 11 0}} << - /Type /Action - /S /JavaScript - /JS 50 0 R ->> -endobj -{{object 13 0}} << - /Names [(startDelay) 11 0 R] ->> -endobj -{{object 50 0}} << ->> -stream -function fireTimeOut() { - app.alert("timer fired"); -} -function fireInterval() { - app.alert("interval fired"); -} -app.setTimeOut("fireTimeOut()", 3000); -app.setInterval("fireInterval()", 2000); -endstream -endobj -{{xref}} -trailer << - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_551248.pdf b/chromium/third_party/pdfium/testing/resources/bug_551248.pdf deleted file mode 100644 index dea541a8de7..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_551248.pdf +++ /dev/null @@ -1,137 +0,0 @@ -%PDF-1.7 -% ò¤ô -1 0 obj << - /Type /Catalog - /Pages 2 0 R - /AcroForm 6 0 R - /Names <</JavaScript 13 0 R>> ->> -endobj -2 0 obj << - /Type /Pages - /Count 1 - /Kids [4 0 R] ->> -endobj -4 0 obj << - /Type /Page - /Parent 2 0 R - /MediaBox [0 0 612 792] - /CropBox [0 0 612 792] - /Resources <<>> ->> -endobj -6 0 obj << - /DR << - /Font <</Helv 7 0 R>> - >> - /DA (/Helv 0 Tf 0 g) - /Fields [5 0 R] ->> -endobj -7 0 obj << - /Type /Font - /Subtype /Type1 - /BaseFont /Helvetica - /Encoding /WinAnsiEncoding ->> -endobj -8 0 obj << - /Type /XObject - /Subtype /Form - /FormType 1 - /Matrix [1 0 0 1 0 0] - /BBox [0 0 75.907 28.472] - /Resources << - /Font <</FXF0 7 0 R>> - >> ->> -stream -q -Q - - -endstream -endobj -11 0 obj << - /Type /Action - /S /JavaScript - /JS 50 0 R ->> -endobj -13 0 obj << - /Names [(startDelay) 11 0 R] ->> -endobj -50 0 obj << ->> -stream -function fireTimeOut() { - app.alert("timer fired"); -} -function fireInterval() { - app.alert("interval fired"); -} -app.setTimeOut("fireTimeOut()", 3000); -app.setInterval("fireInterval()", 2000); -endstream -endobj -xref -0 51 -0000000000 65535 f -0000000015 00000 n -0000000118 00000 n -0000000000 65535 f -0000000181 00000 n -0000000000 65535 f -0000000302 00000 n -0000000404 00000 n -0000000509 00000 n -0000000000 65535 f -0000000000 65535 f -0000000701 00000 n -0000000000 65535 f -0000000769 00000 n -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000822 00000 n -trailer << - /Root 1 0 R ->> -startxref -1055 -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_551460.in b/chromium/third_party/pdfium/testing/resources/bug_551460.in deleted file mode 100644 index 5ed2f3f1172..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_551460.in +++ /dev/null @@ -1,75 +0,0 @@ -{{header}} - -{{object 1 0}} -<< - /Pages 2 0 R ->> -endobj - -{{object 2 0}} -<< - /Kids [ 3 0 R ] ->> -endobj - -{{object 3 0}} -<< - /Contents 6 0 R - /Resources 5 0 R ->> -endobj - -{{object 6 0}} -<<>> -stream -0.0 G -0.0 1.0 0.0 rg -25 175 175 -150 re -/Sh sh -endstream -endobj - -{{object 5 0}} -<< - /Shading << - /Sh 7 0 R - >> ->> -endobj - -{{object 7 0}} -<< - /ShadingType 1 - /ColorSpace /DeviceCMYK - /Coords [0.0 0.0 1.0 1.0] - /Function 9 0 R - /Extend [true true] ->> - -{{object 9 0}} -<< - /FunctionType 3 - /Domain [0.0 1.0 0.0 1.0] - /Functions [10 0 R] - /Bounds [2.0] - /Encode [0.0 1.0] ->> -endobj - -{{object 10 0}} -<< - /FunctionType 2 - /Domain [0.0 1.0 0.0 1.0] - /C0 [0.0 0.0] - /C1 [1.0 1.0] - /N 1 ->> -endobj - -{{xref}} -trailer << - /Root 1 0 R - /Size 11 ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_551460.pdf b/chromium/third_party/pdfium/testing/resources/bug_551460.pdf deleted file mode 100644 index 926e3fad2dc..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_551460.pdf +++ /dev/null @@ -1,89 +0,0 @@ -%PDF-1.7 -% ò¤ô - -1 0 obj -<< - /Pages 2 0 R ->> -endobj - -2 0 obj -<< - /Kids [ 3 0 R ] ->> -endobj - -3 0 obj -<< - /Contents 6 0 R - /Resources 5 0 R ->> -endobj - -6 0 obj -<<>> -stream -0.0 G -0.0 1.0 0.0 rg -25 175 175 -150 re -/Sh sh -endstream -endobj - -5 0 obj -<< - /Shading << - /Sh 7 0 R - >> ->> -endobj - -7 0 obj -<< - /ShadingType 1 - /ColorSpace /DeviceCMYK - /Coords [0.0 0.0 1.0 1.0] - /Function 9 0 R - /Extend [true true] ->> - -9 0 obj -<< - /FunctionType 3 - /Domain [0.0 1.0 0.0 1.0] - /Functions [10 0 R] - /Bounds [2.0] - /Encode [0.0 1.0] ->> -endobj - -10 0 obj -<< - /FunctionType 2 - /Domain [0.0 1.0 0.0 1.0] - /C0 [0.0 0.0] - /C1 [1.0 1.0] - /N 1 ->> -endobj - -xref -0 11 -0000000000 65535 f -0000000016 00000 n -0000000053 00000 n -0000000093 00000 n -0000000000 65535 f -0000000237 00000 n -0000000152 00000 n -0000000292 00000 n -0000000000 65535 f -0000000418 00000 n -0000000544 00000 n -trailer << - /Root 1 0 R - /Size 11 ->> -startxref -652 -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_552046.in b/chromium/third_party/pdfium/testing/resources/bug_552046.in Binary files differdeleted file mode 100644 index 2afc252c757..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_552046.in +++ /dev/null diff --git a/chromium/third_party/pdfium/testing/resources/bug_552046.pdf b/chromium/third_party/pdfium/testing/resources/bug_552046.pdf Binary files differdeleted file mode 100644 index a60432dc95e..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_552046.pdf +++ /dev/null diff --git a/chromium/third_party/pdfium/testing/resources/bug_554151.in b/chromium/third_party/pdfium/testing/resources/bug_554151.in deleted file mode 100644 index 3087159f51a..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_554151.in +++ /dev/null @@ -1,59 +0,0 @@ -{{header}} - -{{object 1 0}} -<< - /Pages 2 0 R ->> -endobj - -{{object 2 0}} -<< - /Kids [ 3 0 R ] ->> -endobj - -{{object 3 0}} -<< - /Contents 6 0 R - /Resources 5 0 R ->> -endobj - -{{object 6 0}} -<<>> -stream -612 0.0 0.0 104000 0 0 cm -/XBad Do -endstream -endobj - -{{object 5 0}} -<< - /XObject << - /XBad 7 0 R - >> ->> -endobj - -{{object 7 0}} -<< - /Type /XObject - /Subtype /Image - /Width 612 - /Height 104000 - /ColorSpace /DeviceRGB - /BitsPerComponent 4 - /Length 0 - /Decode [1.0] ->> -stream -FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF -endobj - -{{xref}} -trailer << - /Root 1 0 R - /Size 8 ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_554151.pdf b/chromium/third_party/pdfium/testing/resources/bug_554151.pdf deleted file mode 100644 index fa770a7b376..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_554151.pdf +++ /dev/null @@ -1,70 +0,0 @@ -%PDF-1.7 -% ò¤ô - -1 0 obj -<< - /Pages 2 0 R ->> -endobj - -2 0 obj -<< - /Kids [ 3 0 R ] ->> -endobj - -3 0 obj -<< - /Contents 6 0 R - /Resources 5 0 R ->> -endobj - -6 0 obj -<<>> -stream -612 0.0 0.0 104000 0 0 cm -/XBad Do -endstream -endobj - -5 0 obj -<< - /XObject << - /XBad 7 0 R - >> ->> -endobj - -7 0 obj -<< - /Type /XObject - /Subtype /Image - /Width 612 - /Height 104000 - /ColorSpace /DeviceRGB - /BitsPerComponent 4 - /Length 0 - /Decode [1.0] ->> -stream -FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF -endobj - -xref -0 8 -0000000000 65535 f -0000000016 00000 n -0000000053 00000 n -0000000093 00000 n -0000000000 65535 f -0000000225 00000 n -0000000152 00000 n -0000000282 00000 n -trailer << - /Root 1 0 R - /Size 8 ->> -startxref -1370 -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_555784.in b/chromium/third_party/pdfium/testing/resources/bug_555784.in deleted file mode 100644 index c6a1f43b7c0..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_555784.in +++ /dev/null @@ -1,74 +0,0 @@ -{{header}} - -{{object 1 0}} -<< - /Pages 2 0 R ->> -endobj - -{{object 2 0}} -<< - /Kids [ 3 0 R ] ->> -endobj - -{{object 3 0}} -<< - /Contents 6 0 R - /Resources 5 0 R ->> -endobj - -{{object 6 0}} -<<>> -stream -4178 0.0 0.0 1 0 0 cm -/XBad Do -endstream -endobj - -{{object 5 0}} -<< - /XObject << - /XBad 7 0 R - >> ->> -endobj - -{{object 7 0}} -<< - /Type /XObject - /Subtype /Image - /Width 81915 - /Height 1 - /ColorSpace [/DeviceN [ -/a0 /a1 /a2 /a3 /a4 /a5 /a6 /a7 /a8 /a9 /aa /ab /ac /ad /ae /af /a10 /a11 /a12 /a13 /a14 /a15 /a16 /a17 /a18 /a19 /a1a /a1b /a1c /a1d /a1e /a1f /a20 /a21 /a22 /a23 /a24 /a25 /a26 /a27 /a28 /a29 /a2a /a2b /a2c /a2d /a2e /a2f /a30 /a31 /a32 /a33 /a34 /a35 /a36 /a37 /a38 /a39 /a3a /a3b /a3c /a3d /a3e /a3f /a40 /a41 /a42 /a43 /a44 /a45 /a46 /a47 /a48 /a49 /a4a /a4b /a4c /a4d /a4e /a4f /a50 /a51 /a52 /a53 /a54 /a55 /a56 /a57 /a58 /a59 /a5a /a5b /a5c /a5d /a5e /a5f /a60 /a61 /a62 /a63 /a64 /a65 /a66 /a67 /a68 /a69 /a6a /a6b /a6c /a6d /a6e /a6f /a70 /a71 /a72 /a73 /a74 /a75 /a76 /a77 /a78 /a79 /a7a /a7b /a7c /a7d /a7e /a7f /a80 /a81 /a82 /a83 /a84 /a85 /a86 /a87 /a88 /a89 /a8a /a8b /a8c /a8d /a8e /a8f /a90 /a91 /a92 /a93 /a94 /a95 /a96 /a97 /a98 /a99 /a9a /a9b /a9c /a9d /a9e /a9f /aa0 /aa1 /aa2 /aa3 /aa4 /aa5 /aa6 /aa7 /aa8 /aa9 /aaa /aab /aac /aad /aae /aaf /ab0 /ab1 /ab2 /ab3 /ab4 /ab5 /ab6 /ab7 /ab8 /ab9 /aba /abb /abc /abd /abe /abf /ac0 /ac1 /ac2 /ac3 /ac4 /ac5 /ac6 /ac7 /ac8 /ac9 /aca /acb /acc /acd /ace /acf /ad0 /ad1 /ad2 /ad3 /ad4 /ad5 /ad6 /ad7 /ad8 /ad9 /ada /adb /adc /add /ade /adf /ae0 /ae1 /ae2 /ae3 /ae4 /ae5 /ae6 /ae7 /ae8 /ae9 /aea /aeb /aec /aed /aee /aef /af0 /af1 /af2 /af3 /af4 /af5 /af6 /af7 /af8 /af9 /afa /afb /afc /afd /afe /aff /a100 /a101 /a102 /a103 /a104 /a105 /a106 /a107 /a108 /a109 /a10a /a10b /a10c /a10d /a10e /a10f /a110 /a111 /a112 /a113 /a114 /a115 /a116 /a117 /a118 /a119 /a11a /a11b /a11c /a11d /a11e /a11f /a120 /a121 /a122 /a123 /a124 /a125 /a126 /a127 /a128 /a129 /a12a /a12b /a12c /a12d /a12e /a12f /a130 /a131 /a132 /a133 /a134 /a135 /a136 /a137 /a138 /a139 /a13a /a13b /a13c /a13d /a13e /a13f /a140 /a141 /a142 /a143 /a144 /a145 /a146 /a147 /a148 /a149 /a14a /a14b /a14c /a14d /a14e /a14f /a150 /a151 /a152 /a153 /a154 /a155 /a156 /a157 /a158 /a159 /a15a /a15b /a15c /a15d /a15e /a15f /a160 /a161 /a162 /a163 /a164 /a165 /a166 /a167 /a168 /a169 /a16a /a16b /a16c /a16d /a16e /a16f /a170 /a171 /a172 /a173 /a174 /a175 /a176 /a177 /a178 /a179 /a17a /a17b /a17c /a17d /a17e /a17f /a180 /a181 /a182 /a183 /a184 /a185 /a186 /a187 /a188 /a189 /a18a /a18b /a18c /a18d /a18e /a18f /a190 /a191 /a192 /a193 /a194 /a195 /a196 /a197 /a198 /a199 /a19a /a19b /a19c /a19d /a19e /a19f /a1a0 /a1a1 /a1a2 /a1a3 /a1a4 /a1a5 /a1a6 /a1a7 /a1a8 /a1a9 /a1aa /a1ab /a1ac /a1ad /a1ae /a1af /a1b0 /a1b1 /a1b2 /a1b3 /a1b4 /a1b5 /a1b6 /a1b7 /a1b8 /a1b9 /a1ba /a1bb /a1bc /a1bd /a1be /a1bf /a1c0 /a1c1 /a1c2 /a1c3 /a1c4 /a1c5 /a1c6 /a1c7 /a1c8 /a1c9 /a1ca /a1cb /a1cc /a1cd /a1ce /a1cf /a1d0 /a1d1 /a1d2 /a1d3 /a1d4 /a1d5 /a1d6 /a1d7 /a1d8 /a1d9 /a1da /a1db /a1dc /a1dd /a1de /a1df /a1e0 /a1e1 /a1e2 /a1e3 /a1e4 /a1e5 /a1e6 /a1e7 /a1e8 /a1e9 /a1ea /a1eb /a1ec /a1ed /a1ee /a1ef /a1f0 /a1f1 /a1f2 /a1f3 /a1f4 /a1f5 /a1f6 /a1f7 /a1f8 /a1f9 /a1fa /a1fb /a1fc /a1fd /a1fe /a1ff /a200 /a201 /a202 /a203 /a204 /a205 /a206 /a207 /a208 /a209 /a20a /a20b /a20c /a20d /a20e /a20f /a210 /a211 /a212 /a213 /a214 /a215 /a216 /a217 /a218 /a219 /a21a /a21b /a21c /a21d /a21e /a21f /a220 /a221 /a222 /a223 /a224 /a225 /a226 /a227 /a228 /a229 /a22a /a22b /a22c /a22d /a22e /a22f /a230 /a231 /a232 /a233 /a234 /a235 /a236 /a237 /a238 /a239 /a23a /a23b /a23c /a23d /a23e /a23f /a240 /a241 /a242 /a243 /a244 /a245 /a246 /a247 /a248 /a249 /a24a /a24b /a24c /a24d /a24e /a24f /a250 /a251 /a252 /a253 /a254 /a255 /a256 /a257 /a258 /a259 /a25a /a25b /a25c /a25d /a25e /a25f /a260 /a261 /a262 /a263 /a264 /a265 /a266 /a267 /a268 /a269 /a26a /a26b /a26c /a26d /a26e /a26f /a270 /a271 /a272 /a273 /a274 /a275 /a276 /a277 /a278 /a279 /a27a /a27b /a27c /a27d /a27e /a27f /a280 /a281 /a282 /a283 /a284 /a285 /a286 /a287 /a288 /a289 /a28a /a28b /a28c /a28d /a28e /a28f /a290 /a291 /a292 /a293 /a294 /a295 /a296 /a297 /a298 /a299 /a29a /a29b /a29c /a29d /a29e /a29f /a2a0 /a2a1 /a2a2 /a2a3 /a2a4 /a2a5 /a2a6 /a2a7 /a2a8 /a2a9 /a2aa /a2ab /a2ac /a2ad /a2ae /a2af /a2b0 /a2b1 /a2b2 /a2b3 /a2b4 /a2b5 /a2b6 /a2b7 /a2b8 /a2b9 /a2ba /a2bb /a2bc /a2bd /a2be /a2bf /a2c0 /a2c1 /a2c2 /a2c3 /a2c4 /a2c5 /a2c6 /a2c7 /a2c8 /a2c9 /a2ca /a2cb /a2cc /a2cd /a2ce /a2cf /a2d0 /a2d1 /a2d2 /a2d3 /a2d4 /a2d5 /a2d6 /a2d7 /a2d8 /a2d9 /a2da /a2db /a2dc /a2dd /a2de /a2df /a2e0 /a2e1 /a2e2 /a2e3 /a2e4 /a2e5 /a2e6 /a2e7 /a2e8 /a2e9 /a2ea /a2eb /a2ec /a2ed /a2ee /a2ef /a2f0 /a2f1 /a2f2 /a2f3 /a2f4 /a2f5 /a2f6 /a2f7 /a2f8 /a2f9 /a2fa /a2fb /a2fc /a2fd /a2fe /a2ff /a300 /a301 /a302 /a303 /a304 /a305 /a306 /a307 /a308 /a309 /a30a /a30b /a30c /a30d /a30e /a30f /a310 /a311 /a312 /a313 /a314 /a315 /a316 /a317 /a318 /a319 /a31a /a31b /a31c /a31d /a31e /a31f /a320 /a321 /a322 /a323 /a324 /a325 /a326 /a327 /a328 /a329 /a32a /a32b /a32c /a32d /a32e /a32f /a330 /a331 /a332 /a333 /a334 /a335 /a336 /a337 /a338 /a339 /a33a /a33b /a33c /a33d /a33e /a33f /a340 /a341 /a342 /a343 /a344 /a345 /a346 /a347 /a348 /a349 /a34a /a34b /a34c /a34d /a34e /a34f /a350 /a351 /a352 /a353 /a354 /a355 /a356 /a357 /a358 /a359 /a35a /a35b /a35c /a35d /a35e /a35f /a360 /a361 /a362 /a363 /a364 /a365 /a366 /a367 /a368 /a369 /a36a /a36b /a36c /a36d /a36e /a36f /a370 /a371 /a372 /a373 /a374 /a375 /a376 /a377 /a378 /a379 /a37a /a37b /a37c /a37d /a37e /a37f /a380 /a381 /a382 /a383 /a384 /a385 /a386 /a387 /a388 /a389 /a38a /a38b /a38c /a38d /a38e /a38f /a390 /a391 /a392 /a393 /a394 /a395 /a396 /a397 /a398 /a399 /a39a /a39b /a39c /a39d /a39e /a39f /a3a0 /a3a1 /a3a2 /a3a3 /a3a4 /a3a5 /a3a6 /a3a7 /a3a8 /a3a9 /a3aa /a3ab /a3ac /a3ad /a3ae /a3af /a3b0 /a3b1 /a3b2 /a3b3 /a3b4 /a3b5 /a3b6 /a3b7 /a3b8 /a3b9 /a3ba /a3bb /a3bc /a3bd /a3be /a3bf /a3c0 /a3c1 /a3c2 /a3c3 /a3c4 /a3c5 /a3c6 /a3c7 /a3c8 /a3c9 /a3ca /a3cb /a3cc /a3cd /a3ce /a3cf /a3d0 /a3d1 /a3d2 /a3d3 /a3d4 /a3d5 /a3d6 /a3d7 /a3d8 /a3d9 /a3da /a3db /a3dc /a3dd /a3de /a3df /a3e0 /a3e1 /a3e2 /a3e3 /a3e4 /a3e5 /a3e6 /a3e7 -/a3e8 /a3e9 /a3ea /a3eb /a3ec /a3ed /a3ee /a3ef /a3f0 /a3f1 /a3f2 /a3f3 /a3f4 /a3f5 /a3f6 /a3f7 /a3f8 /a3f9 /a3fa /a3fb /a3fc /a3fd /a3fe /a3ff /a400 /a401 /a402 /a403 /a404 /a405 /a406 /a407 /a408 /a409 /a40a /a40b /a40c /a40d /a40e /a40f /a410 /a411 /a412 /a413 /a414 /a415 /a416 /a417 /a418 /a419 /a41a /a41b /a41c /a41d /a41e /a41f /a420 /a421 /a422 /a423 /a424 /a425 /a426 /a427 /a428 /a429 /a42a /a42b /a42c /a42d /a42e /a42f /a430 /a431 /a432 /a433 /a434 /a435 /a436 /a437 /a438 /a439 /a43a /a43b /a43c /a43d /a43e /a43f /a440 /a441 /a442 /a443 /a444 /a445 /a446 /a447 /a448 /a449 /a44a /a44b /a44c /a44d /a44e /a44f /a450 /a451 /a452 /a453 /a454 /a455 /a456 /a457 /a458 /a459 /a45a /a45b /a45c /a45d /a45e /a45f /a460 /a461 /a462 /a463 /a464 /a465 /a466 /a467 /a468 /a469 /a46a /a46b /a46c /a46d /a46e /a46f /a470 /a471 /a472 /a473 /a474 /a475 /a476 /a477 /a478 /a479 /a47a /a47b /a47c /a47d /a47e /a47f /a480 /a481 /a482 /a483 /a484 /a485 /a486 /a487 /a488 /a489 /a48a /a48b /a48c /a48d /a48e /a48f /a490 /a491 /a492 /a493 /a494 /a495 /a496 /a497 /a498 /a499 /a49a /a49b /a49c /a49d /a49e /a49f /a4a0 /a4a1 /a4a2 /a4a3 /a4a4 /a4a5 /a4a6 /a4a7 /a4a8 /a4a9 /a4aa /a4ab /a4ac /a4ad /a4ae /a4af /a4b0 /a4b1 /a4b2 /a4b3 /a4b4 /a4b5 /a4b6 /a4b7 /a4b8 /a4b9 /a4ba /a4bb /a4bc /a4bd /a4be /a4bf /a4c0 /a4c1 /a4c2 /a4c3 /a4c4 /a4c5 /a4c6 /a4c7 /a4c8 /a4c9 /a4ca /a4cb /a4cc /a4cd /a4ce /a4cf /a4d0 /a4d1 /a4d2 /a4d3 /a4d4 /a4d5 /a4d6 /a4d7 /a4d8 /a4d9 /a4da /a4db /a4dc /a4dd /a4de /a4df /a4e0 /a4e1 /a4e2 /a4e3 /a4e4 /a4e5 /a4e6 /a4e7 /a4e8 /a4e9 /a4ea /a4eb /a4ec /a4ed /a4ee /a4ef /a4f0 /a4f1 /a4f2 /a4f3 /a4f4 /a4f5 /a4f6 /a4f7 /a4f8 /a4f9 /a4fa /a4fb /a4fc /a4fd /a4fe /a4ff /a500 /a501 /a502 /a503 /a504 /a505 /a506 /a507 /a508 /a509 /a50a /a50b /a50c /a50d /a50e /a50f /a510 /a511 /a512 /a513 /a514 /a515 /a516 /a517 /a518 /a519 /a51a /a51b /a51c /a51d /a51e /a51f /a520 /a521 /a522 /a523 /a524 /a525 /a526 /a527 /a528 /a529 /a52a /a52b /a52c /a52d /a52e /a52f /a530 /a531 /a532 /a533 /a534 /a535 /a536 /a537 /a538 /a539 /a53a /a53b /a53c /a53d /a53e /a53f /a540 /a541 /a542 /a543 /a544 /a545 /a546 /a547 /a548 /a549 /a54a /a54b /a54c /a54d /a54e /a54f /a550 /a551 /a552 /a553 /a554 /a555 /a556 /a557 /a558 /a559 /a55a /a55b /a55c /a55d /a55e /a55f /a560 /a561 /a562 /a563 /a564 /a565 /a566 /a567 /a568 /a569 /a56a /a56b /a56c /a56d /a56e /a56f /a570 /a571 /a572 /a573 /a574 /a575 /a576 /a577 /a578 /a579 /a57a /a57b /a57c /a57d /a57e /a57f /a580 /a581 /a582 /a583 /a584 /a585 /a586 /a587 /a588 /a589 /a58a /a58b /a58c /a58d /a58e /a58f /a590 /a591 /a592 /a593 /a594 /a595 /a596 /a597 /a598 /a599 /a59a /a59b /a59c /a59d /a59e /a59f /a5a0 /a5a1 /a5a2 /a5a3 /a5a4 /a5a5 /a5a6 /a5a7 /a5a8 /a5a9 /a5aa /a5ab /a5ac /a5ad /a5ae /a5af /a5b0 /a5b1 /a5b2 /a5b3 /a5b4 /a5b5 /a5b6 /a5b7 /a5b8 /a5b9 /a5ba /a5bb /a5bc /a5bd /a5be /a5bf /a5c0 /a5c1 /a5c2 /a5c3 /a5c4 /a5c5 /a5c6 /a5c7 /a5c8 /a5c9 /a5ca /a5cb /a5cc /a5cd /a5ce /a5cf /a5d0 /a5d1 /a5d2 /a5d3 /a5d4 /a5d5 /a5d6 /a5d7 /a5d8 /a5d9 /a5da /a5db /a5dc /a5dd /a5de /a5df /a5e0 /a5e1 /a5e2 /a5e3 /a5e4 /a5e5 /a5e6 /a5e7 /a5e8 /a5e9 /a5ea /a5eb /a5ec /a5ed /a5ee /a5ef /a5f0 /a5f1 /a5f2 /a5f3 /a5f4 /a5f5 /a5f6 /a5f7 /a5f8 /a5f9 /a5fa /a5fb /a5fc /a5fd /a5fe /a5ff /a600 /a601 /a602 /a603 /a604 /a605 /a606 /a607 /a608 /a609 /a60a /a60b /a60c /a60d /a60e /a60f /a610 /a611 /a612 /a613 /a614 /a615 /a616 /a617 /a618 /a619 /a61a /a61b /a61c /a61d /a61e /a61f /a620 /a621 /a622 /a623 /a624 /a625 /a626 /a627 /a628 /a629 /a62a /a62b /a62c /a62d /a62e /a62f /a630 /a631 /a632 /a633 /a634 /a635 /a636 /a637 /a638 /a639 /a63a /a63b /a63c /a63d /a63e /a63f /a640 /a641 /a642 /a643 /a644 /a645 /a646 /a647 /a648 /a649 /a64a /a64b /a64c /a64d /a64e /a64f /a650 /a651 /a652 /a653 /a654 /a655 /a656 /a657 /a658 /a659 /a65a /a65b /a65c /a65d /a65e /a65f /a660 /a661 /a662 /a663 /a664 /a665 /a666 /a667 /a668 /a669 /a66a /a66b /a66c /a66d /a66e /a66f /a670 /a671 /a672 /a673 /a674 /a675 /a676 /a677 /a678 /a679 /a67a /a67b /a67c /a67d /a67e /a67f /a680 /a681 /a682 /a683 /a684 /a685 /a686 /a687 /a688 /a689 /a68a /a68b /a68c /a68d /a68e /a68f /a690 /a691 /a692 /a693 /a694 /a695 /a696 /a697 /a698 /a699 /a69a /a69b /a69c /a69d /a69e /a69f /a6a0 /a6a1 /a6a2 /a6a3 /a6a4 /a6a5 /a6a6 /a6a7 /a6a8 /a6a9 /a6aa /a6ab /a6ac /a6ad /a6ae /a6af /a6b0 /a6b1 /a6b2 /a6b3 /a6b4 /a6b5 /a6b6 /a6b7 /a6b8 /a6b9 /a6ba /a6bb /a6bc /a6bd /a6be /a6bf /a6c0 /a6c1 /a6c2 /a6c3 /a6c4 /a6c5 /a6c6 /a6c7 /a6c8 /a6c9 /a6ca /a6cb /a6cc /a6cd /a6ce /a6cf /a6d0 /a6d1 /a6d2 /a6d3 /a6d4 /a6d5 /a6d6 /a6d7 /a6d8 /a6d9 /a6da /a6db /a6dc /a6dd /a6de /a6df /a6e0 /a6e1 /a6e2 /a6e3 /a6e4 /a6e5 /a6e6 /a6e7 /a6e8 /a6e9 /a6ea /a6eb /a6ec /a6ed /a6ee /a6ef /a6f0 /a6f1 /a6f2 /a6f3 /a6f4 /a6f5 /a6f6 /a6f7 /a6f8 /a6f9 /a6fa /a6fb /a6fc /a6fd /a6fe /a6ff /a700 /a701 /a702 /a703 /a704 /a705 /a706 /a707 /a708 /a709 /a70a /a70b /a70c /a70d /a70e /a70f /a710 /a711 /a712 /a713 /a714 /a715 /a716 /a717 /a718 /a719 /a71a /a71b /a71c /a71d /a71e /a71f /a720 /a721 /a722 /a723 /a724 /a725 /a726 /a727 /a728 /a729 /a72a /a72b /a72c /a72d /a72e /a72f /a730 /a731 /a732 /a733 /a734 /a735 /a736 /a737 /a738 /a739 /a73a /a73b /a73c /a73d /a73e /a73f /a740 /a741 /a742 /a743 /a744 /a745 /a746 /a747 /a748 /a749 /a74a /a74b /a74c /a74d /a74e /a74f /a750 /a751 /a752 /a753 /a754 /a755 /a756 /a757 /a758 /a759 /a75a /a75b /a75c /a75d /a75e /a75f /a760 /a761 /a762 /a763 /a764 /a765 /a766 /a767 /a768 /a769 /a76a /a76b /a76c /a76d /a76e /a76f /a770 /a771 /a772 /a773 /a774 /a775 /a776 /a777 /a778 /a779 /a77a /a77b /a77c /a77d /a77e /a77f /a780 /a781 /a782 /a783 /a784 /a785 /a786 /a787 /a788 /a789 /a78a /a78b /a78c /a78d /a78e /a78f /a790 /a791 /a792 /a793 /a794 /a795 /a796 /a797 /a798 /a799 /a79a /a79b /a79c /a79d /a79e /a79f /a7a0 /a7a1 /a7a2 /a7a3 /a7a4 /a7a5 /a7a6 /a7a7 /a7a8 /a7a9 /a7aa /a7ab /a7ac /a7ad /a7ae /a7af /a7b0 /a7b1 /a7b2 /a7b3 /a7b4 /a7b5 /a7b6 /a7b7 /a7b8 /a7b9 /a7ba /a7bb /a7bc /a7bd /a7be /a7bf /a7c0 /a7c1 /a7c2 /a7c3 /a7c4 /a7c5 /a7c6 /a7c7 /a7c8 /a7c9 /a7ca /a7cb /a7cc /a7cd /a7ce /a7cf -/a7d0 /a7d1 /a7d2 /a7d3 /a7d4 /a7d5 /a7d6 /a7d7 /a7d8 /a7d9 /a7da /a7db /a7dc /a7dd /a7de /a7df /a7e0 /a7e1 /a7e2 /a7e3 /a7e4 /a7e5 /a7e6 /a7e7 /a7e8 /a7e9 /a7ea /a7eb /a7ec /a7ed /a7ee /a7ef /a7f0 /a7f1 /a7f2 /a7f3 /a7f4 /a7f5 /a7f6 /a7f7 /a7f8 /a7f9 /a7fa /a7fb /a7fc /a7fd /a7fe /a7ff /a800 /a801 /a802 /a803 /a804 /a805 /a806 /a807 /a808 /a809 /a80a /a80b /a80c /a80d /a80e /a80f /a810 /a811 /a812 /a813 /a814 /a815 /a816 /a817 /a818 /a819 /a81a /a81b /a81c /a81d /a81e /a81f /a820 /a821 /a822 /a823 /a824 /a825 /a826 /a827 /a828 /a829 /a82a /a82b /a82c /a82d /a82e /a82f /a830 /a831 /a832 /a833 /a834 /a835 /a836 /a837 /a838 /a839 /a83a /a83b /a83c /a83d /a83e /a83f /a840 /a841 /a842 /a843 /a844 /a845 /a846 /a847 /a848 /a849 /a84a /a84b /a84c /a84d /a84e /a84f /a850 /a851 /a852 /a853 /a854 /a855 /a856 /a857 /a858 /a859 /a85a /a85b /a85c /a85d /a85e /a85f /a860 /a861 /a862 /a863 /a864 /a865 /a866 /a867 /a868 /a869 /a86a /a86b /a86c /a86d /a86e /a86f /a870 /a871 /a872 /a873 /a874 /a875 /a876 /a877 /a878 /a879 /a87a /a87b /a87c /a87d /a87e /a87f /a880 /a881 /a882 /a883 /a884 /a885 /a886 /a887 /a888 /a889 /a88a /a88b /a88c /a88d /a88e /a88f /a890 /a891 /a892 /a893 /a894 /a895 /a896 /a897 /a898 /a899 /a89a /a89b /a89c /a89d /a89e /a89f /a8a0 /a8a1 /a8a2 /a8a3 /a8a4 /a8a5 /a8a6 /a8a7 /a8a8 /a8a9 /a8aa /a8ab /a8ac /a8ad /a8ae /a8af /a8b0 /a8b1 /a8b2 /a8b3 /a8b4 /a8b5 /a8b6 /a8b7 /a8b8 /a8b9 /a8ba /a8bb /a8bc /a8bd /a8be /a8bf /a8c0 /a8c1 /a8c2 /a8c3 /a8c4 /a8c5 /a8c6 /a8c7 /a8c8 /a8c9 /a8ca /a8cb /a8cc /a8cd /a8ce /a8cf /a8d0 /a8d1 /a8d2 /a8d3 /a8d4 /a8d5 /a8d6 /a8d7 /a8d8 /a8d9 /a8da /a8db /a8dc /a8dd /a8de /a8df /a8e0 /a8e1 /a8e2 /a8e3 /a8e4 /a8e5 /a8e6 /a8e7 /a8e8 /a8e9 /a8ea /a8eb /a8ec /a8ed /a8ee /a8ef /a8f0 /a8f1 /a8f2 /a8f3 /a8f4 /a8f5 /a8f6 /a8f7 /a8f8 /a8f9 /a8fa /a8fb /a8fc /a8fd /a8fe /a8ff /a900 /a901 /a902 /a903 /a904 /a905 /a906 /a907 /a908 /a909 /a90a /a90b /a90c /a90d /a90e /a90f /a910 /a911 /a912 /a913 /a914 /a915 /a916 /a917 /a918 /a919 /a91a /a91b /a91c /a91d /a91e /a91f /a920 /a921 /a922 /a923 /a924 /a925 /a926 /a927 /a928 /a929 /a92a /a92b /a92c /a92d /a92e /a92f /a930 /a931 /a932 /a933 /a934 /a935 /a936 /a937 /a938 /a939 /a93a /a93b /a93c /a93d /a93e /a93f /a940 /a941 /a942 /a943 /a944 /a945 /a946 /a947 /a948 /a949 /a94a /a94b /a94c /a94d /a94e /a94f /a950 /a951 /a952 /a953 /a954 /a955 /a956 /a957 /a958 /a959 /a95a /a95b /a95c /a95d /a95e /a95f /a960 /a961 /a962 /a963 /a964 /a965 /a966 /a967 /a968 /a969 /a96a /a96b /a96c /a96d /a96e /a96f /a970 /a971 /a972 /a973 /a974 /a975 /a976 /a977 /a978 /a979 /a97a /a97b /a97c /a97d /a97e /a97f /a980 /a981 /a982 /a983 /a984 /a985 /a986 /a987 /a988 /a989 /a98a /a98b /a98c /a98d /a98e /a98f /a990 /a991 /a992 /a993 /a994 /a995 /a996 /a997 /a998 /a999 /a99a /a99b /a99c /a99d /a99e /a99f /a9a0 /a9a1 /a9a2 /a9a3 /a9a4 /a9a5 /a9a6 /a9a7 /a9a8 /a9a9 /a9aa /a9ab /a9ac /a9ad /a9ae /a9af /a9b0 /a9b1 /a9b2 /a9b3 /a9b4 /a9b5 /a9b6 /a9b7 /a9b8 /a9b9 /a9ba /a9bb /a9bc /a9bd /a9be /a9bf /a9c0 /a9c1 /a9c2 /a9c3 /a9c4 /a9c5 /a9c6 /a9c7 /a9c8 /a9c9 /a9ca /a9cb /a9cc /a9cd /a9ce /a9cf /a9d0 /a9d1 /a9d2 /a9d3 /a9d4 /a9d5 /a9d6 /a9d7 /a9d8 /a9d9 /a9da /a9db /a9dc /a9dd /a9de /a9df /a9e0 /a9e1 /a9e2 /a9e3 /a9e4 /a9e5 /a9e6 /a9e7 /a9e8 /a9e9 /a9ea /a9eb /a9ec /a9ed /a9ee /a9ef /a9f0 /a9f1 /a9f2 /a9f3 /a9f4 /a9f5 /a9f6 /a9f7 /a9f8 /a9f9 /a9fa /a9fb /a9fc /a9fd /a9fe /a9ff /aa00 /aa01 /aa02 /aa03 /aa04 /aa05 /aa06 /aa07 /aa08 /aa09 /aa0a /aa0b /aa0c /aa0d /aa0e /aa0f /aa10 /aa11 /aa12 /aa13 /aa14 /aa15 /aa16 /aa17 /aa18 /aa19 /aa1a /aa1b /aa1c /aa1d /aa1e /aa1f /aa20 /aa21 /aa22 /aa23 /aa24 /aa25 /aa26 /aa27 /aa28 /aa29 /aa2a /aa2b /aa2c /aa2d /aa2e /aa2f /aa30 /aa31 /aa32 /aa33 /aa34 /aa35 /aa36 /aa37 /aa38 /aa39 /aa3a /aa3b /aa3c /aa3d /aa3e /aa3f /aa40 /aa41 /aa42 /aa43 /aa44 /aa45 /aa46 /aa47 /aa48 /aa49 /aa4a /aa4b /aa4c /aa4d /aa4e /aa4f /aa50 /aa51 /aa52 /aa53 /aa54 /aa55 /aa56 /aa57 /aa58 /aa59 /aa5a /aa5b /aa5c /aa5d /aa5e /aa5f /aa60 /aa61 /aa62 /aa63 /aa64 /aa65 /aa66 /aa67 /aa68 /aa69 /aa6a /aa6b /aa6c /aa6d /aa6e /aa6f /aa70 /aa71 /aa72 /aa73 /aa74 /aa75 /aa76 /aa77 /aa78 /aa79 /aa7a /aa7b /aa7c /aa7d /aa7e /aa7f /aa80 /aa81 /aa82 /aa83 /aa84 /aa85 /aa86 /aa87 /aa88 /aa89 /aa8a /aa8b /aa8c /aa8d /aa8e /aa8f /aa90 /aa91 /aa92 /aa93 /aa94 /aa95 /aa96 /aa97 /aa98 /aa99 /aa9a /aa9b /aa9c /aa9d /aa9e /aa9f /aaa0 /aaa1 /aaa2 /aaa3 /aaa4 /aaa5 /aaa6 /aaa7 /aaa8 /aaa9 /aaaa /aaab /aaac /aaad /aaae /aaaf /aab0 /aab1 /aab2 /aab3 /aab4 /aab5 /aab6 /aab7 /aab8 /aab9 /aaba /aabb /aabc /aabd /aabe /aabf /aac0 /aac1 /aac2 /aac3 /aac4 /aac5 /aac6 /aac7 /aac8 /aac9 /aaca /aacb /aacc /aacd /aace /aacf /aad0 /aad1 /aad2 /aad3 /aad4 /aad5 /aad6 /aad7 /aad8 /aad9 /aada /aadb /aadc /aadd /aade /aadf /aae0 /aae1 /aae2 /aae3 /aae4 /aae5 /aae6 /aae7 /aae8 /aae9 /aaea /aaeb /aaec /aaed /aaee /aaef /aaf0 /aaf1 /aaf2 /aaf3 /aaf4 /aaf5 /aaf6 /aaf7 /aaf8 /aaf9 /aafa /aafb /aafc /aafd /aafe /aaff /ab00 /ab01 /ab02 /ab03 /ab04 /ab05 /ab06 /ab07 /ab08 /ab09 /ab0a /ab0b /ab0c /ab0d /ab0e /ab0f /ab10 /ab11 /ab12 /ab13 /ab14 /ab15 /ab16 /ab17 /ab18 /ab19 /ab1a /ab1b /ab1c /ab1d /ab1e /ab1f /ab20 /ab21 /ab22 /ab23 /ab24 /ab25 /ab26 /ab27 /ab28 /ab29 /ab2a /ab2b /ab2c /ab2d /ab2e /ab2f /ab30 /ab31 /ab32 /ab33 /ab34 /ab35 /ab36 /ab37 /ab38 /ab39 /ab3a /ab3b /ab3c /ab3d /ab3e /ab3f /ab40 /ab41 /ab42 /ab43 /ab44 /ab45 /ab46 /ab47 /ab48 /ab49 /ab4a /ab4b /ab4c /ab4d /ab4e /ab4f /ab50 /ab51 /ab52 /ab53 /ab54 /ab55 /ab56 /ab57 /ab58 /ab59 /ab5a /ab5b /ab5c /ab5d /ab5e /ab5f /ab60 /ab61 /ab62 /ab63 /ab64 /ab65 /ab66 /ab67 /ab68 /ab69 /ab6a /ab6b /ab6c /ab6d /ab6e /ab6f /ab70 /ab71 /ab72 /ab73 /ab74 /ab75 /ab76 /ab77 /ab78 /ab79 /ab7a /ab7b /ab7c /ab7d /ab7e /ab7f /ab80 /ab81 /ab82 /ab83 /ab84 /ab85 /ab86 /ab87 /ab88 /ab89 /ab8a /ab8b /ab8c /ab8d /ab8e /ab8f /ab90 /ab91 /ab92 /ab93 /ab94 /ab95 /ab96 /ab97 /ab98 /ab99 /ab9a /ab9b /ab9c /ab9d /ab9e /ab9f /aba0 /aba1 /aba2 /aba3 /aba4 /aba5 /aba6 /aba7 /aba8 /aba9 /abaa /abab /abac /abad /abae /abaf /abb0 /abb1 /abb2 /abb3 /abb4 /abb5 /abb6 /abb7 -/abb8 /abb9 /abba /abbb /abbc /abbd /abbe /abbf /abc0 /abc1 /abc2 /abc3 /abc4 /abc5 /abc6 /abc7 /abc8 /abc9 /abca /abcb /abcc /abcd /abce /abcf /abd0 /abd1 /abd2 /abd3 /abd4 /abd5 /abd6 /abd7 /abd8 /abd9 /abda /abdb /abdc /abdd /abde /abdf /abe0 /abe1 /abe2 /abe3 /abe4 /abe5 /abe6 /abe7 /abe8 /abe9 /abea /abeb /abec /abed /abee /abef /abf0 /abf1 /abf2 /abf3 /abf4 /abf5 /abf6 /abf7 /abf8 /abf9 /abfa /abfb /abfc /abfd /abfe /abff /ac00 /ac01 /ac02 /ac03 /ac04 /ac05 /ac06 /ac07 /ac08 /ac09 /ac0a /ac0b /ac0c /ac0d /ac0e /ac0f /ac10 /ac11 /ac12 /ac13 /ac14 /ac15 /ac16 /ac17 /ac18 /ac19 /ac1a /ac1b /ac1c /ac1d /ac1e /ac1f /ac20 /ac21 /ac22 /ac23 /ac24 /ac25 /ac26 /ac27 /ac28 /ac29 /ac2a /ac2b /ac2c /ac2d /ac2e /ac2f /ac30 /ac31 /ac32 /ac33 /ac34 /ac35 /ac36 /ac37 /ac38 /ac39 /ac3a /ac3b /ac3c /ac3d /ac3e /ac3f /ac40 /ac41 /ac42 /ac43 /ac44 /ac45 /ac46 /ac47 /ac48 /ac49 /ac4a /ac4b /ac4c /ac4d /ac4e /ac4f /ac50 /ac51 /ac52 /ac53 /ac54 /ac55 /ac56 /ac57 /ac58 /ac59 /ac5a /ac5b /ac5c /ac5d /ac5e /ac5f /ac60 /ac61 /ac62 /ac63 /ac64 /ac65 /ac66 /ac67 /ac68 /ac69 /ac6a /ac6b /ac6c /ac6d /ac6e /ac6f /ac70 /ac71 /ac72 /ac73 /ac74 /ac75 /ac76 /ac77 /ac78 /ac79 /ac7a /ac7b /ac7c /ac7d /ac7e /ac7f /ac80 /ac81 /ac82 /ac83 /ac84 /ac85 /ac86 /ac87 /ac88 /ac89 /ac8a /ac8b /ac8c /ac8d /ac8e /ac8f /ac90 /ac91 /ac92 /ac93 /ac94 /ac95 /ac96 /ac97 /ac98 /ac99 /ac9a /ac9b /ac9c /ac9d /ac9e /ac9f /aca0 /aca1 /aca2 /aca3 /aca4 /aca5 /aca6 /aca7 /aca8 /aca9 /acaa /acab /acac /acad /acae /acaf /acb0 /acb1 /acb2 /acb3 /acb4 /acb5 /acb6 /acb7 /acb8 /acb9 /acba /acbb /acbc /acbd /acbe /acbf /acc0 /acc1 /acc2 /acc3 /acc4 /acc5 /acc6 /acc7 /acc8 /acc9 /acca /accb /accc -] /DeviceRGB 10 0 R] - /BitsPerComponent 16 - /Filter [/ASCIIHexDecode /FlateDecode /RunLengthDecode] ->> -stream -789cecc101010000008090ed3def080a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080db8303020000000021ff5f3724000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009c05dff2c7ae -endstream -endobj - -{{object 10 0}} -<< - /FunctionType 2 - /Domain [0.0 1.0 0.0 1.0] - /C0 [0.0 0.0] - /C1 [1.0 1.0] - /N 1 ->> -endobj - -{{xref}} -trailer << - /Root 1 0 R - /Size 11 ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_555784.pdf b/chromium/third_party/pdfium/testing/resources/bug_555784.pdf deleted file mode 100644 index 5c56a958d29..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_555784.pdf +++ /dev/null @@ -1,88 +0,0 @@ -%PDF-1.7 -% ò¤ô - -1 0 obj -<< - /Pages 2 0 R ->> -endobj - -2 0 obj -<< - /Kids [ 3 0 R ] ->> -endobj - -3 0 obj -<< - /Contents 6 0 R - /Resources 5 0 R ->> -endobj - -6 0 obj -<<>> -stream -4178 0.0 0.0 1 0 0 cm -/XBad Do -endstream -endobj - -5 0 obj -<< - /XObject << - /XBad 7 0 R - >> ->> -endobj - -7 0 obj -<< - /Type /XObject - /Subtype /Image - /Width 81915 - /Height 1 - /ColorSpace [/DeviceN [ -/a0 /a1 /a2 /a3 /a4 /a5 /a6 /a7 /a8 /a9 /aa /ab /ac /ad /ae /af /a10 /a11 /a12 /a13 /a14 /a15 /a16 /a17 /a18 /a19 /a1a /a1b /a1c /a1d /a1e /a1f /a20 /a21 /a22 /a23 /a24 /a25 /a26 /a27 /a28 /a29 /a2a /a2b /a2c /a2d /a2e /a2f /a30 /a31 /a32 /a33 /a34 /a35 /a36 /a37 /a38 /a39 /a3a /a3b /a3c /a3d /a3e /a3f /a40 /a41 /a42 /a43 /a44 /a45 /a46 /a47 /a48 /a49 /a4a /a4b /a4c /a4d /a4e /a4f /a50 /a51 /a52 /a53 /a54 /a55 /a56 /a57 /a58 /a59 /a5a /a5b /a5c /a5d /a5e /a5f /a60 /a61 /a62 /a63 /a64 /a65 /a66 /a67 /a68 /a69 /a6a /a6b /a6c /a6d /a6e /a6f /a70 /a71 /a72 /a73 /a74 /a75 /a76 /a77 /a78 /a79 /a7a /a7b /a7c /a7d /a7e /a7f /a80 /a81 /a82 /a83 /a84 /a85 /a86 /a87 /a88 /a89 /a8a /a8b /a8c /a8d /a8e /a8f /a90 /a91 /a92 /a93 /a94 /a95 /a96 /a97 /a98 /a99 /a9a /a9b /a9c /a9d /a9e /a9f /aa0 /aa1 /aa2 /aa3 /aa4 /aa5 /aa6 /aa7 /aa8 /aa9 /aaa /aab /aac /aad /aae /aaf /ab0 /ab1 /ab2 /ab3 /ab4 /ab5 /ab6 /ab7 /ab8 /ab9 /aba /abb /abc /abd /abe /abf /ac0 /ac1 /ac2 /ac3 /ac4 /ac5 /ac6 /ac7 /ac8 /ac9 /aca /acb /acc /acd /ace /acf /ad0 /ad1 /ad2 /ad3 /ad4 /ad5 /ad6 /ad7 /ad8 /ad9 /ada /adb /adc /add /ade /adf /ae0 /ae1 /ae2 /ae3 /ae4 /ae5 /ae6 /ae7 /ae8 /ae9 /aea /aeb /aec /aed /aee /aef /af0 /af1 /af2 /af3 /af4 /af5 /af6 /af7 /af8 /af9 /afa /afb /afc /afd /afe /aff /a100 /a101 /a102 /a103 /a104 /a105 /a106 /a107 /a108 /a109 /a10a /a10b /a10c /a10d /a10e /a10f /a110 /a111 /a112 /a113 /a114 /a115 /a116 /a117 /a118 /a119 /a11a /a11b /a11c /a11d /a11e /a11f /a120 /a121 /a122 /a123 /a124 /a125 /a126 /a127 /a128 /a129 /a12a /a12b /a12c /a12d /a12e /a12f /a130 /a131 /a132 /a133 /a134 /a135 /a136 /a137 /a138 /a139 /a13a /a13b /a13c /a13d /a13e /a13f /a140 /a141 /a142 /a143 /a144 /a145 /a146 /a147 /a148 /a149 /a14a /a14b /a14c /a14d /a14e /a14f /a150 /a151 /a152 /a153 /a154 /a155 /a156 /a157 /a158 /a159 /a15a /a15b /a15c /a15d /a15e /a15f /a160 /a161 /a162 /a163 /a164 /a165 /a166 /a167 /a168 /a169 /a16a /a16b /a16c /a16d /a16e /a16f /a170 /a171 /a172 /a173 /a174 /a175 /a176 /a177 /a178 /a179 /a17a /a17b /a17c /a17d /a17e /a17f /a180 /a181 /a182 /a183 /a184 /a185 /a186 /a187 /a188 /a189 /a18a /a18b /a18c /a18d /a18e /a18f /a190 /a191 /a192 /a193 /a194 /a195 /a196 /a197 /a198 /a199 /a19a /a19b /a19c /a19d /a19e /a19f /a1a0 /a1a1 /a1a2 /a1a3 /a1a4 /a1a5 /a1a6 /a1a7 /a1a8 /a1a9 /a1aa /a1ab /a1ac /a1ad /a1ae /a1af /a1b0 /a1b1 /a1b2 /a1b3 /a1b4 /a1b5 /a1b6 /a1b7 /a1b8 /a1b9 /a1ba /a1bb /a1bc /a1bd /a1be /a1bf /a1c0 /a1c1 /a1c2 /a1c3 /a1c4 /a1c5 /a1c6 /a1c7 /a1c8 /a1c9 /a1ca /a1cb /a1cc /a1cd /a1ce /a1cf /a1d0 /a1d1 /a1d2 /a1d3 /a1d4 /a1d5 /a1d6 /a1d7 /a1d8 /a1d9 /a1da /a1db /a1dc /a1dd /a1de /a1df /a1e0 /a1e1 /a1e2 /a1e3 /a1e4 /a1e5 /a1e6 /a1e7 /a1e8 /a1e9 /a1ea /a1eb /a1ec /a1ed /a1ee /a1ef /a1f0 /a1f1 /a1f2 /a1f3 /a1f4 /a1f5 /a1f6 /a1f7 /a1f8 /a1f9 /a1fa /a1fb /a1fc /a1fd /a1fe /a1ff /a200 /a201 /a202 /a203 /a204 /a205 /a206 /a207 /a208 /a209 /a20a /a20b /a20c /a20d /a20e /a20f /a210 /a211 /a212 /a213 /a214 /a215 /a216 /a217 /a218 /a219 /a21a /a21b /a21c /a21d /a21e /a21f /a220 /a221 /a222 /a223 /a224 /a225 /a226 /a227 /a228 /a229 /a22a /a22b /a22c /a22d /a22e /a22f /a230 /a231 /a232 /a233 /a234 /a235 /a236 /a237 /a238 /a239 /a23a /a23b /a23c /a23d /a23e /a23f /a240 /a241 /a242 /a243 /a244 /a245 /a246 /a247 /a248 /a249 /a24a /a24b /a24c /a24d /a24e /a24f /a250 /a251 /a252 /a253 /a254 /a255 /a256 /a257 /a258 /a259 /a25a /a25b /a25c /a25d /a25e /a25f /a260 /a261 /a262 /a263 /a264 /a265 /a266 /a267 /a268 /a269 /a26a /a26b /a26c /a26d /a26e /a26f /a270 /a271 /a272 /a273 /a274 /a275 /a276 /a277 /a278 /a279 /a27a /a27b /a27c /a27d /a27e /a27f /a280 /a281 /a282 /a283 /a284 /a285 /a286 /a287 /a288 /a289 /a28a /a28b /a28c /a28d /a28e /a28f /a290 /a291 /a292 /a293 /a294 /a295 /a296 /a297 /a298 /a299 /a29a /a29b /a29c /a29d /a29e /a29f /a2a0 /a2a1 /a2a2 /a2a3 /a2a4 /a2a5 /a2a6 /a2a7 /a2a8 /a2a9 /a2aa /a2ab /a2ac /a2ad /a2ae /a2af /a2b0 /a2b1 /a2b2 /a2b3 /a2b4 /a2b5 /a2b6 /a2b7 /a2b8 /a2b9 /a2ba /a2bb /a2bc /a2bd /a2be /a2bf /a2c0 /a2c1 /a2c2 /a2c3 /a2c4 /a2c5 /a2c6 /a2c7 /a2c8 /a2c9 /a2ca /a2cb /a2cc /a2cd /a2ce /a2cf /a2d0 /a2d1 /a2d2 /a2d3 /a2d4 /a2d5 /a2d6 /a2d7 /a2d8 /a2d9 /a2da /a2db /a2dc /a2dd /a2de /a2df /a2e0 /a2e1 /a2e2 /a2e3 /a2e4 /a2e5 /a2e6 /a2e7 /a2e8 /a2e9 /a2ea /a2eb /a2ec /a2ed /a2ee /a2ef /a2f0 /a2f1 /a2f2 /a2f3 /a2f4 /a2f5 /a2f6 /a2f7 /a2f8 /a2f9 /a2fa /a2fb /a2fc /a2fd /a2fe /a2ff /a300 /a301 /a302 /a303 /a304 /a305 /a306 /a307 /a308 /a309 /a30a /a30b /a30c /a30d /a30e /a30f /a310 /a311 /a312 /a313 /a314 /a315 /a316 /a317 /a318 /a319 /a31a /a31b /a31c /a31d /a31e /a31f /a320 /a321 /a322 /a323 /a324 /a325 /a326 /a327 /a328 /a329 /a32a /a32b /a32c /a32d /a32e /a32f /a330 /a331 /a332 /a333 /a334 /a335 /a336 /a337 /a338 /a339 /a33a /a33b /a33c /a33d /a33e /a33f /a340 /a341 /a342 /a343 /a344 /a345 /a346 /a347 /a348 /a349 /a34a /a34b /a34c /a34d /a34e /a34f /a350 /a351 /a352 /a353 /a354 /a355 /a356 /a357 /a358 /a359 /a35a /a35b /a35c /a35d /a35e /a35f /a360 /a361 /a362 /a363 /a364 /a365 /a366 /a367 /a368 /a369 /a36a /a36b /a36c /a36d /a36e /a36f /a370 /a371 /a372 /a373 /a374 /a375 /a376 /a377 /a378 /a379 /a37a /a37b /a37c /a37d /a37e /a37f /a380 /a381 /a382 /a383 /a384 /a385 /a386 /a387 /a388 /a389 /a38a /a38b /a38c /a38d /a38e /a38f /a390 /a391 /a392 /a393 /a394 /a395 /a396 /a397 /a398 /a399 /a39a /a39b /a39c /a39d /a39e /a39f /a3a0 /a3a1 /a3a2 /a3a3 /a3a4 /a3a5 /a3a6 /a3a7 /a3a8 /a3a9 /a3aa /a3ab /a3ac /a3ad /a3ae /a3af /a3b0 /a3b1 /a3b2 /a3b3 /a3b4 /a3b5 /a3b6 /a3b7 /a3b8 /a3b9 /a3ba /a3bb /a3bc /a3bd /a3be /a3bf /a3c0 /a3c1 /a3c2 /a3c3 /a3c4 /a3c5 /a3c6 /a3c7 /a3c8 /a3c9 /a3ca /a3cb /a3cc /a3cd /a3ce /a3cf /a3d0 /a3d1 /a3d2 /a3d3 /a3d4 /a3d5 /a3d6 /a3d7 /a3d8 /a3d9 /a3da /a3db /a3dc /a3dd /a3de /a3df /a3e0 /a3e1 /a3e2 /a3e3 /a3e4 /a3e5 /a3e6 /a3e7 -/a3e8 /a3e9 /a3ea /a3eb /a3ec /a3ed /a3ee /a3ef /a3f0 /a3f1 /a3f2 /a3f3 /a3f4 /a3f5 /a3f6 /a3f7 /a3f8 /a3f9 /a3fa /a3fb /a3fc /a3fd /a3fe /a3ff /a400 /a401 /a402 /a403 /a404 /a405 /a406 /a407 /a408 /a409 /a40a /a40b /a40c /a40d /a40e /a40f /a410 /a411 /a412 /a413 /a414 /a415 /a416 /a417 /a418 /a419 /a41a /a41b /a41c /a41d /a41e /a41f /a420 /a421 /a422 /a423 /a424 /a425 /a426 /a427 /a428 /a429 /a42a /a42b /a42c /a42d /a42e /a42f /a430 /a431 /a432 /a433 /a434 /a435 /a436 /a437 /a438 /a439 /a43a /a43b /a43c /a43d /a43e /a43f /a440 /a441 /a442 /a443 /a444 /a445 /a446 /a447 /a448 /a449 /a44a /a44b /a44c /a44d /a44e /a44f /a450 /a451 /a452 /a453 /a454 /a455 /a456 /a457 /a458 /a459 /a45a /a45b /a45c /a45d /a45e /a45f /a460 /a461 /a462 /a463 /a464 /a465 /a466 /a467 /a468 /a469 /a46a /a46b /a46c /a46d /a46e /a46f /a470 /a471 /a472 /a473 /a474 /a475 /a476 /a477 /a478 /a479 /a47a /a47b /a47c /a47d /a47e /a47f /a480 /a481 /a482 /a483 /a484 /a485 /a486 /a487 /a488 /a489 /a48a /a48b /a48c /a48d /a48e /a48f /a490 /a491 /a492 /a493 /a494 /a495 /a496 /a497 /a498 /a499 /a49a /a49b /a49c /a49d /a49e /a49f /a4a0 /a4a1 /a4a2 /a4a3 /a4a4 /a4a5 /a4a6 /a4a7 /a4a8 /a4a9 /a4aa /a4ab /a4ac /a4ad /a4ae /a4af /a4b0 /a4b1 /a4b2 /a4b3 /a4b4 /a4b5 /a4b6 /a4b7 /a4b8 /a4b9 /a4ba /a4bb /a4bc /a4bd /a4be /a4bf /a4c0 /a4c1 /a4c2 /a4c3 /a4c4 /a4c5 /a4c6 /a4c7 /a4c8 /a4c9 /a4ca /a4cb /a4cc /a4cd /a4ce /a4cf /a4d0 /a4d1 /a4d2 /a4d3 /a4d4 /a4d5 /a4d6 /a4d7 /a4d8 /a4d9 /a4da /a4db /a4dc /a4dd /a4de /a4df /a4e0 /a4e1 /a4e2 /a4e3 /a4e4 /a4e5 /a4e6 /a4e7 /a4e8 /a4e9 /a4ea /a4eb /a4ec /a4ed /a4ee /a4ef /a4f0 /a4f1 /a4f2 /a4f3 /a4f4 /a4f5 /a4f6 /a4f7 /a4f8 /a4f9 /a4fa /a4fb /a4fc /a4fd /a4fe /a4ff /a500 /a501 /a502 /a503 /a504 /a505 /a506 /a507 /a508 /a509 /a50a /a50b /a50c /a50d /a50e /a50f /a510 /a511 /a512 /a513 /a514 /a515 /a516 /a517 /a518 /a519 /a51a /a51b /a51c /a51d /a51e /a51f /a520 /a521 /a522 /a523 /a524 /a525 /a526 /a527 /a528 /a529 /a52a /a52b /a52c /a52d /a52e /a52f /a530 /a531 /a532 /a533 /a534 /a535 /a536 /a537 /a538 /a539 /a53a /a53b /a53c /a53d /a53e /a53f /a540 /a541 /a542 /a543 /a544 /a545 /a546 /a547 /a548 /a549 /a54a /a54b /a54c /a54d /a54e /a54f /a550 /a551 /a552 /a553 /a554 /a555 /a556 /a557 /a558 /a559 /a55a /a55b /a55c /a55d /a55e /a55f /a560 /a561 /a562 /a563 /a564 /a565 /a566 /a567 /a568 /a569 /a56a /a56b /a56c /a56d /a56e /a56f /a570 /a571 /a572 /a573 /a574 /a575 /a576 /a577 /a578 /a579 /a57a /a57b /a57c /a57d /a57e /a57f /a580 /a581 /a582 /a583 /a584 /a585 /a586 /a587 /a588 /a589 /a58a /a58b /a58c /a58d /a58e /a58f /a590 /a591 /a592 /a593 /a594 /a595 /a596 /a597 /a598 /a599 /a59a /a59b /a59c /a59d /a59e /a59f /a5a0 /a5a1 /a5a2 /a5a3 /a5a4 /a5a5 /a5a6 /a5a7 /a5a8 /a5a9 /a5aa /a5ab /a5ac /a5ad /a5ae /a5af /a5b0 /a5b1 /a5b2 /a5b3 /a5b4 /a5b5 /a5b6 /a5b7 /a5b8 /a5b9 /a5ba /a5bb /a5bc /a5bd /a5be /a5bf /a5c0 /a5c1 /a5c2 /a5c3 /a5c4 /a5c5 /a5c6 /a5c7 /a5c8 /a5c9 /a5ca /a5cb /a5cc /a5cd /a5ce /a5cf /a5d0 /a5d1 /a5d2 /a5d3 /a5d4 /a5d5 /a5d6 /a5d7 /a5d8 /a5d9 /a5da /a5db /a5dc /a5dd /a5de /a5df /a5e0 /a5e1 /a5e2 /a5e3 /a5e4 /a5e5 /a5e6 /a5e7 /a5e8 /a5e9 /a5ea /a5eb /a5ec /a5ed /a5ee /a5ef /a5f0 /a5f1 /a5f2 /a5f3 /a5f4 /a5f5 /a5f6 /a5f7 /a5f8 /a5f9 /a5fa /a5fb /a5fc /a5fd /a5fe /a5ff /a600 /a601 /a602 /a603 /a604 /a605 /a606 /a607 /a608 /a609 /a60a /a60b /a60c /a60d /a60e /a60f /a610 /a611 /a612 /a613 /a614 /a615 /a616 /a617 /a618 /a619 /a61a /a61b /a61c /a61d /a61e /a61f /a620 /a621 /a622 /a623 /a624 /a625 /a626 /a627 /a628 /a629 /a62a /a62b /a62c /a62d /a62e /a62f /a630 /a631 /a632 /a633 /a634 /a635 /a636 /a637 /a638 /a639 /a63a /a63b /a63c /a63d /a63e /a63f /a640 /a641 /a642 /a643 /a644 /a645 /a646 /a647 /a648 /a649 /a64a /a64b /a64c /a64d /a64e /a64f /a650 /a651 /a652 /a653 /a654 /a655 /a656 /a657 /a658 /a659 /a65a /a65b /a65c /a65d /a65e /a65f /a660 /a661 /a662 /a663 /a664 /a665 /a666 /a667 /a668 /a669 /a66a /a66b /a66c /a66d /a66e /a66f /a670 /a671 /a672 /a673 /a674 /a675 /a676 /a677 /a678 /a679 /a67a /a67b /a67c /a67d /a67e /a67f /a680 /a681 /a682 /a683 /a684 /a685 /a686 /a687 /a688 /a689 /a68a /a68b /a68c /a68d /a68e /a68f /a690 /a691 /a692 /a693 /a694 /a695 /a696 /a697 /a698 /a699 /a69a /a69b /a69c /a69d /a69e /a69f /a6a0 /a6a1 /a6a2 /a6a3 /a6a4 /a6a5 /a6a6 /a6a7 /a6a8 /a6a9 /a6aa /a6ab /a6ac /a6ad /a6ae /a6af /a6b0 /a6b1 /a6b2 /a6b3 /a6b4 /a6b5 /a6b6 /a6b7 /a6b8 /a6b9 /a6ba /a6bb /a6bc /a6bd /a6be /a6bf /a6c0 /a6c1 /a6c2 /a6c3 /a6c4 /a6c5 /a6c6 /a6c7 /a6c8 /a6c9 /a6ca /a6cb /a6cc /a6cd /a6ce /a6cf /a6d0 /a6d1 /a6d2 /a6d3 /a6d4 /a6d5 /a6d6 /a6d7 /a6d8 /a6d9 /a6da /a6db /a6dc /a6dd /a6de /a6df /a6e0 /a6e1 /a6e2 /a6e3 /a6e4 /a6e5 /a6e6 /a6e7 /a6e8 /a6e9 /a6ea /a6eb /a6ec /a6ed /a6ee /a6ef /a6f0 /a6f1 /a6f2 /a6f3 /a6f4 /a6f5 /a6f6 /a6f7 /a6f8 /a6f9 /a6fa /a6fb /a6fc /a6fd /a6fe /a6ff /a700 /a701 /a702 /a703 /a704 /a705 /a706 /a707 /a708 /a709 /a70a /a70b /a70c /a70d /a70e /a70f /a710 /a711 /a712 /a713 /a714 /a715 /a716 /a717 /a718 /a719 /a71a /a71b /a71c /a71d /a71e /a71f /a720 /a721 /a722 /a723 /a724 /a725 /a726 /a727 /a728 /a729 /a72a /a72b /a72c /a72d /a72e /a72f /a730 /a731 /a732 /a733 /a734 /a735 /a736 /a737 /a738 /a739 /a73a /a73b /a73c /a73d /a73e /a73f /a740 /a741 /a742 /a743 /a744 /a745 /a746 /a747 /a748 /a749 /a74a /a74b /a74c /a74d /a74e /a74f /a750 /a751 /a752 /a753 /a754 /a755 /a756 /a757 /a758 /a759 /a75a /a75b /a75c /a75d /a75e /a75f /a760 /a761 /a762 /a763 /a764 /a765 /a766 /a767 /a768 /a769 /a76a /a76b /a76c /a76d /a76e /a76f /a770 /a771 /a772 /a773 /a774 /a775 /a776 /a777 /a778 /a779 /a77a /a77b /a77c /a77d /a77e /a77f /a780 /a781 /a782 /a783 /a784 /a785 /a786 /a787 /a788 /a789 /a78a /a78b /a78c /a78d /a78e /a78f /a790 /a791 /a792 /a793 /a794 /a795 /a796 /a797 /a798 /a799 /a79a /a79b /a79c /a79d /a79e /a79f /a7a0 /a7a1 /a7a2 /a7a3 /a7a4 /a7a5 /a7a6 /a7a7 /a7a8 /a7a9 /a7aa /a7ab /a7ac /a7ad /a7ae /a7af /a7b0 /a7b1 /a7b2 /a7b3 /a7b4 /a7b5 /a7b6 /a7b7 /a7b8 /a7b9 /a7ba /a7bb /a7bc /a7bd /a7be /a7bf /a7c0 /a7c1 /a7c2 /a7c3 /a7c4 /a7c5 /a7c6 /a7c7 /a7c8 /a7c9 /a7ca /a7cb /a7cc /a7cd /a7ce /a7cf -/a7d0 /a7d1 /a7d2 /a7d3 /a7d4 /a7d5 /a7d6 /a7d7 /a7d8 /a7d9 /a7da /a7db /a7dc /a7dd /a7de /a7df /a7e0 /a7e1 /a7e2 /a7e3 /a7e4 /a7e5 /a7e6 /a7e7 /a7e8 /a7e9 /a7ea /a7eb /a7ec /a7ed /a7ee /a7ef /a7f0 /a7f1 /a7f2 /a7f3 /a7f4 /a7f5 /a7f6 /a7f7 /a7f8 /a7f9 /a7fa /a7fb /a7fc /a7fd /a7fe /a7ff /a800 /a801 /a802 /a803 /a804 /a805 /a806 /a807 /a808 /a809 /a80a /a80b /a80c /a80d /a80e /a80f /a810 /a811 /a812 /a813 /a814 /a815 /a816 /a817 /a818 /a819 /a81a /a81b /a81c /a81d /a81e /a81f /a820 /a821 /a822 /a823 /a824 /a825 /a826 /a827 /a828 /a829 /a82a /a82b /a82c /a82d /a82e /a82f /a830 /a831 /a832 /a833 /a834 /a835 /a836 /a837 /a838 /a839 /a83a /a83b /a83c /a83d /a83e /a83f /a840 /a841 /a842 /a843 /a844 /a845 /a846 /a847 /a848 /a849 /a84a /a84b /a84c /a84d /a84e /a84f /a850 /a851 /a852 /a853 /a854 /a855 /a856 /a857 /a858 /a859 /a85a /a85b /a85c /a85d /a85e /a85f /a860 /a861 /a862 /a863 /a864 /a865 /a866 /a867 /a868 /a869 /a86a /a86b /a86c /a86d /a86e /a86f /a870 /a871 /a872 /a873 /a874 /a875 /a876 /a877 /a878 /a879 /a87a /a87b /a87c /a87d /a87e /a87f /a880 /a881 /a882 /a883 /a884 /a885 /a886 /a887 /a888 /a889 /a88a /a88b /a88c /a88d /a88e /a88f /a890 /a891 /a892 /a893 /a894 /a895 /a896 /a897 /a898 /a899 /a89a /a89b /a89c /a89d /a89e /a89f /a8a0 /a8a1 /a8a2 /a8a3 /a8a4 /a8a5 /a8a6 /a8a7 /a8a8 /a8a9 /a8aa /a8ab /a8ac /a8ad /a8ae /a8af /a8b0 /a8b1 /a8b2 /a8b3 /a8b4 /a8b5 /a8b6 /a8b7 /a8b8 /a8b9 /a8ba /a8bb /a8bc /a8bd /a8be /a8bf /a8c0 /a8c1 /a8c2 /a8c3 /a8c4 /a8c5 /a8c6 /a8c7 /a8c8 /a8c9 /a8ca /a8cb /a8cc /a8cd /a8ce /a8cf /a8d0 /a8d1 /a8d2 /a8d3 /a8d4 /a8d5 /a8d6 /a8d7 /a8d8 /a8d9 /a8da /a8db /a8dc /a8dd /a8de /a8df /a8e0 /a8e1 /a8e2 /a8e3 /a8e4 /a8e5 /a8e6 /a8e7 /a8e8 /a8e9 /a8ea /a8eb /a8ec /a8ed /a8ee /a8ef /a8f0 /a8f1 /a8f2 /a8f3 /a8f4 /a8f5 /a8f6 /a8f7 /a8f8 /a8f9 /a8fa /a8fb /a8fc /a8fd /a8fe /a8ff /a900 /a901 /a902 /a903 /a904 /a905 /a906 /a907 /a908 /a909 /a90a /a90b /a90c /a90d /a90e /a90f /a910 /a911 /a912 /a913 /a914 /a915 /a916 /a917 /a918 /a919 /a91a /a91b /a91c /a91d /a91e /a91f /a920 /a921 /a922 /a923 /a924 /a925 /a926 /a927 /a928 /a929 /a92a /a92b /a92c /a92d /a92e /a92f /a930 /a931 /a932 /a933 /a934 /a935 /a936 /a937 /a938 /a939 /a93a /a93b /a93c /a93d /a93e /a93f /a940 /a941 /a942 /a943 /a944 /a945 /a946 /a947 /a948 /a949 /a94a /a94b /a94c /a94d /a94e /a94f /a950 /a951 /a952 /a953 /a954 /a955 /a956 /a957 /a958 /a959 /a95a /a95b /a95c /a95d /a95e /a95f /a960 /a961 /a962 /a963 /a964 /a965 /a966 /a967 /a968 /a969 /a96a /a96b /a96c /a96d /a96e /a96f /a970 /a971 /a972 /a973 /a974 /a975 /a976 /a977 /a978 /a979 /a97a /a97b /a97c /a97d /a97e /a97f /a980 /a981 /a982 /a983 /a984 /a985 /a986 /a987 /a988 /a989 /a98a /a98b /a98c /a98d /a98e /a98f /a990 /a991 /a992 /a993 /a994 /a995 /a996 /a997 /a998 /a999 /a99a /a99b /a99c /a99d /a99e /a99f /a9a0 /a9a1 /a9a2 /a9a3 /a9a4 /a9a5 /a9a6 /a9a7 /a9a8 /a9a9 /a9aa /a9ab /a9ac /a9ad /a9ae /a9af /a9b0 /a9b1 /a9b2 /a9b3 /a9b4 /a9b5 /a9b6 /a9b7 /a9b8 /a9b9 /a9ba /a9bb /a9bc /a9bd /a9be /a9bf /a9c0 /a9c1 /a9c2 /a9c3 /a9c4 /a9c5 /a9c6 /a9c7 /a9c8 /a9c9 /a9ca /a9cb /a9cc /a9cd /a9ce /a9cf /a9d0 /a9d1 /a9d2 /a9d3 /a9d4 /a9d5 /a9d6 /a9d7 /a9d8 /a9d9 /a9da /a9db /a9dc /a9dd /a9de /a9df /a9e0 /a9e1 /a9e2 /a9e3 /a9e4 /a9e5 /a9e6 /a9e7 /a9e8 /a9e9 /a9ea /a9eb /a9ec /a9ed /a9ee /a9ef /a9f0 /a9f1 /a9f2 /a9f3 /a9f4 /a9f5 /a9f6 /a9f7 /a9f8 /a9f9 /a9fa /a9fb /a9fc /a9fd /a9fe /a9ff /aa00 /aa01 /aa02 /aa03 /aa04 /aa05 /aa06 /aa07 /aa08 /aa09 /aa0a /aa0b /aa0c /aa0d /aa0e /aa0f /aa10 /aa11 /aa12 /aa13 /aa14 /aa15 /aa16 /aa17 /aa18 /aa19 /aa1a /aa1b /aa1c /aa1d /aa1e /aa1f /aa20 /aa21 /aa22 /aa23 /aa24 /aa25 /aa26 /aa27 /aa28 /aa29 /aa2a /aa2b /aa2c /aa2d /aa2e /aa2f /aa30 /aa31 /aa32 /aa33 /aa34 /aa35 /aa36 /aa37 /aa38 /aa39 /aa3a /aa3b /aa3c /aa3d /aa3e /aa3f /aa40 /aa41 /aa42 /aa43 /aa44 /aa45 /aa46 /aa47 /aa48 /aa49 /aa4a /aa4b /aa4c /aa4d /aa4e /aa4f /aa50 /aa51 /aa52 /aa53 /aa54 /aa55 /aa56 /aa57 /aa58 /aa59 /aa5a /aa5b /aa5c /aa5d /aa5e /aa5f /aa60 /aa61 /aa62 /aa63 /aa64 /aa65 /aa66 /aa67 /aa68 /aa69 /aa6a /aa6b /aa6c /aa6d /aa6e /aa6f /aa70 /aa71 /aa72 /aa73 /aa74 /aa75 /aa76 /aa77 /aa78 /aa79 /aa7a /aa7b /aa7c /aa7d /aa7e /aa7f /aa80 /aa81 /aa82 /aa83 /aa84 /aa85 /aa86 /aa87 /aa88 /aa89 /aa8a /aa8b /aa8c /aa8d /aa8e /aa8f /aa90 /aa91 /aa92 /aa93 /aa94 /aa95 /aa96 /aa97 /aa98 /aa99 /aa9a /aa9b /aa9c /aa9d /aa9e /aa9f /aaa0 /aaa1 /aaa2 /aaa3 /aaa4 /aaa5 /aaa6 /aaa7 /aaa8 /aaa9 /aaaa /aaab /aaac /aaad /aaae /aaaf /aab0 /aab1 /aab2 /aab3 /aab4 /aab5 /aab6 /aab7 /aab8 /aab9 /aaba /aabb /aabc /aabd /aabe /aabf /aac0 /aac1 /aac2 /aac3 /aac4 /aac5 /aac6 /aac7 /aac8 /aac9 /aaca /aacb /aacc /aacd /aace /aacf /aad0 /aad1 /aad2 /aad3 /aad4 /aad5 /aad6 /aad7 /aad8 /aad9 /aada /aadb /aadc /aadd /aade /aadf /aae0 /aae1 /aae2 /aae3 /aae4 /aae5 /aae6 /aae7 /aae8 /aae9 /aaea /aaeb /aaec /aaed /aaee /aaef /aaf0 /aaf1 /aaf2 /aaf3 /aaf4 /aaf5 /aaf6 /aaf7 /aaf8 /aaf9 /aafa /aafb /aafc /aafd /aafe /aaff /ab00 /ab01 /ab02 /ab03 /ab04 /ab05 /ab06 /ab07 /ab08 /ab09 /ab0a /ab0b /ab0c /ab0d /ab0e /ab0f /ab10 /ab11 /ab12 /ab13 /ab14 /ab15 /ab16 /ab17 /ab18 /ab19 /ab1a /ab1b /ab1c /ab1d /ab1e /ab1f /ab20 /ab21 /ab22 /ab23 /ab24 /ab25 /ab26 /ab27 /ab28 /ab29 /ab2a /ab2b /ab2c /ab2d /ab2e /ab2f /ab30 /ab31 /ab32 /ab33 /ab34 /ab35 /ab36 /ab37 /ab38 /ab39 /ab3a /ab3b /ab3c /ab3d /ab3e /ab3f /ab40 /ab41 /ab42 /ab43 /ab44 /ab45 /ab46 /ab47 /ab48 /ab49 /ab4a /ab4b /ab4c /ab4d /ab4e /ab4f /ab50 /ab51 /ab52 /ab53 /ab54 /ab55 /ab56 /ab57 /ab58 /ab59 /ab5a /ab5b /ab5c /ab5d /ab5e /ab5f /ab60 /ab61 /ab62 /ab63 /ab64 /ab65 /ab66 /ab67 /ab68 /ab69 /ab6a /ab6b /ab6c /ab6d /ab6e /ab6f /ab70 /ab71 /ab72 /ab73 /ab74 /ab75 /ab76 /ab77 /ab78 /ab79 /ab7a /ab7b /ab7c /ab7d /ab7e /ab7f /ab80 /ab81 /ab82 /ab83 /ab84 /ab85 /ab86 /ab87 /ab88 /ab89 /ab8a /ab8b /ab8c /ab8d /ab8e /ab8f /ab90 /ab91 /ab92 /ab93 /ab94 /ab95 /ab96 /ab97 /ab98 /ab99 /ab9a /ab9b /ab9c /ab9d /ab9e /ab9f /aba0 /aba1 /aba2 /aba3 /aba4 /aba5 /aba6 /aba7 /aba8 /aba9 /abaa /abab /abac /abad /abae /abaf /abb0 /abb1 /abb2 /abb3 /abb4 /abb5 /abb6 /abb7 -/abb8 /abb9 /abba /abbb /abbc /abbd /abbe /abbf /abc0 /abc1 /abc2 /abc3 /abc4 /abc5 /abc6 /abc7 /abc8 /abc9 /abca /abcb /abcc /abcd /abce /abcf /abd0 /abd1 /abd2 /abd3 /abd4 /abd5 /abd6 /abd7 /abd8 /abd9 /abda /abdb /abdc /abdd /abde /abdf /abe0 /abe1 /abe2 /abe3 /abe4 /abe5 /abe6 /abe7 /abe8 /abe9 /abea /abeb /abec /abed /abee /abef /abf0 /abf1 /abf2 /abf3 /abf4 /abf5 /abf6 /abf7 /abf8 /abf9 /abfa /abfb /abfc /abfd /abfe /abff /ac00 /ac01 /ac02 /ac03 /ac04 /ac05 /ac06 /ac07 /ac08 /ac09 /ac0a /ac0b /ac0c /ac0d /ac0e /ac0f /ac10 /ac11 /ac12 /ac13 /ac14 /ac15 /ac16 /ac17 /ac18 /ac19 /ac1a /ac1b /ac1c /ac1d /ac1e /ac1f /ac20 /ac21 /ac22 /ac23 /ac24 /ac25 /ac26 /ac27 /ac28 /ac29 /ac2a /ac2b /ac2c /ac2d /ac2e /ac2f /ac30 /ac31 /ac32 /ac33 /ac34 /ac35 /ac36 /ac37 /ac38 /ac39 /ac3a /ac3b /ac3c /ac3d /ac3e /ac3f /ac40 /ac41 /ac42 /ac43 /ac44 /ac45 /ac46 /ac47 /ac48 /ac49 /ac4a /ac4b /ac4c /ac4d /ac4e /ac4f /ac50 /ac51 /ac52 /ac53 /ac54 /ac55 /ac56 /ac57 /ac58 /ac59 /ac5a /ac5b /ac5c /ac5d /ac5e /ac5f /ac60 /ac61 /ac62 /ac63 /ac64 /ac65 /ac66 /ac67 /ac68 /ac69 /ac6a /ac6b /ac6c /ac6d /ac6e /ac6f /ac70 /ac71 /ac72 /ac73 /ac74 /ac75 /ac76 /ac77 /ac78 /ac79 /ac7a /ac7b /ac7c /ac7d /ac7e /ac7f /ac80 /ac81 /ac82 /ac83 /ac84 /ac85 /ac86 /ac87 /ac88 /ac89 /ac8a /ac8b /ac8c /ac8d /ac8e /ac8f /ac90 /ac91 /ac92 /ac93 /ac94 /ac95 /ac96 /ac97 /ac98 /ac99 /ac9a /ac9b /ac9c /ac9d /ac9e /ac9f /aca0 /aca1 /aca2 /aca3 /aca4 /aca5 /aca6 /aca7 /aca8 /aca9 /acaa /acab /acac /acad /acae /acaf /acb0 /acb1 /acb2 /acb3 /acb4 /acb5 /acb6 /acb7 /acb8 /acb9 /acba /acbb /acbc /acbd /acbe /acbf /acc0 /acc1 /acc2 /acc3 /acc4 /acc5 /acc6 /acc7 /acc8 /acc9 /acca /accb /accc -] /DeviceRGB 10 0 R] - /BitsPerComponent 16 - /Filter [/ASCIIHexDecode /FlateDecode /RunLengthDecode] ->> -stream -789cecc101010000008090ed3def080a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080db8303020000000021ff5f3724000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009c05dff2c7ae -endstream -endobj - -10 0 obj -<< - /FunctionType 2 - /Domain [0.0 1.0 0.0 1.0] - /C0 [0.0 0.0] - /C1 [1.0 1.0] - /N 1 ->> -endobj - -xref -0 11 -0000000000 65535 f -0000000016 00000 n -0000000053 00000 n -0000000093 00000 n -0000000000 65535 f -0000000221 00000 n -0000000152 00000 n -0000000278 00000 n -0000000000 65535 f -0000000000 65535 f -0000036227 00000 n -trailer << - /Root 1 0 R - /Size 11 ->> -startxref -36335 -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_557223.in b/chromium/third_party/pdfium/testing/resources/bug_557223.in Binary files differdeleted file mode 100644 index 78f590d9349..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_557223.in +++ /dev/null diff --git a/chromium/third_party/pdfium/testing/resources/bug_557223.pdf b/chromium/third_party/pdfium/testing/resources/bug_557223.pdf Binary files differdeleted file mode 100644 index e80805a996a..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_557223.pdf +++ /dev/null diff --git a/chromium/third_party/pdfium/testing/resources/bug_57.in b/chromium/third_party/pdfium/testing/resources/bug_57.in deleted file mode 100644 index 0825efdfa87..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_57.in +++ /dev/null @@ -1,48 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R ->> -{{object 2 0}} << - /Type /Pages - /MediaBox [ 0 0 200 200 ] - /Count 1 - /Kids [ 3 0 R ] ->> -endobj -{{object 3 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font << - /F1 4 0 R - >> - >> - /Contents 5 0 R ->> -endobj -{{object 4 0}} << - /Type /Font - /Subtype /Type1 - /BaseFont /Times-Roman ->> -endobj -% page content with streamlength past end-of-file. -{{object 5 0}} << - /Length 9999 ->> -stream -BT -70 50 TD -/F1 12 Tf -(Hello, world!) Tj -ET -endstream -endobj -{{xref}} -trailer << - /Size 6 - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_57.pdf b/chromium/third_party/pdfium/testing/resources/bug_57.pdf deleted file mode 100644 index 0c3f7dfdab1..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_57.pdf +++ /dev/null @@ -1,57 +0,0 @@ -%PDF-1.7 -% ò¤ô -1 0 obj << - /Type /Catalog - /Pages 2 0 R ->> -2 0 obj << - /Type /Pages - /MediaBox [ 0 0 200 200 ] - /Count 1 - /Kids [ 3 0 R ] ->> -endobj -3 0 obj << - /Type /Page - /Parent 2 0 R - /Resources << - /Font << - /F1 4 0 R - >> - >> - /Contents 5 0 R ->> -endobj -4 0 obj << - /Type /Font - /Subtype /Type1 - /BaseFont /Times-Roman ->> -endobj -% page content with streamlength past end-of-file. -5 0 obj << - /Length 9999 ->> -stream -BT -70 50 TD -/F1 12 Tf -(Hello, world!) Tj -ET -endstream -endobj -xref -0 6 -0000000000 65535 f -0000000015 00000 n -0000000061 00000 n -0000000154 00000 n -0000000280 00000 n -0000000409 00000 n -trailer << - /Size 6 - /Root 1 0 R ->> -startxref -506 -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_572871.in b/chromium/third_party/pdfium/testing/resources/bug_572871.in deleted file mode 100644 index 20cb94394e6..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_572871.in +++ /dev/null @@ -1,96 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R - /AcroForm 3 0 R - /AA 11 0 R ->> -endobj -{{object 2 0}} << - /Type /Pages - /Count 3 - /Kids [4 0 R 5 0 R 6 0 R ] ->> -endobj -{{object 3 0}} << - /CO [9 0 R] - /Fields [9 0 R 7 0 R] ->> -endobj -{{object 4 0}} << - /Type /Page - /Parent 2 0 R - /MediaBox [0 0 612 792] - /Resources <<>> ->> -endobj -{{object 5 0}} << - /Type /Page - /Parent 2 0 R - /MediaBox [0 0 612 792] - /Resources <<>> ->> -endobj -{{object 6 0}} << - /Type /Page - /Parent 2 0 R - /MediaBox [0 0 612 792] - /Resources <<>> - /Annots [7 0 R 9 0 R] ->> -endobj -{{object 7 0}} << - /FT /Tx - /Type /Annot - /Subtype /Widget - /T (txtName2) - /F 4 - /AP <</N 8 0 R>> - /Rect [20 20 400 60] ->> -endobj -{{object 8 0}} << - /Type /XObject - /Subtype /Form - /FormType 1 ->> -endobj -{{object 9 0}} << - /FT /Tx - /Type /Annot - /Subtype /Widget - /T (txtName1) - /F 4 - /AP <</N 10 0 R>> - /Rect [200 200 400 260] ->> -endobj -{{object 10 0}} << - /Type /XObject - /Subtype /Form - /FormType 1 ->> -endobj -{{object 11 0}} << - /WC 12 0 R ->> -endobj -{{object 12 0}} << - /Type /Action - /S /JavaScript - /JS 13 0 R ->> -endobj -{{object 13 0}} <<>> -stream -t = this.getField('txtName2'); -t.setFocus(); -endstream -endobj -{{xref}} -trailer << - /Size 14 - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_572871.pdf b/chromium/third_party/pdfium/testing/resources/bug_572871.pdf deleted file mode 100644 index 1f26bc56a28..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_572871.pdf +++ /dev/null @@ -1,113 +0,0 @@ -%PDF-1.7 -% ò¤ô -1 0 obj << - /Type /Catalog - /Pages 2 0 R - /AcroForm 3 0 R - /AA 11 0 R ->> -endobj -2 0 obj << - /Type /Pages - /Count 3 - /Kids [4 0 R 5 0 R 6 0 R ] ->> -endobj -3 0 obj << - /CO [9 0 R] - /Fields [9 0 R 7 0 R] ->> -endobj -4 0 obj << - /Type /Page - /Parent 2 0 R - /MediaBox [0 0 612 792] - /Resources <<>> ->> -endobj -5 0 obj << - /Type /Page - /Parent 2 0 R - /MediaBox [0 0 612 792] - /Resources <<>> ->> -endobj -6 0 obj << - /Type /Page - /Parent 2 0 R - /MediaBox [0 0 612 792] - /Resources <<>> - /Annots [7 0 R 9 0 R] ->> -endobj -7 0 obj << - /FT /Tx - /Type /Annot - /Subtype /Widget - /T (txtName2) - /F 4 - /AP <</N 8 0 R>> - /Rect [20 20 400 60] ->> -endobj -8 0 obj << - /Type /XObject - /Subtype /Form - /FormType 1 ->> -endobj -9 0 obj << - /FT /Tx - /Type /Annot - /Subtype /Widget - /T (txtName1) - /F 4 - /AP <</N 10 0 R>> - /Rect [200 200 400 260] ->> -endobj -10 0 obj << - /Type /XObject - /Subtype /Form - /FormType 1 ->> -endobj -11 0 obj << - /WC 12 0 R ->> -endobj -12 0 obj << - /Type /Action - /S /JavaScript - /JS 13 0 R ->> -endobj -13 0 obj <<>> -stream -t = this.getField('txtName2'); -t.setFocus(); -endstream -endobj -xref -0 14 -0000000000 65535 f -0000000015 00000 n -0000000099 00000 n -0000000175 00000 n -0000000234 00000 n -0000000329 00000 n -0000000424 00000 n -0000000543 00000 n -0000000673 00000 n -0000000742 00000 n -0000000876 00000 n -0000000946 00000 n -0000000981 00000 n -0000001049 00000 n -trailer << - /Size 14 - /Root 1 0 R ->> -startxref -1132 -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_583.pdf b/chromium/third_party/pdfium/testing/resources/bug_583.pdf deleted file mode 100644 index fcb30d4c2a7..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_583.pdf +++ /dev/null @@ -1,216 +0,0 @@ -%PDF-1.4 -%Óëéá -1 0 obj -<</Title (skbug_5606_b) -/Subject (rendering correctness test) -/Creator (Skia/DM) -/Producer (Skia/PDF m55)>> -endobj -2 0 obj -<</Length 117>> stream -1 0 0 -1 0 48 cm -1 1 1 RG 1 1 1 rg -/G0 gs -0 0 48 48 re -f -0 0 0 RG 0 0 0 rg -BT -/F0 18 Tf -1 0 0 -1 16 32 Tm -<01> Tj -ET - -endstream -endobj -3 0 obj -<</Type /Catalog -/Pages 4 0 R>> -endobj -4 0 obj -<</Type /Pages -/Count 1 -/Kids [5 0 R]>> -endobj -5 0 obj -<</Type /Page -/Resources <</ProcSets [/PDF /Text /ImageB /ImageC /ImageI] -/ExtGState <</G0 6 0 R>> -/Font <</F0 7 0 R>>>> -/MediaBox [0 0 48 48] -/Contents 2 0 R -/Parent 4 0 R>> -endobj -6 0 obj -<</Type /ExtGState -/Type /ExtGState -/CA 1 -/ca 1 -/LC 0 -/LJ 0 -/LW 0 -/ML 4 -/SA true -/BM /Normal>> -endobj -7 0 obj -<</Type /Font -/Subtype /Type3 -/FontMatrix [.00100000005 0 0 -.00100000005 0 0] -/FirstChar 0 -/LastChar 1 -/FontBBox [0 40 640 -740] -/CIDToGIDMap /Identity -/ToUnicode 8 0 R -/Widths [500 640] -/Encoding <</Type /Encoding -/Differences [0 /g0 /g100]>> -/CharProcs <</g0 9 0 R -/g100 10 0 R>>>> -endobj -8 0 obj -<</Length 338>> stream -/CIDInit /ProcSet findresource begin -12 dict begin -begincmap -/CIDSystemInfo -<< /Registry (Adobe) -/Ordering (UCS) -/Supplement 0 ->> def -/CMapName /Adobe-Identity-UCS def -/CMapType 2 def -1 begincodespacerange -<0001> <0001> -endcodespacerange -1 beginbfchar -<0001> <0000> -endbfchar -endcmap -CMapName currentdict /CMap defineresource pop -end -end -endstream -endobj -9 0 obj -<</Length 0>> stream - -endstream -endobj -10 0 obj -<</Length 938>> stream -640 0 0 -740 640 40 d1 -640 -150 m -640 -660 l -520 -660 l -320 -610 l -390 -655 l -390 -710 l -360 -740 l -300 -740 l -260 -700 l -260 -670 l -280 -650 l -300 -650 l -290 -670 l -300 -690 l -320 -700 l -340 -700 l -350 -680 l -340 -660 l -300 -620 l -240 -590 l -40 -540 l -20 -540 l -0 -550 l -0 -40 l -120 -40 l -320 -90 l -250 -45 l -250 10 l -280 40 l -340 40 l -380 0 l -380 -30 l -360 -50 l -340 -50 l -350 -30 l -340 -10 l -320 0 l -300 0 l -290 -20 l -300 -40 l -340 -80 l -400 -110 l -600 -160 l -620 -160 l -640 -150 l -h -600 -620 m -40 -480 l -40 -500 l -560 -630 l -600 -630 l -600 -620 l -h -541 -567 m -530 -525 l -530 -240 l -471 -225 l -375 -373 l -367 -394 l -370 -371 l -370 -238 l -380 -203 l -284 -179 l -295 -219 l -295 -468 l -282 -502 l -375 -526 l -451 -408 l -460 -387 l -457 -410 l -457 -506 l -445 -543 l -541 -567 l -h -600 -200 m -80 -70 l -40 -70 l -40 -80 l -600 -220 l -600 -200 l -h -206 -159 m -99 -132 l -110 -172 l -110 -421 l -99 -456 l -206 -483 l -195 -444 l -195 -193 l -206 -159 l -h -f - -endstream -endobj -xref -0 11 -0000000000 65535 f -0000000015 00000 n -0000000138 00000 n -0000000304 00000 n -0000000351 00000 n -0000000406 00000 n -0000000596 00000 n -0000000706 00000 n -0000001006 00000 n -0000001393 00000 n -0000001440 00000 n -trailer -<</Size 11 -/Root 3 0 R -/Info 1 0 R>> -startxref -2428 -%%EOF
\ No newline at end of file diff --git a/chromium/third_party/pdfium/testing/resources/bug_601362.pdf b/chromium/third_party/pdfium/testing/resources/bug_601362.pdf deleted file mode 100644 index d21a83405ea..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_601362.pdf +++ /dev/null @@ -1,105 +0,0 @@ -%PDF-1.5 -%¿÷¢þ -1 0 obj -<< /Lang (en-US) /MarkInfo << /Marked true >> /Pages 3 0 R /Type /Catalog >> -endobj -2 0 obj -<< /CreationDate (D:20160411190039+00'00') /Creator (Microsoft Word) /ModDate (D:20160411190039+00'00') >> -endobj -3 0 obj -<< /Count 1 /Kids [ 4 0 R ] /Type /Pages >> -endobj -4 0 obj -<< /Contents 5 0 R /Group << /CS /DeviceRGB /S /Transparency /Type /Group >> /MediaBox [ 0 0 612 792 ] /Parent 3 0 R /Resources << /ExtGState << /GS7 6 0 R /GS8 7 0 R >> /Font << /F1 8 0 R /F2 9 0 R >> /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] >> /StructParents 0 /Tabs /S /Type /Page >> -endobj -5 0 obj -<< /Length 464 >> -stream - /P <</MCID 0>> BDC q -0.00000912 0 612 792 re -W* n -BT -/F1 11 Tf -1 0 0 1 72.025 709.72 Tm -/GS7 gs -0 g -/GS8 gs -0 G -[(T)10(est)] TJ -ET -Q -q -0.00000912 0 612 792 re -W* n -BT -/F2 11 Tf -1 0 0 1 90.8 709.72 Tm -0 g -0 G -[( )] TJ -ET -Q -q -0.00000912 0 612 792 re -W* n -BT -/F2 11 Tf -1 0 0 1 93.3 709.72 Tm -0 g -0 G -[(f)10(il)5(e.)] TJ -ET -Q -q -0.00000912 0 612 792 re -W* n -BT -/F1 11 Tf -1 0 0 1 109.8 709.72 Tm -0 g -0 G -[( )] TJ -ET -Q - EMC endstream -endobj -6 0 obj -<< /BM /Normal /Type /ExtGState /ca 1 >> -endobj -7 0 obj -<< /BM /Normal /CA 1 /Type /ExtGState >> -endobj -8 0 obj -<< /BaseFont /ABCDEE+Calibri /Encoding /WinAnsiEncoding /FirstChar 32 /FontDescriptor 10 0 R /LastChar 116 /Name /F1 /Subtype /TrueType /Type /Font /Widths 11 0 R >> -endobj -9 0 obj -<< /BaseFont /ABCDEE+Calibri,Italic /Encoding /WinAnsiEncoding /FirstChar 32 /FontDescriptor 12 0 R /LastChar 108 /Name /F2 /Subtype /TrueType /Type /Font >> -endobj -10 0 obj -<< /Ascent 750 /AvgWidth 521 /CapHeight 750 /Descent -250 /Flags 32 /FontBBox [ -503 -250 1240 750 ] /FontName /ABCDEE+Calibri /FontWeight 400 /ItalicAngle 0 /MaxWidth 1743 /StemV 52 /Type /FontDescriptor /XHeight 250 >> -endobj -11 0 obj -[ 226 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 487 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 498 0 0 0 0 0 0 0 0 0 0 0 0 0 391 335 ] -endobj -12 0 obj -<< /Ascent 750 /AvgWidth 521 /CapHeight 750 /Descent -250 /Flags 32 /FontBBox [ -725 -250 1260 750 ] /FontName /ABCDEE+Calibri,Italic /FontWeight 400 /ItalicAngle 2147483649 /MaxWidth 1984 /StemV 52 /Type /FontDescriptor /XHeight 250 >> -endobj -xref -0 13 -0000000000 65535 f -0000000015 00000 n -0000000107 00000 n -0000000229 00000 n -0000000288 00000 n -0000000597 00000 n -0000001111 00000 n -0000001167 00000 n -0000001223 00000 n -0000001404 00000 n -0000001577 00000 n -0000001814 00000 n -0000002014 00000 n -trailer << /Info 2 0 R /Root 1 0 R /Size 13 /ID [<205a1ea7cf6e0a45ac68694d38f6b9f7><32b8937a599b7da08d5dc591fd416f1b>] >> -startxref -2267 -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_602650.pdf b/chromium/third_party/pdfium/testing/resources/bug_602650.pdf deleted file mode 100644 index fc915f3e80b..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_602650.pdf +++ /dev/null @@ -1,105 +0,0 @@ -%PDF-1.3 -% ò¤ô -1 0 obj << - /Type /Font - /Subtype /Type1 - /BaseFont /Times-Roman ->> -endobj -2 0 obj << - /Type /Font - /Subtype /Type1 - /BaseFont /Helvetica ->> -endobj -3 0 obj << ->> -stream -BT -20 50 Td -/F1 12 Tf -(Hello, world!) Tj -0 50 Td -/F2 16 Tf -(Goodbye, world!) Tj -ET -endstream -endobj -4 0 obj << - /Type /Catalog - /Pages 5 0 R ->> -5 0 obj << - /Type /Pages - /MediaBox [ 0 0 200 200 ] - /Count 1 - /Kids [ 6 0 R ] ->> -endobj -6 0 obj << - /Type /Page - /Parent 5 0 R - /Resources << - /Font << - /F1 1 0 R - /F2 2 0 R - >> - >> - /Contents 3 0 R ->> -endobj -xref -1 7 -0000000000 65535 f -0000000015 00000 n -0000000093 00000 n -0000000169 00000 n -0000000290 00000 n -0000000336 00000 n -0000000429 00000 n -trailer << - /Size 7 - /Root 4 0 R ->> -startxref -571 -%%EOF -4 0 obj << - /Type /Catalog - /Pages 5 0 R ->> -endobj -5 0 obj << - /Type /Pages - /MediaBox [ 1 1 250 250 ] - /Count 1 - /Kids [ 6 0 R ] ->> -endobj -6 0 obj << - /Type /Page - /Parent 5 0 R - /Resources << - /Font << - /F1 1 0 R - /F2 2 0 R - >> - >> - /Contents 3 0 R ->> -endobj -xref -0 1 -0000000000 65535 f -4 3 -0000000778 00000 n -0000000831 00000 n -0000000924 00000 n -trailer << - /Size 7 - /Root 4 0 R - /Prev 571 ->> -startxref -1066 -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_603518.pdf b/chromium/third_party/pdfium/testing/resources/bug_603518.pdf Binary files differdeleted file mode 100644 index 1af6005e6cd..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_603518.pdf +++ /dev/null diff --git a/chromium/third_party/pdfium/testing/resources/bug_620428.in b/chromium/third_party/pdfium/testing/resources/bug_620428.in deleted file mode 100644 index 050488b1eea..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_620428.in +++ /dev/null @@ -1,99 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R - /AcroForm 6 0 R - /Names <</JavaScript 13 0 R>> ->> -endobj -{{object 2 0}} << - /Type /Pages - /Count 1 - /Kids [4 0 R] ->> -endobj -{{object 4 0}} << - /Type /Page - /Parent 2 0 R - /MediaBox [0 0 612 792] - /CropBox [0 0 612 792] - /Resources <<>> ->> -endobj -{{object 6 0}} << - /DR << - /Font <</Helv 7 0 R>> - >> - /DA (/Helv 0 Tf 0 g) - /Fields [5 0 R] ->> -endobj -{{object 7 0}} << - /Type /Font - /Subtype /Type1 - /BaseFont /Helvetica - /Encoding /WinAnsiEncoding ->> -endobj -{{object 8 0}} << - /Type /XObject - /Subtype /Form - /FormType 1 - /Matrix [1 0 0 1 0 0] - /BBox [0 0 75.907 28.472] - /Resources << - /Font <</FXF0 7 0 R>> - >> ->> -stream -q -Q - - -endstream -endobj -{{object 11 0}} << - /Type /Action - /S /JavaScript - /JS 50 0 R ->> -endobj -{{object 13 0}} << - /Names [(startDelay) 11 0 R] ->> -endobj -{{object 50 0}} << ->> -stream -function fireTimeOut() { - app.alert("hello world"); -} -function fireInterval() { - app.alert("goodbye world"); -} -var timer = app.setTimeOut("fireTimeOut()", 3000); -var interval = app.setInterval("fireInterval()", 1000); -// Clear timers before they fire. -app.clearTimeOut(timer); -app.clearInterval(interval); -// Check that clearing a cleared timer is ok. -app.clearTimeOut(timer); -app.clearInterval(interval); -// Check that invoking the wrong clear method is ok -var timer = app.setTimeOut("fireTimeOut()", 3000); -var interval = app.setInterval("fireInterval()", 1000); -app.clearTimeOut(interval); -app.clearInterval(timer); -// Check that clearing a non-timer is ok. -app.clearTimeOut({"size": 42}); -app.clearInterval({"size": 42}); -// Be sure all of this code ran to completion. -app.alert("done"); -endstream -endobj -{{xref}} -trailer << - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_620428.pdf b/chromium/third_party/pdfium/testing/resources/bug_620428.pdf deleted file mode 100644 index e53ed50e24b..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_620428.pdf +++ /dev/null @@ -1,153 +0,0 @@ -%PDF-1.7 -% ò¤ô -1 0 obj << - /Type /Catalog - /Pages 2 0 R - /AcroForm 6 0 R - /Names <</JavaScript 13 0 R>> ->> -endobj -2 0 obj << - /Type /Pages - /Count 1 - /Kids [4 0 R] ->> -endobj -4 0 obj << - /Type /Page - /Parent 2 0 R - /MediaBox [0 0 612 792] - /CropBox [0 0 612 792] - /Resources <<>> ->> -endobj -6 0 obj << - /DR << - /Font <</Helv 7 0 R>> - >> - /DA (/Helv 0 Tf 0 g) - /Fields [5 0 R] ->> -endobj -7 0 obj << - /Type /Font - /Subtype /Type1 - /BaseFont /Helvetica - /Encoding /WinAnsiEncoding ->> -endobj -8 0 obj << - /Type /XObject - /Subtype /Form - /FormType 1 - /Matrix [1 0 0 1 0 0] - /BBox [0 0 75.907 28.472] - /Resources << - /Font <</FXF0 7 0 R>> - >> ->> -stream -q -Q - - -endstream -endobj -11 0 obj << - /Type /Action - /S /JavaScript - /JS 50 0 R ->> -endobj -13 0 obj << - /Names [(startDelay) 11 0 R] ->> -endobj -50 0 obj << ->> -stream -function fireTimeOut() { - app.alert("hello world"); -} -function fireInterval() { - app.alert("goodbye world"); -} -var timer = app.setTimeOut("fireTimeOut()", 3000); -var interval = app.setInterval("fireInterval()", 1000); -// Clear timers before they fire. -app.clearTimeOut(timer); -app.clearInterval(interval); -// Check that clearing a cleared timer is ok. -app.clearTimeOut(timer); -app.clearInterval(interval); -// Check that invoking the wrong clear method is ok -var timer = app.setTimeOut("fireTimeOut()", 3000); -var interval = app.setInterval("fireInterval()", 1000); -app.clearTimeOut(interval); -app.clearInterval(timer); -// Check that clearing a non-timer is ok. -app.clearTimeOut({"size": 42}); -app.clearInterval({"size": 42}); -// Be sure all of this code ran to completion. -app.alert("done"); -endstream -endobj -xref -0 51 -0000000000 65535 f -0000000015 00000 n -0000000118 00000 n -0000000000 65535 f -0000000181 00000 n -0000000000 65535 f -0000000302 00000 n -0000000404 00000 n -0000000509 00000 n -0000000000 65535 f -0000000000 65535 f -0000000701 00000 n -0000000000 65535 f -0000000769 00000 n -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000822 00000 n -trailer << - /Root 1 0 R ->> -startxref -1655 -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_631912.pdf b/chromium/third_party/pdfium/testing/resources/bug_631912.pdf Binary files differdeleted file mode 100644 index cd68ea0a863..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_631912.pdf +++ /dev/null diff --git a/chromium/third_party/pdfium/testing/resources/bug_634394.in b/chromium/third_party/pdfium/testing/resources/bug_634394.in deleted file mode 100644 index 528b4637da3..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_634394.in +++ /dev/null @@ -1,85 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R - /AcroForm 6 0 R - /Names <</JavaScript 13 0 R>> ->> -endobj -{{object 2 0}} << - /Type /Pages - /Count 1 - /Kids [4 0 R] ->> -endobj -{{object 4 0}} << - /Type /Page - /Parent 2 0 R - /MediaBox [0 0 612 792] - /CropBox [0 0 612 792] - /Resources <<>> ->> -endobj -{{object 6 0}} << - /DR << - /Font <</Helv 7 0 R>> - >> - /DA (/Helv 0 Tf 0 g) - /Fields [5 0 R] ->> -endobj -{{object 7 0}} << - /Type /Font - /Subtype /Type1 - /BaseFont /Helvetica - /Encoding /WinAnsiEncoding ->> -endobj -{{object 8 0}} << - /Type /XObject - /Subtype /Form - /FormType 1 - /Matrix [1 0 0 1 0 0] - /BBox [0 0 75.907 28.472] - /Resources << - /Font <</FXF0 7 0 R>> - >> ->> -stream -q -Q - - -endstream -endobj -{{object 11 0}} << - /Type /Action - /S /JavaScript - /JS 50 0 R ->> -endobj -{{object 13 0}} << - /Names [(startDelay) 11 0 R] ->> -endobj -{{object 50 0}} << ->> -stream -var timer = app.setTimeOut("fireTimeOut()", 3000); -var interval = app.setInterval("fireInterval()", 1000); -function fireTimeOut() { - app.alert("goodbye world"); - app.clearInterval(interval); -} -function fireInterval() { - app.alert("hello world"); - app.clearInterval(interval); -} -endstream -endobj -{{xref}} -trailer << - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_634394.pdf b/chromium/third_party/pdfium/testing/resources/bug_634394.pdf deleted file mode 100644 index a17a9f213e5..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_634394.pdf +++ /dev/null @@ -1,139 +0,0 @@ -%PDF-1.7 -% ò¤ô -1 0 obj << - /Type /Catalog - /Pages 2 0 R - /AcroForm 6 0 R - /Names <</JavaScript 13 0 R>> ->> -endobj -2 0 obj << - /Type /Pages - /Count 1 - /Kids [4 0 R] ->> -endobj -4 0 obj << - /Type /Page - /Parent 2 0 R - /MediaBox [0 0 612 792] - /CropBox [0 0 612 792] - /Resources <<>> ->> -endobj -6 0 obj << - /DR << - /Font <</Helv 7 0 R>> - >> - /DA (/Helv 0 Tf 0 g) - /Fields [5 0 R] ->> -endobj -7 0 obj << - /Type /Font - /Subtype /Type1 - /BaseFont /Helvetica - /Encoding /WinAnsiEncoding ->> -endobj -8 0 obj << - /Type /XObject - /Subtype /Form - /FormType 1 - /Matrix [1 0 0 1 0 0] - /BBox [0 0 75.907 28.472] - /Resources << - /Font <</FXF0 7 0 R>> - >> ->> -stream -q -Q - - -endstream -endobj -11 0 obj << - /Type /Action - /S /JavaScript - /JS 50 0 R ->> -endobj -13 0 obj << - /Names [(startDelay) 11 0 R] ->> -endobj -50 0 obj << ->> -stream -var timer = app.setTimeOut("fireTimeOut()", 3000); -var interval = app.setInterval("fireInterval()", 1000); -function fireTimeOut() { - app.alert("goodbye world"); - app.clearInterval(interval); -} -function fireInterval() { - app.alert("hello world"); - app.clearInterval(interval); -} -endstream -endobj -xref -0 51 -0000000000 65535 f -0000000015 00000 n -0000000118 00000 n -0000000000 65535 f -0000000181 00000 n -0000000000 65535 f -0000000302 00000 n -0000000404 00000 n -0000000509 00000 n -0000000000 65535 f -0000000000 65535 f -0000000701 00000 n -0000000000 65535 f -0000000769 00000 n -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000822 00000 n -trailer << - /Root 1 0 R ->> -startxref -1143 -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_634716.in b/chromium/third_party/pdfium/testing/resources/bug_634716.in deleted file mode 100644 index a485daed973..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_634716.in +++ /dev/null @@ -1,126 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R - /AcroForm 6 0 R - /Names <</JavaScript 13 0 R>> ->> -endobj -{{object 2 0}} << - /Type /Pages - /Count 1 - /Kids [4 0 R] ->> -endobj -{{object 4 0}} << - /Type /Page - /Parent 2 0 R - /MediaBox [0 0 612 792] - /CropBox [0 0 612 792] - /Resources <<>> ->> -endobj -{{object 6 0}} << - /DR << - /Font <</Helv 7 0 R>> - >> - /DA (/Helv 0 Tf 0 g) - /Fields [5 0 R] ->> -endobj -{{object 7 0}} << - /Type /Font - /Subtype /Type1 - /BaseFont /Helvetica - /Encoding /WinAnsiEncoding ->> -endobj -{{object 8 0}} << - /Type /XObject - /Subtype /Form - /FormType 1 - /Matrix [1 0 0 1 0 0] - /BBox [0 0 75.907 28.472] - /Resources << - /Font <</FXF0 7 0 R>> - >> ->> -stream -q -Q - - -endstream -endobj -{{object 11 0}} << - /Type /Action - /S /JavaScript - /JS 50 0 R ->> -endobj -{{object 13 0}} << - /Names [(startDelay) 11 0 R] ->> -endobj -{{object 50 0}} << ->> -stream -var timeOut = 0; -var array = new Array(1024*4); -var doc = this; - -function myFunction() { - try { - // Free the Timer Objects - app.clearTimeOut(timeOut); - for (var i=0; i<array.length; i++) { - for (var j=0; j<array[i].length; j++) { - app.clearTimeOut(array[i][j]); - } - } - - // Trigger the Garbage Collection - array.length = 0; - array.push(new ArrayBuffer(1024*1024)); - array.length=0; - array.length=1024*4; - var str = 'AA'; - for (var i = 0; i < array.length ; i++) { - for (var j = 0; j < 10; j++ ) { - doc.addIcon(str + "-" + str + str + str + str + str, doc.icons); - } - } - } catch(err) { - app.alert(err); - } -} - -function main() { - try { - for (var i = 0; i < array.length ; i++) { - if (i == array.length / 2) { - timeOut = app.setTimeOut("myFunction()", 1000); - } - array[i] = new Array(4); - for (var j = 0; j < array[i].length ; j++ ) { - array[i][j] = app.setTimeOut("aaaaaaaaaa()", 100000); - } - } - } catch(err) { - app.alert(err); - } -} - -// Execute the JS. -app.setTimeOut("main()", 1000); - -// Be sure all of this code ran to completion. -app.alert("done"); -endstream -endobj -{{xref}} -trailer << - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_634716.pdf b/chromium/third_party/pdfium/testing/resources/bug_634716.pdf deleted file mode 100644 index 6330b9a4e53..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_634716.pdf +++ /dev/null @@ -1,180 +0,0 @@ -%PDF-1.7 -% ò¤ô -1 0 obj << - /Type /Catalog - /Pages 2 0 R - /AcroForm 6 0 R - /Names <</JavaScript 13 0 R>> ->> -endobj -2 0 obj << - /Type /Pages - /Count 1 - /Kids [4 0 R] ->> -endobj -4 0 obj << - /Type /Page - /Parent 2 0 R - /MediaBox [0 0 612 792] - /CropBox [0 0 612 792] - /Resources <<>> ->> -endobj -6 0 obj << - /DR << - /Font <</Helv 7 0 R>> - >> - /DA (/Helv 0 Tf 0 g) - /Fields [5 0 R] ->> -endobj -7 0 obj << - /Type /Font - /Subtype /Type1 - /BaseFont /Helvetica - /Encoding /WinAnsiEncoding ->> -endobj -8 0 obj << - /Type /XObject - /Subtype /Form - /FormType 1 - /Matrix [1 0 0 1 0 0] - /BBox [0 0 75.907 28.472] - /Resources << - /Font <</FXF0 7 0 R>> - >> ->> -stream -q -Q - - -endstream -endobj -11 0 obj << - /Type /Action - /S /JavaScript - /JS 50 0 R ->> -endobj -13 0 obj << - /Names [(startDelay) 11 0 R] ->> -endobj -50 0 obj << ->> -stream -var timeOut = 0; -var array = new Array(1024*4); -var doc = this; - -function myFunction() { - try { - // Free the Timer Objects - app.clearTimeOut(timeOut); - for (var i=0; i<array.length; i++) { - for (var j=0; j<array[i].length; j++) { - app.clearTimeOut(array[i][j]); - } - } - - // Trigger the Garbage Collection - array.length = 0; - array.push(new ArrayBuffer(1024*1024)); - array.length=0; - array.length=1024*4; - var str = 'AA'; - for (var i = 0; i < array.length ; i++) { - for (var j = 0; j < 10; j++ ) { - doc.addIcon(str + "-" + str + str + str + str + str, doc.icons); - } - } - } catch(err) { - app.alert(err); - } -} - -function main() { - try { - for (var i = 0; i < array.length ; i++) { - if (i == array.length / 2) { - timeOut = app.setTimeOut("myFunction()", 1000); - } - array[i] = new Array(4); - for (var j = 0; j < array[i].length ; j++ ) { - array[i][j] = app.setTimeOut("aaaaaaaaaa()", 100000); - } - } - } catch(err) { - app.alert(err); - } -} - -// Execute the JS. -app.setTimeOut("main()", 1000); - -// Be sure all of this code ran to completion. -app.alert("done"); -endstream -endobj -xref -0 51 -0000000000 65535 f -0000000015 00000 n -0000000118 00000 n -0000000000 65535 f -0000000181 00000 n -0000000000 65535 f -0000000302 00000 n -0000000404 00000 n -0000000509 00000 n -0000000000 65535 f -0000000000 65535 f -0000000701 00000 n -0000000000 65535 f -0000000769 00000 n -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000822 00000 n -trailer << - /Root 1 0 R ->> -startxref -2036 -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_644.in b/chromium/third_party/pdfium/testing/resources/bug_644.in deleted file mode 100644 index 0a936f58d89..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_644.in +++ /dev/null @@ -1,51 +0,0 @@ -{{header}} -{{object 1 0}} << - /CF << - /StdCF << - /Length 32 - /AuthEvent /DocOpen - /CFM /AESV3 - >> - >> - /Filter /Standard - /Length 256 - /O <B6C711683D98F878929688EF497A0BB928E1F0013A0B5C357BE701E42DC4A6A9E124B0C505DDDA91562C5EA791E2B7AC> - /OE <26B337B3B635C18262B4915289F1D353EB432D7E7FF6BE5450C82D690202A093> - /P 4092 - /Perms <3D62C200CDB31A603EF202E12993AE13> - /R 5 - /StmF /StdCF - /StrF /StdCF - /U <69F20E0450E8B2A8ACA6AF1DE1284DB11EC4E38F6E7CB2B9AE9A1CFF6F95BA6CD83783C4ED8B31D933482CBB7A791290> - /UE <5104E81C113D43246A264580FE82D2890B7B8CEEF4A3D667B81A32EED62D8C54> - /V 5 ->> -endobj -{{object 2 0}} << - /Type /Catalog - /Pages 5 0 R ->> -endobj -{{object 5 0}} << - /Type /Pages - /Count 1 - /Kids [6 0 R] ->> -endobj -{{object 6 0}} << - /Parent 5 0 R - /Resources << - /ProcSet [/PDF /Text /ImageC] - >> - /MediaBox [0.00000 0.00000 595.00000 842.00000] - /Type /Page ->> -endobj -{{xref}} -trailer << - /Encrypt 1 0 R - /Root 2 0 R - /Size 46 ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_644.pdf b/chromium/third_party/pdfium/testing/resources/bug_644.pdf deleted file mode 100644 index 59d6ad2357b..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_644.pdf +++ /dev/null @@ -1,61 +0,0 @@ -%PDF-1.7 -% ò¤ô -1 0 obj << - /CF << - /StdCF << - /Length 32 - /AuthEvent /DocOpen - /CFM /AESV3 - >> - >> - /Filter /Standard - /Length 256 - /O <B6C711683D98F878929688EF497A0BB928E1F0013A0B5C357BE701E42DC4A6A9E124B0C505DDDA91562C5EA791E2B7AC> - /OE <26B337B3B635C18262B4915289F1D353EB432D7E7FF6BE5450C82D690202A093> - /P 4092 - /Perms <3D62C200CDB31A603EF202E12993AE13> - /R 5 - /StmF /StdCF - /StrF /StdCF - /U <69F20E0450E8B2A8ACA6AF1DE1284DB11EC4E38F6E7CB2B9AE9A1CFF6F95BA6CD83783C4ED8B31D933482CBB7A791290> - /UE <5104E81C113D43246A264580FE82D2890B7B8CEEF4A3D667B81A32EED62D8C54> - /V 5 ->> -endobj -2 0 obj << - /Type /Catalog - /Pages 5 0 R ->> -endobj -5 0 obj << - /Type /Pages - /Count 1 - /Kids [6 0 R] ->> -endobj -6 0 obj << - /Parent 5 0 R - /Resources << - /ProcSet [/PDF /Text /ImageC] - >> - /MediaBox [0.00000 0.00000 595.00000 842.00000] - /Type /Page ->> -endobj -xref -0 7 -0000000000 65535 f -0000000015 00000 n -0000000618 00000 n -0000000000 65535 f -0000000000 65535 f -0000000671 00000 n -0000000734 00000 n -trailer << - /Encrypt 1 0 R - /Root 2 0 R - /Size 46 ->> -startxref -890 -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_650.pdf b/chromium/third_party/pdfium/testing/resources/bug_650.pdf Binary files differdeleted file mode 100644 index 5e46032f6ca..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_650.pdf +++ /dev/null diff --git a/chromium/third_party/pdfium/testing/resources/bug_664284.in b/chromium/third_party/pdfium/testing/resources/bug_664284.in deleted file mode 100644 index 50ba8e050a2..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_664284.in +++ /dev/null @@ -1,75 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R - /ViewerPreferences << - /Foo /foo - /HideToolbar true - /Direction /R2L - /ViewArea /CropBox - /NumCopies 5 - >> ->> -endobj -{{object 2 0}} << - /Type /Pages - /Count 1 - /Kids [ - 3 0 R - ] ->> -endobj -% Page number 0. -{{object 3 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /Contents [21 0 R] - /MediaBox [0 0 612 792] - /Annots [999 0 R] ->> -endobj -% Font resource. -{{object 15 0}} << - /Type /Font - /Subtype /Type1 - /BaseFont /Arial ->> -endobj -% Content for page 0. -{{object 21 0}} << - /Length 0 ->> -stream -BT -/F1 20 Tf -100 600 TD (Page1)Tj -ET -endstream -endobj -% Annots array -{{object 999 0}} [ - 29 0 R -] -endobj -{{object 29 0}} << - /Dest 37 0 R - /Type /Annot ->> -endobj -{{object 37 0}} [ - 11 0 R -] -endobj -{{object 11 0}} << - /Type /Page ->> -{{xref}} -trailer << - /Size 6 - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_664284.pdf b/chromium/third_party/pdfium/testing/resources/bug_664284.pdf deleted file mode 100644 index 126938a4c83..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_664284.pdf +++ /dev/null @@ -1,1078 +0,0 @@ -%PDF-1.7 -% ò¤ô -1 0 obj << - /Type /Catalog - /Pages 2 0 R - /ViewerPreferences << - /Foo /foo - /HideToolbar true - /Direction /R2L - /ViewArea /CropBox - /NumCopies 5 - >> ->> -endobj -2 0 obj << - /Type /Pages - /Count 1 - /Kids [ - 3 0 R - ] ->> -endobj -% Page number 0. -3 0 obj << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /Contents [21 0 R] - /MediaBox [0 0 612 792] - /Annots [999 0 R] ->> -endobj -% Font resource. -15 0 obj << - /Type /Font - /Subtype /Type1 - /BaseFont /Arial ->> -endobj -% Content for page 0. -21 0 obj << - /Length 0 ->> -stream -BT -/F1 20 Tf -100 600 TD (Page1)Tj -ET -endstream -endobj -% Annots array -999 0 obj [ - 29 0 R -] -endobj -29 0 obj << - /Dest 37 0 R - /Type /Annot ->> -endobj -37 0 obj [ - 11 0 R -] -endobj -11 0 obj << - /Type /Page ->> -xref -0 1000 -0000000000 65535 f -0000000015 00000 n -0000000193 00000 n -0000000281 00000 n -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000771 00000 n -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000462 00000 n -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000557 00000 n -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000690 00000 n -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000742 00000 n -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000660 00000 n -trailer << - /Size 6 - /Root 1 0 R ->> -startxref -800 -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_679649.in b/chromium/third_party/pdfium/testing/resources/bug_679649.in deleted file mode 100644 index 338f910c326..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_679649.in +++ /dev/null @@ -1,80 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R - /AcroForm 6 0 R - /Names <</JavaScript 13 0 R>> ->> -endobj -{{object 2 0}} << - /Type /Pages - /Count 1 - /Kids [4 0 R] ->> -endobj -{{object 4 0}} << - /Type /Page - /Parent 2 0 R - /MediaBox [0 0 612 792] - /CropBox [0 0 612 792] - /Resources <<>> ->> -endobj -{{object 6 0}} << - /DR << - /Font <</Helv 7 0 R>> - >> - /DA (/Helv 0 Tf 0 g) - /Fields [5 0 R] ->> -endobj -{{object 7 0}} << - /Type /Font - /Subtype /Type1 - /BaseFont /Helvetica - /Encoding /WinAnsiEncoding ->> -endobj -{{object 8 0}} << - /Type /XObject - /Subtype /Form - /FormType 1 - /Matrix [1 0 0 1 0 0] - /BBox [0 0 75.907 28.472] - /Resources << - /Font <</FXF0 7 0 R>> - >> ->> -stream -q -Q - - -endstream -endobj -{{object 11 0}} << - /Type /Action - /S /JavaScript - /JS 50 0 R ->> -endobj -{{object 13 0}} << - /Names [(startDelay) 11 0 R] ->> -endobj -{{object 50 0}} << ->> -stream -function ping() { - app.alert("ping"); -} -var timer = app.setTimeOut("ping()", 100); -app.clearTimeOut(timer); -endstream -endobj -{{xref}} -trailer << - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_679649.pdf b/chromium/third_party/pdfium/testing/resources/bug_679649.pdf deleted file mode 100644 index f94d463f92f..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_679649.pdf +++ /dev/null @@ -1,134 +0,0 @@ -%PDF-1.7 -% ò¤ô -1 0 obj << - /Type /Catalog - /Pages 2 0 R - /AcroForm 6 0 R - /Names <</JavaScript 13 0 R>> ->> -endobj -2 0 obj << - /Type /Pages - /Count 1 - /Kids [4 0 R] ->> -endobj -4 0 obj << - /Type /Page - /Parent 2 0 R - /MediaBox [0 0 612 792] - /CropBox [0 0 612 792] - /Resources <<>> ->> -endobj -6 0 obj << - /DR << - /Font <</Helv 7 0 R>> - >> - /DA (/Helv 0 Tf 0 g) - /Fields [5 0 R] ->> -endobj -7 0 obj << - /Type /Font - /Subtype /Type1 - /BaseFont /Helvetica - /Encoding /WinAnsiEncoding ->> -endobj -8 0 obj << - /Type /XObject - /Subtype /Form - /FormType 1 - /Matrix [1 0 0 1 0 0] - /BBox [0 0 75.907 28.472] - /Resources << - /Font <</FXF0 7 0 R>> - >> ->> -stream -q -Q - - -endstream -endobj -11 0 obj << - /Type /Action - /S /JavaScript - /JS 50 0 R ->> -endobj -13 0 obj << - /Names [(startDelay) 11 0 R] ->> -endobj -50 0 obj << ->> -stream -function ping() { - app.alert("ping"); -} -var timer = app.setTimeOut("ping()", 100); -app.clearTimeOut(timer); -endstream -endobj -xref -0 51 -0000000000 65535 f -0000000015 00000 n -0000000118 00000 n -0000000000 65535 f -0000000181 00000 n -0000000000 65535 f -0000000302 00000 n -0000000404 00000 n -0000000509 00000 n -0000000000 65535 f -0000000000 65535 f -0000000701 00000 n -0000000000 65535 f -0000000769 00000 n -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000822 00000 n -trailer << - /Root 1 0 R ->> -startxref -970 -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_680376.in b/chromium/third_party/pdfium/testing/resources/bug_680376.in deleted file mode 100644 index c21df245fb2..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_680376.in +++ /dev/null @@ -1,130 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R - /Names << - /Dests 10 0 R - >> - /Dests 14 0 R ->> -endobj -{{object 2 0}} << - /Type /Pages - /Count 4 - /Kids [ - 5 0 R - 6 0 R - ] ->> -endobj -% Page number 0. -{{object 3 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /Contents [21 0 R] - /MediaBox [0 0 612 792] ->> -endobj -% Page number 1. -{{object 4 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /Contents [22 0 R] - /MediaBox [0 0 612 792] ->> -endobj -% Tree node with bad Count, duplicated kids. -{{object 5 0}} << - /Type /Pages - /Parent 2 0 R - /Count 2 - /Kids [ - 3 0 R - 3 0 R - 3 0 R - 3 0 R - ] ->> -endobj -% tree node with actual kids -{{object 6 0}} << - /Type /Pages - /Count 2 - /Kids [ - 3 0 R - 4 0 R - ] ->> -% Root of Dests NameTree -{{object 10 0}} << - /Kids [ - 11 0 R - 12 0 R - ] ->> -endobj -% Left child for Dests NameTree -{{object 11 0}} << - /Names [ - (First) [4 0 R] - ] ->> -endobj -% Right child for Dests NameTree -{{object 12 0}} << - /Names [ - (WrongKey) <</Fail [10 /FitH]>> - (WrongType) /NameNotAllowedHere - ] ->> -endobj -% Old-style top-level Dests dictionary. Note that FirstAlternate -% intentionally references non-exisstant page 11 and LastAlternate -% intentionally references non-existant object 999. -{{object 14 0}} << - /FirstAlternate [11 /XYZ 200 400 800] - /LastAlternate <</D [999 0 R /XYZ 0 0 -200]>> ->> -endobj -% Font resource. -{{object 15 0}} << - /Type /Font - /Subtype /Type1 - /BaseFont /Arial ->> -endobj -% Content for page 0. -{{object 21 0}} << - /Length 0 ->> -stream -BT -/F1 20 Tf -100 600 TD (Page1)Tj -ET -endstream -endobj -% Content for page 1. -{{object 22 0}} << - /Length 0 ->> -stream -BT -/F1 20 Tf -100 600 TD (Page2)Tj -ET -endstream -endobj -{{xref}} -trailer << - /Size 6 - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_680376.pdf b/chromium/third_party/pdfium/testing/resources/bug_680376.pdf deleted file mode 100644 index fb01c57613d..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_680376.pdf +++ /dev/null @@ -1,156 +0,0 @@ -%PDF-1.7 -% ò¤ô -1 0 obj << - /Type /Catalog - /Pages 2 0 R - /Names << - /Dests 10 0 R - >> - /Dests 14 0 R ->> -endobj -2 0 obj << - /Type /Pages - /Count 4 - /Kids [ - 5 0 R - 6 0 R - ] ->> -endobj -% Page number 0. -3 0 obj << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /Contents [21 0 R] - /MediaBox [0 0 612 792] ->> -endobj -% Page number 1. -4 0 obj << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /Contents [22 0 R] - /MediaBox [0 0 612 792] ->> -endobj -% Tree node with bad Count, duplicated kids. -5 0 obj << - /Type /Pages - /Parent 2 0 R - /Count 2 - /Kids [ - 3 0 R - 3 0 R - 3 0 R - 3 0 R - ] ->> -endobj -% tree node with actual kids -6 0 obj << - /Type /Pages - /Count 2 - /Kids [ - 3 0 R - 4 0 R - ] ->> -% Root of Dests NameTree -10 0 obj << - /Kids [ - 11 0 R - 12 0 R - ] ->> -endobj -% Left child for Dests NameTree -11 0 obj << - /Names [ - (First) [4 0 R] - ] ->> -endobj -% Right child for Dests NameTree -12 0 obj << - /Names [ - (WrongKey) <</Fail [10 /FitH]>> - (WrongType) /NameNotAllowedHere - ] ->> -endobj -% Old-style top-level Dests dictionary. Note that FirstAlternate -% intentionally references non-exisstant page 11 and LastAlternate -% intentionally references non-existant object 999. -14 0 obj << - /FirstAlternate [11 /XYZ 200 400 800] - /LastAlternate <</D [999 0 R /XYZ 0 0 -200]>> ->> -endobj -% Font resource. -15 0 obj << - /Type /Font - /Subtype /Type1 - /BaseFont /Arial ->> -endobj -% Content for page 0. -21 0 obj << - /Length 0 ->> -stream -BT -/F1 20 Tf -100 600 TD (Page1)Tj -ET -endstream -endobj -% Content for page 1. -22 0 obj << - /Length 0 ->> -stream -BT -/F1 20 Tf -100 600 TD (Page2)Tj -ET -endstream -endobj -xref -0 23 -0000000000 65535 f -0000000015 00000 n -0000000119 00000 n -0000000217 00000 n -0000000378 00000 n -0000000568 00000 n -0000000714 00000 n -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000813 00000 n -0000000903 00000 n -0000000993 00000 n -0000000000 65535 f -0000001287 00000 n -0000001415 00000 n -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000001510 00000 n -0000001620 00000 n -trailer << - /Size 6 - /Root 1 0 R ->> -startxref -1708 -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_709793.in b/chromium/third_party/pdfium/testing/resources/bug_709793.in deleted file mode 100644 index c9fe0882a74..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_709793.in +++ /dev/null @@ -1,22 +0,0 @@ -{{header}} -{{object 1 0}} << - /Pages 3 0 R - /AcroForm << - /XFA 7 0 R - >> ->> -endobj -{{object 3 0}} << ->> -endobj -{{object 7 0}} << ->>stream -<xdp:xdp xmlns:xdp="http://ns.adobe.com/xdp/"><config><form/></></> -endstream -endobj -{{xref}} -trailer << - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_709793.pdf b/chromium/third_party/pdfium/testing/resources/bug_709793.pdf deleted file mode 100644 index 003c7cf7698..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_709793.pdf +++ /dev/null @@ -1,33 +0,0 @@ -%PDF-1.7 -% ò¤ô -1 0 obj << - /Pages 3 0 R - /AcroForm << - /XFA 7 0 R - >> ->> -endobj -3 0 obj << ->> -endobj -7 0 obj << ->>stream -<xdp:xdp xmlns:xdp="http://ns.adobe.com/xdp/"><config><form/></></> -endstream -endobj -xref -0 8 -0000000000 65535 f -0000000015 00000 n -0000000000 65535 f -0000000086 00000 n -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000107 00000 n -trailer << - /Root 1 0 R ->> -startxref -212 -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_713197.in b/chromium/third_party/pdfium/testing/resources/bug_713197.in deleted file mode 100644 index 10a57fd1c06..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_713197.in +++ /dev/null @@ -1,27 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R ->> -endobj -{{object 2 0}}<< - /Type /Pages - /MediaBox [0 0 600 800] - /Count 1 - /Kids [ 3 0 R ] ->> -endobj -{{object 3 0}}<< - /Type /Page - /Parent 2 0 R - /Resources <<>> - /Rotate -90 ->> -endobj -{{xref}} -trailer << - /Size 4 - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_713197.pdf b/chromium/third_party/pdfium/testing/resources/bug_713197.pdf deleted file mode 100644 index 14457b9ce81..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_713197.pdf +++ /dev/null @@ -1,34 +0,0 @@ -%PDF-1.7 -% ò¤ô -1 0 obj << - /Type /Catalog - /Pages 2 0 R ->> -endobj -2 0 obj<< - /Type /Pages - /MediaBox [0 0 600 800] - /Count 1 - /Kids [ 3 0 R ] ->> -endobj -3 0 obj<< - /Type /Page - /Parent 2 0 R - /Resources <<>> - /Rotate -90 ->> -endobj -xref -0 4 -0000000000 65535 f -0000000016 00000 n -0000000074 00000 n -0000000171 00000 n -trailer << - /Size 4 - /Root 1 0 R ->> -startxref -260 -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/bug_xrefv4_loop.pdf b/chromium/third_party/pdfium/testing/resources/bug_xrefv4_loop.pdf deleted file mode 100644 index c1169773f74..00000000000 --- a/chromium/third_party/pdfium/testing/resources/bug_xrefv4_loop.pdf +++ /dev/null @@ -1,45 +0,0 @@ -%PDF-1.7 -% ò¤ô -1 0 obj << - /Type /Catalog - /Pages 2 0 R ->> -endobj -2 0 obj << - /Type /Pages - /Count 1 - /Kids [ - 3 0 R - ] ->> -endobj -3 0 obj << - /Type /Page - /Parent 2 0 R - /MediaBox [0 0 612 792] ->> -endobj -xref -0 2 -0000000000 65535 f -0000000015 00000 n -trailer << - /Prev 346 ->> -xref -2 1 -0000000068 00000 n -trailer << - /Prev 216 ->> -xref -3 1 -0000000139 00000 n -trailer << - /Size 4 - /Prev 291 - /Root 1 0 R ->> -startxref -346 -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/circular_viewer_ref.in b/chromium/third_party/pdfium/testing/resources/circular_viewer_ref.in deleted file mode 100644 index f791607e91f..00000000000 --- a/chromium/third_party/pdfium/testing/resources/circular_viewer_ref.in +++ /dev/null @@ -1,24 +0,0 @@ -{{header}} -{{object 1 0}} -<</Names 1 0 R - /ViewerPreferences<< - /Names 1 0 R - /ViewerPreferences<< - /Names 1 0 R - /ViewerPreferences<<>> - >>>> ->> -endobj - -{{object 2 0}} -<</Names[(0) 7 0 R]>> -endobj - -{{object 7 0}} -<</JS(this.print\({bUI:true,bSilent:false,bShrinkToFit:true}\);)/S/JavaScript>> -endobj - -{{xref}} -trailer <</Root 1 0 R>> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/circular_viewer_ref.pdf b/chromium/third_party/pdfium/testing/resources/circular_viewer_ref.pdf deleted file mode 100644 index 2e5c4dd8abd..00000000000 --- a/chromium/third_party/pdfium/testing/resources/circular_viewer_ref.pdf +++ /dev/null @@ -1,35 +0,0 @@ -%PDF-1.7 -% ò¤ô -1 0 obj -<</Names 1 0 R - /ViewerPreferences<< - /Names 1 0 R - /ViewerPreferences<< - /Names 1 0 R - /ViewerPreferences<<>> - >>>> ->> -endobj - -2 0 obj -<</Names[(0) 7 0 R]>> -endobj - -7 0 obj -<</JS(this.print\({bUI:true,bSilent:false,bShrinkToFit:true}\);)/S/JavaScript>> -endobj - -xref -0 8 -0000000000 65535 f -0000000015 00000 n -0000000157 00000 n -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000195 00000 n -trailer <</Root 1 0 R>> -startxref -291 -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/encrypted.pdf b/chromium/third_party/pdfium/testing/resources/encrypted.pdf Binary files differdeleted file mode 100644 index b489d56ff24..00000000000 --- a/chromium/third_party/pdfium/testing/resources/encrypted.pdf +++ /dev/null diff --git a/chromium/third_party/pdfium/testing/resources/feature_linearized_loading.pdf b/chromium/third_party/pdfium/testing/resources/feature_linearized_loading.pdf Binary files differdeleted file mode 100644 index e6995c516d9..00000000000 --- a/chromium/third_party/pdfium/testing/resources/feature_linearized_loading.pdf +++ /dev/null diff --git a/chromium/third_party/pdfium/testing/resources/hello_world.in b/chromium/third_party/pdfium/testing/resources/hello_world.in deleted file mode 100644 index 19fce0ce335..00000000000 --- a/chromium/third_party/pdfium/testing/resources/hello_world.in +++ /dev/null @@ -1,56 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R ->> -{{object 2 0}} << - /Type /Pages - /MediaBox [ 0 0 200 200 ] - /Count 1 - /Kids [ 3 0 R ] ->> -endobj -{{object 3 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font << - /F1 4 0 R - /F2 5 0 R - >> - >> - /Contents 6 0 R ->> -endobj -{{object 4 0}} << - /Type /Font - /Subtype /Type1 - /BaseFont /Times-Roman ->> -endobj -{{object 5 0}} << - /Type /Font - /Subtype /Type1 - /BaseFont /Helvetica ->> -endobj -{{object 6 0}} << ->> -stream -BT -20 50 Td -/F1 12 Tf -(Hello, world!) Tj -0 50 Td -/F2 16 Tf -(Goodbye, world!) Tj -ET -endstream -endobj -{{xref}} -trailer << - /Size 6 - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/hello_world.pdf b/chromium/third_party/pdfium/testing/resources/hello_world.pdf deleted file mode 100644 index bb4f0a88e7a..00000000000 --- a/chromium/third_party/pdfium/testing/resources/hello_world.pdf +++ /dev/null @@ -1,66 +0,0 @@ -%PDF-1.7 -% ò¤ô -1 0 obj << - /Type /Catalog - /Pages 2 0 R ->> -2 0 obj << - /Type /Pages - /MediaBox [ 0 0 200 200 ] - /Count 1 - /Kids [ 3 0 R ] ->> -endobj -3 0 obj << - /Type /Page - /Parent 2 0 R - /Resources << - /Font << - /F1 4 0 R - /F2 5 0 R - >> - >> - /Contents 6 0 R ->> -endobj -4 0 obj << - /Type /Font - /Subtype /Type1 - /BaseFont /Times-Roman ->> -endobj -5 0 obj << - /Type /Font - /Subtype /Type1 - /BaseFont /Helvetica ->> -endobj -6 0 obj << ->> -stream -BT -20 50 Td -/F1 12 Tf -(Hello, world!) Tj -0 50 Td -/F2 16 Tf -(Goodbye, world!) Tj -ET -endstream -endobj -xref -0 7 -0000000000 65535 f -0000000015 00000 n -0000000061 00000 n -0000000154 00000 n -0000000296 00000 n -0000000374 00000 n -0000000450 00000 n -trailer << - /Size 6 - /Root 1 0 R ->> -startxref -571 -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/javascript/app_alert.in b/chromium/third_party/pdfium/testing/resources/javascript/app_alert.in deleted file mode 100644 index 75aecc90753..00000000000 --- a/chromium/third_party/pdfium/testing/resources/javascript/app_alert.in +++ /dev/null @@ -1,71 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R - /OpenAction 10 0 R ->> -endobj -{{object 2 0}} << - /Type /Pages - /Count 1 - /Kids [ - 3 0 R - ] ->> -endobj -% Page number 0. -{{object 3 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /Contents [21 0 R] - /MediaBox [0 0 612 792] ->> -% OpenAction action -{{object 10 0}} << - /Type /Action - /S /JavaScript - /JS 11 0 R ->> -endobj -% JS program to exexute -{{object 11 0}} << ->> -stream -app.alert("This test passes if alert() logs output under the test utility."); -app.alert("message", 1, 2, "title"); -app.alert({"cMsg": "message", "cTitle": "title"}); -app.alert({"cMsg": "message", "cTitle": "title", "nIcon": 3, "nType": 4}); -app.alert(undefined); -app.alert(null); -app.alert(true); -app.alert(false); -app.alert(42); -app.alert([1, 2, 3]); -app.alert([1, 2, {"color": "red"}]); -app.alert({"color": "red"}, 5, 6, "title"); -try { - app.alert(); -} catch (e) { - app.alert("Caught expected error " + e); -} -try { - app.alert({}); -} catch (e) { - app.alert("Caught expected error " + e); -} -try { - app.alert({"color": "red", "size": 42}); -} catch (e) { - app.alert("Caught expected error " + e); -} -endstream -endobj -{{xref}} -trailer << - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/javascript/app_alert_expected.txt b/chromium/third_party/pdfium/testing/resources/javascript/app_alert_expected.txt deleted file mode 100644 index b44fa73a946..00000000000 --- a/chromium/third_party/pdfium/testing/resources/javascript/app_alert_expected.txt +++ /dev/null @@ -1,15 +0,0 @@ -Alert: This test passes if alert() logs output under the test utility. -title[icon=1,type=2]: message -title: message -title[icon=3,type=4]: message -Alert: undefined -Alert: null -Alert: true -Alert: false -Alert: 42 -Alert: [1, 2, 3] -Alert: [1, 2, [object Object]] -title[icon=5,type=6]: [object Object] -Alert: Caught expected error app.alert: Incorrect number of parameters passed to function. -Alert: Caught expected error app.alert: Incorrect number of parameters passed to function. -Alert: Caught expected error app.alert: Incorrect number of parameters passed to function. diff --git a/chromium/third_party/pdfium/testing/resources/javascript/app_mailmsg.in b/chromium/third_party/pdfium/testing/resources/javascript/app_mailmsg.in deleted file mode 100644 index 990709be47a..00000000000 --- a/chromium/third_party/pdfium/testing/resources/javascript/app_mailmsg.in +++ /dev/null @@ -1,72 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R - /OpenAction 10 0 R ->> -endobj -{{object 2 0}} << - /Type /Pages - /Count 1 - /Kids [ - 3 0 R - ] ->> -endobj -% Page number 0. -{{object 3 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /Contents [21 0 R] - /MediaBox [0 0 612 792] ->> -% OpenAction action -{{object 10 0}} << - /Type /Action - /S /JavaScript - /JS 11 0 R ->> -endobj -% JS program to exexute -{{object 11 0}} << ->> -stream -app.alert("This test passes if mailMsg() logs output under the test utility."); -app.mailMsg(true); -app.mailMsg(false, "user@example.com"); -app.mailMsg(false, "user@example.com", "cc@example.com", - "bcc@example.com", "subject", "body"); -app.mailMsg({"bUI": true}); -app.mailMsg({"bUI": false, "cTo": "user@example.com"}); -app.mailMsg({"bUI": false, - "cTo": "user@example.com", - "cCc": "cc@example.com", - "cBcc": "bcc@example.com", - "cSubject": "subject", - "cMsg": "body"}); -try { - app.mailMsg(); -} catch (e) { - app.alert("Caught expected error " + e); -} -try { - app.mailMsg(false); -} catch (e) { - app.alert("Caught expected error " + e); -} -try { - app.mailMsg({"color": "red", "size": 42}); -} catch (e) { - app.alert("Caught expected error " + e); -} -endstream -endobj -{{xref}} -trailer << - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/javascript/app_mailmsg_expected.txt b/chromium/third_party/pdfium/testing/resources/javascript/app_mailmsg_expected.txt deleted file mode 100644 index 59928ae954c..00000000000 --- a/chromium/third_party/pdfium/testing/resources/javascript/app_mailmsg_expected.txt +++ /dev/null @@ -1,10 +0,0 @@ -Alert: This test passes if mailMsg() logs output under the test utility. -Mail Msg: 1, to=, cc=, bcc=, subject=, body= -Mail Msg: 0, to=user@example.com, cc=, bcc=, subject=, body= -Mail Msg: 0, to=user@example.com, cc=cc@example.com, bcc=bcc@example.com, subject=subject, body=body -Mail Msg: 1, to=, cc=, bcc=, subject=, body= -Mail Msg: 0, to=user@example.com, cc=, bcc=, subject=, body= -Mail Msg: 0, to=user@example.com, cc=cc@example.com, bcc=bcc@example.com, subject=subject, body=body -Alert: Caught expected error app.mailMsg: Incorrect number of parameters passed to function. -Alert: Caught expected error app.mailMsg: Incorrect number of parameters passed to function. -Alert: Caught expected error app.mailMsg: Incorrect number of parameters passed to function. diff --git a/chromium/third_party/pdfium/testing/resources/javascript/app_props.in b/chromium/third_party/pdfium/testing/resources/javascript/app_props.in deleted file mode 100644 index 89511b0b136..00000000000 --- a/chromium/third_party/pdfium/testing/resources/javascript/app_props.in +++ /dev/null @@ -1,124 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R - /OpenAction 10 0 R ->> -endobj -{{object 2 0}} << - /Type /Pages - /Count 4 - /Kids [ - 3 0 R - 4 0 R - 5 0 R - 6 0 R - ] ->> -endobj -% Page number 0. -{{object 3 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /MediaBox [0 0 612 792] ->> -% Page number 1. -{{object 4 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /MediaBox [0 0 612 792] ->> -% Page number 2. -{{object 5 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /MediaBox [0 0 612 792] ->> -% Page number 3. -{{object 6 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /MediaBox [0 0 612 792] ->> - -% Info -{{object 9 0}} << - /Author (Joe Random Author) - /Creator (Joe Random Creator) ->> -endobj -% OpenAction action -{{object 10 0}} << - /Type /Action - /S /JavaScript - /JS 11 0 R ->> -endobj -% JS program to exexute -{{object 11 0}} << ->> -stream -var app_props = [ - 'activeDocs', - 'calculate', - 'formsVersion', - 'fs', - 'fullscreen', - 'language', - 'media', - 'platform', - 'runtimeHighlight', - 'viewerType', - 'viewerVariation', - 'viewerVersion' -]; - -function testGetProps(props) { - app.alert('*** Getting properties ***'); - for (var i = 0; i < props.length; ++i) { - try { - var expr1 = "app." + props[i]; - var expr2 = "typeof " + expr1; - app.alert(expr1 + " is " + eval(expr2) + ' ' + eval(expr1)); - } catch (e) { - app.alert("ERROR: " + e.toString()); - } - } -} - -function testSetProps(props) { - app.alert('*** Setting properties ***'); - for (var i = 0; i < props.length; ++i) { - try { - var expr1 = "app." + props[i] + ' = 3;' - app.alert(expr1 + " yields " + eval(expr1)); - } catch (e) { - app.alert("ERROR: " + e.toString()); - } - } -} - -testGetProps(app_props); -testSetProps(app_props); -testGetProps(app_props); -endstream -endobj -{{xref}} -trailer << - /Root 1 0 R - /Info 9 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/javascript/app_props_expected.txt b/chromium/third_party/pdfium/testing/resources/javascript/app_props_expected.txt deleted file mode 100644 index a17e0f82b5d..00000000000 --- a/chromium/third_party/pdfium/testing/resources/javascript/app_props_expected.txt +++ /dev/null @@ -1,39 +0,0 @@ -Alert: *** Getting properties *** -Alert: app.activeDocs is object [object global] -Alert: app.calculate is boolean true -Alert: app.formsVersion is number 7 -Alert: ERROR: app.fs: -Alert: ERROR: app.fullscreen: -Alert: app.language is string ENU -Alert: ERROR: app.media: -Alert: app.platform is string WIN -Alert: app.runtimeHighlight is boolean false -Alert: app.viewerType is string pdfium -Alert: app.viewerVariation is string Full -Alert: app.viewerVersion is number 8 -Alert: *** Setting properties *** -Alert: ERROR: app.activeDocs: -Alert: app.calculate = 3; yields 3 -Alert: ERROR: app.formsVersion: -Alert: ERROR: app.fs: -Alert: ERROR: app.fullscreen: -Alert: ERROR: app.language: -Alert: ERROR: app.media: -Alert: ERROR: app.platform: -Alert: app.runtimeHighlight = 3; yields 3 -Alert: ERROR: app.viewerType: -Alert: ERROR: app.viewerVariation: -Alert: ERROR: app.viewerVersion: -Alert: *** Getting properties *** -Alert: app.activeDocs is object [object global] -Alert: app.calculate is boolean true -Alert: app.formsVersion is number 7 -Alert: ERROR: app.fs: -Alert: ERROR: app.fullscreen: -Alert: app.language is string ENU -Alert: ERROR: app.media: -Alert: app.platform is string WIN -Alert: app.runtimeHighlight is boolean true -Alert: app.viewerType is string pdfium -Alert: app.viewerVariation is string Full -Alert: app.viewerVersion is number 8 diff --git a/chromium/third_party/pdfium/testing/resources/javascript/app_repsonse.in b/chromium/third_party/pdfium/testing/resources/javascript/app_repsonse.in deleted file mode 100644 index bd78da35e3c..00000000000 --- a/chromium/third_party/pdfium/testing/resources/javascript/app_repsonse.in +++ /dev/null @@ -1,75 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R - /OpenAction 10 0 R ->> -endobj -{{object 2 0}} << - /Type /Pages - /Count 1 - /Kids [ - 3 0 R - ] ->> -endobj -% Page number 0. -{{object 3 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /Contents [21 0 R] - /MediaBox [0 0 612 792] ->> -% OpenAction action -{{object 10 0}} << - /Type /Action - /S /JavaScript - /JS 11 0 R ->> -endobj -% JS program to exexute -{{object 11 0}} << ->> -stream -var result; -try { - result = app.response("question"); - app.alert("result: " + result); - result = app.response("question", "title", "default", true, "label"); - app.alert("result: " + result); - result = app.response({"cQuestion": "question"}); - app.alert("result: " + result); - result = app.response({ - "cQuestion": "question", - "cTitle": "title", - "cDefault": "default", - "bPassword": true, - "cLabel": "label" - }); - app.alert("result: " + result); -} catch (e) { - app.alert("unexpected error " + e); -} -try { - app.response(); - app.alert("unexpected success"); -} catch (e) { - app.alert("Caught expected error " + e); -} -try { - app.response({}); - app.alert("unexpected success"); -} catch (e) { - app.alert("Caught expected error " + e); -} -endstream -endobj -{{xref}} -trailer << - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/javascript/app_repsonse_expected.txt b/chromium/third_party/pdfium/testing/resources/javascript/app_repsonse_expected.txt deleted file mode 100644 index 8a2995986b5..00000000000 --- a/chromium/third_party/pdfium/testing/resources/javascript/app_repsonse_expected.txt +++ /dev/null @@ -1,10 +0,0 @@ -PDF: question, defaultValue=, label=, isPassword=0, length=2048 -Alert: result: No -title: question, defaultValue=default, label=label, isPassword=1, length=2048 -Alert: result: No -PDF: question, defaultValue=, label=, isPassword=0, length=2048 -Alert: result: No -title: question, defaultValue=default, label=label, isPassword=1, length=2048 -Alert: result: No -Alert: Caught expected error app.response: Incorrect number of parameters passed to function. -Alert: Caught expected error app.response: Incorrect number of parameters passed to function. diff --git a/chromium/third_party/pdfium/testing/resources/javascript/apply.in b/chromium/third_party/pdfium/testing/resources/javascript/apply.in deleted file mode 100644 index 1342c1af4e7..00000000000 --- a/chromium/third_party/pdfium/testing/resources/javascript/apply.in +++ /dev/null @@ -1,75 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R - /OpenAction 10 0 R ->> -endobj -{{object 2 0}} << - /Type /Pages - /Count 1 - /Kids [ - 3 0 R - ] ->> -endobj -% Page number 0. -{{object 3 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /Contents [21 0 R] - /MediaBox [0 0 612 792] ->> -% OpenAction action -{{object 10 0}} << - /Type /Action - /S /JavaScript - /JS 11 0 R ->> -endobj -% JS program to exexute -{{object 11 0}} << ->> -stream -app.alert('Applying to util itself - should succeed'); -try { - app.alert(util.byteToChar.apply(util, [65])); -} -catch (e) { - app.alert('Caught: ' + e); -} - -app.alert('Applying to array - should throw'); -try { - app.alert(util.byteToChar.apply([], [65])); -} -catch (e) { - app.alert('Caught: ' + e); -} - -app.alert('Applying to number - should throw'); -try { - app.alert(util.byteToChar.apply(7, [65])); -} -catch (e) { - app.alert('Caught: ' + e); -} - -app.alert('Applying to wrong native obj - should throw'); -try { - app.alert(util.byteToChar.apply(app, [65])); -} -catch (e) { - app.alert('Caught: ' + e); -} -endstream -endobj -{{xref}} -trailer << - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/javascript/apply_expected.txt b/chromium/third_party/pdfium/testing/resources/javascript/apply_expected.txt deleted file mode 100644 index 750676f2354..00000000000 --- a/chromium/third_party/pdfium/testing/resources/javascript/apply_expected.txt +++ /dev/null @@ -1,8 +0,0 @@ -Alert: Applying to util itself - should succeed -Alert: A -Alert: Applying to array - should throw -Alert: Caught: TypeError: Illegal invocation -Alert: Applying to number - should throw -Alert: Caught: TypeError: Illegal invocation -Alert: Applying to wrong native obj - should throw -Alert: Caught: TypeError: Illegal invocation diff --git a/chromium/third_party/pdfium/testing/resources/javascript/array_buffer.in b/chromium/third_party/pdfium/testing/resources/javascript/array_buffer.in deleted file mode 100644 index 1f3e32d60d7..00000000000 --- a/chromium/third_party/pdfium/testing/resources/javascript/array_buffer.in +++ /dev/null @@ -1,68 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R - /OpenAction 10 0 R ->> -endobj -{{object 2 0}} << - /Type /Pages - /Count 1 - /Kids [ - 3 0 R - ] ->> -endobj -% Page number 0. -{{object 3 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /Contents [21 0 R] - /MediaBox [0 0 612 792] ->> -% OpenAction action -{{object 10 0}} << - /Type /Action - /S /JavaScript - /JS 11 0 R ->> -endobj -% JS program to exexute -{{object 11 0}} << ->> -stream -app.alert("This test attempts to make array buffers until exhausted"); - -function test(size) { - var i, ab, ia; - app.alert("Trying size " + size); - ab = new ArrayBuffer(size); - ia = new Int32Array(ab); - for (i = 0; i < size / 4; ++i) { - ia[i] = i; - } - for (i = 0; i < size / 4; ++i) { - if (ia[i] != i) { - throw('aaaaaaah'); - } - } -} - -try { - test(1000); - test(2000000); - test(4000000000); -} catch (e) { - app.alert("Caught error " + e); -} -endstream -endobj -{{xref}} -trailer << - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/javascript/array_buffer_expected.txt b/chromium/third_party/pdfium/testing/resources/javascript/array_buffer_expected.txt deleted file mode 100644 index f8f3bf227c3..00000000000 --- a/chromium/third_party/pdfium/testing/resources/javascript/array_buffer_expected.txt +++ /dev/null @@ -1,5 +0,0 @@ -Alert: This test attempts to make array buffers until exhausted -Alert: Trying size 1000 -Alert: Trying size 2000000 -Alert: Trying size 4000000000 -Alert: Caught error RangeError: Array buffer allocation failed diff --git a/chromium/third_party/pdfium/testing/resources/javascript/bug_361.in b/chromium/third_party/pdfium/testing/resources/javascript/bug_361.in deleted file mode 100644 index 92cd8e30d3c..00000000000 --- a/chromium/third_party/pdfium/testing/resources/javascript/bug_361.in +++ /dev/null @@ -1,112 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R - /AcroForm 4 0 R - /OpenAction 10 0 R ->> -endobj -{{object 2 0}} << - /Type /Pages - /Count 1 - /Kids [ - 3 0 R - ] ->> -endobj -% Page number 0. -{{object 3 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /Contents [21 0 R] - /MediaBox [0 0 612 792] ->> -% Forms -{{object 4 0}} << - /Fields [5 0 R] ->> -% Field -{{object 5 0}} << - /FT /Tx - /T (MyField) - /Type /Annot - /Subtype /Widget - /Rect [100 200 150 250] ->> -% OpenAction action -{{object 10 0}} << - /Type /Action - /S /JavaScript - /JS 11 0 R ->> -endobj -% JS program to exexute -{{object 11 0}} << ->> -stream -function testField(x) { - var field = this.getField("MyField"); - field.value = x; - var y = field.value; - app.alert("Answer for \"" + x + "\" is: " + typeof(y) + " " + y); -} -testField(""); -testField("goats"); -testField("b4"); -testField("b4.5"); -testField("4x"); -testField("4.5x"); -testField(4); -testField("4"); -testField(" 4"); -testField("4 "); -testField(" 4 "); -testField("4 3 2 1"); -testField("-4"); -testField("23.00000001"); -testField("23.00000000000000001"); -testField(40000000000000000000000000); -testField("40000000000000000000000000"); -testField("25,5"); -testField("1e+5"); -testField("1e5"); -testField("1e-5"); -testField("-1e-5"); -testField("1.2e5"); -testField(Infinity); -testField("Infinity"); -testField("INFINITY"); -testField("INF"); -testField(NaN); -testField("NaN"); -testField("NAN"); -testField("0x100"); -testField("0x100.1"); -testField("0x100,1"); -testField("0x100x1"); -testField("123x6"); -testField("123xy6"); -testField("123.y6"); -testField("1,000,000"); -testField("1.2.3"); -testField("1-3"); -testField("1+3"); -testField("1.-3"); -testField("1.+3"); -testField([1, 2, 3, 4]); -testField("[1, 2, 3, 4]"); -testField({a: 1, b: 2}); -testField("{a: 1, b: 2}"); -testField(function(x) { return x+1; }); -testField("function(x) { return x+1; }"); -endstream -endobj -{{xref}} -trailer << - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/javascript/bug_361_expected.txt b/chromium/third_party/pdfium/testing/resources/javascript/bug_361_expected.txt deleted file mode 100644 index 04d72bce20c..00000000000 --- a/chromium/third_party/pdfium/testing/resources/javascript/bug_361_expected.txt +++ /dev/null @@ -1,49 +0,0 @@ -Alert: Answer for "" is: string -Alert: Answer for "goats" is: string goats -Alert: Answer for "b4" is: string b4 -Alert: Answer for "b4.5" is: string b4.5 -Alert: Answer for "4x" is: string 4x -Alert: Answer for "4.5x" is: string 4.5x -Alert: Answer for "4" is: number 4 -Alert: Answer for "4" is: number 4 -Alert: Answer for " 4" is: number 4 -Alert: Answer for "4 " is: number 4 -Alert: Answer for " 4 " is: number 4 -Alert: Answer for "4 3 2 1" is: string 4 3 2 1 -Alert: Answer for "-4" is: number -4 -Alert: Answer for "23.00000001" is: number 23.00000001 -Alert: Answer for "23.00000000000000001" is: number 23 -Alert: Answer for "4e+25" is: number 4e+25 -Alert: Answer for "40000000000000000000000000" is: number 4e+25 -Alert: Answer for "25,5" is: string 25,5 -Alert: Answer for "1e+5" is: number 100000 -Alert: Answer for "1e5" is: number 100000 -Alert: Answer for "1e-5" is: number 0.00001 -Alert: Answer for "-1e-5" is: number -0.00001 -Alert: Answer for "1.2e5" is: number 120000 -Alert: Answer for "Infinity" is: number Infinity -Alert: Answer for "Infinity" is: number Infinity -Alert: Answer for "INFINITY" is: string INFINITY -Alert: Answer for "INF" is: string INF -Alert: Answer for "NaN" is: number NaN -Alert: Answer for "NaN" is: number NaN -Alert: Answer for "NAN" is: string NAN -Alert: Answer for "0x100" is: number 256 -Alert: Answer for "0x100.1" is: string 0x100.1 -Alert: Answer for "0x100,1" is: string 0x100,1 -Alert: Answer for "0x100x1" is: string 0x100x1 -Alert: Answer for "123x6" is: string 123x6 -Alert: Answer for "123xy6" is: string 123xy6 -Alert: Answer for "123.y6" is: string 123.y6 -Alert: Answer for "1,000,000" is: string 1,000,000 -Alert: Answer for "1.2.3" is: string 1.2.3 -Alert: Answer for "1-3" is: string 1-3 -Alert: Answer for "1+3" is: string 1+3 -Alert: Answer for "1.-3" is: string 1.-3 -Alert: Answer for "1.+3" is: string 1.+3 -Alert: Answer for "1,2,3,4" is: number 1 -Alert: Answer for "[1, 2, 3, 4]" is: string [1, 2, 3, 4] -Alert: Answer for "[object Object]" is: string [object Object] -Alert: Answer for "{a: 1, b: 2}" is: string {a: 1, b: 2} -Alert: Answer for "function (x) { return x+1; }" is: string function (x) { return x+1; } -Alert: Answer for "function(x) { return x+1; }" is: string function(x) { return x+1; } diff --git a/chromium/third_party/pdfium/testing/resources/javascript/bug_492_1.in b/chromium/third_party/pdfium/testing/resources/javascript/bug_492_1.in deleted file mode 100644 index f2b03b01bc7..00000000000 --- a/chromium/third_party/pdfium/testing/resources/javascript/bug_492_1.in +++ /dev/null @@ -1,95 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R - /OpenAction 20 0 R ->> -endobj -{{object 2 0}} << - /Type /Pages - /Count 2 - /Kids [ - 10 0 R - 11 0 R - ] ->> -endobj -% Page number 0. -{{object 10 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /MediaBox [0 0 612 792] - /Annots [ - 22 0 R - ] - /Tabs /R ->> -endobj -% Page number 1. -{{object 11 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /MediaBox [0 0 612 792] - /Annots [ - 22 0 R - ] - /Tabs /C ->> -endobj - -% OpenAction action -{{object 20 0}} << - /Type /Action - /S /JavaScript - /JS 21 0 R ->> -endobj -% JS program to exexute -{{object 21 0}} << ->> -stream - var annots = this.getAnnots(); - for (var i = 0; i < annots.length; i++) - app.alert(annots[i].name); -endstream -endobj - -{{object 22 0}} << - /Type /Annot - /Subtype /Highlight - /QuadPoints [ - 115.80264 - 718.9139232 - 157.211172 - 718.9139232 - 115.80264 - 706.26441 - 6 - 157.211172 - 706.264416 - ] - /Rect [ 115.75062 706.328568 157.001868 719.2715904 ] - /F 4 - /Border [ 0 0 1 ] - /C [ 1 1 0 ] - /CA 1 - /Contents <feff> - /M (D:20160712221733) - /NM (annot_s_name) - /P 9 0 R - /T <feff004a006100650020004800790075006e0020005000610072006b> ->> -endobj - -{{xref}} -trailer << - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/javascript/bug_492_1_expected.txt b/chromium/third_party/pdfium/testing/resources/javascript/bug_492_1_expected.txt deleted file mode 100644 index 2862e4427a1..00000000000 --- a/chromium/third_party/pdfium/testing/resources/javascript/bug_492_1_expected.txt +++ /dev/null @@ -1,2 +0,0 @@ -Alert: annot_s_name -Alert: annot_s_name diff --git a/chromium/third_party/pdfium/testing/resources/javascript/bug_494057.in b/chromium/third_party/pdfium/testing/resources/javascript/bug_494057.in deleted file mode 100644 index 188b7bf5fa3..00000000000 --- a/chromium/third_party/pdfium/testing/resources/javascript/bug_494057.in +++ /dev/null @@ -1,116 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R - /AcroForm 4 0 R - /OpenAction 10 0 R ->> -endobj -{{object 2 0}} << - /Type /Pages - /Count 1 - /Kids [ - 3 0 R - ] ->> -endobj -% Page number 0. -{{object 3 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /Contents [21 0 R] - /MediaBox [0 0 612 792] ->> -endobj -% Forms -{{object 4 0}} << - /Fields [5 0 R] ->> -endobj -% Fields -{{object 5 0}} << - /T (MyField) - /Type /Annot - /Subtype /Widget - /Rect [100 100 400 400] - /Kids [ - 6 0 R - 7 0 R - 8 0 R - 9 0 R - ] ->> -endobj -{{object 6 0}} << - /FT /Tx - /Parent 5 0 R - /T (Sub_X) - /Type /Annot - /Subtype /Widget - /Rect [200 200 220 220] ->> -endobj -{{object 7 0}} << - /FT /Tx - /Parent 5 0 R - /T (Sub_A) - /Type /Annot - /Subtype /Widget - /Rect [220 220 240 240] ->> -endobj -{{object 8 0}} << - /FT /Tx - /Parent 5 0 R - /T (Sub_Z) - /Type /Annot - /Subtype /Widget - /Rect [240 240 260 260] ->> -endobj -{{object 9 0}} << - /FT /Tx - /Parent 5 0 R - /T (Sub_B) - /Type /Annot - /Subtype /Widget - /Rect [260 260 280 280] ->> -endobj -% OpenAction action -{{object 10 0}} << - /Type /Action - /S /JavaScript - /JS 11 0 R ->> -endobj -% JS program to exexute -{{object 11 0}} << ->> -stream -function TestGetFieldWithDelay() { - try { - var ff = this.getField("MyField"); - app.alert("field is " + ff.name); - app.alert("field value is '" + ff.value + "'"); - ff.delay = true; - ff.value = "new value"; - this.delay=true; - ff.delay = false; - app.alert("field value is '" + ff.value + "'"); - } catch (e) { - app.alert("Unexpected error: " + e); - } -} -TestGetFieldWithDelay(); -endstream -endobj -{{xref}} -trailer << - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/javascript/bug_494057_expected.txt b/chromium/third_party/pdfium/testing/resources/javascript/bug_494057_expected.txt deleted file mode 100644 index 7325a1cd1fc..00000000000 --- a/chromium/third_party/pdfium/testing/resources/javascript/bug_494057_expected.txt +++ /dev/null @@ -1,3 +0,0 @@ -Alert: field is MyField -Alert: field value is '' -Alert: field value is '' diff --git a/chromium/third_party/pdfium/testing/resources/javascript/bug_679642.in b/chromium/third_party/pdfium/testing/resources/javascript/bug_679642.in deleted file mode 100644 index 2241723dd22..00000000000 --- a/chromium/third_party/pdfium/testing/resources/javascript/bug_679642.in +++ /dev/null @@ -1,140 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R - /AcroForm 4 0 R - /OpenAction 10 0 R ->> -endobj -{{object 2 0}} << - /Type /Pages - /Count 1 - /Kids [ - 3 0 R - ] ->> -endobj -% Page number 0. -{{object 3 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /Contents [21 0 R] - /MediaBox [0 0 612 792] - /Annots [7 0 R 8 0 R 9 0 R] ->> -endobj -% Forms -{{object 4 0}} << - /XFA [ - (xdp:xdp) 23 0 R - (form) 29 0 R - (</xdp:xdp>) 30 0 R - ] - /Fields [ - 5 0 R - ] ->> -endobj -% Fields -{{object 5 0}} << - /T (MyField) - /Kids [ - 6 0 R - ] - /Rect [100 100 400 400] ->> -endobj -{{object 6 0}} << - /Parent 5 0 R - /FT /Btn - /Kids [ - 7 0 R - 8 0 R - 9 0 R - ] - /Rect [200 200 220 220] ->> -endobj -{{object 7 0}} << - /Parent 6 0 R - /Type /Annot - /Subtype /Widget - /Rect [220 220 240 240] ->> -endobj -{{object 8 0}} << - /Parent 6 0 R - /Type /Annot - /Subtype /Widget - /Rect [240 240 260 260] ->> -endobj -{{object 9 0}} << - /Parent 6 0 R - /Type /Annot - /Subtype /Widget - /Rect [240 240 260 260] ->> -endobj -% OpenAction action -{{object 10 0}} << - /Type /Action - /S /JavaScript - /JS 11 0 R ->> -endobj -% JS program to exexute -{{object 11 0}} << ->> -stream -var theName = "MyField"; -function Mangles() { - app.alert('Starting ...'); - try { - var f = this.getField(theName); - Object.defineProperty(Array.prototype, 1, { - get: () => { - return this[1]; - }, - set: (v) => { - app.alert('Firing ...'); - this.removeField(theName); - gc(); - return false; - }, - enumerable: true - }); - f.page; - } catch (e) { - app.alert("failed: " + e); - } -} -Mangles(); -endstream -endobj -{{object 23 0}} << ->>stream -<?xml version="1.0" encoding="UTF-8"?> -<xdp:xdp xmlns:xdp="http://ns.adobe.com/xdp/"> -endstream -endobj -{{object 29 0}} << ->>stream -<config></config> -<template></template> -endstream -endobj -{{object 30 0}} << ->>stream -</xdp:xdp> -endstream -endobj -{{xref}} -trailer << - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/javascript/bug_679642_expected.txt b/chromium/third_party/pdfium/testing/resources/javascript/bug_679642_expected.txt deleted file mode 100644 index 9e99cc6883f..00000000000 --- a/chromium/third_party/pdfium/testing/resources/javascript/bug_679642_expected.txt +++ /dev/null @@ -1,3 +0,0 @@ -Alert: Starting ... -Alert: Firing ... -Alert: failed: Field.page: Object no longer exists. diff --git a/chromium/third_party/pdfium/testing/resources/javascript/bug_679643.in b/chromium/third_party/pdfium/testing/resources/javascript/bug_679643.in deleted file mode 100644 index e9643860f7e..00000000000 --- a/chromium/third_party/pdfium/testing/resources/javascript/bug_679643.in +++ /dev/null @@ -1,135 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R - /AcroForm 4 0 R - /OpenAction 10 0 R ->> -endobj -{{object 2 0}} << - /Type /Pages - /Count 1 - /Kids [ - 3 0 R - ] ->> -endobj -% Page number 0. -{{object 3 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /Contents [21 0 R] - /MediaBox [0 0 612 792] - /Annots [7 0 R 8 0 R 9 0 R] ->> -endobj -% Forms -{{object 4 0}} << - /XFA [ - (xdp:xdp) 23 0 R - (form) 29 0 R - (</xdp:xdp>) 30 0 R - ] - /Fields [ - 5 0 R - ] ->> -endobj -% Fields -{{object 5 0}} << - /T (MyField) - /Kids [ - 6 0 R - ] - /Rect [100 100 400 400] ->> -endobj -{{object 6 0}} << - /Parent 5 0 R - /FT /Btn - /Kids [ - 7 0 R - 8 0 R - 9 0 R - ] - /Rect [200 200 220 220] ->> -endobj -{{object 7 0}} << - /Parent 6 0 R - /Type /Annot - /Subtype /Widget - /Rect [220 220 240 240] ->> -endobj -{{object 8 0}} << - /Parent 6 0 R - /Type /Annot - /Subtype /Widget - /Rect [240 240 260 260] ->> -endobj -{{object 9 0}} << - /Parent 6 0 R - /Type /Annot - /Subtype /Widget - /Rect [240 240 260 260] ->> -endobj -% OpenAction action -{{object 10 0}} << - /Type /Action - /S /JavaScript - /JS 11 0 R ->> -endobj -% JS program to exexute -{{object 11 0}} << ->> -stream -var theName = "MyField"; -function Mangles() { - app.alert('Starting ...'); - try { - var annots = this.getAnnots(); - annots[0].name = { - toString: () => { - app.alert('Firing ...'); - this.removeField(theName); - gc(); - return false; - } - }; - } catch (e) { - app.alert("failed: " + e); - } -} -Mangles(); -endstream -endobj -{{object 23 0}} << ->>stream -<?xml version="1.0" encoding="UTF-8"?> -<xdp:xdp xmlns:xdp="http://ns.adobe.com/xdp/"> -endstream -endobj -{{object 29 0}} << ->>stream -<config></config> -<template></template> -endstream -endobj -{{object 30 0}} << ->>stream -</xdp:xdp> -endstream -endobj -{{xref}} -trailer << - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/javascript/bug_679643_expected.txt b/chromium/third_party/pdfium/testing/resources/javascript/bug_679643_expected.txt deleted file mode 100644 index 36d4a313440..00000000000 --- a/chromium/third_party/pdfium/testing/resources/javascript/bug_679643_expected.txt +++ /dev/null @@ -1,3 +0,0 @@ -Alert: Starting ... -Alert: Firing ... -Alert: failed: Annot.name: Object no longer exists. diff --git a/chromium/third_party/pdfium/testing/resources/javascript/bug_695826.in b/chromium/third_party/pdfium/testing/resources/javascript/bug_695826.in deleted file mode 100644 index b20908bc79b..00000000000 --- a/chromium/third_party/pdfium/testing/resources/javascript/bug_695826.in +++ /dev/null @@ -1,47 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R - /OpenAction 10 0 R ->> -endobj -{{object 2 0}} << - /Type /Pages - /Count 1 - /Kids [ - 3 0 R - ] ->> -endobj -% Page number 0. -{{object 3 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /Contents [21 0 R] - /MediaBox [0 0 612 792] ->> -% OpenAction action -{{object 10 0}} << - /Type /Action - /S /JavaScript - /JS 11 0 R ->> -endobj -% JS program to exexute -{{object 11 0}} << ->> -stream -var obj = new this.constructor; -obj.author = 3; -app.alert('Done!'); -endstream -endobj -{{xref}} -trailer << - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/javascript/bug_695826_expected.txt b/chromium/third_party/pdfium/testing/resources/javascript/bug_695826_expected.txt deleted file mode 100644 index 5bb6e859663..00000000000 --- a/chromium/third_party/pdfium/testing/resources/javascript/bug_695826_expected.txt +++ /dev/null @@ -1 +0,0 @@ -Alert: Done! diff --git a/chromium/third_party/pdfium/testing/resources/javascript/consts.in b/chromium/third_party/pdfium/testing/resources/javascript/consts.in deleted file mode 100644 index 6fb82158e3d..00000000000 --- a/chromium/third_party/pdfium/testing/resources/javascript/consts.in +++ /dev/null @@ -1,137 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R - /OpenAction 10 0 R ->> -endobj -{{object 2 0}} << - /Type /Pages - /Count 1 - /Kids [ - 3 0 R - ] ->> -endobj -% Page number 0. -{{object 3 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /Contents [21 0 R] - /MediaBox [0 0 612 792] ->> -% OpenAction action -{{object 10 0}} << - /Type /Action - /S /JavaScript - /JS 11 0 R ->> -endobj -% JS program to exexute -{{object 11 0}} << ->> -stream - -function doTest(name, props) { - try { - for (var i = 0; i < props.length; ++i) { - var expr = name + "." + props[i]; - app.alert(expr + " is " + eval(expr)); - } - } catch (e) { - app.alert("ERROR: " + e.toString()); - } -} - -function doGlobalTest(props) { - try { - for (var i = 0; i < props.length; ++i) { - app.alert(props[i] + " is " + eval(props[i])); - } - } catch (e) { - app.alert("ERROR: " + e.toString()); - } -} - -function doGlobalArrayTest(props) { - try { - for (var i = 0; i < props.length; ++i) { - app.alert(props[i] + " is\n " + eval(props[i]).join(",\n ")); - } - } catch (e) { - app.alert("ERROR: " + e.toString()); - } -} - -function doEqualityTests() { - app.alert("String equality test (==): " + - (IDS_GREATER_THAN == IDS_GREATER_THAN)); - app.alert("String equality test (===): " + - (IDS_GREATER_THAN === IDS_GREATER_THAN)); - app.alert("Array equality test (==): " + - (RE_PHONE_COMMIT == RE_PHONE_COMMIT)); - app.alert("Array equality test (===): " + - (RE_PHONE_COMMIT === RE_PHONE_COMMIT)); -} - -try { - doTest("border", ["s", "b", "d", "i", "u", "nonesuch"]); - doTest("display", ["visible", "hidden", "noPrint", "noView", "nonesuch"]); - doTest("font", ["Times", "TimesB", "TimesI", "TimesBI", "Helv", "HelvB", - "HelvI", "HelvBI", "Cour", "CourB", "CourI", "CourBI", - "Symbol", "ZapfD", "Nonesuch"]); - - doTest("highlight", ["n", "i", "p", "o", "nonesuch"]); - doTest("position", ["textOnly", "iconOnly", "iconTextV", "textIconV", - "iconTextH", "textIconH", "overlay", "nonesuch"]); - - doTest("scaleHow", ["proportional", "anamorphic", "nonesuch"]); - doTest("scaleWhen", ["always", "never", "tooBig", "tooSmall", "nonesuch"]); - doTest("style", ["ch", "cr", "di", "ci", "st", "sq", "nonesuch"]); - doTest("zoomtype", ["none", "fitP", "fitW", "fitH", "fitV", "pref", "refW", - "nonesuch"]); - - doGlobalTest([ - "IDS_GREATER_THAN", - "IDS_GT_AND_LT", - "IDS_LESS_THAN", - "IDS_INVALID_MONTH", - "IDS_INVALID_DATE", - "IDS_INVALID_VALUE", - "IDS_AM", - "IDS_PM", - "IDS_MONTH_INFO", - "IDS_STARTUP_CONSOLE_MSG" - ]); - - doGlobalArrayTest([ - "RE_NUMBER_ENTRY_DOT_SEP", - "RE_NUMBER_COMMIT_DOT_SEP", - "RE_NUMBER_ENTRY_COMMA_SEP", - "RE_NUMBER_COMMIT_COMMA_SEP", - "RE_ZIP_ENTRY", - "RE_ZIP_COMMIT", - "RE_ZIP4_ENTRY", - "RE_ZIP4_COMMIT", - "RE_PHONE_ENTRY", - "RE_PHONE_COMMIT", - "RE_SSN_ENTRY", - "RE_SSN_COMMIT" - ]); - - doEqualityTests(); -} catch (e) { - app.alert("ERROR: " + e.toString()); -} -endstream -endobj -{{xref}} -trailer << - /Root 1 0 R ->> -{{startxref}} -%%EOF - diff --git a/chromium/third_party/pdfium/testing/resources/javascript/consts_expected.txt b/chromium/third_party/pdfium/testing/resources/javascript/consts_expected.txt deleted file mode 100644 index a2d29a99731..00000000000 --- a/chromium/third_party/pdfium/testing/resources/javascript/consts_expected.txt +++ /dev/null @@ -1,112 +0,0 @@ -Alert: border.s is solid -Alert: border.b is beveled -Alert: border.d is dashed -Alert: border.i is inset -Alert: border.u is underline -Alert: border.nonesuch is undefined -Alert: display.visible is 0 -Alert: display.hidden is 1 -Alert: display.noPrint is 2 -Alert: display.noView is 3 -Alert: display.nonesuch is undefined -Alert: font.Times is Times-Roman -Alert: font.TimesB is Times-Bold -Alert: font.TimesI is Times-Italic -Alert: font.TimesBI is Times-BoldItalic -Alert: font.Helv is Helvetica -Alert: font.HelvB is Helvetica-Bold -Alert: font.HelvI is Helvetica-Oblique -Alert: font.HelvBI is Helvetica-BoldOblique -Alert: font.Cour is Courier -Alert: font.CourB is Courier-Bold -Alert: font.CourI is Courier-Oblique -Alert: font.CourBI is Courier-BoldOblique -Alert: font.Symbol is Symbol -Alert: font.ZapfD is ZapfDingbats -Alert: font.Nonesuch is undefined -Alert: highlight.n is none -Alert: highlight.i is invert -Alert: highlight.p is push -Alert: highlight.o is outline -Alert: highlight.nonesuch is undefined -Alert: position.textOnly is 0 -Alert: position.iconOnly is 1 -Alert: position.iconTextV is 2 -Alert: position.textIconV is 3 -Alert: position.iconTextH is 4 -Alert: position.textIconH is 5 -Alert: position.overlay is 6 -Alert: position.nonesuch is undefined -Alert: scaleHow.proportional is 0 -Alert: scaleHow.anamorphic is 1 -Alert: scaleHow.nonesuch is undefined -Alert: scaleWhen.always is 0 -Alert: scaleWhen.never is 1 -Alert: scaleWhen.tooBig is 2 -Alert: scaleWhen.tooSmall is 3 -Alert: scaleWhen.nonesuch is undefined -Alert: style.ch is check -Alert: style.cr is cross -Alert: style.di is diamond -Alert: style.ci is circle -Alert: style.st is star -Alert: style.sq is square -Alert: style.nonesuch is undefined -Alert: zoomtype.none is NoVary -Alert: zoomtype.fitP is FitPage -Alert: zoomtype.fitW is FitWidth -Alert: zoomtype.fitH is FitHeight -Alert: zoomtype.fitV is FitVisibleWidth -Alert: zoomtype.pref is Preferred -Alert: zoomtype.refW is ReflowWidth -Alert: zoomtype.nonesuch is undefined -Alert: IDS_GREATER_THAN is Invalid value: must be greater than or equal to % s. -Alert: IDS_GT_AND_LT is Invalid value: must be greater than or equal to % s and less than or equal to % s. -Alert: IDS_LESS_THAN is Invalid value: must be less than or equal to % s. -Alert: IDS_INVALID_MONTH is **Invalid** -Alert: IDS_INVALID_DATE is Invalid date / time: please ensure that the date / time exists.Field -Alert: IDS_INVALID_VALUE is The value entered does not match the format of the field -Alert: IDS_AM is am -Alert: IDS_PM is pm -Alert: IDS_MONTH_INFO is January[1] February[2] March[3] April[4] May[5] June[6] July[7] August[8] September[9] October[10] November[11] December[12] Sept[9] Jan[1] Feb[2] Mar[3] Apr[4] Jun[6] Jul[7] Aug[8] Sep[9] Oct[10] Nov[11] Dec[12] -Alert: IDS_STARTUP_CONSOLE_MSG is ** ^ _ ^ ** -Alert: RE_NUMBER_ENTRY_DOT_SEP is - [+-]?\d*\.?\d* -Alert: RE_NUMBER_COMMIT_DOT_SEP is - [+-]?\d+(\.\d+)?, - [+-]?\.\d+, - [+-]?\d+\. -Alert: RE_NUMBER_ENTRY_COMMA_SEP is - [+-]?\d*,?\d* -Alert: RE_NUMBER_COMMIT_COMMA_SEP is - [+-]?\d+([.,]\d+)?, - [+-]?[.,]\d+, - [+-]?\d+[.,] -Alert: RE_ZIP_ENTRY is - \d{0,5} -Alert: RE_ZIP_COMMIT is - \d{5} -Alert: RE_ZIP4_ENTRY is - \d{0,5}(\.|[- ])?\d{0,4} -Alert: RE_ZIP4_COMMIT is - \d{5}(\.|[- ])?\d{4} -Alert: RE_PHONE_ENTRY is - \d{0,3}(\.|[- ])?\d{0,3}(\.|[- ])?\d{0,4}, - \(\d{0,3}, - \(\d{0,3}\)(\.|[- ])?\d{0,3}(\.|[- ])?\d{0,4}, - \(\d{0,3}(\.|[- ])?\d{0,3}(\.|[- ])?\d{0,4}, - \d{0,3}\)(\.|[- ])?\d{0,3}(\.|[- ])?\d{0,4}, - 011(\.|[- \d])* -Alert: RE_PHONE_COMMIT is - \d{3}(\.|[- ])?\d{4}, - \d{3}(\.|[- ])?\d{3}(\.|[- ])?\d{4}, - \(\d{3}\)(\.|[- ])?\d{3}(\.|[- ])?\d{4}, - 011(\.|[- \d])* -Alert: RE_SSN_ENTRY is - \d{0,3}(\.|[- ])?\d{0,2}(\.|[- ])?\d{0,4} -Alert: RE_SSN_COMMIT is - \d{3}(\.|[- ])?\d{2}(\.|[- ])?\d{4} -Alert: String equality test (==): true -Alert: String equality test (===): true -Alert: Array equality test (==): true -Alert: Array equality test (===): true diff --git a/chromium/third_party/pdfium/testing/resources/javascript/document_methods.in b/chromium/third_party/pdfium/testing/resources/javascript/document_methods.in deleted file mode 100644 index 8c5a14a59ee..00000000000 --- a/chromium/third_party/pdfium/testing/resources/javascript/document_methods.in +++ /dev/null @@ -1,355 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R - /OpenAction 10 0 R ->> -endobj -{{object 2 0}} << - /Type /Pages - /Count 4 - /Kids [ - 3 0 R - 4 0 R - 5 0 R - 6 0 R - ] ->> -endobj -% Page number 0. -{{object 3 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /MediaBox [0 0 612 792] - /Contents 8 0 R ->> -% Page number 1. -{{object 4 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /MediaBox [0 0 612 792] ->> -% Page number 2. -{{object 5 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /MediaBox [0 0 612 792] ->> -% Page number 3. -{{object 6 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /MediaBox [0 0 612 792] ->> -% Contents of the page. -{{object 8 0}} << ->> -stream -BT -20 50 Td -/F1 12 Tf -(Hello, world!) Tj -0 50 Td -endstream -endobj -% Info -{{object 9 0}} << - /Author (Joe Random Author) - /Creator (Joe Random Creator) ->> -endobj -% OpenAction action -{{object 10 0}} << - /Type /Action - /S /JavaScript - /JS 11 0 R ->> -endobj -% JS program to exexute -{{object 11 0}} << ->> -stream -function expect(str, expected) { - try { - var result = eval(str); - if (result == expected) { - app.alert('PASS: ' + str + ' = ' + result); - } else { - app.alert('FAIL: ' + str + ' = ' + result + ', expected = ' + expected); - } - } catch (e) { - app.alert('ERROR: ' + e.toString()); - } -} - -function expectError(str) { - try { - var result = eval(str); - app.alert('FAIL: ' + str + ' = ' + result + ', expected to throw error'); - } catch (e) { - app.alert('PASS: ' + str + ' threw error ' + e.toString()); - } -} - -// "Unsupported" methods are present in the document object, but not -// implemented. They always return |undefined| regardless of arguments. -function testUnsupported(str) { - expect('typeof ' + str, 'function'); - expect(str + '()', undefined); - expect(str + '(1, 2, "clams", [1, 2, 3])', undefined); -} - -function testAddIcon() { - // Method is present. - expect('typeof this.addIcon', 'function'); - - // Method takes exactly two arguments. - expectError('this.addIcon()'); - expectError('this.addIcon(1)'); - expectError('this.addIcon(1, 2, 3)'); - - // Second argument must actually be an icon. - expectError('this.addIcon("myicon", 3)'); - expectError('this.addIcon("myicon", undefined)'); - - // TODO(tsepez): test success cases. -} - -function testCalculateNow() { - // Method is present. - expect('typeof this.calculateNow', 'function'); - - // TODO(tsepez): test with no permissions. - // TODO(tsepez): test success cases. -} - -function testGetAnnot() { - // Method is present. - expect('typeof this.getAnnot', 'function'); - - // Method needs two arguments. - expectError('this.getAnnot()'); - expectError('this.getAnnot(0)'); - expectError('this.getAnnot(0, "test", 0)'); - - // TODO(tonikitoo): test success cases. -} - -function testGetAnnots() { - // Method is present. - expect('typeof this.getAnnots', 'function'); - - // TODO(tonikitoo): test success cases. -} - -function testGetField() { - // Method is present. - expect('typeof this.getField', 'function'); - - // Method needs at least one argument. - expectError('this.getField()'); - - // TODO(tsepez): test success cases. -} - -function testGetIcon() { - // Method is present. - expect('typeof this.getIcon', 'function'); - - // Method needs exactly one argument. - expectError('this.getIcon()'); - expectError('this.getIcon(1, 2)'); - - // TODO(tsepez): test success cases. -} - -function testGetNthFieldName() { - // Method is present. - expect('typeof this.getNthFieldName', 'function'); - - // Method needs at least one argument. - expectError('this.getNthFieldName()'); - - // Argument can not be negative. - expectError('this.getNthFieldName(-1)'); - - // TODO(tsepez): test success cases. -} - -function testGetPageNthWord() { - // Method is present. - expect('typeof this.getPageNthWord', 'function'); - - // Method accepts any number of parameters. - expect('this.getPageNthWord(0, 0, true, "clams", [1, 2])', 'Hello,'); - - // Arguments can't be negative or out of range. - expectError('this.getPageNthWord(-1, 0, true)'); - expectError('this.getPageNthWord(6, 0, true)'); - - // TODO(tsepez): test with no permissions. - // TODO(tsepez): test success cases. -} - -function testGetPageNthWordQuads() { - // Method is present. - expect('typeof this.getPageNthWordQuads', 'function'); - - // TODO(tsepez): test with no permissions. - // TODO(tsepez): test success cases. -} - -function testGetPageNumWords() { - // Method is present. - expect('typeof this.getPageNumWords', 'function'); - - // Method accepts any number of parameters. - expect('this.getPageNumWords(0, "clams", [1, 2])', 2); - - // Arguments can't be negative or out of range. - expectError('this.getPageNumWords(-1)'); - expectError('this.getPageNumWords(6)'); - - // TODO(tsepez): test with no permissions. - // TODO(tsepez): test success cases. -} - -function testGetPrintParams() { - // Method is present. - expect('typeof this.getPrintParams', 'function'); - - // TODO(tsepez): test success cases. -} - -function testGotoNamedDest() { - // Method is present. - expect('typeof this.gotoNamedDest', 'function'); - - // Method needs exactly one argument. - expectError('this.gotoNamedDest()'); - expectError('this.gotoNamedDest(1, 2)'); - - // TODO(tonikitoo): test success cases. -} - -function testMailDoc() { - // Method is present. - expect('typeof this.mailDoc', 'function'); - - // TODO(tsepez): test with no permissions. - // TODO(tsepez): test success cases. -} - -function testMailForm() { - // Method is present. - expect('typeof this.mailForm', 'function'); - - // TODO(tsepez): test with no permissions. - // TODO(tsepez): test success cases. -} - -function testPrint() { - // Method is present. - expect('typeof this.print', 'function'); - - // TODO(tsepez): test success cases. -} - -function testRemoveField() { - // Method is present. - expect('typeof this.removeField', 'function'); - - // Method requires at least one argument. - expectError('this.removeField()'); - - // TODO(tsepez): test with no permissions. - // TODO(tsepez): test success cases. -} - -function testResetForm() { - // Method is present. - expect('typeof this.resetForm', 'function'); - - // TODO(tsepez): test with no permissions. - // TODO(tsepez): test success cases. -} - -function testSubmitForm() { - // Method is present. - expect('typeof this.submitForm', 'function'); - - // Method requires at least one argument. - expectError('this.submitForm()'); - - // TODO(tsepez): test success cases. -} - -try { - app.alert('*** Testing Unsupported Methods ***'); - testUnsupported('this.addAnnot'); - testUnsupported('this.addField'); - testUnsupported('this.addLink'); - testUnsupported('this.closeDoc'); - testUnsupported('this.createDataObject'); - testUnsupported('this.deletePages'); - testUnsupported('this.exportAsFDF'); - testUnsupported('this.exportAsText'); - testUnsupported('this.exportAsXFDF'); - testUnsupported('this.extractPages'); - testUnsupported('this.getAnnot3D'); - testUnsupported('this.getLinks'); - testUnsupported('this.getOCGs'); - testUnsupported('this.getPageBox'); - testUnsupported('this.getURL'); - testUnsupported('this.importAnFDF'); - testUnsupported('this.importAnXFDF'); - testUnsupported('this.importTextData'); - testUnsupported('this.insertPages'); - testUnsupported('this.removeIcon'); - testUnsupported('this.replacePages'); - testUnsupported('this.saveAs'); - testUnsupported('this.syncAnnotScan'); - - app.alert('*** Testing Supported Methods ***'); - testAddIcon(); - testCalculateNow(); - testGetAnnot(); - testGetAnnots(); - testGetField(); - testGetIcon(); - testGetNthFieldName(); - testGetPageNthWord(); - testGetPageNthWordQuads(); - testGetPageNumWords(); - testGetPrintParams(); - testGotoNamedDest(); - testMailDoc(); - testMailForm(); - testPrint(); - testRemoveField(); - testResetForm(); - testSubmitForm(); -} catch (e) { - app.alert('FATAL: ' + e.toString()); -} -endstream -endobj -{{xref}} -trailer << - /Root 1 0 R - /Info 9 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/javascript/document_methods_expected.txt b/chromium/third_party/pdfium/testing/resources/javascript/document_methods_expected.txt deleted file mode 100644 index 4a2c4d7ee65..00000000000 --- a/chromium/third_party/pdfium/testing/resources/javascript/document_methods_expected.txt +++ /dev/null @@ -1,112 +0,0 @@ -Alert: *** Testing Unsupported Methods *** -Alert: PASS: typeof this.addAnnot = function -Alert: PASS: this.addAnnot() = undefined -Alert: PASS: this.addAnnot(1, 2, "clams", [1, 2, 3]) = undefined -Alert: PASS: typeof this.addField = function -Alert: PASS: this.addField() = undefined -Alert: PASS: this.addField(1, 2, "clams", [1, 2, 3]) = undefined -Alert: PASS: typeof this.addLink = function -Alert: PASS: this.addLink() = undefined -Alert: PASS: this.addLink(1, 2, "clams", [1, 2, 3]) = undefined -Alert: PASS: typeof this.closeDoc = function -Alert: PASS: this.closeDoc() = undefined -Alert: PASS: this.closeDoc(1, 2, "clams", [1, 2, 3]) = undefined -Alert: PASS: typeof this.createDataObject = function -Alert: PASS: this.createDataObject() = undefined -Alert: PASS: this.createDataObject(1, 2, "clams", [1, 2, 3]) = undefined -Alert: PASS: typeof this.deletePages = function -Alert: PASS: this.deletePages() = undefined -Alert: PASS: this.deletePages(1, 2, "clams", [1, 2, 3]) = undefined -Alert: PASS: typeof this.exportAsFDF = function -Alert: PASS: this.exportAsFDF() = undefined -Alert: PASS: this.exportAsFDF(1, 2, "clams", [1, 2, 3]) = undefined -Alert: PASS: typeof this.exportAsText = function -Alert: PASS: this.exportAsText() = undefined -Alert: PASS: this.exportAsText(1, 2, "clams", [1, 2, 3]) = undefined -Alert: PASS: typeof this.exportAsXFDF = function -Alert: PASS: this.exportAsXFDF() = undefined -Alert: PASS: this.exportAsXFDF(1, 2, "clams", [1, 2, 3]) = undefined -Alert: PASS: typeof this.extractPages = function -Alert: PASS: this.extractPages() = undefined -Alert: PASS: this.extractPages(1, 2, "clams", [1, 2, 3]) = undefined -Alert: PASS: typeof this.getAnnot3D = function -Alert: PASS: this.getAnnot3D() = undefined -Alert: PASS: this.getAnnot3D(1, 2, "clams", [1, 2, 3]) = undefined -Alert: PASS: typeof this.getLinks = function -Alert: PASS: this.getLinks() = undefined -Alert: PASS: this.getLinks(1, 2, "clams", [1, 2, 3]) = undefined -Alert: PASS: typeof this.getOCGs = function -Alert: PASS: this.getOCGs() = undefined -Alert: PASS: this.getOCGs(1, 2, "clams", [1, 2, 3]) = undefined -Alert: PASS: typeof this.getPageBox = function -Alert: PASS: this.getPageBox() = undefined -Alert: PASS: this.getPageBox(1, 2, "clams", [1, 2, 3]) = undefined -Alert: PASS: typeof this.getURL = function -Alert: PASS: this.getURL() = undefined -Alert: PASS: this.getURL(1, 2, "clams", [1, 2, 3]) = undefined -Alert: PASS: typeof this.importAnFDF = function -Alert: PASS: this.importAnFDF() = undefined -Alert: PASS: this.importAnFDF(1, 2, "clams", [1, 2, 3]) = undefined -Alert: PASS: typeof this.importAnXFDF = function -Alert: PASS: this.importAnXFDF() = undefined -Alert: PASS: this.importAnXFDF(1, 2, "clams", [1, 2, 3]) = undefined -Alert: PASS: typeof this.importTextData = function -Alert: PASS: this.importTextData() = undefined -Alert: PASS: this.importTextData(1, 2, "clams", [1, 2, 3]) = undefined -Alert: PASS: typeof this.insertPages = function -Alert: PASS: this.insertPages() = undefined -Alert: PASS: this.insertPages(1, 2, "clams", [1, 2, 3]) = undefined -Alert: PASS: typeof this.removeIcon = function -Alert: PASS: this.removeIcon() = undefined -Alert: PASS: this.removeIcon(1, 2, "clams", [1, 2, 3]) = undefined -Alert: PASS: typeof this.replacePages = function -Alert: PASS: this.replacePages() = undefined -Alert: PASS: this.replacePages(1, 2, "clams", [1, 2, 3]) = undefined -Alert: PASS: typeof this.saveAs = function -Alert: PASS: this.saveAs() = undefined -Alert: PASS: this.saveAs(1, 2, "clams", [1, 2, 3]) = undefined -Alert: PASS: typeof this.syncAnnotScan = function -Alert: PASS: this.syncAnnotScan() = undefined -Alert: PASS: this.syncAnnotScan(1, 2, "clams", [1, 2, 3]) = undefined -Alert: *** Testing Supported Methods *** -Alert: PASS: typeof this.addIcon = function -Alert: PASS: this.addIcon() threw error Document.addIcon: Incorrect number of parameters passed to function. -Alert: PASS: this.addIcon(1) threw error Document.addIcon: Incorrect number of parameters passed to function. -Alert: PASS: this.addIcon(1, 2, 3) threw error Document.addIcon: Incorrect number of parameters passed to function. -Alert: PASS: this.addIcon("myicon", 3) threw error Document.addIcon: Incorrect parameter type. -Alert: PASS: this.addIcon("myicon", undefined) threw error Document.addIcon: Incorrect parameter type. -Alert: PASS: typeof this.calculateNow = function -Alert: PASS: typeof this.getAnnot = function -Alert: PASS: this.getAnnot() threw error Document.getAnnot: Incorrect number of parameters passed to function. -Alert: PASS: this.getAnnot(0) threw error Document.getAnnot: Incorrect number of parameters passed to function. -Alert: PASS: this.getAnnot(0, "test", 0) threw error Document.getAnnot: Incorrect number of parameters passed to function. -Alert: PASS: typeof this.getAnnots = function -Alert: PASS: typeof this.getField = function -Alert: PASS: this.getField() threw error Document.getField: Incorrect number of parameters passed to function. -Alert: PASS: typeof this.getIcon = function -Alert: PASS: this.getIcon() threw error Document.getIcon: Incorrect number of parameters passed to function. -Alert: PASS: this.getIcon(1, 2) threw error Document.getIcon: Incorrect number of parameters passed to function. -Alert: PASS: typeof this.getNthFieldName = function -Alert: PASS: this.getNthFieldName() threw error Document.getNthFieldName: Incorrect number of parameters passed to function. -Alert: PASS: this.getNthFieldName(-1) threw error Document.getNthFieldName: Incorrect parameter value. -Alert: PASS: typeof this.getPageNthWord = function -Alert: PASS: this.getPageNthWord(0, 0, true, "clams", [1, 2]) = Hello, -Alert: PASS: this.getPageNthWord(-1, 0, true) threw error Document.getPageNthWord: Incorrect parameter value. -Alert: PASS: this.getPageNthWord(6, 0, true) threw error Document.getPageNthWord: Incorrect parameter value. -Alert: PASS: typeof this.getPageNthWordQuads = function -Alert: PASS: typeof this.getPageNumWords = function -Alert: PASS: this.getPageNumWords(0, "clams", [1, 2]) = 2 -Alert: PASS: this.getPageNumWords(-1) threw error Document.getPageNumWords: Incorrect parameter value. -Alert: PASS: this.getPageNumWords(6) threw error Document.getPageNumWords: Incorrect parameter value. -Alert: PASS: typeof this.getPrintParams = function -Alert: PASS: typeof this.gotoNamedDest = function -Alert: PASS: this.gotoNamedDest() threw error Document.gotoNamedDest: Incorrect number of parameters passed to function. -Alert: PASS: this.gotoNamedDest(1, 2) threw error Document.gotoNamedDest: Incorrect number of parameters passed to function. -Alert: PASS: typeof this.mailDoc = function -Alert: PASS: typeof this.mailForm = function -Alert: PASS: typeof this.print = function -Alert: PASS: typeof this.removeField = function -Alert: PASS: this.removeField() threw error Document.removeField: Incorrect number of parameters passed to function. -Alert: PASS: typeof this.resetForm = function -Alert: PASS: typeof this.submitForm = function -Alert: PASS: this.submitForm() threw error Document.submitForm: Incorrect number of parameters passed to function. diff --git a/chromium/third_party/pdfium/testing/resources/javascript/document_props.in b/chromium/third_party/pdfium/testing/resources/javascript/document_props.in deleted file mode 100644 index 1882f79c8a4..00000000000 --- a/chromium/third_party/pdfium/testing/resources/javascript/document_props.in +++ /dev/null @@ -1,144 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R - /OpenAction 10 0 R ->> -endobj -{{object 2 0}} << - /Type /Pages - /Count 4 - /Kids [ - 3 0 R - 4 0 R - 5 0 R - 6 0 R - ] ->> -endobj -% Page number 0. -{{object 3 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /MediaBox [0 0 612 792] ->> -% Page number 1. -{{object 4 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /MediaBox [0 0 612 792] ->> -% Page number 2. -{{object 5 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /MediaBox [0 0 612 792] ->> -% Page number 3. -{{object 6 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /MediaBox [0 0 612 792] ->> - -% Info -{{object 9 0}} << - /Author (Joe Random Author) - /Creator (Joe Random Creator) ->> -endobj -% OpenAction action -{{object 10 0}} << - /Type /Action - /S /JavaScript - /JS 11 0 R ->> -endobj -% JS program to exexute -{{object 11 0}} << ->> -stream -var document_props = [ - 'ADBE', - 'author', - 'baseURL', - 'bookmarkRoot', - 'calculate', - 'Collab', - 'creationDate', - 'creator', - 'delay', - 'dirty', - 'documentFileName', - 'external', - 'filesize', - 'icons', - 'info', - 'keywords', - 'layout', - 'media', - 'modDate', - 'mouseX', - 'mouseY', - 'numFields', - 'numPages', - 'pageNum', - 'pageWindowRect', - 'path', - 'producer', - 'subject', - 'title', - 'URL', - 'zoom', - 'zoomType', -]; - -function testGetProps(props) { - app.alert('*** Getting properties ***'); - for (var i = 0; i < props.length; ++i) { - try { - var expr1 = "this." + props[i]; - var expr2 = "typeof " + expr1; - app.alert(expr1 + " is " + eval(expr2) + ' ' + eval(expr1)); - } catch (e) { - app.alert("ERROR: " + e.toString()); - } - } -} - -function testSetProps(props) { - app.alert('*** Setting properties ***'); - for (var i = 0; i < props.length; ++i) { - try { - var expr1 = "this." + props[i] + ' = 3;' - app.alert(expr1 + " yields " + eval(expr1)); - } catch (e) { - app.alert("ERROR: " + e.toString()); - } - } -} - -testGetProps(document_props); -testSetProps(document_props); -testGetProps(document_props); -endstream -endobj -{{xref}} -trailer << - /Root 1 0 R - /Info 9 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/javascript/document_props_expected.txt b/chromium/third_party/pdfium/testing/resources/javascript/document_props_expected.txt deleted file mode 100644 index 28172ee6094..00000000000 --- a/chromium/third_party/pdfium/testing/resources/javascript/document_props_expected.txt +++ /dev/null @@ -1,100 +0,0 @@ -Alert: *** Getting properties *** -Alert: this.ADBE is undefined undefined -Alert: this.author is string Joe Random Author -Alert: this.baseURL is string -Alert: this.bookmarkRoot is undefined undefined -Alert: this.calculate is boolean true -Alert: this.Collab is undefined undefined -Alert: this.creationDate is string -Alert: this.creator is string Joe Random Creator -Alert: this.delay is boolean false -Alert: this.dirty is boolean false -Alert: this.documentFileName is string -Alert: this.external is boolean true -Alert: this.filesize is number 0 -Alert: this.icons is undefined undefined -Alert: this.info is object [object Object] -Alert: this.keywords is string -Alert: this.layout is undefined undefined -Alert: this.media is undefined undefined -Alert: this.modDate is string -Alert: this.mouseX is undefined undefined -Alert: this.mouseY is undefined undefined -Alert: this.numFields is number 0 -Alert: this.numPages is number 4 -Alert: this.pageNum is undefined undefined -Alert: this.pageWindowRect is undefined undefined -Alert: this.path is string / -Alert: this.producer is string -Alert: this.subject is string -Alert: this.title is string -Alert: this.URL is string -Alert: this.zoom is undefined undefined -Alert: this.zoomType is undefined undefined -Alert: *** Setting properties *** -Alert: this.ADBE = 3; yields 3 -Alert: this.author = 3; yields 3 -Alert: this.baseURL = 3; yields 3 -Alert: this.bookmarkRoot = 3; yields 3 -Alert: this.calculate = 3; yields 3 -Alert: this.Collab = 3; yields 3 -Alert: this.creationDate = 3; yields 3 -Alert: this.creator = 3; yields 3 -Alert: this.delay = 3; yields 3 -Alert: this.dirty = 3; yields 3 -Alert: ERROR: Document.documentFileName: Cannot assign to readonly property. -Alert: this.external = 3; yields 3 -Alert: ERROR: Document.filesize: Cannot assign to readonly property. -Alert: ERROR: Document.icons: Cannot assign to readonly property. -Alert: ERROR: Document.info: Cannot assign to readonly property. -Alert: this.keywords = 3; yields 3 -Alert: this.layout = 3; yields 3 -Alert: this.media = 3; yields 3 -Alert: this.modDate = 3; yields 3 -Alert: this.mouseX = 3; yields 3 -Alert: this.mouseY = 3; yields 3 -Alert: ERROR: Document.numFields: Cannot assign to readonly property. -Alert: ERROR: Document.numPages: Cannot assign to readonly property. -Goto Page: 3 -Alert: this.pageNum = 3; yields 3 -Alert: this.pageWindowRect = 3; yields 3 -Alert: ERROR: Document.path: Cannot assign to readonly property. -Alert: this.producer = 3; yields 3 -Alert: this.subject = 3; yields 3 -Alert: this.title = 3; yields 3 -Alert: ERROR: Document.URL: Cannot assign to readonly property. -Alert: this.zoom = 3; yields 3 -Alert: this.zoomType = 3; yields 3 -Alert: *** Getting properties *** -Alert: this.ADBE is undefined undefined -Alert: this.author is string 3 -Alert: this.baseURL is string 3 -Alert: this.bookmarkRoot is undefined undefined -Alert: this.calculate is boolean true -Alert: this.Collab is undefined undefined -Alert: this.creationDate is string 3 -Alert: this.creator is string 3 -Alert: this.delay is boolean true -Alert: this.dirty is boolean true -Alert: this.documentFileName is string -Alert: this.external is boolean true -Alert: this.filesize is number 0 -Alert: this.icons is undefined undefined -Alert: this.info is object [object Object] -Alert: this.keywords is string 3 -Alert: this.layout is undefined undefined -Alert: this.media is undefined undefined -Alert: this.modDate is string 3 -Alert: this.mouseX is undefined undefined -Alert: this.mouseY is undefined undefined -Alert: this.numFields is number 0 -Alert: this.numPages is number 4 -Alert: this.pageNum is undefined undefined -Alert: this.pageWindowRect is undefined undefined -Alert: this.path is string / -Alert: this.producer is string 3 -Alert: this.subject is string 3 -Alert: this.title is string 3 -Alert: this.URL is string -Alert: this.zoom is undefined undefined -Alert: this.zoomType is undefined undefined diff --git a/chromium/third_party/pdfium/testing/resources/javascript/field.in b/chromium/third_party/pdfium/testing/resources/javascript/field.in deleted file mode 100644 index c23b81a604e..00000000000 --- a/chromium/third_party/pdfium/testing/resources/javascript/field.in +++ /dev/null @@ -1,126 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R - /AcroForm 4 0 R - /OpenAction 10 0 R ->> -endobj -{{object 2 0}} << - /Type /Pages - /Count 1 - /Kids [ - 3 0 R - ] ->> -endobj -% Page number 0. -{{object 3 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /Contents [21 0 R] - /MediaBox [0 0 612 792] ->> -endobj -% Forms -{{object 4 0}} << - /Fields [5 0 R] ->> -endobj -% Fields -{{object 5 0}} << - /T (MyField) - /Type /Annot - /Subtype /Widget - /Rect [100 100 400 400] - /Kids [ - 6 0 R - 7 0 R - 8 0 R - 9 0 R - ] ->> -endobj -{{object 6 0}} << - /FT /Tx - /Parent 5 0 R - /T (Sub_X) - /Type /Annot - /Subtype /Widget - /Rect [200 200 220 220] ->> -endobj -{{object 7 0}} << - /FT /Tx - /Parent 5 0 R - /T (Sub_A) - /Type /Annot - /Subtype /Widget - /Rect [220 220 240 240] ->> -endobj -{{object 8 0}} << - /FT /Tx - /Parent 5 0 R - /T (Sub_Z) - /Type /Annot - /Subtype /Widget - /Rect [240 240 260 260] ->> -endobj -{{object 9 0}} << - /FT /Tx - /Parent 5 0 R - /T (Sub_B) - /Type /Annot - /Subtype /Widget - /Rect [260 260 280 280] ->> -endobj -% OpenAction action -{{object 10 0}} << - /Type /Action - /S /JavaScript - /JS 11 0 R ->> -endobj -% JS program to exexute -{{object 11 0}} << ->> -stream -function TestGetField() { - try { - var field = this.getField("MyField"); - app.alert("field is " + field.name); - var sub_a = this.getField("MyField.Sub_A"); - app.alert("sub_a is " + sub_a.name); - var nonesuch = this.getField("MyField.nonesuch"); - app.alert("nonesuch is " + nonesuch); - } catch (e) { - app.alert("Unexpected error: " + e); - } -} -function TestGetArray() { - try { - var subs = this.getField("MyField").getArray(); - app.alert("found " + subs.length + " sub-fields:"); - for (i = 0; i < subs.length; ++i) { - app.alert(subs[i].name); - } - } catch (e) { - app.alert("Unexpected error: " + e); - } -} -TestGetField(); -TestGetArray(); -endstream -endobj -{{xref}} -trailer << - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/javascript/field_expected.txt b/chromium/third_party/pdfium/testing/resources/javascript/field_expected.txt deleted file mode 100644 index 04aafd737e4..00000000000 --- a/chromium/third_party/pdfium/testing/resources/javascript/field_expected.txt +++ /dev/null @@ -1,8 +0,0 @@ -Alert: field is MyField -Alert: sub_a is MyField.Sub_A -Alert: nonesuch is undefined -Alert: found 4 sub-fields: -Alert: MyField.Sub_A -Alert: MyField.Sub_B -Alert: MyField.Sub_X -Alert: MyField.Sub_Z diff --git a/chromium/third_party/pdfium/testing/resources/javascript/globals.in b/chromium/third_party/pdfium/testing/resources/javascript/globals.in deleted file mode 100644 index 4812101e7a2..00000000000 --- a/chromium/third_party/pdfium/testing/resources/javascript/globals.in +++ /dev/null @@ -1,159 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R - /OpenAction 10 0 R ->> -endobj -{{object 2 0}} << - /Type /Pages - /Count 1 - /Kids [ - 3 0 R - ] ->> -endobj -% Page number 0. -{{object 3 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /Contents [21 0 R] - /MediaBox [0 0 612 792] ->> -% OpenAction action -{{object 10 0}} << - /Type /Action - /S /JavaScript - /JS 11 0 R ->> -endobj -% JS program to exexute -{{object 11 0}} << ->> -stream -// The "global" object stores data in a C-like manner, and -// can theoretically persist them between sessions (though -// pdfium deliberately excludes that functionality). - -var some_object = { "colors": [ "red", "green", "blue"] }; - -var props_to_test = [ - // Cover both bool values. - { "name": "true_var", "value": true }, - { "name": "false_var", "value": false }, - - // Include both zero and a number with some fractional digits. - { "name": "zero_var", "value": 0 }, - { "name": "number_var", "value": -3.918 }, - - // TODO(tsepez): unicode doesn't seem to survive. - { "name": "string_var", "value": "This is a string" }, - - // Try a complex object. - { "name": "object_var", "value": some_object }, - - // Test null and undefined. - { "name": "null_var", "value": null }, - { "name": "undefined_var", "value": undefined } -]; - -function setup_global() { - for (var i = 0; i < props_to_test.length; ++i) { - var prop = props_to_test[i]; - try { - global[prop.name] = prop.value; - } catch (e) { - app.alert("For " + prop.name + ": Setup: ERROR: " + e.toString()); - } - } -} - -function delete_global() { - for (var i = 0; i < props_to_test.length; ++i) { - var prop = props_to_test[i]; - try { - delete global[prop.name]; - } catch (e) { - app.alert("For " + prop.name + ": Delete: ERROR: " + e.toString()); - } - } -} - -function persist_global(should_persist) { - for (var i = 0; i < props_to_test.length; ++i) { - var prop = props_to_test[i]; - try { - global.setPersistent(prop.name, should_persist); - } catch (e) { - app.alert("For " + prop.name + - ": Set Persistent: ERROR: " + e.toString()); - } - } -} - -function dump_global(msg) { - app.alert("************ " + msg + " ************"); - app.alert("Enumerable Globals:"); - for (var name in global) { - try { - app.alert(" " + name + " = " + global[name] + - ", own property = " + global.hasOwnProperty(name)); - } catch (e) { - app.alert("For " + name + ": Dump: ERROR: " + e.toString()); - } - } - app.alert("Expected Globals:"); - for (var i = 0; i < props_to_test.length; ++i) { - var prop = props_to_test[i]; - try { - var actual = global[prop.name]; - app.alert(" " + prop.name + " = " + actual); - if (actual != null && typeof actual == "object") { - app.alert(" " + actual.colors[0]); - app.alert(" " + actual.colors[1]); - app.alert(" " + actual.colors[2]); - } - } catch (e) { - app.alert("For " + prop.name + - ": Dump Expected: ERROR: " + e.toString()); - } - } -} - -dump_global("Initial State"); - -// Check that they all exist. -setup_global(); -dump_global("After Setup"); - -// Test deletion. -delete_global(); -dump_global("After Deletion"); - -// setPersistent() should be a no-op for pdfium. -setup_global(); -persist_global(false); -dump_global("After Setup and Persist false"); - -// Test setting deleted variables as persistent. -delete_global(); -persist_global(true); -dump_global("After Delete and Persist"); - -// Exit with variables marked as persistent to test whatever path -// may exist to persist them (should be igonored on pdfium). -setup_global(); -persist_global(true); -dump_global("After Setup and Persist true"); - -endstream -endobj -{{xref}} -trailer << - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/javascript/globals_expected.txt b/chromium/third_party/pdfium/testing/resources/javascript/globals_expected.txt deleted file mode 100644 index fcebd704661..00000000000 --- a/chromium/third_party/pdfium/testing/resources/javascript/globals_expected.txt +++ /dev/null @@ -1,115 +0,0 @@ -Alert: ************ Initial State ************ -Alert: Enumerable Globals: -Alert: setPersistent = function setPersistent() { [native code] }, own property = true -Alert: Expected Globals: -Alert: true_var = undefined -Alert: false_var = undefined -Alert: zero_var = undefined -Alert: number_var = undefined -Alert: string_var = undefined -Alert: object_var = undefined -Alert: null_var = undefined -Alert: undefined_var = undefined -Alert: ************ After Setup ************ -Alert: Enumerable Globals: -Alert: setPersistent = function setPersistent() { [native code] }, own property = true -Alert: true_var = true, own property = true -Alert: false_var = false, own property = true -Alert: zero_var = 0, own property = true -Alert: number_var = -3.918, own property = true -Alert: string_var = This is a string, own property = true -Alert: object_var = [object Object], own property = true -Alert: null_var = null, own property = true -Alert: undefined_var = undefined, own property = true -Alert: Expected Globals: -Alert: true_var = true -Alert: false_var = false -Alert: zero_var = 0 -Alert: number_var = -3.918 -Alert: string_var = This is a string -Alert: object_var = [object Object] -Alert: red -Alert: green -Alert: blue -Alert: null_var = null -Alert: undefined_var = undefined -Alert: ************ After Deletion ************ -Alert: Enumerable Globals: -Alert: setPersistent = function setPersistent() { [native code] }, own property = true -Alert: Expected Globals: -Alert: true_var = undefined -Alert: false_var = undefined -Alert: zero_var = undefined -Alert: number_var = undefined -Alert: string_var = undefined -Alert: object_var = undefined -Alert: null_var = undefined -Alert: undefined_var = undefined -Alert: For undefined_var: Set Persistent: ERROR: global.setPersistent: Global value not found. -Alert: ************ After Setup and Persist false ************ -Alert: Enumerable Globals: -Alert: setPersistent = function setPersistent() { [native code] }, own property = true -Alert: true_var = true, own property = true -Alert: false_var = false, own property = true -Alert: zero_var = 0, own property = true -Alert: number_var = -3.918, own property = true -Alert: string_var = This is a string, own property = true -Alert: object_var = [object Object], own property = true -Alert: null_var = null, own property = true -Alert: undefined_var = undefined, own property = true -Alert: Expected Globals: -Alert: true_var = true -Alert: false_var = false -Alert: zero_var = 0 -Alert: number_var = -3.918 -Alert: string_var = This is a string -Alert: object_var = [object Object] -Alert: red -Alert: green -Alert: blue -Alert: null_var = null -Alert: undefined_var = undefined -Alert: For true_var: Set Persistent: ERROR: global.setPersistent: Global value not found. -Alert: For false_var: Set Persistent: ERROR: global.setPersistent: Global value not found. -Alert: For zero_var: Set Persistent: ERROR: global.setPersistent: Global value not found. -Alert: For number_var: Set Persistent: ERROR: global.setPersistent: Global value not found. -Alert: For string_var: Set Persistent: ERROR: global.setPersistent: Global value not found. -Alert: For object_var: Set Persistent: ERROR: global.setPersistent: Global value not found. -Alert: For null_var: Set Persistent: ERROR: global.setPersistent: Global value not found. -Alert: For undefined_var: Set Persistent: ERROR: global.setPersistent: Global value not found. -Alert: ************ After Delete and Persist ************ -Alert: Enumerable Globals: -Alert: setPersistent = function setPersistent() { [native code] }, own property = true -Alert: Expected Globals: -Alert: true_var = undefined -Alert: false_var = undefined -Alert: zero_var = undefined -Alert: number_var = undefined -Alert: string_var = undefined -Alert: object_var = undefined -Alert: null_var = undefined -Alert: undefined_var = undefined -Alert: For undefined_var: Set Persistent: ERROR: global.setPersistent: Global value not found. -Alert: ************ After Setup and Persist true ************ -Alert: Enumerable Globals: -Alert: setPersistent = function setPersistent() { [native code] }, own property = true -Alert: true_var = true, own property = true -Alert: false_var = false, own property = true -Alert: zero_var = 0, own property = true -Alert: number_var = -3.918, own property = true -Alert: string_var = This is a string, own property = true -Alert: object_var = [object Object], own property = true -Alert: null_var = null, own property = true -Alert: undefined_var = undefined, own property = true -Alert: Expected Globals: -Alert: true_var = true -Alert: false_var = false -Alert: zero_var = 0 -Alert: number_var = -3.918 -Alert: string_var = This is a string -Alert: object_var = [object Object] -Alert: red -Alert: green -Alert: blue -Alert: null_var = null -Alert: undefined_var = undefined diff --git a/chromium/third_party/pdfium/testing/resources/javascript/util_bytetochar.in b/chromium/third_party/pdfium/testing/resources/javascript/util_bytetochar.in deleted file mode 100644 index a9adfbccaf7..00000000000 --- a/chromium/third_party/pdfium/testing/resources/javascript/util_bytetochar.in +++ /dev/null @@ -1,76 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R - /OpenAction 10 0 R ->> -endobj -{{object 2 0}} << - /Type /Pages - /Count 1 - /Kids [ - 3 0 R - ] ->> -endobj -% Page number 0. -{{object 3 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /Contents [21 0 R] - /MediaBox [0 0 612 792] ->> -% OpenAction action -{{object 10 0}} << - /Type /Action - /S /JavaScript - /JS 11 0 R ->> -endobj -% JS program to exexute -{{object 11 0}} << ->> -stream -function TestOneInput(x) { - try { - var s = util.byteToChar(x); - if (s.length) { - s = s.charCodeAt(0); - } - app.alert(x + " => " + s); - } - catch (e) { - app.alert(x + ": Caught error: " + e); - } -} -TestOneInput(0); -TestOneInput(65); -TestOneInput(127); -TestOneInput(128); -TestOneInput(255); -TestOneInput(256); -TestOneInput(40000000); -TestOneInput(-1); -try { - util.byteToChar(); -} -catch (e) { - app.alert("Caught expected error: " + e); -} -try { - util.byteToChar({x:39}); -} -catch (e) { - app.alert("Caught expected error: " + e); -} -endstream -endobj -{{xref}} -trailer << - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/javascript/util_bytetochar_expected.txt b/chromium/third_party/pdfium/testing/resources/javascript/util_bytetochar_expected.txt deleted file mode 100644 index df15ee7226a..00000000000 --- a/chromium/third_party/pdfium/testing/resources/javascript/util_bytetochar_expected.txt +++ /dev/null @@ -1,9 +0,0 @@ -Alert: 0 => -Alert: 65 => 65 -Alert: 127 => 127 -Alert: 128 => 128 -Alert: 255 => 255 -Alert: 256: Caught error: util.byteToChar: Incorrect parameter value. -Alert: 40000000: Caught error: util.byteToChar: Incorrect parameter value. -Alert: -1: Caught error: util.byteToChar: Incorrect parameter value. -Alert: Caught expected error: util.byteToChar: Incorrect number of parameters passed to function. diff --git a/chromium/third_party/pdfium/testing/resources/javascript/util_printd.in b/chromium/third_party/pdfium/testing/resources/javascript/util_printd.in deleted file mode 100644 index f098187cf07..00000000000 --- a/chromium/third_party/pdfium/testing/resources/javascript/util_printd.in +++ /dev/null @@ -1,104 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R - /OpenAction 10 0 R ->> -endobj -{{object 2 0}} << - /Type /Pages - /Count 1 - /Kids [ - 3 0 R - ] ->> -endobj -% Page number 0. -{{object 3 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /Contents [21 0 R] - /MediaBox [0 0 612 792] ->> -% OpenAction action -{{object 10 0}} << - /Type /Action - /S /JavaScript - /JS 11 0 R ->> -endobj -% JS program to exexute -{{object 11 0}} << ->> -stream -function TestOneFormat(str, d) { - try { - app.alert(str + ": " + util.printd(str, d)); - } - catch (e) { - app.alert(str + ": Caught error: " + e); - } -} -function TestOneXFAFormat(str, d, flag) { - try { - app.alert(str + ": " + util.printd(str, d, flag)); - } - catch (e) { - app.alert(str + ": Caught error: " + e); - } -} -// July 4th, 2014 11:59:59 AM local time. -var d1 = new Date(2014, 06, 04, 15, 59, 58); -TestOneFormat("mm/dd/yyyy HH:MM:ss", d1); -TestOneFormat(0, d1); -TestOneFormat(1, d1); -TestOneFormat(2, d1); -TestOneFormat(3, d1); -TestOneFormat("mmmm", d1); -TestOneFormat("mmm", d1); -TestOneFormat("mm", d1); -TestOneFormat("m", d1); -TestOneFormat("dddd", d1); -TestOneFormat("ddd", d1); -TestOneFormat("dd", d1); -TestOneFormat("d", d1); -TestOneFormat("yyyy", d1); -TestOneFormat("yy", d1); -TestOneFormat("HH", d1); -TestOneFormat("H", d1); -TestOneFormat("hh", d1); -// "h" is inconsitent between platforms: " 3" vs. "3" -TestOneFormat("MM", d1); -TestOneFormat("M", d1); -TestOneFormat("ss", d1); -TestOneFormat("s", d1); -// "tt" is inconsitent between platforms: "PM" vs, "pm" vs. "P" -TestOneFormat("t", d1); -TestOneFormat("abc.efg.i.kl.nopqr..uvwxyzABC.EFG.I.KL.NOPQR..UVWXYZ0123456780", d1); -TestOneFormat("!@#$^&*()-_<>[];:~", d1); -TestOneFormat("%z %d %%z %%d %%%z %%%d %%% hh:MM", d1); -TestOneFormat("", d1); -TestOneFormat("mm/dd/yyyy", d1); -TestOneFormat("mm/dd/yyyy", new Date(1850, 0, 1)); -TestOneFormat("mm/dd/yyyy", new Date(2525, 11, 31)); -TestOneFormat("mm/dd/yyyy"); -TestOneFormat(); -TestOneFormat("mm/dd/yyyy", 42); -TestOneFormat("mm/dd/yyyy", "clams"); -TestOneFormat("mm/dd/yyyy", {"clams": 3}); -TestOneFormat("mm/dd/yyyy", ["clams", 3]); -TestOneFormat({"clams": 3}, d1); -TestOneFormat(["clams", 3], d1); -TestOneXFAFormat("mm", d1, false); -TestOneXFAFormat("mm", d1, true); -endstream -endobj -{{xref}} -trailer << - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/javascript/util_printd_expected.txt b/chromium/third_party/pdfium/testing/resources/javascript/util_printd_expected.txt deleted file mode 100644 index 47abb2fd423..00000000000 --- a/chromium/third_party/pdfium/testing/resources/javascript/util_printd_expected.txt +++ /dev/null @@ -1,40 +0,0 @@ -Alert: mm/dd/yyyy HH:MM:ss: 07/04/2014 15:59:58 -Alert: 0: D:20140704155958 -Alert: 1: 2014.07.04 15:59:58 -Alert: 2: 2014/07/04 15:59:58 -Alert: 3: Caught error: util.printd: Incorrect parameter value. -Alert: mmmm: July -Alert: mmm: Jul -Alert: mm: 07 -Alert: m: 7 -Alert: dddd: Sunday -Alert: ddd: Sun -Alert: dd: 04 -Alert: d: 4 -Alert: yyyy: 2014 -Alert: yy: 14 -Alert: HH: 15 -Alert: H: 15 -Alert: hh: 03 -Alert: MM: 59 -Alert: M: 59 -Alert: ss: 58 -Alert: s: 58 -Alert: t: t -Alert: abc.efg.i.kl.nopqr..uvwxyzABC.EFG.I.KL.NOPQR..UVWXYZ0123456780: abc.efg.i.kl.nopqr..uvwxyzABC.EFG.I.KL.NOPQR..UVWXYZ0123456780 -Alert: !@#$^&*()-_<>[];:~: !@#$^&*()-_<>[];:~ -Alert: %z %d %%z %%d %%%z %%%d %%% hh:MM: z 4 z 4 z 4 03:59 -Alert: : -Alert: mm/dd/yyyy: 07/04/2014 -Alert: mm/dd/yyyy: 01/01/1850 -Alert: mm/dd/yyyy: 12/31/2525 -Alert: mm/dd/yyyy: Caught error: util.printd: The second parameter can't be converted to a Date. -Alert: undefined: Caught error: util.printd: The second parameter can't be converted to a Date. -Alert: mm/dd/yyyy: Caught error: util.printd: The second parameter can't be converted to a Date. -Alert: mm/dd/yyyy: Caught error: util.printd: The second parameter can't be converted to a Date. -Alert: mm/dd/yyyy: Caught error: util.printd: The second parameter can't be converted to a Date. -Alert: mm/dd/yyyy: Caught error: util.printd: The second parameter can't be converted to a Date. -Alert: [object Object]: Caught error: util.printd: Incorrect parameter type. -Alert: clams,3: Caught error: util.printd: Incorrect parameter type. -Alert: mm: 07 -Alert: mm: Caught error: util.printd: Operation not supported. diff --git a/chromium/third_party/pdfium/testing/resources/javascript/util_printx.in b/chromium/third_party/pdfium/testing/resources/javascript/util_printx.in deleted file mode 100644 index 7085edc3ea4..00000000000 --- a/chromium/third_party/pdfium/testing/resources/javascript/util_printx.in +++ /dev/null @@ -1,88 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R - /OpenAction 10 0 R ->> -endobj -{{object 2 0}} << - /Type /Pages - /Count 1 - /Kids [ - 3 0 R - ] ->> -endobj -% Page number 0. -{{object 3 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /Contents [21 0 R] - /MediaBox [0 0 612 792] ->> -% OpenAction action -{{object 10 0}} << - /Type /Action - /S /JavaScript - /JS 11 0 R ->> -endobj -% JS program to exexute -{{object 11 0}} << ->> -stream -function TestOneFormat(fmt, src) { - var title = "('" + fmt + "', '" + src + "')"; - try { - app.alert(title + " => '" + util.printx(fmt, src) + "'"); - } - catch (e) { - app.alert(title + ": Caught error: " + e); - } -} -TestOneFormat("", ""); -TestOneFormat("", "123"); -TestOneFormat("??", ""); -TestOneFormat("??", "f2"); -TestOneFormat("??", "f27"); -TestOneFormat("XXX", ""); -TestOneFormat("XXX", "1afp3."); -TestOneFormat("XXX", "-1Afp3.d33F$"); -TestOneFormat("AAA", ""); -TestOneFormat("AAA", "-1Afp3."); -TestOneFormat("AAA", "-1Afp3.d33F$"); -TestOneFormat("999", ""); -TestOneFormat("999", "-1Afp3."); -TestOneFormat("999", "-1Afp3.d33F$"); -TestOneFormat("9*9", ""); -TestOneFormat("9*9", "-1Afp3."); -TestOneFormat("[*]X", "-1Afp3."); -TestOneFormat("<*", "-1Afp3.d33F$"); -TestOneFormat(">*", "-1Afp3.d33F$"); -TestOneFormat("<[AAAAAAAAAAA]", "-1Afp3.d33F$"); -TestOneFormat(">[AAAAAAAAAAA]", "-1Afp3.d33F$"); -TestOneFormat("<[XXXXXXXXXXX]", "-1Afp3.d33F$"); -TestOneFormat(">[XXXXXXXXXXX]", "-1Afp3.d33F$"); -TestOneFormat("<[XXXXXXXXXXX]", "-1Afp3.d33F$"); -TestOneFormat(">[???????????]", "-1Afp3.d33F$"); -TestOneFormat("<[???????????]", "-1Afp3.d33F$"); -TestOneFormat("\\>[\\**]", "-1Afp3.d33F$"); -TestOneFormat("\\>[\\\\**]", "-1Afp3.d33F$"); -TestOneFormat("=*", "-1Afp3.d33F$"); -TestOneFormat("<??????=*", "-1Afp3.d33F$"); -TestOneFormat(">??????=*", "-1Afp3.d33F$"); -TestOneFormat(">??????<*", "-1Afp3.d33F$"); -TestOneFormat("clams", "-1Afp3.d33F$"); -TestOneFormat("cl9ms", "-1Afp3.d33F$"); -TestOneFormat("cl\\9ms", "-1Afp3.d33F$"); -endstream -endobj -{{xref}} -trailer << - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/javascript/util_printx_expected.txt b/chromium/third_party/pdfium/testing/resources/javascript/util_printx_expected.txt deleted file mode 100644 index 124767d5fd2..00000000000 --- a/chromium/third_party/pdfium/testing/resources/javascript/util_printx_expected.txt +++ /dev/null @@ -1,35 +0,0 @@ -Alert: ('', '') => '' -Alert: ('', '123') => '' -Alert: ('??', '') => '' -Alert: ('??', 'f2') => 'f2' -Alert: ('??', 'f27') => 'f2' -Alert: ('XXX', '') => '' -Alert: ('XXX', '1afp3.') => '1af' -Alert: ('XXX', '-1Afp3.d33F$') => '1Af' -Alert: ('AAA', '') => '' -Alert: ('AAA', '-1Afp3.') => 'Afp' -Alert: ('AAA', '-1Afp3.d33F$') => 'Afp' -Alert: ('999', '') => '' -Alert: ('999', '-1Afp3.') => '13' -Alert: ('999', '-1Afp3.d33F$') => '133' -Alert: ('9*9', '') => '' -Alert: ('9*9', '-1Afp3.') => '1Afp3.' -Alert: ('[*]X', '-1Afp3.') => '[-1Afp3.]' -Alert: ('<*', '-1Afp3.d33F$') => '-1afp3.d33f$' -Alert: ('>*', '-1Afp3.d33F$') => '-1AFP3.D33F$' -Alert: ('<[AAAAAAAAAAA]', '-1Afp3.d33F$') => '[afpdf]' -Alert: ('>[AAAAAAAAAAA]', '-1Afp3.d33F$') => '[AFPDF]' -Alert: ('<[XXXXXXXXXXX]', '-1Afp3.d33F$') => '[1afp3d33f]' -Alert: ('>[XXXXXXXXXXX]', '-1Afp3.d33F$') => '[1AFP3D33F]' -Alert: ('<[XXXXXXXXXXX]', '-1Afp3.d33F$') => '[1afp3d33f]' -Alert: ('>[???????????]', '-1Afp3.d33F$') => '[-1AFP3.D33F]' -Alert: ('<[???????????]', '-1Afp3.d33F$') => '[-1afp3.d33f]' -Alert: ('\>[\**]', '-1Afp3.d33F$') => '>[*-1Afp3.d33F$]' -Alert: ('\>[\\**]', '-1Afp3.d33F$') => '>[\-1Afp3.d33F$]' -Alert: ('=*', '-1Afp3.d33F$') => '-1Afp3.d33F$' -Alert: ('<??????=*', '-1Afp3.d33F$') => '-1afp3.d33F$' -Alert: ('>??????=*', '-1Afp3.d33F$') => '-1AFP3.d33F$' -Alert: ('>??????<*', '-1Afp3.d33F$') => '-1AFP3.d33f$' -Alert: ('clams', '-1Afp3.d33F$') => 'clams' -Alert: ('cl9ms', '-1Afp3.d33F$') => 'cl1ms' -Alert: ('cl\9ms', '-1Afp3.d33F$') => 'cl9ms' diff --git a/chromium/third_party/pdfium/testing/resources/launch_action.in b/chromium/third_party/pdfium/testing/resources/launch_action.in deleted file mode 100644 index c98539f5eaf..00000000000 --- a/chromium/third_party/pdfium/testing/resources/launch_action.in +++ /dev/null @@ -1,54 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R ->> -{{object 2 0}} << - /Type /Pages - /MediaBox [ 0 0 200 200 ] - /Count 1 - /Kids [ 3 0 R ] ->> -endobj -{{object 3 0}} << - /Type /Page - /Parent 2 0 R - /Annots [4 0 R] ->> -endobj -{{object 4 0}} << - /A 5 0 R - /FT /Tx - /Ff 29360128 - /T (txtName) - /Type /Annot - /Subtype /Link - /F 4 - /M (D:20150514070426+05'30') - /Rect [1 1 199 199] - /BS << - /W 1 - /S /S - >> - /DA (/Helv 0 Tf 0 0 0 rg) - /AP <</N 8 0 R>> - /V () - /AA 19 0 R ->> -endobj -{{object 5 0}} << - /F 6 0 R - /S /Launch ->> -{{object 6 0}} << - /F (test.pdf) - /Type / Filespec ->> -endobj -{{xref}} -trailer << - /Size 6 - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/launch_action.pdf b/chromium/third_party/pdfium/testing/resources/launch_action.pdf deleted file mode 100644 index 99a42923dee..00000000000 --- a/chromium/third_party/pdfium/testing/resources/launch_action.pdf +++ /dev/null @@ -1,64 +0,0 @@ -%PDF-1.7 -% ò¤ô -1 0 obj << - /Type /Catalog - /Pages 2 0 R ->> -2 0 obj << - /Type /Pages - /MediaBox [ 0 0 200 200 ] - /Count 1 - /Kids [ 3 0 R ] ->> -endobj -3 0 obj << - /Type /Page - /Parent 2 0 R - /Annots [4 0 R] ->> -endobj -4 0 obj << - /A 5 0 R - /FT /Tx - /Ff 29360128 - /T (txtName) - /Type /Annot - /Subtype /Link - /F 4 - /M (D:20150514070426+05'30') - /Rect [1 1 199 199] - /BS << - /W 1 - /S /S - >> - /DA (/Helv 0 Tf 0 0 0 rg) - /AP <</N 8 0 R>> - /V () - /AA 19 0 R ->> -endobj -5 0 obj << - /F 6 0 R - /S /Launch ->> -6 0 obj << - /F (test.pdf) - /Type / Filespec ->> -endobj -xref -0 7 -0000000000 65535 f -0000000015 00000 n -0000000061 00000 n -0000000154 00000 n -0000000223 00000 n -0000000489 00000 n -0000000527 00000 n -trailer << - /Size 6 - /Root 1 0 R ->> -startxref -583 -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/named_dests.in b/chromium/third_party/pdfium/testing/resources/named_dests.in deleted file mode 100644 index 5309ee23aab..00000000000 --- a/chromium/third_party/pdfium/testing/resources/named_dests.in +++ /dev/null @@ -1,109 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R - /Names << - /Dests 10 0 R - >> - /Dests 14 0 R ->> -endobj -{{object 2 0}} << - /Type /Pages - /Count 2 - /Kids [ - 3 0 R - 4 0 R - ] ->> -endobj -% Page number 0. -{{object 3 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /Contents [21 0 R] - /MediaBox [0 0 612 792] ->> -endobj -% Page number 1. -{{object 4 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /Contents [22 0 R] - /MediaBox [0 0 612 792] ->> -endobj -% Root of Dests NameTree -{{object 10 0}} << - /Kids [ - 11 0 R - 12 0 R - ] ->> -endobj -% Left child for Dests NameTree -{{object 11 0}} << - /Names [ - (First) [1 /XYZ 0 0 1] - (Next) <</D [4 0 R /Fit]>> - ] ->> -endobj -% Right child for Dests NameTree -{{object 12 0}} << - /Names [ - (WrongKey) <</Fail [10 /FitH]>> - (WrongType) /NameNotAllowedHere - ] ->> -endobj -% Old-style top-level Dests dictionary. Note that FirstAlternate -% intentionally references non-exisstant page 11 and LastAlternate -% intentionally references non-existant object 999. -{{object 14 0}} << - /FirstAlternate [11 /XYZ 200 400 800] - /LastAlternate <</D [999 0 R /XYZ 0 0 -200]>> ->> -endobj -% Font resource. -{{object 15 0}} << - /Type /Font - /Subtype /Type1 - /BaseFont /Arial ->> -endobj -% Content for page 0. -{{object 21 0}} << - /Length 0 ->> -stream -BT -/F1 20 Tf -100 600 TD (Page1)Tj -ET -endstream -endobj -% Content for page 1. -{{object 22 0}} << - /Length 0 ->> -stream -BT -/F1 20 Tf -100 600 TD (Page2)Tj -ET -endstream -endobj -{{xref}} -trailer << - /Size 6 - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/named_dests.pdf b/chromium/third_party/pdfium/testing/resources/named_dests.pdf deleted file mode 100644 index 2e0e5ce71d6..00000000000 --- a/chromium/third_party/pdfium/testing/resources/named_dests.pdf +++ /dev/null @@ -1,135 +0,0 @@ -%PDF-1.7 -% ò¤ô -1 0 obj << - /Type /Catalog - /Pages 2 0 R - /Names << - /Dests 10 0 R - >> - /Dests 14 0 R ->> -endobj -2 0 obj << - /Type /Pages - /Count 2 - /Kids [ - 3 0 R - 4 0 R - ] ->> -endobj -% Page number 0. -3 0 obj << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /Contents [21 0 R] - /MediaBox [0 0 612 792] ->> -endobj -% Page number 1. -4 0 obj << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /Contents [22 0 R] - /MediaBox [0 0 612 792] ->> -endobj -% Root of Dests NameTree -10 0 obj << - /Kids [ - 11 0 R - 12 0 R - ] ->> -endobj -% Left child for Dests NameTree -11 0 obj << - /Names [ - (First) [1 /XYZ 0 0 1] - (Next) <</D [4 0 R /Fit]>> - ] ->> -endobj -% Right child for Dests NameTree -12 0 obj << - /Names [ - (WrongKey) <</Fail [10 /FitH]>> - (WrongType) /NameNotAllowedHere - ] ->> -endobj -% Old-style top-level Dests dictionary. Note that FirstAlternate -% intentionally references non-exisstant page 11 and LastAlternate -% intentionally references non-existant object 999. -14 0 obj << - /FirstAlternate [11 /XYZ 200 400 800] - /LastAlternate <</D [999 0 R /XYZ 0 0 -200]>> ->> -endobj -% Font resource. -15 0 obj << - /Type /Font - /Subtype /Type1 - /BaseFont /Arial ->> -endobj -% Content for page 0. -21 0 obj << - /Length 0 ->> -stream -BT -/F1 20 Tf -100 600 TD (Page1)Tj -ET -endstream -endobj -% Content for page 1. -22 0 obj << - /Length 0 ->> -stream -BT -/F1 20 Tf -100 600 TD (Page2)Tj -ET -endstream -endobj -xref -0 23 -0000000000 65535 f -0000000015 00000 n -0000000119 00000 n -0000000217 00000 n -0000000378 00000 n -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000548 00000 n -0000000638 00000 n -0000000766 00000 n -0000000000 65535 f -0000001060 00000 n -0000001188 00000 n -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000001283 00000 n -0000001393 00000 n -trailer << - /Size 6 - /Root 1 0 R ->> -startxref -1481 -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/page_labels.pdf b/chromium/third_party/pdfium/testing/resources/page_labels.pdf Binary files differdeleted file mode 100644 index fd1a1e55e90..00000000000 --- a/chromium/third_party/pdfium/testing/resources/page_labels.pdf +++ /dev/null diff --git a/chromium/third_party/pdfium/testing/resources/parser_rebuildxref_correct.pdf b/chromium/third_party/pdfium/testing/resources/parser_rebuildxref_correct.pdf deleted file mode 100644 index 5e4f60bc385..00000000000 --- a/chromium/third_party/pdfium/testing/resources/parser_rebuildxref_correct.pdf +++ /dev/null @@ -1,55 +0,0 @@ -%PDF-1.7 -% ò¤ô -1 0 obj << - /Type /Catalog - /Pages 2 2 R ->> -2 2 obj << - /Type /Pages - /MediaBox [ 0 0 200 200 ] - /Count 1 - /Kids [ 3 4 R ] ->> -endobj -3 4 obj << - /Type /Page - /Parent 2 2 R - /Resources << - /Font << - /F1 4 6 R - /F2 5 8 R - >> - >> - /Contents 6 0 R ->> -endobj -4 6 obj << - /Type /Font - /Subtype /Type1 - /BaseFont /Times-Roman ->> -endobj -5 8 obj << - /Type /Font - /Subtype /Type1 - /BaseFont /Helvetica ->> -endobj -6 0 obj << ->> -stream -BT -20 50 Td -/F1 12 Tf -(Hello, world!) Tj -0 50 Td -/F2 16 Tf -(Goodbye, world!) Tj -ET -endstream -endobj -trailer << - /Size 6 - /Root 1 0 R ->> -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/parser_rebuildxref_error_notrailer.pdf b/chromium/third_party/pdfium/testing/resources/parser_rebuildxref_error_notrailer.pdf deleted file mode 100644 index 93f56fba9b2..00000000000 --- a/chromium/third_party/pdfium/testing/resources/parser_rebuildxref_error_notrailer.pdf +++ /dev/null @@ -1,51 +0,0 @@ -%PDF-1.7 -% ò¤ô -1 0 obj << - /Type /Catalog - /Pages 2 2 R ->> -2 2 obj << - /Type /Pages - /MediaBox [ 0 0 200 200 ] - /Count 1 - /Kids [ 3 4 R ] ->> -endobj -3 4 obj << - /Type /Page - /Parent 2 2 R - /Resources << - /Font << - /F1 4 6 R - /F2 5 8 R - >> - >> - /Contents 6 0 R ->> -endobj -4 6 obj << - /Type /Font - /Subtype /Type1 - /BaseFont /Times-Roman ->> -endobj -5 8 obj << - /Type /Font - /Subtype /Type1 - /BaseFont /Helvetica ->> -endobj -6 0 obj << ->> -stream -BT -20 50 Td -/F1 12 Tf -(Hello, world!) Tj -0 50 Td -/F2 16 Tf -(Goodbye, world!) Tj -ET -endstream -endobj -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_113910.evt b/chromium/third_party/pdfium/testing/resources/pixel/bug_113910.evt deleted file mode 100644 index ca8821f0062..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_113910.evt +++ /dev/null @@ -1,8 +0,0 @@ -mousemove,150,120 -mousedown,left,150,120 -mouseup,left,150,120 -charcode,49 -charcode,50 -charcode,51 -charcode,52 -charcode,13 diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_113910.in b/chromium/third_party/pdfium/testing/resources/pixel/bug_113910.in deleted file mode 100644 index fdfcc543645..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_113910.in +++ /dev/null @@ -1,66 +0,0 @@ -{{header}} -{{object 1 0}} -<< - /Type /Catalog - /Pages 2 0 R - /AcroForm << /Fields [ 4 0 R 10 0 R ] /DR 5 0 R >> ->> -endobj -{{object 2 0}} -<< /Count 1 /Kids [ 3 0 R ] /Type /Pages >> -endobj -{{object 3 0}} -<< - /Type /Page - /Parent 2 0 R - /Resources 5 0 R - /MediaBox [ 0 0 300 200 ] - /Contents 8 0 R - /Annots [ 4 0 R 10 0 R ] ->> -endobj -{{object 4 0}} -<< - /Type /Annot - /FT /Tx - /T (Text Box) - /DA (0 0 0 rg /F1 12 Tf) - /Rect [ 100 100 200 130 ] - /Subtype /Widget - /AA << /F 9 0 R >> ->> -endobj -{{object 5 0}} -<< /Font 6 0 R >> -endobj -{{object 6 0}} -<< /F1 7 0 R >> -endobj -{{object 7 0}} << - /Type /Font - /Subtype /Type1 - /BaseFont /Helvetica ->> -endobj -{{object 8 0}}<< ->> -stream -endstream -endobj -{{object 9 0}} -<< /JS (AFNumber_Format\(0, 1, 0, 0, "", false\);) /S /JavaScript >> -endobj -{{object 10 0}} -<< - /Type /Annot - /FT /Tx - /T (Text2) - /DA (0 0 0 rg /F1 12 Tf) - /Rect [ 100 40 200 70 ] - /Subtype /Widget ->> -endobj -{{xref}} -trailer<< /Root 1 0 R >> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_113910_expected.pdf.0.png b/chromium/third_party/pdfium/testing/resources/pixel/bug_113910_expected.pdf.0.png Binary files differdeleted file mode 100644 index 38043478256..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_113910_expected.pdf.0.png +++ /dev/null diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_113910_expected_mac.pdf.0.png b/chromium/third_party/pdfium/testing/resources/pixel/bug_113910_expected_mac.pdf.0.png Binary files differdeleted file mode 100644 index 5b21f5ab789..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_113910_expected_mac.pdf.0.png +++ /dev/null diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_492.in b/chromium/third_party/pdfium/testing/resources/pixel/bug_492.in deleted file mode 100644 index 45c4a6f38b0..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_492.in +++ /dev/null @@ -1,64 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R - /OpenAction 20 0 R ->> -endobj -{{object 2 0}} << - /Type /Pages - /Count 1 - /Kids [ - 10 0 R - ] ->> -endobj -% Page number 0. -{{object 10 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /MediaBox [0 0 612 792] - /Annots [ - 22 0 R - ] - /Tabs /R ->> -endobj - -% OpenAction action -{{object 20 0}} << - /Type /Action - /S /JavaScript - /JS 21 0 R ->> -endobj -% JS program to exexute -{{object 21 0}} << ->> -stream - var annot = this.getAnnot(0, "Annot-1"); - annot.hidden = false; -endstream -endobj - -{{object 22 0}} << - /Type /Annot - /Subtype /Highlight - /Rect [ 475 681 512 690 ] - /NM (Annot-1) - /F 2 - /QuadPoints [ 475 688 512 688 475 679 512 679 ] - /C [ 0.0001108646 0.001760244 0.9982184 ] - /Contents () ->> -endobj - -{{xref}} -trailer << - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_492.pdf.0.png b/chromium/third_party/pdfium/testing/resources/pixel/bug_492.pdf.0.png Binary files differdeleted file mode 100644 index adc4b53e0ee..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_492.pdf.0.png +++ /dev/null diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_512557.in b/chromium/third_party/pdfium/testing/resources/pixel/bug_512557.in Binary files differdeleted file mode 100644 index 5f353341d56..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_512557.in +++ /dev/null diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_512557_expected.pdf.0.png b/chromium/third_party/pdfium/testing/resources/pixel/bug_512557_expected.pdf.0.png Binary files differdeleted file mode 100644 index 66c73aebeaa..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_512557_expected.pdf.0.png +++ /dev/null diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_1.in b/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_1.in deleted file mode 100644 index 61ac6f4bb27..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_1.in +++ /dev/null @@ -1,61 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R ->> -{{object 2 0}} << - /Type /Pages - /MediaBox [ 0 0 200 200 ] - /Count 1 - /Kids [ 3 0 R ] ->> -endobj -{{object 3 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font << - /F1 4 0 R - /F2 5 0 R - >> - >> - /Contents 6 0 R ->> -endobj -{{object 4 0}} << - /Type /Font - /Subtype /Type1 - /BaseFont /Times-Roman ->> -endobj -{{object 5 0}} << - /Type /Font - /Subtype /Type1 - /BaseFont /Helvetica ->> -endobj -% Case 1: -% /Length identifies intended end of stream, despite embedded keywords. -% Both should render as text. -{{object 6 0}} << - /Length 107 ->> -stream -BT -20 50 Td -/F1 12 Tf -(endobj is text) Tj -endstream -0 50 Td -/F2 13 Tf -(endstream is text per /Length) Tj -ET -endstream -endobj -{{xref}} -trailer << - /Size 6 - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_1_expected.pdf.0.png b/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_1_expected.pdf.0.png Binary files differdeleted file mode 100644 index 5a46384d7b4..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_1_expected.pdf.0.png +++ /dev/null diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_1_expected_mac.pdf.0.png b/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_1_expected_mac.pdf.0.png Binary files differdeleted file mode 100644 index b85b9d0f967..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_1_expected_mac.pdf.0.png +++ /dev/null diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_2.in b/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_2.in deleted file mode 100644 index 0ee43da1064..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_2.in +++ /dev/null @@ -1,62 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R ->> -{{object 2 0}} << - /Type /Pages - /MediaBox [ 0 0 200 200 ] - /Count 1 - /Kids [ 3 0 R ] ->> -endobj -{{object 3 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font << - /F1 4 0 R - /F2 5 0 R - >> - >> - /Contents 6 0 R ->> -endobj -{{object 4 0}} << - /Type /Font - /Subtype /Type1 - /BaseFont /Times-Roman ->> -endobj -{{object 5 0}} << - /Type /Font - /Subtype /Type1 - /BaseFont /Helvetica ->> -endobj -% Case 2: -% /Length incorrectly identifies middle of stream. -% The stream is blocked by the keyword "endstream" -% Only the text before the keyword can be rendered. -{{object 6 0}} << - /Length 87 ->> -stream -BT -20 50 Td -/F1 12 Tf -(endobj is text) Tj -endstream -0 50 Td -/F2 13 Tf -(It's wrong when you see the text!) Tj -ET -endstream -endobj -{{xref}} -trailer << - /Size 6 - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_2_expected.pdf.0.png b/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_2_expected.pdf.0.png Binary files differdeleted file mode 100644 index 34aa9b428b0..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_2_expected.pdf.0.png +++ /dev/null diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_2_expected_mac.pdf.0.png b/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_2_expected_mac.pdf.0.png Binary files differdeleted file mode 100644 index ecede7d82c0..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_2_expected_mac.pdf.0.png +++ /dev/null diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_3.in b/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_3.in deleted file mode 100644 index 716345ede12..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_3.in +++ /dev/null @@ -1,62 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R ->> -{{object 2 0}} << - /Type /Pages - /MediaBox [ 0 0 200 200 ] - /Count 1 - /Kids [ 3 0 R ] ->> -endobj -{{object 3 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font << - /F1 4 0 R - /F2 5 0 R - >> - >> - /Contents 6 0 R ->> -endobj -{{object 4 0}} << - /Type /Font - /Subtype /Type1 - /BaseFont /Times-Roman ->> -endobj -{{object 5 0}} << - /Type /Font - /Subtype /Type1 - /BaseFont /Helvetica ->> -endobj -% Case 3: -% /Length incorrectly identifies middle of stream. -% "eendstream" shouldn't block the stream. -% Both should render as text. -{{object 6 0}} << - /Length 87 ->> -stream -BT -20 50 Td -/F1 12 Tf -(endobj is text) Tj -eendstream -0 50 Td -/F2 13 Tf -(endstream is text per /Length) Tj -ET -endstream -endobj -{{xref}} -trailer << - /Size 6 - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_3_expected.pdf.0.png b/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_3_expected.pdf.0.png Binary files differdeleted file mode 100644 index 5a46384d7b4..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_3_expected.pdf.0.png +++ /dev/null diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_3_expected_mac.pdf.0.png b/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_3_expected_mac.pdf.0.png Binary files differdeleted file mode 100644 index b85b9d0f967..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_3_expected_mac.pdf.0.png +++ /dev/null diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_4.in b/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_4.in deleted file mode 100644 index 6cdb3d18a72..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_4.in +++ /dev/null @@ -1,61 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R ->> -{{object 2 0}} << - /Type /Pages - /MediaBox [ 0 0 200 200 ] - /Count 1 - /Kids [ 3 0 R ] ->> -endobj -{{object 3 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font << - /F1 4 0 R - /F2 5 0 R - >> - >> - /Contents 6 0 R ->> -endobj -{{object 4 0}} << - /Type /Font - /Subtype /Type1 - /BaseFont /Times-Roman ->> -endobj -{{object 5 0}} << - /Type /Font - /Subtype /Type1 - /BaseFont /Helvetica ->> -endobj -% Case 4: -% /Length incorrectly identifies middle of stream. -% "endstream." shouldn't block the stream. -% Both should render as text even "endstream" is missing. -{{object 6 0}} << - /Length 87 ->> -stream -BT -20 50 Td -/F1 12 Tf -(endobj is text) Tj -endstream. -0 50 Td -/F2 13 Tf -(endstream is text per /Length) Tj -ET -endobj -{{xref}} -trailer << - /Size 6 - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_4_expected.pdf.0.png b/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_4_expected.pdf.0.png Binary files differdeleted file mode 100644 index 5a46384d7b4..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_4_expected.pdf.0.png +++ /dev/null diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_4_expected_mac.pdf.0.png b/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_4_expected_mac.pdf.0.png Binary files differdeleted file mode 100644 index b85b9d0f967..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_4_expected_mac.pdf.0.png +++ /dev/null diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_5.in b/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_5.in deleted file mode 100644 index 799674628dd..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_5.in +++ /dev/null @@ -1,61 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R ->> -{{object 2 0}} << - /Type /Pages - /MediaBox [ 0 0 200 200 ] - /Count 1 - /Kids [ 3 0 R ] ->> -endobj -{{object 3 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font << - /F1 4 0 R - /F2 5 0 R - >> - >> - /Contents 6 0 R ->> -endobj -{{object 4 0}} << - /Type /Font - /Subtype /Type1 - /BaseFont /Times-Roman ->> -endobj -{{object 5 0}} << - /Type /Font - /Subtype /Type1 - /BaseFont /Helvetica ->> -endobj -% Case 5: -% /Length incorrectly identifies middle of stream. -% "endstream%" shouldn't block the stream. -% Both should render as text even "endobj" is missing. -{{object 6 0}} << - /Length 87 ->> -stream -BT -20 50 Td -/F1 12 Tf -(endobj is text) Tj -endstream% -0 50 Td -/F2 13 Tf -(endstream is text per /Length) Tj -ET -endstream -{{xref}} -trailer << - /Size 6 - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_5_expected.pdf.0.png b/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_5_expected.pdf.0.png Binary files differdeleted file mode 100644 index 5a46384d7b4..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_5_expected.pdf.0.png +++ /dev/null diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_5_expected_mac.pdf.0.png b/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_5_expected_mac.pdf.0.png Binary files differdeleted file mode 100644 index b85b9d0f967..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_5_expected_mac.pdf.0.png +++ /dev/null diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_6.in b/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_6.in deleted file mode 100644 index 318b20750df..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_6.in +++ /dev/null @@ -1,60 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R ->> -{{object 2 0}} << - /Type /Pages - /MediaBox [ 0 0 200 200 ] - /Count 1 - /Kids [ 3 0 R ] ->> -endobj -{{object 3 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font << - /F1 4 0 R - /F2 5 0 R - >> - >> - /Contents 6 0 R ->> -endobj -{{object 4 0}} << - /Type /Font - /Subtype /Type1 - /BaseFont /Times-Roman ->> -endobj -{{object 5 0}} << - /Type /Font - /Subtype /Type1 - /BaseFont /Helvetica ->> -endobj -% Case 6: -% /Length incorrectly identifies middle of stream. -% "endstream+" shouldn't block the stream. -% Nothing will be rendered when both "endstream" and "endobj" are missing. -{{object 6 0}} << - /Length 87 ->> -stream -BT -20 50 Td -/F1 12 Tf -(endobj is text) Tj -endstream+ -0 50 Td -/F2 13 Tf -(endstream is text per /Length) Tj -ET -{{xref}} -trailer << - /Size 6 - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_6_expected.pdf.0.png b/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_6_expected.pdf.0.png Binary files differdeleted file mode 100644 index 3edcc2db897..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_6_expected.pdf.0.png +++ /dev/null diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_6_expected_mac.pdf.0.png b/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_6_expected_mac.pdf.0.png Binary files differdeleted file mode 100644 index 3edcc2db897..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_6_expected_mac.pdf.0.png +++ /dev/null diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_7.in b/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_7.in deleted file mode 100644 index c95f2d94e1d..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_7.in +++ /dev/null @@ -1,61 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R ->> -{{object 2 0}} << - /Type /Pages - /MediaBox [ 0 0 200 200 ] - /Count 1 - /Kids [ 3 0 R ] ->> -endobj -{{object 3 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font << - /F1 4 0 R - /F2 5 0 R - >> - >> - /Contents 6 0 R ->> -endobj -{{object 4 0}} << - /Type /Font - /Subtype /Type1 - /BaseFont /Times-Roman ->> -endobj -{{object 5 0}} << - /Type /Font - /Subtype /Type1 - /BaseFont /Helvetica ->> -endobj -% Case 7: -% /Length incorrectly identifies middle of stream. -% "endstream" will block the stream. -% The text before the keyword "endstream" can be rendered although -% both "endstream" and "endobj" are missing at the end of stream. -{{object 6 0}} << - /Length 87 ->> -stream -BT -20 50 Td -/F1 12 Tf -(endobj is text) Tj -endstream -0 50 Td -/F2 13 Tf -(endstream is text per /Length) Tj -ET -{{xref}} -trailer << - /Size 6 - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_7_expected.pdf.0.png b/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_7_expected.pdf.0.png Binary files differdeleted file mode 100644 index 34aa9b428b0..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_7_expected.pdf.0.png +++ /dev/null diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_7_expected_mac.pdf.0.png b/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_7_expected_mac.pdf.0.png Binary files differdeleted file mode 100644 index ecede7d82c0..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_524043_7_expected_mac.pdf.0.png +++ /dev/null diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_527174.in b/chromium/third_party/pdfium/testing/resources/pixel/bug_527174.in Binary files differdeleted file mode 100644 index 2b33e304c46..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_527174.in +++ /dev/null diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_527174_expected.pdf.0.png b/chromium/third_party/pdfium/testing/resources/pixel/bug_527174_expected.pdf.0.png Binary files differdeleted file mode 100644 index 4035b7632cb..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_527174_expected.pdf.0.png +++ /dev/null diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_528103.in b/chromium/third_party/pdfium/testing/resources/pixel/bug_528103.in deleted file mode 100644 index 9223b0b77a6..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_528103.in +++ /dev/null @@ -1,47 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R ->> -endobj -{{object 2 0}} << - /Type /Pages - /MediaBox [ 0 0 500 100 ] - /Count 1 - /Kids [ 3 0 R ] ->> -endobj -{{object 3 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font << - /F1 4 0 R - >> - >> - /Contents 5 0 R ->> -endobj -{{object 4 0}} << - /Type /Font - /Subtype /Type1 - /BaseFont /Arial ->> -endobj -{{object 5 0}} << ->> -stream -BT -150 Tz -100 50 TD /F1 12 Tf [(Intentionally)] TJ -10 0 TD [-5000(Nonoverlapping)] TJ -10 0 TD [-12000(Text)] TJ -ET -endstream -endobj -{{xref}} -trailer << - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_528103_expected.pdf.0.png b/chromium/third_party/pdfium/testing/resources/pixel/bug_528103_expected.pdf.0.png Binary files differdeleted file mode 100644 index 479b0fd42e6..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_528103_expected.pdf.0.png +++ /dev/null diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_528103_expected_mac.pdf.0.png b/chromium/third_party/pdfium/testing/resources/pixel/bug_528103_expected_mac.pdf.0.png Binary files differdeleted file mode 100644 index cb028f9e139..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_528103_expected_mac.pdf.0.png +++ /dev/null diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_528103_expected_win.pdf.0.png b/chromium/third_party/pdfium/testing/resources/pixel/bug_528103_expected_win.pdf.0.png Binary files differdeleted file mode 100644 index 27c0df7fd2d..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_528103_expected_win.pdf.0.png +++ /dev/null diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_543018_1.in b/chromium/third_party/pdfium/testing/resources/pixel/bug_543018_1.in deleted file mode 100644 index f8f651506ff..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_543018_1.in +++ /dev/null @@ -1,61 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R ->> -{{object 2 0}} << - /Type /Pages - /MediaBox [ 0 0 200 200 ] - /Count 1 - /Kids [ 3 0 R ] ->> -endobj -{{object 3 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font << - /F1 4 0 R - /F2 5 0 R - >> - >> - /Contents 6 0 R ->> -endobj -{{object 4 0}} << - /Type /Font - /Subtype /Type1 - /BaseFont /Times-Roman ->> -endobj -{{object 5 0}} << - /Type /Font - /Subtype /Type1 - /BaseFont /Helvetica ->> -endobj -% Case 1: -% A white space rather than end of line markers follows the keyword "stream". -% Both should render as text. -{{object 6 0}} << - /Length 107 ->> -stream -BT -20 50 Td -/F1 12 Tf -(endobj is text) Tj -endstream -0 50 Td -/F2 13 Tf -(endstream is text per /Length) Tj -ET -endstream -endobj -{{xref}} -trailer << - /Size 6 - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_543018_1_expected.pdf.0.png b/chromium/third_party/pdfium/testing/resources/pixel/bug_543018_1_expected.pdf.0.png Binary files differdeleted file mode 100644 index 5a46384d7b4..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_543018_1_expected.pdf.0.png +++ /dev/null diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_543018_1_expected_mac.pdf.0.png b/chromium/third_party/pdfium/testing/resources/pixel/bug_543018_1_expected_mac.pdf.0.png Binary files differdeleted file mode 100644 index b85b9d0f967..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_543018_1_expected_mac.pdf.0.png +++ /dev/null diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_543018_2.in b/chromium/third_party/pdfium/testing/resources/pixel/bug_543018_2.in deleted file mode 100644 index 4562e58c27e..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_543018_2.in +++ /dev/null @@ -1,62 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R ->> -{{object 2 0}} << - /Type /Pages - /MediaBox [ 0 0 200 200 ] - /Count 1 - /Kids [ 3 0 R ] ->> -endobj -{{object 3 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font << - /F1 4 0 R - /F2 5 0 R - >> - >> - /Contents 6 0 R ->> -endobj -{{object 4 0}} << - /Type /Font - /Subtype /Type1 - /BaseFont /Times-Roman ->> -endobj -{{object 5 0}} << - /Type /Font - /Subtype /Type1 - /BaseFont /Helvetica ->> -endobj -% Case 2: -% Three white spaces and other chars follow the keyword "stream" -% before end of line markers. They should be ignored. The content -% in stream should be rendered as text. -{{object 6 0}} << - /Length 107 ->> -stream "this part will be ignored" -BT -20 50 Td -/F1 12 Tf -(endobj is text) Tj -endstream -0 50 Td -/F2 13 Tf -(endstream is text per /Length) Tj -ET -endstream -endobj -{{xref}} -trailer << - /Size 6 - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_543018_2_expected.pdf.0.png b/chromium/third_party/pdfium/testing/resources/pixel/bug_543018_2_expected.pdf.0.png Binary files differdeleted file mode 100644 index 5a46384d7b4..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_543018_2_expected.pdf.0.png +++ /dev/null diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_543018_2_expected_mac.pdf.0.png b/chromium/third_party/pdfium/testing/resources/pixel/bug_543018_2_expected_mac.pdf.0.png Binary files differdeleted file mode 100644 index b85b9d0f967..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_543018_2_expected_mac.pdf.0.png +++ /dev/null diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_551258_1.in b/chromium/third_party/pdfium/testing/resources/pixel/bug_551258_1.in deleted file mode 100644 index f254f2d43d4..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_551258_1.in +++ /dev/null @@ -1,60 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R ->> -{{object 2 0}} << - /Type /Pages - /MediaBox [ 0 0 200 200 ] - /Count 1 - /Kids [ 3 0 R ] ->> -endobj -{{object 3 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font << - /F1 4 0 R - /F2 5 0 R - >> - >> - /Contents 6 0 R ->> -endobj -{{object 4 0}} << - /Type /Font - /Subtype /Type1 - /BaseFont /Times-Roman ->> -endobj -{{object 5 0}} << - /Type /Font - /Subtype /Type1 - /BaseFont /Helvetica ->> -endobj -% Case 1: -% Earlier version of PDF doesn't require EOL before 'endstream'. If the length -% of bytes end before 'endstream', we should take it. -{{object 6 0}} << - /Length 107 ->> -stream -BT -20 50 Td -/F1 12 Tf -(endobj is text) Tj -endstream -0 50 Td -/F2 13 Tf -(endstream is text per /Length) Tj -ETendstream -endobj -{{xref}} -trailer << - /Size 6 - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_551258_1_expected.pdf.0.png b/chromium/third_party/pdfium/testing/resources/pixel/bug_551258_1_expected.pdf.0.png Binary files differdeleted file mode 100644 index 5a46384d7b4..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_551258_1_expected.pdf.0.png +++ /dev/null diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_551258_1_expected_mac.pdf.0.png b/chromium/third_party/pdfium/testing/resources/pixel/bug_551258_1_expected_mac.pdf.0.png Binary files differdeleted file mode 100644 index b85b9d0f967..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_551258_1_expected_mac.pdf.0.png +++ /dev/null diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_585.in b/chromium/third_party/pdfium/testing/resources/pixel/bug_585.in deleted file mode 100644 index b8b56ad427c..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_585.in +++ /dev/null @@ -1,175 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R ->> -endobj -{{object 2 0}} << - /Type /Pages - /Count 1 - /Kids [ - 10 0 R - ] ->> -endobj -% Page number 0. -{{object 10 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /MediaBox [0 0 612 792] - /Annots [ - 22 0 R - 23 0 R - 24 0 R - 25 0 R - ] - /Tabs /R ->> -endobj - -{{object 22 0}} << - /Type /Annot - /Subtype /Highlight - /Rect [ -1 -1 -1 -1 ] - /NM (Annot-1) - /F 4 - /QuadPoints [ 475 688 512 688 475 679 512 679 ] - /C [ 0.0001108646 0.001760244 0.9982184 ] - /Contents () ->> -endobj - -{{object 23 0}} << - /Border [ - 0 - 0 - 1 - ] - /C [ - 0.294118 - 0.6 - 1 - ] - /CA 1 - /CreationDate (D:20150312175256+08'00') - /F 4 - /M (D:20150312175256+08'00') - /NM (7f264ba2-e270-42a1-a390-eb41278072ff) - /QuadPoints [ - 227.567 - 688.016 - 298.115 - 688.016 - 227.567 - 679.292 - 298.115 - 679.292 - ] - /RC (<?xml version="1.0"?><body xmlns="http://www.w3.org/1999/xhtml" xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" xfa:APIVersion="Acroform:2.7.0.0" xfa:spec="2.1"><p style="text-align:left" dir="ltr"><span style="line-height:0pt,font-size:0pt;font-style:normal;font-weight:normal;color:#000000;font-family:Helvetica"></span>\r\n</p>\r\n</body>\r\n) - /Rect [ - -1 - -1 - -1 - -1 - ] - /Subj (Squiggly) - /Subtype /Squiggly - /T (Administrator) - /Type /Annot ->> -endobj - -{{object 24 0}} << - /Border [ - 0 - 0 - 1 - ] - /C [ - 0.278431 - 0.603922 - 0.6 - ] - /CA 1 - /CreationDate (D:20150312175350+08'00') - /F 4 - /IRT 6 0 R - /IT /StrikeOutTextEdit - /M (D:20150312175350+08'00') - /NM (2912a3cf-3b30-48a7-8531-431ce468e6a8) - /P 4 0 R - /QuadPoints [ - 186.875 - 714.836 - 293.483 - 714.836 - 186.875 - 706.064 - 293.483 - 706.064 - ] - /RT /Group - /Rect [ - -1 - -1 - -1 - -1 - ] - /Subj (Replace) - /Subtype /StrikeOut - /T (Administrator) - /Type /Annot ->> -endobj - -{{object 25 0}} << - /Border [ - 0 - 0 - 1 - ] - /C [ - 0.2 - 0.619608 - 0 - ] - /CA 1 - /CreationDate (D:20150312175318+08'00') - /F 4 - /M (D:20150312175318+08'00') - /NM (c99bdf16-3040-4bf6-9b8a-a80cc563a6a7) - /P 4 0 R - /Popup 6 0 R - /QuadPoints [ - 204.395 - 647.984 - 403.895 - 647.984 - 204.395 - 636.872 - 403.895 - 636.872 - ] - /RC (<?xml version="1.0"?><body xmlns="http://www.w3.org/1999/xhtml" xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" xfa:APIVersion="Acroform:2.7.0.0" xfa:spec="2.1"><p style="text-align:left" dir="ltr"><span style="line-height:0pt,font-size:0pt;font-style:normal;font-weight:normal;color:#000000;font-family:Helvetica"></span>\r\n</p>\r\n</body>\r\n) - /Rect [ - -1 - -1 - -1 - -1 - ] - /Subj (Underline) - /Subtype /Underline - /T (Administrator) - /Type /Annot ->> -endobj - -{{xref}} -trailer << - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_585_expected.pdf.0.png b/chromium/third_party/pdfium/testing/resources/pixel/bug_585_expected.pdf.0.png Binary files differdeleted file mode 100644 index 34bc892231f..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_585_expected.pdf.0.png +++ /dev/null diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_591137.in b/chromium/third_party/pdfium/testing/resources/pixel/bug_591137.in Binary files differdeleted file mode 100644 index 98686ac6a3d..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_591137.in +++ /dev/null diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_591137_expected.pdf.0.png b/chromium/third_party/pdfium/testing/resources/pixel/bug_591137_expected.pdf.0.png Binary files differdeleted file mode 100644 index 265e6828dbe..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_591137_expected.pdf.0.png +++ /dev/null diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_665467.in b/chromium/third_party/pdfium/testing/resources/pixel/bug_665467.in deleted file mode 100644 index 6ef2c1cb822..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_665467.in +++ /dev/null @@ -1,99 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R ->> -endobj - -{{object 2 0}} << - /Type /Pages - /MediaBox [ 0 0 100 100 ] - /Count 1 - /Kids [ 3 0 R ] ->> -endobj - -{{object 3 0}} << - /Type /Page - /Parent 2 0 R - /Resources - << - /Font << /F1 4 0 R >> - >> - /Contents 8 0 R ->> -endobj - -{{object 4 0}} << - /Type /Font - /Subtype /TrueType - /BaseFont /ChromeSansMM - /Encoding 5 0 R - /FirstChar 32 - /LastChar 255 - /Name /F1 - /ToUnicode 6 0 R - /FontDescriptor 7 0 R ->> -endobj - -{{object 5 0}} << - /Differences [ 161 /someunknownname ] - /Type /Encoding ->> -endobj - -{{object 6 0}} << ->> -stream -/CIDInit /ProcSet findresource begin -12 dict begin -begincmap -/CIDSystemInfo -<</Registry (Adobe) -/Ordering (Identity) -/Supplement 0 ->> def -/CMapName /Adobe-Identity-H def -CMapType 2 def -1 begincodespacerange -<00> <FF> -endcodespacerange -1 beginbfchar -<A1> <043B> -endbfchar -endcmap -CMapName currentdict /CMap defineresource pop -end -end -endstream -endobj - -{{object 7 0}} << - << /Ascent 1000 - /CapHeight 0 - /Descent -200 - /Flags 32 - /FontBBox [ -599 -207 1338 1034 ] - /FontName /ChromeSansMM - /ItalicAngle 0 - /StemV 0 - /Type /FontDescriptor ->> -endobj - -{{object 8 0}} << ->> -stream -BT -50 50 Td /F1 15 Tf <A1> Tj -ET -endstream -endobj - -{{xref}} -trailer << - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_665467_expected.pdf.0.png b/chromium/third_party/pdfium/testing/resources/pixel/bug_665467_expected.pdf.0.png Binary files differdeleted file mode 100644 index 617cb0a9162..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_665467_expected.pdf.0.png +++ /dev/null diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_665467_expected_mac.pdf.0.png b/chromium/third_party/pdfium/testing/resources/pixel/bug_665467_expected_mac.pdf.0.png Binary files differdeleted file mode 100644 index 9f51dcb8554..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_665467_expected_mac.pdf.0.png +++ /dev/null diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_71.in b/chromium/third_party/pdfium/testing/resources/pixel/bug_71.in Binary files differdeleted file mode 100644 index 6bb6f19db01..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_71.in +++ /dev/null diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_714187.in b/chromium/third_party/pdfium/testing/resources/pixel/bug_714187.in deleted file mode 100644 index 4ec2395b02c..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_714187.in +++ /dev/null @@ -1,68 +0,0 @@ -{{header}} - -{{object 2 0}} << - /Type /Pages - /Rotate 90 - /Kids [ 3 0 R ] - /Count 1 ->> -endobj - -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R ->> -endobj - -{{object 3 0}} << - /Type /Page - /Parent 2 0 R - /Contents 4 0 R - /Resources << - /XObject << - /S5 5 0 R - >> - >> ->> -endobj - -{{object 4 0}} << - /Length 187 ->> -stream -q -0 1 -1 0 0 0 cm -1 0 0 -1 0 0 cm -0.072 0 0 0.072 0 0 cm -1 0 0 0.9598603839 0 275 cm -1.0 0 0 1.0 250 850 cm -1.0 0 0 1.0 2283.515625 845.525 cm -0.0005208333 0 0 -0.0005426136 0 0 cm -/S5 Do -Q - -endstream -endobj - -{{object 5 0}} << - /Type /XObject - /Subtype /Form - /FormType 1 - /BBox [ 24320 -704128 524224 -121856 ] - /Length 68 ->> -stream -524213 -411346 m -109719 -121914 24382 -263727 24382 -416322 c -h -f - -endstream -endobj - -{{xref}} -trailer << - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_714187_expected.pdf.0.png b/chromium/third_party/pdfium/testing/resources/pixel/bug_714187_expected.pdf.0.png Binary files differdeleted file mode 100644 index 195dad2d71d..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_714187_expected.pdf.0.png +++ /dev/null diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_718762.in b/chromium/third_party/pdfium/testing/resources/pixel/bug_718762.in deleted file mode 100644 index 3459dc0a1c6..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_718762.in +++ /dev/null @@ -1,67 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Pages - /Count 1 - /Kids[ 3 0 R ] ->> -endobj -{{object 2 0}} << - /Type /Catalog - /Pages 1 0 R ->> -endobj -{{object 3 0}} << - /Type /Page - /Parent 1 0 R - /Resources 6 0 R - /MediaBox[ 0 0 64 64] - /Contents[ 5 0 R ] ->> -endobj -{{object 4 0}} << - /Type /XObject - /Subtype /Image - /Name /I1 - /Width 5000 - /Height 5000 - /BitsPerComponent 8 - /ColorSpace /DeviceCMYK - /Filter [/ASCIIHexDecode /FlateDecode /DCTDecode] - /Decode [1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0] - /Length 734 ->> -stream -789cedcd3d4ec2001806e00f680529d4165a643671f112c6901095b09838b01983899bd7e02c9ec -2c143f8b37802af50cba81770799eef9ddebcc9d7bc355f515c2faf96d1e974e2b2bd68be23bfd8 -3edd3fc436f69acf5844afdbdda795b44907699a24e9b0df3f188c86a35136ccb2713e29c679996 -759312bca6955d7f5e8e8783eabe693aaae9a97a806d3dd74972c4e625dc6a68c5519cd6bd4ede3 -f8edb0adabe26f1bcd47e4c922d6b18955c4793cdf9ddedc9e3dfe9d01000000000000000000000 -0000000000000000000000000000000000000000000000000000000000000000000000000000000 -0000000000000000000000000000000000000000000000000000000000000000000000000000000 -0000000000000000000000000000000000000000000000000000000000000000000000000000000 -000000000000000000000000000000000000000000000000000000000000000000000000fc835ef -3fe03ce2e1eba -endstream -endobj -{{object 5 0}} << -/Length 28 ->> -stream -q -64 0 0 64 0 0 cm -/I1 Do -Q -endstream -endobj -{{object 6 0}} << - /ProcSet [/PDF /ImageC] - /XObject<</I1 4 0 R >> ->> -endobj -{{xref}} -trailer << - /Size 7 - /Root 2 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_718762_expected.pdf.0.png b/chromium/third_party/pdfium/testing/resources/pixel/bug_718762_expected.pdf.0.png Binary files differdeleted file mode 100644 index 73069f23aa2..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_718762_expected.pdf.0.png +++ /dev/null diff --git a/chromium/third_party/pdfium/testing/resources/pixel/bug_71_expected.pdf.0.png b/chromium/third_party/pdfium/testing/resources/pixel/bug_71_expected.pdf.0.png Binary files differdeleted file mode 100644 index 65d23c27b09..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/bug_71_expected.pdf.0.png +++ /dev/null diff --git a/chromium/third_party/pdfium/testing/resources/pixel/font_size.in b/chromium/third_party/pdfium/testing/resources/pixel/font_size.in deleted file mode 100644 index c4e21e23586..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/font_size.in +++ /dev/null @@ -1,62 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R ->> -{{object 2 0}} << - /Type /Pages - /MediaBox [ 0 0 100 400 ] - /Count 1 - /Kids [ 3 0 R ] ->> -endobj -{{object 3 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font << - /F1 4 0 R - >> - >> - /Contents 6 0 R ->> -endobj -{{object 4 0}} << - /Type /Font - /Subtype /Type1 - /BaseFont /Times-Roman ->> -endobj -{{object 6 0}} << ->> -stream -BT -20 0 Td -0 20 Td /F1 0 Tf (Size 0) Tj -0 20 Td /F1 1 Tf (Size 1) Tj -0 20 Td /F1 2 Tf (Size 2) Tj -0 20 Td /F1 3 Tf (Size 3) Tj -0 20 Td /F1 4 Tf (Size 4) Tj -0 20 Td /F1 5 Tf (Size 5) Tj -0 20 Td /F1 6 Tf (Size 6) Tj -0 20 Td /F1 7 Tf (Size 7) Tj -0 20 Td /F1 8 Tf (Size 8) Tj -0 20 Td /F1 9 Tf (Size 9) Tj -0 20 Td /F1 10 Tf (Size 10) Tj -0 20 Td /F1 11 Tf (Size 11) Tj -0 20 Td /F1 12 Tf (Size 12) Tj -0 20 Td /F1 13 Tf (Size 13) Tj -0 20 Td /F1 14 Tf (Size 14) Tj -0 20 Td /F1 15 Tf (Size 15) Tj -0 20 Td /F1 16 Tf (Size 16) Tj -0 20 Td /F1 17 Tf (Size 17) Tj -0 20 Td /F1 18 Tf (Size 18) Tj -ET -endstream -endobj -{{xref}} -trailer << - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/pixel/font_size_expected.pdf.0.png b/chromium/third_party/pdfium/testing/resources/pixel/font_size_expected.pdf.0.png Binary files differdeleted file mode 100644 index 5950b749f8f..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/font_size_expected.pdf.0.png +++ /dev/null diff --git a/chromium/third_party/pdfium/testing/resources/pixel/font_size_expected_mac.pdf.0.png b/chromium/third_party/pdfium/testing/resources/pixel/font_size_expected_mac.pdf.0.png Binary files differdeleted file mode 100644 index dfd06901a4b..00000000000 --- a/chromium/third_party/pdfium/testing/resources/pixel/font_size_expected_mac.pdf.0.png +++ /dev/null diff --git a/chromium/third_party/pdfium/testing/resources/repeat_viewer_ref.in b/chromium/third_party/pdfium/testing/resources/repeat_viewer_ref.in deleted file mode 100644 index 6b436e535f3..00000000000 --- a/chromium/third_party/pdfium/testing/resources/repeat_viewer_ref.in +++ /dev/null @@ -1,19 +0,0 @@ -{{header}} -{{object 1 0}} -<</Names<</JavaScript 2 0 R>>/ViewerPreferences<< -<</Names<</JavaScript 2 0 R>>/ViewerPreferences<< -<</Names<</JavaScript 2 0 R>>/ViewerPreferences<<>> -endobj - -{{object 2 0}} -<</Names[(0) 7 0 R]>> -endobj - -{{object 7 0}} -<</JS(this.print\({bUI:true,bSilent:false,bShrinkToFit:true}\);)/S/JavaScript>> -endobj - -{{xref}} -trailer <</Root 1 0 R>> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/repeat_viewer_ref.pdf b/chromium/third_party/pdfium/testing/resources/repeat_viewer_ref.pdf deleted file mode 100644 index 3f4ee477243..00000000000 --- a/chromium/third_party/pdfium/testing/resources/repeat_viewer_ref.pdf +++ /dev/null @@ -1,30 +0,0 @@ -%PDF-1.7 -% ò¤ô -1 0 obj -<</Names<</JavaScript 2 0 R>>/ViewerPreferences<< -<</Names<</JavaScript 2 0 R>>/ViewerPreferences<< -<</Names<</JavaScript 2 0 R>>/ViewerPreferences<<>> -endobj - -2 0 obj -<</Names[(0) 7 0 R]>> -endobj - -7 0 obj -<</JS(this.print\({bUI:true,bSilent:false,bShrinkToFit:true}\);)/S/JavaScript>> -endobj - -xref -0 8 -0000000000 65535 f -0000000015 00000 n -0000000183 00000 n -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000221 00000 n -trailer <</Root 1 0 R>> -startxref -317 -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/simple_xfa.pdf b/chromium/third_party/pdfium/testing/resources/simple_xfa.pdf Binary files differdeleted file mode 100644 index ef8eb7dcc97..00000000000 --- a/chromium/third_party/pdfium/testing/resources/simple_xfa.pdf +++ /dev/null diff --git a/chromium/third_party/pdfium/testing/resources/tagged_alt_text.pdf b/chromium/third_party/pdfium/testing/resources/tagged_alt_text.pdf Binary files differdeleted file mode 100644 index a899ce11af1..00000000000 --- a/chromium/third_party/pdfium/testing/resources/tagged_alt_text.pdf +++ /dev/null diff --git a/chromium/third_party/pdfium/testing/resources/text_form.in b/chromium/third_party/pdfium/testing/resources/text_form.in deleted file mode 100644 index 4872986af18..00000000000 --- a/chromium/third_party/pdfium/testing/resources/text_form.in +++ /dev/null @@ -1,57 +0,0 @@ -{{header}} -{{object 1 0}} -<< - /Type /Catalog - /Pages 2 0 R - /AcroForm << /Fields [ 4 0 R ] /DR 5 0 R >> ->> -endobj -{{object 2 0}} -<< /Count 1 /Kids [ 3 0 R ] /Type /Pages >> -endobj -{{object 3 0}} -<< - /Type /Page - /Parent 2 0 R - /Resources 5 0 R - /MediaBox [ 0 0 300 300 ] - /Contents 8 0 R - /Annots [ 4 0 R ] ->> -endobj -{{object 4 0}} -<< - /Type /Annot - /FT /Tx - /T (Text Box) - /DA (0 0 0 rg /F1 12 Tf) - /Rect [ 100 100 200 130 ] - /Subtype /Widget ->> -endobj -{{object 5 0}} -<< /Font 6 0 R >> -endobj -{{object 6 0}} -<< /F1 7 0 R >> -endobj -{{object 7 0}} << - /Type /Font - /Subtype /Type1 - /BaseFont /Helvetica ->> -{{object 8 0}} -<< /Length 51 >> -stream -BT -0 0 0 rg -/F1 12 Tf -100 150 Td -(Test Form) Tj -ET -endstream -endobj -{{xref}} -trailer<< /Size 8 /Root 1 0 R >> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/text_form.pdf b/chromium/third_party/pdfium/testing/resources/text_form.pdf deleted file mode 100644 index f72a73567bf..00000000000 --- a/chromium/third_party/pdfium/testing/resources/text_form.pdf +++ /dev/null @@ -1,69 +0,0 @@ -%PDF-1.7 -% ò¤ô -1 0 obj -<< - /Type /Catalog - /Pages 2 0 R - /AcroForm << /Fields [ 4 0 R ] /DR 5 0 R >> ->> -endobj -2 0 obj -<< /Count 1 /Kids [ 3 0 R ] /Type /Pages >> -endobj -3 0 obj -<< - /Type /Page - /Parent 2 0 R - /Resources 5 0 R - /MediaBox [ 0 0 300 300 ] - /Contents 8 0 R - /Annots [ 4 0 R ] ->> -endobj -4 0 obj -<< - /Type /Annot - /FT /Tx - /T (Text Box) - /DA (0 0 0 rg /F1 12 Tf) - /Rect [ 100 100 200 130 ] - /Subtype /Widget ->> -endobj -5 0 obj -<< /Font 6 0 R >> -endobj -6 0 obj -<< /F1 7 0 R >> -endobj -7 0 obj << - /Type /Font - /Subtype /Type1 - /BaseFont /Helvetica ->> -8 0 obj -<< /Length 51 >> -stream -BT -0 0 0 rg -/F1 12 Tf -100 150 Td -(Test Form) Tj -ET -endstream -endobj -xref -0 9 -0000000000 65535 f -0000000015 00000 n -0000000114 00000 n -0000000173 00000 n -0000000309 00000 n -0000000445 00000 n -0000000478 00000 n -0000000509 00000 n -0000000578 00000 n -trailer<< /Size 8 /Root 1 0 R >> -startxref -678 -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/trailer_as_hexstring.in b/chromium/third_party/pdfium/testing/resources/trailer_as_hexstring.in deleted file mode 100644 index ec2368fab41..00000000000 --- a/chromium/third_party/pdfium/testing/resources/trailer_as_hexstring.in +++ /dev/null @@ -1,29 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R - /Names << - /Dests 10 0 R - >> - /Dests 14 0 R ->> -endobj -{{object 2 0}} << - /Type /Pages - /Count 1 - /Kids [ - 3 0 R - ] ->> -endobj -{{object 3 0}} << - /Type /Page - /Parent 2 0 R - /MediaBox [0 0 612 792] ->> -endobj -{{xref}} -% trailer erroneously contains a hex string, not a dictionary. -trailer <0000deadbabe0000> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/trailer_as_hexstring.pdf b/chromium/third_party/pdfium/testing/resources/trailer_as_hexstring.pdf deleted file mode 100644 index bd94c4779d3..00000000000 --- a/chromium/third_party/pdfium/testing/resources/trailer_as_hexstring.pdf +++ /dev/null @@ -1,36 +0,0 @@ -%PDF-1.7 -% ò¤ô -1 0 obj << - /Type /Catalog - /Pages 2 0 R - /Names << - /Dests 10 0 R - >> - /Dests 14 0 R ->> -endobj -2 0 obj << - /Type /Pages - /Count 1 - /Kids [ - 3 0 R - ] ->> -endobj -3 0 obj << - /Type /Page - /Parent 2 0 R - /MediaBox [0 0 612 792] ->> -endobj -xref -0 4 -0000000000 65535 f -0000000015 00000 n -0000000119 00000 n -0000000190 00000 n -% trailer erroneously contains a hex string, not a dictionary. -trailer <0000deadbabe0000> -startxref -267 -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/trailer_unterminated.in b/chromium/third_party/pdfium/testing/resources/trailer_unterminated.in deleted file mode 100644 index c0c74b749c8..00000000000 --- a/chromium/third_party/pdfium/testing/resources/trailer_unterminated.in +++ /dev/null @@ -1,31 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R - /Names << - /Dests 10 0 R - >> - /Dests 14 0 R ->> -endobj -{{object 2 0}} << - /Type /Pages - /Count 1 - /Kids [ - 3 0 R - ] ->> -endobj -{{object 3 0}} << - /Type /Page - /Parent 2 0 R - /MediaBox [0 0 612 792] ->> -endobj -{{xref}} -% closing angle-brackets not present for trailer dictionary. -trailer << - /Size 6 - /Root 1 0 R -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/trailer_unterminated.pdf b/chromium/third_party/pdfium/testing/resources/trailer_unterminated.pdf deleted file mode 100644 index be59202db45..00000000000 --- a/chromium/third_party/pdfium/testing/resources/trailer_unterminated.pdf +++ /dev/null @@ -1,38 +0,0 @@ -%PDF-1.7 -% ò¤ô -1 0 obj << - /Type /Catalog - /Pages 2 0 R - /Names << - /Dests 10 0 R - >> - /Dests 14 0 R ->> -endobj -2 0 obj << - /Type /Pages - /Count 1 - /Kids [ - 3 0 R - ] ->> -endobj -3 0 obj << - /Type /Page - /Parent 2 0 R - /MediaBox [0 0 612 792] ->> -endobj -xref -0 4 -0000000000 65535 f -0000000015 00000 n -0000000119 00000 n -0000000190 00000 n -% closing angle-brackets not present for trailer dictionary. -trailer << - /Size 6 - /Root 1 0 R -startxref -267 -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/unsupported_feature.in b/chromium/third_party/pdfium/testing/resources/unsupported_feature.in deleted file mode 100644 index 3aa8632d145..00000000000 --- a/chromium/third_party/pdfium/testing/resources/unsupported_feature.in +++ /dev/null @@ -1,32 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R - /Collection /Test ->> -endobj -{{object 2 0}} << - /Type /Pages - /Count 3 - /Kids [ - 10 0 R - ] ->> -endobj -% Page number 0. -{{object 10 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /MediaBox [0 0 612 792] - /Tabs /R ->> -endobj -{{xref}} -trailer << - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/unsupported_feature.pdf b/chromium/third_party/pdfium/testing/resources/unsupported_feature.pdf deleted file mode 100644 index f7091c50164..00000000000 --- a/chromium/third_party/pdfium/testing/resources/unsupported_feature.pdf +++ /dev/null @@ -1,46 +0,0 @@ -%PDF-1.7 -% ò¤ô -1 0 obj << - /Type /Catalog - /Pages 2 0 R - /Collection /Test ->> -endobj -2 0 obj << - /Type /Pages - /Count 3 - /Kids [ - 10 0 R - ] ->> -endobj -% Page number 0. -10 0 obj << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /MediaBox [0 0 612 792] - /Tabs /R ->> -endobj -xref -0 11 -0000000000 65535 f -0000000015 00000 n -0000000088 00000 n -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000177 00000 n -trailer << - /Root 1 0 R ->> -startxref -312 -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/use_outlines.in b/chromium/third_party/pdfium/testing/resources/use_outlines.in deleted file mode 100644 index b344143f64e..00000000000 --- a/chromium/third_party/pdfium/testing/resources/use_outlines.in +++ /dev/null @@ -1,57 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R - /PageMode /UseOutlines ->> -{{object 2 0}} << - /Type /Pages - /MediaBox [ 0 0 200 200 ] - /Count 1 - /Kids [ 3 0 R ] ->> -endobj -{{object 3 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font << - /F1 4 0 R - /F2 5 0 R - >> - >> - /Contents 6 0 R ->> -endobj -{{object 4 0}} << - /Type /Font - /Subtype /Type1 - /BaseFont /Times-Roman ->> -endobj -{{object 5 0}} << - /Type /Font - /Subtype /Type1 - /BaseFont /Helvetica ->> -endobj -{{object 6 0}} << ->> -stream -BT -20 50 Td -/F1 12 Tf -(Hello, world!) Tj -0 50 Td -/F2 16 Tf -(Goodbye, world!) Tj -ET -endstream -endobj -{{xref}} -trailer << - /Size 6 - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/use_outlines.pdf b/chromium/third_party/pdfium/testing/resources/use_outlines.pdf deleted file mode 100644 index 371ff4083c9..00000000000 --- a/chromium/third_party/pdfium/testing/resources/use_outlines.pdf +++ /dev/null @@ -1,67 +0,0 @@ -%PDF-1.7 -% ò¤ô -1 0 obj << - /Type /Catalog - /Pages 2 0 R - /PageMode /UseOutlines ->> -2 0 obj << - /Type /Pages - /MediaBox [ 0 0 200 200 ] - /Count 1 - /Kids [ 3 0 R ] ->> -endobj -3 0 obj << - /Type /Page - /Parent 2 0 R - /Resources << - /Font << - /F1 4 0 R - /F2 5 0 R - >> - >> - /Contents 6 0 R ->> -endobj -4 0 obj << - /Type /Font - /Subtype /Type1 - /BaseFont /Times-Roman ->> -endobj -5 0 obj << - /Type /Font - /Subtype /Type1 - /BaseFont /Helvetica ->> -endobj -6 0 obj << ->> -stream -BT -20 50 Td -/F1 12 Tf -(Hello, world!) Tj -0 50 Td -/F2 16 Tf -(Goodbye, world!) Tj -ET -endstream -endobj -xref -0 7 -0000000000 65535 f -0000000015 00000 n -0000000086 00000 n -0000000179 00000 n -0000000321 00000 n -0000000399 00000 n -0000000475 00000 n -trailer << - /Size 6 - /Root 1 0 R ->> -startxref -596 -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/viewer_ref.in b/chromium/third_party/pdfium/testing/resources/viewer_ref.in deleted file mode 100644 index 62ae372dfe9..00000000000 --- a/chromium/third_party/pdfium/testing/resources/viewer_ref.in +++ /dev/null @@ -1,57 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R - /ViewerPreferences << - /Foo /foo - /HideToolbar true - /Direction /R2L - /ViewArea /CropBox - /NumCopies 5 - >> ->> -endobj -{{object 2 0}} << - /Type /Pages - /Count 1 - /Kids [ - 3 0 R - ] ->> -endobj -% Page number 0. -{{object 3 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /Contents [21 0 R] - /MediaBox [0 0 612 792] ->> -endobj -% Font resource. -{{object 15 0}} << - /Type /Font - /Subtype /Type1 - /BaseFont /Arial ->> -endobj -% Content for page 0. -{{object 21 0}} << - /Length 0 ->> -stream -BT -/F1 20 Tf -100 600 TD (Page1)Tj -ET -endstream -endobj -{{xref}} -trailer << - /Size 6 - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/viewer_ref.pdf b/chromium/third_party/pdfium/testing/resources/viewer_ref.pdf deleted file mode 100644 index fb72107b5bf..00000000000 --- a/chromium/third_party/pdfium/testing/resources/viewer_ref.pdf +++ /dev/null @@ -1,82 +0,0 @@ -%PDF-1.7 -% ò¤ô -1 0 obj << - /Type /Catalog - /Pages 2 0 R - /ViewerPreferences << - /Foo /foo - /HideToolbar true - /Direction /R2L - /ViewArea /CropBox - /NumCopies 5 - >> ->> -endobj -2 0 obj << - /Type /Pages - /Count 1 - /Kids [ - 3 0 R - ] ->> -endobj -% Page number 0. -3 0 obj << - /Type /Page - /Parent 2 0 R - /Resources << - /Font <</F1 15 0 R>> - >> - /Contents [21 0 R] - /MediaBox [0 0 612 792] ->> -endobj -% Font resource. -15 0 obj << - /Type /Font - /Subtype /Type1 - /BaseFont /Arial ->> -endobj -% Content for page 0. -21 0 obj << - /Length 0 ->> -stream -BT -/F1 20 Tf -100 600 TD (Page1)Tj -ET -endstream -endobj -xref -0 22 -0000000000 65535 f -0000000015 00000 n -0000000193 00000 n -0000000281 00000 n -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000442 00000 n -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000000 65535 f -0000000537 00000 n -trailer << - /Size 6 - /Root 1 0 R ->> -startxref -625 -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/weblinks.in b/chromium/third_party/pdfium/testing/resources/weblinks.in deleted file mode 100644 index ed20b2e6427..00000000000 --- a/chromium/third_party/pdfium/testing/resources/weblinks.in +++ /dev/null @@ -1,66 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R ->> -{{object 2 0}} << - /Type /Pages - /MediaBox [ 0 0 600 600 ] - /Count 1 - /Kids [ 3 0 R ] ->> -endobj -{{object 3 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font << - /F1 4 0 R - /F2 5 0 R - >> - >> - /Contents 6 0 R ->> -endobj -{{object 4 0}} << - /Type /Font - /Subtype /Type1 - /BaseFont /Times-Roman ->> -endobj -{{object 4 0}} << - /Type /Font - /Subtype /Type1 - /BaseFont /Helvetica ->> -endobj -{{object 6 0}} << ->> -stream -BT -/F1 12 Tf -50 50 Td -(Hello, world! This is not a link.) Tj -0 50 Td -(http://example.com?q=foo. This might be a link.) Tj -/F2 16 Tf -0 50 Td -(https://example.com?q=foo. This might be a link in another font.) Tj -0 50 Td -(javascript:alert(0). This might be a JS link.) Tj -0 50 Td -(ftp://example.org. This might be a FTP link.) Tj -0 50 Td -(file:///home/foo/example.txt. This might be a file link.) Tj -0 50 Td -(This is a rather long and pointless piece of non-link text.) Tj -ET -endstream -endobj -{{xref}} -trailer << - /Size 6 - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/weblinks.pdf b/chromium/third_party/pdfium/testing/resources/weblinks.pdf deleted file mode 100644 index 0d201a45aa7..00000000000 --- a/chromium/third_party/pdfium/testing/resources/weblinks.pdf +++ /dev/null @@ -1,76 +0,0 @@ -%PDF-1.7 -% ò¤ô -1 0 obj << - /Type /Catalog - /Pages 2 0 R ->> -2 0 obj << - /Type /Pages - /MediaBox [ 0 0 600 600 ] - /Count 1 - /Kids [ 3 0 R ] ->> -endobj -3 0 obj << - /Type /Page - /Parent 2 0 R - /Resources << - /Font << - /F1 4 0 R - /F2 5 0 R - >> - >> - /Contents 6 0 R ->> -endobj -4 0 obj << - /Type /Font - /Subtype /Type1 - /BaseFont /Times-Roman ->> -endobj -4 0 obj << - /Type /Font - /Subtype /Type1 - /BaseFont /Helvetica ->> -endobj -6 0 obj << ->> -stream -BT -/F1 12 Tf -50 50 Td -(Hello, world! This is not a link.) Tj -0 50 Td -(http://example.com?q=foo. This might be a link.) Tj -/F2 16 Tf -0 50 Td -(https://example.com?q=foo. This might be a link in another font.) Tj -0 50 Td -(javascript:alert(0). This might be a JS link.) Tj -0 50 Td -(ftp://example.org. This might be a FTP link.) Tj -0 50 Td -(file:///home/foo/example.txt. This might be a file link.) Tj -0 50 Td -(This is a rather long and pointless piece of non-link text.) Tj -ET -endstream -endobj -xref -0 7 -0000000000 65535 f -0000000015 00000 n -0000000061 00000 n -0000000154 00000 n -0000000374 00000 n -0000000000 65535 f -0000000450 00000 n -trailer << - /Size 6 - /Root 1 0 R ->> -startxref -963 -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/weblinks_across_lines.in b/chromium/third_party/pdfium/testing/resources/weblinks_across_lines.in deleted file mode 100644 index bb04b5e9cf2..00000000000 --- a/chromium/third_party/pdfium/testing/resources/weblinks_across_lines.in +++ /dev/null @@ -1,74 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R ->> -{{object 2 0}} << - /Type /Pages - /MediaBox [ 0 0 600 600 ] - /Count 1 - /Kids [ 3 0 R ] ->> -endobj -{{object 3 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font << - /F1 4 0 R - /F2 5 0 R - >> - >> - /Contents 6 0 R ->> -endobj -{{object 4 0}} << - /Type /Font - /Subtype /Type1 - /BaseFont /Times-Roman ->> -endobj -{{object 5 0}} << - /Type /Font - /Subtype /Type1 - /BaseFont /Helvetica ->> -endobj -{{object 6 0}} << ->> -stream -BT -/F1 12 Tf -50 50 Td -(Hello, world! This is not a link.) Tj -0 50 Td -(Is this http://example.com?) Tj -0 50 Td -(foo a link?) Tj -/F2 14 Tf -0 50 Td -(How about this http://example.com/) Tj -0 50 Td -(foo a link?) Tj -0 50 Td -(Is this http://example.com/test-) Tj -0 50 Td -(foo a link?) Tj -(Is this http://abc.com/test-) Tj -0 50 Td -0 50 Td -(foo a link?) Tj -0 50 Td -(And this http://example.com/) Tj -0 50 Td -(http://www.abc.com a link?) Tj -ET -endstream -endobj -{{xref}} -trailer << - /Size 6 - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/weblinks_across_lines.pdf b/chromium/third_party/pdfium/testing/resources/weblinks_across_lines.pdf deleted file mode 100644 index e9327c4b34b..00000000000 --- a/chromium/third_party/pdfium/testing/resources/weblinks_across_lines.pdf +++ /dev/null @@ -1,84 +0,0 @@ -%PDF-1.7 -% ò¤ô -1 0 obj << - /Type /Catalog - /Pages 2 0 R ->> -2 0 obj << - /Type /Pages - /MediaBox [ 0 0 600 600 ] - /Count 1 - /Kids [ 3 0 R ] ->> -endobj -3 0 obj << - /Type /Page - /Parent 2 0 R - /Resources << - /Font << - /F1 4 0 R - /F2 5 0 R - >> - >> - /Contents 6 0 R ->> -endobj -4 0 obj << - /Type /Font - /Subtype /Type1 - /BaseFont /Times-Roman ->> -endobj -5 0 obj << - /Type /Font - /Subtype /Type1 - /BaseFont /Helvetica ->> -endobj -6 0 obj << ->> -stream -BT -/F1 12 Tf -50 50 Td -(Hello, world! This is not a link.) Tj -0 50 Td -(Is this http://example.com?) Tj -0 50 Td -(foo a link?) Tj -/F2 14 Tf -0 50 Td -(How about this http://example.com/) Tj -0 50 Td -(foo a link?) Tj -0 50 Td -(Is this http://example.com/test-) Tj -0 50 Td -(foo a link?) Tj -(Is this http://abc.com/test-) Tj -0 50 Td -0 50 Td -(foo a link?) Tj -0 50 Td -(And this http://example.com/) Tj -0 50 Td -(http://www.abc.com a link?) Tj -ET -endstream -endobj -xref -0 7 -0000000000 65535 f -0000000015 00000 n -0000000061 00000 n -0000000154 00000 n -0000000296 00000 n -0000000374 00000 n -0000000450 00000 n -trailer << - /Size 6 - /Root 1 0 R ->> -startxref -921 -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/zero_length_stream.in b/chromium/third_party/pdfium/testing/resources/zero_length_stream.in deleted file mode 100644 index 5b258d4d746..00000000000 --- a/chromium/third_party/pdfium/testing/resources/zero_length_stream.in +++ /dev/null @@ -1,63 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R ->> -{{object 2 0}} << - /Type /Pages - /MediaBox [ 0 0 200 200 ] - /Count 1 - /Kids [ 3 0 R ] ->> -endobj -{{object 3 0}} << - /Type /Page - /Parent 2 0 R - /Resources << - /Font << - /F1 4 0 R - /F2 5 0 R - >> - >> - /Contents [6 0 R 7 0 R] ->> -endobj -{{object 4 0}} << - /Type /Font - /Subtype /Type1 - /BaseFont /Times-Roman ->> -endobj -{{object 5 0}} << - /Type /Font - /Subtype /Type1 - /BaseFont /Helvetica ->> -endobj -{{object 6 0}} << - /Filter /FlateDecode - /Length 0 ->> -stream -endstream -endobj -{{object 7 0}} << ->> -stream -BT -20 50 Td -/F1 12 Tf -(Hello, world!) Tj -0 50 Td -/F2 16 Tf -(Goodbye, world!) Tj -ET -endstream -endobj -{{xref}} -trailer << - /Size 6 - /Root 1 0 R ->> -{{startxref}} -%%EOF diff --git a/chromium/third_party/pdfium/testing/resources/zero_length_stream.pdf b/chromium/third_party/pdfium/testing/resources/zero_length_stream.pdf deleted file mode 100644 index 90fae5be7f4..00000000000 --- a/chromium/third_party/pdfium/testing/resources/zero_length_stream.pdf +++ /dev/null @@ -1,74 +0,0 @@ -%PDF-1.7 -% ò¤ô -1 0 obj << - /Type /Catalog - /Pages 2 0 R ->> -2 0 obj << - /Type /Pages - /MediaBox [ 0 0 200 200 ] - /Count 1 - /Kids [ 3 0 R ] ->> -endobj -3 0 obj << - /Type /Page - /Parent 2 0 R - /Resources << - /Font << - /F1 4 0 R - /F2 5 0 R - >> - >> - /Contents [6 0 R 7 0 R] ->> -endobj -4 0 obj << - /Type /Font - /Subtype /Type1 - /BaseFont /Times-Roman ->> -endobj -5 0 obj << - /Type /Font - /Subtype /Type1 - /BaseFont /Helvetica ->> -endobj -6 0 obj << - /Filter /FlateDecode - /Length 0 ->> -stream -endstream -endobj -7 0 obj << ->> -stream -BT -20 50 Td -/F1 12 Tf -(Hello, world!) Tj -0 50 Td -/F2 16 Tf -(Goodbye, world!) Tj -ET -endstream -endobj -xref -0 8 -0000000000 65535 f -0000000015 00000 n -0000000061 00000 n -0000000154 00000 n -0000000304 00000 n -0000000382 00000 n -0000000458 00000 n -0000000531 00000 n -trailer << - /Size 6 - /Root 1 0 R ->> -startxref -652 -%%EOF diff --git a/chromium/third_party/pdfium/testing/test_support.cpp b/chromium/third_party/pdfium/testing/test_support.cpp index 608e4ae75bc..e5c3ab45a09 100644 --- a/chromium/third_party/pdfium/testing/test_support.cpp +++ b/chromium/third_party/pdfium/testing/test_support.cpp @@ -7,13 +7,14 @@ #include <stdio.h> #include <string.h> -#include <string> - +#include "core/fdrm/crypto/fx_crypt.h" #include "core/fxcrt/fx_memory.h" +#include "core/fxcrt/fx_string.h" #include "testing/utils/path_service.h" #ifdef PDF_ENABLE_V8 #include "v8/include/libplatform/libplatform.h" +#include "v8/include/v8.h" #endif namespace { @@ -103,6 +104,13 @@ std::unique_ptr<char, pdfium::FreeDeleter> GetFileContents(const char* filename, return buffer; } +std::string GetPlatformString(FPDF_WIDESTRING wstr) { + return std::string( + CFX_WideString::FromUTF16LE(wstr, CFX_WideString::WStringLength(wstr)) + .UTF8Encode() + .c_str()); +} + std::wstring GetPlatformWString(FPDF_WIDESTRING wstr) { if (!wstr) return nullptr; @@ -211,38 +219,3 @@ int TestLoader::GetBlock(void* param, memcpy(pBuf, pLoader->m_pBuf + pos, size); return 1; } - -TestSaver::TestSaver() { - FPDF_FILEWRITE::version = 1; - FPDF_FILEWRITE::WriteBlock = WriteBlockCallback; -} - -void TestSaver::ClearString() { - m_String.clear(); -} - -// static -int TestSaver::WriteBlockCallback(FPDF_FILEWRITE* pFileWrite, - const void* data, - unsigned long size) { - TestSaver* pThis = static_cast<TestSaver*>(pFileWrite); - pThis->m_String.append(static_cast<const char*>(data), size); - return 1; -} - -// static -int TestSaver::GetBlockFromString(void* param, - unsigned long pos, - unsigned char* buf, - unsigned long size) { - std::string* new_file = static_cast<std::string*>(param); - if (!new_file || pos + size < pos) - return 0; - - unsigned long file_size = new_file->size(); - if (pos + size > file_size) - return 0; - - memcpy(buf, new_file->data() + pos, size); - return 1; -} diff --git a/chromium/third_party/pdfium/testing/test_support.h b/chromium/third_party/pdfium/testing/test_support.h index a2d3528e730..feec4bbe0b9 100644 --- a/chromium/third_party/pdfium/testing/test_support.h +++ b/chromium/third_party/pdfium/testing/test_support.h @@ -6,18 +6,12 @@ #define TESTING_TEST_SUPPORT_H_ #include <stdlib.h> + #include <memory> #include <string> #include <vector> -#include "core/fdrm/crypto/fx_crypt.h" -#include "public/fpdf_save.h" #include "public/fpdfview.h" -#include "testing/gtest/include/gtest/gtest.h" - -#ifdef PDF_ENABLE_V8 -#include "v8/include/v8.h" -#endif // PDF_ENABLE_V8 namespace pdfium { @@ -68,9 +62,13 @@ std::unique_ptr<char, pdfium::FreeDeleter> GetFileContents(const char* filename, std::vector<std::string> StringSplit(const std::string& str, char delimiter); +// Converts a FPDF_WIDESTRING to a std::string. +// Deals with differences between UTF16LE and UTF8. +std::string GetPlatformString(FPDF_WIDESTRING wstr); + // Converts a FPDF_WIDESTRING to a std::wstring. // Deals with differences between UTF16LE and wchar_t. -std::wstring GetPlatformWString(const FPDF_WIDESTRING wstr); +std::wstring GetPlatformWString(FPDF_WIDESTRING wstr); // Returns a newly allocated FPDF_WIDESTRING. // Deals with differences between UTF16LE and wchar_t. @@ -81,7 +79,13 @@ std::string CryptToBase16(const uint8_t* digest); std::string GenerateMD5Base16(const uint8_t* data, uint32_t size); #ifdef PDF_ENABLE_V8 +namespace v8 { +class Platform; +} #ifdef V8_USE_EXTERNAL_STARTUP_DATA +namespace v8 { +class StartupData; +} bool InitializeV8ForPDFium(const std::string& exe_path, const std::string& bin_dir, v8::StartupData* natives_blob, @@ -106,25 +110,4 @@ class TestLoader { const size_t m_Len; }; -class TestSaver : public FPDF_FILEWRITE { - public: - TestSaver(); - - void ClearString(); - const std::string& GetString() const { return m_String; } - - protected: - static int GetBlockFromString(void* param, - unsigned long pos, - unsigned char* buf, - unsigned long size); - - private: - static int WriteBlockCallback(FPDF_FILEWRITE* pFileWrite, - const void* data, - unsigned long size); - - std::string m_String; -}; - #endif // TESTING_TEST_SUPPORT_H_ diff --git a/chromium/third_party/pdfium/testing/tools/fixup_pdf_template.py b/chromium/third_party/pdfium/testing/tools/fixup_pdf_template.py index 80a712f6e89..10ca241242f 100755 --- a/chromium/third_party/pdfium/testing/tools/fixup_pdf_template.py +++ b/chromium/third_party/pdfium/testing/tools/fixup_pdf_template.py @@ -10,8 +10,10 @@ script replaces {{name}}-style variables in the input with calculated results {{header}} - expands to the header comment required for PDF files. {{xref}} - expands to a generated xref table, noting the offset. + {{trailer}} - expands to a standard trailer with "1 0 R" as the /Root. {{startxref} - expands to a startxref directive followed by correct offset. - {{object x y}} - expands to |x y obj| declaration, noting the offset.""" + {{object x y}} - expands to |x y obj| declaration, noting the offset. +""" import optparse import os @@ -19,15 +21,19 @@ import re import sys class TemplateProcessor: - HEADER_TOKEN = '{{header}}' + HEADER_TOKEN = '{{header}}' HEADER_REPLACEMENT = '%PDF-1.7\n%\xa0\xf2\xa4\xf4' XREF_TOKEN = '{{xref}}' XREF_REPLACEMENT = 'xref\n%d %d\n' - # XREF rows must be exactly 20 bytes - space required. XREF_REPLACEMENT_N = '%010d %05d n \n' XREF_REPLACEMENT_F = '0000000000 65535 f \n' + # XREF rows must be exactly 20 bytes - space required. + assert(len(XREF_REPLACEMENT_F) == 20) + + TRAILER_TOKEN = '{{trailer}}' + TRAILER_REPLACEMENT = 'trailer<< /Root 1 0 R /Size %d >>' STARTXREF_TOKEN= '{{startxref}}' STARTXREF_REPLACEMENT = 'startxref\n%d' @@ -60,6 +66,9 @@ class TemplateProcessor: if self.XREF_TOKEN in line: self.xref_offset = self.offset line = self.generate_xref_table() + if self.TRAILER_TOKEN in line: + replacement = self.TRAILER_REPLACEMENT % (self.max_object_number + 1) + line = line.replace(self.TRAILER_TOKEN, replacement) if self.STARTXREF_TOKEN in line: replacement = self.STARTXREF_REPLACEMENT % self.xref_offset line = line.replace(self.STARTXREF_TOKEN, replacement) diff --git a/chromium/third_party/pdfium/testing/tools/run_corpus_tests.py b/chromium/third_party/pdfium/testing/tools/run_corpus_tests.py index 49424065796..1175de497c5 100755 --- a/chromium/third_party/pdfium/testing/tools/run_corpus_tests.py +++ b/chromium/third_party/pdfium/testing/tools/run_corpus_tests.py @@ -9,6 +9,8 @@ import test_runner def main(): runner = test_runner.TestRunner('corpus') + runner.SetEnforceExpectedImages(True) + runner.SetOneShotRenderer(True) return runner.Run() if __name__ == '__main__': diff --git a/chromium/third_party/pdfium/testing/tools/run_pixel_tests.py b/chromium/third_party/pdfium/testing/tools/run_pixel_tests.py index aad39c56002..1d61966c2ef 100755 --- a/chromium/third_party/pdfium/testing/tools/run_pixel_tests.py +++ b/chromium/third_party/pdfium/testing/tools/run_pixel_tests.py @@ -9,6 +9,7 @@ import test_runner def main(): runner = test_runner.TestRunner('pixel') + runner.SetEnforceExpectedImages(True) return runner.Run() if __name__ == '__main__': diff --git a/chromium/third_party/pdfium/testing/tools/suppressor.py b/chromium/third_party/pdfium/testing/tools/suppressor.py index 3b2872df95f..2b4b5d3f08a 100755 --- a/chromium/third_party/pdfium/testing/tools/suppressor.py +++ b/chromium/third_party/pdfium/testing/tools/suppressor.py @@ -12,11 +12,16 @@ class Suppressor: feature_vector = feature_string.strip().split(",") self.has_v8 = "V8" in feature_vector self.has_xfa = "XFA" in feature_vector + self.suppression_set = self._LoadSuppressedSet('SUPPRESSIONS', finder) + self.image_suppression_set = self._LoadSuppressedSet( + 'SUPPRESSIONS_IMAGE_DIFF', + finder) + + def _LoadSuppressedSet(self, suppressions_filename, finder): v8_option = "v8" if self.has_v8 else "nov8" xfa_option = "xfa" if self.has_xfa else "noxfa" - - with open(os.path.join(finder.TestingDir(), 'SUPPRESSIONS')) as f: - self.suppression_set = set(self._FilterSuppressions( + with open(os.path.join(finder.TestingDir(), suppressions_filename)) as f: + return set(self._FilterSuppressions( common.os_name(), v8_option, xfa_option, self._ExtractSuppressions(f))) def _ExtractSuppressions(self, f): @@ -47,3 +52,9 @@ class Suppressor: print "%s execution is suppressed" % input_filepath return True return False + + def IsImageDiffSuppressed(self, input_filename): + if input_filename in self.image_suppression_set: + print "%s image diff comparison is suppressed" % input_filename + return True + return False diff --git a/chromium/third_party/pdfium/testing/tools/test_runner.py b/chromium/third_party/pdfium/testing/tools/test_runner.py index 6cd3a6c05ab..9524b7459b0 100644 --- a/chromium/third_party/pdfium/testing/tools/test_runner.py +++ b/chromium/third_party/pdfium/testing/tools/test_runner.py @@ -39,6 +39,8 @@ def TestOneFileParallel(this, test_case): class TestRunner: def __init__(self, dirname): self.test_dir = dirname + self.enforce_expected_images = False + self.oneshot_renderer = False # GenerateAndTest returns a tuple <success, outputfiles> where # success is a boolean indicating whether the tests passed comparison @@ -62,8 +64,8 @@ class TestRunner: raised_exception = self.Generate(source_dir, input_filename, input_root, pdf_path) - if raised_exception != None: - print "FAILURE: " + input_filename + "; " + str(raised_exception) + if raised_exception is not None: + print 'FAILURE: %s; %s' % (input_filename, raised_exception) return False, [] results = [] @@ -72,23 +74,29 @@ class TestRunner: else: raised_exception, results = self.TestPixel(input_root, pdf_path) - if raised_exception != None: - print "FAILURE: " + input_filename + "; " + str(raised_exception) + if raised_exception is not None: + print 'FAILURE: %s; %s' % (input_filename, raised_exception) return False, results - if len(actual_images): + if actual_images: if self.image_differ.HasDifferences(input_filename, source_dir, self.working_dir): return False, results + else: + if (self.enforce_expected_images + and not self.test_suppressor.IsImageDiffSuppressed(input_filename)): + print 'FAILURE: %s; Missing expected images' % input_filename + return False, results + return True, results def Generate(self, source_dir, input_filename, input_root, pdf_path): original_path = os.path.join(source_dir, input_filename) input_path = os.path.join(source_dir, input_root + '.in') - input_event_path = os.path.join(source_dir, input_root + ".evt") + input_event_path = os.path.join(source_dir, input_root + '.evt') if os.path.exists(input_event_path): - output_event_path = os.path.splitext(pdf_path)[0] + ".evt" + output_event_path = os.path.splitext(pdf_path)[0] + '.evt' shutil.copyfile(input_event_path, output_event_path) if not os.path.exists(input_path): @@ -118,6 +126,8 @@ class TestRunner: cmd_to_run = [self.pdfium_test_path, '--send-events', '--png'] if self.gold_results: cmd_to_run.append('--md5') + if self.oneshot_renderer: + cmd_to_run.append('--render-oneshot') cmd_to_run.append(pdf_path) return common.RunCommandExtractHashedFiles(cmd_to_run) @@ -131,6 +141,7 @@ class TestRunner: self.gold_results.AddTestResult(test_name, md5_hash, img_path) if self.test_suppressor.IsResultSuppressed(input_filename): + self.result_suppressed_cases.append(input_filename) if success: self.surprises.append(input_path) else: @@ -178,7 +189,7 @@ class TestRunner: self.pdfium_test_path = finder.ExecutablePath('pdfium_test') if not os.path.exists(self.pdfium_test_path): print "FAILURE: Can't find test executable '%s'" % self.pdfium_test_path - print "Use --build-dir to specify its location." + print 'Use --build-dir to specify its location.' return 1 self.working_dir = finder.WorkingDir(os.path.join('testing', self.test_dir)) @@ -192,45 +203,49 @@ class TestRunner: walk_from_dir = finder.TestingDir(test_dir); - test_cases = [] - input_file_re = re.compile('^[a-zA-Z0-9_.]+[.](in|pdf)$') - if len(args): + self.test_cases = [] + self.execution_suppressed_cases = [] + input_file_re = re.compile('^.+[.](in|pdf)$') + if args: for file_name in args: - file_name.replace(".pdf", ".in") + file_name.replace('.pdf', '.in') input_path = os.path.join(walk_from_dir, file_name) if not os.path.isfile(input_path): print "Can't find test file '%s'" % file_name return 1 - test_cases.append((os.path.basename(input_path), + self.test_cases.append((os.path.basename(input_path), os.path.dirname(input_path))) else: for file_dir, _, filename_list in os.walk(walk_from_dir): for input_filename in filename_list: if input_file_re.match(input_filename): input_path = os.path.join(file_dir, input_filename) - if not self.test_suppressor.IsExecutionSuppressed(input_path): + if self.test_suppressor.IsExecutionSuppressed(input_path): + self.execution_suppressed_cases.append(input_path) + else: if os.path.isfile(input_path): - test_cases.append((input_filename, file_dir)) + self.test_cases.append((input_filename, file_dir)) self.failures = [] self.surprises = [] + self.result_suppressed_cases = [] # Collect Gold results if an output directory was named. self.gold_results = None if options.gold_output_dir: - self.gold_results = gold.GoldResults("pdfium", + self.gold_results = gold.GoldResults('pdfium', options.gold_output_dir, options.gold_properties, options.gold_key, options.gold_ignore_hashes) - if options.num_workers > 1 and len(test_cases) > 1: + if options.num_workers > 1 and len(self.test_cases) > 1: try: pool = multiprocessing.Pool(options.num_workers) worker_func = functools.partial(TestOneFileParallel, self) - worker_results = pool.imap(worker_func, test_cases) + worker_results = pool.imap(worker_func, self.test_cases) for worker_result in worker_results: result, input_filename, source_dir = worker_result input_path = os.path.join(source_dir, input_filename) @@ -243,7 +258,7 @@ class TestRunner: pool.close() pool.join() else: - for test_case in test_cases: + for test_case in self.test_cases: input_filename, input_file_dir = test_case result = self.GenerateAndTest(input_filename, input_file_dir) self.HandleResult(input_filename, @@ -256,7 +271,7 @@ class TestRunner: self.surprises.sort() print '\n\nUnexpected Successes:' for surprise in self.surprises: - print surprise; + print surprise if self.failures: self.failures.sort() @@ -264,6 +279,33 @@ class TestRunner: for failure in self.failures: print failure + self._PrintSummary() + + if self.failures: if not options.ignore_errors: return 1 + return 0 + + def _PrintSummary(self): + number_test_cases = len(self.test_cases) + number_failures = len(self.failures) + number_suppressed = len(self.result_suppressed_cases) + number_successes = number_test_cases - number_failures - number_suppressed + number_surprises = len(self.surprises) + print + print 'Test cases executed: %d' % number_test_cases + print ' Successes: %d' % number_successes + print ' Suppressed: %d' % number_suppressed + print ' Surprises: %d' % number_surprises + print ' Failures: %d' % number_failures + print + print 'Test cases not executed: %d' % len(self.execution_suppressed_cases) + + def SetEnforceExpectedImages(self, new_value): + """Set whether to enforce that each test case provide an expected image.""" + self.enforce_expected_images = new_value + + def SetOneShotRenderer(self, new_value): + """Set whether to use the oneshot renderer. """ + self.oneshot_renderer = new_value diff --git a/chromium/third_party/pdfium/testing/xfa_js_embedder_test.cpp b/chromium/third_party/pdfium/testing/xfa_js_embedder_test.cpp index 4a29872eab7..d36cc815e67 100644 --- a/chromium/third_party/pdfium/testing/xfa_js_embedder_test.cpp +++ b/chromium/third_party/pdfium/testing/xfa_js_embedder_test.cpp @@ -53,18 +53,27 @@ bool XFAJSEmbedderTest::OpenDocument(const std::string& filename, } bool XFAJSEmbedderTest::Execute(const CFX_ByteStringC& input) { - value_ = pdfium::MakeUnique<CFXJSE_Value>(GetIsolate()); - if (script_context_->RunScript(XFA_SCRIPTLANGTYPE_Formcalc, - CFX_WideString::FromUTF8(input).AsStringC(), - value_.get(), GetXFADocument()->GetRoot())) { + if (ExecuteHelper(input)) { return true; } CFXJSE_Value msg(GetIsolate()); value_->GetObjectPropertyByIdx(1, &msg); - EXPECT_TRUE(msg.IsString()); - - fprintf(stderr, "JS: %.*s\n", input.GetLength(), input.c_str()); - fprintf(stderr, "JS ERROR: %ls\n", msg.ToWideString().c_str()); + fprintf(stderr, "JS: %.*s\n", input.GetLength(), input.unterminated_c_str()); + // If the parsing of the input fails, then v8 will not run, so there will be + // no value here to print. + if (msg.IsString() && !msg.ToWideString().IsEmpty()) + fprintf(stderr, "JS ERROR: %ls\n", msg.ToWideString().c_str()); return false; } + +bool XFAJSEmbedderTest::ExecuteSilenceFailure(const CFX_ByteStringC& input) { + return ExecuteHelper(input); +} + +bool XFAJSEmbedderTest::ExecuteHelper(const CFX_ByteStringC& input) { + value_ = pdfium::MakeUnique<CFXJSE_Value>(GetIsolate()); + return script_context_->RunScript(XFA_SCRIPTLANGTYPE_Formcalc, + CFX_WideString::FromUTF8(input).AsStringC(), + value_.get(), GetXFADocument()->GetRoot()); +} diff --git a/chromium/third_party/pdfium/testing/xfa_js_embedder_test.h b/chromium/third_party/pdfium/testing/xfa_js_embedder_test.h index afbdb26e1a5..1dc06f05e65 100644 --- a/chromium/third_party/pdfium/testing/xfa_js_embedder_test.h +++ b/chromium/third_party/pdfium/testing/xfa_js_embedder_test.h @@ -33,6 +33,8 @@ class XFAJSEmbedderTest : public EmbedderTest { CXFA_Document* GetXFADocument(); bool Execute(const CFX_ByteStringC& input); + bool ExecuteSilenceFailure(const CFX_ByteStringC& input); + CFXJSE_Value* GetValue() const { return value_.get(); } private: @@ -40,6 +42,8 @@ class XFAJSEmbedderTest : public EmbedderTest { std::unique_ptr<CFXJSE_Value> value_; v8::Isolate* isolate_; CXFA_ScriptContext* script_context_; + + bool ExecuteHelper(const CFX_ByteStringC& input); }; #endif // TESTING_XFA_JS_EMBEDDER_TEST_H_ diff --git a/chromium/third_party/pdfium/third_party/freetype/README.pdfium b/chromium/third_party/pdfium/third_party/freetype/README.pdfium index b451ed93848..f5c43072c07 100644 --- a/chromium/third_party/pdfium/third_party/freetype/README.pdfium +++ b/chromium/third_party/pdfium/third_party/freetype/README.pdfium @@ -1,7 +1,7 @@ Name: FreeType URL: http://www.freetype.org/ -Version: VER-2-8 -Revision: a12a34451a99cbbcad55d466940fd445171927fd +Version: VER-2-8-73 +Revision: 38bdf22bfe68432aebdd33c198a0bd11b4ebb96f Security Critical: yes License: FreeType License (FTL) License File: FTL.TXT diff --git a/chromium/third_party/pdfium/third_party/libtiff/0010-fix-leak-imagebegin.patch b/chromium/third_party/pdfium/third_party/libtiff/0010-fix-leak-imagebegin.patch deleted file mode 100644 index 41aaf91a385..00000000000 --- a/chromium/third_party/pdfium/third_party/libtiff/0010-fix-leak-imagebegin.patch +++ /dev/null @@ -1,15 +0,0 @@ -diff --git a/third_party/libtiff/tif_getimage.c b/third_party/libtiff/tif_getimage.c -index 8523793..97fa94d 100644 ---- a/third_party/libtiff/tif_getimage.c -+++ b/third_party/libtiff/tif_getimage.c -@@ -478,10 +478,7 @@ TIFFRGBAImageBegin(TIFFRGBAImage* img, TIFF* tif, int stop, char emsg[1024]) - return 1; - - fail_return: -- _TIFFfree( img->redcmap ); -- _TIFFfree( img->greencmap ); -- _TIFFfree( img->bluecmap ); -- img->redcmap = img->greencmap = img->bluecmap = NULL; -+ TIFFRGBAImageEnd(img); - return 0; - } diff --git a/chromium/third_party/pdfium/third_party/libtiff/0011-fix-leak-imagebegin2.patch b/chromium/third_party/pdfium/third_party/libtiff/0011-fix-leak-imagebegin2.patch deleted file mode 100644 index 6d8e402ea71..00000000000 --- a/chromium/third_party/pdfium/third_party/libtiff/0011-fix-leak-imagebegin2.patch +++ /dev/null @@ -1,32 +0,0 @@ -diff --git a/third_party/libtiff/tif_getimage.c b/third_party/libtiff/tif_getimage.c -index 66ace060e..6e605c441 100644 ---- a/third_party/libtiff/tif_getimage.c -+++ b/third_party/libtiff/tif_getimage.c -@@ -284,6 +283,13 @@ TIFFRGBAImageBegin(TIFFRGBAImage* img, TIFF* tif, int stop, char emsg[1024]) - img->redcmap = NULL; - img->greencmap = NULL; - img->bluecmap = NULL; -+ img->Map = NULL; -+ img->BWmap = NULL; -+ img->PALmap = NULL; -+ img->ycbcr = NULL; -+ img->cielab = NULL; -+ img->UaToAa = NULL; -+ img->Bitdepth16To8 = NULL; - img->req_orientation = ORIENTATION_BOTLEFT; /* It is the default */ - - img->tif = tif; -@@ -476,13 +468,6 @@ TIFFRGBAImageBegin(TIFFRGBAImage* img, TIFF* tif, int stop, char emsg[1024]) - photoTag, img->photometric); - goto fail_return; - } -- img->Map = NULL; -- img->BWmap = NULL; -- img->PALmap = NULL; -- img->ycbcr = NULL; -- img->cielab = NULL; -- img->UaToAa = NULL; -- img->Bitdepth16To8 = NULL; - TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &img->width); - TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &img->height); - TIFFGetFieldDefaulted(tif, TIFFTAG_ORIENTATION, &img->orientation); diff --git a/chromium/third_party/pdfium/third_party/libtiff/0012-initialize-tif-rawdata.patch b/chromium/third_party/pdfium/third_party/libtiff/0012-initialize-tif-rawdata.patch deleted file mode 100644 index 2543b89eb01..00000000000 --- a/chromium/third_party/pdfium/third_party/libtiff/0012-initialize-tif-rawdata.patch +++ /dev/null @@ -1,14 +0,0 @@ -diff --git a/third_party/libtiff/tif_read.c b/third_party/libtiff/tif_read.c -index 5cb419bd4..548b1f5ea 100644 ---- a/third_party/libtiff/tif_read.c -+++ b/third_party/libtiff/tif_read.c -@@ -936,6 +936,9 @@ TIFFReadBufferSetup(TIFF* tif, void* bp, tmsize_t size) - return (0); - } - tif->tif_rawdata = (uint8*) _TIFFmalloc(tif->tif_rawdatasize); -+ if (tif->tif_rawdata) -+ memset(tif->tif_rawdata, 0, tif->tif_rawdatasize); -+ - tif->tif_flags |= TIFF_MYBUFFER; - } - if (tif->tif_rawdata == NULL) { diff --git a/chromium/third_party/pdfium/third_party/libtiff/0013-validate-refblackwhite.patch b/chromium/third_party/pdfium/third_party/libtiff/0013-validate-refblackwhite.patch deleted file mode 100644 index a314fbdc3f1..00000000000 --- a/chromium/third_party/pdfium/third_party/libtiff/0013-validate-refblackwhite.patch +++ /dev/null @@ -1,19 +0,0 @@ -diff --git a/third_party/libtiff/tif_dir.c b/third_party/libtiff/tif_dir.c -index 73212c02d..16ce3d3ce 100644 ---- a/third_party/libtiff/tif_dir.c -+++ b/third_party/libtiff/tif_dir.c -@@ -426,6 +426,14 @@ _TIFFVSetField(TIFF* tif, uint32 tag, va_list ap) - case TIFFTAG_REFERENCEBLACKWHITE: - /* XXX should check for null range */ - _TIFFsetFloatArray(&td->td_refblackwhite, va_arg(ap, float*), 6); -+ for (int i = 0; i < 6; i++) { -+ if (isnan(td->td_refblackwhite[i])) { -+ if (i % 2 == 0) -+ td->td_refblackwhite[i] = 0; -+ else -+ td->td_refblackwhite[i] = pow(2, td->td_bitspersample) - 1; -+ } -+ } - break; - case TIFFTAG_INKNAMES: - v = (uint16) va_arg(ap, uint16_vap); diff --git a/chromium/third_party/pdfium/third_party/libtiff/0014-cast-to-unsigned-in-putagreytile.patch b/chromium/third_party/pdfium/third_party/libtiff/0014-cast-to-unsigned-in-putagreytile.patch deleted file mode 100644 index 00336b188c5..00000000000 --- a/chromium/third_party/pdfium/third_party/libtiff/0014-cast-to-unsigned-in-putagreytile.patch +++ /dev/null @@ -1,13 +0,0 @@ -diff --git a/third_party/libtiff/tif_getimage.c b/third_party/libtiff/tif_getimage.c -index 1cf6ac6b4..2861cdd1e 100644 ---- a/third_party/libtiff/tif_getimage.c -+++ b/third_party/libtiff/tif_getimage.c -@@ -1281,7 +1281,7 @@ DECLAREContigPutFunc(putagreytile) - while (h-- > 0) { - for (x = w; x-- > 0;) - { -- *cp++ = BWmap[*pp][0] & (*(pp+1) << 24 | ~A1); -+ *cp++ = BWmap[*pp][0] & ((uint32)*(pp+1) << 24 | ~A1); - pp += samplesperpixel; - } - cp += toskew; diff --git a/chromium/third_party/pdfium/third_party/libtiff/0015-fix-leaks-in-tif_ojpeg.patch b/chromium/third_party/pdfium/third_party/libtiff/0015-fix-leaks-in-tif_ojpeg.patch deleted file mode 100644 index d2ddd4aad66..00000000000 --- a/chromium/third_party/pdfium/third_party/libtiff/0015-fix-leaks-in-tif_ojpeg.patch +++ /dev/null @@ -1,43 +0,0 @@ -diff --git a/third_party/libtiff/tif_ojpeg.c b/third_party/libtiff/tif_ojpeg.c -index e128887bf..465f9ebc4 100644 ---- a/third_party/libtiff/tif_ojpeg.c -+++ b/third_party/libtiff/tif_ojpeg.c -@@ -1791,7 +1791,12 @@ OJPEGReadHeaderInfoSecTablesQTable(TIFF* tif) - TIFFSeekFile(tif,sp->qtable_offset[m],SEEK_SET); - p=(uint32)TIFFReadFile(tif,&ob[sizeof(uint32)+5],64); - if (p!=64) -+ { -+ _TIFFfree(ob); - return(0); -+ } -+ if (sp->qtable[m]!=0) -+ _TIFFfree(sp->qtable[m]); - sp->qtable[m]=ob; - sp->sof_tq[m]=m; - } -@@ -1860,7 +1855,12 @@ OJPEGReadHeaderInfoSecTablesDcTable(TIFF* tif) - rb[sizeof(uint32)+5+n]=o[n]; - p=(uint32)TIFFReadFile(tif,&(rb[sizeof(uint32)+21]),q); - if (p!=q) -+ { -+ _TIFFfree(rb); - return(0); -+ } -+ if (sp->dctable[m]!=0) -+ _TIFFfree(sp->dctable[m]); - sp->dctable[m]=rb; - sp->sos_tda[m]=(m<<4); - } -@@ -1929,7 +1919,12 @@ OJPEGReadHeaderInfoSecTablesAcTable(TIFF* tif) - rb[sizeof(uint32)+5+n]=o[n]; - p=(uint32)TIFFReadFile(tif,&(rb[sizeof(uint32)+21]),q); - if (p!=q) -+ { -+ _TIFFfree(rb); - return(0); -+ } -+ if (sp->actable[m]) -+ _TIFFfree(sp->actable[m]); - sp->actable[m]=rb; - sp->sos_tda[m]=(sp->sos_tda[m]|m); - } diff --git a/chromium/third_party/pdfium/third_party/libtiff/0018-fix-leak-in-PredictorSetupDecode.patch b/chromium/third_party/pdfium/third_party/libtiff/0018-fix-leak-in-PredictorSetupDecode.patch deleted file mode 100644 index e7758eb5732..00000000000 --- a/chromium/third_party/pdfium/third_party/libtiff/0018-fix-leak-in-PredictorSetupDecode.patch +++ /dev/null @@ -1,15 +0,0 @@ -diff --git a/third_party/libtiff/tif_predict.c b/third_party/libtiff/tif_predict.c -index 1bb78e209..0b185d2e2 100644 ---- a/third_party/libtiff/tif_predict.c -+++ b/third_party/libtiff/tif_predict.c -@@ -118,7 +118,10 @@ PredictorSetupDecode(TIFF* tif) - TIFFDirectory* td = &tif->tif_dir; - - if (!(*sp->setupdecode)(tif) || !PredictorSetup(tif)) -+ { -+ (*tif->tif_cleanup)(tif); - return 0; -+ } - - if (sp->predictor == 2) { - switch (td->td_bitspersample) { diff --git a/chromium/third_party/pdfium/third_party/libtiff/0019-oom-TIFFReadDirEntryArray.patch b/chromium/third_party/pdfium/third_party/libtiff/0019-oom-TIFFReadDirEntryArray.patch deleted file mode 100644 index 1144e06ef4a..00000000000 --- a/chromium/third_party/pdfium/third_party/libtiff/0019-oom-TIFFReadDirEntryArray.patch +++ /dev/null @@ -1,81 +0,0 @@ -diff --git a/third_party/libtiff/tif_dirread.c b/third_party/libtiff/tif_dirread.c -index 7dd944483..d50b39a80 100644 ---- a/third_party/libtiff/tif_dirread.c -+++ b/third_party/libtiff/tif_dirread.c -@@ -790,44 +790,43 @@ static enum TIFFReadDirEntryErr TIFFReadDirEntryArray(TIFF* tif, TIFFDirEntry* d - *count=(uint32)direntry->tdir_count; - datasize=(*count)*typesize; - assert((tmsize_t)datasize>0); -- data=_TIFFCheckMalloc(tif, *count, typesize, "ReadDirEntryArray"); -- if (data==0) -- return(TIFFReadDirEntryErrAlloc); -+ const uint32 small_alloc_threshold=(tif->tif_flags&TIFF_BIGTIFF)? 8 : 4; -+ if (datasize <= small_alloc_threshold) -+ { -+ data=_TIFFCheckMalloc(tif, *count, typesize, "ReadDirEntryArray"); -+ if (data==0) -+ return(TIFFReadDirEntryErrAlloc); -+ _TIFFmemcpy(data,&direntry->tdir_offset,datasize); -+ *value=data; -+ return(TIFFReadDirEntryErrOk); -+ } -+ uint64 offset; - if (!(tif->tif_flags&TIFF_BIGTIFF)) - { -- if (datasize<=4) -- _TIFFmemcpy(data,&direntry->tdir_offset,datasize); -- else -- { -- enum TIFFReadDirEntryErr err; -- uint32 offset = direntry->tdir_offset.toff_long; -- if (tif->tif_flags&TIFF_SWAB) -- TIFFSwabLong(&offset); -- err=TIFFReadDirEntryData(tif,(uint64)offset,(tmsize_t)datasize,data); -- if (err!=TIFFReadDirEntryErrOk) -- { -- _TIFFfree(data); -- return(err); -- } -- } -+ uint32 small_offset=direntry->tdir_offset.toff_long; -+ if (tif->tif_flags&TIFF_SWAB) -+ TIFFSwabLong(&small_offset); -+ offset=(uint64)small_offset; - } - else - { -- if (datasize<=8) -- _TIFFmemcpy(data,&direntry->tdir_offset,datasize); -- else -- { -- enum TIFFReadDirEntryErr err; -- uint64 offset = direntry->tdir_offset.toff_long8; -- if (tif->tif_flags&TIFF_SWAB) -- TIFFSwabLong8(&offset); -- err=TIFFReadDirEntryData(tif,offset,(tmsize_t)datasize,data); -- if (err!=TIFFReadDirEntryErrOk) -- { -- _TIFFfree(data); -- return(err); -- } -- } -+ offset = direntry->tdir_offset.toff_long8; -+ if (tif->tif_flags&TIFF_SWAB) -+ TIFFSwabLong8(&offset); -+ } -+ if ((uint64)(-1) - offset < datasize) -+ return(TIFFReadDirEntryErrIo); -+ const uint64 size=isMapped(tif)? (uint64)tif->tif_size : TIFFGetFileSize(tif); -+ if (offset + datasize > size) -+ return(TIFFReadDirEntryErrIo); -+ data=_TIFFCheckMalloc(tif, *count, typesize, "ReadDirEntryArray"); -+ if (data==0) -+ return(TIFFReadDirEntryErrAlloc); -+ enum TIFFReadDirEntryErr err=TIFFReadDirEntryData(tif,offset,(tmsize_t)datasize,data); -+ if (err!=TIFFReadDirEntryErrOk) -+ { -+ _TIFFfree(data); -+ return(err); - } - *value=data; - return(TIFFReadDirEntryErrOk); diff --git a/chromium/third_party/pdfium/third_party/libtiff/0020-upstream-security-fixes.patch b/chromium/third_party/pdfium/third_party/libtiff/0020-upstream-security-fixes.patch deleted file mode 100644 index 139b79ddebb..00000000000 --- a/chromium/third_party/pdfium/third_party/libtiff/0020-upstream-security-fixes.patch +++ /dev/null @@ -1,270 +0,0 @@ -diff --git a/third_party/libtiff/tif_dir.c b/third_party/libtiff/tif_dir.c -index 4b3632ab1..81b849374 100644 ---- a/third_party/libtiff/tif_dir.c -+++ b/third_party/libtiff/tif_dir.c -@@ -862,6 +862,32 @@ _TIFFVGetField(TIFF* tif, uint32 tag, va_list ap) - if( fip == NULL ) /* cannot happen since TIFFGetField() already checks it */ - return 0; - -+ if( tag == TIFFTAG_NUMBEROFINKS ) -+ { -+ int i; -+ for (i = 0; i < td->td_customValueCount; i++) { -+ uint16 val; -+ TIFFTagValue *tv = td->td_customValues + i; -+ if (tv->info->field_tag != tag) -+ continue; -+ val = *(uint16 *)tv->value; -+ /* Truncate to SamplesPerPixel, since the */ -+ /* setting code for INKNAMES assume that there are SamplesPerPixel */ -+ /* inknames. */ -+ /* Fixes http://bugzilla.maptools.org/show_bug.cgi?id=2599 */ -+ if( val > td->td_samplesperpixel ) -+ { -+ TIFFWarningExt(tif->tif_clientdata,"_TIFFVGetField", -+ "Truncating NumberOfInks from %u to %u", -+ val, td->td_samplesperpixel); -+ val = td->td_samplesperpixel; -+ } -+ *va_arg(ap, uint16*) = val; -+ return 1; -+ } -+ return 0; -+ } -+ - /* - * We want to force the custom code to be used for custom - * fields even if the tag happens to match a well known -diff --git a/third_party/libtiff/tif_dirread.c b/third_party/libtiff/tif_dirread.c -index d50b39a80..7dbcf6d86 100644 ---- a/third_party/libtiff/tif_dirread.c -+++ b/third_party/libtiff/tif_dirread.c -@@ -5503,8 +5503,7 @@ ChopUpSingleUncompressedStrip(TIFF* tif) - uint64 rowblockbytes; - uint64 stripbytes; - uint32 strip; -- uint64 nstrips64; -- uint32 nstrips32; -+ uint32 nstrips; - uint32 rowsperstrip; - uint64* newcounts; - uint64* newoffsets; -@@ -5535,18 +5534,17 @@ ChopUpSingleUncompressedStrip(TIFF* tif) - return; - - /* -- * never increase the number of strips in an image -+ * never increase the number of rows per strip - */ - if (rowsperstrip >= td->td_rowsperstrip) - return; -- nstrips64 = TIFFhowmany_64(bytecount, stripbytes); -- if ((nstrips64==0)||(nstrips64>0xFFFFFFFF)) /* something is wonky, do nothing. */ -- return; -- nstrips32 = (uint32)nstrips64; -+ nstrips = TIFFhowmany_32(td->td_imagelength, rowsperstrip); -+ if( nstrips == 0 ) -+ return; - -- newcounts = (uint64*) _TIFFCheckMalloc(tif, nstrips32, sizeof (uint64), -+ newcounts = (uint64*) _TIFFCheckMalloc(tif, nstrips, sizeof (uint64), - "for chopped \"StripByteCounts\" array"); -- newoffsets = (uint64*) _TIFFCheckMalloc(tif, nstrips32, sizeof (uint64), -+ newoffsets = (uint64*) _TIFFCheckMalloc(tif, nstrips, sizeof (uint64), - "for chopped \"StripOffsets\" array"); - if (newcounts == NULL || newoffsets == NULL) { - /* -@@ -5563,18 +5561,18 @@ ChopUpSingleUncompressedStrip(TIFF* tif) - * Fill the strip information arrays with new bytecounts and offsets - * that reflect the broken-up format. - */ -- for (strip = 0; strip < nstrips32; strip++) { -+ for (strip = 0; strip < nstrips; strip++) { - if (stripbytes > bytecount) - stripbytes = bytecount; - newcounts[strip] = stripbytes; -- newoffsets[strip] = offset; -+ newoffsets[strip] = stripbytes ? offset : 0; - offset += stripbytes; - bytecount -= stripbytes; - } - /* - * Replace old single strip info with multi-strip info. - */ -- td->td_stripsperimage = td->td_nstrips = nstrips32; -+ td->td_stripsperimage = td->td_nstrips = nstrips; - TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, rowsperstrip); - - _TIFFfree(td->td_stripbytecount); -diff --git a/third_party/libtiff/tif_luv.c b/third_party/libtiff/tif_luv.c -index ca08f30a7..220c15034 100644 ---- a/third_party/libtiff/tif_luv.c -+++ b/third_party/libtiff/tif_luv.c -@@ -158,6 +158,7 @@ - typedef struct logLuvState LogLuvState; - - struct logLuvState { -+ int encoder_state; /* 1 if encoder correctly initialized */ - int user_datafmt; /* user data format */ - int encode_meth; /* encoding method */ - int pixel_size; /* bytes per pixel */ -@@ -1552,6 +1553,7 @@ LogLuvSetupEncode(TIFF* tif) - td->td_photometric, "must be either LogLUV or LogL"); - break; - } -+ sp->encoder_state = 1; - return (1); - notsupported: - TIFFErrorExt(tif->tif_clientdata, module, -@@ -1563,19 +1565,27 @@ notsupported: - static void - LogLuvClose(TIFF* tif) - { -+ LogLuvState* sp = (LogLuvState*) tif->tif_data; - TIFFDirectory *td = &tif->tif_dir; - -+ assert(sp != 0); - /* - * For consistency, we always want to write out the same - * bitspersample and sampleformat for our TIFF file, - * regardless of the data format being used by the application. - * Since this routine is called after tags have been set but - * before they have been recorded in the file, we reset them here. -+ * Note: this is really a nasty approach. See PixarLogClose - */ -- td->td_samplesperpixel = -- (td->td_photometric == PHOTOMETRIC_LOGL) ? 1 : 3; -- td->td_bitspersample = 16; -- td->td_sampleformat = SAMPLEFORMAT_INT; -+ if( sp->encoder_state ) -+ { -+ /* See PixarLogClose. Might avoid issues with tags whose size depends -+ * on those below, but not completely sure this is enough. */ -+ td->td_samplesperpixel = -+ (td->td_photometric == PHOTOMETRIC_LOGL) ? 1 : 3; -+ td->td_bitspersample = 16; -+ td->td_sampleformat = SAMPLEFORMAT_INT; -+ } - } - - static void -diff --git a/third_party/libtiff/tif_ojpeg.c b/third_party/libtiff/tif_ojpeg.c -index e128887bf..cb84be96b 100644 ---- a/third_party/libtiff/tif_ojpeg.c -+++ b/third_party/libtiff/tif_ojpeg.c -@@ -253,6 +253,7 @@ typedef enum { - - typedef struct { - TIFF* tif; -+ int decoder_ok; - #ifndef LIBJPEG_ENCAP_EXTERNAL - JMP_BUF exit_jmpbuf; - #endif -@@ -731,6 +732,7 @@ OJPEGPreDecode(TIFF* tif, uint16 s) - } - sp->write_curstrile++; - } -+ sp->decoder_ok = 1; - return(1); - } - -@@ -793,8 +795,14 @@ OJPEGPreDecodeSkipScanlines(TIFF* tif) - static int - OJPEGDecode(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s) - { -+ static const char module[]="OJPEGDecode"; - OJPEGState* sp=(OJPEGState*)tif->tif_data; - (void)s; -+ if( !sp->decoder_ok ) -+ { -+ TIFFErrorExt(tif->tif_clientdata,module,"Cannot decode: decoder not correctly initialized"); -+ return 0; -+ } - if (sp->libjpeg_jpeg_query_style==0) - { - if (OJPEGDecodeRaw(tif,buf,cc)==0) -diff --git a/third_party/libtiff/tif_pixarlog.c b/third_party/libtiff/tif_pixarlog.c -index 8f6ca8f63..e6574ec3d 100644 ---- a/third_party/libtiff/tif_pixarlog.c -+++ b/third_party/libtiff/tif_pixarlog.c -@@ -1233,8 +1233,10 @@ PixarLogPostEncode(TIFF* tif) - static void - PixarLogClose(TIFF* tif) - { -+ PixarLogState* sp = (PixarLogState*) tif->tif_data; - TIFFDirectory *td = &tif->tif_dir; - -+ assert(sp != 0); - /* In a really sneaky (and really incorrect, and untruthful, and - * troublesome, and error-prone) maneuver that completely goes against - * the spirit of TIFF, and breaks TIFF, on close, we covertly -@@ -1243,8 +1245,19 @@ PixarLogClose(TIFF* tif) - * readers that don't know about PixarLog, or how to set - * the PIXARLOGDATFMT pseudo-tag. - */ -- td->td_bitspersample = 8; -- td->td_sampleformat = SAMPLEFORMAT_UINT; -+ -+ if (sp->state&PLSTATE_INIT) { -+ /* We test the state to avoid an issue such as in -+ * http://bugzilla.maptools.org/show_bug.cgi?id=2604 -+ * What appends in that case is that the bitspersample is 1 and -+ * a TransferFunction is set. The size of the TransferFunction -+ * depends on 1<<bitspersample. So if we increase it, an access -+ * out of the buffer will happen at directory flushing. -+ * Another option would be to clear those targs. -+ */ -+ td->td_bitspersample = 8; -+ td->td_sampleformat = SAMPLEFORMAT_UINT; -+ } - } - - static void -diff --git a/third_party/libtiff/tif_read.c b/third_party/libtiff/tif_read.c -index 795153bbf..1ba100e54 100644 ---- a/third_party/libtiff/tif_read.c -+++ b/third_party/libtiff/tif_read.c -@@ -346,7 +346,7 @@ TIFFReadEncodedStrip(TIFF* tif, uint32 strip, void* buf, tmsize_t size) - rowsperstrip=td->td_rowsperstrip; - if (rowsperstrip>td->td_imagelength) - rowsperstrip=td->td_imagelength; -- stripsperplane=((td->td_imagelength+rowsperstrip-1)/rowsperstrip); -+ stripsperplane= TIFFhowmany_32_maxuint_compat(td->td_imagelength, rowsperstrip); - stripinplane=(strip%stripsperplane); - plane=(uint16)(strip/stripsperplane); - rows=td->td_imagelength-stripinplane*rowsperstrip; -diff --git a/third_party/libtiff/tif_strip.c b/third_party/libtiff/tif_strip.c -index b6098dd31..3b55285cd 100644 ---- a/third_party/libtiff/tif_strip.c -+++ b/third_party/libtiff/tif_strip.c -@@ -63,15 +63,6 @@ TIFFNumberOfStrips(TIFF* tif) - TIFFDirectory *td = &tif->tif_dir; - uint32 nstrips; - -- /* If the value was already computed and store in td_nstrips, then return it, -- since ChopUpSingleUncompressedStrip might have altered and resized the -- since the td_stripbytecount and td_stripoffset arrays to the new value -- after the initial affectation of td_nstrips = TIFFNumberOfStrips() in -- tif_dirread.c ~line 3612. -- See http://bugzilla.maptools.org/show_bug.cgi?id=2587 */ -- if( td->td_nstrips ) -- return td->td_nstrips; -- - nstrips = (td->td_rowsperstrip == (uint32) -1 ? 1 : - TIFFhowmany_32(td->td_imagelength, td->td_rowsperstrip)); - if (td->td_planarconfig == PLANARCONFIG_SEPARATE) -diff --git a/third_party/libtiff/tiffiop.h b/third_party/libtiff/tiffiop.h -index b6db1e932..1925a6b5e 100644 ---- a/third_party/libtiff/tiffiop.h -+++ b/third_party/libtiff/tiffiop.h -@@ -249,6 +249,10 @@ struct tiff { - #define TIFFhowmany_32(x, y) (((uint32)x < (0xffffffff - (uint32)(y-1))) ? \ - ((((uint32)(x))+(((uint32)(y))-1))/((uint32)(y))) : \ - 0U) -+/* Variant of TIFFhowmany_32() that doesn't return 0 if x close to MAXUINT. */ -+/* Caution: TIFFhowmany_32_maxuint_compat(x,y)*y might overflow */ -+#define TIFFhowmany_32_maxuint_compat(x, y) \ -+ (((uint32)(x) / (uint32)(y)) + ((((uint32)(x) % (uint32)(y)) != 0) ? 1 : 0)) - #define TIFFhowmany8_32(x) (((x)&0x07)?((uint32)(x)>>3)+1:(uint32)(x)>>3) - #define TIFFroundup_32(x, y) (TIFFhowmany_32(x,y)*(y)) - #define TIFFhowmany_64(x, y) ((((uint64)(x))+(((uint64)(y))-1))/((uint64)(y))) diff --git a/chromium/third_party/pdfium/third_party/libtiff/0021-oom-TIFFFillStrip.patch b/chromium/third_party/pdfium/third_party/libtiff/0021-oom-TIFFFillStrip.patch deleted file mode 100644 index a64dc5ed13a..00000000000 --- a/chromium/third_party/pdfium/third_party/libtiff/0021-oom-TIFFFillStrip.patch +++ /dev/null @@ -1,18 +0,0 @@ -diff --git a/third_party/libtiff/tif_read.c b/third_party/libtiff/tif_read.c -index 1ba100e54..c25e7e79f 100644 ---- a/third_party/libtiff/tif_read.c -+++ b/third_party/libtiff/tif_read.c -@@ -616,6 +616,13 @@ TIFFFillStrip(TIFF* tif, uint32 strip) - TIFFErrorExt(tif->tif_clientdata,module,"Integer overflow"); - return(0); - } -+ const tmsize_t size=isMapped(tif)? tif->tif_size : (tmsize_t)TIFFGetFileSize(tif); -+ if (bytecountm > size) { -+ TIFFErrorExt(tif->tif_clientdata, module, -+ "Requested read strip size %lu is too large", -+ (unsigned long) strip); -+ return (0); -+ } - if (bytecountm > tif->tif_rawdatasize) { - tif->tif_curstrip = NOSTRIP; - if ((tif->tif_flags & TIFF_MYBUFFER) == 0) { diff --git a/chromium/third_party/pdfium/third_party/libtiff/0022-upstream-patch-0012.patch b/chromium/third_party/pdfium/third_party/libtiff/0022-upstream-patch-0012.patch deleted file mode 100644 index ce9b5ebc91a..00000000000 --- a/chromium/third_party/pdfium/third_party/libtiff/0022-upstream-patch-0012.patch +++ /dev/null @@ -1,29 +0,0 @@ -diff --git a/third_party/libtiff/tif_read.c b/third_party/libtiff/tif_read.c -index c25e7e79f..47686a473 100644 ---- a/third_party/libtiff/tif_read.c -+++ b/third_party/libtiff/tif_read.c -@@ -983,9 +983,9 @@ TIFFReadBufferSetup(TIFF* tif, void* bp, tmsize_t size) - "Invalid buffer size"); - return (0); - } -- tif->tif_rawdata = (uint8*) _TIFFmalloc(tif->tif_rawdatasize); -- if (tif->tif_rawdata) -- memset(tif->tif_rawdata, 0, tif->tif_rawdatasize); -+ /* Initialize to zero to avoid uninitialized buffers in case of */ -+ /* short reads (http://bugzilla.maptools.org/show_bug.cgi?id=2651) */ -+ tif->tif_rawdata = (uint8*) _TIFFcalloc(1, tif->tif_rawdatasize); - - tif->tif_flags |= TIFF_MYBUFFER; - } -diff --git a/third_party/libtiff/tiffio.h b/third_party/libtiff/tiffio.h -index dd6c9a429..7d0da761f 100644 ---- a/third_party/libtiff/tiffio.h -+++ b/third_party/libtiff/tiffio.h -@@ -293,6 +293,7 @@ extern TIFFCodec* TIFFGetConfiguredCODECs(void); - */ - - extern void* _TIFFmalloc(tmsize_t s); -+extern void* _TIFFcalloc(tmsize_t nmemb, tmsize_t siz); - extern void* _TIFFrealloc(void* p, tmsize_t s); - extern void _TIFFmemset(void* p, int v, tmsize_t c); - extern void _TIFFmemcpy(void* d, const void* s, tmsize_t c); diff --git a/chromium/third_party/pdfium/third_party/libtiff/0023-upstream-security-fixes.patch b/chromium/third_party/pdfium/third_party/libtiff/0023-upstream-security-fixes.patch deleted file mode 100644 index 3566e489e8a..00000000000 --- a/chromium/third_party/pdfium/third_party/libtiff/0023-upstream-security-fixes.patch +++ /dev/null @@ -1,353 +0,0 @@ -diff --git a/third_party/libtiff/tif_dir.c b/third_party/libtiff/tif_dir.c -index 81b849374..72148411f 100644 ---- a/third_party/libtiff/tif_dir.c -+++ b/third_party/libtiff/tif_dir.c -@@ -31,6 +31,7 @@ - * (and also some miscellaneous stuff) - */ - #include "tiffiop.h" -+#include <float.h> - - /* - * These are used in the backwards compatibility code... -@@ -154,6 +155,15 @@ bad: - return (0); - } - -+static float TIFFClampDoubleToFloat( double val ) -+{ -+ if( val > FLT_MAX ) -+ return FLT_MAX; -+ if( val < -FLT_MAX ) -+ return -FLT_MAX; -+ return (float)val; -+} -+ - static int - _TIFFVSetField(TIFF* tif, uint32 tag, va_list ap) - { -@@ -312,13 +322,13 @@ _TIFFVSetField(TIFF* tif, uint32 tag, va_list ap) - dblval = va_arg(ap, double); - if( dblval < 0 ) - goto badvaluedouble; -- td->td_xresolution = (float) dblval; -+ td->td_xresolution = TIFFClampDoubleToFloat( dblval ); - break; - case TIFFTAG_YRESOLUTION: - dblval = va_arg(ap, double); - if( dblval < 0 ) - goto badvaluedouble; -- td->td_yresolution = (float) dblval; -+ td->td_yresolution = TIFFClampDoubleToFloat( dblval ); - break; - case TIFFTAG_PLANARCONFIG: - v = (uint16) va_arg(ap, uint16_vap); -@@ -327,10 +337,10 @@ _TIFFVSetField(TIFF* tif, uint32 tag, va_list ap) - td->td_planarconfig = (uint16) v; - break; - case TIFFTAG_XPOSITION: -- td->td_xposition = (float) va_arg(ap, double); -+ td->td_xposition = TIFFClampDoubleToFloat( va_arg(ap, double) ); - break; - case TIFFTAG_YPOSITION: -- td->td_yposition = (float) va_arg(ap, double); -+ td->td_yposition = TIFFClampDoubleToFloat( va_arg(ap, double) ); - break; - case TIFFTAG_RESOLUTIONUNIT: - v = (uint16) va_arg(ap, uint16_vap); -diff --git a/third_party/libtiff/tif_dirread.c b/third_party/libtiff/tif_dirread.c -index 7dbcf6d86..0926e1625 100644 ---- a/third_party/libtiff/tif_dirread.c -+++ b/third_party/libtiff/tif_dirread.c -@@ -40,6 +40,7 @@ - */ - - #include "tiffiop.h" -+#include <float.h> - - #define IGNORE 0 /* tag placeholder used below */ - #define FAILED_FII ((uint32) -1) -@@ -2405,7 +2406,14 @@ static enum TIFFReadDirEntryErr TIFFReadDirEntryFloatArray(TIFF* tif, TIFFDirEnt - ma=(double*)origdata; - mb=data; - for (n=0; n<count; n++) -- *mb++=(float)(*ma++); -+ { -+ double val = *ma++; -+ if( val > FLT_MAX ) -+ val = FLT_MAX; -+ else if( val < -FLT_MAX ) -+ val = -FLT_MAX; -+ *mb++=(float)val; -+ } - } - break; - } -@@ -2871,7 +2879,10 @@ static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckedRational(TIFF* tif, TIFFD - m.l = direntry->tdir_offset.toff_long8; - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabArrayOfLong(m.i,2); -- if (m.i[0]==0) -+ /* Not completely sure what we should do when m.i[1]==0, but some */ -+ /* sanitizers do not like division by 0.0: */ -+ /* http://bugzilla.maptools.org/show_bug.cgi?id=2644 */ -+ if (m.i[0]==0 || m.i[1]==0) - *value=0.0; - else - *value=(double)m.i[0]/(double)m.i[1]; -@@ -2899,7 +2910,10 @@ static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckedSrational(TIFF* tif, TIFF - m.l=direntry->tdir_offset.toff_long8; - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabArrayOfLong(m.i,2); -- if ((int32)m.i[0]==0) -+ /* Not completely sure what we should do when m.i[1]==0, but some */ -+ /* sanitizers do not like division by 0.0: */ -+ /* http://bugzilla.maptools.org/show_bug.cgi?id=2644 */ -+ if ((int32)m.i[0]==0 || m.i[1]==0) - *value=0.0; - else - *value=(double)((int32)m.i[0])/(double)m.i[1]; -diff --git a/third_party/libtiff/tif_dirwrite.c b/third_party/libtiff/tif_dirwrite.c -index d34f6f611..f4d8034ec 100644 ---- a/third_party/libtiff/tif_dirwrite.c -+++ b/third_party/libtiff/tif_dirwrite.c -@@ -30,6 +30,7 @@ - * Directory Write Support Routines. - */ - #include "tiffiop.h" -+#include <float.h> - - #ifdef HAVE_IEEEFP - #define TIFFCvtNativeToIEEEFloat(tif, n, fp) -@@ -939,6 +940,69 @@ bad: - return(0); - } - -+static float TIFFClampDoubleToFloat( double val ) -+{ -+ if( val > FLT_MAX ) -+ return FLT_MAX; -+ if( val < -FLT_MAX ) -+ return -FLT_MAX; -+ return (float)val; -+} -+ -+static int8 TIFFClampDoubleToInt8( double val ) -+{ -+ if( val > 127 ) -+ return 127; -+ if( val < -128 || val != val ) -+ return -128; -+ return (int8)val; -+} -+ -+static int16 TIFFClampDoubleToInt16( double val ) -+{ -+ if( val > 32767 ) -+ return 32767; -+ if( val < -32768 || val != val ) -+ return -32768; -+ return (int16)val; -+} -+ -+static int32 TIFFClampDoubleToInt32( double val ) -+{ -+ if( val > 0x7FFFFFFF ) -+ return 0x7FFFFFFF; -+ if( val < -0x7FFFFFFF-1 || val != val ) -+ return -0x7FFFFFFF-1; -+ return (int32)val; -+} -+ -+static uint8 TIFFClampDoubleToUInt8( double val ) -+{ -+ if( val < 0 ) -+ return 0; -+ if( val > 255 || val != val ) -+ return 255; -+ return (uint8)val; -+} -+ -+static uint16 TIFFClampDoubleToUInt16( double val ) -+{ -+ if( val < 0 ) -+ return 0; -+ if( val > 65535 || val != val ) -+ return 65535; -+ return (uint16)val; -+} -+ -+static uint32 TIFFClampDoubleToUInt32( double val ) -+{ -+ if( val < 0 ) -+ return 0; -+ if( val > 0xFFFFFFFFU || val != val ) -+ return 0xFFFFFFFFU; -+ return (uint32)val; -+} -+ - static int - TIFFWriteDirectoryTagSampleformatArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, double* value) - { -@@ -959,7 +1023,7 @@ TIFFWriteDirectoryTagSampleformatArray(TIFF* tif, uint32* ndir, TIFFDirEntry* di - if (tif->tif_dir.td_bitspersample<=32) - { - for (i = 0; i < count; ++i) -- ((float*)conv)[i] = (float)value[i]; -+ ((float*)conv)[i] = TIFFClampDoubleToFloat(value[i]); - ok = TIFFWriteDirectoryTagFloatArray(tif,ndir,dir,tag,count,(float*)conv); - } - else -@@ -971,19 +1035,19 @@ TIFFWriteDirectoryTagSampleformatArray(TIFF* tif, uint32* ndir, TIFFDirEntry* di - if (tif->tif_dir.td_bitspersample<=8) - { - for (i = 0; i < count; ++i) -- ((int8*)conv)[i] = (int8)value[i]; -+ ((int8*)conv)[i] = TIFFClampDoubleToInt8(value[i]); - ok = TIFFWriteDirectoryTagSbyteArray(tif,ndir,dir,tag,count,(int8*)conv); - } - else if (tif->tif_dir.td_bitspersample<=16) - { - for (i = 0; i < count; ++i) -- ((int16*)conv)[i] = (int16)value[i]; -+ ((int16*)conv)[i] = TIFFClampDoubleToInt16(value[i]); - ok = TIFFWriteDirectoryTagSshortArray(tif,ndir,dir,tag,count,(int16*)conv); - } - else - { - for (i = 0; i < count; ++i) -- ((int32*)conv)[i] = (int32)value[i]; -+ ((int32*)conv)[i] = TIFFClampDoubleToInt32(value[i]); - ok = TIFFWriteDirectoryTagSlongArray(tif,ndir,dir,tag,count,(int32*)conv); - } - break; -@@ -991,19 +1055,19 @@ TIFFWriteDirectoryTagSampleformatArray(TIFF* tif, uint32* ndir, TIFFDirEntry* di - if (tif->tif_dir.td_bitspersample<=8) - { - for (i = 0; i < count; ++i) -- ((uint8*)conv)[i] = (uint8)value[i]; -+ ((uint8*)conv)[i] = TIFFClampDoubleToUInt8(value[i]); - ok = TIFFWriteDirectoryTagByteArray(tif,ndir,dir,tag,count,(uint8*)conv); - } - else if (tif->tif_dir.td_bitspersample<=16) - { - for (i = 0; i < count; ++i) -- ((uint16*)conv)[i] = (uint16)value[i]; -+ ((uint16*)conv)[i] = TIFFClampDoubleToUInt16(value[i]); - ok = TIFFWriteDirectoryTagShortArray(tif,ndir,dir,tag,count,(uint16*)conv); - } - else - { - for (i = 0; i < count; ++i) -- ((uint32*)conv)[i] = (uint32)value[i]; -+ ((uint32*)conv)[i] = TIFFClampDoubleToUInt32(value[i]); - ok = TIFFWriteDirectoryTagLongArray(tif,ndir,dir,tag,count,(uint32*)conv); - } - break; -@@ -2094,15 +2158,25 @@ TIFFWriteDirectoryTagCheckedSlong8Array(TIFF* tif, uint32* ndir, TIFFDirEntry* d - static int - TIFFWriteDirectoryTagCheckedRational(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, double value) - { -+ static const char module[] = "TIFFWriteDirectoryTagCheckedRational"; - uint32 m[2]; -- assert(value>=0.0); - assert(sizeof(uint32)==4); -- if (value<=0.0) -+ if( value < 0 ) -+ { -+ TIFFErrorExt(tif->tif_clientdata,module,"Negative value is illegal"); -+ return 0; -+ } -+ else if( value != value ) -+ { -+ TIFFErrorExt(tif->tif_clientdata,module,"Not-a-number value is illegal"); -+ return 0; -+ } -+ else if (value==0.0) - { - m[0]=0; - m[1]=1; - } -- else if (value==(double)(uint32)value) -+ else if (value <= 0xFFFFFFFFU && value==(double)(uint32)value) - { - m[0]=(uint32)value; - m[1]=1; -@@ -2143,12 +2217,13 @@ TIFFWriteDirectoryTagCheckedRationalArray(TIFF* tif, uint32* ndir, TIFFDirEntry* - } - for (na=value, nb=m, nc=0; nc<count; na++, nb+=2, nc++) - { -- if (*na<=0.0) -+ if (*na<=0.0 || *na != *na) - { - nb[0]=0; - nb[1]=1; - } -- else if (*na==(float)(uint32)(*na)) -+ else if (*na >= 0 && *na <= (float)0xFFFFFFFFU && -+ *na==(float)(uint32)(*na)) - { - nb[0]=(uint32)(*na); - nb[1]=1; -diff --git a/third_party/libtiff/tif_jpeg.c b/third_party/libtiff/tif_jpeg.c -index abd0b0aa2..4f154a7c2 100644 ---- a/third_party/libtiff/tif_jpeg.c -+++ b/third_party/libtiff/tif_jpeg.c -@@ -1634,6 +1634,20 @@ JPEGSetupEncode(TIFF* tif) - case PHOTOMETRIC_YCBCR: - sp->h_sampling = td->td_ycbcrsubsampling[0]; - sp->v_sampling = td->td_ycbcrsubsampling[1]; -+ if( sp->h_sampling == 0 || sp->v_sampling == 0 ) -+ { -+ TIFFErrorExt(tif->tif_clientdata, module, -+ "Invalig horizontal/vertical sampling value"); -+ return (0); -+ } -+ if( td->td_bitspersample > 16 ) -+ { -+ TIFFErrorExt(tif->tif_clientdata, module, -+ "BitsPerSample %d not allowed for JPEG", -+ td->td_bitspersample); -+ return (0); -+ } -+ - /* - * A ReferenceBlackWhite field *must* be present since the - * default value is inappropriate for YCbCr. Fill in the -diff --git a/third_party/libtiff/tif_read.c b/third_party/libtiff/tif_read.c -index 47686a473..c916ac8ac 100644 ---- a/third_party/libtiff/tif_read.c -+++ b/third_party/libtiff/tif_read.c -@@ -420,16 +420,25 @@ TIFFReadRawStrip1(TIFF* tif, uint32 strip, void* buf, tmsize_t size, - return ((tmsize_t)(-1)); - } - } else { -- tmsize_t ma,mb; -+ tmsize_t ma; - tmsize_t n; -- ma=(tmsize_t)td->td_stripoffset[strip]; -- mb=ma+size; -- if ((td->td_stripoffset[strip] > (uint64)TIFF_TMSIZE_T_MAX)||(ma>tif->tif_size)) -+ if ((td->td_stripoffset[strip] > (uint64)TIFF_TMSIZE_T_MAX)|| -+ ((ma=(tmsize_t)td->td_stripoffset[strip])>tif->tif_size)) -+ { - n=0; -- else if ((mb<ma)||(mb<size)||(mb>tif->tif_size)) -- n=tif->tif_size-ma; -+ } -+ else if( ma > TIFF_TMSIZE_T_MAX - size ) -+ { -+ n=0; -+ } - else -- n=size; -+ { -+ tmsize_t mb=ma+size; -+ if (mb>tif->tif_size) -+ n=tif->tif_size-ma; -+ else -+ n=size; -+ } - if (n!=size) { - #if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) - TIFFErrorExt(tif->tif_clientdata, module, diff --git a/chromium/third_party/pdfium/third_party/libtiff/0024-upstream-PackBitsDecode-fix.patch b/chromium/third_party/pdfium/third_party/libtiff/0024-upstream-PackBitsDecode-fix.patch deleted file mode 100644 index eaae79746d9..00000000000 --- a/chromium/third_party/pdfium/third_party/libtiff/0024-upstream-PackBitsDecode-fix.patch +++ /dev/null @@ -1,17 +0,0 @@ -diff --git a/third_party/libtiff/tif_packbits.c b/third_party/libtiff/tif_packbits.c -index d2a0165de..92185e7f7 100644 ---- a/third_party/libtiff/tif_packbits.c -+++ b/third_party/libtiff/tif_packbits.c -@@ -244,6 +244,12 @@ PackBitsDecode(TIFF* tif, uint8* op, tmsize_t occ, uint16 s) - (unsigned long) ((tmsize_t)n - occ)); - n = (long)occ; - } -+ if( cc == 0 ) -+ { -+ TIFFWarningExt(tif->tif_clientdata, module, -+ "Terminating PackBitsDecode due to lack of data."); -+ break; -+ } - occ -= n; - b = *bp++; - cc--; diff --git a/chromium/third_party/pdfium/third_party/libtiff/0025-upstream-OOM-gtTileContig.patch b/chromium/third_party/pdfium/third_party/libtiff/0025-upstream-OOM-gtTileContig.patch new file mode 100644 index 00000000000..d4d3d7028fc --- /dev/null +++ b/chromium/third_party/pdfium/third_party/libtiff/0025-upstream-OOM-gtTileContig.patch @@ -0,0 +1,460 @@ +diff --git a/third_party/libtiff/tif_getimage.c b/third_party/libtiff/tif_getimage.c +index 53c938a89..03c9a81fb 100644 +--- a/third_party/libtiff/tif_getimage.c ++++ b/third_party/libtiff/tif_getimage.c +@@ -627,7 +627,7 @@ gtTileContig(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) + uint32 col, row, y, rowstoread; + tmsize_t pos; + uint32 tw, th; +- unsigned char* buf; ++ unsigned char* buf = NULL; + int32 fromskew, toskew; + int64 safeskew; + uint32 nrow; +@@ -636,13 +636,14 @@ gtTileContig(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) + int32 this_toskew, leftmost_toskew; + int32 leftmost_fromskew; + uint32 leftmost_tw; ++ tmsize_t bufsize; + +- buf = (unsigned char*) _TIFFmalloc(TIFFTileSize(tif)); +- if (buf == 0) { +- TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "%s", "No space for tile buffer"); +- return (0); ++ bufsize = TIFFTileSize(tif); ++ if (bufsize == 0) { ++ TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "%s", "No space for tile buffer"); ++ return (0); + } +- _TIFFmemset(buf, 0, TIFFTileSize(tif)); ++ + TIFFGetField(tif, TIFFTAG_TILEWIDTH, &tw); + TIFFGetField(tif, TIFFTAG_TILELENGTH, &th); + +@@ -691,8 +692,9 @@ gtTileContig(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) + col = img->col_offset; + while (tocol < w) + { +- if (TIFFReadTile(tif, buf, col, +- row+img->row_offset, 0, 0)==(tmsize_t)(-1) && img->stoponerr) ++ if (_TIFFReadTileAndAllocBuffer(tif, (void**) &buf, bufsize, col, ++ row+img->row_offset, 0, 0)==(tmsize_t)(-1) && ++ (buf == NULL || img->stoponerr)) + { + ret = 0; + break; +@@ -772,11 +774,11 @@ gtTileSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) + uint32 col, row, y, rowstoread; + tmsize_t pos; + uint32 tw, th; +- unsigned char* buf; +- unsigned char* p0; +- unsigned char* p1; +- unsigned char* p2; +- unsigned char* pa; ++ unsigned char* buf = NULL; ++ unsigned char* p0 = NULL; ++ unsigned char* p1 = NULL; ++ unsigned char* p2 = NULL; ++ unsigned char* pa = NULL; + tmsize_t tilesize; + tmsize_t bufsize; + int32 fromskew, toskew; +@@ -795,16 +797,7 @@ gtTileSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) + TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "Integer overflow in %s", "gtTileSeparate"); + return (0); + } +- buf = (unsigned char*) _TIFFmalloc(bufsize); +- if (buf == 0) { +- TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "%s", "No space for tile buffer"); +- return (0); +- } +- _TIFFmemset(buf, 0, bufsize); +- p0 = buf; +- p1 = p0 + tilesize; +- p2 = p1 + tilesize; +- pa = (alpha?(p2+tilesize):NULL); ++ + TIFFGetField(tif, TIFFTAG_TILEWIDTH, &tw); + TIFFGetField(tif, TIFFTAG_TILELENGTH, &th); + +@@ -824,7 +817,6 @@ gtTileSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) + case PHOTOMETRIC_MINISBLACK: + case PHOTOMETRIC_PALETTE: + colorchannels = 1; +- p2 = p1 = p0; + break; + + default: +@@ -849,7 +841,30 @@ gtTileSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) + col = img->col_offset; + while (tocol < w) + { +- if (TIFFReadTile(tif, p0, col, ++ if( buf == NULL ) ++ { ++ if (_TIFFReadTileAndAllocBuffer( ++ tif, (void**) &buf, bufsize, col, ++ row+img->row_offset,0,0)==(tmsize_t)(-1) ++ && (buf == NULL || img->stoponerr)) ++ { ++ ret = 0; ++ break; ++ } ++ p0 = buf; ++ if( colorchannels == 1 ) ++ { ++ p2 = p1 = p0; ++ pa = (alpha?(p0+3*tilesize):NULL); ++ } ++ else ++ { ++ p1 = p0 + tilesize; ++ p2 = p1 + tilesize; ++ pa = (alpha?(p2+tilesize):NULL); ++ } ++ } ++ else if (TIFFReadTile(tif, p0, col, + row+img->row_offset,0,0)==(tmsize_t)(-1) && img->stoponerr) + { + ret = 0; +@@ -940,13 +955,14 @@ gtStripContig(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) + tileContigRoutine put = img->put.contig; + uint32 row, y, nrow, nrowsub, rowstoread; + tmsize_t pos; +- unsigned char* buf; ++ unsigned char* buf = NULL; + uint32 rowsperstrip; + uint16 subsamplinghor,subsamplingver; + uint32 imagewidth = img->width; + tmsize_t scanline; + int32 fromskew, toskew; + int ret = 1, flip; ++ tmsize_t maxstripsize; + + TIFFGetFieldDefaulted(tif, TIFFTAG_YCBCRSUBSAMPLING, &subsamplinghor, &subsamplingver); + if( subsamplingver == 0 ) { +@@ -954,12 +970,7 @@ gtStripContig(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) + return (0); + } + +- buf = (unsigned char*) _TIFFmalloc(TIFFStripSize(tif)); +- if (buf == 0) { +- TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "No space for strip buffer"); +- return (0); +- } +- _TIFFmemset(buf, 0, TIFFStripSize(tif)); ++ maxstripsize = TIFFStripSize(tif); + + flip = setorientation(img); + if (flip & FLIP_VERTICALLY) { +@@ -981,11 +992,12 @@ gtStripContig(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) + nrowsub = nrow; + if ((nrowsub%subsamplingver)!=0) + nrowsub+=subsamplingver-nrowsub%subsamplingver; +- if (TIFFReadEncodedStrip(tif, ++ if (_TIFFReadEncodedStripAndAllocBuffer(tif, + TIFFComputeStrip(tif,row+img->row_offset, 0), +- buf, ++ (void**)(&buf), ++ maxstripsize, + ((row + img->row_offset)%rowsperstrip + nrowsub) * scanline)==(tmsize_t)(-1) +- && img->stoponerr) ++ && (buf == NULL || img->stoponerr)) + { + ret = 0; + break; +@@ -1029,8 +1041,8 @@ gtStripSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) + { + TIFF* tif = img->tif; + tileSeparateRoutine put = img->put.separate; +- unsigned char *buf; +- unsigned char *p0, *p1, *p2, *pa; ++ unsigned char *buf = NULL; ++ unsigned char *p0 = NULL, *p1 = NULL, *p2 = NULL, *pa = NULL; + uint32 row, y, nrow, rowstoread; + tmsize_t pos; + tmsize_t scanline; +@@ -1049,15 +1061,6 @@ gtStripSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) + TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "Integer overflow in %s", "gtStripSeparate"); + return (0); + } +- p0 = buf = (unsigned char *)_TIFFmalloc(bufsize); +- if (buf == 0) { +- TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "No space for tile buffer"); +- return (0); +- } +- _TIFFmemset(buf, 0, bufsize); +- p1 = p0 + stripsize; +- p2 = p1 + stripsize; +- pa = (alpha?(p2+stripsize):NULL); + + flip = setorientation(img); + if (flip & FLIP_VERTICALLY) { +@@ -1075,7 +1078,6 @@ gtStripSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) + case PHOTOMETRIC_MINISBLACK: + case PHOTOMETRIC_PALETTE: + colorchannels = 1; +- p2 = p1 = p0; + break; + + default: +@@ -1091,7 +1093,31 @@ gtStripSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) + rowstoread = rowsperstrip - (row + img->row_offset) % rowsperstrip; + nrow = (row + rowstoread > h ? h - row : rowstoread); + offset_row = row + img->row_offset; +- if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, offset_row, 0), ++ if( buf == NULL ) ++ { ++ if (_TIFFReadEncodedStripAndAllocBuffer( ++ tif, TIFFComputeStrip(tif, offset_row, 0), ++ (void**) &buf, bufsize, ++ ((row + img->row_offset)%rowsperstrip + nrow) * scanline)==(tmsize_t)(-1) ++ && (buf == NULL || img->stoponerr)) ++ { ++ ret = 0; ++ break; ++ } ++ p0 = buf; ++ if( colorchannels == 1 ) ++ { ++ p2 = p1 = p0; ++ pa = (alpha?(p0+3*stripsize):NULL); ++ } ++ else ++ { ++ p1 = p0 + stripsize; ++ p2 = p1 + stripsize; ++ pa = (alpha?(p2+stripsize):NULL); ++ } ++ } ++ else if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, offset_row, 0), + p0, ((row + img->row_offset)%rowsperstrip + nrow) * scanline)==(tmsize_t)(-1) + && img->stoponerr) + { +diff --git a/third_party/libtiff/tif_read.c b/third_party/libtiff/tif_read.c +index cc4f5d2f6..ad0a778c0 100644 +--- a/third_party/libtiff/tif_read.c ++++ b/third_party/libtiff/tif_read.c +@@ -442,18 +442,17 @@ TIFFReadScanline(TIFF* tif, void* buf, uint32 row, uint16 sample) + } + + /* +- * Read a strip of data and decompress the specified +- * amount into the user-supplied buffer. ++ * Calculate the strip size according to the number of ++ * rows in the strip (check for truncated last strip on any ++ * of the separations). + */ +-tmsize_t +-TIFFReadEncodedStrip(TIFF* tif, uint32 strip, void* buf, tmsize_t size) ++static tmsize_t TIFFReadEncodedStripGetStripSize(TIFF* tif, uint32 strip, uint16* pplane) + { + static const char module[] = "TIFFReadEncodedStrip"; + TIFFDirectory *td = &tif->tif_dir; + uint32 rowsperstrip; + uint32 stripsperplane; + uint32 stripinplane; +- uint16 plane; + uint32 rows; + tmsize_t stripsize; + if (!TIFFCheckRead(tif,0)) +@@ -465,23 +464,37 @@ TIFFReadEncodedStrip(TIFF* tif, uint32 strip, void* buf, tmsize_t size) + (unsigned long)td->td_nstrips); + return((tmsize_t)(-1)); + } +- /* +- * Calculate the strip size according to the number of +- * rows in the strip (check for truncated last strip on any +- * of the separations). +- */ ++ + rowsperstrip=td->td_rowsperstrip; + if (rowsperstrip>td->td_imagelength) + rowsperstrip=td->td_imagelength; + stripsperplane= TIFFhowmany_32_maxuint_compat(td->td_imagelength, rowsperstrip); + stripinplane=(strip%stripsperplane); +- plane=(uint16)(strip/stripsperplane); ++ if( pplane ) *pplane=(uint16)(strip/stripsperplane); + rows=td->td_imagelength-stripinplane*rowsperstrip; + if (rows>rowsperstrip) + rows=rowsperstrip; + stripsize=TIFFVStripSize(tif,rows); + if (stripsize==0) + return((tmsize_t)(-1)); ++ return stripsize; ++} ++ ++/* ++ * Read a strip of data and decompress the specified ++ * amount into the user-supplied buffer. ++ */ ++tmsize_t ++TIFFReadEncodedStrip(TIFF* tif, uint32 strip, void* buf, tmsize_t size) ++{ ++ static const char module[] = "TIFFReadEncodedStrip"; ++ TIFFDirectory *td = &tif->tif_dir; ++ tmsize_t stripsize; ++ uint16 plane; ++ ++ stripsize=TIFFReadEncodedStripGetStripSize(tif, strip, &plane); ++ if (stripsize==((tmsize_t)(-1))) ++ return((tmsize_t)(-1)); + + /* shortcut to avoid an extra memcpy() */ + if( td->td_compression == COMPRESSION_NONE && +@@ -510,6 +523,50 @@ TIFFReadEncodedStrip(TIFF* tif, uint32 strip, void* buf, tmsize_t size) + return(stripsize); + } + ++/* Variant of TIFFReadEncodedStrip() that does ++ * * if *buf == NULL, *buf = _TIFFmalloc(bufsizetoalloc) only after TIFFFillStrip() has ++ * suceeded. This avoid excessive memory allocation in case of truncated ++ * file. ++ * * calls regular TIFFReadEncodedStrip() if *buf != NULL ++ */ ++tmsize_t ++_TIFFReadEncodedStripAndAllocBuffer(TIFF* tif, uint32 strip, ++ void **buf, tmsize_t bufsizetoalloc, ++ tmsize_t size_to_read) ++{ ++ tmsize_t this_stripsize; ++ uint16 plane; ++ ++ if( *buf != NULL ) ++ { ++ return TIFFReadEncodedStrip(tif, strip, *buf, size_to_read); ++ } ++ ++ this_stripsize=TIFFReadEncodedStripGetStripSize(tif, strip, &plane); ++ if (this_stripsize==((tmsize_t)(-1))) ++ return((tmsize_t)(-1)); ++ ++ if ((size_to_read!=(tmsize_t)(-1))&&(size_to_read<this_stripsize)) ++ this_stripsize=size_to_read; ++ if (!TIFFFillStrip(tif,strip)) ++ return((tmsize_t)(-1)); ++ ++ *buf = _TIFFmalloc(bufsizetoalloc); ++ if (*buf == NULL) { ++ TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "No space for strip buffer"); ++ return((tmsize_t)(-1)); ++ } ++ _TIFFmemset(*buf, 0, bufsizetoalloc); ++ ++ if ((*tif->tif_decodestrip)(tif,*buf,this_stripsize,plane)<=0) ++ return((tmsize_t)(-1)); ++ (*tif->tif_postdecode)(tif,*buf,this_stripsize); ++ return(this_stripsize); ++ ++ ++} ++ ++ + static tmsize_t + TIFFReadRawStrip1(TIFF* tif, uint32 strip, void* buf, tmsize_t size, + const char* module) +@@ -939,6 +996,78 @@ TIFFReadEncodedTile(TIFF* tif, uint32 tile, void* buf, tmsize_t size) + return ((tmsize_t)(-1)); + } + ++/* Variant of TIFFReadTile() that does ++ * * if *buf == NULL, *buf = _TIFFmalloc(bufsizetoalloc) only after TIFFFillTile() has ++ * suceeded. This avoid excessive memory allocation in case of truncated ++ * file. ++ * * calls regular TIFFReadEncodedTile() if *buf != NULL ++ */ ++tmsize_t ++_TIFFReadTileAndAllocBuffer(TIFF* tif, ++ void **buf, tmsize_t bufsizetoalloc, ++ uint32 x, uint32 y, uint32 z, uint16 s) ++{ ++ if (!TIFFCheckRead(tif, 1) || !TIFFCheckTile(tif, x, y, z, s)) ++ return ((tmsize_t)(-1)); ++ return (_TIFFReadEncodedTileAndAllocBuffer(tif, ++ TIFFComputeTile(tif, x, y, z, s), ++ buf, bufsizetoalloc, ++ (tmsize_t)(-1))); ++} ++ ++/* Variant of TIFFReadEncodedTile() that does ++ * * if *buf == NULL, *buf = _TIFFmalloc(bufsizetoalloc) only after TIFFFillTile() has ++ * suceeded. This avoid excessive memory allocation in case of truncated ++ * file. ++ * * calls regular TIFFReadEncodedTile() if *buf != NULL ++ */ ++tmsize_t ++_TIFFReadEncodedTileAndAllocBuffer(TIFF* tif, uint32 tile, ++ void **buf, tmsize_t bufsizetoalloc, ++ tmsize_t size_to_read) ++{ ++ static const char module[] = "_TIFFReadEncodedTileAndAllocBuffer"; ++ TIFFDirectory *td = &tif->tif_dir; ++ tmsize_t tilesize = tif->tif_tilesize; ++ ++ if( *buf != NULL ) ++ { ++ return TIFFReadEncodedTile(tif, tile, *buf, size_to_read); ++ } ++ ++ if (!TIFFCheckRead(tif, 1)) ++ return ((tmsize_t)(-1)); ++ if (tile >= td->td_nstrips) { ++ TIFFErrorExt(tif->tif_clientdata, module, ++ "%lu: Tile out of range, max %lu", ++ (unsigned long) tile, (unsigned long) td->td_nstrips); ++ return ((tmsize_t)(-1)); ++ } ++ ++ if (!TIFFFillTile(tif,tile)) ++ return((tmsize_t)(-1)); ++ ++ *buf = _TIFFmalloc(bufsizetoalloc); ++ if (*buf == NULL) { ++ TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), ++ "No space for tile buffer"); ++ return((tmsize_t)(-1)); ++ } ++ _TIFFmemset(*buf, 0, bufsizetoalloc); ++ ++ if (size_to_read == (tmsize_t)(-1)) ++ size_to_read = tilesize; ++ else if (size_to_read > tilesize) ++ size_to_read = tilesize; ++ if( (*tif->tif_decodetile)(tif, ++ (uint8*) *buf, size_to_read, (uint16)(tile/td->td_stripsperimage))) { ++ (*tif->tif_postdecode)(tif, (uint8*) *buf, size_to_read); ++ return (size_to_read); ++ } else ++ return ((tmsize_t)(-1)); ++} ++ ++ + static tmsize_t + TIFFReadRawTile1(TIFF* tif, uint32 tile, void* buf, tmsize_t size, const char* module) + { +diff --git a/third_party/libtiff/tiffiop.h b/third_party/libtiff/tiffiop.h +index 7e415c750..6fb47de5b 100644 +--- a/third_party/libtiff/tiffiop.h ++++ b/third_party/libtiff/tiffiop.h +@@ -364,6 +364,20 @@ extern void* _TIFFCheckRealloc(TIFF*, void*, tmsize_t, tmsize_t, const char*); + extern double _TIFFUInt64ToDouble(uint64); + extern float _TIFFUInt64ToFloat(uint64); + ++extern tmsize_t ++_TIFFReadEncodedStripAndAllocBuffer(TIFF* tif, uint32 strip, ++ void **buf, tmsize_t bufsizetoalloc, ++ tmsize_t size_to_read); ++extern tmsize_t ++_TIFFReadEncodedTileAndAllocBuffer(TIFF* tif, uint32 tile, ++ void **buf, tmsize_t bufsizetoalloc, ++ tmsize_t size_to_read); ++extern tmsize_t ++_TIFFReadTileAndAllocBuffer(TIFF* tif, ++ void **buf, tmsize_t bufsizetoalloc, ++ uint32 x, uint32 y, uint32 z, uint16 s); ++ ++ + extern int TIFFInitDumpMode(TIFF*, int); + #ifdef PACKBITS_SUPPORT + extern int TIFFInitPackBits(TIFF*, int); diff --git a/chromium/third_party/pdfium/third_party/libtiff/README.pdfium b/chromium/third_party/pdfium/third_party/libtiff/README.pdfium index d3c9c658150..285a628fdde 100644 --- a/chromium/third_party/pdfium/third_party/libtiff/README.pdfium +++ b/chromium/third_party/pdfium/third_party/libtiff/README.pdfium @@ -1,6 +1,6 @@ Name: LibTIFF -URL: http://www.remotesensing.org/libtiff/ -Version: 4.0.7 +URL: http://www.simplesystems.org/libtiff/ +Version: 4.0.8 Security Critical: yes License: BSD @@ -15,17 +15,5 @@ Local Modifications: 0006-HeapBufferOverflow-ChopUpSingleUncompressedStrip.patch: Fix a heap buffer overflow 0007-uninitialized-value.patch: Fix potentially uninitialized dircount value 0008-HeapBufferOverflow-ChopUpSingleUncompressedStrip.patch: Fix a heap buffer overflow -0010-fix-leak-imagebegin: Fix a leak when TIFFRGBAImageBegin fails -0011-fix-leak-imagebegin2: Apply upstream fix related to our previous patch -0012-initialize-tif-rawdata.patch: Initialize tif_rawdata to guard against unitialized access -0013-validate-refblackwhite.patch: Make sure the refblackwhite values aren't nan. -0014-cast-to-unsigned-in-putagreytile.patch: casting to avoid undefined shifts. -0015-fix-leaks-in-tif_ojpeg.patch: fix direct leaks in tif_ojpeg.c methods 0017-safe_skews_in_gtTileContig.patch: return error if to/from skews overflow from int32. -0018-fix-leak-in-PredictorSetupDecode.patch: call tif->tif_cleanup if the setup fails. -0019-oom-TIFFReadDirEntryArray.patch: Try to avoid out-of-memory in tif_dirread.c. -0020-upstream-security-fixes.patch: patch our copy with several upstream security fixes. -0021-oom-TIFFFillStrip.patch: Try to avoid out-of-memory in tif_read.c -0022-upstream-patch-0012.patch: Use the upstream solution corresponding to patch 0012. -0023-upstream-security-fixes.patch: more upstream patches related to security issues. -0024-upstream-PackBitsDecode-fix.patch: fix Heap-buffer-overflow in tif_packbits.c. +0025-upstream-OOM-gtTileContig: allocates the decoded buffer only after a first successful TIFFFillStrip. diff --git a/chromium/third_party/pdfium/third_party/libtiff/tif_color.c b/chromium/third_party/pdfium/third_party/libtiff/tif_color.c index 89194c20760..8b8418c3011 100644 --- a/chromium/third_party/pdfium/third_party/libtiff/tif_color.c +++ b/chromium/third_party/pdfium/third_party/libtiff/tif_color.c @@ -1,4 +1,4 @@ -/* $Id: tif_color.c,v 1.22 2016-09-04 21:32:56 erouault Exp $ */ +/* $Id: tif_color.c,v 1.23 2017-05-13 18:17:34 erouault Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -199,6 +199,23 @@ TIFFYCbCrtoRGB(TIFFYCbCrToRGB *ycbcr, uint32 Y, int32 Cb, int32 Cr, *b = CLAMP(i, 0, 255); } +/* Clamp function for sanitization purposes. Normally clamping should not */ +/* occur for well behaved chroma and refBlackWhite coefficients */ +static float CLAMPw(float v, float vmin, float vmax) +{ + if( v < vmin ) + { + /* printf("%f clamped to %f\n", v, vmin); */ + return vmin; + } + if( v > vmax ) + { + /* printf("%f clamped to %f\n", v, vmax); */ + return vmax; + } + return v; +} + /* * Initialize the YCbCr->RGB conversion tables. The conversion * is done according to the 6.0 spec: @@ -238,10 +255,10 @@ TIFFYCbCrToRGBInit(TIFFYCbCrToRGB* ycbcr, float *luma, float *refBlackWhite) ycbcr->Cb_g_tab = ycbcr->Cr_g_tab + 256; ycbcr->Y_tab = ycbcr->Cb_g_tab + 256; - { float f1 = 2-2*LumaRed; int32 D1 = FIX(f1); - float f2 = LumaRed*f1/LumaGreen; int32 D2 = -FIX(f2); - float f3 = 2-2*LumaBlue; int32 D3 = FIX(f3); - float f4 = LumaBlue*f3/LumaGreen; int32 D4 = -FIX(f4); + { float f1 = 2-2*LumaRed; int32 D1 = FIX(CLAMP(f1,0.0F,2.0F)); + float f2 = LumaRed*f1/LumaGreen; int32 D2 = -FIX(CLAMP(f2,0.0F,2.0F)); + float f3 = 2-2*LumaBlue; int32 D3 = FIX(CLAMP(f3,0.0F,2.0F)); + float f4 = LumaBlue*f3/LumaGreen; int32 D4 = -FIX(CLAMP(f4,0.0F,2.0F)); int x; #undef LumaBlue @@ -256,17 +273,20 @@ TIFFYCbCrToRGBInit(TIFFYCbCrToRGB* ycbcr, float *luma, float *refBlackWhite) * constructing tables indexed by the raw pixel data. */ for (i = 0, x = -128; i < 256; i++, x++) { - int32 Cr = (int32)Code2V(x, refBlackWhite[4] - 128.0F, - refBlackWhite[5] - 128.0F, 127); - int32 Cb = (int32)Code2V(x, refBlackWhite[2] - 128.0F, - refBlackWhite[3] - 128.0F, 127); + int32 Cr = (int32)CLAMPw(Code2V(x, refBlackWhite[4] - 128.0F, + refBlackWhite[5] - 128.0F, 127), + -128.0F * 64, 128.0F * 64); + int32 Cb = (int32)CLAMPw(Code2V(x, refBlackWhite[2] - 128.0F, + refBlackWhite[3] - 128.0F, 127), + -128.0F * 64, 128.0F * 64); ycbcr->Cr_r_tab[i] = (int32)((D1*Cr + ONE_HALF)>>SHIFT); ycbcr->Cb_b_tab[i] = (int32)((D3*Cb + ONE_HALF)>>SHIFT); ycbcr->Cr_g_tab[i] = D2*Cr; ycbcr->Cb_g_tab[i] = D4*Cb + ONE_HALF; ycbcr->Y_tab[i] = - (int32)Code2V(x + 128, refBlackWhite[0], refBlackWhite[1], 255); + (int32)CLAMPw(Code2V(x + 128, refBlackWhite[0], refBlackWhite[1], 255), + -128.0F * 64, 128.0F * 64); } } diff --git a/chromium/third_party/pdfium/third_party/libtiff/tif_dir.c b/chromium/third_party/pdfium/third_party/libtiff/tif_dir.c index 72148411fde..a88394917aa 100644 --- a/chromium/third_party/pdfium/third_party/libtiff/tif_dir.c +++ b/chromium/third_party/pdfium/third_party/libtiff/tif_dir.c @@ -1,4 +1,4 @@ -/* $Id: tif_dir.c,v 1.127 2016-10-25 21:35:15 erouault Exp $ */ +/* $Id: tif_dir.c,v 1.130 2017-05-17 21:54:05 erouault Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -460,14 +460,6 @@ _TIFFVSetField(TIFF* tif, uint32 tag, va_list ap) case TIFFTAG_REFERENCEBLACKWHITE: /* XXX should check for null range */ _TIFFsetFloatArray(&td->td_refblackwhite, va_arg(ap, float*), 6); - for (int i = 0; i < 6; i++) { - if (isnan(td->td_refblackwhite[i])) { - if (i % 2 == 0) - td->td_refblackwhite[i] = 0; - else - td->td_refblackwhite[i] = pow(2, td->td_bitspersample) - 1; - } - } break; case TIFFTAG_INKNAMES: v = (uint16) va_arg(ap, uint16_vap); @@ -694,7 +686,7 @@ _TIFFVSetField(TIFF* tif, uint32 tag, va_list ap) case TIFF_SRATIONAL: case TIFF_FLOAT: { - float v2 = (float)va_arg(ap, double); + float v2 = TIFFClampDoubleToFloat(va_arg(ap, double)); _TIFFmemcpy(val, &v2, tv_size); } break; @@ -872,31 +864,31 @@ _TIFFVGetField(TIFF* tif, uint32 tag, va_list ap) if( fip == NULL ) /* cannot happen since TIFFGetField() already checks it */ return 0; - if( tag == TIFFTAG_NUMBEROFINKS ) - { - int i; - for (i = 0; i < td->td_customValueCount; i++) { - uint16 val; - TIFFTagValue *tv = td->td_customValues + i; - if (tv->info->field_tag != tag) - continue; - val = *(uint16 *)tv->value; - /* Truncate to SamplesPerPixel, since the */ - /* setting code for INKNAMES assume that there are SamplesPerPixel */ - /* inknames. */ - /* Fixes http://bugzilla.maptools.org/show_bug.cgi?id=2599 */ - if( val > td->td_samplesperpixel ) - { - TIFFWarningExt(tif->tif_clientdata,"_TIFFVGetField", - "Truncating NumberOfInks from %u to %u", - val, td->td_samplesperpixel); - val = td->td_samplesperpixel; - } - *va_arg(ap, uint16*) = val; - return 1; - } - return 0; - } + if( tag == TIFFTAG_NUMBEROFINKS ) + { + int i; + for (i = 0; i < td->td_customValueCount; i++) { + uint16 val; + TIFFTagValue *tv = td->td_customValues + i; + if (tv->info->field_tag != tag) + continue; + val = *(uint16 *)tv->value; + /* Truncate to SamplesPerPixel, since the */ + /* setting code for INKNAMES assume that there are SamplesPerPixel */ + /* inknames. */ + /* Fixes http://bugzilla.maptools.org/show_bug.cgi?id=2599 */ + if( val > td->td_samplesperpixel ) + { + TIFFWarningExt(tif->tif_clientdata,"_TIFFVGetField", + "Truncating NumberOfInks from %u to %u", + val, td->td_samplesperpixel); + val = td->td_samplesperpixel; + } + *va_arg(ap, uint16*) = val; + return 1; + } + return 0; + } /* * We want to force the custom code to be used for custom diff --git a/chromium/third_party/pdfium/third_party/libtiff/tif_dirread.c b/chromium/third_party/pdfium/third_party/libtiff/tif_dirread.c index 0926e16254e..385ed12db03 100644 --- a/chromium/third_party/pdfium/third_party/libtiff/tif_dirread.c +++ b/chromium/third_party/pdfium/third_party/libtiff/tif_dirread.c @@ -1,4 +1,4 @@ -/* $Id: tif_dirread.c,v 1.204 2016-11-16 15:14:15 erouault Exp $ */ +/* $Id: tif_dirread.c,v 1.208 2017-04-27 15:46:22 erouault Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -791,43 +791,44 @@ static enum TIFFReadDirEntryErr TIFFReadDirEntryArray(TIFF* tif, TIFFDirEntry* d *count=(uint32)direntry->tdir_count; datasize=(*count)*typesize; assert((tmsize_t)datasize>0); - const uint32 small_alloc_threshold=(tif->tif_flags&TIFF_BIGTIFF)? 8 : 4; - if (datasize <= small_alloc_threshold) - { - data=_TIFFCheckMalloc(tif, *count, typesize, "ReadDirEntryArray"); - if (data==0) - return(TIFFReadDirEntryErrAlloc); - _TIFFmemcpy(data,&direntry->tdir_offset,datasize); - *value=data; - return(TIFFReadDirEntryErrOk); - } - uint64 offset; + data=_TIFFCheckMalloc(tif, *count, typesize, "ReadDirEntryArray"); + if (data==0) + return(TIFFReadDirEntryErrAlloc); if (!(tif->tif_flags&TIFF_BIGTIFF)) { - uint32 small_offset=direntry->tdir_offset.toff_long; - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabLong(&small_offset); - offset=(uint64)small_offset; + if (datasize<=4) + _TIFFmemcpy(data,&direntry->tdir_offset,datasize); + else + { + enum TIFFReadDirEntryErr err; + uint32 offset = direntry->tdir_offset.toff_long; + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabLong(&offset); + err=TIFFReadDirEntryData(tif,(uint64)offset,(tmsize_t)datasize,data); + if (err!=TIFFReadDirEntryErrOk) + { + _TIFFfree(data); + return(err); + } + } } else { - offset = direntry->tdir_offset.toff_long8; - if (tif->tif_flags&TIFF_SWAB) - TIFFSwabLong8(&offset); - } - if ((uint64)(-1) - offset < datasize) - return(TIFFReadDirEntryErrIo); - const uint64 size=isMapped(tif)? (uint64)tif->tif_size : TIFFGetFileSize(tif); - if (offset + datasize > size) - return(TIFFReadDirEntryErrIo); - data=_TIFFCheckMalloc(tif, *count, typesize, "ReadDirEntryArray"); - if (data==0) - return(TIFFReadDirEntryErrAlloc); - enum TIFFReadDirEntryErr err=TIFFReadDirEntryData(tif,offset,(tmsize_t)datasize,data); - if (err!=TIFFReadDirEntryErrOk) - { - _TIFFfree(data); - return(err); + if (datasize<=8) + _TIFFmemcpy(data,&direntry->tdir_offset,datasize); + else + { + enum TIFFReadDirEntryErr err; + uint64 offset = direntry->tdir_offset.toff_long8; + if (tif->tif_flags&TIFF_SWAB) + TIFFSwabLong8(&offset); + err=TIFFReadDirEntryData(tif,offset,(tmsize_t)datasize,data); + if (err!=TIFFReadDirEntryErrOk) + { + _TIFFfree(data); + return(err); + } + } } *value=data; return(TIFFReadDirEntryErrOk); @@ -2406,14 +2407,14 @@ static enum TIFFReadDirEntryErr TIFFReadDirEntryFloatArray(TIFF* tif, TIFFDirEnt ma=(double*)origdata; mb=data; for (n=0; n<count; n++) - { - double val = *ma++; - if( val > FLT_MAX ) - val = FLT_MAX; - else if( val < -FLT_MAX ) - val = -FLT_MAX; - *mb++=(float)val; - } + { + double val = *ma++; + if( val > FLT_MAX ) + val = FLT_MAX; + else if( val < -FLT_MAX ) + val = -FLT_MAX; + *mb++=(float)val; + } } break; } @@ -2879,9 +2880,9 @@ static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckedRational(TIFF* tif, TIFFD m.l = direntry->tdir_offset.toff_long8; if (tif->tif_flags&TIFF_SWAB) TIFFSwabArrayOfLong(m.i,2); - /* Not completely sure what we should do when m.i[1]==0, but some */ - /* sanitizers do not like division by 0.0: */ - /* http://bugzilla.maptools.org/show_bug.cgi?id=2644 */ + /* Not completely sure what we should do when m.i[1]==0, but some */ + /* sanitizers do not like division by 0.0: */ + /* http://bugzilla.maptools.org/show_bug.cgi?id=2644 */ if (m.i[0]==0 || m.i[1]==0) *value=0.0; else @@ -2910,9 +2911,9 @@ static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckedSrational(TIFF* tif, TIFF m.l=direntry->tdir_offset.toff_long8; if (tif->tif_flags&TIFF_SWAB) TIFFSwabArrayOfLong(m.i,2); - /* Not completely sure what we should do when m.i[1]==0, but some */ - /* sanitizers do not like division by 0.0: */ - /* http://bugzilla.maptools.org/show_bug.cgi?id=2644 */ + /* Not completely sure what we should do when m.i[1]==0, but some */ + /* sanitizers do not like division by 0.0: */ + /* http://bugzilla.maptools.org/show_bug.cgi?id=2644 */ if ((int32)m.i[0]==0 || m.i[1]==0) *value=0.0; else @@ -3737,6 +3738,14 @@ TIFFReadDirectory(TIFF* tif) _TIFFmemcpy( &(tif->tif_dir.td_stripoffset_entry), dp, sizeof(TIFFDirEntry) ); #else + if( tif->tif_dir.td_stripoffset != NULL ) + { + TIFFErrorExt(tif->tif_clientdata, module, + "tif->tif_dir.td_stripoffset is " + "already allocated. Likely duplicated " + "StripOffsets/TileOffsets tag"); + goto bad; + } if (!TIFFFetchStripThing(tif,dp,tif->tif_dir.td_nstrips,&tif->tif_dir.td_stripoffset)) goto bad; #endif @@ -3747,7 +3756,15 @@ TIFFReadDirectory(TIFF* tif) _TIFFmemcpy( &(tif->tif_dir.td_stripbytecount_entry), dp, sizeof(TIFFDirEntry) ); #else - if (!TIFFFetchStripThing(tif,dp,tif->tif_dir.td_nstrips,&tif->tif_dir.td_stripbytecount)) + if( tif->tif_dir.td_stripbytecount != NULL ) + { + TIFFErrorExt(tif->tif_clientdata, module, + "tif->tif_dir.td_stripbytecount is " + "already allocated. Likely duplicated " + "StripByteCounts/TileByteCounts tag"); + goto bad; + } + if (!TIFFFetchStripThing(tif,dp,tif->tif_dir.td_nstrips,&tif->tif_dir.td_stripbytecount)) goto bad; #endif break; @@ -5552,9 +5569,9 @@ ChopUpSingleUncompressedStrip(TIFF* tif) */ if (rowsperstrip >= td->td_rowsperstrip) return; - nstrips = TIFFhowmany_32(td->td_imagelength, rowsperstrip); - if( nstrips == 0 ) - return; + nstrips = TIFFhowmany_32(td->td_imagelength, rowsperstrip); + if( nstrips == 0 ) + return; newcounts = (uint64*) _TIFFCheckMalloc(tif, nstrips, sizeof (uint64), "for chopped \"StripByteCounts\" array"); diff --git a/chromium/third_party/pdfium/third_party/libtiff/tif_dirwrite.c b/chromium/third_party/pdfium/third_party/libtiff/tif_dirwrite.c index f4d8034ec9a..f7339685130 100644 --- a/chromium/third_party/pdfium/third_party/libtiff/tif_dirwrite.c +++ b/chromium/third_party/pdfium/third_party/libtiff/tif_dirwrite.c @@ -1,4 +1,4 @@ -/* $Id: tif_dirwrite.c,v 1.83 2016-10-25 21:35:15 erouault Exp $ */ +/* $Id: tif_dirwrite.c,v 1.85 2017-01-11 16:09:02 erouault Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -2158,19 +2158,19 @@ TIFFWriteDirectoryTagCheckedSlong8Array(TIFF* tif, uint32* ndir, TIFFDirEntry* d static int TIFFWriteDirectoryTagCheckedRational(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, double value) { - static const char module[] = "TIFFWriteDirectoryTagCheckedRational"; + static const char module[] = "TIFFWriteDirectoryTagCheckedRational"; uint32 m[2]; assert(sizeof(uint32)==4); - if( value < 0 ) - { - TIFFErrorExt(tif->tif_clientdata,module,"Negative value is illegal"); - return 0; - } - else if( value != value ) - { - TIFFErrorExt(tif->tif_clientdata,module,"Not-a-number value is illegal"); - return 0; - } + if( value < 0 ) + { + TIFFErrorExt(tif->tif_clientdata,module,"Negative value is illegal"); + return 0; + } + else if( value != value ) + { + TIFFErrorExt(tif->tif_clientdata,module,"Not-a-number value is illegal"); + return 0; + } else if (value==0.0) { m[0]=0; @@ -2223,7 +2223,7 @@ TIFFWriteDirectoryTagCheckedRationalArray(TIFF* tif, uint32* ndir, TIFFDirEntry* nb[1]=1; } else if (*na >= 0 && *na <= (float)0xFFFFFFFFU && - *na==(float)(uint32)(*na)) + *na==(float)(uint32)(*na)) { nb[0]=(uint32)(*na); nb[1]=1; diff --git a/chromium/third_party/pdfium/third_party/libtiff/tif_fax3.c b/chromium/third_party/pdfium/third_party/libtiff/tif_fax3.c index 16bb4d36f04..087cedddc11 100644 --- a/chromium/third_party/pdfium/third_party/libtiff/tif_fax3.c +++ b/chromium/third_party/pdfium/third_party/libtiff/tif_fax3.c @@ -1,4 +1,4 @@ -/* $Id: tif_fax3.c,v 1.78 2016-09-04 21:32:56 erouault Exp $ */ +/* $Id: tif_fax3.c,v 1.80 2017-04-27 19:50:01 erouault Exp $ */ /* * Copyright (c) 1990-1997 Sam Leffler @@ -329,34 +329,64 @@ Fax3Decode2D(TIFF* tif, uint8* buf, tmsize_t occ, uint16 s) #if SIZEOF_UNSIGNED_LONG == 8 # define FILL(n, cp) \ switch (n) { \ - case 15:(cp)[14] = 0xff; case 14:(cp)[13] = 0xff; case 13: (cp)[12] = 0xff;\ - case 12:(cp)[11] = 0xff; case 11:(cp)[10] = 0xff; case 10: (cp)[9] = 0xff;\ - case 9: (cp)[8] = 0xff; case 8: (cp)[7] = 0xff; case 7: (cp)[6] = 0xff;\ - case 6: (cp)[5] = 0xff; case 5: (cp)[4] = 0xff; case 4: (cp)[3] = 0xff;\ - case 3: (cp)[2] = 0xff; case 2: (cp)[1] = 0xff; \ - case 1: (cp)[0] = 0xff; (cp) += (n); case 0: ; \ + case 15:(cp)[14] = 0xff; /*-fallthrough*/ \ + case 14:(cp)[13] = 0xff; /*-fallthrough*/ \ + case 13:(cp)[12] = 0xff; /*-fallthrough*/ \ + case 12:(cp)[11] = 0xff; /*-fallthrough*/ \ + case 11:(cp)[10] = 0xff; /*-fallthrough*/ \ + case 10: (cp)[9] = 0xff; /*-fallthrough*/ \ + case 9: (cp)[8] = 0xff; /*-fallthrough*/ \ + case 8: (cp)[7] = 0xff; /*-fallthrough*/ \ + case 7: (cp)[6] = 0xff; /*-fallthrough*/ \ + case 6: (cp)[5] = 0xff; /*-fallthrough*/ \ + case 5: (cp)[4] = 0xff; /*-fallthrough*/ \ + case 4: (cp)[3] = 0xff; /*-fallthrough*/ \ + case 3: (cp)[2] = 0xff; /*-fallthrough*/ \ + case 2: (cp)[1] = 0xff; /*-fallthrough*/ \ + case 1: (cp)[0] = 0xff; (cp) += (n); /*-fallthrough*/ \ + case 0: ; \ } # define ZERO(n, cp) \ switch (n) { \ - case 15:(cp)[14] = 0; case 14:(cp)[13] = 0; case 13: (cp)[12] = 0; \ - case 12:(cp)[11] = 0; case 11:(cp)[10] = 0; case 10: (cp)[9] = 0; \ - case 9: (cp)[8] = 0; case 8: (cp)[7] = 0; case 7: (cp)[6] = 0; \ - case 6: (cp)[5] = 0; case 5: (cp)[4] = 0; case 4: (cp)[3] = 0; \ - case 3: (cp)[2] = 0; case 2: (cp)[1] = 0; \ - case 1: (cp)[0] = 0; (cp) += (n); case 0: ; \ + case 15:(cp)[14] = 0; /*-fallthrough*/ \ + case 14:(cp)[13] = 0; /*-fallthrough*/ \ + case 13:(cp)[12] = 0; /*-fallthrough*/ \ + case 12:(cp)[11] = 0; /*-fallthrough*/ \ + case 11:(cp)[10] = 0; /*-fallthrough*/ \ + case 10: (cp)[9] = 0; /*-fallthrough*/ \ + case 9: (cp)[8] = 0; /*-fallthrough*/ \ + case 8: (cp)[7] = 0; /*-fallthrough*/ \ + case 7: (cp)[6] = 0; /*-fallthrough*/ \ + case 6: (cp)[5] = 0; /*-fallthrough*/ \ + case 5: (cp)[4] = 0; /*-fallthrough*/ \ + case 4: (cp)[3] = 0; /*-fallthrough*/ \ + case 3: (cp)[2] = 0; /*-fallthrough*/ \ + case 2: (cp)[1] = 0; /*-fallthrough*/ \ + case 1: (cp)[0] = 0; (cp) += (n); /*-fallthrough*/ \ + case 0: ; \ } #else # define FILL(n, cp) \ switch (n) { \ - case 7: (cp)[6] = 0xff; case 6: (cp)[5] = 0xff; case 5: (cp)[4] = 0xff; \ - case 4: (cp)[3] = 0xff; case 3: (cp)[2] = 0xff; case 2: (cp)[1] = 0xff; \ - case 1: (cp)[0] = 0xff; (cp) += (n); case 0: ; \ + case 7: (cp)[6] = 0xff; /*-fallthrough*/ \ + case 6: (cp)[5] = 0xff; /*-fallthrough*/ \ + case 5: (cp)[4] = 0xff; /*-fallthrough*/ \ + case 4: (cp)[3] = 0xff; /*-fallthrough*/ \ + case 3: (cp)[2] = 0xff; /*-fallthrough*/ \ + case 2: (cp)[1] = 0xff; /*-fallthrough*/ \ + case 1: (cp)[0] = 0xff; (cp) += (n); /*-fallthrough*/ \ + case 0: ; \ } # define ZERO(n, cp) \ switch (n) { \ - case 7: (cp)[6] = 0; case 6: (cp)[5] = 0; case 5: (cp)[4] = 0; \ - case 4: (cp)[3] = 0; case 3: (cp)[2] = 0; case 2: (cp)[1] = 0; \ - case 1: (cp)[0] = 0; (cp) += (n); case 0: ; \ + case 7: (cp)[6] = 0; /*-fallthrough*/ \ + case 6: (cp)[5] = 0; /*-fallthrough*/ \ + case 5: (cp)[4] = 0; /*-fallthrough*/ \ + case 4: (cp)[3] = 0; /*-fallthrough*/ \ + case 3: (cp)[2] = 0; /*-fallthrough*/ \ + case 2: (cp)[1] = 0; /*-fallthrough*/ \ + case 1: (cp)[0] = 0; (cp) += (n); /*-fallthrough*/ \ + case 0: ; \ } #endif @@ -1099,7 +1129,7 @@ Fax3PostEncode(TIFF* tif) static void Fax3Close(TIFF* tif) { - if ((Fax3State(tif)->mode & FAXMODE_NORTC) == 0) { + if ((Fax3State(tif)->mode & FAXMODE_NORTC) == 0 && tif->tif_rawcp) { Fax3CodecState* sp = EncoderState(tif); unsigned int code = EOL; unsigned int length = 12; @@ -1321,6 +1351,7 @@ InitCCITTFax3(TIFF* tif) "No space for state block"); return (0); } + _TIFFmemset(tif->tif_data, 0, sizeof (Fax3CodecState)); sp = Fax3State(tif); sp->rw_mode = tif->tif_mode; diff --git a/chromium/third_party/pdfium/third_party/libtiff/tif_fax3.h b/chromium/third_party/pdfium/third_party/libtiff/tif_fax3.h index e0b2ca6bfc9..8a435059c7b 100644 --- a/chromium/third_party/pdfium/third_party/libtiff/tif_fax3.h +++ b/chromium/third_party/pdfium/third_party/libtiff/tif_fax3.h @@ -1,4 +1,4 @@ -/* $Id: tif_fax3.h,v 1.11 2016-01-23 21:20:34 erouault Exp $ */ +/* $Id: tif_fax3.h,v 1.13 2016-12-14 18:36:27 faxguy Exp $ */ /* * Copyright (c) 1990-1997 Sam Leffler @@ -81,10 +81,12 @@ extern void _TIFFFax3fillruns(unsigned char*, uint32*, uint32*, uint32); #define S_MakeUp 11 #define S_EOL 12 +/* WARNING: do not change the layout of this structure as the HylaFAX software */ +/* really depends on it. See http://bugzilla.maptools.org/show_bug.cgi?id=2636 */ typedef struct { /* state table entry */ unsigned char State; /* see above */ unsigned char Width; /* width of code in bits */ - uint16 Param; /* unsigned 16-bit run length in bits */ + uint32 Param; /* unsigned 32-bit run length in bits (holds on 16 bit actually, but cannot be changed. See above warning) */ } TIFFFaxTabEnt; extern const TIFFFaxTabEnt TIFFFaxMainTable[]; diff --git a/chromium/third_party/pdfium/third_party/libtiff/tif_getimage.c b/chromium/third_party/pdfium/third_party/libtiff/tif_getimage.c index 84cc1d1a769..03c9a81fb61 100644 --- a/chromium/third_party/pdfium/third_party/libtiff/tif_getimage.c +++ b/chromium/third_party/pdfium/third_party/libtiff/tif_getimage.c @@ -1,4 +1,4 @@ -/* $Id: tif_getimage.c,v 1.98 2016-11-18 02:47:45 bfriesen Exp $ */ +/* $Id: tif_getimage.c,v 1.106 2017-05-20 11:29:02 erouault Exp $ */ /* * Copyright (c) 1991-1997 Sam Leffler @@ -495,7 +495,7 @@ TIFFRGBAImageBegin(TIFFRGBAImage* img, TIFF* tif, int stop, char emsg[1024]) return 1; fail_return: - TIFFRGBAImageEnd(img); + TIFFRGBAImageEnd( img ); return 0; } @@ -627,7 +627,7 @@ gtTileContig(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) uint32 col, row, y, rowstoread; tmsize_t pos; uint32 tw, th; - unsigned char* buf; + unsigned char* buf = NULL; int32 fromskew, toskew; int64 safeskew; uint32 nrow; @@ -636,13 +636,14 @@ gtTileContig(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) int32 this_toskew, leftmost_toskew; int32 leftmost_fromskew; uint32 leftmost_tw; + tmsize_t bufsize; - buf = (unsigned char*) _TIFFmalloc(TIFFTileSize(tif)); - if (buf == 0) { - TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "%s", "No space for tile buffer"); - return (0); + bufsize = TIFFTileSize(tif); + if (bufsize == 0) { + TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "%s", "No space for tile buffer"); + return (0); } - _TIFFmemset(buf, 0, TIFFTileSize(tif)); + TIFFGetField(tif, TIFFTAG_TILEWIDTH, &tw); TIFFGetField(tif, TIFFTAG_TILELENGTH, &th); @@ -691,8 +692,9 @@ gtTileContig(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) col = img->col_offset; while (tocol < w) { - if (TIFFReadTile(tif, buf, col, - row+img->row_offset, 0, 0)==(tmsize_t)(-1) && img->stoponerr) + if (_TIFFReadTileAndAllocBuffer(tif, (void**) &buf, bufsize, col, + row+img->row_offset, 0, 0)==(tmsize_t)(-1) && + (buf == NULL || img->stoponerr)) { ret = 0; break; @@ -734,7 +736,7 @@ gtTileContig(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) this_toskew = toskew; } - y += (flip & FLIP_VERTICALLY ? -(int32) nrow : (int32) nrow); + y += ((flip & FLIP_VERTICALLY) ? -(int32) nrow : (int32) nrow); } _TIFFfree(buf); @@ -772,11 +774,11 @@ gtTileSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) uint32 col, row, y, rowstoread; tmsize_t pos; uint32 tw, th; - unsigned char* buf; - unsigned char* p0; - unsigned char* p1; - unsigned char* p2; - unsigned char* pa; + unsigned char* buf = NULL; + unsigned char* p0 = NULL; + unsigned char* p1 = NULL; + unsigned char* p2 = NULL; + unsigned char* pa = NULL; tmsize_t tilesize; tmsize_t bufsize; int32 fromskew, toskew; @@ -795,16 +797,7 @@ gtTileSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "Integer overflow in %s", "gtTileSeparate"); return (0); } - buf = (unsigned char*) _TIFFmalloc(bufsize); - if (buf == 0) { - TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "%s", "No space for tile buffer"); - return (0); - } - _TIFFmemset(buf, 0, bufsize); - p0 = buf; - p1 = p0 + tilesize; - p2 = p1 + tilesize; - pa = (alpha?(p2+tilesize):NULL); + TIFFGetField(tif, TIFFTAG_TILEWIDTH, &tw); TIFFGetField(tif, TIFFTAG_TILELENGTH, &th); @@ -824,7 +817,6 @@ gtTileSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) case PHOTOMETRIC_MINISBLACK: case PHOTOMETRIC_PALETTE: colorchannels = 1; - p2 = p1 = p0; break; default: @@ -849,7 +841,30 @@ gtTileSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) col = img->col_offset; while (tocol < w) { - if (TIFFReadTile(tif, p0, col, + if( buf == NULL ) + { + if (_TIFFReadTileAndAllocBuffer( + tif, (void**) &buf, bufsize, col, + row+img->row_offset,0,0)==(tmsize_t)(-1) + && (buf == NULL || img->stoponerr)) + { + ret = 0; + break; + } + p0 = buf; + if( colorchannels == 1 ) + { + p2 = p1 = p0; + pa = (alpha?(p0+3*tilesize):NULL); + } + else + { + p1 = p0 + tilesize; + p2 = p1 + tilesize; + pa = (alpha?(p2+tilesize):NULL); + } + } + else if (TIFFReadTile(tif, p0, col, row+img->row_offset,0,0)==(tmsize_t)(-1) && img->stoponerr) { ret = 0; @@ -903,7 +918,7 @@ gtTileSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) this_toskew = toskew; } - y += (flip & FLIP_VERTICALLY ?-(int32) nrow : (int32) nrow); + y += ((flip & FLIP_VERTICALLY) ?-(int32) nrow : (int32) nrow); } if (flip & FLIP_HORIZONTALLY) { @@ -940,13 +955,14 @@ gtStripContig(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) tileContigRoutine put = img->put.contig; uint32 row, y, nrow, nrowsub, rowstoread; tmsize_t pos; - unsigned char* buf; + unsigned char* buf = NULL; uint32 rowsperstrip; uint16 subsamplinghor,subsamplingver; uint32 imagewidth = img->width; tmsize_t scanline; int32 fromskew, toskew; int ret = 1, flip; + tmsize_t maxstripsize; TIFFGetFieldDefaulted(tif, TIFFTAG_YCBCRSUBSAMPLING, &subsamplinghor, &subsamplingver); if( subsamplingver == 0 ) { @@ -954,12 +970,7 @@ gtStripContig(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) return (0); } - buf = (unsigned char*) _TIFFmalloc(TIFFStripSize(tif)); - if (buf == 0) { - TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "No space for strip buffer"); - return (0); - } - _TIFFmemset(buf, 0, TIFFStripSize(tif)); + maxstripsize = TIFFStripSize(tif); flip = setorientation(img); if (flip & FLIP_VERTICALLY) { @@ -981,11 +992,12 @@ gtStripContig(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) nrowsub = nrow; if ((nrowsub%subsamplingver)!=0) nrowsub+=subsamplingver-nrowsub%subsamplingver; - if (TIFFReadEncodedStrip(tif, + if (_TIFFReadEncodedStripAndAllocBuffer(tif, TIFFComputeStrip(tif,row+img->row_offset, 0), - buf, + (void**)(&buf), + maxstripsize, ((row + img->row_offset)%rowsperstrip + nrowsub) * scanline)==(tmsize_t)(-1) - && img->stoponerr) + && (buf == NULL || img->stoponerr)) { ret = 0; break; @@ -994,7 +1006,7 @@ gtStripContig(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) pos = ((row + img->row_offset) % rowsperstrip) * scanline + \ ((tmsize_t) img->col_offset * img->samplesperpixel); (*put)(img, raster+y*w, 0, y, w, nrow, fromskew, toskew, buf + pos); - y += (flip & FLIP_VERTICALLY ? -(int32) nrow : (int32) nrow); + y += ((flip & FLIP_VERTICALLY) ? -(int32) nrow : (int32) nrow); } if (flip & FLIP_HORIZONTALLY) { @@ -1029,8 +1041,8 @@ gtStripSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) { TIFF* tif = img->tif; tileSeparateRoutine put = img->put.separate; - unsigned char *buf; - unsigned char *p0, *p1, *p2, *pa; + unsigned char *buf = NULL; + unsigned char *p0 = NULL, *p1 = NULL, *p2 = NULL, *pa = NULL; uint32 row, y, nrow, rowstoread; tmsize_t pos; tmsize_t scanline; @@ -1049,15 +1061,6 @@ gtStripSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "Integer overflow in %s", "gtStripSeparate"); return (0); } - p0 = buf = (unsigned char *)_TIFFmalloc(bufsize); - if (buf == 0) { - TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "No space for tile buffer"); - return (0); - } - _TIFFmemset(buf, 0, bufsize); - p1 = p0 + stripsize; - p2 = p1 + stripsize; - pa = (alpha?(p2+stripsize):NULL); flip = setorientation(img); if (flip & FLIP_VERTICALLY) { @@ -1075,7 +1078,6 @@ gtStripSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) case PHOTOMETRIC_MINISBLACK: case PHOTOMETRIC_PALETTE: colorchannels = 1; - p2 = p1 = p0; break; default: @@ -1091,7 +1093,31 @@ gtStripSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) rowstoread = rowsperstrip - (row + img->row_offset) % rowsperstrip; nrow = (row + rowstoread > h ? h - row : rowstoread); offset_row = row + img->row_offset; - if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, offset_row, 0), + if( buf == NULL ) + { + if (_TIFFReadEncodedStripAndAllocBuffer( + tif, TIFFComputeStrip(tif, offset_row, 0), + (void**) &buf, bufsize, + ((row + img->row_offset)%rowsperstrip + nrow) * scanline)==(tmsize_t)(-1) + && (buf == NULL || img->stoponerr)) + { + ret = 0; + break; + } + p0 = buf; + if( colorchannels == 1 ) + { + p2 = p1 = p0; + pa = (alpha?(p0+3*stripsize):NULL); + } + else + { + p1 = p0 + stripsize; + p2 = p1 + stripsize; + pa = (alpha?(p2+stripsize):NULL); + } + } + else if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, offset_row, 0), p0, ((row + img->row_offset)%rowsperstrip + nrow) * scanline)==(tmsize_t)(-1) && img->stoponerr) { @@ -1129,7 +1155,7 @@ gtStripSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) ((tmsize_t) img->col_offset * img->samplesperpixel); (*put)(img, raster+y*w, 0, y, w, nrow, fromskew, toskew, p0 + pos, p1 + pos, p2 + pos, (alpha?(pa+pos):NULL)); - y += (flip & FLIP_VERTICALLY ? -(int32) nrow : (int32) nrow); + y += ((flip & FLIP_VERTICALLY) ? -(int32) nrow : (int32) nrow); } if (flip & FLIP_HORIZONTALLY) { @@ -1168,11 +1194,15 @@ gtStripSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) #define REPEAT2(op) op; op #define CASE8(x,op) \ switch (x) { \ - case 7: op; case 6: op; case 5: op; \ - case 4: op; case 3: op; case 2: op; \ + case 7: op; /*-fallthrough*/ \ + case 6: op; /*-fallthrough*/ \ + case 5: op; /*-fallthrough*/ \ + case 4: op; /*-fallthrough*/ \ + case 3: op; /*-fallthrough*/ \ + case 2: op; /*-fallthrough*/ \ case 1: op; \ } -#define CASE4(x,op) switch (x) { case 3: op; case 2: op; case 1: op; } +#define CASE4(x,op) switch (x) { case 3: op; /*-fallthrough*/ case 2: op; /*-fallthrough*/ case 1: op; } #define NOP #define UNROLL8(w, op1, op2) { \ @@ -2078,9 +2108,9 @@ DECLAREContigPutFunc(putcontig8bitYCbCr41tile) int32 Cr = pp[5]; switch( (w&3) ) { - case 3: YCbCrtoRGB(cp [2], pp[2]); - case 2: YCbCrtoRGB(cp [1], pp[1]); - case 1: YCbCrtoRGB(cp [0], pp[0]); + case 3: YCbCrtoRGB(cp [2], pp[2]); /*-fallthrough*/ + case 2: YCbCrtoRGB(cp [1], pp[1]); /*-fallthrough*/ + case 1: YCbCrtoRGB(cp [0], pp[0]); /*-fallthrough*/ case 0: break; } @@ -2270,6 +2300,11 @@ DECLARESepPutFunc(putseparate8bitYCbCr11tile) } #undef YCbCrtoRGB +static int isInRefBlackWhiteRange(float f) +{ + return f >= (float)(-0x7FFFFFFF + 128) && f <= (float)0x7FFFFFFF; +} + static int initYCbCrConversion(TIFFRGBAImage* img) { @@ -2294,6 +2329,31 @@ initYCbCrConversion(TIFFRGBAImage* img) TIFFGetFieldDefaulted(img->tif, TIFFTAG_YCBCRCOEFFICIENTS, &luma); TIFFGetFieldDefaulted(img->tif, TIFFTAG_REFERENCEBLACKWHITE, &refBlackWhite); + + /* Do some validation to avoid later issues. Detect NaN for now */ + /* and also if lumaGreen is zero since we divide by it later */ + if( luma[0] != luma[0] || + luma[1] != luma[1] || + luma[1] == 0.0 || + luma[2] != luma[2] ) + { + TIFFErrorExt(img->tif->tif_clientdata, module, + "Invalid values for YCbCrCoefficients tag"); + return (0); + } + + if( !isInRefBlackWhiteRange(refBlackWhite[0]) || + !isInRefBlackWhiteRange(refBlackWhite[1]) || + !isInRefBlackWhiteRange(refBlackWhite[2]) || + !isInRefBlackWhiteRange(refBlackWhite[3]) || + !isInRefBlackWhiteRange(refBlackWhite[4]) || + !isInRefBlackWhiteRange(refBlackWhite[5]) ) + { + TIFFErrorExt(img->tif->tif_clientdata, module, + "Invalid values for ReferenceBlackWhite tag"); + return (0); + } + if (TIFFYCbCrToRGBInit(img->ycbcr, luma, refBlackWhite) < 0) return(0); return (1); @@ -2848,6 +2908,13 @@ int TIFFReadRGBAStrip(TIFF* tif, uint32 row, uint32 * raster ) { + return TIFFReadRGBAStripExt(tif, row, raster, 0 ); +} + +int +TIFFReadRGBAStripExt(TIFF* tif, uint32 row, uint32 * raster, int stop_on_error) + +{ char emsg[1024] = ""; TIFFRGBAImage img; int ok; @@ -2868,7 +2935,7 @@ TIFFReadRGBAStrip(TIFF* tif, uint32 row, uint32 * raster ) return (0); } - if (TIFFRGBAImageOK(tif, emsg) && TIFFRGBAImageBegin(&img, tif, 0, emsg)) { + if (TIFFRGBAImageOK(tif, emsg) && TIFFRGBAImageBegin(&img, tif, stop_on_error, emsg)) { img.row_offset = row; img.col_offset = 0; @@ -2899,6 +2966,13 @@ int TIFFReadRGBATile(TIFF* tif, uint32 col, uint32 row, uint32 * raster) { + return TIFFReadRGBATileExt(tif, col, row, raster, 0 ); +} + + +int +TIFFReadRGBATileExt(TIFF* tif, uint32 col, uint32 row, uint32 * raster, int stop_on_error ) +{ char emsg[1024] = ""; TIFFRGBAImage img; int ok; @@ -2933,7 +3007,7 @@ TIFFReadRGBATile(TIFF* tif, uint32 col, uint32 row, uint32 * raster) */ if (!TIFFRGBAImageOK(tif, emsg) - || !TIFFRGBAImageBegin(&img, tif, 0, emsg)) { + || !TIFFRGBAImageBegin(&img, tif, stop_on_error, emsg)) { TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "%s", emsg); return( 0 ); } diff --git a/chromium/third_party/pdfium/third_party/libtiff/tif_jpeg.c b/chromium/third_party/pdfium/third_party/libtiff/tif_jpeg.c index 4f154a7c2b2..df06e03fab2 100644 --- a/chromium/third_party/pdfium/third_party/libtiff/tif_jpeg.c +++ b/chromium/third_party/pdfium/third_party/libtiff/tif_jpeg.c @@ -1,4 +1,4 @@ -/* $Id: tif_jpeg.c,v 1.123 2016-01-23 21:20:34 erouault Exp $ */ +/* $Id: tif_jpeg.c,v 1.127 2017-01-31 13:02:27 erouault Exp $ */ /* * Copyright (c) 1994-1997 Sam Leffler @@ -705,9 +705,11 @@ static int JPEGFixupTags(TIFF* tif) { #ifdef CHECK_JPEG_YCBCR_SUBSAMPLING + JPEGState* sp = JState(tif); if ((tif->tif_dir.td_photometric==PHOTOMETRIC_YCBCR)&& (tif->tif_dir.td_planarconfig==PLANARCONFIG_CONTIG)&& - (tif->tif_dir.td_samplesperpixel==3)) + (tif->tif_dir.td_samplesperpixel==3) && + !sp->ycbcrsampling_fetched) JPEGFixupTagsSubsampling(tif); #endif @@ -1634,19 +1636,19 @@ JPEGSetupEncode(TIFF* tif) case PHOTOMETRIC_YCBCR: sp->h_sampling = td->td_ycbcrsubsampling[0]; sp->v_sampling = td->td_ycbcrsubsampling[1]; - if( sp->h_sampling == 0 || sp->v_sampling == 0 ) - { - TIFFErrorExt(tif->tif_clientdata, module, - "Invalig horizontal/vertical sampling value"); - return (0); - } - if( td->td_bitspersample > 16 ) - { - TIFFErrorExt(tif->tif_clientdata, module, - "BitsPerSample %d not allowed for JPEG", - td->td_bitspersample); - return (0); - } + if( sp->h_sampling == 0 || sp->v_sampling == 0 ) + { + TIFFErrorExt(tif->tif_clientdata, module, + "Invalig horizontal/vertical sampling value"); + return (0); + } + if( td->td_bitspersample > 16 ) + { + TIFFErrorExt(tif->tif_clientdata, module, + "BitsPerSample %d not allowed for JPEG", + td->td_bitspersample); + return (0); + } /* * A ReferenceBlackWhite field *must* be present since the @@ -2313,6 +2315,15 @@ static int JPEGInitializeLibJPEG( TIFF * tif, int decompress ) } else { if (!TIFFjpeg_create_compress(sp)) return (0); +#ifndef TIFF_JPEG_MAX_MEMORY_TO_USE +#define TIFF_JPEG_MAX_MEMORY_TO_USE (10 * 1024 * 1024) +#endif + /* Increase the max memory usable. This helps when creating files */ + /* with "big" tile, without using libjpeg temporary files. */ + /* For example a 512x512 tile with 3 bands */ + /* requires 1.5 MB which is above libjpeg 1MB default */ + if( sp->cinfo.c.mem->max_memory_to_use < TIFF_JPEG_MAX_MEMORY_TO_USE ) + sp->cinfo.c.mem->max_memory_to_use = TIFF_JPEG_MAX_MEMORY_TO_USE; } sp->cinfo_initialized = TRUE; diff --git a/chromium/third_party/pdfium/third_party/libtiff/tif_luv.c b/chromium/third_party/pdfium/third_party/libtiff/tif_luv.c index 220c15034a2..59d0a74cc6b 100644 --- a/chromium/third_party/pdfium/third_party/libtiff/tif_luv.c +++ b/chromium/third_party/pdfium/third_party/libtiff/tif_luv.c @@ -1,4 +1,4 @@ -/* $Id: tif_luv.c,v 1.43 2016-09-04 21:32:56 erouault Exp $ */ +/* $Id: tif_luv.c,v 1.47 2017-05-14 10:17:27 erouault Exp $ */ /* * Copyright (c) 1997 Greg Ward Larson @@ -158,7 +158,7 @@ typedef struct logLuvState LogLuvState; struct logLuvState { - int encoder_state; /* 1 if encoder correctly initialized */ + int encoder_state; /* 1 if encoder correctly initialized */ int user_datafmt; /* user data format */ int encode_meth; /* encoding method */ int pixel_size; /* bytes per pixel */ @@ -473,7 +473,7 @@ LogL16Encode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) tif->tif_rawcp = op; tif->tif_rawcc = tif->tif_rawdatasize - occ; if (!TIFFFlushData1(tif)) - return (-1); + return (0); op = tif->tif_rawcp; occ = tif->tif_rawdatasize - tif->tif_rawcc; } @@ -505,7 +505,7 @@ LogL16Encode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) tif->tif_rawcp = op; tif->tif_rawcc = tif->tif_rawdatasize - occ; if (!TIFFFlushData1(tif)) - return (-1); + return (0); op = tif->tif_rawcp; occ = tif->tif_rawdatasize - tif->tif_rawcc; } @@ -565,7 +565,7 @@ LogLuvEncode24(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) tif->tif_rawcp = op; tif->tif_rawcc = tif->tif_rawdatasize - occ; if (!TIFFFlushData1(tif)) - return (-1); + return (0); op = tif->tif_rawcp; occ = tif->tif_rawdatasize - tif->tif_rawcc; } @@ -624,7 +624,7 @@ LogLuvEncode32(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) tif->tif_rawcp = op; tif->tif_rawcc = tif->tif_rawdatasize - occ; if (!TIFFFlushData1(tif)) - return (-1); + return (0); op = tif->tif_rawcp; occ = tif->tif_rawdatasize - tif->tif_rawcc; } @@ -656,7 +656,7 @@ LogLuvEncode32(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) tif->tif_rawcp = op; tif->tif_rawcc = tif->tif_rawdatasize - occ; if (!TIFFFlushData1(tif)) - return (-1); + return (0); op = tif->tif_rawcp; occ = tif->tif_rawdatasize - tif->tif_rawcc; } @@ -1264,15 +1264,16 @@ LogL16GuessDataFmt(TIFFDirectory *td) return (SGILOGDATAFMT_UNKNOWN); } + +#define TIFF_SIZE_T_MAX ((size_t) ~ ((size_t)0)) +#define TIFF_TMSIZE_T_MAX (tmsize_t)(TIFF_SIZE_T_MAX >> 1) + static tmsize_t multiply_ms(tmsize_t m1, tmsize_t m2) { - tmsize_t bytes = m1 * m2; - - if (m1 && bytes / m1 != m2) - bytes = 0; - - return bytes; + if( m1 == 0 || m2 > TIFF_TMSIZE_T_MAX / m1 ) + return 0; + return m1 * m2; } static int @@ -1313,8 +1314,10 @@ LogL16InitState(TIFF* tif) } if( isTiled(tif) ) sp->tbuflen = multiply_ms(td->td_tilewidth, td->td_tilelength); - else + else if( td->td_rowsperstrip != (uint32)-1 ) sp->tbuflen = multiply_ms(td->td_imagewidth, td->td_rowsperstrip); + else + sp->tbuflen = multiply_ms(td->td_imagewidth, td->td_imagelength); if (multiply_ms(sp->tbuflen, sizeof (int16)) == 0 || (sp->tbuf = (uint8*) _TIFFmalloc(sp->tbuflen * sizeof (int16))) == NULL) { TIFFErrorExt(tif->tif_clientdata, module, "No space for SGILog translation buffer"); @@ -1565,7 +1568,7 @@ notsupported: static void LogLuvClose(TIFF* tif) { - LogLuvState* sp = (LogLuvState*) tif->tif_data; + LogLuvState* sp = (LogLuvState*) tif->tif_data; TIFFDirectory *td = &tif->tif_dir; assert(sp != 0); @@ -1575,17 +1578,17 @@ LogLuvClose(TIFF* tif) * regardless of the data format being used by the application. * Since this routine is called after tags have been set but * before they have been recorded in the file, we reset them here. - * Note: this is really a nasty approach. See PixarLogClose + * Note: this is really a nasty approach. See PixarLogClose */ - if( sp->encoder_state ) - { - /* See PixarLogClose. Might avoid issues with tags whose size depends - * on those below, but not completely sure this is enough. */ - td->td_samplesperpixel = - (td->td_photometric == PHOTOMETRIC_LOGL) ? 1 : 3; - td->td_bitspersample = 16; - td->td_sampleformat = SAMPLEFORMAT_INT; - } + if( sp->encoder_state ) + { + /* See PixarLogClose. Might avoid issues with tags whose size depends + * on those below, but not completely sure this is enough. */ + td->td_samplesperpixel = + (td->td_photometric == PHOTOMETRIC_LOGL) ? 1 : 3; + td->td_bitspersample = 16; + td->td_sampleformat = SAMPLEFORMAT_INT; + } } static void diff --git a/chromium/third_party/pdfium/third_party/libtiff/tif_lzw.c b/chromium/third_party/pdfium/third_party/libtiff/tif_lzw.c index 240e19c2e05..5f1acf83da0 100644 --- a/chromium/third_party/pdfium/third_party/libtiff/tif_lzw.c +++ b/chromium/third_party/pdfium/third_party/libtiff/tif_lzw.c @@ -1,4 +1,4 @@ -/* $Id: tif_lzw.c,v 1.52 2016-09-04 21:32:56 erouault Exp $ */ +/* $Id: tif_lzw.c,v 1.55 2017-05-17 09:38:58 erouault Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -318,7 +318,7 @@ LZWPreDecode(TIFF* tif, uint16 s) sp->dec_restart = 0; sp->dec_nbitsmask = MAXCODE(BITS_MIN); #ifdef LZW_CHECKEOS - sp->dec_bitsleft = ((uint64)tif->tif_rawcc) << 3; + sp->dec_bitsleft = 0; #endif sp->dec_free_entp = sp->dec_codetab + CODE_FIRST; /* @@ -425,6 +425,9 @@ LZWDecode(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s) } bp = (unsigned char *)tif->tif_rawcp; +#ifdef LZW_CHECKEOS + sp->dec_bitsleft = (((uint64)tif->tif_rawcc) << 3); +#endif nbits = sp->lzw_nbits; nextdata = sp->lzw_nextdata; nextbits = sp->lzw_nextbits; @@ -549,6 +552,7 @@ LZWDecode(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s) } } + tif->tif_rawcc -= (tmsize_t)( (uint8*) bp - tif->tif_rawcp ); tif->tif_rawcp = (uint8*) bp; sp->lzw_nbits = (unsigned short) nbits; sp->lzw_nextdata = nextdata; @@ -969,7 +973,8 @@ LZWEncode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) */ if (op > limit) { tif->tif_rawcc = (tmsize_t)(op - tif->tif_rawdata); - TIFFFlushData1(tif); + if( !TIFFFlushData1(tif) ) + return 0; op = tif->tif_rawdata; } PutNextCode(op, ent); @@ -1054,12 +1059,32 @@ LZWPostEncode(TIFF* tif) if (op > sp->enc_rawlimit) { tif->tif_rawcc = (tmsize_t)(op - tif->tif_rawdata); - TIFFFlushData1(tif); + if( !TIFFFlushData1(tif) ) + return 0; op = tif->tif_rawdata; } if (sp->enc_oldcode != (hcode_t) -1) { + int free_ent = sp->lzw_free_ent; + PutNextCode(op, sp->enc_oldcode); sp->enc_oldcode = (hcode_t) -1; + free_ent ++; + + if (free_ent == CODE_MAX-1) { + /* table is full, emit clear code and reset */ + outcount = 0; + PutNextCode(op, CODE_CLEAR); + nbits = BITS_MIN; + } else { + /* + * If the next entry is going to be too big for + * the code size, then increase it, if possible. + */ + if (free_ent > sp->lzw_maxcode) { + nbits++; + assert(nbits <= BITS_MAX); + } + } } PutNextCode(op, CODE_EOI); /* Explicit 0xff masking to make icc -check=conversions happy */ diff --git a/chromium/third_party/pdfium/third_party/libtiff/tif_ojpeg.c b/chromium/third_party/pdfium/third_party/libtiff/tif_ojpeg.c index cb84be96ba4..60e4eca9190 100644 --- a/chromium/third_party/pdfium/third_party/libtiff/tif_ojpeg.c +++ b/chromium/third_party/pdfium/third_party/libtiff/tif_ojpeg.c @@ -1,4 +1,4 @@ -/* $Id: tif_ojpeg.c,v 1.65 2016-09-04 21:32:56 erouault Exp $ */ +/* $Id: tif_ojpeg.c,v 1.69 2017-04-27 17:29:26 erouault Exp $ */ /* WARNING: The type of JPEG encapsulation defined by the TIFF Version 6.0 specification is now totally obsolete and deprecated for new applications and @@ -253,7 +253,7 @@ typedef enum { typedef struct { TIFF* tif; - int decoder_ok; + int decoder_ok; #ifndef LIBJPEG_ENCAP_EXTERNAL JMP_BUF exit_jmpbuf; #endif @@ -795,14 +795,14 @@ OJPEGPreDecodeSkipScanlines(TIFF* tif) static int OJPEGDecode(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s) { - static const char module[]="OJPEGDecode"; + static const char module[]="OJPEGDecode"; OJPEGState* sp=(OJPEGState*)tif->tif_data; (void)s; - if( !sp->decoder_ok ) - { - TIFFErrorExt(tif->tif_clientdata,module,"Cannot decode: decoder not correctly initialized"); - return 0; - } + if( !sp->decoder_ok ) + { + TIFFErrorExt(tif->tif_clientdata,module,"Cannot decode: decoder not correctly initialized"); + return 0; + } if (sp->libjpeg_jpeg_query_style==0) { if (OJPEGDecodeRaw(tif,buf,cc)==0) @@ -1799,10 +1799,10 @@ OJPEGReadHeaderInfoSecTablesQTable(TIFF* tif) TIFFSeekFile(tif,sp->qtable_offset[m],SEEK_SET); p=(uint32)TIFFReadFile(tif,&ob[sizeof(uint32)+5],64); if (p!=64) - { - _TIFFfree(ob); + { + _TIFFfree(ob); return(0); - } + } if (sp->qtable[m]!=0) _TIFFfree(sp->qtable[m]); sp->qtable[m]=ob; @@ -1868,10 +1868,10 @@ OJPEGReadHeaderInfoSecTablesDcTable(TIFF* tif) rb[sizeof(uint32)+5+n]=o[n]; p=(uint32)TIFFReadFile(tif,&(rb[sizeof(uint32)+21]),q); if (p!=q) - { - _TIFFfree(rb); + { + _TIFFfree(rb); return(0); - } + } if (sp->dctable[m]!=0) _TIFFfree(sp->dctable[m]); sp->dctable[m]=rb; @@ -1937,11 +1937,11 @@ OJPEGReadHeaderInfoSecTablesAcTable(TIFF* tif) rb[sizeof(uint32)+5+n]=o[n]; p=(uint32)TIFFReadFile(tif,&(rb[sizeof(uint32)+21]),q); if (p!=q) - { - _TIFFfree(rb); + { + _TIFFfree(rb); return(0); - } - if (sp->actable[m]) + } + if (sp->actable[m]!=0) _TIFFfree(sp->actable[m]); sp->actable[m]=rb; sp->sos_tda[m]=(sp->sos_tda[m]|m); diff --git a/chromium/third_party/pdfium/third_party/libtiff/tif_open.c b/chromium/third_party/pdfium/third_party/libtiff/tif_open.c index 5c9036e6b4f..a7279e1ea05 100644 --- a/chromium/third_party/pdfium/third_party/libtiff/tif_open.c +++ b/chromium/third_party/pdfium/third_party/libtiff/tif_open.c @@ -1,4 +1,4 @@ -/* $Id: tif_open.c,v 1.47 2016-01-23 21:20:34 erouault Exp $ */ +/* $Id: tif_open.c,v 1.48 2016-11-20 22:29:47 erouault Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -279,10 +279,10 @@ TIFFClientOpen( * Setup header and write. */ #ifdef WORDS_BIGENDIAN - tif->tif_header.common.tiff_magic = tif->tif_flags & TIFF_SWAB + tif->tif_header.common.tiff_magic = (tif->tif_flags & TIFF_SWAB) ? TIFF_LITTLEENDIAN : TIFF_BIGENDIAN; #else - tif->tif_header.common.tiff_magic = tif->tif_flags & TIFF_SWAB + tif->tif_header.common.tiff_magic = (tif->tif_flags & TIFF_SWAB) ? TIFF_BIGENDIAN : TIFF_LITTLEENDIAN; #endif if (!(tif->tif_flags&TIFF_BIGTIFF)) diff --git a/chromium/third_party/pdfium/third_party/libtiff/tif_packbits.c b/chromium/third_party/pdfium/third_party/libtiff/tif_packbits.c index 92185e7f747..18904b01370 100644 --- a/chromium/third_party/pdfium/third_party/libtiff/tif_packbits.c +++ b/chromium/third_party/pdfium/third_party/libtiff/tif_packbits.c @@ -1,4 +1,4 @@ -/* $Id: tif_packbits.c,v 1.24 2016-09-04 21:32:56 erouault Exp $ */ +/* $Id: tif_packbits.c,v 1.26 2017-05-14 02:26:07 erouault Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -99,7 +99,7 @@ PackBitsEncode(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s) slop = (long)(op - lastliteral); tif->tif_rawcc += (tmsize_t)(lastliteral - tif->tif_rawcp); if (!TIFFFlushData1(tif)) - return (-1); + return (0); op = tif->tif_rawcp; while (slop-- > 0) *op++ = *lastliteral++; @@ -107,7 +107,7 @@ PackBitsEncode(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s) } else { tif->tif_rawcc += (tmsize_t)(op - tif->tif_rawcp); if (!TIFFFlushData1(tif)) - return (-1); + return (0); op = tif->tif_rawcp; } } diff --git a/chromium/third_party/pdfium/third_party/libtiff/tif_pixarlog.c b/chromium/third_party/pdfium/third_party/libtiff/tif_pixarlog.c index c2903bffef4..f2263950e17 100644 --- a/chromium/third_party/pdfium/third_party/libtiff/tif_pixarlog.c +++ b/chromium/third_party/pdfium/third_party/libtiff/tif_pixarlog.c @@ -1,4 +1,4 @@ -/* $Id: tif_pixarlog.c,v 1.48 2016-09-23 22:12:18 erouault Exp $ */ +/* $Id: tif_pixarlog.c,v 1.53 2017-05-17 09:53:06 erouault Exp $ */ /* * Copyright (c) 1996-1997 Sam Leffler @@ -636,29 +636,27 @@ PixarLogGuessDataFmt(TIFFDirectory *td) return guess; } +#define TIFF_SIZE_T_MAX ((size_t) ~ ((size_t)0)) +#define TIFF_TMSIZE_T_MAX (tmsize_t)(TIFF_SIZE_T_MAX >> 1) + static tmsize_t multiply_ms(tmsize_t m1, tmsize_t m2) { - tmsize_t bytes = m1 * m2; - - if (m1 && bytes / m1 != m2) - bytes = 0; - - return bytes; + if( m1 == 0 || m2 > TIFF_TMSIZE_T_MAX / m1 ) + return 0; + return m1 * m2; } static tmsize_t add_ms(tmsize_t m1, tmsize_t m2) { - tmsize_t bytes = m1 + m2; - /* if either input is zero, assume overflow already occurred */ if (m1 == 0 || m2 == 0) - bytes = 0; - else if (bytes <= m1 || bytes <= m2) - bytes = 0; + return 0; + else if (m1 > TIFF_TMSIZE_T_MAX - m2) + return 0; - return bytes; + return m1 + m2; } static int @@ -678,6 +676,12 @@ PixarLogSetupDecode(TIFF* tif) assert(sp != NULL); + /* This function can possibly be called several times by */ + /* PredictorSetupDecode() if this function succeeds but */ + /* PredictorSetup() fails */ + if( (sp->state & PLSTATE_INIT) != 0 ) + return 1; + /* Make sure no byte swapping happens on the data * after decompression. */ tif->tif_postdecode = _TIFFNoPostDecode; @@ -699,6 +703,9 @@ PixarLogSetupDecode(TIFF* tif) if (sp->user_datafmt == PIXARLOGDATAFMT_UNKNOWN) sp->user_datafmt = PixarLogGuessDataFmt(td); if (sp->user_datafmt == PIXARLOGDATAFMT_UNKNOWN) { + _TIFFfree(sp->tbuf); + sp->tbuf = NULL; + sp->tbuf_size = 0; TIFFErrorExt(tif->tif_clientdata, module, "PixarLog compression can't handle bits depth/data format combination (depth: %d)", td->td_bitspersample); @@ -706,6 +713,9 @@ PixarLogSetupDecode(TIFF* tif) } if (inflateInit(&sp->stream) != Z_OK) { + _TIFFfree(sp->tbuf); + sp->tbuf = NULL; + sp->tbuf_size = 0; TIFFErrorExt(tif->tif_clientdata, module, "%s", sp->stream.msg ? sp->stream.msg : "(null)"); return (0); } else { @@ -774,6 +784,10 @@ PixarLogDecode(TIFF* tif, uint8* op, tmsize_t occ, uint16 s) (void) s; assert(sp != NULL); + + sp->stream.next_in = tif->tif_rawcp; + sp->stream.avail_in = (uInt) tif->tif_rawcc; + sp->stream.next_out = (unsigned char *) sp->tbuf; assert(sizeof(sp->stream.avail_out)==4); /* if this assert gets raised, we need to simplify this code to reflect a ZLib that is likely updated @@ -819,6 +833,9 @@ PixarLogDecode(TIFF* tif, uint8* op, tmsize_t occ, uint16 s) return (0); } + tif->tif_rawcp = sp->stream.next_in; + tif->tif_rawcc = sp->stream.avail_in; + up = sp->tbuf; /* Swap bytes in the data if from a different endian machine. */ if (tif->tif_flags & TIFF_SWAB) @@ -1233,7 +1250,7 @@ PixarLogPostEncode(TIFF* tif) static void PixarLogClose(TIFF* tif) { - PixarLogState* sp = (PixarLogState*) tif->tif_data; + PixarLogState* sp = (PixarLogState*) tif->tif_data; TIFFDirectory *td = &tif->tif_dir; assert(sp != 0); @@ -1246,18 +1263,18 @@ PixarLogClose(TIFF* tif) * the PIXARLOGDATFMT pseudo-tag. */ - if (sp->state&PLSTATE_INIT) { - /* We test the state to avoid an issue such as in - * http://bugzilla.maptools.org/show_bug.cgi?id=2604 - * What appends in that case is that the bitspersample is 1 and - * a TransferFunction is set. The size of the TransferFunction - * depends on 1<<bitspersample. So if we increase it, an access - * out of the buffer will happen at directory flushing. - * Another option would be to clear those targs. - */ - td->td_bitspersample = 8; - td->td_sampleformat = SAMPLEFORMAT_UINT; - } + if (sp->state&PLSTATE_INIT) { + /* We test the state to avoid an issue such as in + * http://bugzilla.maptools.org/show_bug.cgi?id=2604 + * What appends in that case is that the bitspersample is 1 and + * a TransferFunction is set. The size of the TransferFunction + * depends on 1<<bitspersample. So if we increase it, an access + * out of the buffer will happen at directory flushing. + * Another option would be to clear those targs. + */ + td->td_bitspersample = 8; + td->td_sampleformat = SAMPLEFORMAT_UINT; + } } static void diff --git a/chromium/third_party/pdfium/third_party/libtiff/tif_predict.c b/chromium/third_party/pdfium/third_party/libtiff/tif_predict.c index 1bb78e2097a..7a60a39edfd 100644 --- a/chromium/third_party/pdfium/third_party/libtiff/tif_predict.c +++ b/chromium/third_party/pdfium/third_party/libtiff/tif_predict.c @@ -1,4 +1,4 @@ -/* $Id: tif_predict.c,v 1.40 2016-11-04 09:19:13 erouault Exp $ */ +/* $Id: tif_predict.c,v 1.43 2017-05-10 15:21:16 erouault Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -117,11 +117,11 @@ PredictorSetupDecode(TIFF* tif) TIFFPredictorState* sp = PredictorState(tif); TIFFDirectory* td = &tif->tif_dir; + /* Note: when PredictorSetup() fails, the effets of setupdecode() */ + /* will not be "cancelled" so setupdecode() might be robust to */ + /* be called several times. */ if (!(*sp->setupdecode)(tif) || !PredictorSetup(tif)) - { - (*tif->tif_cleanup)(tif); return 0; - } if (sp->predictor == 2) { switch (td->td_bitspersample) { @@ -262,11 +262,12 @@ PredictorSetupEncode(TIFF* tif) #define REPEAT4(n, op) \ switch (n) { \ - default: { tmsize_t i; for (i = n-4; i > 0; i--) { op; } } \ - case 4: op; \ - case 3: op; \ - case 2: op; \ - case 1: op; \ + default: { \ + tmsize_t i; for (i = n-4; i > 0; i--) { op; } } /*-fallthrough*/ \ + case 4: op; /*-fallthrough*/ \ + case 3: op; /*-fallthrough*/ \ + case 2: op; /*-fallthrough*/ \ + case 1: op; /*-fallthrough*/ \ case 0: ; \ } @@ -800,7 +801,7 @@ PredictorPrintDir(TIFF* tif, FILE* fd, long flags) case 2: fprintf(fd, "horizontal differencing "); break; case 3: fprintf(fd, "floating point predictor "); break; } - fprintf(fd, "%u (0x%x)\n", sp->predictor, sp->predictor); + fprintf(fd, "%d (0x%x)\n", sp->predictor, sp->predictor); } if (sp->printdir) (*sp->printdir)(tif, fd, flags); diff --git a/chromium/third_party/pdfium/third_party/libtiff/tif_print.c b/chromium/third_party/pdfium/third_party/libtiff/tif_print.c index 186f2ee5c00..24d4b98a682 100644 --- a/chromium/third_party/pdfium/third_party/libtiff/tif_print.c +++ b/chromium/third_party/pdfium/third_party/libtiff/tif_print.c @@ -1,4 +1,4 @@ -/* $Id: tif_print.c,v 1.64 2015-12-06 22:19:56 erouault Exp $ */ +/* $Id: tif_print.c,v 1.65 2016-11-20 22:31:22 erouault Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -262,7 +262,7 @@ TIFFPrintDirectory(TIFF* tif, FILE* fd, long flags) if (td->td_subfiletype & FILETYPE_MASK) fprintf(fd, "%stransparency mask", sep); fprintf(fd, " (%lu = 0x%lx)\n", - (long) td->td_subfiletype, (long) td->td_subfiletype); + (unsigned long) td->td_subfiletype, (long) td->td_subfiletype); } if (TIFFFieldSet(tif,FIELD_IMAGEDIMENSIONS)) { fprintf(fd, " Image Width: %lu Image Length: %lu", @@ -521,7 +521,7 @@ TIFFPrintDirectory(TIFF* tif, FILE* fd, long flags) fprintf(fd, "\n"); n = 1L<<td->td_bitspersample; for (l = 0; l < n; l++) - fprintf(fd, " %5lu: %5u %5u %5u\n", + fprintf(fd, " %5ld: %5u %5u %5u\n", l, td->td_colormap[0][l], td->td_colormap[1][l], @@ -544,7 +544,7 @@ TIFFPrintDirectory(TIFF* tif, FILE* fd, long flags) n = 1L<<td->td_bitspersample; for (l = 0; l < n; l++) { uint16 i; - fprintf(fd, " %2lu: %5u", + fprintf(fd, " %2ld: %5u", l, td->td_transferfunction[0][l]); for (i = 1; i < td->td_samplesperpixel; i++) fprintf(fd, " %5u", @@ -661,7 +661,7 @@ TIFFPrintDirectory(TIFF* tif, FILE* fd, long flags) uint32 s; fprintf(fd, " %lu %s:\n", - (long) td->td_nstrips, + (unsigned long) td->td_nstrips, isTiled(tif) ? "Tiles" : "Strips"); for (s = 0; s < td->td_nstrips; s++) #if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) diff --git a/chromium/third_party/pdfium/third_party/libtiff/tif_read.c b/chromium/third_party/pdfium/third_party/libtiff/tif_read.c index c916ac8acbd..ad0a778c0f5 100644 --- a/chromium/third_party/pdfium/third_party/libtiff/tif_read.c +++ b/chromium/third_party/pdfium/third_party/libtiff/tif_read.c @@ -1,4 +1,4 @@ -/* $Id: tif_read.c,v 1.49 2016-07-10 18:00:21 erouault Exp $ */ +/* $Id: tif_read.c,v 1.59 2017-05-13 15:34:06 erouault Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -47,6 +47,121 @@ TIFFReadRawTile1(TIFF* tif, uint32 tile, void* buf, tmsize_t size, const char* m #define NOSTRIP ((uint32)(-1)) /* undefined state */ #define NOTILE ((uint32)(-1)) /* undefined state */ +#define INITIAL_THRESHOLD (1024 * 1024) +#define THRESHOLD_MULTIPLIER 10 +#define MAX_THRESHOLD (THRESHOLD_MULTIPLIER * THRESHOLD_MULTIPLIER * THRESHOLD_MULTIPLIER * INITIAL_THRESHOLD) + +/* Read 'size' bytes in tif_rawdata buffer starting at offset 'rawdata_offset' + * Returns 1 in case of success, 0 otherwise. */ +static int TIFFReadAndRealloc( TIFF* tif, tmsize_t size, + tmsize_t rawdata_offset, + int is_strip, uint32 strip_or_tile, + const char* module ) +{ +#if SIZEOF_VOIDP == 8 || SIZEOF_SIZE_T == 8 + tmsize_t threshold = INITIAL_THRESHOLD; +#endif + tmsize_t already_read = 0; + + /* On 64 bit processes, read first a maximum of 1 MB, then 10 MB, etc */ + /* so as to avoid allocating too much memory in case the file is too */ + /* short. We could ask for the file size, but this might be */ + /* expensive with some I/O layers (think of reading a gzipped file) */ + /* Restrict to 64 bit processes, so as to avoid reallocs() */ + /* on 32 bit processes where virtual memory is scarce. */ + while( already_read < size ) + { + tmsize_t bytes_read; + tmsize_t to_read = size - already_read; +#if SIZEOF_VOIDP == 8 || SIZEOF_SIZE_T == 8 + if( to_read >= threshold && threshold < MAX_THRESHOLD && + already_read + to_read + rawdata_offset > tif->tif_rawdatasize ) + { + to_read = threshold; + threshold *= THRESHOLD_MULTIPLIER; + } +#endif + if (already_read + to_read + rawdata_offset > tif->tif_rawdatasize) { + uint8* new_rawdata; + assert((tif->tif_flags & TIFF_MYBUFFER) != 0); + tif->tif_rawdatasize = (tmsize_t)TIFFroundup_64( + (uint64)already_read + to_read + rawdata_offset, 1024); + if (tif->tif_rawdatasize==0) { + TIFFErrorExt(tif->tif_clientdata, module, + "Invalid buffer size"); + return 0; + } + new_rawdata = (uint8*) _TIFFrealloc( + tif->tif_rawdata, tif->tif_rawdatasize); + if( new_rawdata == 0 ) + { + TIFFErrorExt(tif->tif_clientdata, module, + "No space for data buffer at scanline %lu", + (unsigned long) tif->tif_row); + _TIFFfree(tif->tif_rawdata); + tif->tif_rawdata = 0; + tif->tif_rawdatasize = 0; + return 0; + } + tif->tif_rawdata = new_rawdata; + } + + bytes_read = TIFFReadFile(tif, + tif->tif_rawdata + rawdata_offset + already_read, to_read); + already_read += bytes_read; + if (bytes_read != to_read) { + memset( tif->tif_rawdata + rawdata_offset + already_read, 0, + tif->tif_rawdatasize - rawdata_offset - already_read ); +#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) + if( is_strip ) + { + TIFFErrorExt(tif->tif_clientdata, module, + "Read error at scanline %lu; got %I64u bytes, " + "expected %I64u", + (unsigned long) tif->tif_row, + (unsigned __int64) already_read, + (unsigned __int64) size); + } + else + { + TIFFErrorExt(tif->tif_clientdata, module, + "Read error at row %lu, col %lu, tile %lu; " + "got %I64u bytes, expected %I64u", + (unsigned long) tif->tif_row, + (unsigned long) tif->tif_col, + (unsigned long) strip_or_tile, + (unsigned __int64) already_read, + (unsigned __int64) size); + } +#else + if( is_strip ) + { + TIFFErrorExt(tif->tif_clientdata, module, + "Read error at scanline %lu; got %llu bytes, " + "expected %llu", + (unsigned long) tif->tif_row, + (unsigned long long) already_read, + (unsigned long long) size); + } + else + { + TIFFErrorExt(tif->tif_clientdata, module, + "Read error at row %lu, col %lu, tile %lu; " + "got %llu bytes, expected %llu", + (unsigned long) tif->tif_row, + (unsigned long) tif->tif_col, + (unsigned long) strip_or_tile, + (unsigned long long) already_read, + (unsigned long long) size); + } +#endif + return 0; + } + } + return 1; +} + + static int TIFFFillStripPartial( TIFF *tif, int strip, tmsize_t read_ahead, int restart ) { @@ -54,7 +169,8 @@ TIFFFillStripPartial( TIFF *tif, int strip, tmsize_t read_ahead, int restart ) register TIFFDirectory *td = &tif->tif_dir; tmsize_t unused_data; uint64 read_offset; - tmsize_t cc, to_read; + tmsize_t to_read; + tmsize_t read_ahead_mod; /* tmsize_t bytecountm; */ if (!_TIFFFillStriles( tif ) || !tif->tif_dir.td_stripbytecount) @@ -67,7 +183,14 @@ TIFFFillStripPartial( TIFF *tif, int strip, tmsize_t read_ahead, int restart ) */ /* bytecountm=(tmsize_t) td->td_stripbytecount[strip]; */ - if (read_ahead*2 > tif->tif_rawdatasize) { + + /* Not completely sure where the * 2 comes from, but probably for */ + /* an exponentional growth strategy of tif_rawdatasize */ + if( read_ahead < TIFF_TMSIZE_T_MAX / 2 ) + read_ahead_mod = read_ahead * 2; + else + read_ahead_mod = read_ahead; + if (read_ahead_mod > tif->tif_rawdatasize) { assert( restart ); tif->tif_curstrip = NOSTRIP; @@ -77,8 +200,6 @@ TIFFFillStripPartial( TIFF *tif, int strip, tmsize_t read_ahead, int restart ) (unsigned long) strip); return (0); } - if (!TIFFReadBufferSetup(tif, 0, read_ahead*2)) - return (0); } if( restart ) @@ -118,7 +239,10 @@ TIFFFillStripPartial( TIFF *tif, int strip, tmsize_t read_ahead, int restart ) /* ** How much do we want to read? */ - to_read = tif->tif_rawdatasize - unused_data; + if( read_ahead_mod > tif->tif_rawdatasize ) + to_read = read_ahead_mod - unused_data; + else + to_read = tif->tif_rawdatasize - unused_data; if( (uint64) to_read > td->td_stripbytecount[strip] - tif->tif_rawdataoff - tif->tif_rawdataloaded ) { @@ -127,25 +251,14 @@ TIFFFillStripPartial( TIFF *tif, int strip, tmsize_t read_ahead, int restart ) } assert((tif->tif_flags&TIFF_BUFFERMMAP)==0); - cc = TIFFReadFile(tif, tif->tif_rawdata + unused_data, to_read); - - if (cc != to_read) { -#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) - TIFFErrorExt(tif->tif_clientdata, module, - "Read error at scanline %lu; got %I64u bytes, expected %I64u", - (unsigned long) tif->tif_row, - (unsigned __int64) cc, - (unsigned __int64) to_read); -#else - TIFFErrorExt(tif->tif_clientdata, module, - "Read error at scanline %lu; got %llu bytes, expected %llu", - (unsigned long) tif->tif_row, - (unsigned long long) cc, - (unsigned long long) to_read); -#endif + if( !TIFFReadAndRealloc( tif, to_read, unused_data, + 1, /* is_strip */ + 0, /* strip_or_tile */ + module) ) + { return 0; } - + tif->tif_rawdataoff = tif->tif_rawdataoff + tif->tif_rawdataloaded - unused_data ; tif->tif_rawdataloaded = unused_data + to_read; @@ -164,7 +277,10 @@ TIFFFillStripPartial( TIFF *tif, int strip, tmsize_t read_ahead, int restart ) if( restart ) return TIFFStartStrip(tif, strip); else + { + tif->tif_rawcc = tif->tif_rawdataloaded; return 1; + } } /* @@ -219,7 +335,18 @@ TIFFSeek(TIFF* tif, uint32 row, uint16 sample ) if( !whole_strip ) { - read_ahead = tif->tif_scanlinesize * 16 + 5000; + /* 16 is for YCbCr mode where we may need to read 16 */ + /* lines at a time to get a decompressed line, and 5000 */ + /* is some constant value, for example for JPEG tables */ + if( tif->tif_scanlinesize < TIFF_TMSIZE_T_MAX / 16 && + tif->tif_scanlinesize * 16 < TIFF_TMSIZE_T_MAX - 5000 ) + { + read_ahead = tif->tif_scanlinesize * 16 + 5000; + } + else + { + read_ahead = tif->tif_scanlinesize; + } } /* @@ -315,18 +442,17 @@ TIFFReadScanline(TIFF* tif, void* buf, uint32 row, uint16 sample) } /* - * Read a strip of data and decompress the specified - * amount into the user-supplied buffer. + * Calculate the strip size according to the number of + * rows in the strip (check for truncated last strip on any + * of the separations). */ -tmsize_t -TIFFReadEncodedStrip(TIFF* tif, uint32 strip, void* buf, tmsize_t size) +static tmsize_t TIFFReadEncodedStripGetStripSize(TIFF* tif, uint32 strip, uint16* pplane) { static const char module[] = "TIFFReadEncodedStrip"; TIFFDirectory *td = &tif->tif_dir; uint32 rowsperstrip; uint32 stripsperplane; uint32 stripinplane; - uint16 plane; uint32 rows; tmsize_t stripsize; if (!TIFFCheckRead(tif,0)) @@ -338,23 +464,37 @@ TIFFReadEncodedStrip(TIFF* tif, uint32 strip, void* buf, tmsize_t size) (unsigned long)td->td_nstrips); return((tmsize_t)(-1)); } - /* - * Calculate the strip size according to the number of - * rows in the strip (check for truncated last strip on any - * of the separations). - */ + rowsperstrip=td->td_rowsperstrip; if (rowsperstrip>td->td_imagelength) rowsperstrip=td->td_imagelength; stripsperplane= TIFFhowmany_32_maxuint_compat(td->td_imagelength, rowsperstrip); stripinplane=(strip%stripsperplane); - plane=(uint16)(strip/stripsperplane); + if( pplane ) *pplane=(uint16)(strip/stripsperplane); rows=td->td_imagelength-stripinplane*rowsperstrip; if (rows>rowsperstrip) rows=rowsperstrip; stripsize=TIFFVStripSize(tif,rows); if (stripsize==0) return((tmsize_t)(-1)); + return stripsize; +} + +/* + * Read a strip of data and decompress the specified + * amount into the user-supplied buffer. + */ +tmsize_t +TIFFReadEncodedStrip(TIFF* tif, uint32 strip, void* buf, tmsize_t size) +{ + static const char module[] = "TIFFReadEncodedStrip"; + TIFFDirectory *td = &tif->tif_dir; + tmsize_t stripsize; + uint16 plane; + + stripsize=TIFFReadEncodedStripGetStripSize(tif, strip, &plane); + if (stripsize==((tmsize_t)(-1))) + return((tmsize_t)(-1)); /* shortcut to avoid an extra memcpy() */ if( td->td_compression == COMPRESSION_NONE && @@ -383,6 +523,50 @@ TIFFReadEncodedStrip(TIFF* tif, uint32 strip, void* buf, tmsize_t size) return(stripsize); } +/* Variant of TIFFReadEncodedStrip() that does + * * if *buf == NULL, *buf = _TIFFmalloc(bufsizetoalloc) only after TIFFFillStrip() has + * suceeded. This avoid excessive memory allocation in case of truncated + * file. + * * calls regular TIFFReadEncodedStrip() if *buf != NULL + */ +tmsize_t +_TIFFReadEncodedStripAndAllocBuffer(TIFF* tif, uint32 strip, + void **buf, tmsize_t bufsizetoalloc, + tmsize_t size_to_read) +{ + tmsize_t this_stripsize; + uint16 plane; + + if( *buf != NULL ) + { + return TIFFReadEncodedStrip(tif, strip, *buf, size_to_read); + } + + this_stripsize=TIFFReadEncodedStripGetStripSize(tif, strip, &plane); + if (this_stripsize==((tmsize_t)(-1))) + return((tmsize_t)(-1)); + + if ((size_to_read!=(tmsize_t)(-1))&&(size_to_read<this_stripsize)) + this_stripsize=size_to_read; + if (!TIFFFillStrip(tif,strip)) + return((tmsize_t)(-1)); + + *buf = _TIFFmalloc(bufsizetoalloc); + if (*buf == NULL) { + TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "No space for strip buffer"); + return((tmsize_t)(-1)); + } + _TIFFmemset(*buf, 0, bufsizetoalloc); + + if ((*tif->tif_decodestrip)(tif,*buf,this_stripsize,plane)<=0) + return((tmsize_t)(-1)); + (*tif->tif_postdecode)(tif,*buf,this_stripsize); + return(this_stripsize); + + +} + + static tmsize_t TIFFReadRawStrip1(TIFF* tif, uint32 strip, void* buf, tmsize_t size, const char* module) @@ -420,25 +604,25 @@ TIFFReadRawStrip1(TIFF* tif, uint32 strip, void* buf, tmsize_t size, return ((tmsize_t)(-1)); } } else { - tmsize_t ma; + tmsize_t ma = 0; tmsize_t n; if ((td->td_stripoffset[strip] > (uint64)TIFF_TMSIZE_T_MAX)|| - ((ma=(tmsize_t)td->td_stripoffset[strip])>tif->tif_size)) - { - n=0; - } - else if( ma > TIFF_TMSIZE_T_MAX - size ) - { - n=0; - } - else - { - tmsize_t mb=ma+size; - if (mb>tif->tif_size) - n=tif->tif_size-ma; - else - n=size; - } + ((ma=(tmsize_t)td->td_stripoffset[strip])>tif->tif_size)) + { + n=0; + } + else if( ma > TIFF_TMSIZE_T_MAX - size ) + { + n=0; + } + else + { + tmsize_t mb=ma+size; + if (mb>tif->tif_size) + n=tif->tif_size-ma; + else + n=size; + } if (n!=size) { #if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) TIFFErrorExt(tif->tif_clientdata, module, @@ -463,6 +647,43 @@ TIFFReadRawStrip1(TIFF* tif, uint32 strip, void* buf, tmsize_t size, return (size); } +static tmsize_t +TIFFReadRawStripOrTile2(TIFF* tif, uint32 strip_or_tile, int is_strip, + tmsize_t size, const char* module) +{ + TIFFDirectory *td = &tif->tif_dir; + + assert( !isMapped(tif) ); + assert((tif->tif_flags&TIFF_NOREADRAW)==0); + + if (!SeekOK(tif, td->td_stripoffset[strip_or_tile])) { + if( is_strip ) + { + TIFFErrorExt(tif->tif_clientdata, module, + "Seek error at scanline %lu, strip %lu", + (unsigned long) tif->tif_row, + (unsigned long) strip_or_tile); + } + else + { + TIFFErrorExt(tif->tif_clientdata, module, + "Seek error at row %lu, col %lu, tile %lu", + (unsigned long) tif->tif_row, + (unsigned long) tif->tif_col, + (unsigned long) strip_or_tile); + } + return ((tmsize_t)(-1)); + } + + if( !TIFFReadAndRealloc( tif, size, 0, is_strip, + strip_or_tile, module ) ) + { + return ((tmsize_t)(-1)); + } + + return (size); +} + /* * Read a strip of data from the file. */ @@ -544,6 +765,39 @@ TIFFFillStrip(TIFF* tif, uint32 strip) #endif return (0); } + + /* To avoid excessive memory allocations: */ + /* Byte count should normally not be larger than a number of */ + /* times the uncompressed size plus some margin */ + if( bytecount > 1024 * 1024 ) + { + /* 10 and 4096 are just values that could be adjusted. */ + /* Hopefully they are safe enough for all codecs */ + tmsize_t stripsize = TIFFStripSize(tif); + if( stripsize != 0 && + (bytecount - 4096) / 10 > (uint64)stripsize ) + { + uint64 newbytecount = (uint64)stripsize * 10 + 4096; + if( (int64)newbytecount >= 0 ) + { +#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) + TIFFWarningExt(tif->tif_clientdata, module, + "Too large strip byte count %I64u, strip %lu. Limiting to %I64u", + (unsigned __int64) bytecount, + (unsigned long) strip, + (unsigned __int64) newbytecount); +#else + TIFFErrorExt(tif->tif_clientdata, module, + "Too large strip byte count %llu, strip %lu. Limiting to %llu", + (unsigned long long) bytecount, + (unsigned long) strip, + (unsigned long long) newbytecount); +#endif + bytecount = newbytecount; + } + } + } + if (isMapped(tif) && (isFillOrder(tif, td->td_fillorder) || (tif->tif_flags & TIFF_NOBITREV))) { @@ -625,13 +879,6 @@ TIFFFillStrip(TIFF* tif, uint32 strip) TIFFErrorExt(tif->tif_clientdata,module,"Integer overflow"); return(0); } - const tmsize_t size=isMapped(tif)? tif->tif_size : (tmsize_t)TIFFGetFileSize(tif); - if (bytecountm > size) { - TIFFErrorExt(tif->tif_clientdata, module, - "Requested read strip size %lu is too large", - (unsigned long) strip); - return (0); - } if (bytecountm > tif->tif_rawdatasize) { tif->tif_curstrip = NOSTRIP; if ((tif->tif_flags & TIFF_MYBUFFER) == 0) { @@ -640,17 +887,36 @@ TIFFFillStrip(TIFF* tif, uint32 strip) (unsigned long) strip); return (0); } - if (!TIFFReadBufferSetup(tif, 0, bytecountm)) - return (0); } if (tif->tif_flags&TIFF_BUFFERMMAP) { tif->tif_curstrip = NOSTRIP; - if (!TIFFReadBufferSetup(tif, 0, bytecountm)) + tif->tif_rawdata = NULL; + tif->tif_rawdatasize = 0; + tif->tif_flags &= ~TIFF_BUFFERMMAP; + } + + if( isMapped(tif) ) + { + if (bytecountm > tif->tif_rawdatasize && + !TIFFReadBufferSetup(tif, 0, bytecountm)) + { return (0); + } + if (TIFFReadRawStrip1(tif, strip, tif->tif_rawdata, + bytecountm, module) != bytecountm) + { + return (0); + } + } + else + { + if (TIFFReadRawStripOrTile2(tif, strip, 1, + bytecountm, module) != bytecountm) + { + return (0); + } } - if (TIFFReadRawStrip1(tif, strip, tif->tif_rawdata, - bytecountm, module) != bytecountm) - return (0); + tif->tif_rawdataoff = 0; tif->tif_rawdataloaded = bytecountm; @@ -730,6 +996,78 @@ TIFFReadEncodedTile(TIFF* tif, uint32 tile, void* buf, tmsize_t size) return ((tmsize_t)(-1)); } +/* Variant of TIFFReadTile() that does + * * if *buf == NULL, *buf = _TIFFmalloc(bufsizetoalloc) only after TIFFFillTile() has + * suceeded. This avoid excessive memory allocation in case of truncated + * file. + * * calls regular TIFFReadEncodedTile() if *buf != NULL + */ +tmsize_t +_TIFFReadTileAndAllocBuffer(TIFF* tif, + void **buf, tmsize_t bufsizetoalloc, + uint32 x, uint32 y, uint32 z, uint16 s) +{ + if (!TIFFCheckRead(tif, 1) || !TIFFCheckTile(tif, x, y, z, s)) + return ((tmsize_t)(-1)); + return (_TIFFReadEncodedTileAndAllocBuffer(tif, + TIFFComputeTile(tif, x, y, z, s), + buf, bufsizetoalloc, + (tmsize_t)(-1))); +} + +/* Variant of TIFFReadEncodedTile() that does + * * if *buf == NULL, *buf = _TIFFmalloc(bufsizetoalloc) only after TIFFFillTile() has + * suceeded. This avoid excessive memory allocation in case of truncated + * file. + * * calls regular TIFFReadEncodedTile() if *buf != NULL + */ +tmsize_t +_TIFFReadEncodedTileAndAllocBuffer(TIFF* tif, uint32 tile, + void **buf, tmsize_t bufsizetoalloc, + tmsize_t size_to_read) +{ + static const char module[] = "_TIFFReadEncodedTileAndAllocBuffer"; + TIFFDirectory *td = &tif->tif_dir; + tmsize_t tilesize = tif->tif_tilesize; + + if( *buf != NULL ) + { + return TIFFReadEncodedTile(tif, tile, *buf, size_to_read); + } + + if (!TIFFCheckRead(tif, 1)) + return ((tmsize_t)(-1)); + if (tile >= td->td_nstrips) { + TIFFErrorExt(tif->tif_clientdata, module, + "%lu: Tile out of range, max %lu", + (unsigned long) tile, (unsigned long) td->td_nstrips); + return ((tmsize_t)(-1)); + } + + if (!TIFFFillTile(tif,tile)) + return((tmsize_t)(-1)); + + *buf = _TIFFmalloc(bufsizetoalloc); + if (*buf == NULL) { + TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), + "No space for tile buffer"); + return((tmsize_t)(-1)); + } + _TIFFmemset(*buf, 0, bufsizetoalloc); + + if (size_to_read == (tmsize_t)(-1)) + size_to_read = tilesize; + else if (size_to_read > tilesize) + size_to_read = tilesize; + if( (*tif->tif_decodetile)(tif, + (uint8*) *buf, size_to_read, (uint16)(tile/td->td_stripsperimage))) { + (*tif->tif_postdecode)(tif, (uint8*) *buf, size_to_read); + return (size_to_read); + } else + return ((tmsize_t)(-1)); +} + + static tmsize_t TIFFReadRawTile1(TIFF* tif, uint32 tile, void* buf, tmsize_t size, const char* module) { @@ -933,18 +1271,36 @@ TIFFFillTile(TIFF* tif, uint32 tile) (unsigned long) tile); return (0); } - if (!TIFFReadBufferSetup(tif, 0, bytecountm)) - return (0); } if (tif->tif_flags&TIFF_BUFFERMMAP) { tif->tif_curtile = NOTILE; - if (!TIFFReadBufferSetup(tif, 0, bytecountm)) + tif->tif_rawdata = NULL; + tif->tif_rawdatasize = 0; + tif->tif_flags &= ~TIFF_BUFFERMMAP; + } + + if( isMapped(tif) ) + { + if (bytecountm > tif->tif_rawdatasize && + !TIFFReadBufferSetup(tif, 0, bytecountm)) + { return (0); + } + if (TIFFReadRawTile1(tif, tile, tif->tif_rawdata, + bytecountm, module) != bytecountm) + { + return (0); + } + } + else + { + if (TIFFReadRawStripOrTile2(tif, tile, 0, + bytecountm, module) != bytecountm) + { + return (0); + } } - if (TIFFReadRawTile1(tif, tile, tif->tif_rawdata, - bytecountm, module) != bytecountm) - return (0); tif->tif_rawdataoff = 0; tif->tif_rawdataloaded = bytecountm; @@ -995,7 +1351,6 @@ TIFFReadBufferSetup(TIFF* tif, void* bp, tmsize_t size) /* Initialize to zero to avoid uninitialized buffers in case of */ /* short reads (http://bugzilla.maptools.org/show_bug.cgi?id=2651) */ tif->tif_rawdata = (uint8*) _TIFFcalloc(1, tif->tif_rawdatasize); - tif->tif_flags |= TIFF_MYBUFFER; } if (tif->tif_rawdata == NULL) { @@ -1037,7 +1392,10 @@ TIFFStartStrip(TIFF* tif, uint32 strip) else { tif->tif_rawcp = tif->tif_rawdata; - tif->tif_rawcc = (tmsize_t)td->td_stripbytecount[strip]; + if( tif->tif_rawdataloaded > 0 ) + tif->tif_rawcc = tif->tif_rawdataloaded; + else + tif->tif_rawcc = (tmsize_t)td->td_stripbytecount[strip]; } return ((*tif->tif_predecode)(tif, (uint16)(strip / td->td_stripsperimage))); diff --git a/chromium/third_party/pdfium/third_party/libtiff/tif_strip.c b/chromium/third_party/pdfium/third_party/libtiff/tif_strip.c index 3b55285cd3b..6e9f2ef6ddf 100644 --- a/chromium/third_party/pdfium/third_party/libtiff/tif_strip.c +++ b/chromium/third_party/pdfium/third_party/libtiff/tif_strip.c @@ -1,4 +1,4 @@ -/* $Id: tif_strip.c,v 1.37 2016-11-09 23:00:49 erouault Exp $ */ +/* $Id: tif_strip.c,v 1.38 2016-12-03 11:02:15 erouault Exp $ */ /* * Copyright (c) 1991-1997 Sam Leffler diff --git a/chromium/third_party/pdfium/third_party/libtiff/tif_write.c b/chromium/third_party/pdfium/third_party/libtiff/tif_write.c index 34c4d81a09d..4c216ec200a 100644 --- a/chromium/third_party/pdfium/third_party/libtiff/tif_write.c +++ b/chromium/third_party/pdfium/third_party/libtiff/tif_write.c @@ -1,4 +1,4 @@ -/* $Id: tif_write.c,v 1.45 2016-09-23 22:12:18 erouault Exp $ */ +/* $Id: tif_write.c,v 1.46 2016-12-03 21:57:44 erouault Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -476,22 +476,22 @@ TIFFWriteEncodedTile(TIFF* tif, uint32 tile, void* data, tmsize_t cc) sample = (uint16)(tile/td->td_stripsperimage); if (!(*tif->tif_preencode)(tif, sample)) return ((tmsize_t)(-1)); - /* swab if needed - note that source buffer will be altered */ - tif->tif_postdecode( tif, (uint8*) data, cc ); + /* swab if needed - note that source buffer will be altered */ + tif->tif_postdecode( tif, (uint8*) data, cc ); - if (!(*tif->tif_encodetile)(tif, (uint8*) data, cc, sample)) - return ((tmsize_t) -1); - if (!(*tif->tif_postencode)(tif)) - return ((tmsize_t)(-1)); - if (!isFillOrder(tif, td->td_fillorder) && - (tif->tif_flags & TIFF_NOBITREV) == 0) - TIFFReverseBits((uint8*)tif->tif_rawdata, tif->tif_rawcc); - if (tif->tif_rawcc > 0 && !TIFFAppendToStrip(tif, tile, - tif->tif_rawdata, tif->tif_rawcc)) - return ((tmsize_t)(-1)); - tif->tif_rawcc = 0; - tif->tif_rawcp = tif->tif_rawdata; - return (cc); + if (!(*tif->tif_encodetile)(tif, (uint8*) data, cc, sample)) + return ((tmsize_t) -1); + if (!(*tif->tif_postencode)(tif)) + return ((tmsize_t)(-1)); + if (!isFillOrder(tif, td->td_fillorder) && + (tif->tif_flags & TIFF_NOBITREV) == 0) + TIFFReverseBits((uint8*)tif->tif_rawdata, tif->tif_rawcc); + if (tif->tif_rawcc > 0 && !TIFFAppendToStrip(tif, tile, + tif->tif_rawdata, tif->tif_rawcc)) + return ((tmsize_t)(-1)); + tif->tif_rawcc = 0; + tif->tif_rawcp = tif->tif_rawdata; + return (cc); } /* diff --git a/chromium/third_party/pdfium/third_party/libtiff/tif_zip.c b/chromium/third_party/pdfium/third_party/libtiff/tif_zip.c index 8c35aea83df..42943fbb14f 100644 --- a/chromium/third_party/pdfium/third_party/libtiff/tif_zip.c +++ b/chromium/third_party/pdfium/third_party/libtiff/tif_zip.c @@ -1,4 +1,4 @@ -/* $Id: tif_zip.c,v 1.36 2016-11-12 16:48:28 erouault Exp $ */ +/* $Id: tif_zip.c,v 1.37 2017-05-10 15:21:16 erouault Exp $ */ /* * Copyright (c) 1995-1997 Sam Leffler @@ -107,7 +107,11 @@ ZIPSetupDecode(TIFF* tif) sp->state = 0; } - if (inflateInit(&sp->stream) != Z_OK) { + /* This function can possibly be called several times by */ + /* PredictorSetupDecode() if this function succeeds but */ + /* PredictorSetup() fails */ + if ((sp->state & ZSTATE_INIT_DECODE) == 0 && + inflateInit(&sp->stream) != Z_OK) { TIFFErrorExt(tif->tif_clientdata, module, "%s", SAFE_MSG(sp)); return (0); } else { diff --git a/chromium/third_party/pdfium/third_party/libtiff/tiffio.h b/chromium/third_party/pdfium/third_party/libtiff/tiffio.h index 7d0da761fcb..f1d2fdc1640 100644 --- a/chromium/third_party/pdfium/third_party/libtiff/tiffio.h +++ b/chromium/third_party/pdfium/third_party/libtiff/tiffio.h @@ -1,4 +1,4 @@ -/* $Id: tiffio.h,v 1.92 2016-01-23 21:20:34 erouault Exp $ */ +/* $Id: tiffio.h,v 1.94 2017-01-11 19:02:49 erouault Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -432,6 +432,8 @@ extern int TIFFReadRGBAImageOriented(TIFF*, uint32, uint32, uint32*, int, int); extern int TIFFReadRGBAStrip(TIFF*, uint32, uint32 * ); extern int TIFFReadRGBATile(TIFF*, uint32, uint32, uint32 * ); +extern int TIFFReadRGBAStripExt(TIFF*, uint32, uint32 *, int stop_on_error ); +extern int TIFFReadRGBATileExt(TIFF*, uint32, uint32, uint32 *, int stop_on_error ); extern int TIFFRGBAImageOK(TIFF*, char [1024]); extern int TIFFRGBAImageBegin(TIFFRGBAImage*, TIFF*, int, char [1024]); extern int TIFFRGBAImageGet(TIFFRGBAImage*, uint32*, uint32, uint32); diff --git a/chromium/third_party/pdfium/third_party/libtiff/tiffiop.h b/chromium/third_party/pdfium/third_party/libtiff/tiffiop.h index 1925a6b5e4b..6fb47de5b2c 100644 --- a/chromium/third_party/pdfium/third_party/libtiff/tiffiop.h +++ b/chromium/third_party/pdfium/third_party/libtiff/tiffiop.h @@ -1,4 +1,4 @@ -/* $Id: tiffiop.h,v 1.89 2016-01-23 21:20:34 erouault Exp $ */ +/* $Id: tiffiop.h,v 1.90 2016-12-02 21:56:56 erouault Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -364,6 +364,20 @@ extern void* _TIFFCheckRealloc(TIFF*, void*, tmsize_t, tmsize_t, const char*); extern double _TIFFUInt64ToDouble(uint64); extern float _TIFFUInt64ToFloat(uint64); +extern tmsize_t +_TIFFReadEncodedStripAndAllocBuffer(TIFF* tif, uint32 strip, + void **buf, tmsize_t bufsizetoalloc, + tmsize_t size_to_read); +extern tmsize_t +_TIFFReadEncodedTileAndAllocBuffer(TIFF* tif, uint32 tile, + void **buf, tmsize_t bufsizetoalloc, + tmsize_t size_to_read); +extern tmsize_t +_TIFFReadTileAndAllocBuffer(TIFF* tif, + void **buf, tmsize_t bufsizetoalloc, + uint32 x, uint32 y, uint32 z, uint16 s); + + extern int TIFFInitDumpMode(TIFF*, int); #ifdef PACKBITS_SUPPORT extern int TIFFInitPackBits(TIFF*, int); diff --git a/chromium/third_party/pdfium/third_party/libtiff/tiffvers.h b/chromium/third_party/pdfium/third_party/libtiff/tiffvers.h index fe55c726cb9..890e433d8a0 100644 --- a/chromium/third_party/pdfium/third_party/libtiff/tiffvers.h +++ b/chromium/third_party/pdfium/third_party/libtiff/tiffvers.h @@ -1,4 +1,4 @@ -#define TIFFLIB_VERSION_STR "LIBTIFF, Version 4.0.7\nCopyright (c) 1988-1996 Sam Leffler\nCopyright (c) 1991-1996 Silicon Graphics, Inc." +#define TIFFLIB_VERSION_STR "LIBTIFF, Version 4.0.8\nCopyright (c) 1988-1996 Sam Leffler\nCopyright (c) 1991-1996 Silicon Graphics, Inc." /* * This define can be used in code that requires * compilation-related definitions specific to a @@ -6,4 +6,4 @@ * version checking should be done based on the * string returned by TIFFGetVersion. */ -#define TIFFLIB_VERSION 20161119 +#define TIFFLIB_VERSION 20170521 diff --git a/chromium/third_party/pdfium/xfa/fde/cfde_rendercontext.cpp b/chromium/third_party/pdfium/xfa/fde/cfde_rendercontext.cpp index 702f7ce2955..dc2a628c23f 100644 --- a/chromium/third_party/pdfium/xfa/fde/cfde_rendercontext.cpp +++ b/chromium/third_party/pdfium/xfa/fde/cfde_rendercontext.cpp @@ -40,15 +40,13 @@ void CFDE_RenderContext::DoRender() { if (!m_pRenderDevice || !m_pIterator) return; - CFX_Matrix rm; - rm.SetReverse(m_Transform); CFX_RectF rtDocClip = m_pRenderDevice->GetClipRect(); if (rtDocClip.IsEmpty()) { rtDocClip.left = rtDocClip.top = 0; rtDocClip.width = (float)m_pRenderDevice->GetWidth(); rtDocClip.height = (float)m_pRenderDevice->GetHeight(); } - rm.TransformRect(rtDocClip); + m_Transform.GetInverse().TransformRect(rtDocClip); IFDE_VisualSet* pVisualSet; FDE_TEXTEDITPIECE* pPiece; int32_t iCount = 0; diff --git a/chromium/third_party/pdfium/xfa/fde/cfde_textout.cpp b/chromium/third_party/pdfium/xfa/fde/cfde_textout.cpp index 6d5ab2a980d..5d84b6d12b8 100644 --- a/chromium/third_party/pdfium/xfa/fde/cfde_textout.cpp +++ b/chromium/third_party/pdfium/xfa/fde/cfde_textout.cpp @@ -294,9 +294,7 @@ void CFDE_TextOut::DrawText(const wchar_t* pwsStr, int32_t iLength, const CFX_RectF& rect) { CFX_RectF rtText(rect.left, rect.top, rect.width, rect.height); - CFX_Matrix rm; - rm.SetReverse(m_Matrix); - rm.TransformRect(rtText); + m_Matrix.GetInverse().TransformRect(rtText); DrawText(pwsStr, iLength, rtText, m_rtClip); } diff --git a/chromium/third_party/pdfium/xfa/fde/css/cfde_cssdeclaration.cpp b/chromium/third_party/pdfium/xfa/fde/css/cfde_cssdeclaration.cpp index 00a2c9e33cf..e15e5f7fe7a 100644 --- a/chromium/third_party/pdfium/xfa/fde/css/cfde_cssdeclaration.cpp +++ b/chromium/third_party/pdfium/xfa/fde/css/cfde_cssdeclaration.cpp @@ -160,9 +160,8 @@ void CFDE_CSSDeclaration::AddProperty(const FDE_CSSPropertyTable* pTable, const CFX_WideStringC& value) { ASSERT(!value.IsEmpty()); - const wchar_t* pszValue = value.c_str(); + const wchar_t* pszValue = value.unterminated_c_str(); int32_t iValueLen = value.GetLength(); - bool bImportant = false; if (iValueLen >= 10 && pszValue[iValueLen - 10] == '!' && FXSYS_wcsnicmp(L"important", pszValue + iValueLen - 9, 9) == 0) { diff --git a/chromium/third_party/pdfium/xfa/fde/css/cfde_cssexttextbuf.cpp b/chromium/third_party/pdfium/xfa/fde/css/cfde_cssexttextbuf.cpp new file mode 100644 index 00000000000..86f6776c48d --- /dev/null +++ b/chromium/third_party/pdfium/xfa/fde/css/cfde_cssexttextbuf.cpp @@ -0,0 +1,17 @@ +// Copyright 2017 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 "xfa/fde/css/cfde_cssexttextbuf.h" + +CFDE_CSSExtTextBuf::CFDE_CSSExtTextBuf() + : m_pExtBuffer(nullptr), m_iDatLen(0), m_iDatPos(0) {} + +CFDE_CSSExtTextBuf::~CFDE_CSSExtTextBuf() {} + +void CFDE_CSSExtTextBuf::AttachBuffer(const wchar_t* pBuffer, int32_t iBufLen) { + m_pExtBuffer = pBuffer; + m_iDatLen = iBufLen; +} diff --git a/chromium/third_party/pdfium/xfa/fde/css/cfde_cssexttextbuf.h b/chromium/third_party/pdfium/xfa/fde/css/cfde_cssexttextbuf.h new file mode 100644 index 00000000000..0760182f25c --- /dev/null +++ b/chromium/third_party/pdfium/xfa/fde/css/cfde_cssexttextbuf.h @@ -0,0 +1,34 @@ +// Copyright 2017 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 + +#ifndef XFA_FDE_CSS_CFDE_CSSEXTTEXTBUF_H_ +#define XFA_FDE_CSS_CFDE_CSSEXTTEXTBUF_H_ + +#include "core/fxcrt/fx_system.h" + +class CFDE_CSSExtTextBuf { + public: + CFDE_CSSExtTextBuf(); + ~CFDE_CSSExtTextBuf(); + + void AttachBuffer(const wchar_t* pBuffer, int32_t iBufLen); + + bool IsEOF() const { return m_iDatPos >= m_iDatLen; } + + wchar_t GetChar() const { return m_pExtBuffer[m_iDatPos]; } + wchar_t GetNextChar() const { + return (m_iDatPos + 1 >= m_iDatLen) ? 0 : m_pExtBuffer[m_iDatPos + 1]; + } + + void MoveNext() { m_iDatPos++; } + + protected: + const wchar_t* m_pExtBuffer; + int32_t m_iDatLen; + int32_t m_iDatPos; +}; + +#endif // XFA_FDE_CSS_CFDE_CSSEXTTEXTBUF_H_ diff --git a/chromium/third_party/pdfium/xfa/fde/css/cfde_cssselector.cpp b/chromium/third_party/pdfium/xfa/fde/css/cfde_cssselector.cpp index c1e9f7f22a6..ad2ec40c2bd 100644 --- a/chromium/third_party/pdfium/xfa/fde/css/cfde_cssselector.cpp +++ b/chromium/third_party/pdfium/xfa/fde/css/cfde_cssselector.cpp @@ -52,7 +52,7 @@ std::unique_ptr<CFDE_CSSSelector> CFDE_CSSSelector::FromString( const CFX_WideStringC& str) { ASSERT(!str.IsEmpty()); - const wchar_t* psz = str.c_str(); + const wchar_t* psz = str.unterminated_c_str(); const wchar_t* pStart = psz; const wchar_t* pEnd = psz + str.GetLength(); for (; psz < pEnd; ++psz) { diff --git a/chromium/third_party/pdfium/xfa/fde/css/cfde_cssstyleselector.cpp b/chromium/third_party/pdfium/xfa/fde/css/cfde_cssstyleselector.cpp index 461192e9768..2fe306faec6 100644 --- a/chromium/third_party/pdfium/xfa/fde/css/cfde_cssstyleselector.cpp +++ b/chromium/third_party/pdfium/xfa/fde/css/cfde_cssstyleselector.cpp @@ -142,10 +142,8 @@ void CFDE_CSSStyleSelector::AppendInlineStyle(CFDE_CSSDeclaration* pDecl, const CFX_WideString& style) { ASSERT(pDecl && !style.IsEmpty()); - auto pSyntax = pdfium::MakeUnique<CFDE_CSSSyntaxParser>(); - if (!pSyntax->Init(style.c_str(), style.GetLength(), 32, true)) - return; - + auto pSyntax = pdfium::MakeUnique<CFDE_CSSSyntaxParser>( + style.c_str(), style.GetLength(), 32, true); int32_t iLen2 = 0; const FDE_CSSPropertyTable* table = nullptr; CFX_WideString wsName; diff --git a/chromium/third_party/pdfium/xfa/fde/css/cfde_cssstylesheet.cpp b/chromium/third_party/pdfium/xfa/fde/css/cfde_cssstylesheet.cpp index c16e25156c4..369279853e9 100644 --- a/chromium/third_party/pdfium/xfa/fde/css/cfde_cssstylesheet.cpp +++ b/chromium/third_party/pdfium/xfa/fde/css/cfde_cssstylesheet.cpp @@ -35,12 +35,10 @@ CFDE_CSSStyleRule* CFDE_CSSStyleSheet::GetRule(int32_t index) const { } bool CFDE_CSSStyleSheet::LoadBuffer(const wchar_t* pBuffer, int32_t iBufSize) { - ASSERT(pBuffer && iBufSize > 0); - - auto pSyntax = pdfium::MakeUnique<CFDE_CSSSyntaxParser>(); - if (!pSyntax->Init(pBuffer, iBufSize)) - return false; + ASSERT(pBuffer); + ASSERT(iBufSize > 0); + auto pSyntax = pdfium::MakeUnique<CFDE_CSSSyntaxParser>(pBuffer, iBufSize); Reset(); FDE_CSSSyntaxStatus eStatus; do { diff --git a/chromium/third_party/pdfium/xfa/fde/css/cfde_csssyntaxparser.cpp b/chromium/third_party/pdfium/xfa/fde/css/cfde_csssyntaxparser.cpp index e943f29f4da..51d99f1992e 100644 --- a/chromium/third_party/pdfium/xfa/fde/css/cfde_csssyntaxparser.cpp +++ b/chromium/third_party/pdfium/xfa/fde/css/cfde_csssyntaxparser.cpp @@ -22,38 +22,26 @@ bool IsSelectorStart(wchar_t wch) { } // namespace -CFDE_CSSSyntaxParser::CFDE_CSSSyntaxParser() +CFDE_CSSSyntaxParser::CFDE_CSSSyntaxParser(const wchar_t* pBuffer, + int32_t iBufferSize) + : CFDE_CSSSyntaxParser(pBuffer, iBufferSize, 32, false) {} + +CFDE_CSSSyntaxParser::CFDE_CSSSyntaxParser(const wchar_t* pBuffer, + int32_t iBufferSize, + int32_t iTextDatSize, + bool bOnlyDeclaration) : m_iTextDataLen(0), m_dwCheck(0xFFFFFFFF), - m_eMode(FDE_CSSSyntaxMode::RuleSet), - m_eStatus(FDE_CSSSyntaxStatus::None) {} - -CFDE_CSSSyntaxParser::~CFDE_CSSSyntaxParser() { - m_TextData.Reset(); - m_TextPlane.Reset(); -} - -bool CFDE_CSSSyntaxParser::Init(const wchar_t* pBuffer, - int32_t iBufferSize, - int32_t iTextDatSize, - bool bOnlyDeclaration) { + m_eStatus(FDE_CSSSyntaxStatus::None) { ASSERT(pBuffer && iBufferSize > 0 && iTextDatSize > 0); - Reset(bOnlyDeclaration); - if (!m_TextData.EstimateSize(iTextDatSize)) - return false; - return m_TextPlane.AttachBuffer(pBuffer, iBufferSize); -} - -void CFDE_CSSSyntaxParser::Reset(bool bOnlyDeclaration) { - m_TextPlane.Reset(); - m_TextData.Reset(); - m_iTextDataLen = 0; - m_dwCheck = 0xFFFFFFFF; - m_eStatus = FDE_CSSSyntaxStatus::None; m_eMode = bOnlyDeclaration ? FDE_CSSSyntaxMode::PropertyName : FDE_CSSSyntaxMode::RuleSet; + m_TextData.InitWithSize(iTextDatSize); + m_TextPlane.AttachBuffer(pBuffer, iBufferSize); } +CFDE_CSSSyntaxParser::~CFDE_CSSSyntaxParser() {} + FDE_CSSSyntaxStatus CFDE_CSSSyntaxParser::DoSyntaxParse() { while (m_eStatus >= FDE_CSSSyntaxStatus::None) { if (m_TextPlane.IsEOF()) { @@ -170,7 +158,7 @@ FDE_CSSSyntaxStatus CFDE_CSSSyntaxParser::DoSyntaxParse() { break; case FDE_CSSSyntaxMode::Comment: if (wch == '/' && m_TextData.GetLength() > 0 && - m_TextData.GetAt(m_TextData.GetLength() - 1) == '*') { + m_TextData.GetBuffer()[m_TextData.GetLength() - 1] == '*') { RestoreMode(); } else { m_TextData.AppendChar(wch); diff --git a/chromium/third_party/pdfium/xfa/fde/css/cfde_csssyntaxparser.h b/chromium/third_party/pdfium/xfa/fde/css/cfde_csssyntaxparser.h index a5e79d50e54..c17d84aef1e 100644 --- a/chromium/third_party/pdfium/xfa/fde/css/cfde_csssyntaxparser.h +++ b/chromium/third_party/pdfium/xfa/fde/css/cfde_csssyntaxparser.h @@ -9,6 +9,8 @@ #include <stack> +#include "core/fxcrt/fx_string.h" +#include "xfa/fde/css/cfde_cssexttextbuf.h" #include "xfa/fde/css/cfde_csstextbuf.h" #define FDE_CSSSYNTAXCHECK_AllowCharset 1 @@ -37,18 +39,17 @@ enum class FDE_CSSSyntaxStatus : uint8_t { class CFDE_CSSSyntaxParser { public: - CFDE_CSSSyntaxParser(); + CFDE_CSSSyntaxParser(const wchar_t* pBuffer, int32_t iBufferSize); + CFDE_CSSSyntaxParser(const wchar_t* pBuffer, + int32_t iBufferSize, + int32_t iTextDatSize, + bool bOnlyDeclaration); ~CFDE_CSSSyntaxParser(); - bool Init(const wchar_t* pBuffer, - int32_t iBufferSize, - int32_t iTextDatSize = 32, - bool bOnlyDeclaration = false); FDE_CSSSyntaxStatus DoSyntaxParse(); CFX_WideStringC GetCurrentString() const; protected: - void Reset(bool bOnlyDeclaration); void SwitchMode(FDE_CSSSyntaxMode eMode); int32_t SwitchToComment(); @@ -63,7 +64,7 @@ class CFDE_CSSSyntaxParser { void DisableImport() { m_dwCheck = 0; } CFDE_CSSTextBuf m_TextData; - CFDE_CSSTextBuf m_TextPlane; + CFDE_CSSExtTextBuf m_TextPlane; int32_t m_iTextDataLen; uint32_t m_dwCheck; FDE_CSSSyntaxMode m_eMode; diff --git a/chromium/third_party/pdfium/xfa/fde/css/cfde_csstextbuf.cpp b/chromium/third_party/pdfium/xfa/fde/css/cfde_csstextbuf.cpp index 2d8f93f2b3a..0d8ba2d6ce4 100644 --- a/chromium/third_party/pdfium/xfa/fde/css/cfde_csstextbuf.cpp +++ b/chromium/third_party/pdfium/xfa/fde/css/cfde_csstextbuf.cpp @@ -6,63 +6,44 @@ #include "xfa/fde/css/cfde_csstextbuf.h" -#include "third_party/base/stl_util.h" +#include "core/fxcrt/fx_memory.h" CFDE_CSSTextBuf::CFDE_CSSTextBuf() - : m_bExtBuf(false), - m_pBuffer(nullptr), - m_iBufLen(0), - m_iDatLen(0), - m_iDatPos(0) {} + : m_pBuffer(nullptr), m_iBufLen(0), m_iDatLen(0) {} CFDE_CSSTextBuf::~CFDE_CSSTextBuf() { - Reset(); + FX_Free(m_pBuffer); + m_pBuffer = nullptr; + m_iDatLen = m_iBufLen; } -void CFDE_CSSTextBuf::Reset() { - if (!m_bExtBuf) { - FX_Free(m_pBuffer); - m_pBuffer = nullptr; - } - m_iDatPos = m_iDatLen = m_iBufLen; +void CFDE_CSSTextBuf::InitWithSize(int32_t iAllocSize) { + ExpandBuf(iAllocSize); } -bool CFDE_CSSTextBuf::AttachBuffer(const wchar_t* pBuffer, int32_t iBufLen) { - Reset(); - m_pBuffer = const_cast<wchar_t*>(pBuffer); - m_iDatLen = m_iBufLen = iBufLen; - return m_bExtBuf = true; +void CFDE_CSSTextBuf::AppendChar(wchar_t wch) { + if (m_iDatLen >= m_iBufLen) + ExpandBuf(m_iBufLen * 2); + + m_pBuffer[m_iDatLen++] = wch; } -bool CFDE_CSSTextBuf::EstimateSize(int32_t iAllocSize) { - ASSERT(iAllocSize > 0); - Clear(); - m_bExtBuf = false; - return ExpandBuf(iAllocSize); +int32_t CFDE_CSSTextBuf::TrimEnd() { + while (m_iDatLen > 0 && m_pBuffer[m_iDatLen - 1] <= ' ') + --m_iDatLen; + AppendChar(0); + return --m_iDatLen; } -bool CFDE_CSSTextBuf::ExpandBuf(int32_t iDesiredSize) { - if (m_bExtBuf) - return false; - if (!m_pBuffer) - m_pBuffer = FX_Alloc(wchar_t, iDesiredSize); - else if (m_iBufLen != iDesiredSize) +void CFDE_CSSTextBuf::ExpandBuf(int32_t iDesiredSize) { + ASSERT(iDesiredSize > 0); + if (m_pBuffer && m_iBufLen == iDesiredSize) + return; + + if (m_pBuffer) m_pBuffer = FX_Realloc(wchar_t, m_pBuffer, iDesiredSize); else - return true; + m_pBuffer = FX_Alloc(wchar_t, iDesiredSize); - if (!m_pBuffer) { - m_iBufLen = 0; - return false; - } m_iBufLen = iDesiredSize; - return true; -} - -void CFDE_CSSTextBuf::Subtract(int32_t iStart, int32_t iLength) { - ASSERT(iStart >= 0 && iLength >= 0); - - iLength = pdfium::clamp(iLength, 0, m_iDatLen - iStart); - memmove(m_pBuffer, m_pBuffer + iStart, iLength * sizeof(wchar_t)); - m_iDatLen = iLength; } diff --git a/chromium/third_party/pdfium/xfa/fde/css/cfde_csstextbuf.h b/chromium/third_party/pdfium/xfa/fde/css/cfde_csstextbuf.h index 71c76f3361d..b2c17c95f88 100644 --- a/chromium/third_party/pdfium/xfa/fde/css/cfde_csstextbuf.h +++ b/chromium/third_party/pdfium/xfa/fde/css/cfde_csstextbuf.h @@ -7,9 +7,6 @@ #ifndef XFA_FDE_CSS_CFDE_CSSTEXTBUF_H_ #define XFA_FDE_CSS_CFDE_CSSTEXTBUF_H_ -#include "core/fxcrt/cfx_retain_ptr.h" -#include "core/fxcrt/cfx_seekablestreamproxy.h" -#include "core/fxcrt/fx_memory.h" #include "core/fxcrt/fx_system.h" class CFDE_CSSTextBuf { @@ -17,46 +14,22 @@ class CFDE_CSSTextBuf { CFDE_CSSTextBuf(); ~CFDE_CSSTextBuf(); - bool AttachBuffer(const wchar_t* pBuffer, int32_t iBufLen); - bool EstimateSize(int32_t iAllocSize); - bool AppendChar(wchar_t wch) { - if (m_iDatLen >= m_iBufLen && !ExpandBuf(m_iBufLen * 2)) - return false; - m_pBuffer[m_iDatLen++] = wch; - return true; - } + void InitWithSize(int32_t iAllocSize); + void AppendChar(wchar_t wch); - void Clear() { m_iDatPos = m_iDatLen = 0; } - void Reset(); + void Clear() { m_iDatLen = 0; } - int32_t TrimEnd() { - while (m_iDatLen > 0 && m_pBuffer[m_iDatLen - 1] <= ' ') - --m_iDatLen; - AppendChar(0); - return --m_iDatLen; - } - - void Subtract(int32_t iStart, int32_t iLength); - bool IsEOF() const { return m_iDatPos >= m_iDatLen; } - - wchar_t GetAt(int32_t index) const { return m_pBuffer[index]; } - wchar_t GetChar() const { return m_pBuffer[m_iDatPos]; } - wchar_t GetNextChar() const { - return (m_iDatPos + 1 >= m_iDatLen) ? 0 : m_pBuffer[m_iDatPos + 1]; - } - - void MoveNext() { m_iDatPos++; } + int32_t TrimEnd(); int32_t GetLength() const { return m_iDatLen; } const wchar_t* GetBuffer() const { return m_pBuffer; } protected: - bool ExpandBuf(int32_t iDesiredSize); - bool m_bExtBuf; + void ExpandBuf(int32_t iDesiredSize); + wchar_t* m_pBuffer; int32_t m_iBufLen; int32_t m_iDatLen; - int32_t m_iDatPos; }; #endif // XFA_FDE_CSS_CFDE_CSSTEXTBUF_H_ diff --git a/chromium/third_party/pdfium/xfa/fgas/crt/cfgas_formatstring.cpp b/chromium/third_party/pdfium/xfa/fgas/crt/cfgas_formatstring.cpp index 0c2e307b7cc..0abc86fbf34 100644 --- a/chromium/third_party/pdfium/xfa/fgas/crt/cfgas_formatstring.cpp +++ b/chromium/third_party/pdfium/xfa/fgas/crt/cfgas_formatstring.cpp @@ -21,6 +21,10 @@ #define FX_LOCALECATEGORY_ZeroHash 0x568cb500 #define FX_LOCALECATEGORY_NullHash 0x052931bb +#define FX_NUMSTYLE_Percent 0x01 +#define FX_NUMSTYLE_Exponent 0x02 +#define FX_NUMSTYLE_DotVorv 0x04 + namespace { struct FX_LOCALESUBCATEGORYINFO { @@ -49,16 +53,14 @@ const int32_t g_iFXLocaleNumSubCatCount = sizeof(g_FXLocaleNumSubCatData) / sizeof(FX_LOCALESUBCATEGORYINFO); struct FX_LOCALETIMEZONEINFO { - uint32_t uHash; + const wchar_t* name; int16_t iHour; int16_t iMinute; }; const FX_LOCALETIMEZONEINFO g_FXLocaleTimeZoneData[] = { - {FXBSTR_ID(0, 'C', 'D', 'T'), -5, 0}, {FXBSTR_ID(0, 'C', 'S', 'T'), -6, 0}, - {FXBSTR_ID(0, 'E', 'D', 'T'), -4, 0}, {FXBSTR_ID(0, 'E', 'S', 'T'), -5, 0}, - {FXBSTR_ID(0, 'M', 'D', 'T'), -6, 0}, {FXBSTR_ID(0, 'M', 'S', 'T'), -7, 0}, - {FXBSTR_ID(0, 'P', 'D', 'T'), -7, 0}, {FXBSTR_ID(0, 'P', 'S', 'T'), -8, 0}, + {L"CDT", -5, 0}, {L"CST", -6, 0}, {L"EDT", -4, 0}, {L"EST", -5, 0}, + {L"MDT", -6, 0}, {L"MST", -7, 0}, {L"PDT", -7, 0}, {L"PST", -8, 0}, }; const wchar_t gs_wsTimeSymbols[] = L"hHkKMSFAzZ"; @@ -74,14 +76,14 @@ int32_t ParseTimeZone(const wchar_t* pStr, int32_t iLen, FX_TIMEZONE* tz) { int32_t iStart = 1; int32_t iEnd = iStart + 2; while (iStart < iLen && iStart < iEnd) - tz->tzHour = tz->tzHour * 10 + pStr[iStart++] - '0'; + tz->tzHour = tz->tzHour * 10 + FXSYS_DecimalCharToInt(pStr[iStart++]); if (iStart < iLen && pStr[iStart] == ':') iStart++; iEnd = iStart + 2; while (iStart < iLen && iStart < iEnd) - tz->tzMinute = tz->tzMinute * 10 + pStr[iStart++] - '0'; + tz->tzMinute = tz->tzMinute * 10 + FXSYS_DecimalCharToInt(pStr[iStart++]); if (pStr[0] == '-') tz->tzHour = -tz->tzHour; @@ -90,72 +92,69 @@ int32_t ParseTimeZone(const wchar_t* pStr, int32_t iLen, FX_TIMEZONE* tz) { } int32_t ConvertHex(int32_t iKeyValue, wchar_t ch) { - if (std::iswdigit(ch)) - return iKeyValue * 16 + ch - '0'; - if (FXSYS_islower(ch)) - return iKeyValue * 16 + ch - 'a' + 10; - if (FXSYS_isupper(ch)) - return iKeyValue * 16 + ch - 'A' + 10; + if (FXSYS_isHexDigit(ch)) + return iKeyValue * 16 + FXSYS_HexCharToInt(ch); return iKeyValue; } CFX_WideString GetLiteralText(const wchar_t* pStrPattern, - int32_t& iPattern, + int32_t* iPattern, int32_t iLenPattern) { CFX_WideString wsOutput; - if (pStrPattern[iPattern] != '\'') { + if (pStrPattern[*iPattern] != '\'') return wsOutput; - } - iPattern++; + + (*iPattern)++; int32_t iQuote = 1; - while (iPattern < iLenPattern) { - if (pStrPattern[iPattern] == '\'') { + while (*iPattern < iLenPattern) { + if (pStrPattern[*iPattern] == '\'') { iQuote++; - if ((iPattern + 1 >= iLenPattern) || - ((pStrPattern[iPattern + 1] != '\'') && (iQuote % 2 == 0))) { + if ((*iPattern + 1 >= iLenPattern) || + ((pStrPattern[*iPattern + 1] != '\'') && (iQuote % 2 == 0))) { break; } iQuote++; - iPattern++; - } else if (pStrPattern[iPattern] == '\\' && (iPattern + 1 < iLenPattern) && - pStrPattern[iPattern + 1] == 'u') { + (*iPattern)++; + } else if (pStrPattern[*iPattern] == '\\' && + (*iPattern + 1 < iLenPattern) && + pStrPattern[*iPattern + 1] == 'u') { int32_t iKeyValue = 0; - iPattern += 2; + *iPattern += 2; int32_t i = 0; - while (iPattern < iLenPattern && i++ < 4) { - wchar_t ch = pStrPattern[iPattern++]; + while (*iPattern < iLenPattern && i++ < 4) { + wchar_t ch = pStrPattern[(*iPattern)++]; iKeyValue = ConvertHex(iKeyValue, ch); } - if (iKeyValue != 0) { - wsOutput += (wchar_t)(iKeyValue & 0x0000FFFF); - } + if (iKeyValue != 0) + wsOutput += static_cast<wchar_t>(iKeyValue & 0x0000FFFF); + continue; } - wsOutput += pStrPattern[iPattern++]; + wsOutput += pStrPattern[(*iPattern)++]; } return wsOutput; } CFX_WideString GetLiteralTextReverse(const wchar_t* pStrPattern, - int32_t& iPattern) { + int32_t* iPattern) { CFX_WideString wsOutput; - if (pStrPattern[iPattern] != '\'') { + if (pStrPattern[*iPattern] != '\'') return wsOutput; - } - iPattern--; + + (*iPattern)--; int32_t iQuote = 1; - while (iPattern >= 0) { - if (pStrPattern[iPattern] == '\'') { + while (*iPattern >= 0) { + if (pStrPattern[*iPattern] == '\'') { iQuote++; - if (iPattern - 1 >= 0 || - ((pStrPattern[iPattern - 1] != '\'') && (iQuote % 2 == 0))) { + if (*iPattern - 1 >= 0 || + ((pStrPattern[*iPattern - 1] != '\'') && (iQuote % 2 == 0))) { break; } iQuote++; - iPattern--; - } else if (pStrPattern[iPattern] == '\\' && - pStrPattern[iPattern + 1] == 'u') { - iPattern--; + (*iPattern)--; + } else if (pStrPattern[*iPattern] == '\\' && + pStrPattern[*iPattern + 1] == 'u') { + (*iPattern)--; int32_t iKeyValue = 0; int32_t iLen = wsOutput.GetLength(); int32_t i = 1; @@ -169,254 +168,188 @@ CFX_WideString GetLiteralTextReverse(const wchar_t* pStrPattern, } continue; } - wsOutput = pStrPattern[iPattern--] + wsOutput; + wsOutput = pStrPattern[(*iPattern)--] + wsOutput; } return wsOutput; } bool GetNumericDotIndex(const CFX_WideString& wsNum, const CFX_WideString& wsDotSymbol, - int32_t& iDotIndex) { + int32_t* iDotIndex) { int32_t ccf = 0; int32_t iLenf = wsNum.GetLength(); const wchar_t* pStr = wsNum.c_str(); int32_t iLenDot = wsDotSymbol.GetLength(); while (ccf < iLenf) { if (pStr[ccf] == '\'') { - GetLiteralText(pStr, ccf, iLenf); + GetLiteralText(pStr, &ccf, iLenf); } else if (ccf + iLenDot <= iLenf && !wcsncmp(pStr + ccf, wsDotSymbol.c_str(), iLenDot)) { - iDotIndex = ccf; + *iDotIndex = ccf; return true; } ccf++; } - iDotIndex = wsNum.Find('.'); - if (iDotIndex < 0) { - iDotIndex = iLenf; - return false; + *iDotIndex = wsNum.Find('.'); + if (*iDotIndex >= 0) + return true; + + *iDotIndex = iLenf; + return false; +} + +bool ExtractCountDigits(const wchar_t* str, + int len, + int count, + int* cc, + uint32_t* value) { + for (int i = count; i > 0; --i) { + if (*cc >= len) + return false; + if (!FXSYS_isDecimalDigit(str[*cc])) + return false; + *value = *value * 10 + FXSYS_DecimalCharToInt(str[(*cc)++]); } return true; } +bool ExtractCountDigitsWithOptional(const wchar_t* str, + int len, + int count, + int* cc, + uint32_t* value) { + if (!ExtractCountDigits(str, len, count, cc, value)) + return false; + ExtractCountDigits(str, len, 1, cc, value); + return true; +} + bool ParseLocaleDate(const CFX_WideString& wsDate, const CFX_WideString& wsDatePattern, IFX_Locale* pLocale, CFX_DateTime* datetime, - int32_t& cc) { - int32_t year = 1900; - int32_t month = 1; - int32_t day = 1; + int32_t* cc) { + uint32_t year = 1900; + uint32_t month = 1; + uint32_t day = 1; int32_t ccf = 0; const wchar_t* str = wsDate.c_str(); int32_t len = wsDate.GetLength(); const wchar_t* strf = wsDatePattern.c_str(); int32_t lenf = wsDatePattern.GetLength(); CFX_WideStringC wsDateSymbols(gs_wsDateSymbols); - while (cc < len && ccf < lenf) { + while (*cc < len && ccf < lenf) { if (strf[ccf] == '\'') { - CFX_WideString wsLiteral = GetLiteralText(strf, ccf, lenf); + CFX_WideString wsLiteral = GetLiteralText(strf, &ccf, lenf); int32_t iLiteralLen = wsLiteral.GetLength(); - if (cc + iLiteralLen > len || - wcsncmp(str + cc, wsLiteral.c_str(), iLiteralLen)) { + if (*cc + iLiteralLen > len || + wcsncmp(str + *cc, wsLiteral.c_str(), iLiteralLen)) { return false; } - cc += iLiteralLen; + *cc += iLiteralLen; ccf++; continue; } else if (wsDateSymbols.Find(strf[ccf]) == -1) { - if (strf[ccf] != str[cc]) + if (strf[ccf] != str[*cc]) return false; - cc++; + (*cc)++; ccf++; continue; } - uint32_t dwSymbolNum = 1; - wchar_t dwCharSymbol = strf[ccf++]; - while (ccf < lenf && strf[ccf] == dwCharSymbol) { - ccf++; - dwSymbolNum++; - } - uint32_t dwSymbol = (dwCharSymbol << 8) | (dwSymbolNum + '0'); - if (dwSymbol == FXBSTR_ID(0, 0, 'D', '1')) { - if (!FXSYS_isDecimalDigit(str[cc])) { - return false; - } - day = str[cc++] - '0'; - if (cc < len && FXSYS_isDecimalDigit(str[cc])) { - day = day * 10 + str[cc++] - '0'; - } - } else if (dwSymbol == FXBSTR_ID(0, 0, 'D', '2')) { - if (!FXSYS_isDecimalDigit(str[cc])) { - return false; - } - day = str[cc++] - '0'; - if (cc < len) { - day = day * 10 + str[cc++] - '0'; - } - } else if (dwSymbol == FXBSTR_ID(0, 0, 'J', '1')) { - int i = 0; - while (cc < len && i < 3 && FXSYS_isDecimalDigit(str[cc])) { - cc++; - i++; - } - } else if (dwSymbol == FXBSTR_ID(0, 0, 'J', '3')) { - cc += 3; - } else if (dwSymbol == FXBSTR_ID(0, 0, 'M', '1')) { - if (!FXSYS_isDecimalDigit(str[cc])) { + + CFX_WideString symbol; + symbol.Reserve(4); + symbol += strf[ccf++]; + while (ccf < lenf && strf[ccf] == symbol[0]) + symbol += strf[ccf++]; + + if (symbol == L"D" || symbol == L"DD") { + day = 0; + if (!ExtractCountDigitsWithOptional(str, len, 1, cc, &day)) return false; - } - month = str[cc++] - '0'; - if (cc < len && FXSYS_isDecimalDigit(str[cc])) { - month = month * 10 + str[cc++] - '0'; - } - } else if (dwSymbol == FXBSTR_ID(0, 0, 'M', '2')) { - if (!FXSYS_isDecimalDigit(str[cc])) { + } else if (symbol == L"J") { + uint32_t val = 0; + ExtractCountDigits(str, len, 3, cc, &val); + } else if (symbol == L"M" || symbol == L"MM") { + month = 0; + if (!ExtractCountDigitsWithOptional(str, len, 1, cc, &month)) return false; - } - month = str[cc++] - '0'; - if (cc < len) { - month = month * 10 + str[cc++] - '0'; - } - } else if (dwSymbol == FXBSTR_ID(0, 0, 'M', '3')) { - CFX_WideString wsMonthNameAbbr; - uint16_t i = 0; - for (; i < 12; i++) { - wsMonthNameAbbr = pLocale->GetMonthName(i, true); - if (wsMonthNameAbbr.IsEmpty()) - continue; - if (!wcsncmp(wsMonthNameAbbr.c_str(), str + cc, - wsMonthNameAbbr.GetLength())) { - break; - } - } - if (i < 12) { - cc += wsMonthNameAbbr.GetLength(); - month = i + 1; - } - } else if (dwSymbol == FXBSTR_ID(0, 0, 'M', '4')) { - CFX_WideString wsMonthName; - uint16_t i = 0; - for (; i < 12; i++) { - wsMonthName = pLocale->GetMonthName(i, false); + } else if (symbol == L"MMM" || symbol == L"MMMM") { + for (uint16_t i = 0; i < 12; i++) { + CFX_WideString wsMonthName = pLocale->GetMonthName(i, symbol == L"MMM"); if (wsMonthName.IsEmpty()) continue; - if (!wcsncmp(wsMonthName.c_str(), str + cc, wsMonthName.GetLength())) { + if (!wcsncmp(wsMonthName.c_str(), str + *cc, wsMonthName.GetLength())) { + *cc += wsMonthName.GetLength(); + month = i + 1; break; } } - if (i < 12) { - cc += wsMonthName.GetLength(); - month = i + 1; - } - } else if (dwSymbol == FXBSTR_ID(0, 0, 'E', '1')) { - cc += 1; - } else if (dwSymbol == FXBSTR_ID(0, 0, 'E', '3')) { - CFX_WideString wsDayNameAbbr; - uint16_t i = 0; - for (; i < 7; i++) { - wsDayNameAbbr = pLocale->GetDayName(i, true); - if (wsDayNameAbbr.IsEmpty()) + } else if (symbol == L"EEE" || symbol == L"EEEE") { + for (uint16_t i = 0; i < 7; i++) { + CFX_WideString wsDayName = pLocale->GetDayName(i, symbol == L"EEE"); + if (wsDayName.IsEmpty()) continue; - if (!wcsncmp(wsDayNameAbbr.c_str(), str + cc, - wsDayNameAbbr.GetLength())) { + if (!wcsncmp(wsDayName.c_str(), str + *cc, wsDayName.GetLength())) { + *cc += wsDayName.GetLength(); break; } } - if (i < 12) { - cc += wsDayNameAbbr.GetLength(); - } - } else if (dwSymbol == FXBSTR_ID(0, 0, 'E', '4')) { - CFX_WideString wsDayName; - int32_t i = 0; - for (; i < 7; i++) { - wsDayName = pLocale->GetDayName(i, false); - if (wsDayName == L"") - continue; - if (!wcsncmp(wsDayName.c_str(), str + cc, wsDayName.GetLength())) { - break; - } - } - if (i < 12) { - cc += wsDayName.GetLength(); - } - } else if (dwSymbol == FXBSTR_ID(0, 0, 'e', '1')) { - cc += 1; - } else if (dwSymbol == FXBSTR_ID(0, 0, 'G', '1')) { - cc += 2; - } else if (dwSymbol == FXBSTR_ID(0, 0, 'Y', '2')) { - if (cc + 2 > len) { + } else if (symbol == L"YY" || symbol == L"YYYY") { + if (*cc + symbol.GetLength() > len) return false; - } - if (!FXSYS_isDecimalDigit(str[cc])) { - return false; - } - year = str[cc++] - '0'; - if (cc >= len || !FXSYS_isDecimalDigit(str[cc])) { - return false; - } - year = year * 10 + str[cc++] - '0'; - if (year <= 29) { - year += 2000; - } else { - year += 1900; - } - } else if (dwSymbol == FXBSTR_ID(0, 0, 'Y', '4')) { - int i = 0; + year = 0; - if (cc + 4 > len) { + if (!ExtractCountDigits(str, len, symbol.GetLength(), cc, &year)) return false; + if (symbol == L"YY") { + if (year <= 29) + year += 2000; + else + year += 1900; } - while (i < 4) { - if (!FXSYS_isDecimalDigit(str[cc])) { - return false; - } - year = year * 10 + str[cc] - '0'; - cc++; - i++; - } - } else if (dwSymbol == FXBSTR_ID(0, 0, 'w', '1')) { - cc += 1; - } else if (dwSymbol == FXBSTR_ID(0, 0, 'W', '2')) { - cc += 2; + } else if (symbol == L"G") { + *cc += 2; + } else if (symbol == L"JJJ" || symbol == L"E" || symbol == L"e" || + symbol == L"w" || symbol == L"WW") { + *cc += symbol.GetLength(); } } - if (cc < len) + if (*cc < len) return false; datetime->SetDate(year, month, day); - return !!cc; + return !!(*cc); } -void ResolveZone(uint8_t& wHour, - uint8_t& wMinute, - FX_TIMEZONE tzDiff, - IFX_Locale* pLocale) { - int32_t iMinuteDiff = wHour * 60 + wMinute; +void ResolveZone(FX_TIMEZONE tzDiff, + IFX_Locale* pLocale, + uint32_t* wHour, + uint32_t* wMinute) { + int32_t iMinuteDiff = *wHour * 60 + *wMinute; FX_TIMEZONE tzLocale = pLocale->GetTimeZone(); iMinuteDiff += tzLocale.tzHour * 60 + (tzLocale.tzHour < 0 ? -tzLocale.tzMinute : tzLocale.tzMinute); iMinuteDiff -= tzDiff.tzHour * 60 + (tzDiff.tzHour < 0 ? -tzDiff.tzMinute : tzDiff.tzMinute); - while (iMinuteDiff > 1440) { - iMinuteDiff -= 1440; - } - while (iMinuteDiff < 0) { + + iMinuteDiff %= 1440; + if (iMinuteDiff < 0) iMinuteDiff += 1440; - } - wHour = iMinuteDiff / 60; - wMinute = iMinuteDiff % 60; + + *wHour = iMinuteDiff / 60; + *wMinute = iMinuteDiff % 60; } bool ParseLocaleTime(const CFX_WideString& wsTime, const CFX_WideString& wsTimePattern, IFX_Locale* pLocale, CFX_DateTime* datetime, - int32_t& cc) { - uint8_t hour = 0; - uint8_t minute = 0; - uint8_t second = 0; - uint16_t millisecond = 0; + int32_t* cc) { + uint32_t hour = 0; + uint32_t minute = 0; + uint32_t second = 0; + uint32_t millisecond = 0; int32_t ccf = 0; const wchar_t* str = wsTime.c_str(); int len = wsTime.GetLength(); @@ -425,185 +358,132 @@ bool ParseLocaleTime(const CFX_WideString& wsTime, bool bHasA = false; bool bPM = false; CFX_WideStringC wsTimeSymbols(gs_wsTimeSymbols); - while (cc < len && ccf < lenf) { + while (*cc < len && ccf < lenf) { if (strf[ccf] == '\'') { - CFX_WideString wsLiteral = GetLiteralText(strf, ccf, lenf); + CFX_WideString wsLiteral = GetLiteralText(strf, &ccf, lenf); int32_t iLiteralLen = wsLiteral.GetLength(); - if (cc + iLiteralLen > len || - wcsncmp(str + cc, wsLiteral.c_str(), iLiteralLen)) { + if (*cc + iLiteralLen > len || + wcsncmp(str + *cc, wsLiteral.c_str(), iLiteralLen)) { return false; } - cc += iLiteralLen; + *cc += iLiteralLen; ccf++; continue; - } else if (wsTimeSymbols.Find(strf[ccf]) == -1) { - if (strf[ccf] != str[cc]) + } + if (wsTimeSymbols.Find(strf[ccf]) == -1) { + if (strf[ccf] != str[*cc]) return false; - cc++; + (*cc)++; ccf++; continue; } - uint32_t dwSymbolNum = 1; - wchar_t dwCharSymbol = strf[ccf++]; - while (ccf < lenf && strf[ccf] == dwCharSymbol) { - ccf++; - dwSymbolNum++; - } - uint32_t dwSymbol = (dwCharSymbol << 8) | (dwSymbolNum + '0'); - if (dwSymbol == FXBSTR_ID(0, 0, 'k', '1') || - dwSymbol == FXBSTR_ID(0, 0, 'H', '1') || - dwSymbol == FXBSTR_ID(0, 0, 'h', '1') || - dwSymbol == FXBSTR_ID(0, 0, 'K', '1')) { - if (!FXSYS_isDecimalDigit(str[cc])) { + + CFX_WideString symbol; + symbol.Reserve(4); + symbol += strf[ccf++]; + while (ccf < lenf && strf[ccf] == symbol[0]) + symbol += strf[ccf++]; + + if (symbol == L"k" || symbol == L"K" || symbol == L"h" || symbol == L"H") { + hour = 0; + if (!ExtractCountDigitsWithOptional(str, len, 1, cc, &hour)) return false; - } - hour = str[cc++] - '0'; - if (cc < len && FXSYS_isDecimalDigit(str[cc])) { - hour = hour * 10 + str[cc++] - '0'; - } - if (dwSymbol == FXBSTR_ID(0, 0, 'K', '1') && hour == 24) { + if (symbol == L"K" && hour == 24) hour = 0; - } - } else if (dwSymbol == FXBSTR_ID(0, 0, 'k', '2') || - dwSymbol == FXBSTR_ID(0, 0, 'H', '2') || - dwSymbol == FXBSTR_ID(0, 0, 'h', '2') || - dwSymbol == FXBSTR_ID(0, 0, 'K', '2')) { - if (!FXSYS_isDecimalDigit(str[cc])) { - return false; - } - hour = str[cc++] - '0'; - if (cc >= len) { - return false; - } - if (!FXSYS_isDecimalDigit(str[cc])) { + } else if (symbol == L"kk" || symbol == L"KK" || symbol == L"hh" || + symbol == L"HH") { + hour = 0; + if (!ExtractCountDigits(str, len, 2, cc, &hour)) return false; - } - hour = hour * 10 + str[cc++] - '0'; - if (dwSymbol == FXBSTR_ID(0, 0, 'K', '2') && hour == 24) { + if (symbol == L"KK" && hour == 24) hour = 0; - } - } else if (dwSymbol == FXBSTR_ID(0, 0, 'M', '1')) { - if (!FXSYS_isDecimalDigit(str[cc])) { - return false; - } - minute = str[cc++] - '0'; - if (cc < len && FXSYS_isDecimalDigit(str[cc])) { - minute = minute * 10 + str[cc++] - '0'; - } - } else if (dwSymbol == FXBSTR_ID(0, 0, 'M', '2')) { - if (!FXSYS_isDecimalDigit(str[cc])) { - return false; - } - minute = str[cc++] - '0'; - if (cc >= len) { - return false; - } - if (!FXSYS_isDecimalDigit(str[cc])) { + } else if (symbol == L"M") { + minute = 0; + if (!ExtractCountDigitsWithOptional(str, len, 1, cc, &minute)) return false; - } - minute = minute * 10 + str[cc++] - '0'; - } else if (dwSymbol == FXBSTR_ID(0, 0, 'S', '1')) { - if (!FXSYS_isDecimalDigit(str[cc])) { + } else if (symbol == L"MM") { + minute = 0; + if (!ExtractCountDigits(str, len, 2, cc, &minute)) return false; - } - second = str[cc++] - '0'; - if (cc < len && FXSYS_isDecimalDigit(str[cc])) { - second = second * 10 + str[cc++] - '0'; - } - } else if (dwSymbol == FXBSTR_ID(0, 0, 'S', '2')) { - if (!FXSYS_isDecimalDigit(str[cc])) { - return false; - } - second = str[cc++] - '0'; - if (cc >= len) { + } else if (symbol == L"S") { + second = 0; + if (!ExtractCountDigitsWithOptional(str, len, 1, cc, &second)) return false; - } - if (!FXSYS_isDecimalDigit(str[cc])) { + } else if (symbol == L"SS") { + second = 0; + if (!ExtractCountDigits(str, len, 2, cc, &second)) return false; - } - second = second * 10 + str[cc++] - '0'; - } else if (dwSymbol == FXBSTR_ID(0, 0, 'F', '3')) { - if (cc + 3 >= len) { + } else if (symbol == L"FFF") { + millisecond = 0; + if (!ExtractCountDigits(str, len, 3, cc, &millisecond)) return false; - } - int i = 0; - while (i < 3) { - if (!FXSYS_isDecimalDigit(str[cc])) { - return false; - } - millisecond = millisecond * 10 + str[cc++] - '0'; - i++; - } - } else if (dwSymbol == FXBSTR_ID(0, 0, 'A', '1')) { + } else if (symbol == L"A") { CFX_WideString wsAM = pLocale->GetMeridiemName(true); CFX_WideString wsPM = pLocale->GetMeridiemName(false); - if ((cc + wsAM.GetLength() <= len) && - (CFX_WideStringC(str + cc, wsAM.GetLength()) == wsAM)) { - cc += wsAM.GetLength(); + if ((*cc + wsAM.GetLength() <= len) && + (CFX_WideStringC(str + *cc, wsAM.GetLength()) == wsAM)) { + *cc += wsAM.GetLength(); bHasA = true; - } else if ((cc + wsPM.GetLength() <= len) && - (CFX_WideStringC(str + cc, wsPM.GetLength()) == wsPM)) { - cc += wsPM.GetLength(); + } else if ((*cc + wsPM.GetLength() <= len) && + (CFX_WideStringC(str + *cc, wsPM.GetLength()) == wsPM)) { + *cc += wsPM.GetLength(); bHasA = true; bPM = true; } - } else if (dwSymbol == FXBSTR_ID(0, 0, 'Z', '1')) { - if (cc + 3 > len) { + } else if (symbol == L"Z") { + if (*cc + 3 > len) continue; - } - uint32_t dwHash = str[cc++]; - dwHash = (dwHash << 8) | str[cc++]; - dwHash = (dwHash << 8) | str[cc++]; - if (dwHash == FXBSTR_ID(0, 'G', 'M', 'T')) { + + CFX_WideString tz(str[(*cc)++]); + tz += str[(*cc)++]; + tz += str[(*cc)++]; + if (tz == L"GMT") { FX_TIMEZONE tzDiff; tzDiff.tzHour = 0; tzDiff.tzMinute = 0; - if (cc < len && (str[cc] == '-' || str[cc] == '+')) - cc += ParseTimeZone(str + cc, len - cc, &tzDiff); + if (*cc < len && (str[*cc] == '-' || str[*cc] == '+')) + *cc += ParseTimeZone(str + *cc, len - *cc, &tzDiff); - ResolveZone(hour, minute, tzDiff, pLocale); + ResolveZone(tzDiff, pLocale, &hour, &minute); } else { - const FX_LOCALETIMEZONEINFO* pEnd = - g_FXLocaleTimeZoneData + FX_ArraySize(g_FXLocaleTimeZoneData); - const FX_LOCALETIMEZONEINFO* pTimeZoneInfo = - std::lower_bound(g_FXLocaleTimeZoneData, pEnd, dwHash, - [](const FX_LOCALETIMEZONEINFO& info, - uint32_t hash) { return info.uHash < hash; }); - if (pTimeZoneInfo < pEnd && dwHash == pTimeZoneInfo->uHash) { - hour += pTimeZoneInfo->iHour; - minute += pTimeZoneInfo->iHour > 0 ? pTimeZoneInfo->iMinute - : -pTimeZoneInfo->iMinute; + // Search the timezone list. There are only 8 of them, so linear scan. + for (size_t i = 0; i < FX_ArraySize(g_FXLocaleTimeZoneData); ++i) { + const FX_LOCALETIMEZONEINFO& info = g_FXLocaleTimeZoneData[i]; + if (tz != info.name) + continue; + + hour += info.iHour; + minute += info.iHour > 0 ? info.iMinute : -info.iMinute; + break; } } - } else if (dwSymbol == FXBSTR_ID(0, 0, 'z', '1')) { - if (str[cc] != 'Z') { + } else if (symbol == L"z") { + if (str[*cc] != 'Z') { FX_TIMEZONE tzDiff; - cc += ParseTimeZone(str + cc, len - cc, &tzDiff); - ResolveZone(hour, minute, tzDiff, pLocale); + *cc += ParseTimeZone(str + *cc, len - *cc, &tzDiff); + ResolveZone(tzDiff, pLocale, &hour, &minute); } else { - cc++; + (*cc)++; } } } if (bHasA) { if (bPM) { hour += 12; - if (hour == 24) { + if (hour == 24) hour = 12; - } } else { - if (hour == 12) { + if (hour == 12) hour = 0; - } } } datetime->SetTime(hour, minute, second, millisecond); - return !!cc; + return !!(*cc); } int32_t GetNumTrailingLimit(const CFX_WideString& wsFormat, int iDotPos, - bool& bTrimTailZeros) { + bool* bTrimTailZeros) { if (iDotPos < 0) return 0; @@ -613,25 +493,37 @@ int32_t GetNumTrailingLimit(const CFX_WideString& wsFormat, wchar_t wc = wsFormat[iDotPos]; if (wc == L'z' || wc == L'9' || wc == 'Z') { iTreading++; - bTrimTailZeros = wc != L'9'; + *bTrimTailZeros = wc != L'9'; } } return iTreading; } +bool IsLeapYear(uint32_t year) { + return (year % 4 == 0 && year % 100 != 0) || year % 400 == 0; +} + +bool MonthHas30Days(uint32_t month) { + return month == 4 || month == 6 || month == 9 || month == 11; +} + +bool MonthHas31Days(uint32_t month) { + return month != 2 && !MonthHas30Days(month); +} + +// |month| is 1-based. e.g. 1 means January. uint16_t GetSolarMonthDays(uint16_t year, uint16_t month) { - if (month % 2) - return 31; if (month == 2) return FX_IsLeapYear(year) ? 29 : 28; - return 30; + + return MonthHas30Days(month) ? 30 : 31; } uint16_t GetWeekDay(uint16_t year, uint16_t month, uint16_t day) { - uint16_t g_month_day[] = {0, 3, 3, 6, 1, 4, 6, 2, 5, 0, 3, 5}; + static const uint16_t month_day[] = {0, 3, 3, 6, 1, 4, 6, 2, 5, 0, 3, 5}; uint16_t nDays = (year - 1) % 7 + (year - 1) / 4 - (year - 1) / 100 + (year - 1) / 400; - nDays += g_month_day[month - 1] + day; + nDays += month_day[month - 1] + day; if (FX_IsLeapYear(year) && month > 2) nDays++; return nDays % 7; @@ -662,11 +554,16 @@ uint16_t GetWeekOfYear(uint16_t year, uint16_t month, uint16_t day) { return week_index; } -bool DateFormat(const CFX_WideString& wsDatePattern, - IFX_Locale* pLocale, - const CFX_DateTime& datetime, - CFX_WideString& wsResult) { - bool bRet = true; +CFX_WideString NumToString(size_t fmt_size, int32_t value) { + CFX_WideString str; + str.Format(fmt_size == 1 ? L"%d" : fmt_size == 2 ? L"%02d" : L"%03d", value); + return str; +} + +CFX_WideString DateFormat(const CFX_WideString& wsDatePattern, + IFX_Locale* pLocale, + const CFX_DateTime& datetime) { + CFX_WideString wsResult; int32_t year = datetime.GetYear(); uint8_t month = datetime.GetMonth(); uint8_t day = datetime.GetDay(); @@ -676,106 +573,59 @@ bool DateFormat(const CFX_WideString& wsDatePattern, CFX_WideStringC wsDateSymbols(gs_wsDateSymbols); while (ccf < lenf) { if (strf[ccf] == '\'') { - wsResult += GetLiteralText(strf, ccf, lenf); + wsResult += GetLiteralText(strf, &ccf, lenf); ccf++; continue; - } else if (wsDateSymbols.Find(strf[ccf]) == -1) { + } + if (wsDateSymbols.Find(strf[ccf]) == -1) { wsResult += strf[ccf++]; continue; } - uint32_t dwSymbolNum = 1; - wchar_t dwCharSymbol = strf[ccf++]; - while (ccf < lenf && strf[ccf] == dwCharSymbol) { - ccf++; - dwSymbolNum++; - } - uint32_t dwSymbol = (dwCharSymbol << 8) | (dwSymbolNum + '0'); - if (dwSymbol == FXBSTR_ID(0, 0, 'D', '1')) { - CFX_WideString wsDay; - wsDay.Format(L"%d", day); - wsResult += wsDay; - } else if (dwSymbol == FXBSTR_ID(0, 0, 'D', '2')) { - CFX_WideString wsDay; - wsDay.Format(L"%02d", day); - wsResult += wsDay; - } else if (dwSymbol == FXBSTR_ID(0, 0, 'J', '1')) { - uint16_t nDays = 0; - for (int i = 1; i < month; i++) { - nDays += GetSolarMonthDays(year, i); - } - nDays += day; - CFX_WideString wsDays; - wsDays.Format(L"%d", nDays); - wsResult += wsDays; - } else if (dwSymbol == FXBSTR_ID(0, 0, 'J', '3')) { + + CFX_WideString symbol; + symbol.Reserve(4); + symbol += strf[ccf++]; + while (ccf < lenf && strf[ccf] == symbol[0]) + symbol += strf[ccf++]; + + if (symbol == L"D" || symbol == L"DD") { + wsResult += NumToString(symbol.GetLength(), day); + } else if (symbol == L"J" || symbol == L"JJJ") { uint16_t nDays = 0; - for (int i = 1; i < month; i++) { + for (int i = 1; i < month; i++) nDays += GetSolarMonthDays(year, i); - } nDays += day; - CFX_WideString wsDays; - wsDays.Format(L"%03d", nDays); - wsResult += wsDays; - } else if (dwSymbol == FXBSTR_ID(0, 0, 'M', '1')) { - CFX_WideString wsMonth; - wsMonth.Format(L"%d", month); - wsResult += wsMonth; - } else if (dwSymbol == FXBSTR_ID(0, 0, 'M', '2')) { - CFX_WideString wsMonth; - wsMonth.Format(L"%02d", month); - wsResult += wsMonth; - } else if (dwSymbol == FXBSTR_ID(0, 0, 'M', '3')) { - wsResult += pLocale->GetMonthName(month - 1, true); - } else if (dwSymbol == FXBSTR_ID(0, 0, 'M', '4')) { - wsResult += pLocale->GetMonthName(month - 1, false); - } else if (dwSymbol == FXBSTR_ID(0, 0, 'E', '1')) { + wsResult += NumToString(symbol.GetLength(), nDays); + } else if (symbol == L"M" || symbol == L"MM") { + wsResult += NumToString(symbol.GetLength(), month); + } else if (symbol == L"MMM" || symbol == L"MMMM") { + wsResult += pLocale->GetMonthName(month - 1, symbol == L"MMM"); + } else if (symbol == L"E" || symbol == L"e") { uint16_t wWeekDay = GetWeekDay(year, month, day); - CFX_WideString wsWeekDay; - wsWeekDay.Format(L"%d", wWeekDay + 1); - wsResult += wsWeekDay; - } else if (dwSymbol == FXBSTR_ID(0, 0, 'E', '3')) { - uint16_t wWeekDay = GetWeekDay(year, month, day); - wsResult += pLocale->GetDayName(wWeekDay, true); - } else if (dwSymbol == FXBSTR_ID(0, 0, 'E', '4')) { - uint16_t wWeekDay = GetWeekDay(year, month, day); - if (pLocale) - wsResult += pLocale->GetDayName(wWeekDay, false); - } else if (dwSymbol == FXBSTR_ID(0, 0, 'e', '1')) { - uint16_t wWeekDay = GetWeekDay(year, month, day); - CFX_WideString wsWeekDay; - wsWeekDay.Format(L"%d", wWeekDay ? wWeekDay : 7); - wsResult += wsWeekDay; - } else if (dwSymbol == FXBSTR_ID(0, 0, 'G', '1')) { - wsResult += pLocale->GetEraName(year < 0); - } else if (dwSymbol == FXBSTR_ID(0, 0, 'Y', '2')) { - CFX_WideString wsYear; - wsYear.Format(L"%02d", year % 100); - wsResult += wsYear; - } else if (dwSymbol == FXBSTR_ID(0, 0, 'Y', '4')) { - CFX_WideString wsYear; - wsYear.Format(L"%d", year); - wsResult += wsYear; - } else if (dwSymbol == FXBSTR_ID(0, 0, 'w', '1')) { - uint16_t week_index = GetWeekOfMonth(year, month, day); - CFX_WideString wsWeekInMonth; - wsWeekInMonth.Format(L"%d", week_index); - wsResult += wsWeekInMonth; - } else if (dwSymbol == FXBSTR_ID(0, 0, 'W', '2')) { - uint16_t week_index = GetWeekOfYear(year, month, day); - CFX_WideString wsWeekInYear; - wsWeekInYear.Format(L"%02d", week_index); - wsResult += wsWeekInYear; - } - } - return bRet; + wsResult += NumToString( + 1, symbol == L"E" ? wWeekDay + 1 : (wWeekDay ? wWeekDay : 7)); + } else if (symbol == L"EEE" || symbol == L"EEEE") { + wsResult += + pLocale->GetDayName(GetWeekDay(year, month, day), symbol == L"EEE"); + } else if (symbol == L"G") { + wsResult += pLocale->GetEraName(year > 0); + } else if (symbol == L"YY") { + wsResult += NumToString(2, year % 100); + } else if (symbol == L"YYYY") { + wsResult += NumToString(1, year); + } else if (symbol == L"w") { + wsResult += NumToString(1, GetWeekOfMonth(year, month, day)); + } else if (symbol == L"WW") { + wsResult += NumToString(2, GetWeekOfYear(year, month, day)); + } + } + return wsResult; } -bool TimeFormat(const CFX_WideString& wsTimePattern, - IFX_Locale* pLocale, - const CFX_DateTime& datetime, - CFX_WideString& wsResult) { - bool bGMT = false; - bool bRet = true; +CFX_WideString TimeFormat(const CFX_WideString& wsTimePattern, + IFX_Locale* pLocale, + const CFX_DateTime& datetime) { + CFX_WideString wsResult; uint8_t hour = datetime.GetHour(); uint8_t minute = datetime.GetMinute(); uint8_t second = datetime.GetSecond(); @@ -786,106 +636,54 @@ bool TimeFormat(const CFX_WideString& wsTimePattern, uint16_t wHour = hour; bool bPM = false; if (wsTimePattern.Find('A') != -1) { - if (wHour >= 12) { + if (wHour >= 12) bPM = true; - } } + CFX_WideStringC wsTimeSymbols(gs_wsTimeSymbols); while (ccf < lenf) { if (strf[ccf] == '\'') { - wsResult += GetLiteralText(strf, ccf, lenf); + wsResult += GetLiteralText(strf, &ccf, lenf); ccf++; continue; - } else if (wsTimeSymbols.Find(strf[ccf]) == -1) { + } + if (wsTimeSymbols.Find(strf[ccf]) == -1) { wsResult += strf[ccf++]; continue; } - uint32_t dwSymbolNum = 1; - wchar_t dwCharSymbol = strf[ccf++]; - while (ccf < lenf && strf[ccf] == dwCharSymbol) { - ccf++; - dwSymbolNum++; - } - uint32_t dwSymbol = (dwCharSymbol << 8) | (dwSymbolNum + '0'); - if (dwSymbol == FXBSTR_ID(0, 0, 'h', '1')) { - if (wHour > 12) { - wHour -= 12; - } - CFX_WideString wsHour; - wsHour.Format(L"%d", wHour == 0 ? 12 : wHour); - wsResult += wsHour; - } else if (dwSymbol == FXBSTR_ID(0, 0, 'h', '2')) { - if (wHour > 12) { - wHour -= 12; - } - CFX_WideString wsHour; - wsHour.Format(L"%02d", wHour == 0 ? 12 : wHour); - wsResult += wsHour; - } else if (dwSymbol == FXBSTR_ID(0, 0, 'K', '1')) { - CFX_WideString wsHour; - wsHour.Format(L"%d", wHour == 0 ? 24 : wHour); - wsResult += wsHour; - } else if (dwSymbol == FXBSTR_ID(0, 0, 'K', '2')) { - CFX_WideString wsHour; - wsHour.Format(L"%02d", wHour == 0 ? 24 : wHour); - wsResult += wsHour; - } else if (dwSymbol == FXBSTR_ID(0, 0, 'k', '1')) { - if (wHour > 12) { + + CFX_WideString symbol; + symbol.Reserve(4); + symbol += strf[ccf++]; + while (ccf < lenf && strf[ccf] == symbol[0]) + symbol += strf[ccf++]; + + if (symbol == L"h" || symbol == L"hh") { + if (wHour > 12) wHour -= 12; - } - CFX_WideString wsHour; - wsHour.Format(L"%d", wHour); - wsResult += wsHour; - } else if (dwSymbol == FXBSTR_ID(0, 0, 'H', '1')) { - CFX_WideString wsHour; - wsHour.Format(L"%d", wHour); - wsResult += wsHour; - } else if (dwSymbol == FXBSTR_ID(0, 0, 'k', '2')) { - if (wHour > 12) { + wsResult += NumToString(symbol.GetLength(), wHour == 0 ? 12 : wHour); + } else if (symbol == L"K" || symbol == L"KK") { + wsResult += NumToString(symbol.GetLength(), wHour == 0 ? 24 : wHour); + } else if (symbol == L"k" || symbol == L"kk") { + if (wHour > 12) wHour -= 12; - } - CFX_WideString wsHour; - wsHour.Format(L"%02d", wHour); - wsResult += wsHour; - } else if (dwSymbol == FXBSTR_ID(0, 0, 'H', '2')) { - CFX_WideString wsHour; - wsHour.Format(L"%02d", wHour); - wsResult += wsHour; - } else if (dwSymbol == FXBSTR_ID(0, 0, 'M', '1')) { - CFX_WideString wsMinute; - wsMinute.Format(L"%d", minute); - wsResult += wsMinute; - } else if (dwSymbol == FXBSTR_ID(0, 0, 'M', '2')) { - CFX_WideString wsMinute; - wsMinute.Format(L"%02d", minute); - wsResult += wsMinute; - } else if (dwSymbol == FXBSTR_ID(0, 0, 'S', '1')) { - CFX_WideString wsSecond; - wsSecond.Format(L"%d", second); - wsResult += wsSecond; - } else if (dwSymbol == FXBSTR_ID(0, 0, 'S', '2')) { - CFX_WideString wsSecond; - wsSecond.Format(L"%02d", second); - wsResult += wsSecond; - } else if (dwSymbol == FXBSTR_ID(0, 0, 'F', '3')) { - CFX_WideString wsMilliseconds; - wsMilliseconds.Format(L"%03d", millisecond); - wsResult += wsMilliseconds; - } else if (dwSymbol == FXBSTR_ID(0, 0, 'A', '1')) { + wsResult += NumToString(symbol.GetLength(), wHour); + } else if (symbol == L"H" || symbol == L"HH") { + wsResult += NumToString(symbol.GetLength(), wHour); + } else if (symbol == L"M" || symbol == L"MM") { + wsResult += NumToString(symbol.GetLength(), minute); + } else if (symbol == L"S" || symbol == L"SS") { + wsResult += NumToString(symbol.GetLength(), second); + } else if (symbol == L"FFF") { + wsResult += NumToString(3, millisecond); + } else if (symbol == L"A") { wsResult += pLocale->GetMeridiemName(!bPM); - } else if (dwSymbol == FXBSTR_ID(0, 0, 'Z', '1')) { - wsResult += L"GMT"; - FX_TIMEZONE tz = pLocale->GetTimeZone(); - if (!bGMT && (tz.tzHour != 0 || tz.tzMinute != 0)) { - wsResult += tz.tzHour < 0 ? L"-" : L"+"; + } else if (symbol == L"Z" || symbol == L"z") { + if (symbol == L"Z") + wsResult += L"GMT"; - CFX_WideString wsTimezone; - wsTimezone.Format(L"%02d:%02d", abs(tz.tzHour), tz.tzMinute); - wsResult += wsTimezone; - } - } else if (dwSymbol == FXBSTR_ID(0, 0, 'z', '1')) { FX_TIMEZONE tz = pLocale->GetTimeZone(); - if (!bGMT && tz.tzHour != 0 && tz.tzMinute != 0) { + if (tz.tzHour != 0 || tz.tzMinute != 0) { wsResult += tz.tzHour < 0 ? L"-" : L"+"; CFX_WideString wsTimezone; @@ -894,102 +692,73 @@ bool TimeFormat(const CFX_WideString& wsTimePattern, } } } - return bRet; + return wsResult; } -bool FormatDateTimeInternal(const CFX_DateTime& dt, - const CFX_WideString& wsDatePattern, - const CFX_WideString& wsTimePattern, - bool bDateFirst, - IFX_Locale* pLocale, - CFX_WideString& wsOutput) { - bool bRet = true; - CFX_WideString wsDateOut, wsTimeOut; +CFX_WideString FormatDateTimeInternal(const CFX_DateTime& dt, + const CFX_WideString& wsDatePattern, + const CFX_WideString& wsTimePattern, + bool bDateFirst, + IFX_Locale* pLocale) { + CFX_WideString wsDateOut; if (!wsDatePattern.IsEmpty()) - bRet &= DateFormat(wsDatePattern, pLocale, dt, wsDateOut); + wsDateOut = DateFormat(wsDatePattern, pLocale, dt); + + CFX_WideString wsTimeOut; if (!wsTimePattern.IsEmpty()) - bRet &= TimeFormat(wsTimePattern, pLocale, dt, wsTimeOut); + wsTimeOut = TimeFormat(wsTimePattern, pLocale, dt); - wsOutput = bDateFirst ? wsDateOut + wsTimeOut : wsTimeOut + wsDateOut; - return bRet; + return bDateFirst ? wsDateOut + wsTimeOut : wsTimeOut + wsDateOut; } } // namespace bool FX_DateFromCanonical(const CFX_WideString& wsDate, CFX_DateTime* datetime) { - int32_t year = 1900; - int32_t month = 1; - int32_t day = 1; - uint16_t wYear = 0; - int cc_start = 0, cc = 0; const wchar_t* str = wsDate.c_str(); int len = wsDate.GetLength(); - if (len > 10) { + if (len > 10) return false; + + int cc = 0; + uint32_t year = 0; + if (!ExtractCountDigits(str, len, 4, &cc, &year)) + return false; + if (year < 1900) + return false; + if (cc >= len) { + datetime->SetDate(year, 1, 1); + return true; } - while (cc < len && cc < 4) { - if (!FXSYS_isDecimalDigit(str[cc])) { - return false; - } - wYear = wYear * 10 + str[cc++] - '0'; - } - year = wYear; - if (cc < 4 || wYear < 1900) { + + if (str[cc] == '-') + cc++; + + uint32_t month = 0; + if (!ExtractCountDigits(str, len, 2, &cc, &month)) + return false; + if (month > 12 || month < 1) return false; + if (cc >= len) { + datetime->SetDate(year, month, 1); + return true; } - if (cc < len) { - if (str[cc] == '-') { - cc++; - } - cc_start = cc; - uint8_t tmpM = 0; - while (cc < len && cc < cc_start + 2) { - if (!FXSYS_isDecimalDigit(str[cc])) { - return false; - } - tmpM = tmpM * 10 + str[cc++] - '0'; - } - month = tmpM; - if (cc == cc_start + 1 || tmpM > 12 || tmpM < 1) { - return false; - } - if (cc < len) { - if (str[cc] == '-') { - cc++; - } - uint8_t tmpD = 0; - cc_start = cc; - while (cc < len && cc < cc_start + 2) { - if (!FXSYS_isDecimalDigit(str[cc])) { - return false; - } - tmpD = tmpD * 10 + str[cc++] - '0'; - } - day = tmpD; - if (tmpD < 1) { - return false; - } - if ((tmpM == 1 || tmpM == 3 || tmpM == 5 || tmpM == 7 || tmpM == 8 || - tmpM == 10 || tmpM == 12) && - tmpD > 31) { - return false; - } - if ((tmpM == 4 || tmpM == 6 || tmpM == 9 || tmpM == 11) && tmpD > 30) { - return false; - } - bool iLeapYear; - if ((wYear % 4 == 0 && wYear % 100 != 0) || wYear % 400 == 0) { - iLeapYear = true; - } else { - iLeapYear = false; - } - if ((iLeapYear && tmpM == 2 && tmpD > 29) || - (!iLeapYear && tmpM == 2 && tmpD > 28)) { - return false; - } - } + + if (str[cc] == '-') + cc++; + + uint32_t day = 0; + if (!ExtractCountDigits(str, len, 2, &cc, &day)) + return false; + if (day < 1) + return false; + if ((MonthHas31Days(month) && day > 31) || + (MonthHas30Days(month) && day > 30)) { + return false; } + if (month == 2 && day > (IsLeapYear(year) ? 29U : 28U)) + return false; + datetime->SetDate(year, month, day); return true; } @@ -1000,74 +769,68 @@ bool FX_TimeFromCanonical(const CFX_WideStringC& wsTime, if (wsTime.GetLength() == 0) return false; - uint8_t hour = 0; - uint8_t minute = 0; - uint8_t second = 0; - uint16_t millisecond = 0; - int cc_start = 0, cc = cc_start; - const wchar_t* str = wsTime.c_str(); + const wchar_t* str = wsTime.unterminated_c_str(); int len = wsTime.GetLength(); - while (cc < len && cc < 2) { - if (!FXSYS_isDecimalDigit(str[cc])) { - return false; - } - hour = hour * 10 + str[cc++] - '0'; + + int cc = 0; + uint32_t hour = 0; + if (!ExtractCountDigits(str, len, 2, &cc, &hour)) + return false; + if (hour >= 24) + return false; + if (cc >= len) { + datetime->SetTime(hour, 0, 0, 0); + return true; } - if (cc < 2 || hour >= 24) { + + if (str[cc] == ':') + cc++; + + uint32_t minute = 0; + if (!ExtractCountDigits(str, len, 2, &cc, &minute)) + return false; + if (minute >= 60) return false; + + if (cc >= len) { + datetime->SetTime(hour, minute, 0, 0); + return true; } - if (cc < len) { - if (str[cc] == ':') { - cc++; - } - cc_start = cc; - while (cc < len && cc < cc_start + 2) { - if (!FXSYS_isDecimalDigit(str[cc])) { - return false; - } - minute = minute * 10 + str[cc++] - '0'; - } - if (cc == cc_start + 1 || minute >= 60) { + + if (str[cc] == ':') + cc++; + + uint32_t second = 0; + uint32_t millisecond = 0; + if (str[cc] != 'Z') { + if (!ExtractCountDigits(str, len, 2, &cc, &second)) return false; - } - if (cc < len) { - if (str[cc] == ':') { - cc++; - } - cc_start = cc; - while (cc < len && cc < cc_start + 2) { - if (!FXSYS_isDecimalDigit(str[cc])) { - return false; - } - second = second * 10 + str[cc++] - '0'; - } - if (cc == cc_start + 1 || second >= 60) { + if (second >= 60) + return false; + if (cc < len && str[cc] == '.') { + cc++; + if (!ExtractCountDigits(str, len, 3, &cc, &millisecond)) return false; - } - if (cc < len) { - if (str[cc] == '.') { - cc++; - cc_start = cc; - while (cc < len && cc < cc_start + 3) { - if (!FXSYS_isDecimalDigit(str[cc])) { - return false; - } - millisecond = millisecond * 10 + str[cc++] - '0'; - } - if (cc < cc_start + 3) - return false; - } - if (cc < len) { - FX_TIMEZONE tzDiff; - tzDiff.tzHour = 0; - tzDiff.tzMinute = 0; - if (str[cc] != 'Z') - cc += ParseTimeZone(str + cc, len - cc, &tzDiff); - ResolveZone(hour, minute, tzDiff, pLocale); - } - } } } + + // Skip until we find a + or - for the time zone. + while (cc < len) { + if (str[cc] == '+' || str[cc] == '-') + break; + ++cc; + } + + if (cc < len) { + FX_TIMEZONE tzDiff; + tzDiff.tzHour = 0; + tzDiff.tzMinute = 0; + if (str[cc] != 'Z') + cc += ParseTimeZone(str + cc, len - cc, &tzDiff); + + ResolveZone(tzDiff, pLocale, &hour, &minute); + } + datetime->SetTime(hour, minute, second, millisecond); return true; } @@ -1079,7 +842,7 @@ CFGAS_FormatString::~CFGAS_FormatString() {} void CFGAS_FormatString::SplitFormatString( const CFX_WideString& wsFormatString, - std::vector<CFX_WideString>& wsPatterns) { + std::vector<CFX_WideString>* wsPatterns) { int32_t iStrLen = wsFormatString.GetLength(); const wchar_t* pStr = wsFormatString.c_str(); const wchar_t* pToken = pStr; @@ -1087,13 +850,13 @@ void CFGAS_FormatString::SplitFormatString( bool iQuote = false; while (true) { if (pStr >= pEnd) { - wsPatterns.push_back(CFX_WideString(pToken, pStr - pToken)); + wsPatterns->push_back(CFX_WideString(pToken, pStr - pToken)); return; } if (*pStr == '\'') { iQuote = !iQuote; } else if (*pStr == L'|' && !iQuote) { - wsPatterns.push_back(CFX_WideString(pToken, pStr - pToken)); + wsPatterns->push_back(CFX_WideString(pToken, pStr - pToken)); pToken = pStr + 1; } pStr++; @@ -1110,17 +873,15 @@ FX_LOCALECATEGORY CFGAS_FormatString::GetCategory( CFX_WideStringC wsConstChars(gs_wsConstChars); while (ccf < iLenf) { if (pStr[ccf] == '\'') { - GetLiteralText(pStr, ccf, iLenf); + GetLiteralText(pStr, &ccf, iLenf); } else if (!bBraceOpen && wsConstChars.Find(pStr[ccf]) == -1) { CFX_WideString wsCategory(pStr[ccf]); ccf++; while (true) { - if (ccf == iLenf) { + if (ccf == iLenf) return eCategory; - } - if (pStr[ccf] == '.' || pStr[ccf] == '(') { + if (pStr[ccf] == '.' || pStr[ccf] == '(') break; - } if (pStr[ccf] == '{') { bBraceOpen = true; break; @@ -1128,16 +889,15 @@ FX_LOCALECATEGORY CFGAS_FormatString::GetCategory( wsCategory += pStr[ccf]; ccf++; } + uint32_t dwHash = FX_HashCode_GetW(wsCategory.AsStringC(), false); if (dwHash == FX_LOCALECATEGORY_DateHash) { - if (eCategory == FX_LOCALECATEGORY_Time) { + if (eCategory == FX_LOCALECATEGORY_Time) return FX_LOCALECATEGORY_DateTime; - } eCategory = FX_LOCALECATEGORY_Date; } else if (dwHash == FX_LOCALECATEGORY_TimeHash) { - if (eCategory == FX_LOCALECATEGORY_Date) { + if (eCategory == FX_LOCALECATEGORY_Date) return FX_LOCALECATEGORY_DateTime; - } eCategory = FX_LOCALECATEGORY_Time; } else if (dwHash == FX_LOCALECATEGORY_DateTimeHash) { return FX_LOCALECATEGORY_DateTime; @@ -1158,40 +918,19 @@ FX_LOCALECATEGORY CFGAS_FormatString::GetCategory( return eCategory; } -CFX_WideString CFGAS_FormatString::GetLocaleName( - const CFX_WideString& wsPattern) { - int32_t ccf = 0; - int32_t iLenf = wsPattern.GetLength(); - const wchar_t* pStr = wsPattern.c_str(); - while (ccf < iLenf) { - if (pStr[ccf] == '\'') { - GetLiteralText(pStr, ccf, iLenf); - } else if (pStr[ccf] == '(') { - ccf++; - CFX_WideString wsLCID; - while (ccf < iLenf && pStr[ccf] != ')') { - wsLCID += pStr[ccf++]; - } - return wsLCID; - } - ccf++; - } - return CFX_WideString(); -} - -IFX_Locale* CFGAS_FormatString::GetTextFormat(const CFX_WideString& wsPattern, - const CFX_WideStringC& wsCategory, - CFX_WideString& wsPurgePattern) { - IFX_Locale* pLocale = nullptr; +CFX_WideString CFGAS_FormatString::GetTextFormat( + const CFX_WideString& wsPattern, + const CFX_WideStringC& wsCategory) { int32_t ccf = 0; int32_t iLenf = wsPattern.GetLength(); const wchar_t* pStr = wsPattern.c_str(); bool bBrackOpen = false; CFX_WideStringC wsConstChars(gs_wsConstChars); + CFX_WideString wsPurgePattern; while (ccf < iLenf) { if (pStr[ccf] == '\'') { int32_t iCurChar = ccf; - GetLiteralText(pStr, ccf, iLenf); + GetLiteralText(pStr, &ccf, iLenf); wsPurgePattern += CFX_WideStringC(pStr + iCurChar, ccf - iCurChar + 1); } else if (!bBrackOpen && wsConstChars.Find(pStr[ccf]) == -1) { CFX_WideString wsSearchCategory(pStr[ccf]); @@ -1201,17 +940,15 @@ IFX_Locale* CFGAS_FormatString::GetTextFormat(const CFX_WideString& wsPattern, wsSearchCategory += pStr[ccf]; ccf++; } - if (wsSearchCategory != wsCategory) { + if (wsSearchCategory != wsCategory) continue; - } + while (ccf < iLenf) { if (pStr[ccf] == '(') { ccf++; - CFX_WideString wsLCID; - while (ccf < iLenf && pStr[ccf] != ')') { - wsLCID += pStr[ccf++]; - } - pLocale = GetPatternLocale(wsLCID); + // Skip over the encoding name. + while (ccf < iLenf && pStr[ccf] != ')') + ccf++; } else if (pStr[ccf] == '{') { bBrackOpen = true; break; @@ -1223,23 +960,18 @@ IFX_Locale* CFGAS_FormatString::GetTextFormat(const CFX_WideString& wsPattern, } ccf++; } - if (!bBrackOpen) { + if (!bBrackOpen) wsPurgePattern = wsPattern; - } - if (!pLocale) { - pLocale = m_pLocaleMgr->GetDefLocale(); - } - return pLocale; + + return wsPurgePattern; } -#define FX_NUMSTYLE_Percent 0x01 -#define FX_NUMSTYLE_Exponent 0x02 -#define FX_NUMSTYLE_DotVorv 0x04 + IFX_Locale* CFGAS_FormatString::GetNumericFormat( const CFX_WideString& wsPattern, - int32_t& iDotIndex, - uint32_t& dwStyle, - CFX_WideString& wsPurgePattern) { - dwStyle = 0; + int32_t* iDotIndex, + uint32_t* dwStyle, + CFX_WideString* wsPurgePattern) { + *dwStyle = 0; IFX_Locale* pLocale = nullptr; int32_t ccf = 0; int32_t iLenf = wsPattern.GetLength(); @@ -1250,8 +982,8 @@ IFX_Locale* CFGAS_FormatString::GetNumericFormat( while (ccf < iLenf) { if (pStr[ccf] == '\'') { int32_t iCurChar = ccf; - GetLiteralText(pStr, ccf, iLenf); - wsPurgePattern += CFX_WideStringC(pStr + iCurChar, ccf - iCurChar + 1); + GetLiteralText(pStr, &ccf, iLenf); + *wsPurgePattern += CFX_WideStringC(pStr + iCurChar, ccf - iCurChar + 1); } else if (!bBrackOpen && wsConstChars.Find(pStr[ccf]) == -1) { CFX_WideString wsCategory(pStr[ccf]); ccf++; @@ -1269,19 +1001,19 @@ IFX_Locale* CFGAS_FormatString::GetNumericFormat( if (pStr[ccf] == '(') { ccf++; CFX_WideString wsLCID; - while (ccf < iLenf && pStr[ccf] != ')') { + while (ccf < iLenf && pStr[ccf] != ')') wsLCID += pStr[ccf++]; - } - pLocale = GetPatternLocale(wsLCID); + + pLocale = m_pLocaleMgr->GetLocaleByName(wsLCID); } else if (pStr[ccf] == '{') { bBrackOpen = true; break; } else if (pStr[ccf] == '.') { CFX_WideString wsSubCategory; ccf++; - while (ccf < iLenf && pStr[ccf] != '(' && pStr[ccf] != '{') { + while (ccf < iLenf && pStr[ccf] != '(' && pStr[ccf] != '{') wsSubCategory += pStr[ccf++]; - } + uint32_t dwSubHash = FX_HashCode_GetW(wsSubCategory.AsStringC(), false); FX_LOCALENUMSUBCATEGORY eSubCategory = FX_LOCALENUMPATTERN_Decimal; @@ -1298,60 +1030,58 @@ IFX_Locale* CFGAS_FormatString::GetNumericFormat( ASSERT(pLocale); wsSubCategory = pLocale->GetNumPattern(eSubCategory); - iDotIndex = wsSubCategory.Find('.'); - if (iDotIndex > 0) { - iDotIndex += wsPurgePattern.GetLength(); + *iDotIndex = wsSubCategory.Find('.'); + if (*iDotIndex > 0) { + *iDotIndex += wsPurgePattern->GetLength(); bFindDot = true; - dwStyle |= FX_NUMSTYLE_DotVorv; - } - wsPurgePattern += wsSubCategory; - if (eSubCategory == FX_LOCALENUMPATTERN_Percent) { - dwStyle |= FX_NUMSTYLE_Percent; + *dwStyle |= FX_NUMSTYLE_DotVorv; } + *wsPurgePattern += wsSubCategory; + if (eSubCategory == FX_LOCALENUMPATTERN_Percent) + *dwStyle |= FX_NUMSTYLE_Percent; + continue; } ccf++; } } else if (pStr[ccf] == 'E') { - dwStyle |= FX_NUMSTYLE_Exponent; - wsPurgePattern += pStr[ccf]; + *dwStyle |= FX_NUMSTYLE_Exponent; + *wsPurgePattern += pStr[ccf]; } else if (pStr[ccf] == '%') { - dwStyle |= FX_NUMSTYLE_Percent; - wsPurgePattern += pStr[ccf]; + *dwStyle |= FX_NUMSTYLE_Percent; + *wsPurgePattern += pStr[ccf]; } else if (pStr[ccf] != '}') { - wsPurgePattern += pStr[ccf]; + *wsPurgePattern += pStr[ccf]; } if (!bFindDot) { if (pStr[ccf] == '.' || pStr[ccf] == 'V' || pStr[ccf] == 'v') { bFindDot = true; - iDotIndex = wsPurgePattern.GetLength() - 1; - dwStyle |= FX_NUMSTYLE_DotVorv; + *iDotIndex = wsPurgePattern->GetLength() - 1; + *dwStyle |= FX_NUMSTYLE_DotVorv; } } ccf++; } - if (!bFindDot) { - iDotIndex = wsPurgePattern.GetLength(); - } - if (!pLocale) { + if (!bFindDot) + *iDotIndex = wsPurgePattern->GetLength(); + if (!pLocale) pLocale = m_pLocaleMgr->GetDefLocale(); - } return pLocale; } bool CFGAS_FormatString::ParseText(const CFX_WideString& wsSrcText, const CFX_WideString& wsPattern, - CFX_WideString& wsValue) { - wsValue.clear(); - if (wsSrcText.IsEmpty() || wsPattern.IsEmpty()) { + CFX_WideString* wsValue) { + wsValue->clear(); + if (wsSrcText.IsEmpty() || wsPattern.IsEmpty()) return false; - } - CFX_WideString wsTextFormat; - GetTextFormat(wsPattern, L"text", wsTextFormat); - if (wsTextFormat.IsEmpty()) { + + CFX_WideString wsTextFormat = GetTextFormat(wsPattern, L"text"); + if (wsTextFormat.IsEmpty()) return false; - } - int32_t iText = 0, iPattern = 0; + + int32_t iText = 0; + int32_t iPattern = 0; const wchar_t* pStrText = wsSrcText.c_str(); int32_t iLenText = wsSrcText.GetLength(); const wchar_t* pStrPattern = wsTextFormat.c_str(); @@ -1360,11 +1090,11 @@ bool CFGAS_FormatString::ParseText(const CFX_WideString& wsSrcText, switch (pStrPattern[iPattern]) { case '\'': { CFX_WideString wsLiteral = - GetLiteralText(pStrPattern, iPattern, iLenPattern); + GetLiteralText(pStrPattern, &iPattern, iLenPattern); int32_t iLiteralLen = wsLiteral.GetLength(); if (iText + iLiteralLen > iLenText || wcsncmp(pStrText + iText, wsLiteral.c_str(), iLiteralLen)) { - wsValue = wsSrcText; + *wsValue = wsSrcText; return false; } iText += iLiteralLen; @@ -1373,13 +1103,13 @@ bool CFGAS_FormatString::ParseText(const CFX_WideString& wsSrcText, } case 'A': if (FXSYS_iswalpha(pStrText[iText])) { - wsValue += pStrText[iText]; + *wsValue += pStrText[iText]; iText++; } iPattern++; break; case 'X': - wsValue += pStrText[iText]; + *wsValue += pStrText[iText]; iText++; iPattern++; break; @@ -1387,21 +1117,21 @@ bool CFGAS_FormatString::ParseText(const CFX_WideString& wsSrcText, case '0': if (FXSYS_isDecimalDigit(pStrText[iText]) || FXSYS_iswalpha(pStrText[iText])) { - wsValue += pStrText[iText]; + *wsValue += pStrText[iText]; iText++; } iPattern++; break; case '9': if (FXSYS_isDecimalDigit(pStrText[iText])) { - wsValue += pStrText[iText]; + *wsValue += pStrText[iText]; iText++; } iPattern++; break; default: if (pStrPattern[iPattern] != pStrText[iText]) { - wsValue = wsSrcText; + *wsValue = wsSrcText; return false; } iPattern++; @@ -1414,8 +1144,8 @@ bool CFGAS_FormatString::ParseText(const CFX_WideString& wsSrcText, bool CFGAS_FormatString::ParseNum(const CFX_WideString& wsSrcNum, const CFX_WideString& wsPattern, - CFX_WideString& wsValue) { - wsValue.clear(); + CFX_WideString* wsValue) { + wsValue->clear(); if (wsSrcNum.IsEmpty() || wsPattern.IsEmpty()) return false; @@ -1423,7 +1153,7 @@ bool CFGAS_FormatString::ParseNum(const CFX_WideString& wsSrcNum, uint32_t dwFormatStyle = 0; CFX_WideString wsNumFormat; IFX_Locale* pLocale = - GetNumericFormat(wsPattern, dot_index_f, dwFormatStyle, wsNumFormat); + GetNumericFormat(wsPattern, &dot_index_f, &dwFormatStyle, &wsNumFormat); if (!pLocale || wsNumFormat.IsEmpty()) return false; @@ -1435,7 +1165,6 @@ bool CFGAS_FormatString::ParseNum(const CFX_WideString& wsSrcNum, int32_t iGroupLen = wsGroupSymbol.GetLength(); CFX_WideString wsMinus = pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Minus); int32_t iMinusLen = wsMinus.GetLength(); - int cc = 0, ccf = 0; const wchar_t* str = wsSrcNum.c_str(); int len = wsSrcNum.GetLength(); const wchar_t* strf = wsNumFormat.c_str(); @@ -1444,45 +1173,50 @@ bool CFGAS_FormatString::ParseNum(const CFX_WideString& wsSrcNum, bool bNeg = false; bool bReverseParse = false; int32_t dot_index = 0; - if (!GetNumericDotIndex(wsSrcNum, wsDotSymbol, dot_index) && + + // If we're looking for a '.', 'V' or 'v' and the input string does not + // have a dot index for one of those, then we disable parsing the decimal. + if (!GetNumericDotIndex(wsSrcNum, wsDotSymbol, &dot_index) && (dwFormatStyle & FX_NUMSTYLE_DotVorv)) { bReverseParse = true; } - bReverseParse = false; - ccf = dot_index_f - 1; - cc = dot_index - 1; + + // This parse is broken into two parts based on the '.' in the number + // (or 'V' or 'v'). |dot_index_f| is the location of the dot in the format and + // |dot_index| is the location of the dot in the number. + // + // This first while() starts at the '.' and walks backwards to the start of + // the number. The second while() walks from the dot forwards to the end of + // the decimal. + + int ccf = dot_index_f - 1; + int cc = dot_index - 1; while (ccf >= 0 && cc >= 0) { switch (strf[ccf]) { case '\'': { - CFX_WideString wsLiteral = GetLiteralTextReverse(strf, ccf); + CFX_WideString wsLiteral = GetLiteralTextReverse(strf, &ccf); int32_t iLiteralLen = wsLiteral.GetLength(); cc -= iLiteralLen - 1; - if (cc < 0 || wcsncmp(str + cc, wsLiteral.c_str(), iLiteralLen)) { + if (cc < 0 || wcsncmp(str + cc, wsLiteral.c_str(), iLiteralLen)) return false; - } + cc--; ccf--; break; } case '9': - if (!FXSYS_isDecimalDigit(str[cc])) { + if (!FXSYS_isDecimalDigit(str[cc])) return false; - } - wsValue = str[cc] + wsValue; + + wsValue->Insert(0, str[cc]); cc--; ccf--; break; case 'z': - if (FXSYS_isDecimalDigit(str[cc])) { - wsValue = str[cc] + wsValue; - cc--; - } - ccf--; - break; case 'Z': - if (str[cc] != ' ') { + if (strf[ccf] == 'z' || str[cc] != ' ') { if (FXSYS_isDecimalDigit(str[cc])) { - wsValue = str[cc] + wsValue; + wsValue->Insert(0, str[cc]); cc--; } } else { @@ -1491,86 +1225,65 @@ bool CFGAS_FormatString::ParseNum(const CFX_WideString& wsSrcNum, ccf--; break; case 'S': - if (str[cc] == '+' || str[cc] == ' ') { - cc--; - } else { - cc -= iMinusLen - 1; - if (cc < 0 || wcsncmp(str + cc, wsMinus.c_str(), iMinusLen)) { - return false; - } - cc--; - bNeg = true; - } - ccf--; - break; case 's': - if (str[cc] == '+') { + if (str[cc] == '+' || (strf[ccf] == 'S' && str[cc] == ' ')) { cc--; } else { cc -= iMinusLen - 1; - if (cc < 0 || wcsncmp(str + cc, wsMinus.c_str(), iMinusLen)) { + if (cc < 0 || wcsncmp(str + cc, wsMinus.c_str(), iMinusLen)) return false; - } + cc--; bNeg = true; } ccf--; break; case 'E': { - if (cc >= dot_index) { - return false; - } bool bExpSign = false; while (cc >= 0) { - if (str[cc] == 'E' || str[cc] == 'e') { + if (str[cc] == 'E' || str[cc] == 'e') break; - } if (FXSYS_isDecimalDigit(str[cc])) { - iExponent = iExponent + (str[cc] - '0') * 10; + iExponent = iExponent + FXSYS_DecimalCharToInt(str[cc]) * 10; cc--; continue; - } else if (str[cc] == '+') { + } + if (str[cc] == '+') { cc--; continue; - } else if (cc - iMinusLen + 1 > 0 && - !wcsncmp(str + (cc - iMinusLen + 1), wsMinus.c_str(), - iMinusLen)) { + } + if (cc - iMinusLen + 1 > 0 && !wcsncmp(str + (cc - iMinusLen + 1), + wsMinus.c_str(), iMinusLen)) { bExpSign = true; cc -= iMinusLen; - } else { - return false; + continue; } + + return false; } cc--; iExponent = bExpSign ? -iExponent : iExponent; ccf--; - } break; + break; + } case '$': { CFX_WideString wsSymbol = pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_CurrencySymbol); int32_t iSymbolLen = wsSymbol.GetLength(); cc -= iSymbolLen - 1; - if (cc < 0 || wcsncmp(str + cc, wsSymbol.c_str(), iSymbolLen)) { + if (cc < 0 || wcsncmp(str + cc, wsSymbol.c_str(), iSymbolLen)) return false; - } + cc--; ccf--; - } break; - case 'r': - if (ccf - 1 >= 0 && strf[ccf - 1] == 'c') { - if (str[cc] == 'R' && cc - 1 >= 0 && str[cc - 1] == 'C') { - bNeg = true; - cc -= 2; - } - ccf -= 2; - } else { - ccf--; - } break; + } + case 'r': case 'R': - if (ccf - 1 >= 0 && strf[ccf - 1] == 'C') { - if (str[cc] == ' ') { - cc++; + if (ccf - 1 >= 0 && ((strf[ccf] == 'R' && strf[ccf - 1] == 'C') || + (strf[ccf] == 'r' && strf[ccf - 1] == 'c'))) { + if (strf[ccf] == 'R' && str[cc] == ' ') { + cc -= 2; } else if (str[cc] == 'R' && cc - 1 >= 0 && str[cc - 1] == 'C') { bNeg = true; cc -= 2; @@ -1581,20 +1294,11 @@ bool CFGAS_FormatString::ParseNum(const CFX_WideString& wsSrcNum, } break; case 'b': - if (ccf - 1 >= 0 && strf[ccf - 1] == 'd') { - if (str[cc] == 'B' && cc - 1 >= 0 && str[cc - 1] == 'D') { - bNeg = true; - cc -= 2; - } - ccf -= 2; - } else { - ccf--; - } - break; case 'B': - if (ccf - 1 >= 0 && strf[ccf - 1] == 'D') { - if (str[cc] == ' ') { - cc++; + if (ccf - 1 >= 0 && ((strf[ccf] == 'B' && strf[ccf - 1] == 'D') || + (strf[ccf] == 'b' && strf[ccf - 1] == 'd'))) { + if (strf[ccf] == 'B' && str[cc] == ' ') { + cc -= 2; } else if (str[cc] == 'B' && cc - 1 >= 0 && str[cc - 1] == 'D') { bNeg = true; cc -= 2; @@ -1604,22 +1308,22 @@ bool CFGAS_FormatString::ParseNum(const CFX_WideString& wsSrcNum, ccf--; } break; - case '.': - case 'V': - case 'v': - return false; case '%': { CFX_WideString wsSymbol = pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Percent); int32_t iSysmbolLen = wsSymbol.GetLength(); cc -= iSysmbolLen - 1; - if (cc < 0 || wcsncmp(str + cc, wsSymbol.c_str(), iSysmbolLen)) { + if (cc < 0 || wcsncmp(str + cc, wsSymbol.c_str(), iSysmbolLen)) return false; - } + cc--; ccf--; bHavePercentSymbol = true; - } break; + break; + } + case '.': + case 'V': + case 'v': case '8': return false; case ',': { @@ -1633,29 +1337,22 @@ bool CFGAS_FormatString::ParseNum(const CFX_WideString& wsSrcNum, } } ccf--; - } break; - case '(': - if (str[cc] == L'(') { - bNeg = true; - } else if (str[cc] != L' ') { - return false; - } - cc--; - ccf--; break; + } + case '(': case ')': - if (str[cc] == L')') { + if (str[cc] == strf[ccf]) bNeg = true; - } else if (str[cc] != L' ') { + else if (str[cc] != L' ') return false; - } + cc--; ccf--; break; default: - if (strf[ccf] != str[cc]) { + if (strf[ccf] != str[cc]) return false; - } + cc--; ccf--; } @@ -1665,20 +1362,18 @@ bool CFGAS_FormatString::ParseNum(const CFX_WideString& wsSrcNum, bNeg = true; cc--; } - if (cc >= 0) { + if (cc >= 0) return false; - } - } - if (dot_index < len && (dwFormatStyle & FX_NUMSTYLE_DotVorv)) { - wsValue += '.'; } + if (dot_index < len && (dwFormatStyle & FX_NUMSTYLE_DotVorv)) + *wsValue += '.'; if (!bReverseParse) { ccf = dot_index_f + 1; cc = (dot_index == len) ? len : dot_index + 1; while (cc < len && ccf < lenf) { switch (strf[ccf]) { case '\'': { - CFX_WideString wsLiteral = GetLiteralText(strf, ccf, lenf); + CFX_WideString wsLiteral = GetLiteralText(strf, &ccf, lenf); int32_t iLiteralLen = wsLiteral.GetLength(); if (cc + iLiteralLen > len || wcsncmp(str + cc, wsLiteral.c_str(), iLiteralLen)) { @@ -1689,24 +1384,18 @@ bool CFGAS_FormatString::ParseNum(const CFX_WideString& wsSrcNum, break; } case '9': - if (!FXSYS_isDecimalDigit(str[cc])) { + if (!FXSYS_isDecimalDigit(str[cc])) return false; - } - { wsValue += str[cc]; } + + *wsValue += str[cc]; cc++; ccf++; break; case 'z': - if (FXSYS_isDecimalDigit(str[cc])) { - wsValue += str[cc]; - cc++; - } - ccf++; - break; case 'Z': - if (str[cc] != ' ') { + if (strf[ccf] == 'z' || str[cc] != ' ') { if (FXSYS_isDecimalDigit(str[cc])) { - wsValue += str[cc]; + *wsValue += str[cc]; cc++; } } else { @@ -1715,20 +1404,8 @@ bool CFGAS_FormatString::ParseNum(const CFX_WideString& wsSrcNum, ccf++; break; case 'S': - if (str[cc] == '+' || str[cc] == ' ') { - cc++; - } else { - if (cc + iMinusLen > len || - wcsncmp(str + cc, wsMinus.c_str(), iMinusLen)) { - return false; - } - bNeg = true; - cc += iMinusLen; - } - ccf++; - break; case 's': - if (str[cc] == '+') { + if (str[cc] == '+' || (strf[ccf] == 'S' && str[cc] == ' ')) { cc++; } else { if (cc + iMinusLen > len || @@ -1741,9 +1418,9 @@ bool CFGAS_FormatString::ParseNum(const CFX_WideString& wsSrcNum, ccf++; break; case 'E': { - if (cc >= len || (str[cc] != 'E' && str[cc] != 'e')) { + if (cc >= len || (str[cc] != 'E' && str[cc] != 'e')) return false; - } + bool bExpSign = false; cc++; if (cc < len) { @@ -1755,15 +1432,16 @@ bool CFGAS_FormatString::ParseNum(const CFX_WideString& wsSrcNum, } } while (cc < len) { - if (!FXSYS_isDecimalDigit(str[cc])) { + if (!FXSYS_isDecimalDigit(str[cc])) break; - } - iExponent = iExponent * 10 + str[cc] - '0'; + + iExponent = iExponent * 10 + FXSYS_DecimalCharToInt(str[cc]); cc++; } iExponent = bExpSign ? -iExponent : iExponent; ccf++; - } break; + break; + } case '$': { CFX_WideString wsSymbol = pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_CurrencySymbol); @@ -1774,19 +1452,13 @@ bool CFGAS_FormatString::ParseNum(const CFX_WideString& wsSrcNum, } cc += iSymbolLen; ccf++; - } break; - case 'c': - if (ccf + 1 < lenf && strf[ccf + 1] == 'r') { - if (str[cc] == 'C' && cc + 1 < len && str[cc + 1] == 'R') { - bNeg = true; - cc += 2; - } - ccf += 2; - } break; + } + case 'c': case 'C': - if (ccf + 1 < lenf && strf[ccf + 1] == 'R') { - if (str[cc] == ' ') { + if (ccf + 1 < lenf && ((strf[ccf] == 'C' && strf[ccf + 1] == 'R') || + (strf[ccf] == 'c' && strf[ccf + 1] == 'r'))) { + if (strf[ccf] == 'C' && str[cc] == ' ') { cc++; } else if (str[cc] == 'C' && cc + 1 < len && str[cc + 1] == 'R') { bNeg = true; @@ -1796,17 +1468,10 @@ bool CFGAS_FormatString::ParseNum(const CFX_WideString& wsSrcNum, } break; case 'd': - if (ccf + 1 < lenf && strf[ccf + 1] == 'b') { - if (str[cc] == 'D' && cc + 1 < len && str[cc + 1] == 'B') { - bNeg = true; - cc += 2; - } - ccf += 2; - } - break; case 'D': - if (ccf + 1 < lenf && strf[ccf + 1] == 'B') { - if (str[cc] == ' ') { + if (ccf + 1 < lenf && ((strf[ccf] == 'D' && strf[ccf + 1] == 'B') || + (strf[ccf] == 'd' && strf[ccf + 1] == 'b'))) { + if (strf[ccf] == 'D' && str[cc] == ' ') { cc++; } else if (str[cc] == 'D' && cc + 1 < len && str[cc + 1] == 'B') { bNeg = true; @@ -1831,11 +1496,11 @@ bool CFGAS_FormatString::ParseNum(const CFX_WideString& wsSrcNum, bHavePercentSymbol = true; } break; case '8': { - while (ccf < lenf && strf[ccf] == '8') { + while (ccf < lenf && strf[ccf] == '8') ccf++; - } + while (cc < len && FXSYS_isDecimalDigit(str[cc])) { - wsValue += str[cc]; + *wsValue += str[cc]; cc++; } } break; @@ -1845,60 +1510,52 @@ bool CFGAS_FormatString::ParseNum(const CFX_WideString& wsSrcNum, cc += iGroupLen; } ccf++; - } break; - case '(': - if (str[cc] == L'(') { - bNeg = true; - } else if (str[cc] != L' ') { - return false; - } - cc++; - ccf++; break; + } + case '(': case ')': - if (str[cc] == L')') { + if (str[cc] == strf[ccf]) bNeg = true; - } else if (str[cc] != L' ') { + else if (str[cc] != L' ') return false; - } + cc++; ccf++; break; default: - if (strf[ccf] != str[cc]) { + if (strf[ccf] != str[cc]) return false; - } + cc++; ccf++; } } - if (cc != len) { + if (cc != len) return false; - } } if (iExponent || bHavePercentSymbol) { - CFX_Decimal decimal = CFX_Decimal(wsValue.AsStringC()); + CFX_Decimal decimal = CFX_Decimal(wsValue->AsStringC()); if (iExponent) { decimal = decimal * CFX_Decimal(FXSYS_pow(10, static_cast<float>(iExponent)), 3); } - if (bHavePercentSymbol) { + if (bHavePercentSymbol) decimal = decimal / CFX_Decimal(100); - } - wsValue = decimal; - } - if (bNeg) { - wsValue = L'-' + wsValue; + + *wsValue = decimal; } + if (bNeg) + wsValue->Insert(0, L'-'); + return true; } FX_DATETIMETYPE CFGAS_FormatString::GetDateTimeFormat( const CFX_WideString& wsPattern, - IFX_Locale*& pLocale, - CFX_WideString& wsDatePattern, - CFX_WideString& wsTimePattern) { - pLocale = nullptr; + IFX_Locale** pLocale, + CFX_WideString* wsDatePattern, + CFX_WideString* wsTimePattern) { + *pLocale = nullptr; CFX_WideString wsTempPattern; FX_LOCALECATEGORY eCategory = FX_LOCALECATEGORY_Unknown; int32_t ccf = 0; @@ -1910,7 +1567,7 @@ FX_DATETIMETYPE CFGAS_FormatString::GetDateTimeFormat( while (ccf < iLenf) { if (pStr[ccf] == '\'') { int32_t iCurChar = ccf; - GetLiteralText(pStr, ccf, iLenf); + GetLiteralText(pStr, &ccf, iLenf); wsTempPattern += CFX_WideStringC(pStr + iCurChar, ccf - iCurChar + 1); } else if (!bBraceOpen && iFindCategory != 3 && wsConstChars.Find(pStr[ccf]) == -1) { @@ -1919,12 +1576,12 @@ FX_DATETIMETYPE CFGAS_FormatString::GetDateTimeFormat( while (ccf < iLenf && pStr[ccf] != '{' && pStr[ccf] != '.' && pStr[ccf] != '(') { if (pStr[ccf] == 'T') { - wsDatePattern = wsPattern.Left(ccf); - wsTimePattern = wsPattern.Right(wsPattern.GetLength() - ccf); - wsTimePattern.SetAt(0, ' '); - if (!pLocale) { - pLocale = m_pLocaleMgr->GetDefLocale(); - } + *wsDatePattern = wsPattern.Left(ccf); + *wsTimePattern = wsPattern.Right(wsPattern.GetLength() - ccf); + wsTimePattern->SetAt(0, ' '); + if (!*pLocale) + *pLocale = m_pLocaleMgr->GetDefLocale(); + return FX_DATETIMETYPE_DateTime; } wsCategory += pStr[ccf]; @@ -1933,9 +1590,8 @@ FX_DATETIMETYPE CFGAS_FormatString::GetDateTimeFormat( if (!(iFindCategory & 1) && wsCategory == L"date") { iFindCategory |= 1; eCategory = FX_LOCALECATEGORY_Date; - if (iFindCategory & 2) { + if (iFindCategory & 2) iFindCategory = 4; - } } else if (!(iFindCategory & 2) && wsCategory == L"time") { iFindCategory |= 2; eCategory = FX_LOCALECATEGORY_Time; @@ -1949,19 +1605,19 @@ FX_DATETIMETYPE CFGAS_FormatString::GetDateTimeFormat( if (pStr[ccf] == '(') { ccf++; CFX_WideString wsLCID; - while (ccf < iLenf && pStr[ccf] != ')') { + while (ccf < iLenf && pStr[ccf] != ')') wsLCID += pStr[ccf++]; - } - pLocale = GetPatternLocale(wsLCID); + + *pLocale = m_pLocaleMgr->GetLocaleByName(wsLCID); } else if (pStr[ccf] == '{') { bBraceOpen = true; break; } else if (pStr[ccf] == '.') { CFX_WideString wsSubCategory; ccf++; - while (ccf < iLenf && pStr[ccf] != '(' && pStr[ccf] != '{') { + while (ccf < iLenf && pStr[ccf] != '(' && pStr[ccf] != '{') wsSubCategory += pStr[ccf++]; - } + uint32_t dwSubHash = FX_HashCode_GetW(wsSubCategory.AsStringC(), false); FX_LOCALEDATETIMESUBCATEGORY eSubCategory = @@ -1974,23 +1630,23 @@ FX_DATETIMETYPE CFGAS_FormatString::GetDateTimeFormat( break; } } - if (!pLocale) { - pLocale = m_pLocaleMgr->GetDefLocale(); - } - ASSERT(pLocale); + if (!*pLocale) + *pLocale = m_pLocaleMgr->GetDefLocale(); + ASSERT(*pLocale); + switch (eCategory) { case FX_LOCALECATEGORY_Date: - wsDatePattern = - wsTempPattern + pLocale->GetDatePattern(eSubCategory); + *wsDatePattern = + wsTempPattern + (*pLocale)->GetDatePattern(eSubCategory); break; case FX_LOCALECATEGORY_Time: - wsTimePattern = - wsTempPattern + pLocale->GetTimePattern(eSubCategory); + *wsTimePattern = + wsTempPattern + (*pLocale)->GetTimePattern(eSubCategory); break; case FX_LOCALECATEGORY_DateTime: - wsDatePattern = - wsTempPattern + pLocale->GetDatePattern(eSubCategory); - wsTimePattern = pLocale->GetTimePattern(eSubCategory); + *wsDatePattern = + wsTempPattern + (*pLocale)->GetDatePattern(eSubCategory); + *wsTimePattern = (*pLocale)->GetTimePattern(eSubCategory); break; default: break; @@ -2003,11 +1659,11 @@ FX_DATETIMETYPE CFGAS_FormatString::GetDateTimeFormat( } else if (pStr[ccf] == '}') { bBraceOpen = false; if (!wsTempPattern.IsEmpty()) { - if (eCategory == FX_LOCALECATEGORY_Time) { - wsTimePattern = wsTempPattern; - } else if (eCategory == FX_LOCALECATEGORY_Date) { - wsDatePattern = wsTempPattern; - } + if (eCategory == FX_LOCALECATEGORY_Time) + *wsTimePattern = wsTempPattern; + else if (eCategory == FX_LOCALECATEGORY_Date) + *wsDatePattern = wsTempPattern; + wsTempPattern.clear(); } } else { @@ -2015,19 +1671,18 @@ FX_DATETIMETYPE CFGAS_FormatString::GetDateTimeFormat( } ccf++; } + if (!wsTempPattern.IsEmpty()) { - if (eCategory == FX_LOCALECATEGORY_Date) { - wsDatePattern += wsTempPattern; - } else { - wsTimePattern += wsTempPattern; - } - } - if (!pLocale) { - pLocale = m_pLocaleMgr->GetDefLocale(); + if (eCategory == FX_LOCALECATEGORY_Date) + *wsDatePattern += wsTempPattern; + else + *wsTimePattern += wsTempPattern; } + if (!*pLocale) + *pLocale = m_pLocaleMgr->GetDefLocale(); if (!iFindCategory) { - wsTimePattern.clear(); - wsDatePattern = wsPattern; + wsTimePattern->clear(); + *wsDatePattern = wsPattern; } return (FX_DATETIMETYPE)iFindCategory; } @@ -2037,53 +1692,52 @@ bool CFGAS_FormatString::ParseDateTime(const CFX_WideString& wsSrcDateTime, FX_DATETIMETYPE eDateTimeType, CFX_DateTime* dtValue) { dtValue->Reset(); - - if (wsSrcDateTime.IsEmpty() || wsPattern.IsEmpty()) { + if (wsSrcDateTime.IsEmpty() || wsPattern.IsEmpty()) return false; - } - CFX_WideString wsDatePattern, wsTimePattern; + + CFX_WideString wsDatePattern; + CFX_WideString wsTimePattern; IFX_Locale* pLocale = nullptr; FX_DATETIMETYPE eCategory = - GetDateTimeFormat(wsPattern, pLocale, wsDatePattern, wsTimePattern); - if (!pLocale) { + GetDateTimeFormat(wsPattern, &pLocale, &wsDatePattern, &wsTimePattern); + if (!pLocale) return false; - } - if (eCategory == FX_DATETIMETYPE_Unknown) { + if (eCategory == FX_DATETIMETYPE_Unknown) eCategory = eDateTimeType; - } - if (eCategory == FX_DATETIMETYPE_Unknown) { + if (eCategory == FX_DATETIMETYPE_Unknown) return false; - } if (eCategory == FX_DATETIMETYPE_TimeDate) { int32_t iStart = 0; if (!ParseLocaleTime(wsSrcDateTime, wsTimePattern, pLocale, dtValue, - iStart)) { + &iStart)) { return false; } if (!ParseLocaleDate(wsSrcDateTime, wsDatePattern, pLocale, dtValue, - iStart)) { + &iStart)) { return false; } } else { int32_t iStart = 0; if ((eCategory & FX_DATETIMETYPE_Date) && !ParseLocaleDate(wsSrcDateTime, wsDatePattern, pLocale, dtValue, - iStart)) { + &iStart)) { return false; } if ((eCategory & FX_DATETIMETYPE_Time) && !ParseLocaleTime(wsSrcDateTime, wsTimePattern, pLocale, dtValue, - iStart)) { + &iStart)) { return false; } } return true; } + bool CFGAS_FormatString::ParseZero(const CFX_WideString& wsSrcText, const CFX_WideString& wsPattern) { - CFX_WideString wsTextFormat; - GetTextFormat(wsPattern, L"zero", wsTextFormat); - int32_t iText = 0, iPattern = 0; + CFX_WideString wsTextFormat = GetTextFormat(wsPattern, L"zero"); + + int32_t iText = 0; + int32_t iPattern = 0; const wchar_t* pStrText = wsSrcText.c_str(); int32_t iLenText = wsSrcText.GetLength(); const wchar_t* pStrPattern = wsTextFormat.c_str(); @@ -2091,7 +1745,7 @@ bool CFGAS_FormatString::ParseZero(const CFX_WideString& wsSrcText, while (iPattern < iLenPattern && iText < iLenText) { if (pStrPattern[iPattern] == '\'') { CFX_WideString wsLiteral = - GetLiteralText(pStrPattern, iPattern, iLenPattern); + GetLiteralText(pStrPattern, &iPattern, iLenPattern); int32_t iLiteralLen = wsLiteral.GetLength(); if (iText + iLiteralLen > iLenText || wcsncmp(pStrText + iText, wsLiteral.c_str(), iLiteralLen)) { @@ -2100,20 +1754,22 @@ bool CFGAS_FormatString::ParseZero(const CFX_WideString& wsSrcText, iText += iLiteralLen; iPattern++; continue; - } else if (pStrPattern[iPattern] != pStrText[iText]) { - return false; - } else { - iText++; - iPattern++; } + if (pStrPattern[iPattern] != pStrText[iText]) + return false; + + iText++; + iPattern++; } return iPattern == iLenPattern && iText == iLenText; } + bool CFGAS_FormatString::ParseNull(const CFX_WideString& wsSrcText, const CFX_WideString& wsPattern) { - CFX_WideString wsTextFormat; - GetTextFormat(wsPattern, L"null", wsTextFormat); - int32_t iText = 0, iPattern = 0; + CFX_WideString wsTextFormat = GetTextFormat(wsPattern, L"null"); + + int32_t iText = 0; + int32_t iPattern = 0; const wchar_t* pStrText = wsSrcText.c_str(); int32_t iLenText = wsSrcText.GetLength(); const wchar_t* pStrPattern = wsTextFormat.c_str(); @@ -2121,7 +1777,7 @@ bool CFGAS_FormatString::ParseNull(const CFX_WideString& wsSrcText, while (iPattern < iLenPattern && iText < iLenText) { if (pStrPattern[iPattern] == '\'') { CFX_WideString wsLiteral = - GetLiteralText(pStrPattern, iPattern, iLenPattern); + GetLiteralText(pStrPattern, &iPattern, iLenPattern); int32_t iLiteralLen = wsLiteral.GetLength(); if (iText + iLiteralLen > iLenText || wcsncmp(pStrText + iText, wsLiteral.c_str(), iLiteralLen)) { @@ -2130,50 +1786,52 @@ bool CFGAS_FormatString::ParseNull(const CFX_WideString& wsSrcText, iText += iLiteralLen; iPattern++; continue; - } else if (pStrPattern[iPattern] != pStrText[iText]) { - return false; - } else { - iText++; - iPattern++; } + if (pStrPattern[iPattern] != pStrText[iText]) + return false; + + iText++; + iPattern++; } return iPattern == iLenPattern && iText == iLenText; } + bool CFGAS_FormatString::FormatText(const CFX_WideString& wsSrcText, const CFX_WideString& wsPattern, - CFX_WideString& wsOutput) { - if (wsPattern.IsEmpty()) { + CFX_WideString* wsOutput) { + if (wsPattern.IsEmpty()) return false; - } + int32_t iLenText = wsSrcText.GetLength(); - if (iLenText == 0) { + if (iLenText == 0) return false; - } - CFX_WideString wsTextFormat; - GetTextFormat(wsPattern, L"text", wsTextFormat); - int32_t iText = 0, iPattern = 0; + + CFX_WideString wsTextFormat = GetTextFormat(wsPattern, L"text"); + + int32_t iText = 0; + int32_t iPattern = 0; const wchar_t* pStrText = wsSrcText.c_str(); const wchar_t* pStrPattern = wsTextFormat.c_str(); int32_t iLenPattern = wsTextFormat.GetLength(); while (iPattern < iLenPattern) { switch (pStrPattern[iPattern]) { case '\'': { - wsOutput += GetLiteralText(pStrPattern, iPattern, iLenPattern); + *wsOutput += GetLiteralText(pStrPattern, &iPattern, iLenPattern); iPattern++; break; } case 'A': - if (iText >= iLenText || !FXSYS_iswalpha(pStrText[iText])) { + if (iText >= iLenText || !FXSYS_iswalpha(pStrText[iText])) return false; - } - wsOutput += pStrText[iText++]; + + *wsOutput += pStrText[iText++]; iPattern++; break; case 'X': - if (iText >= iLenText) { + if (iText >= iLenText) return false; - } - wsOutput += pStrText[iText++]; + + *wsOutput += pStrText[iText++]; iPattern++; break; case 'O': @@ -2182,18 +1840,18 @@ bool CFGAS_FormatString::FormatText(const CFX_WideString& wsSrcText, !FXSYS_iswalpha(pStrText[iText]))) { return false; } - wsOutput += pStrText[iText++]; + *wsOutput += pStrText[iText++]; iPattern++; break; case '9': - if (iText >= iLenText || !FXSYS_isDecimalDigit(pStrText[iText])) { + if (iText >= iLenText || !FXSYS_isDecimalDigit(pStrText[iText])) return false; - } - wsOutput += pStrText[iText++]; + + *wsOutput += pStrText[iText++]; iPattern++; break; default: - wsOutput += pStrPattern[iPattern++]; + *wsOutput += pStrPattern[iPattern++]; break; } } @@ -2202,38 +1860,39 @@ bool CFGAS_FormatString::FormatText(const CFX_WideString& wsSrcText, bool CFGAS_FormatString::FormatStrNum(const CFX_WideStringC& wsInputNum, const CFX_WideString& wsPattern, - CFX_WideString& wsOutput) { - if (wsInputNum.IsEmpty() || wsPattern.IsEmpty()) { + CFX_WideString* wsOutput) { + if (wsInputNum.IsEmpty() || wsPattern.IsEmpty()) return false; - } + int32_t dot_index_f = -1; uint32_t dwNumStyle = 0; CFX_WideString wsNumFormat; IFX_Locale* pLocale = - GetNumericFormat(wsPattern, dot_index_f, dwNumStyle, wsNumFormat); - if (!pLocale || wsNumFormat.IsEmpty()) { + GetNumericFormat(wsPattern, &dot_index_f, &dwNumStyle, &wsNumFormat); + if (!pLocale || wsNumFormat.IsEmpty()) return false; - } + int32_t cc = 0, ccf = 0; const wchar_t* strf = wsNumFormat.c_str(); int lenf = wsNumFormat.GetLength(); CFX_WideString wsSrcNum(wsInputNum); wsSrcNum.TrimLeft('0'); - if (wsSrcNum.IsEmpty() || wsSrcNum[0] == '.') { + if (wsSrcNum.IsEmpty() || wsSrcNum[0] == '.') wsSrcNum.Insert(0, '0'); - } + CFX_Decimal decimal = CFX_Decimal(wsSrcNum.AsStringC()); if (dwNumStyle & FX_NUMSTYLE_Percent) { decimal = decimal * CFX_Decimal(100); wsSrcNum = decimal; } + int32_t exponent = 0; if (dwNumStyle & FX_NUMSTYLE_Exponent) { int fixed_count = 0; while (ccf < dot_index_f) { switch (strf[ccf]) { case '\'': - GetLiteralText(strf, ccf, dot_index_f); + GetLiteralText(strf, &ccf, dot_index_f); break; case '9': case 'z': @@ -2243,6 +1902,7 @@ bool CFGAS_FormatString::FormatStrNum(const CFX_WideStringC& wsInputNum, } ccf++; } + int threshold = 1; while (fixed_count > 1) { threshold *= 10; @@ -2265,9 +1925,10 @@ bool CFGAS_FormatString::FormatStrNum(const CFX_WideStringC& wsInputNum, } } } + bool bTrimTailZeros = false; int32_t iTreading = - GetNumTrailingLimit(wsNumFormat, dot_index_f, bTrimTailZeros); + GetNumTrailingLimit(wsNumFormat, dot_index_f, &bTrimTailZeros); int32_t scale = decimal.GetScale(); if (iTreading < scale) { decimal.SetScale(iTreading); @@ -2277,6 +1938,7 @@ bool CFGAS_FormatString::FormatStrNum(const CFX_WideStringC& wsInputNum, wsSrcNum.TrimRight(L"0"); wsSrcNum.TrimRight(L"."); } + CFX_WideString wsGroupSymbol = pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Grouping); bool bNeg = false; @@ -2284,71 +1946,67 @@ bool CFGAS_FormatString::FormatStrNum(const CFX_WideStringC& wsInputNum, bNeg = true; wsSrcNum.Delete(0, 1); } + bool bAddNeg = false; const wchar_t* str = wsSrcNum.c_str(); int len = wsSrcNum.GetLength(); int dot_index = wsSrcNum.Find('.'); - if (dot_index == -1) { + if (dot_index == -1) dot_index = len; - } + ccf = dot_index_f - 1; cc = dot_index - 1; while (ccf >= 0) { switch (strf[ccf]) { case '9': if (cc >= 0) { - if (!FXSYS_isDecimalDigit(str[cc])) { + if (!FXSYS_isDecimalDigit(str[cc])) return false; - } - wsOutput = str[cc] + wsOutput; + + wsOutput->Insert(0, str[cc]); cc--; } else { - wsOutput = L'0' + wsOutput; + wsOutput->Insert(0, L'0'); } ccf--; break; case 'z': if (cc >= 0) { - if (!FXSYS_isDecimalDigit(str[cc])) { + if (!FXSYS_isDecimalDigit(str[cc])) return false; - } - if (str[0] != '0') { - wsOutput = str[cc] + wsOutput; - } + if (str[0] != '0') + wsOutput->Insert(0, str[cc]); + cc--; } ccf--; break; case 'Z': if (cc >= 0) { - if (!FXSYS_isDecimalDigit(str[cc])) { + if (!FXSYS_isDecimalDigit(str[cc])) return false; - } - if (str[0] == '0') { - wsOutput = L' ' + wsOutput; - } else { - wsOutput = str[cc] + wsOutput; - } + + wsOutput->Insert(0, str[0] == '0' ? L' ' : str[cc]); cc--; } else { - wsOutput = L' ' + wsOutput; + wsOutput->Insert(0, L' '); } ccf--; break; case 'S': if (bNeg) { - wsOutput = - pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Minus) + wsOutput; + *wsOutput = + pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Minus) + *wsOutput; bAddNeg = true; } else { - wsOutput = L' ' + wsOutput; + wsOutput->Insert(0, L' '); } ccf--; break; case 's': if (bNeg) { - wsOutput = - pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Minus) + wsOutput; + *wsOutput = + pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Minus) + *wsOutput; bAddNeg = true; } ccf--; @@ -2356,118 +2014,102 @@ bool CFGAS_FormatString::FormatStrNum(const CFX_WideStringC& wsInputNum, case 'E': { CFX_WideString wsExp; wsExp.Format(L"E%+d", exponent); - wsOutput = wsExp + wsOutput; - } + *wsOutput = wsExp + *wsOutput; ccf--; break; + } case '$': { - wsOutput = + *wsOutput = pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_CurrencySymbol) + - wsOutput; - } + *wsOutput; ccf--; break; + } case 'r': if (ccf - 1 >= 0 && strf[ccf - 1] == 'c') { - if (bNeg) { - wsOutput = L"CR" + wsOutput; - } + if (bNeg) + *wsOutput = L"CR" + *wsOutput; + ccf -= 2; bAddNeg = true; } break; case 'R': if (ccf - 1 >= 0 && strf[ccf - 1] == 'C') { - if (bNeg) { - wsOutput = L"CR" + wsOutput; - } else { - wsOutput = L" " + wsOutput; - } + *wsOutput = bNeg ? L"CR" : L" " + *wsOutput; ccf -= 2; bAddNeg = true; } break; case 'b': if (ccf - 1 >= 0 && strf[ccf - 1] == 'd') { - if (bNeg) { - wsOutput = L"db" + wsOutput; - } + if (bNeg) + *wsOutput = L"db" + *wsOutput; + ccf -= 2; bAddNeg = true; } break; case 'B': if (ccf - 1 >= 0 && strf[ccf - 1] == 'D') { - if (bNeg) { - wsOutput = L"DB" + wsOutput; - } else { - wsOutput = L" " + wsOutput; - } + *wsOutput = bNeg ? L"DB" : L" " + *wsOutput; ccf -= 2; bAddNeg = true; } break; case '%': { - wsOutput = - pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Percent) + wsOutput; - } + *wsOutput = + pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Percent) + *wsOutput; ccf--; break; + } case ',': - if (cc >= 0) { - wsOutput = wsGroupSymbol + wsOutput; - } + if (cc >= 0) + *wsOutput = wsGroupSymbol + *wsOutput; + ccf--; break; case '(': - if (bNeg) { - wsOutput = L"(" + wsOutput; - } else { - wsOutput = L" " + wsOutput; - } + wsOutput->Insert(0, bNeg ? L'(' : L' '); bAddNeg = true; ccf--; break; case ')': - if (bNeg) { - wsOutput = L")" + wsOutput; - } else { - wsOutput = L" " + wsOutput; - } + wsOutput->Insert(0, bNeg ? L')' : L' '); ccf--; break; case '\'': - wsOutput = GetLiteralTextReverse(strf, ccf) + wsOutput; + *wsOutput = GetLiteralTextReverse(strf, &ccf) + *wsOutput; ccf--; break; default: - wsOutput = strf[ccf] + wsOutput; + wsOutput->Insert(0, strf[ccf]); ccf--; } } + if (cc >= 0) { int nPos = dot_index % 3; - wsOutput.clear(); + wsOutput->clear(); for (int32_t i = 0; i < dot_index; i++) { - if (i % 3 == nPos && i != 0) { - wsOutput += wsGroupSymbol; - } - wsOutput += wsSrcNum[i]; + if (i % 3 == nPos && i != 0) + *wsOutput += wsGroupSymbol; + *wsOutput += wsSrcNum[i]; } if (dot_index < len) { - wsOutput += pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Decimal); - wsOutput += wsSrcNum.Right(len - dot_index - 1); + *wsOutput += pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Decimal); + *wsOutput += wsSrcNum.Right(len - dot_index - 1); } if (bNeg) { - wsOutput = - pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Minus) + wsOutput; + *wsOutput = + pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Minus) + *wsOutput; } return false; } if (dot_index_f == wsNumFormat.GetLength()) { if (!bAddNeg && bNeg) { - wsOutput = - pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Minus) + wsOutput; + *wsOutput = + pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Minus) + *wsOutput; } return true; } @@ -2475,140 +2117,123 @@ bool CFGAS_FormatString::FormatStrNum(const CFX_WideStringC& wsInputNum, CFX_WideString wsDotSymbol = pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Decimal); if (strf[dot_index_f] == 'V') { - wsOutput += wsDotSymbol; + *wsOutput += wsDotSymbol; } else if (strf[dot_index_f] == '.') { - if (dot_index < len) { - wsOutput += wsDotSymbol; - } else { - if (strf[dot_index_f + 1] == '9' || strf[dot_index_f + 1] == 'Z') { - wsOutput += wsDotSymbol; - } - } + if (dot_index < len) + *wsOutput += wsDotSymbol; + else if (strf[dot_index_f + 1] == '9' || strf[dot_index_f + 1] == 'Z') + *wsOutput += wsDotSymbol; } + ccf = dot_index_f + 1; cc = dot_index + 1; while (ccf < lenf) { switch (strf[ccf]) { case '\'': - wsOutput += GetLiteralText(strf, ccf, lenf); + *wsOutput += GetLiteralText(strf, &ccf, lenf); ccf++; break; case '9': if (cc < len) { - if (!FXSYS_isDecimalDigit(str[cc])) { + if (!FXSYS_isDecimalDigit(str[cc])) return false; - } - wsOutput += str[cc]; + + *wsOutput += str[cc]; cc++; } else { - wsOutput += L'0'; + *wsOutput += L'0'; } ccf++; break; case 'z': if (cc < len) { - if (!FXSYS_isDecimalDigit(str[cc])) { + if (!FXSYS_isDecimalDigit(str[cc])) return false; - } - wsOutput += str[cc]; + + *wsOutput += str[cc]; cc++; } ccf++; break; case 'Z': if (cc < len) { - if (!FXSYS_isDecimalDigit(str[cc])) { + if (!FXSYS_isDecimalDigit(str[cc])) return false; - } - wsOutput += str[cc]; + + *wsOutput += str[cc]; cc++; } else { - wsOutput += L'0'; + *wsOutput += L'0'; } ccf++; break; case 'E': { CFX_WideString wsExp; wsExp.Format(L"E%+d", exponent); - wsOutput += wsExp; + *wsOutput += wsExp; ccf++; - } break; + break; + } case '$': - wsOutput += + *wsOutput += pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_CurrencySymbol); ccf++; break; case 'c': if (ccf + 1 < lenf && strf[ccf + 1] == 'r') { - if (bNeg) { - wsOutput += L"CR"; - } + if (bNeg) + *wsOutput += L"CR"; + ccf += 2; bAddNeg = true; } break; case 'C': if (ccf + 1 < lenf && strf[ccf + 1] == 'R') { - if (bNeg) { - wsOutput += L"CR"; - } else { - wsOutput += L" "; - } + *wsOutput += bNeg ? L"CR" : L" "; ccf += 2; bAddNeg = true; } break; case 'd': if (ccf + 1 < lenf && strf[ccf + 1] == 'b') { - if (bNeg) { - wsOutput += L"db"; - } + if (bNeg) + *wsOutput += L"db"; + ccf += 2; bAddNeg = true; } break; case 'D': if (ccf + 1 < lenf && strf[ccf + 1] == 'B') { - if (bNeg) { - wsOutput += L"DB"; - } else { - wsOutput += L" "; - } + *wsOutput += bNeg ? L"DB" : L" "; ccf += 2; bAddNeg = true; } break; case '%': - wsOutput += pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Percent); + *wsOutput += pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Percent); ccf++; break; case '8': while (ccf < lenf && strf[ccf] == '8') ccf++; while (cc < len && FXSYS_isDecimalDigit(str[cc])) { - wsOutput += str[cc]; + *wsOutput += str[cc]; cc++; } break; case ',': - wsOutput += wsGroupSymbol; + *wsOutput += wsGroupSymbol; ccf++; break; case '(': - if (bNeg) { - wsOutput += '('; - } else { - wsOutput += ' '; - } + *wsOutput += bNeg ? '(' : ' '; bAddNeg = true; ccf++; break; case ')': - if (bNeg) { - wsOutput += ')'; - } else { - wsOutput += ' '; - } + *wsOutput += bNeg ? ')' : ' '; ccf++; break; default: @@ -2616,35 +2241,35 @@ bool CFGAS_FormatString::FormatStrNum(const CFX_WideStringC& wsInputNum, } } if (!bAddNeg && bNeg) { - wsOutput = pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Minus) + - wsOutput[0] + wsOutput.Mid(1, wsOutput.GetLength() - 1); + *wsOutput = pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Minus) + + (*wsOutput)[0] + wsOutput->Mid(1, wsOutput->GetLength() - 1); } return true; } bool CFGAS_FormatString::FormatNum(const CFX_WideString& wsSrcNum, const CFX_WideString& wsPattern, - CFX_WideString& wsOutput) { - if (wsSrcNum.IsEmpty() || wsPattern.IsEmpty()) { + CFX_WideString* wsOutput) { + if (wsSrcNum.IsEmpty() || wsPattern.IsEmpty()) return false; - } return FormatStrNum(wsSrcNum.AsStringC(), wsPattern, wsOutput); } bool CFGAS_FormatString::FormatDateTime(const CFX_WideString& wsSrcDateTime, const CFX_WideString& wsPattern, - CFX_WideString& wsOutput, - FX_DATETIMETYPE eDateTimeType) { - if (wsSrcDateTime.IsEmpty() || wsPattern.IsEmpty()) { + FX_DATETIMETYPE eDateTimeType, + CFX_WideString* wsOutput) { + if (wsSrcDateTime.IsEmpty() || wsPattern.IsEmpty()) return false; - } - CFX_WideString wsDatePattern, wsTimePattern; + + CFX_WideString wsDatePattern; + CFX_WideString wsTimePattern; IFX_Locale* pLocale = nullptr; FX_DATETIMETYPE eCategory = - GetDateTimeFormat(wsPattern, pLocale, wsDatePattern, wsTimePattern); - if (!pLocale) { + GetDateTimeFormat(wsPattern, &pLocale, &wsDatePattern, &wsTimePattern); + if (!pLocale) return false; - } + if (eCategory == FX_DATETIMETYPE_Unknown) { if (eDateTimeType == FX_DATETIMETYPE_Time) { wsTimePattern = wsDatePattern; @@ -2652,21 +2277,23 @@ bool CFGAS_FormatString::FormatDateTime(const CFX_WideString& wsSrcDateTime, } eCategory = eDateTimeType; } - if (eCategory == FX_DATETIMETYPE_Unknown) { + if (eCategory == FX_DATETIMETYPE_Unknown) return false; - } + CFX_DateTime dt; int32_t iT = wsSrcDateTime.Find(L"T"); if (iT < 0) { if (eCategory == FX_DATETIMETYPE_Date && FX_DateFromCanonical(wsSrcDateTime, &dt)) { - return FormatDateTimeInternal(dt, wsDatePattern, wsTimePattern, true, - pLocale, wsOutput); + *wsOutput = FormatDateTimeInternal(dt, wsDatePattern, wsTimePattern, true, + pLocale); + return true; } if (eCategory == FX_DATETIMETYPE_Time && FX_TimeFromCanonical(wsSrcDateTime.AsStringC(), &dt, pLocale)) { - return FormatDateTimeInternal(dt, wsDatePattern, wsTimePattern, true, - pLocale, wsOutput); + *wsOutput = FormatDateTimeInternal(dt, wsDatePattern, wsTimePattern, true, + pLocale); + return true; } } else { CFX_WideString wsSrcDate(wsSrcDateTime.c_str(), iT); @@ -2674,63 +2301,55 @@ bool CFGAS_FormatString::FormatDateTime(const CFX_WideString& wsSrcDateTime, wsSrcDateTime.GetLength() - iT - 1); if (wsSrcDate.IsEmpty() || wsSrcTime.IsEmpty()) return false; - if (FX_DateFromCanonical(wsSrcDate, &dt) && FX_TimeFromCanonical(wsSrcTime, &dt, pLocale)) { - return FormatDateTimeInternal(dt, wsDatePattern, wsTimePattern, - eCategory != FX_DATETIMETYPE_TimeDate, - pLocale, wsOutput); + *wsOutput = FormatDateTimeInternal(dt, wsDatePattern, wsTimePattern, + eCategory != FX_DATETIMETYPE_TimeDate, + pLocale); + return true; } } return false; } bool CFGAS_FormatString::FormatZero(const CFX_WideString& wsPattern, - CFX_WideString& wsOutput) { - if (wsPattern.IsEmpty()) { + CFX_WideString* wsOutput) { + if (wsPattern.IsEmpty()) return false; - } - CFX_WideString wsTextFormat; - GetTextFormat(wsPattern, L"zero", wsTextFormat); + + CFX_WideString wsTextFormat = GetTextFormat(wsPattern, L"zero"); int32_t iPattern = 0; const wchar_t* pStrPattern = wsTextFormat.c_str(); int32_t iLenPattern = wsTextFormat.GetLength(); while (iPattern < iLenPattern) { if (pStrPattern[iPattern] == '\'') { - wsOutput += GetLiteralText(pStrPattern, iPattern, iLenPattern); + *wsOutput += GetLiteralText(pStrPattern, &iPattern, iLenPattern); iPattern++; continue; } else { - wsOutput += pStrPattern[iPattern++]; + *wsOutput += pStrPattern[iPattern++]; continue; } } return true; } + bool CFGAS_FormatString::FormatNull(const CFX_WideString& wsPattern, - CFX_WideString& wsOutput) { - if (wsPattern.IsEmpty()) { + CFX_WideString* wsOutput) { + if (wsPattern.IsEmpty()) return false; - } - CFX_WideString wsTextFormat; - GetTextFormat(wsPattern, L"null", wsTextFormat); + + CFX_WideString wsTextFormat = GetTextFormat(wsPattern, L"null"); int32_t iPattern = 0; const wchar_t* pStrPattern = wsTextFormat.c_str(); int32_t iLenPattern = wsTextFormat.GetLength(); while (iPattern < iLenPattern) { if (pStrPattern[iPattern] == '\'') { - wsOutput += GetLiteralText(pStrPattern, iPattern, iLenPattern); + *wsOutput += GetLiteralText(pStrPattern, &iPattern, iLenPattern); iPattern++; continue; - } else { - wsOutput += pStrPattern[iPattern++]; - continue; } + *wsOutput += pStrPattern[iPattern++]; } return true; } - -IFX_Locale* CFGAS_FormatString::GetPatternLocale( - const CFX_WideString& wsLocale) { - return m_pLocaleMgr->GetLocaleByName(wsLocale); -} diff --git a/chromium/third_party/pdfium/xfa/fgas/crt/cfgas_formatstring.h b/chromium/third_party/pdfium/xfa/fgas/crt/cfgas_formatstring.h index d2d35a3042d..c91f43598e6 100644 --- a/chromium/third_party/pdfium/xfa/fgas/crt/cfgas_formatstring.h +++ b/chromium/third_party/pdfium/xfa/fgas/crt/cfgas_formatstring.h @@ -23,15 +23,15 @@ class CFGAS_FormatString { ~CFGAS_FormatString(); void SplitFormatString(const CFX_WideString& wsFormatString, - std::vector<CFX_WideString>& wsPatterns); + std::vector<CFX_WideString>* wsPatterns); FX_LOCALECATEGORY GetCategory(const CFX_WideString& wsPattern); - CFX_WideString GetLocaleName(const CFX_WideString& wsPattern); + bool ParseText(const CFX_WideString& wsSrcText, const CFX_WideString& wsPattern, - CFX_WideString& wsValue); + CFX_WideString* wsValue); bool ParseNum(const CFX_WideString& wsSrcNum, const CFX_WideString& wsPattern, - CFX_WideString& wsValue); + CFX_WideString* wsValue); bool ParseDateTime(const CFX_WideString& wsSrcDateTime, const CFX_WideString& wsPattern, FX_DATETIMETYPE eDateTimeType, @@ -40,35 +40,34 @@ class CFGAS_FormatString { const CFX_WideString& wsPattern); bool ParseNull(const CFX_WideString& wsSrcText, const CFX_WideString& wsPattern); + bool FormatText(const CFX_WideString& wsSrcText, const CFX_WideString& wsPattern, - CFX_WideString& wsOutput); + CFX_WideString* wsOutput); bool FormatNum(const CFX_WideString& wsSrcNum, const CFX_WideString& wsPattern, - CFX_WideString& wsOutput); + CFX_WideString* wsOutput); bool FormatDateTime(const CFX_WideString& wsSrcDateTime, const CFX_WideString& wsPattern, - CFX_WideString& wsOutput, - FX_DATETIMETYPE eDateTimeType); - bool FormatZero(const CFX_WideString& wsPattern, CFX_WideString& wsOutput); - bool FormatNull(const CFX_WideString& wsPattern, CFX_WideString& wsOutput); + FX_DATETIMETYPE eDateTimeType, + CFX_WideString* wsOutput); + bool FormatZero(const CFX_WideString& wsPattern, CFX_WideString* wsOutput); + bool FormatNull(const CFX_WideString& wsPattern, CFX_WideString* wsOutput); private: - IFX_Locale* GetTextFormat(const CFX_WideString& wsPattern, - const CFX_WideStringC& wsCategory, - CFX_WideString& wsPurgePattern); + CFX_WideString GetTextFormat(const CFX_WideString& wsPattern, + const CFX_WideStringC& wsCategory); IFX_Locale* GetNumericFormat(const CFX_WideString& wsPattern, - int32_t& iDotIndex, - uint32_t& dwStyle, - CFX_WideString& wsPurgePattern); + int32_t* iDotIndex, + uint32_t* dwStyle, + CFX_WideString* wsPurgePattern); bool FormatStrNum(const CFX_WideStringC& wsInputNum, const CFX_WideString& wsPattern, - CFX_WideString& wsOutput); + CFX_WideString* wsOutput); FX_DATETIMETYPE GetDateTimeFormat(const CFX_WideString& wsPattern, - IFX_Locale*& pLocale, - CFX_WideString& wsDatePattern, - CFX_WideString& wsTimePattern); - IFX_Locale* GetPatternLocale(const CFX_WideString& wsLocale); + IFX_Locale** pLocale, + CFX_WideString* wsDatePattern, + CFX_WideString* wsTimePattern); CXFA_LocaleMgr* m_pLocaleMgr; }; diff --git a/chromium/third_party/pdfium/xfa/fgas/crt/cfgas_formatstring_unittest.cpp b/chromium/third_party/pdfium/xfa/fgas/crt/cfgas_formatstring_unittest.cpp new file mode 100644 index 00000000000..3adcedf7b27 --- /dev/null +++ b/chromium/third_party/pdfium/xfa/fgas/crt/cfgas_formatstring_unittest.cpp @@ -0,0 +1,661 @@ +// Copyright 2017 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 "xfa/fgas/crt/cfgas_formatstring.h" + +#include <time.h> + +#include <memory> + +#include "core/fpdfapi/cpdf_modulemgr.h" +#include "testing/fx_string_testhelpers.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "testing/test_support.h" +#include "third_party/base/ptr_util.h" +#include "xfa/fxfa/parser/cxfa_localemgr.h" + +class CFGAS_FormatStringTest : public testing::Test { + public: + CFGAS_FormatStringTest() { + SetTZ("UTC"); + CPDF_ModuleMgr::Get()->Init(); + } + + ~CFGAS_FormatStringTest() override { CPDF_ModuleMgr::Get()->Destroy(); } + + void TearDown() override { + fmt_.reset(); + mgr_.reset(); + } + + void SetTZ(const char* tz) { +#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ + _putenv_s("TZ", tz); + _tzset(); +#else + setenv("TZ", tz, 1); + tzset(); +#endif + } + + // Note, this re-creates the fmt on each call. If you need to multiple + // times store it locally. + CFGAS_FormatString* fmt(const CFX_WideString& locale) { + mgr_ = pdfium::MakeUnique<CXFA_LocaleMgr>(nullptr, locale); + fmt_ = pdfium::MakeUnique<CFGAS_FormatString>(mgr_.get()); + return fmt_.get(); + } + + protected: + std::unique_ptr<CXFA_LocaleMgr> mgr_; + std::unique_ptr<CFGAS_FormatString> fmt_; +}; + +// TODO(dsinclair): Looks like the formatter/parser does not handle the various +// 'g' flags. +TEST_F(CFGAS_FormatStringTest, DateFormat) { + struct { + const wchar_t* locale; + const wchar_t* input; + const wchar_t* pattern; + const wchar_t* output; + } tests[] = { + {L"en", L"2002-10-25", L"MMMM DD, YYYY", L"October 25, 2002"}, + // Note, this is in the doc as 5 but it's wrong and should be 3 by the + // example in the Picture Clause Reference section. + {L"en", L"20040722", L"'Week of the month is' w", + L"Week of the month is 3"}, + {L"en", L"20040722", L"e 'days after Sunday'", L"4 days after Sunday"}, + {L"en", L"20040722", L"YYYY-'W'WW-e", L"2004-W30-4"}, + {L"en", L"20040722", L"E 'days after Saturday'", + L"5 days after Saturday"}, + {L"en", L"2000-01-01", L"EEE, 'the' D 'of' MMMM, YYYY", + L"Sat, the 1 of January, 2000"}, + {L"en", L"2000-01-01", L"EEEE, 'the' D 'of' MMMM, YYYY", + L"Saturday, the 1 of January, 2000"}, + {L"en", L"19991202", L"MM/D/YY", L"12/2/99"}, + {L"en", L"19990110", L"MMM D, YYYY", L"Jan 10, 1999"}, + {L"en", L"19990202", L"J", L"33"}, + {L"en", L"19990202", L"JJJ", L"033"}, + {L"en", L"19991231", L"J", L"365"}, + {L"en", L"20001231", L"J", L"366"}, + {L"en", L"19990501", L"J", L"121"}, + {L"en", L"19990901", L"J", L"244"}, + {L"en", L"19990228", L"J", L"59"}, + {L"en", L"20000229", L"J", L"60"}, + {L"en", L"21000501", L"J", L"121"}, + {L"en", L"19990102", L"M", L"1"}, + {L"en", L"19990102", L"MMM", L"Jan"}, + {L"en", L"19990102", L"YYYY G", L"1999 AD"}, + // Week 01 of the year is the week containing Jan 04. + // {L"en", L"19990102", L"WW", L"00"}, -- Returns 01 incorrectly + // {L"en", L"19990104", L"WW", L"01"}, -- Returns 02 incorrectly + // The ?*+ should format as whitespace. + // {L"en", L"19990104", L"YYYY?*+MM", L"1999 01"}, + // {L"en", L"1999-07-16", L"date{DD/MM/YY} '('date{MMM DD, YYYY}')'", + // L"16/07/99 (Jul 16, 1999)"}, + {L"de_CH", L"20041030", L"D. MMMM YYYY", L"30. Oktober 2004"}, + {L"fr_CA", L"20041030", L"D MMMM YYYY", L"30 octobre 2004"}, + {L"en", L"2002-10-25", L"date(fr){DD MMMM, YYYY}", L"25 octobre, 2002"}, + {L"en", L"2002-10-25", L"date(es){EEEE, D 'de' MMMM 'de' YYYY}", + L"viernes, 25 de octubre de 2002"}, + // {L"en", L"2002-20-25", L"date.long(fr)()", L"25 octobre, 2002"}, + // {L"ja", L"2003-11-03", L"gY/M/D", L"H15/11/3"}, + // {L"ja", L"1989-01-08", L"ggY-M-D", L"\u5e731-1-8"}, + // {L"ja", L"1989-11-03", L"gggYY/MM/DD", L"\u5e73\u621089/11/03"}, + }; + // Note, none of the full width date symbols are listed here + // as they are not supported. In theory there are the full width versions + // of DDD, DDDD, MMM, MMMM, E, e, gg, YYY, YYYYY. + + for (size_t i = 0; i < FX_ArraySize(tests); ++i) { + CFX_WideString result; + EXPECT_TRUE(fmt(tests[i].locale) + ->FormatDateTime(tests[i].input, tests[i].pattern, + FX_DATETIMETYPE_Date, &result)); + EXPECT_STREQ(tests[i].output, result.c_str()) << " TEST: " << i; + } +} + +TEST_F(CFGAS_FormatStringTest, TimeFormat) { + struct { + const wchar_t* locale; + const wchar_t* input; + const wchar_t* pattern; + const wchar_t* output; + } tests[] = {{L"en", L"01:01:11", L"h:M A", L"1:1 AM"}, + {L"en", L"13:01:11", L"h:M A", L"1:1 PM"}, + {L"en", L"01:01:11", L"hh:MM:SS A", L"01:01:11 AM"}, + {L"en", L"13:01:11", L"hh:MM:SS A", L"01:01:11 PM"}, + {L"en", L"01:01:11", L"hh:MM:SS A Z", L"01:01:11 AM GMT-02:00"}, + {L"en", L"01:01:11", L"hh:MM:SS A z", L"01:01:11 AM -02:00"}, + // {L"en", L"01:01:11", L"hh:MM:SS A zz", L"01:01:11 AM GMT"}, + // Should change ?*+ into ' ' when formatting. + // {L"en", L"01:01:11", L"hh:MM:SS?*+A", L"01:01:11 AM"}, + {L"en", L"12:01:01", L"k:MM:SS", L"12:01:01"}, + {L"en", L"14:01:01", L"k:MM:SS", L"2:01:01"}, + {L"en", L"12:01:11", L"kk:MM", L"12:01"}, + {L"en", L"14:01:11", L"kk:MM", L"02:01"}, + {L"en", L"12:01:11 +04:30", L"kk:MM", L"05:31"}, + {L"en", L"12:01:11", L"kk:MM A", L"12:01 PM"}, + {L"en", L"00:01:01", L"H:M:S", L"0:1:1"}, + {L"en", L"13:02:11", L"H:M:S", L"13:2:11"}, + {L"en", L"00:01:11.001", L"HH:M:S.FFF", L"00:1:11.001"}, + {L"en", L"13:02:11", L"HH:M", L"13:2"}, + {L"en", L"00:01:11", L"K:M", L"24:1"}, + {L"en", L"00:02:11", L"KK:M", L"24:2"}, + {L"en", L"11:11:11", L"HH:MM:SS 'o''clock' A Z", + L"11:11:11 o'clock AM GMT-02:00"}, + {L"en", L"14:30:59", L"h:MM A", L"2:30 PM"}, + {L"en", L"14:30:59", L"HH:MM:SS A Z", L"14:30:59 PM GMT-02:00"}}; + // Note, none of the full width time symbols are listed here + // as they are not supported. In theory there are the full + // width versions of kkk, kkkk, HHH, HHHH, KKK, KKKK, MMM, MMMM, + // SSS, SSSS plus 2 more that the spec apparently forgot to + // list the symbol. + + // The z modifier only appends if the TZ is outside of +0 + SetTZ("UTC+2"); + + for (size_t i = 0; i < FX_ArraySize(tests); ++i) { + CFX_WideString result; + EXPECT_TRUE(fmt(tests[i].locale) + ->FormatDateTime(tests[i].input, tests[i].pattern, + FX_DATETIMETYPE_Time, &result)); + EXPECT_STREQ(tests[i].output, result.c_str()) << " TEST: " << i; + } + + SetTZ("UTC"); +} + +TEST_F(CFGAS_FormatStringTest, DateTimeFormat) { + struct { + const wchar_t* locale; + const wchar_t* input; + const wchar_t* pattern; + const wchar_t* output; + } tests[] = { + {L"en", L"1999-07-16T10:30Z", + L"'At' time{HH:MM Z} 'on' date{MMM DD, YYYY}", + L"At 10:30 GMT on Jul 16, 1999"}, + {L"en", L"1999-07-16T10:30", L"'At' time{HH:MM} 'on' date{MMM DD, YYYY}", + L"At 10:30 on Jul 16, 1999"}, + {L"en", L"1999-07-16T10:30Z", + L"time{'At' HH:MM Z} date{'on' MMM DD, YYYY}", + L"At 10:30 GMT on Jul 16, 1999"}, + {L"en", L"1999-07-16T10:30Z", + L"time{'At 'HH:MM Z}date{' on 'MMM DD, YYYY}", + L"At 10:30 GMT on Jul 16, 1999"}}; + + for (size_t i = 0; i < FX_ArraySize(tests); ++i) { + CFX_WideString result; + EXPECT_TRUE(fmt(tests[i].locale) + ->FormatDateTime(tests[i].input, tests[i].pattern, + FX_DATETIMETYPE_TimeDate, &result)); + EXPECT_STREQ(tests[i].output, result.c_str()) << " TEST: " << i; + } +} + +TEST_F(CFGAS_FormatStringTest, DateParse) { + struct { + const wchar_t* locale; + const wchar_t* input; + const wchar_t* pattern; + CFX_DateTime output; + } tests[] = { + {L"en", L"12/2/99", L"MM/D/YY", CFX_DateTime(1999, 12, 2, 0, 0, 0, 0)}, + {L"en", L"2/2/99", L"M/D/YY", CFX_DateTime(1999, 2, 2, 0, 0, 0, 0)}, + {L"en", L"2/2/10", L"M/D/YY", CFX_DateTime(2010, 2, 2, 0, 0, 0, 0)}, + {L"en", L"Jan 10, 1999", L"MMM D, YYYY", + CFX_DateTime(1999, 1, 10, 0, 0, 0, 0)}, + {L"en", L"Jan 10, 1999 AD", L"MMM D, YYYY G", + CFX_DateTime(1999, 1, 10, 0, 0, 0, 0)}, + // TODO(dsinclair): Should this be -2 instead of 2? + {L"en", L"Jan 10, 0002 BC", L"MMM D, YYYY G", + CFX_DateTime(2, 1, 10, 0, 0, 0, 0)}, + {L"en", L"October 25, 2002", L"MMMM DD, YYYY", + CFX_DateTime(2002, 10, 25, 0, 0, 0, 0)}, + // TODO(dsinclair): The J and JJJ are ignored during parsing when they + // could be turned back into a date. + {L"en", L"1999-33", L"YYYY-J", CFX_DateTime(1999, 1, 1, 0, 0, 0, 0)}, + {L"en", L"1999-033", L"YYYY-JJJ", CFX_DateTime(1999, 1, 1, 0, 0, 0, 0)}, + {L"de_CH", L"30. Oktober 2004", L"D. MMMM YYYY", + CFX_DateTime(2004, 10, 30, 0, 0, 0, 0)}, + {L"fr_CA", L"30 octobre 2004", L"D MMMM YYYY", + CFX_DateTime(2004, 10, 30, 0, 0, 0, 0)}, + {L"en", L"Saturday, the 1 of January, 2000", + L"EEEE, 'the' D 'of' MMMM, YYYY", CFX_DateTime(2000, 1, 1, 0, 0, 0, 0)}, + {L"en", L"Sat, the 1 of January, 2000", L"EEE, 'the' D 'of' MMMM, YYYY", + CFX_DateTime(2000, 1, 1, 0, 0, 0, 0)}, + {L"en", L"7, the 1 of January, 2000", // 7 == Saturday as 1 == Sunday + L"E, 'the' D 'of' MMMM, YYYY", CFX_DateTime(2000, 1, 1, 0, 0, 0, 0)}, + {L"en", L"6, the 1 of January, 2000", // 6 == Saturday as 1 == Monday + L"e, 'the' D 'of' MMMM, YYYY", CFX_DateTime(2000, 1, 1, 0, 0, 0, 0)}, + {L"en", L"2004-07-22 Week of the month is 3", + L"YYYY-MM-DD 'Week of the month is' w", + CFX_DateTime(2004, 7, 22, 0, 0, 0, 0)}, + {L"en", L"2004-07-22 Week of the year is 03", + L"YYYY-MM-DD 'Week of the year is' WW", + CFX_DateTime(2004, 7, 22, 0, 0, 0, 0)} + // {L"ja", L"H15/11/3", L"gY/M/D", CFX_DateTime(2003, 11, 3, 0, 0, 0, 0)}, + // {L"ja", L"\u5e731-1-8", L"ggY-M-D", CFX_DateTime(1989, 1, 8, 0, 0, 0, + // 0)}, {L"ja", L"\u5e73\u621089/11/03", L"gggYY/MM/DD", + // CFX_DateTime(1989, 11, 3, 0, 0, 0, 0)}, + // {L"ja", L"u337b99/01/08", L"\u0067\u0067YY/MM/DD", + // CFX_DateTime(1999, 1, 8, 0, 0, 0, 0)} + }; + // Note, none of the full width date symbols are listed here as they are + // not supported. In theory there are the full width versions of DDD, + // DDDD, MMM, MMMM, E, e, gg, YYY, YYYYY. + + for (size_t i = 0; i < FX_ArraySize(tests); ++i) { + CFX_DateTime result; + EXPECT_TRUE(fmt(tests[i].locale) + ->ParseDateTime(tests[i].input, tests[i].pattern, + FX_DATETIMETYPE_Date, &result)); + EXPECT_EQ(tests[i].output, result) << " TEST: " << i; + } +} + +// TODO(dsinclair): GetDateTimeFormat is broken and doesn't allow just returning +// a parsed Time. It will assume it's a Date. The method needs to be re-written. +// TEST_F(CFGAS_FormatStringTest, TimeParse) { +// struct { +// const wchar_t* locale; +// const wchar_t* input; +// const wchar_t* pattern; +// CFX_DateTime output; +// } tests[] = { +// {L"en", L"18:00", L"HH:MM", CFX_DateTime(0, 0, 0, 18, 0, 0, 0)}, +// {L"en", L"12.59 Uhr", L"H.MM 'Uhr'", CFX_DateTime(0, 0, 0, 12, 59, 0, +// 0)}, {L"en", L"1:05:10 PM PST", L"h:MM:SS A Z", +// CFX_DateTime(0, 0, 0, 17, 05, 10, 0)}}; +// // Note, none of the full width date symbols are listed here as they are +// // not supported. In theory there are the full width versions of kkk, +// // kkkk, HHH, HHHH, KKK, KKKK, MMM, MMMM, SSS, SSSS plus 2 more that the +// // spec apparently forgot to list the symbol. + +// for (size_t i = 0; i < FX_ArraySize(tests); ++i) { +// CFX_DateTime result; +// EXPECT_TRUE(fmt(tests[i].locale) +// ->ParseDateTime(tests[i].input, tests[i].pattern, +// FX_DATETIMETYPE_Time, &result)); +// EXPECT_EQ(tests[i].output, result) << " TEST: " << i; +// } +// } + +TEST_F(CFGAS_FormatStringTest, SplitFormatString) { + std::vector<CFX_WideString> results; + fmt(L"en")->SplitFormatString( + L"null{'No data'} | null{} | text{999*9999} | text{999*999*9999}", + &results); + EXPECT_EQ(4UL, results.size()); + + const wchar_t* patterns[] = {L"null{'No data'} ", L" null{} ", + L" text{999*9999} ", L" text{999*999*9999}"}; + + for (size_t i = 0; i < results.size(); ++i) { + EXPECT_STREQ(patterns[i], results[i].c_str()); + } +} + +TEST_F(CFGAS_FormatStringTest, NumParse) { + struct { + const wchar_t* locale; + const wchar_t* input; + const wchar_t* pattern; + const wchar_t* output; + } tests[] = { + // {L"en", L"€100.00", L"num(en_GB){$z,zz9.99}", L"100"}, + // {L"en", L"1050", L"99V99", L"10.50"}, + // {L"en", L"3125", L"99V99", L"31.25"}, + {L"en", L"12.345e3", L"99.999E", L"12345.000000"}, + {L"en", L"12.345e+3", L"99.999E", L"12345.000000"}, + {L"en", L"12.345E-2", L"99.999E", L"0.123450"}, + // TODO(dsinclair): Returns 0.000? + // {L"en", L"12e-2", L"99E", L"0.12"}, + {L"en", L"150", L"z999", L"150"}, + {L"en", L"150.50$", L"zzz.zz$", L"150.50"}, + {L"en", L"0150", L"z999", L"0150"}, + {L"en", L"123CR", L"999cr", L"-123"}, + {L"en", L"123", L"999cr", L"123"}, + {L"en", L"123CR", L"999CR", L"-123"}, + {L"en", L"123 ", L"999CR", L"123"}, + {L"en", L"123DB", L"999db", L"-123"}, + {L"en", L"123", L"999db", L"123"}, + {L"en", L"123DB", L"999DB", L"-123"}, + {L"en", L"123 ", L"999DB", L"123"}, + {L"en", L"123.5CR", L"999.9cr", L"-123.5"}, + {L"en", L"123.5", L"999.9cr", L"123.5"}, + {L"en", L"123.5CR", L"999.9CR", L"-123.5"}, + // {L"en", L"123.5 ", L"999.9CR", L"123.5"}, + {L"en", L"123.5DB", L"999.9db", L"-123.5"}, + {L"en", L"123.5", L"999.9db", L"123.5"}, + {L"en", L"123.5DB", L"999.9DB", L"-123.5"}, + // {L"en", L"123.5 ", L"999.9DB", L"123.5"}, + {L"en", L"10.50", L"z,zz9.99", L"10.50"}, + {L"en", L"3,125.00", L"z,zz9.99", L"3125.00"}, + {L"en", L"$1,234.00", L"$z,zz9.99DB", L"1234.00"}, + // TODO(dsinclair): Comes out as 1234 instead of -1234. + // {L"en", L"$,1234.00DB", L"$z,zz9.99DB", L"-1234.00"}, + {L"en", L"1.234", L"zz9.zzz", L"1.234"}, + {L"en", L"1 text", L"num{z 'text'}", L"1"}, + {L"en", L"1.234 text", L"z.zzz 'text'", L"1.234"}, + {L"en", L" 1.234", L"ZZ9.ZZZ", L"1.234"}, + {L"en", L"12.345", L"zz9.zzz", L"12.345"}, + {L"en", L" 12.345", L"ZZ9.ZZZ", L"12.345"}, + {L"en", L"123.456", L"zz9.zzz", L"123.456"}, + {L"en", L"123.456", L"ZZ9.ZZZ", L"123.456"}, + {L"en", L"123.456-", L"ZZ9.ZZZS", L"-123.456"}, + {L"en", L"123.456+", L"ZZ9.ZZZS", L"123.456"}, + {L"en", L"123.456 ", L"ZZ9.ZZZS", L"123.456"}, + {L"en", L"123.456-", L"ZZ9.ZZZS", L"-123.456"}, + {L"en", L"123.456+", L"ZZ9.ZZZS", L"123.456"}, + {L"en", L"123", L"zz9.zzz", L"123"}, + {L"en", L"123.", L"ZZ9.ZZZ", L"123."}, + {L"en", L"123.", L"zz9.zzz", L"123."}, + {L"en", L"123.", L"ZZ9.ZZZ", L"123."}, + {L"en", L"123.0", L"zz9.zzz", L"123.0"}, + {L"en", L"123.0", L"ZZ9.ZZZ", L"123.0"}, + {L"en", L"123.000", L"zz9.zzz", L"123.000"}, + {L"en", L"123.000", L"ZZ9.ZZZ", L"123.000"}, + {L"en", L"12,345.67", L"zzz,zz9.88888888", L"12345.67"}, + {L"en", L"12,345.0000", L"zzz,zz9.88888888", L"12345.0000"}, + {L"en", L"12,345.6789", L"zzz,zz9.8", L"12345.6789"}, + {L"en", L"12,345.", L"zzz,zz9.8", L"12345."}, + {L"en", L"123,456.000", L"zzz,zz9.8888", L"123456.000"}, + {L"en", L"123,456.0", L"zzz,zz9.8888", L"123456.0"}, + {L"en", L"123,456", L"zzz,zz9.8888", L"123456"}, + {L"en", L"123,456", L"ZZZ,ZZ9.88", L"123456"}, + {L"en", L"12,345.67", L"zzz,zz9.88888888", L"12345.67"}, + {L"en", L"12,345.0000", L"zzz,zz9.88888888", L"12345.0000"}, + {L"en", L"12,345.6789", L"zzz,zz9.8", L"12345.6789"}, + {L"en", L"12,345.", L"zzz,zz9.8", L"12345."}, + // TODO(dsinclair): Parses to 0 + // {L"en", L"12%", L"zz9.%%", L".12"}, + {L"en", L"1,234.50%", L"zzz,zz9.99%%", L"12.345"}, + // {L"en", L"-00123", L"S999v99", L"-1.23"}, + {L"en", L" 001.23", L"S999V99", L"001.23"}, + // {L"en", L" 123.00", L"S999V99", L"123"}, + {L"en", L" 12.30", L"SZZ9.99", L"12.30"}, + {L"en", L"- 12.30", L"SZ99.99", L"-12.30"}, + {L"en", L"123.00", L"szz9.99", L"123.00"}, + {L"en", L"-123.00", L"szz9.99", L"-123.00"}, + // {L"en", L"$ 1,234.00 ", L"$ZZ,ZZ9.99CR", L"1234"}, + // {L"en", L"$ 1,234.00CR", L"$ZZ,ZZ9.99CR", L"-1234"}, + // {L"en", L"$1,23400", L"$z,zz9.99DB", L"1234"}, + {L"en", L"$1,234.00DB", L"$z,zz9.99DB", L"-1234.00"}, + {L"en", + L"1\xA0" + L"234", + L"num(fr){z,zzz}", L"1234"}, + // TODO(dsinclair): Parses to blank + // {L"en", L"1,234%", L"num.percent{}", L"12.34"}, + // {L"en", L"1\xA0" L"234%%", L"num(fr).percent{}", L"12.34"}, + // TODO(dsinclair): Parses to blank + // {L"en", L"1,234%", L"num{9,999%%}", L"12.34"}, + {L"fr", + L"123\xA0" + L"456", + L"zzz,zzz", L"123456"}, + {L"en", L"12%", L"zz%", L"0.12"}, + {L"en", L"(123", L"(zzz", L"-123"}, + {L"en", L"123)", L"zzz)", L"-123"}, + {L"en", L"(123)", L"(zzz)", L"-123"}, + {L"en", L"123 ", L"zzz)", L"123"}, + {L"en", L" 123", L"(zzz", L"123"}, + {L"en", L" 123 ", L"(zzz)", L"123"}, + {L"en", L"123.5(", L"zzz.z(", L"-123.5"}, + {L"en", L"123.5)", L"zzz.z)", L"-123.5"}, + {L"en", L"123.5 ", L"zzz.z)", L"123.5"}, + {L"en", L"123.5 ", L"zzz.z(", L"123.5"}, + {L"en", L"123.545,4", L"zzz.zzz,z", L"123.5454"}, + }; + + for (size_t i = 0; i < FX_ArraySize(tests); ++i) { + CFX_WideString result; + EXPECT_TRUE(fmt(tests[i].locale) + ->ParseNum(tests[i].input, tests[i].pattern, &result)) + << " TEST: " << i; + EXPECT_STREQ(tests[i].output, result.c_str()) << " TEST: " << i; + } +} + +TEST_F(CFGAS_FormatStringTest, NumFormat) { + struct { + const wchar_t* locale; + const wchar_t* input; + const wchar_t* pattern; + const wchar_t* output; + } tests[] = { + {L"en", L"1.234", L"zz9.zzz", L"1.234"}, + {L"en", L"1", L"num{z 'text'}", L"1 text"}, + {L"en", L"1", L"num{'text' z}", L"text 1"}, + {L"en", L"1.234", L"ZZ9.ZZZ", L" 1.234"}, + {L"en", L"12.345", L"zz9.zzz", L"12.345"}, + {L"en", L"12.345", L"ZZ9.ZZZ", L" 12.345"}, + {L"en", L"123.456", L"zz9.zzz", L"123.456"}, + {L"en", L"123.456", L"ZZ9.ZZZ", L"123.456"}, + {L"en", L"123", L"zz9.zzz", L"123"}, + {L"en", L"123", L"ZZ9.ZZZ", L"123.000"}, + {L"en", L"123.", L"zz9.zzz", L"123."}, + {L"en", L"123.", L"ZZ9.ZZZ", L"123.000"}, + {L"en", L"123.0", L"zz9.zzz", L"123"}, + {L"en", L"123.0", L"ZZ9.ZZZ", L"123.000"}, + {L"en", L"123.000", L"zz9.zzz", L"123"}, + {L"en", L"123.000", L"ZZ9.ZZZ", L"123.000"}, + // {L"en", L"12345.67", L"zzz,zz9.88888888", L"12,345.67"}, + // {L"en", L"12345.0000", L"zzz,zz9.88888888", L"12,345.0000"}, + // {L"en", L"12345.6789", L"zzz,zz9.8", L"12,345.6789"}, + // {L"en", L"12345.", L"zzz,zz9.8", L"12,345"}, + // {L"en", L"123456.000", L"zzz,zz9.8888", L"123,456.000"}, + // {L"en", L"123456.0", L"zzz,zz9.8888", L"123,456.0"}, + {L"en", L"123456", L"zzz,zz9.8888", L"123,456"}, + {L"en", L"123456", L"ZZZ,ZZ9.88", L"123,456"}, + // {L"en", L"12345.67", L"zzz,zz9.88888888", L"12,345.67"}, + // {L"en", L"12345.0000", L"zzz,zz9.88888888", L"12,345.0000"}, + // {L"en", L"12345.6789", L"zzz,zz9.8", L"12,345.6789"}, + // {L"en", L"12345.", L"zzz,zz9.8", L"12,345"}, + // {L"en", L"12%%", L"zz9.%%", L"12%%"}, + // {L"en", L"1,234.5%%", L"zzz,zz9.99%%", L"1,234.50%%"}, + {L"en", L"-1.23", L"S999v99", L"-00123"}, + {L"en", L"1.23", L"S999V99", L" 001.23"}, + {L"en", L"123", L"S999V99", L" 123.00"}, + {L"en", L"12.3", L"SZZ9.99", L" 12.30"}, + {L"en", L"-12.3", L"SZ99.99", L"- 12.30"}, + {L"en", L"123", L"szz9.99", L"123.00"}, + {L"en", L"-123", L"szz9.99", L"-123.00"}, + // {L"en", L"1234", L"$ZZ,ZZ9.99CR", L"$ 1,234.00 "}, + // {L"en", L"-1234", L"$ZZ,ZZ9.99CR", L"$ 1,234.00CR"}, + // {L"en", L"1234", L"$z,zz9.99DB", L"$1,234.00"}, + {L"en", L"-1234", L"$z,zz9.99DB", L"$1,234.00DB"}, + {L"en", L"12345", L"99.999E", L"12.345E+3"}, + {L"en", L"12345", L"99999E", L"12345E+0"}, + {L"en", L".12345", L"99.999E", L"12.345E-2"}, + {L"en", L"12345", L"99,999", L"12,345"}, + {L"en", L"1234", L"num(fr){z,zzz}", + L"1\xA0" + L"234"}, + {L"en", L"12.34", L"num.percent{}", L"1,234%"}, + {L"en", L"12.34", L"num(fr).percent{}", + L"1\xA0" + L"234%"}, + // {L"en", L"12.34", L"num{9,999%%}", L"1,234%"}, + {L"en", L"-123", L"zzzCR", L"123CR"}, + {L"en", L"123", L"zzzCR", L"123 "}, + {L"en", L"-123", L"zzzcr", L"123CR"}, + {L"en", L"123", L"zzzcr", L"123"}, + {L"en", L"123", L"zzz$", L"123$"}, + {L"en", L"-123.5", L"zzz.zCR", L"123.5CR"}, + {L"en", L"123.5", L"zzz.zCR", L"123.5 "}, + {L"en", L"-123.5", L"zzz.zcr", L"123.5CR"}, + {L"en", L"123.5", L"zzz.zcr", L"123.5"}, + + {L"en", L"-123.5", L"999.9db", L"123.5db"}, + {L"en", L"123.5", L"999.9db", L"123.5"}, + {L"en", L"-123.5", L"999.9DB", L"123.5DB"}, + {L"en", L"123.5", L"999.9DB", L"123.5 "}, + + {L"en", L"-123", L"(zzz", L"(123"}, + // {L"en", L"-123", L"zzz)", L"123)"}, + {L"en", L"-123", L"(zzz)", L"(123)"}, + {L"en", L"123", L"zzz)", L"123 "}, + {L"en", L"123", L"(zzz", L" 123"}, + {L"en", L"123", L"(zzz)", L" 123 "}, + {L"en", L"-123.5", L"zzz.z(", L"123.5("}, + // {L"en", L"-123.5", L"zzz.z)", L"123.5)"}, + {L"en", L"123.5", L"zzz.z)", L"123.5 "}, + {L"en", L"123.5", L"zzz.z(", L"123.5 "}, + }; + + for (size_t i = 0; i < FX_ArraySize(tests); ++i) { + CFX_WideString result; + EXPECT_TRUE(fmt(tests[i].locale) + ->FormatNum(tests[i].input, tests[i].pattern, &result)) + << " TEST: " << i; + EXPECT_STREQ(tests[i].output, result.c_str()) << " TEST: " << i; + } +} + +TEST_F(CFGAS_FormatStringTest, TextParse) { + struct { + const wchar_t* locale; + const wchar_t* input; + const wchar_t* pattern; + const wchar_t* output; + } tests[] = {// TODO(dsinclair) Missing support for the global modifiers: + // ? - wildcard + // * - zero or more whitespace + // + - one or more whitespace + // {L"en", L"555-1212", L"text(th_TH){999*9999}", L"5551212"}, + {L"en", L"ABC-1234-5", L"AAA-9999-X", L"ABC12345"}, + {L"en", L"ABC-1234-D", L"AAA-9999-X", L"ABC1234D"}, + {L"en", L"A1C-1234-D", L"OOO-9999-X", L"A1C1234D"}, + {L"en", L"A1C-1234-D", L"000-9999-X", L"A1C1234D"}, + {L"en", L"A1C-1234-D text", L"000-9999-X 'text'", L"A1C1234D"}}; + + for (size_t i = 0; i < FX_ArraySize(tests); ++i) { + CFX_WideString result; + EXPECT_TRUE(fmt(tests[i].locale) + ->ParseText(tests[i].input, tests[i].pattern, &result)); + EXPECT_STREQ(tests[i].output, result.c_str()) << " TEST: " << i; + } +} + +TEST_F(CFGAS_FormatStringTest, InvalidTextParse) { + // Input does not match mask. + CFX_WideString result; + EXPECT_FALSE(fmt(L"en")->ParseText(L"123-4567-8", L"AAA-9999-X", &result)); +} + +TEST_F(CFGAS_FormatStringTest, TextFormat) { + struct { + const wchar_t* locale; + const wchar_t* input; + const wchar_t* pattern; + const wchar_t* output; + } tests[] = { + {L"en", L"K1S5K2", L"A9A 9A9", L"K1S 5K2"}, + {L"en", L"K1S5K2", L"text(fr){A9A 9A9}", L"K1S 5K2"}, + {L"en", L"6135551212", L"'+1 ('9\u002399') '999-9999", + L"+1 (6#13) 555-1212"}, + {L"en", L"6135551212", L"999.999.9999", L"613.555.1212"}, + {L"en", L"6135551212", L"999\u0023999\u002A9999", L"613#555*1212"}, + {L"en", L"K1#5K2", L"00X OO9", L"K1# 5K2"}, + }; + + for (size_t i = 0; i < FX_ArraySize(tests); ++i) { + CFX_WideString result; + EXPECT_TRUE(fmt(tests[i].locale) + ->FormatText(tests[i].input, tests[i].pattern, &result)); + EXPECT_STREQ(tests[i].output, result.c_str()) << " TEST: " << i; + } +} + +TEST_F(CFGAS_FormatStringTest, NullParse) { + struct { + const wchar_t* locale; + const wchar_t* input; + const wchar_t* pattern; + } tests[] = { + {L"en", L"", L"null{}"}, {L"en", L"No data", L"null{'No data'}"}, + }; + + for (size_t i = 0; i < FX_ArraySize(tests); ++i) { + EXPECT_TRUE( + fmt(tests[i].locale)->ParseNull(tests[i].input, tests[i].pattern)) + << " TEST: " << i; + } +} + +TEST_F(CFGAS_FormatStringTest, NullFormat) { + struct { + const wchar_t* locale; + const wchar_t* pattern; + const wchar_t* output; + } tests[] = {{L"en", L"null{'n/a'}", L"n/a"}, {L"en", L"null{}", L""}}; + + for (size_t i = 0; i < FX_ArraySize(tests); ++i) { + CFX_WideString result; + EXPECT_TRUE(fmt(tests[i].locale)->FormatNull(tests[i].pattern, &result)); + EXPECT_STREQ(tests[i].output, result.c_str()) << " TEST: " << i; + } +} + +TEST_F(CFGAS_FormatStringTest, ZeroParse) { + struct { + const wchar_t* locale; + const wchar_t* input; + const wchar_t* pattern; + } tests[] = {{L"en", L"", L"zero{}"}, + {L"en", L"9", L"zero{9}"}, + {L"en", L"a", L"zero{'a'}"}}; + + for (size_t i = 0; i < FX_ArraySize(tests); ++i) { + EXPECT_TRUE( + fmt(tests[i].locale)->ParseZero(tests[i].input, tests[i].pattern)) + << " TEST: " << i; + } +} + +TEST_F(CFGAS_FormatStringTest, ZeroFormat) { + struct { + const wchar_t* locale; + const wchar_t* input; + const wchar_t* pattern; + const wchar_t* output; + } tests[] = {// TODO(dsinclair): The zero format can take a number specifier + // which we don't take into account. + // {L"en", L"", L"zero {9}", L""}, + // {L"en", L"0", L"zero {9}", L"0"}, + // {L"en", L"0.0", L"zero{9}", L"0"}, + {L"en", L"0", L"zero{}", L""}}; + + for (size_t i = 0; i < FX_ArraySize(tests); ++i) { + CFX_WideString result; + EXPECT_TRUE( + fmt(tests[i].locale) + ->FormatZero(/* tests[i].input,*/ tests[i].pattern, &result)); + EXPECT_STREQ(tests[i].output, result.c_str()) << " TEST: " << i; + } +} + +TEST_F(CFGAS_FormatStringTest, GetCategory) { + CFGAS_FormatString* f = fmt(L"en"); + + EXPECT_EQ(FX_LOCALECATEGORY_Unknown, f->GetCategory(L"'just text'")); + EXPECT_EQ(FX_LOCALECATEGORY_Null, f->GetCategory(L"null{}")); + EXPECT_EQ(FX_LOCALECATEGORY_Zero, f->GetCategory(L"zero{}")); + EXPECT_EQ(FX_LOCALECATEGORY_Num, f->GetCategory(L"num{}")); + EXPECT_EQ(FX_LOCALECATEGORY_Text, f->GetCategory(L"text{}")); + EXPECT_EQ(FX_LOCALECATEGORY_DateTime, f->GetCategory(L"datetime{}")); + EXPECT_EQ(FX_LOCALECATEGORY_Time, f->GetCategory(L"time{}")); + EXPECT_EQ(FX_LOCALECATEGORY_Date, f->GetCategory(L"date{}")); + EXPECT_EQ(FX_LOCALECATEGORY_DateTime, f->GetCategory(L"time{} date{}")); + EXPECT_EQ(FX_LOCALECATEGORY_DateTime, f->GetCategory(L"date{} time{}")); + EXPECT_EQ(FX_LOCALECATEGORY_Num, f->GetCategory(L"num(en_GB){}")); + EXPECT_EQ(FX_LOCALECATEGORY_Date, f->GetCategory(L"date.long{}")); +} diff --git a/chromium/third_party/pdfium/xfa/fgas/font/cfgas_fontmgr.cpp b/chromium/third_party/pdfium/xfa/fgas/font/cfgas_fontmgr.cpp index 8430d4f834e..6f86c7ca071 100644 --- a/chromium/third_party/pdfium/xfa/fgas/font/cfgas_fontmgr.cpp +++ b/chromium/third_party/pdfium/xfa/fgas/font/cfgas_fontmgr.cpp @@ -940,7 +940,12 @@ FXFT_Face CFGAS_FontMgr::LoadFace( if (!library) return nullptr; - FXFT_Stream ftStream = FX_Alloc(FXFT_StreamRec, 1); + // TODO(palmer): This memory will be freed with |ft_free| (which is |free|). + // Ultimately, we want to change this to: + // FXFT_Stream ftStream = FX_Alloc(FXFT_StreamRec, 1); + // https://bugs.chromium.org/p/pdfium/issues/detail?id=690 + FXFT_Stream ftStream = + static_cast<FXFT_Stream>(ft_scalloc(sizeof(FXFT_StreamRec), 1)); memset(ftStream, 0, sizeof(FXFT_StreamRec)); ftStream->base = nullptr; ftStream->descriptor.pointer = static_cast<void*>(pFontStream.Get()); @@ -956,7 +961,7 @@ FXFT_Face CFGAS_FontMgr::LoadFace( FXFT_Face pFace = nullptr; if (FXFT_Open_Face(library, &ftArgs, iFaceIndex, &pFace)) { - FX_Free(ftStream); + ft_sfree(ftStream); return nullptr; } diff --git a/chromium/third_party/pdfium/xfa/fwl/cfwl_app.cpp b/chromium/third_party/pdfium/xfa/fwl/cfwl_app.cpp index febc8a0fdf8..e762125ba84 100644 --- a/chromium/third_party/pdfium/xfa/fwl/cfwl_app.cpp +++ b/chromium/third_party/pdfium/xfa/fwl/cfwl_app.cpp @@ -10,7 +10,7 @@ #include "xfa/fwl/cfwl_notedriver.h" #include "xfa/fwl/cfwl_widget.h" #include "xfa/fwl/cfwl_widgetmgr.h" -#include "xfa/fxfa/app/xfa_fwladapter.h" +#include "xfa/fxfa/app/cxfa_fwladapterwidgetmgr.h" CFWL_App::CFWL_App(CXFA_FFApp* pAdapter) : m_pAdapterNative(pAdapter), diff --git a/chromium/third_party/pdfium/xfa/fwl/cfwl_barcode.cpp b/chromium/third_party/pdfium/xfa/fwl/cfwl_barcode.cpp index 378bb8e06b4..b51bb243663 100644 --- a/chromium/third_party/pdfium/xfa/fwl/cfwl_barcode.cpp +++ b/chromium/third_party/pdfium/xfa/fwl/cfwl_barcode.cpp @@ -35,7 +35,7 @@ void CFWL_Barcode::Update() { GenerateBarcodeImageCache(); } -void CFWL_Barcode::DrawWidget(CFX_Graphics* pGraphics, +void CFWL_Barcode::DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) { if (!pGraphics) return; diff --git a/chromium/third_party/pdfium/xfa/fwl/cfwl_barcode.h b/chromium/third_party/pdfium/xfa/fwl/cfwl_barcode.h index 0620541c2f7..c913a17b104 100644 --- a/chromium/third_party/pdfium/xfa/fwl/cfwl_barcode.h +++ b/chromium/third_party/pdfium/xfa/fwl/cfwl_barcode.h @@ -45,7 +45,7 @@ class CFWL_Barcode : public CFWL_Edit { // CFWL_Widget FWL_Type GetClassID() const override; void Update() override; - void DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; + void DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; void OnProcessEvent(CFWL_Event* pEvent) override; // CFWL_Edit diff --git a/chromium/third_party/pdfium/xfa/fwl/cfwl_caret.cpp b/chromium/third_party/pdfium/xfa/fwl/cfwl_caret.cpp index 21387a47f94..be7ecbf331a 100644 --- a/chromium/third_party/pdfium/xfa/fwl/cfwl_caret.cpp +++ b/chromium/third_party/pdfium/xfa/fwl/cfwl_caret.cpp @@ -43,7 +43,7 @@ FWL_Type CFWL_Caret::GetClassID() const { void CFWL_Caret::Update() {} -void CFWL_Caret::DrawWidget(CFX_Graphics* pGraphics, +void CFWL_Caret::DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) { if (!pGraphics) return; @@ -70,7 +70,7 @@ void CFWL_Caret::HideCaret() { SetStates(FWL_WGTSTATE_Invisible); } -void CFWL_Caret::DrawCaretBK(CFX_Graphics* pGraphics, +void CFWL_Caret::DrawCaretBK(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme, const CFX_Matrix* pMatrix) { if (!(m_pProperties->m_dwStates & FWL_STATE_CAT_HightLight)) @@ -89,7 +89,7 @@ void CFWL_Caret::DrawCaretBK(CFX_Graphics* pGraphics, void CFWL_Caret::OnProcessMessage(CFWL_Message* pMessage) {} -void CFWL_Caret::OnDrawWidget(CFX_Graphics* pGraphics, +void CFWL_Caret::OnDrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) { DrawWidget(pGraphics, pMatrix); } diff --git a/chromium/third_party/pdfium/xfa/fwl/cfwl_caret.h b/chromium/third_party/pdfium/xfa/fwl/cfwl_caret.h index da0548c2bf0..d00f38a29c1 100644 --- a/chromium/third_party/pdfium/xfa/fwl/cfwl_caret.h +++ b/chromium/third_party/pdfium/xfa/fwl/cfwl_caret.h @@ -11,7 +11,7 @@ #include "xfa/fwl/cfwl_timer.h" #include "xfa/fwl/cfwl_widget.h" -#include "xfa/fxgraphics/cfx_color.h" +#include "xfa/fxgraphics/cxfa_color.h" class CFWL_WidgetProperties; class CFWL_Widget; @@ -27,9 +27,9 @@ class CFWL_Caret : public CFWL_Widget { // CFWL_Widget FWL_Type GetClassID() const override; - void DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; + void DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; void OnProcessMessage(CFWL_Message* pMessage) override; - void OnDrawWidget(CFX_Graphics* pGraphics, + void OnDrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; void Update() override; @@ -46,7 +46,7 @@ class CFWL_Caret : public CFWL_Widget { }; friend class CFWL_Caret::Timer; - void DrawCaretBK(CFX_Graphics* pGraphics, + void DrawCaretBK(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme, const CFX_Matrix* pMatrix); diff --git a/chromium/third_party/pdfium/xfa/fwl/cfwl_checkbox.cpp b/chromium/third_party/pdfium/xfa/fwl/cfwl_checkbox.cpp index 5ec3504caec..eed201ba348 100644 --- a/chromium/third_party/pdfium/xfa/fwl/cfwl_checkbox.cpp +++ b/chromium/third_party/pdfium/xfa/fwl/cfwl_checkbox.cpp @@ -61,7 +61,7 @@ void CFWL_CheckBox::Update() { Layout(); } -void CFWL_CheckBox::DrawWidget(CFX_Graphics* pGraphics, +void CFWL_CheckBox::DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) { if (!pGraphics) return; @@ -266,7 +266,7 @@ void CFWL_CheckBox::OnProcessMessage(CFWL_Message* pMessage) { CFWL_Widget::OnProcessMessage(pMessage); } -void CFWL_CheckBox::OnDrawWidget(CFX_Graphics* pGraphics, +void CFWL_CheckBox::OnDrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) { DrawWidget(pGraphics, pMatrix); } diff --git a/chromium/third_party/pdfium/xfa/fwl/cfwl_checkbox.h b/chromium/third_party/pdfium/xfa/fwl/cfwl_checkbox.h index 2f434f23cf3..6fc9033deed 100644 --- a/chromium/third_party/pdfium/xfa/fwl/cfwl_checkbox.h +++ b/chromium/third_party/pdfium/xfa/fwl/cfwl_checkbox.h @@ -41,10 +41,10 @@ class CFWL_CheckBox : public CFWL_Widget { // CFWL_Widget FWL_Type GetClassID() const override; void Update() override; - void DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; + void DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; void OnProcessMessage(CFWL_Message* pMessage) override; - void OnDrawWidget(CFX_Graphics* pGraphics, + void OnDrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; void SetBoxSize(float fHeight); diff --git a/chromium/third_party/pdfium/xfa/fwl/cfwl_combobox.cpp b/chromium/third_party/pdfium/xfa/fwl/cfwl_combobox.cpp index ba72d3d2b2c..acc72b0e641 100644 --- a/chromium/third_party/pdfium/xfa/fwl/cfwl_combobox.cpp +++ b/chromium/third_party/pdfium/xfa/fwl/cfwl_combobox.cpp @@ -125,7 +125,7 @@ FWL_WidgetHit CFWL_ComboBox::HitTest(const CFX_PointF& point) { return CFWL_Widget::HitTest(point); } -void CFWL_ComboBox::DrawWidget(CFX_Graphics* pGraphics, +void CFWL_ComboBox::DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) { if (m_pWidgetMgr->IsFormDisabled()) { DisForm_DrawWidget(pGraphics, pMatrix); @@ -288,7 +288,7 @@ void CFWL_ComboBox::EditModifyStylesEx(uint32_t dwStylesExAdded, m_pEdit->ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); } -void CFWL_ComboBox::DrawStretchHandler(CFX_Graphics* pGraphics, +void CFWL_ComboBox::DrawStretchHandler(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) { CFWL_ThemeBackground param; param.m_pGraphics = pGraphics; @@ -615,10 +615,10 @@ FWL_WidgetHit CFWL_ComboBox::DisForm_HitTest(const CFX_PointF& point) { return FWL_WidgetHit::Unknown; } -void CFWL_ComboBox::DisForm_DrawWidget(CFX_Graphics* pGraphics, +void CFWL_ComboBox::DisForm_DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) { IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; - CFX_Matrix mtOrg(1, 0, 0, 1, 0, 0); + CFX_Matrix mtOrg; if (pMatrix) mtOrg = *pMatrix; @@ -756,7 +756,7 @@ void CFWL_ComboBox::OnProcessEvent(CFWL_Event* pEvent) { } } -void CFWL_ComboBox::OnDrawWidget(CFX_Graphics* pGraphics, +void CFWL_ComboBox::OnDrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) { DrawWidget(pGraphics, pMatrix); } diff --git a/chromium/third_party/pdfium/xfa/fwl/cfwl_combobox.h b/chromium/third_party/pdfium/xfa/fwl/cfwl_combobox.h index 168e203162d..396aa6c9d5c 100644 --- a/chromium/third_party/pdfium/xfa/fwl/cfwl_combobox.h +++ b/chromium/third_party/pdfium/xfa/fwl/cfwl_combobox.h @@ -14,7 +14,7 @@ #include "xfa/fwl/cfwl_combolist.h" #include "xfa/fwl/cfwl_form.h" #include "xfa/fwl/cfwl_listbox.h" -#include "xfa/fxgraphics/cfx_graphics.h" +#include "xfa/fxgraphics/cxfa_graphics.h" class CFWL_WidgetProperties; class CFWL_ComboBox; @@ -52,11 +52,11 @@ class CFWL_ComboBox : public CFWL_Widget { void RemoveStates(uint32_t dwStates) override; void Update() override; FWL_WidgetHit HitTest(const CFX_PointF& point) override; - void DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; + void DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; void SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) override; void OnProcessMessage(CFWL_Message* pMessage) override; void OnProcessEvent(CFWL_Event* pEvent) override; - void OnDrawWidget(CFX_Graphics* pGraphics, + void OnDrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; CFX_WideString GetTextByIndex(int32_t iIndex) const; @@ -95,7 +95,7 @@ class CFWL_ComboBox : public CFWL_Widget { CFX_RectF GetBBox() const; void EditModifyStylesEx(uint32_t dwStylesExAdded, uint32_t dwStylesExRemoved); - void DrawStretchHandler(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix); + void DrawStretchHandler(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix); bool IsDropListVisible() const { return m_pComboBoxProxy && !(m_pComboBoxProxy->GetStates() & FWL_WGTSTATE_Invisible); @@ -136,7 +136,7 @@ class CFWL_ComboBox : public CFWL_Widget { uint32_t dwStylesExRemoved); void DisForm_Update(); FWL_WidgetHit DisForm_HitTest(const CFX_PointF& point); - void DisForm_DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix); + void DisForm_DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix); CFX_RectF DisForm_GetBBox() const; void DisForm_Layout(); void DisForm_OnProcessMessage(CFWL_Message* pMessage); diff --git a/chromium/third_party/pdfium/xfa/fwl/cfwl_comboboxproxy.cpp b/chromium/third_party/pdfium/xfa/fwl/cfwl_comboboxproxy.cpp index 0e2779b5c9c..28c403fb0a2 100644 --- a/chromium/third_party/pdfium/xfa/fwl/cfwl_comboboxproxy.cpp +++ b/chromium/third_party/pdfium/xfa/fwl/cfwl_comboboxproxy.cpp @@ -58,7 +58,7 @@ void CFWL_ComboBoxProxy::OnProcessMessage(CFWL_Message* pMessage) { CFWL_Widget::OnProcessMessage(pMessage); } -void CFWL_ComboBoxProxy::OnDrawWidget(CFX_Graphics* pGraphics, +void CFWL_ComboBoxProxy::OnDrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) { m_pComboBox->DrawStretchHandler(pGraphics, pMatrix); } diff --git a/chromium/third_party/pdfium/xfa/fwl/cfwl_comboboxproxy.h b/chromium/third_party/pdfium/xfa/fwl/cfwl_comboboxproxy.h index 4be14b9e657..8282348657b 100644 --- a/chromium/third_party/pdfium/xfa/fwl/cfwl_comboboxproxy.h +++ b/chromium/third_party/pdfium/xfa/fwl/cfwl_comboboxproxy.h @@ -23,7 +23,7 @@ class CFWL_ComboBoxProxy : public CFWL_FormProxy { // CFWL_FormProxy void OnProcessMessage(CFWL_Message* pMessage) override; - void OnDrawWidget(CFX_Graphics* pGraphics, + void OnDrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; void Reset() { m_bLButtonUpSelf = false; } diff --git a/chromium/third_party/pdfium/xfa/fwl/cfwl_datetimepicker.cpp b/chromium/third_party/pdfium/xfa/fwl/cfwl_datetimepicker.cpp index a49785e9875..1a82a5c7ee4 100644 --- a/chromium/third_party/pdfium/xfa/fwl/cfwl_datetimepicker.cpp +++ b/chromium/third_party/pdfium/xfa/fwl/cfwl_datetimepicker.cpp @@ -114,7 +114,7 @@ FWL_WidgetHit CFWL_DateTimePicker::HitTest(const CFX_PointF& point) { return FWL_WidgetHit::Unknown; } -void CFWL_DateTimePicker::DrawWidget(CFX_Graphics* pGraphics, +void CFWL_DateTimePicker::DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) { if (!pGraphics) return; @@ -195,7 +195,7 @@ void CFWL_DateTimePicker::ModifyEditStylesEx(uint32_t dwStylesExAdded, m_pEdit->ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); } -void CFWL_DateTimePicker::DrawDropDownButton(CFX_Graphics* pGraphics, +void CFWL_DateTimePicker::DrawDropDownButton(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme, const CFX_Matrix* pMatrix) { CFWL_ThemeBackground param; @@ -443,7 +443,7 @@ CFX_RectF CFWL_DateTimePicker::DisForm_GetBBox() const { return rect; } -void CFWL_DateTimePicker::DisForm_DrawWidget(CFX_Graphics* pGraphics, +void CFWL_DateTimePicker::DisForm_DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) { if (!pGraphics) return; @@ -510,7 +510,7 @@ void CFWL_DateTimePicker::OnProcessMessage(CFWL_Message* pMessage) { CFWL_Widget::OnProcessMessage(pMessage); } -void CFWL_DateTimePicker::OnDrawWidget(CFX_Graphics* pGraphics, +void CFWL_DateTimePicker::OnDrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) { DrawWidget(pGraphics, pMatrix); } diff --git a/chromium/third_party/pdfium/xfa/fwl/cfwl_datetimepicker.h b/chromium/third_party/pdfium/xfa/fwl/cfwl_datetimepicker.h index 0f086d6b329..79e9cad9ddd 100644 --- a/chromium/third_party/pdfium/xfa/fwl/cfwl_datetimepicker.h +++ b/chromium/third_party/pdfium/xfa/fwl/cfwl_datetimepicker.h @@ -39,10 +39,10 @@ class CFWL_DateTimePicker : public CFWL_Widget { FWL_Type GetClassID() const override; void Update() override; FWL_WidgetHit HitTest(const CFX_PointF& point) override; - void DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; + void DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; void SetThemeProvider(IFWL_ThemeProvider* pTP) override; void OnProcessMessage(CFWL_Message* pMessage) override; - void OnDrawWidget(CFX_Graphics* pGraphics, + void OnDrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; void GetCurSel(int32_t& iYear, int32_t& iMonth, int32_t& iDay); @@ -67,7 +67,7 @@ class CFWL_DateTimePicker : public CFWL_Widget { CFWL_FormProxy* GetFormProxy() const { return m_pForm.get(); } private: - void DrawDropDownButton(CFX_Graphics* pGraphics, + void DrawDropDownButton(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme, const CFX_Matrix* pMatrix); void FormatDateString(int32_t iYear, @@ -88,7 +88,7 @@ class CFWL_DateTimePicker : public CFWL_Widget { bool DisForm_IsNeedShowButton() const; void DisForm_Update(); CFX_RectF DisForm_GetBBox() const; - void DisForm_DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix); + void DisForm_DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix); void DisForm_OnFocusChanged(CFWL_Message* pMsg, bool bSet); CFX_RectF m_rtBtn; diff --git a/chromium/third_party/pdfium/xfa/fwl/cfwl_edit.cpp b/chromium/third_party/pdfium/xfa/fwl/cfwl_edit.cpp index eff76ffabf1..acefd3a9648 100644 --- a/chromium/third_party/pdfium/xfa/fwl/cfwl_edit.cpp +++ b/chromium/third_party/pdfium/xfa/fwl/cfwl_edit.cpp @@ -32,7 +32,7 @@ #include "xfa/fwl/ifwl_themeprovider.h" #include "xfa/fxfa/cxfa_ffdoc.h" #include "xfa/fxfa/cxfa_ffwidget.h" -#include "xfa/fxgraphics/cfx_path.h" +#include "xfa/fxgraphics/cxfa_path.h" namespace { @@ -44,7 +44,7 @@ bool FX_EDIT_ISLATINWORD(wchar_t c) { c == 0x0027; } -void AddSquigglyPath(CFX_Path* pPathData, +void AddSquigglyPath(CXFA_Path* pPathData, float fStartX, float fEndX, float fY, @@ -158,7 +158,7 @@ FWL_WidgetHit CFWL_Edit::HitTest(const CFX_PointF& point) { return FWL_WidgetHit::Unknown; } -void CFWL_Edit::AddSpellCheckObj(CFX_Path& PathData, +void CFWL_Edit::AddSpellCheckObj(CXFA_Path& PathData, int32_t nStart, int32_t nCount, float fOffSetX, @@ -184,16 +184,16 @@ void CFWL_Edit::AddSpellCheckObj(CFX_Path& PathData, } } -void CFWL_Edit::DrawSpellCheck(CFX_Graphics* pGraphics, +void CFWL_Edit::DrawSpellCheck(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) { pGraphics->SaveGraphState(); if (pMatrix) pGraphics->ConcatMatrix(const_cast<CFX_Matrix*>(pMatrix)); - CFX_Color crLine(0xFFFF0000); + CXFA_Color crLine(0xFFFF0000); CFWL_EventCheckWord checkWordEvent(this); CFX_ByteString sLatinWord; - CFX_Path pathSpell; + CXFA_Path pathSpell; int32_t nStart = 0; float fOffSetX = m_rtEngine.left - m_fScrollOffsetX; float fOffSetY = m_rtEngine.top - m_fScrollOffsetY + m_fVAlignOffset; @@ -240,7 +240,8 @@ void CFWL_Edit::DrawSpellCheck(CFX_Graphics* pGraphics, pGraphics->RestoreGraphState(); } -void CFWL_Edit::DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) { +void CFWL_Edit::DrawWidget(CXFA_Graphics* pGraphics, + const CFX_Matrix* pMatrix) { if (!pGraphics) return; if (!m_pProperties->m_pThemeProvider) @@ -472,7 +473,7 @@ void CFWL_Edit::SetScrollOffset(float fScrollOffset) { m_fScrollOffsetY = fScrollOffset; } -void CFWL_Edit::DrawTextBk(CFX_Graphics* pGraphics, +void CFWL_Edit::DrawTextBk(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme, const CFX_Matrix* pMatrix) { CFWL_ThemeBackground param; @@ -504,7 +505,7 @@ void CFWL_Edit::DrawTextBk(CFX_Graphics* pGraphics, pTheme->DrawBackground(¶m); } -void CFWL_Edit::DrawContent(CFX_Graphics* pGraphics, +void CFWL_Edit::DrawContent(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme, const CFX_Matrix* pMatrix) { CFDE_TxtEdtPage* pPage = m_EdtEngine.GetPage(0); @@ -545,7 +546,7 @@ void CFWL_Edit::DrawContent(CFX_Graphics* pGraphics, &rectArr); } - CFX_Path path; + CXFA_Path path; for (auto& rect : rectArr) { rect.left += fOffSetX; rect.top += fOffSetY; @@ -575,7 +576,7 @@ void CFWL_Edit::DrawContent(CFX_Graphics* pGraphics, if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_CombText) { pGraphics->RestoreGraphState(); - CFX_Path path; + CXFA_Path path; int32_t iLimit = m_nLimit > 0 ? m_nLimit : 1; float fStep = m_rtEngine.width / iLimit; float fLeft = m_rtEngine.left + 1; @@ -1140,34 +1141,24 @@ bool CFWL_Edit::ValidateNumberChar(wchar_t cNum) { return true; CFX_WideString wsText = m_EdtEngine.GetText(0, -1); - if (wsText.IsEmpty()) { - if (cNum == L'0') - return false; - return true; - } + if (wsText.IsEmpty()) + return cNum != L'0'; - int32_t caretPos = m_EdtEngine.GetCaretPos(); - if (CountSelRanges() == 0) { - if (cNum == L'0' && caretPos == 0) - return false; + if (CountSelRanges() != 0) + return wsText.GetInteger() <= m_iMax; - int32_t nLen = wsText.GetLength(); - CFX_WideString l = wsText.Mid(0, caretPos); - CFX_WideString r = wsText.Mid(caretPos, nLen - caretPos); - CFX_WideString wsNew = l + cNum + r; - if (wsNew.GetInteger() <= m_iMax) - return true; + int32_t caretPos = m_EdtEngine.GetCaretPos(); + if (cNum == L'0' && caretPos == 0) return false; - } - if (wsText.GetInteger() <= m_iMax) - return true; - return false; + int32_t nLen = wsText.GetLength(); + CFX_WideString l = wsText.Mid(0, caretPos); + CFX_WideString r = wsText.Mid(caretPos, nLen - caretPos); + CFX_WideString wsNew = l + cNum + r; + return wsNew.GetInteger() <= m_iMax; } void CFWL_Edit::InitCaret() { - if (!m_pCaret) - return; m_pCaret.reset(); } @@ -1233,9 +1224,7 @@ void CFWL_Edit::OnProcessMessage(CFWL_Message* pMessage) { } void CFWL_Edit::OnProcessEvent(CFWL_Event* pEvent) { - if (!pEvent) - return; - if (pEvent->GetType() != CFWL_Event::Type::Scroll) + if (!pEvent || pEvent->GetType() != CFWL_Event::Type::Scroll) return; CFWL_Widget* pSrcTarget = pEvent->m_pSrcTarget; @@ -1247,7 +1236,7 @@ void CFWL_Edit::OnProcessEvent(CFWL_Event* pEvent) { } } -void CFWL_Edit::OnDrawWidget(CFX_Graphics* pGraphics, +void CFWL_Edit::OnDrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) { DrawWidget(pGraphics, pMatrix); } @@ -1261,10 +1250,8 @@ void CFWL_Edit::DoButtonDown(CFWL_MessageMouse* pMsg) { return; bool bBefore = true; - int32_t nIndex = pPage->GetCharIndex(DeviceToEngine(pMsg->m_pos), bBefore); - if (nIndex < 0) - nIndex = 0; - + int32_t nIndex = + std::max(0, pPage->GetCharIndex(DeviceToEngine(pMsg->m_pos), bBefore)); m_EdtEngine.SetCaretPos(nIndex, bBefore); } diff --git a/chromium/third_party/pdfium/xfa/fwl/cfwl_edit.h b/chromium/third_party/pdfium/xfa/fwl/cfwl_edit.h index 0dbbcd6eefa..15d20bf7cb9 100644 --- a/chromium/third_party/pdfium/xfa/fwl/cfwl_edit.h +++ b/chromium/third_party/pdfium/xfa/fwl/cfwl_edit.h @@ -16,7 +16,7 @@ #include "xfa/fwl/cfwl_event.h" #include "xfa/fwl/cfwl_scrollbar.h" #include "xfa/fwl/cfwl_widget.h" -#include "xfa/fxgraphics/cfx_path.h" +#include "xfa/fxgraphics/cxfa_path.h" #define FWL_STYLEEXT_EDT_ReadOnly (1L << 0) #define FWL_STYLEEXT_EDT_MultiLine (1L << 1) @@ -61,11 +61,11 @@ class CFWL_Edit : public CFWL_Widget { void Update() override; FWL_WidgetHit HitTest(const CFX_PointF& point) override; void SetStates(uint32_t dwStates) override; - void DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; + void DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; void SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) override; void OnProcessMessage(CFWL_Message* pMessage) override; void OnProcessEvent(CFWL_Event* pEvent) override; - void OnDrawWidget(CFX_Graphics* pGraphics, + void OnDrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; virtual void SetText(const CFX_WideString& wsText); @@ -109,13 +109,13 @@ class CFWL_Edit : public CFWL_Widget { CFDE_TxtEdtEngine* GetTxtEdtEngine() { return &m_EdtEngine; } private: - void DrawTextBk(CFX_Graphics* pGraphics, + void DrawTextBk(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme, const CFX_Matrix* pMatrix); - void DrawContent(CFX_Graphics* pGraphics, + void DrawContent(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme, const CFX_Matrix* pMatrix); - void DrawSpellCheck(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix); + void DrawSpellCheck(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix); void UpdateEditEngine(); void UpdateEditParams(); @@ -138,7 +138,7 @@ class CFWL_Edit : public CFWL_Widget { bool IsContentHeightOverflow(); int32_t AddDoRecord(std::unique_ptr<IFDE_TxtEdtDoRecord> pRecord); void ProcessInsertError(int32_t iError); - void AddSpellCheckObj(CFX_Path& PathData, + void AddSpellCheckObj(CXFA_Path& PathData, int32_t nStart, int32_t nCount, float fOffSetX, diff --git a/chromium/third_party/pdfium/xfa/fwl/cfwl_event.h b/chromium/third_party/pdfium/xfa/fwl/cfwl_event.h index e326ab32c8d..01e3914b8be 100644 --- a/chromium/third_party/pdfium/xfa/fwl/cfwl_event.h +++ b/chromium/third_party/pdfium/xfa/fwl/cfwl_event.h @@ -13,7 +13,7 @@ #include "xfa/fwl/cfwl_messagekey.h" #include "xfa/fwl/cfwl_messagemouse.h" -class CFX_Graphics; +class CXFA_Graphics; class CFWL_Widget; class CFWL_Event { diff --git a/chromium/third_party/pdfium/xfa/fwl/cfwl_form.cpp b/chromium/third_party/pdfium/xfa/fwl/cfwl_form.cpp index 3e606b3eb93..c560a0d3529 100644 --- a/chromium/third_party/pdfium/xfa/fwl/cfwl_form.cpp +++ b/chromium/third_party/pdfium/xfa/fwl/cfwl_form.cpp @@ -75,7 +75,8 @@ FWL_WidgetHit CFWL_Form::HitTest(const CFX_PointF& point) { : FWL_WidgetHit::Client; } -void CFWL_Form::DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) { +void CFWL_Form::DrawWidget(CXFA_Graphics* pGraphics, + const CFX_Matrix* pMatrix) { if (!pGraphics) return; if (!m_pProperties->m_pThemeProvider) @@ -147,7 +148,7 @@ void CFWL_Form::EndDoModal() { #endif } -void CFWL_Form::DrawBackground(CFX_Graphics* pGraphics, +void CFWL_Form::DrawBackground(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme) { CFWL_ThemeBackground param; param.m_pWidget = this; @@ -238,7 +239,7 @@ void CFWL_Form::OnProcessMessage(CFWL_Message* pMessage) { #endif // FWL_UseMacSystemBorder } -void CFWL_Form::OnDrawWidget(CFX_Graphics* pGraphics, +void CFWL_Form::OnDrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) { DrawWidget(pGraphics, pMatrix); } diff --git a/chromium/third_party/pdfium/xfa/fwl/cfwl_form.h b/chromium/third_party/pdfium/xfa/fwl/cfwl_form.h index ec7fc137beb..96452e8e335 100644 --- a/chromium/third_party/pdfium/xfa/fwl/cfwl_form.h +++ b/chromium/third_party/pdfium/xfa/fwl/cfwl_form.h @@ -38,9 +38,9 @@ class CFWL_Form : public CFWL_Widget { CFX_RectF GetClientRect() override; void Update() override; FWL_WidgetHit HitTest(const CFX_PointF& point) override; - void DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; + void DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; void OnProcessMessage(CFWL_Message* pMessage) override; - void OnDrawWidget(CFX_Graphics* pGraphics, + void OnDrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; CFWL_Widget* DoModal(); @@ -50,7 +50,7 @@ class CFWL_Form : public CFWL_Widget { void SetSubFocus(CFWL_Widget* pWidget) { m_pSubFocus = pWidget; } private: - void DrawBackground(CFX_Graphics* pGraphics, IFWL_ThemeProvider* pTheme); + void DrawBackground(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme); CFX_RectF GetEdgeRect(); void SetWorkAreaRect(); void Layout(); diff --git a/chromium/third_party/pdfium/xfa/fwl/cfwl_formproxy.cpp b/chromium/third_party/pdfium/xfa/fwl/cfwl_formproxy.cpp index 776ba0ac614..af7703e9c0a 100644 --- a/chromium/third_party/pdfium/xfa/fwl/cfwl_formproxy.cpp +++ b/chromium/third_party/pdfium/xfa/fwl/cfwl_formproxy.cpp @@ -32,7 +32,7 @@ bool CFWL_FormProxy::IsInstance(const CFX_WideStringC& wsClass) const { void CFWL_FormProxy::Update() {} -void CFWL_FormProxy::DrawWidget(CFX_Graphics* pGraphics, +void CFWL_FormProxy::DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) {} void CFWL_FormProxy::OnProcessMessage(CFWL_Message* pMessage) { diff --git a/chromium/third_party/pdfium/xfa/fwl/cfwl_formproxy.h b/chromium/third_party/pdfium/xfa/fwl/cfwl_formproxy.h index 4ad70bf15c6..dbc49d8f5ec 100644 --- a/chromium/third_party/pdfium/xfa/fwl/cfwl_formproxy.h +++ b/chromium/third_party/pdfium/xfa/fwl/cfwl_formproxy.h @@ -24,7 +24,7 @@ class CFWL_FormProxy : public CFWL_Form { FWL_Type GetClassID() const override; bool IsInstance(const CFX_WideStringC& wsClass) const override; void Update() override; - void DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; + void DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; void OnProcessMessage(CFWL_Message* pMessage) override; }; diff --git a/chromium/third_party/pdfium/xfa/fwl/cfwl_listbox.cpp b/chromium/third_party/pdfium/xfa/fwl/cfwl_listbox.cpp index 0fd43efa08c..ddad4038f5c 100644 --- a/chromium/third_party/pdfium/xfa/fwl/cfwl_listbox.cpp +++ b/chromium/third_party/pdfium/xfa/fwl/cfwl_listbox.cpp @@ -91,7 +91,7 @@ FWL_WidgetHit CFWL_ListBox::HitTest(const CFX_PointF& point) { return FWL_WidgetHit::Unknown; } -void CFWL_ListBox::DrawWidget(CFX_Graphics* pGraphics, +void CFWL_ListBox::DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) { if (!pGraphics) return; @@ -352,7 +352,7 @@ bool CFWL_ListBox::ScrollToVisible(CFWL_ListItem* pItem) { return true; } -void CFWL_ListBox::DrawBkground(CFX_Graphics* pGraphics, +void CFWL_ListBox::DrawBkground(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme, const CFX_Matrix* pMatrix) { if (!pGraphics) @@ -375,7 +375,7 @@ void CFWL_ListBox::DrawBkground(CFX_Graphics* pGraphics, pTheme->DrawBackground(¶m); } -void CFWL_ListBox::DrawItems(CFX_Graphics* pGraphics, +void CFWL_ListBox::DrawItems(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme, const CFX_Matrix* pMatrix) { float fPosX = 0.0f; @@ -408,7 +408,7 @@ void CFWL_ListBox::DrawItems(CFX_Graphics* pGraphics, } } -void CFWL_ListBox::DrawItem(CFX_Graphics* pGraphics, +void CFWL_ListBox::DrawItem(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme, CFWL_ListItem* pItem, int32_t Index, @@ -714,7 +714,7 @@ void CFWL_ListBox::OnProcessEvent(CFWL_Event* pEvent) { } } -void CFWL_ListBox::OnDrawWidget(CFX_Graphics* pGraphics, +void CFWL_ListBox::OnDrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) { DrawWidget(pGraphics, pMatrix); } diff --git a/chromium/third_party/pdfium/xfa/fwl/cfwl_listbox.h b/chromium/third_party/pdfium/xfa/fwl/cfwl_listbox.h index 18aaf4cbd50..4f934432d6b 100644 --- a/chromium/third_party/pdfium/xfa/fwl/cfwl_listbox.h +++ b/chromium/third_party/pdfium/xfa/fwl/cfwl_listbox.h @@ -42,11 +42,11 @@ class CFWL_ListBox : public CFWL_Widget { FWL_Type GetClassID() const override; void Update() override; FWL_WidgetHit HitTest(const CFX_PointF& point) override; - void DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; + void DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; void SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) override; void OnProcessMessage(CFWL_Message* pMessage) override; void OnProcessEvent(CFWL_Event* pEvent) override; - void OnDrawWidget(CFX_Graphics* pGraphics, + void OnDrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; int32_t CountItems(const CFWL_Widget* pWidget) const; @@ -85,19 +85,19 @@ class CFWL_ListBox : public CFWL_Widget { void SelectAll(); CFWL_ListItem* GetFocusedItem(); void SetFocusItem(CFWL_ListItem* hItem); - void DrawBkground(CFX_Graphics* pGraphics, + void DrawBkground(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme, const CFX_Matrix* pMatrix); - void DrawItems(CFX_Graphics* pGraphics, + void DrawItems(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme, const CFX_Matrix* pMatrix); - void DrawItem(CFX_Graphics* pGraphics, + void DrawItem(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme, CFWL_ListItem* hItem, int32_t Index, const CFX_RectF& rtItem, const CFX_Matrix* pMatrix); - void DrawStatic(CFX_Graphics* pGraphics, IFWL_ThemeProvider* pTheme); + void DrawStatic(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme); CFX_SizeF CalcSize(bool bAutoSize); void UpdateItemSize(CFWL_ListItem* hItem, CFX_SizeF& size, diff --git a/chromium/third_party/pdfium/xfa/fwl/cfwl_monthcalendar.cpp b/chromium/third_party/pdfium/xfa/fwl/cfwl_monthcalendar.cpp index 4ef0c694c55..8c770e545b6 100644 --- a/chromium/third_party/pdfium/xfa/fwl/cfwl_monthcalendar.cpp +++ b/chromium/third_party/pdfium/xfa/fwl/cfwl_monthcalendar.cpp @@ -146,7 +146,7 @@ void CFWL_MonthCalendar::Update() { Layout(); } -void CFWL_MonthCalendar::DrawWidget(CFX_Graphics* pGraphics, +void CFWL_MonthCalendar::DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) { if (!pGraphics) return; @@ -178,7 +178,7 @@ void CFWL_MonthCalendar::SetSelect(int32_t iYear, AddSelDay(iDay); } -void CFWL_MonthCalendar::DrawBackground(CFX_Graphics* pGraphics, +void CFWL_MonthCalendar::DrawBackground(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme, const CFX_Matrix* pMatrix) { CFWL_ThemeBackground params; @@ -192,7 +192,7 @@ void CFWL_MonthCalendar::DrawBackground(CFX_Graphics* pGraphics, pTheme->DrawBackground(¶ms); } -void CFWL_MonthCalendar::DrawHeadBK(CFX_Graphics* pGraphics, +void CFWL_MonthCalendar::DrawHeadBK(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme, const CFX_Matrix* pMatrix) { CFWL_ThemeBackground params; @@ -206,7 +206,7 @@ void CFWL_MonthCalendar::DrawHeadBK(CFX_Graphics* pGraphics, pTheme->DrawBackground(¶ms); } -void CFWL_MonthCalendar::DrawLButton(CFX_Graphics* pGraphics, +void CFWL_MonthCalendar::DrawLButton(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme, const CFX_Matrix* pMatrix) { CFWL_ThemeBackground params; @@ -220,7 +220,7 @@ void CFWL_MonthCalendar::DrawLButton(CFX_Graphics* pGraphics, pTheme->DrawBackground(¶ms); } -void CFWL_MonthCalendar::DrawRButton(CFX_Graphics* pGraphics, +void CFWL_MonthCalendar::DrawRButton(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme, const CFX_Matrix* pMatrix) { CFWL_ThemeBackground params; @@ -234,7 +234,7 @@ void CFWL_MonthCalendar::DrawRButton(CFX_Graphics* pGraphics, pTheme->DrawBackground(¶ms); } -void CFWL_MonthCalendar::DrawCaption(CFX_Graphics* pGraphics, +void CFWL_MonthCalendar::DrawCaption(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme, const CFX_Matrix* pMatrix) { CFWL_ThemeText textParam; @@ -254,7 +254,7 @@ void CFWL_MonthCalendar::DrawCaption(CFX_Graphics* pGraphics, pTheme->DrawText(&textParam); } -void CFWL_MonthCalendar::DrawSeperator(CFX_Graphics* pGraphics, +void CFWL_MonthCalendar::DrawSeperator(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme, const CFX_Matrix* pMatrix) { CFWL_ThemeBackground params; @@ -268,7 +268,7 @@ void CFWL_MonthCalendar::DrawSeperator(CFX_Graphics* pGraphics, pTheme->DrawBackground(¶ms); } -void CFWL_MonthCalendar::DrawDatesInBK(CFX_Graphics* pGraphics, +void CFWL_MonthCalendar::DrawDatesInBK(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme, const CFX_Matrix* pMatrix) { CFWL_ThemeBackground params; @@ -298,7 +298,7 @@ void CFWL_MonthCalendar::DrawDatesInBK(CFX_Graphics* pGraphics, } } -void CFWL_MonthCalendar::DrawWeek(CFX_Graphics* pGraphics, +void CFWL_MonthCalendar::DrawWeek(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme, const CFX_Matrix* pMatrix) { CFWL_ThemeText params; @@ -323,7 +323,7 @@ void CFWL_MonthCalendar::DrawWeek(CFX_Graphics* pGraphics, } } -void CFWL_MonthCalendar::DrawToday(CFX_Graphics* pGraphics, +void CFWL_MonthCalendar::DrawToday(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme, const CFX_Matrix* pMatrix) { CFWL_ThemeText params; @@ -344,7 +344,7 @@ void CFWL_MonthCalendar::DrawToday(CFX_Graphics* pGraphics, pTheme->DrawText(¶ms); } -void CFWL_MonthCalendar::DrawDatesIn(CFX_Graphics* pGraphics, +void CFWL_MonthCalendar::DrawDatesIn(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme, const CFX_Matrix* pMatrix) { CFWL_ThemeText params; @@ -369,7 +369,7 @@ void CFWL_MonthCalendar::DrawDatesIn(CFX_Graphics* pGraphics, } } -void CFWL_MonthCalendar::DrawDatesOut(CFX_Graphics* pGraphics, +void CFWL_MonthCalendar::DrawDatesOut(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme, const CFX_Matrix* pMatrix) { CFWL_ThemeText params; @@ -383,7 +383,7 @@ void CFWL_MonthCalendar::DrawDatesOut(CFX_Graphics* pGraphics, pTheme->DrawText(¶ms); } -void CFWL_MonthCalendar::DrawDatesInCircle(CFX_Graphics* pGraphics, +void CFWL_MonthCalendar::DrawDatesInCircle(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme, const CFX_Matrix* pMatrix) { if (m_iMonth != m_iCurMonth || m_iYear != m_iCurYear) @@ -745,7 +745,7 @@ void CFWL_MonthCalendar::OnProcessMessage(CFWL_Message* pMessage) { CFWL_Widget::OnProcessMessage(pMessage); } -void CFWL_MonthCalendar::OnDrawWidget(CFX_Graphics* pGraphics, +void CFWL_MonthCalendar::OnDrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) { DrawWidget(pGraphics, pMatrix); } diff --git a/chromium/third_party/pdfium/xfa/fwl/cfwl_monthcalendar.h b/chromium/third_party/pdfium/xfa/fwl/cfwl_monthcalendar.h index 70c0401b7d8..e537c331ef4 100644 --- a/chromium/third_party/pdfium/xfa/fwl/cfwl_monthcalendar.h +++ b/chromium/third_party/pdfium/xfa/fwl/cfwl_monthcalendar.h @@ -33,9 +33,9 @@ class CFWL_MonthCalendar : public CFWL_Widget { FWL_Type GetClassID() const override; CFX_RectF GetAutosizedWidgetRect() override; void Update() override; - void DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; + void DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; void OnProcessMessage(CFWL_Message* pMessage) override; - void OnDrawWidget(CFX_Graphics* pGraphics, + void OnDrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; void SetSelect(int32_t iYear, int32_t iMonth, int32_t iDay); @@ -90,40 +90,40 @@ class CFWL_MonthCalendar : public CFWL_Widget { CFX_WideString wsDay; }; - void DrawBackground(CFX_Graphics* pGraphics, + void DrawBackground(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme, const CFX_Matrix* pMatrix); - void DrawHeadBK(CFX_Graphics* pGraphics, + void DrawHeadBK(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme, const CFX_Matrix* pMatrix); - void DrawLButton(CFX_Graphics* pGraphics, + void DrawLButton(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme, const CFX_Matrix* pMatrix); - void DrawRButton(CFX_Graphics* pGraphics, + void DrawRButton(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme, const CFX_Matrix* pMatrix); - void DrawCaption(CFX_Graphics* pGraphics, + void DrawCaption(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme, const CFX_Matrix* pMatrix); - void DrawSeperator(CFX_Graphics* pGraphics, + void DrawSeperator(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme, const CFX_Matrix* pMatrix); - void DrawDatesInBK(CFX_Graphics* pGraphics, + void DrawDatesInBK(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme, const CFX_Matrix* pMatrix); - void DrawWeek(CFX_Graphics* pGraphics, + void DrawWeek(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme, const CFX_Matrix* pMatrix); - void DrawToday(CFX_Graphics* pGraphics, + void DrawToday(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme, const CFX_Matrix* pMatrix); - void DrawDatesIn(CFX_Graphics* pGraphics, + void DrawDatesIn(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme, const CFX_Matrix* pMatrix); - void DrawDatesOut(CFX_Graphics* pGraphics, + void DrawDatesOut(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme, const CFX_Matrix* pMatrix); - void DrawDatesInCircle(CFX_Graphics* pGraphics, + void DrawDatesInCircle(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme, const CFX_Matrix* pMatrix); CFX_SizeF CalcSize(); diff --git a/chromium/third_party/pdfium/xfa/fwl/cfwl_notedriver.h b/chromium/third_party/pdfium/xfa/fwl/cfwl_notedriver.h index b55e701c407..0db482ecbc7 100644 --- a/chromium/third_party/pdfium/xfa/fwl/cfwl_notedriver.h +++ b/chromium/third_party/pdfium/xfa/fwl/cfwl_notedriver.h @@ -14,7 +14,7 @@ #include "xfa/fwl/cfwl_event.h" #include "xfa/fwl/cfwl_widget.h" -#include "xfa/fxgraphics/cfx_graphics.h" +#include "xfa/fxgraphics/cxfa_graphics.h" class CFWL_EventTarget; class CFWL_NoteLoop; diff --git a/chromium/third_party/pdfium/xfa/fwl/cfwl_picturebox.cpp b/chromium/third_party/pdfium/xfa/fwl/cfwl_picturebox.cpp index 8c200e0494a..096b14ec611 100644 --- a/chromium/third_party/pdfium/xfa/fwl/cfwl_picturebox.cpp +++ b/chromium/third_party/pdfium/xfa/fwl/cfwl_picturebox.cpp @@ -32,7 +32,7 @@ void CFWL_PictureBox::Update() { m_rtClient = GetClientRect(); } -void CFWL_PictureBox::DrawWidget(CFX_Graphics* pGraphics, +void CFWL_PictureBox::DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) { if (!pGraphics) return; @@ -44,7 +44,7 @@ void CFWL_PictureBox::DrawWidget(CFX_Graphics* pGraphics, DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix); } -void CFWL_PictureBox::OnDrawWidget(CFX_Graphics* pGraphics, +void CFWL_PictureBox::OnDrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) { DrawWidget(pGraphics, pMatrix); } diff --git a/chromium/third_party/pdfium/xfa/fwl/cfwl_picturebox.h b/chromium/third_party/pdfium/xfa/fwl/cfwl_picturebox.h index 743ea1dc6da..e244c853b88 100644 --- a/chromium/third_party/pdfium/xfa/fwl/cfwl_picturebox.h +++ b/chromium/third_party/pdfium/xfa/fwl/cfwl_picturebox.h @@ -23,8 +23,8 @@ class CFWL_PictureBox : public CFWL_Widget { // CFWL_Widget FWL_Type GetClassID() const override; void Update() override; - void DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; - void OnDrawWidget(CFX_Graphics* pGraphics, + void DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; + void OnDrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; private: diff --git a/chromium/third_party/pdfium/xfa/fwl/cfwl_pushbutton.cpp b/chromium/third_party/pdfium/xfa/fwl/cfwl_pushbutton.cpp index 42925414f8d..382748df537 100644 --- a/chromium/third_party/pdfium/xfa/fwl/cfwl_pushbutton.cpp +++ b/chromium/third_party/pdfium/xfa/fwl/cfwl_pushbutton.cpp @@ -51,7 +51,7 @@ void CFWL_PushButton::Update() { m_rtCaption = m_rtClient; } -void CFWL_PushButton::DrawWidget(CFX_Graphics* pGraphics, +void CFWL_PushButton::DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) { if (!pGraphics) return; @@ -65,7 +65,7 @@ void CFWL_PushButton::DrawWidget(CFX_Graphics* pGraphics, DrawBkground(pGraphics, m_pProperties->m_pThemeProvider, pMatrix); } -void CFWL_PushButton::DrawBkground(CFX_Graphics* pGraphics, +void CFWL_PushButton::DrawBkground(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme, const CFX_Matrix* pMatrix) { CFWL_ThemeBackground param; @@ -144,7 +144,7 @@ void CFWL_PushButton::OnProcessMessage(CFWL_Message* pMessage) { CFWL_Widget::OnProcessMessage(pMessage); } -void CFWL_PushButton::OnDrawWidget(CFX_Graphics* pGraphics, +void CFWL_PushButton::OnDrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) { DrawWidget(pGraphics, pMatrix); } diff --git a/chromium/third_party/pdfium/xfa/fwl/cfwl_pushbutton.h b/chromium/third_party/pdfium/xfa/fwl/cfwl_pushbutton.h index f7323eb46b0..196c53763f5 100644 --- a/chromium/third_party/pdfium/xfa/fwl/cfwl_pushbutton.h +++ b/chromium/third_party/pdfium/xfa/fwl/cfwl_pushbutton.h @@ -28,13 +28,13 @@ class CFWL_PushButton : public CFWL_Widget { FWL_Type GetClassID() const override; void SetStates(uint32_t dwStates) override; void Update() override; - void DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; + void DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; void OnProcessMessage(CFWL_Message* pMessage) override; - void OnDrawWidget(CFX_Graphics* pGraphics, + void OnDrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; private: - void DrawBkground(CFX_Graphics* pGraphics, + void DrawBkground(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme, const CFX_Matrix* pMatrix); uint32_t GetPartStates(); diff --git a/chromium/third_party/pdfium/xfa/fwl/cfwl_scrollbar.cpp b/chromium/third_party/pdfium/xfa/fwl/cfwl_scrollbar.cpp index 79e8b481159..0e1a9be1ba6 100644 --- a/chromium/third_party/pdfium/xfa/fwl/cfwl_scrollbar.cpp +++ b/chromium/third_party/pdfium/xfa/fwl/cfwl_scrollbar.cpp @@ -74,7 +74,7 @@ void CFWL_ScrollBar::Update() { Layout(); } -void CFWL_ScrollBar::DrawWidget(CFX_Graphics* pGraphics, +void CFWL_ScrollBar::DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) { if (!pGraphics) return; @@ -104,7 +104,7 @@ bool CFWL_ScrollBar::DoScroll(CFWL_EventScroll::Code dwCode, float fPos) { return OnScroll(dwCode, fPos); } -void CFWL_ScrollBar::DrawTrack(CFX_Graphics* pGraphics, +void CFWL_ScrollBar::DrawTrack(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme, bool bLower, const CFX_Matrix* pMatrix) { @@ -120,7 +120,7 @@ void CFWL_ScrollBar::DrawTrack(CFX_Graphics* pGraphics, pTheme->DrawBackground(¶m); } -void CFWL_ScrollBar::DrawArrowBtn(CFX_Graphics* pGraphics, +void CFWL_ScrollBar::DrawArrowBtn(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme, bool bMinBtn, const CFX_Matrix* pMatrix) { @@ -137,7 +137,7 @@ void CFWL_ScrollBar::DrawArrowBtn(CFX_Graphics* pGraphics, pTheme->DrawBackground(¶m); } -void CFWL_ScrollBar::DrawThumb(CFX_Graphics* pGraphics, +void CFWL_ScrollBar::DrawThumb(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme, const CFX_Matrix* pMatrix) { CFWL_ThemeBackground param; @@ -355,7 +355,7 @@ void CFWL_ScrollBar::OnProcessMessage(CFWL_Message* pMessage) { } } -void CFWL_ScrollBar::OnDrawWidget(CFX_Graphics* pGraphics, +void CFWL_ScrollBar::OnDrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) { DrawWidget(pGraphics, pMatrix); } diff --git a/chromium/third_party/pdfium/xfa/fwl/cfwl_scrollbar.h b/chromium/third_party/pdfium/xfa/fwl/cfwl_scrollbar.h index 262d0794d8e..368dee96fee 100644 --- a/chromium/third_party/pdfium/xfa/fwl/cfwl_scrollbar.h +++ b/chromium/third_party/pdfium/xfa/fwl/cfwl_scrollbar.h @@ -30,9 +30,9 @@ class CFWL_ScrollBar : public CFWL_Widget { // CFWL_Widget FWL_Type GetClassID() const override; void Update() override; - void DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; + void DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; void OnProcessMessage(CFWL_Message* pMessage) override; - void OnDrawWidget(CFX_Graphics* pGraphics, + void OnDrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; void GetRange(float* fMin, float* fMax) const { @@ -66,15 +66,15 @@ class CFWL_ScrollBar : public CFWL_Widget { bool IsVertical() const { return !!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_SCB_Vert); } - void DrawTrack(CFX_Graphics* pGraphics, + void DrawTrack(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme, bool bLower, const CFX_Matrix* pMatrix); - void DrawArrowBtn(CFX_Graphics* pGraphics, + void DrawArrowBtn(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme, bool bMinBtn, const CFX_Matrix* pMatrix); - void DrawThumb(CFX_Graphics* pGraphics, + void DrawThumb(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme, const CFX_Matrix* pMatrix); void Layout(); diff --git a/chromium/third_party/pdfium/xfa/fwl/cfwl_spinbutton.cpp b/chromium/third_party/pdfium/xfa/fwl/cfwl_spinbutton.cpp index 65bd6cdd3a7..2943c205d7e 100644 --- a/chromium/third_party/pdfium/xfa/fwl/cfwl_spinbutton.cpp +++ b/chromium/third_party/pdfium/xfa/fwl/cfwl_spinbutton.cpp @@ -78,7 +78,7 @@ FWL_WidgetHit CFWL_SpinButton::HitTest(const CFX_PointF& point) { return FWL_WidgetHit::Unknown; } -void CFWL_SpinButton::DrawWidget(CFX_Graphics* pGraphics, +void CFWL_SpinButton::DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) { if (!pGraphics) return; @@ -107,7 +107,7 @@ bool CFWL_SpinButton::IsDownButtonEnabled() { return m_dwDnState != CFWL_PartState_Disabled; } -void CFWL_SpinButton::DrawUpButton(CFX_Graphics* pGraphics, +void CFWL_SpinButton::DrawUpButton(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme, const CFX_Matrix* pMatrix) { CFWL_ThemeBackground params; @@ -122,7 +122,7 @@ void CFWL_SpinButton::DrawUpButton(CFX_Graphics* pGraphics, pTheme->DrawBackground(¶ms); } -void CFWL_SpinButton::DrawDownButton(CFX_Graphics* pGraphics, +void CFWL_SpinButton::DrawDownButton(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme, const CFX_Matrix* pMatrix) { CFWL_ThemeBackground params; @@ -182,7 +182,7 @@ void CFWL_SpinButton::OnProcessMessage(CFWL_Message* pMessage) { CFWL_Widget::OnProcessMessage(pMessage); } -void CFWL_SpinButton::OnDrawWidget(CFX_Graphics* pGraphics, +void CFWL_SpinButton::OnDrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) { DrawWidget(pGraphics, pMatrix); } diff --git a/chromium/third_party/pdfium/xfa/fwl/cfwl_spinbutton.h b/chromium/third_party/pdfium/xfa/fwl/cfwl_spinbutton.h index 3cda761f91d..2dcb8483f23 100644 --- a/chromium/third_party/pdfium/xfa/fwl/cfwl_spinbutton.h +++ b/chromium/third_party/pdfium/xfa/fwl/cfwl_spinbutton.h @@ -28,9 +28,9 @@ class CFWL_SpinButton : public CFWL_Widget { FWL_Type GetClassID() const override; void Update() override; FWL_WidgetHit HitTest(const CFX_PointF& point) override; - void DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; + void DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; void OnProcessMessage(CFWL_Message* pMessage) override; - void OnDrawWidget(CFX_Graphics* pGraphics, + void OnDrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; private: @@ -46,10 +46,10 @@ class CFWL_SpinButton : public CFWL_Widget { void DisableButton(); bool IsUpButtonEnabled(); bool IsDownButtonEnabled(); - void DrawUpButton(CFX_Graphics* pGraphics, + void DrawUpButton(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme, const CFX_Matrix* pMatrix); - void DrawDownButton(CFX_Graphics* pGraphics, + void DrawDownButton(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme, const CFX_Matrix* pMatrix); void OnFocusChanged(CFWL_Message* pMsg, bool bSet); diff --git a/chromium/third_party/pdfium/xfa/fwl/cfwl_themebackground.h b/chromium/third_party/pdfium/xfa/fwl/cfwl_themebackground.h index f23f26e2297..0141754c1e7 100644 --- a/chromium/third_party/pdfium/xfa/fwl/cfwl_themebackground.h +++ b/chromium/third_party/pdfium/xfa/fwl/cfwl_themebackground.h @@ -11,16 +11,16 @@ #include "xfa/fwl/cfwl_themepart.h" class CFX_DIBitmpa; -class CFX_Graphics; -class CFX_Path; +class CXFA_Graphics; +class CXFA_Path; class CFWL_ThemeBackground : public CFWL_ThemePart { public: CFWL_ThemeBackground(); ~CFWL_ThemeBackground(); - CFX_Graphics* m_pGraphics; - CFX_Path* m_pPath; + CXFA_Graphics* m_pGraphics; + CXFA_Path* m_pPath; CFX_RetainPtr<CFX_DIBitmap> m_pImage; }; diff --git a/chromium/third_party/pdfium/xfa/fwl/cfwl_themetext.h b/chromium/third_party/pdfium/xfa/fwl/cfwl_themetext.h index 6cbc465bf32..7c8330e04e6 100644 --- a/chromium/third_party/pdfium/xfa/fwl/cfwl_themetext.h +++ b/chromium/third_party/pdfium/xfa/fwl/cfwl_themetext.h @@ -18,7 +18,7 @@ class CFWL_ThemeText : public CFWL_ThemePart { CFX_WideString m_wsText; uint32_t m_dwTTOStyles; int32_t m_iTTOAlign; - CFX_Graphics* m_pGraphics; + CXFA_Graphics* m_pGraphics; }; #endif // XFA_FWL_CFWL_THEMETEXT_H_ diff --git a/chromium/third_party/pdfium/xfa/fwl/cfwl_widget.cpp b/chromium/third_party/pdfium/xfa/fwl/cfwl_widget.cpp index 172014da62d..a2c270c332a 100644 --- a/chromium/third_party/pdfium/xfa/fwl/cfwl_widget.cpp +++ b/chromium/third_party/pdfium/xfa/fwl/cfwl_widget.cpp @@ -197,9 +197,8 @@ CFX_PointF CFWL_Widget::TransformTo(CFWL_Widget* pWidget, if (!parent) return ret; - CFX_Matrix m; - m.SetReverse(pWidget->GetMatrix()); - return m.Transform(ret) - pWidget->GetWidgetRect().TopLeft(); + return pWidget->GetMatrix().GetInverse().Transform(ret) - + pWidget->GetWidgetRect().TopLeft(); } CFX_Matrix CFWL_Widget::GetMatrix() { @@ -519,7 +518,7 @@ void CFWL_Widget::RepaintRect(const CFX_RectF& pRect) { m_pWidgetMgr->RepaintWidget(this, pRect); } -void CFWL_Widget::DrawBackground(CFX_Graphics* pGraphics, +void CFWL_Widget::DrawBackground(CXFA_Graphics* pGraphics, CFWL_Part iPartBk, IFWL_ThemeProvider* pTheme, const CFX_Matrix* pMatrix) { @@ -533,7 +532,7 @@ void CFWL_Widget::DrawBackground(CFX_Graphics* pGraphics, pTheme->DrawBackground(¶m); } -void CFWL_Widget::DrawBorder(CFX_Graphics* pGraphics, +void CFWL_Widget::DrawBorder(CXFA_Graphics* pGraphics, CFWL_Part iPartBorder, IFWL_ThemeProvider* pTheme, const CFX_Matrix* pMatrix) { @@ -611,5 +610,5 @@ void CFWL_Widget::OnProcessMessage(CFWL_Message* pMessage) { void CFWL_Widget::OnProcessEvent(CFWL_Event* pEvent) {} -void CFWL_Widget::OnDrawWidget(CFX_Graphics* pGraphics, +void CFWL_Widget::OnDrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) {} diff --git a/chromium/third_party/pdfium/xfa/fwl/cfwl_widget.h b/chromium/third_party/pdfium/xfa/fwl/cfwl_widget.h index 9bcbf55cbcf..316e6f5404e 100644 --- a/chromium/third_party/pdfium/xfa/fwl/cfwl_widget.h +++ b/chromium/third_party/pdfium/xfa/fwl/cfwl_widget.h @@ -63,14 +63,14 @@ class CFWL_Widget : public IFWL_WidgetDelegate { virtual void RemoveStates(uint32_t dwStates); virtual void Update() = 0; virtual FWL_WidgetHit HitTest(const CFX_PointF& point); - virtual void DrawWidget(CFX_Graphics* pGraphics, + virtual void DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) = 0; virtual void SetThemeProvider(IFWL_ThemeProvider* pThemeProvider); // IFWL_WidgetDelegate. void OnProcessMessage(CFWL_Message* pMessage) override; void OnProcessEvent(CFWL_Event* pEvent) override; - void OnDrawWidget(CFX_Graphics* pGraphics, + void OnDrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; void InflateWidgetRect(CFX_RectF& rect); @@ -143,7 +143,7 @@ class CFWL_Widget : public IFWL_WidgetDelegate { void RegisterEventTarget(CFWL_Widget* pEventSource); void UnregisterEventTarget(); void DispatchEvent(CFWL_Event* pEvent); - void DrawBorder(CFX_Graphics* pGraphics, + void DrawBorder(CXFA_Graphics* pGraphics, CFWL_Part iPartBorder, IFWL_ThemeProvider* pTheme, const CFX_Matrix* pMatrix); @@ -175,7 +175,7 @@ class CFWL_Widget : public IFWL_WidgetDelegate { float fMaxHeight, const CFX_RectF& rtAnchor, CFX_RectF& rtPopup); - void DrawBackground(CFX_Graphics* pGraphics, + void DrawBackground(CXFA_Graphics* pGraphics, CFWL_Part iPartBk, IFWL_ThemeProvider* pTheme, const CFX_Matrix* pMatrix); diff --git a/chromium/third_party/pdfium/xfa/fwl/cfwl_widgetmgr.cpp b/chromium/third_party/pdfium/xfa/fwl/cfwl_widgetmgr.cpp index d0dbf1f773b..eb98f2ee813 100644 --- a/chromium/third_party/pdfium/xfa/fwl/cfwl_widgetmgr.cpp +++ b/chromium/third_party/pdfium/xfa/fwl/cfwl_widgetmgr.cpp @@ -12,7 +12,7 @@ #include "xfa/fwl/cfwl_app.h" #include "xfa/fwl/cfwl_form.h" #include "xfa/fwl/cfwl_notedriver.h" -#include "xfa/fxfa/app/xfa_fwladapter.h" +#include "xfa/fxfa/app/cxfa_fwladapterwidgetmgr.h" #include "xfa/fxfa/cxfa_ffapp.h" namespace { @@ -266,12 +266,7 @@ CFWL_Widget* CFWL_WidgetMgr::GetWidgetAtPoint(CFWL_Widget* parent, CFWL_Widget* child = GetLastChildWidget(parent); while (child) { if ((child->GetStates() & FWL_WGTSTATE_Invisible) == 0) { - CFX_Matrix m; - m.SetIdentity(); - - CFX_Matrix matrixOnParent; - m.SetReverse(matrixOnParent); - pos = m.Transform(point); + pos = parent->GetMatrix().GetInverse().Transform(point); CFX_RectF bounds = child->GetWidgetRect(); if (bounds.Contains(pos)) { @@ -423,7 +418,7 @@ void CFWL_WidgetMgr::OnProcessMessageToForm(CFWL_Message* pMessage) { } void CFWL_WidgetMgr::OnDrawWidget(CFWL_Widget* pWidget, - CFX_Graphics* pGraphics, + CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) { if (!pWidget || !pGraphics) return; @@ -458,7 +453,7 @@ void CFWL_WidgetMgr::OnDrawWidget(CFWL_Widget* pWidget, void CFWL_WidgetMgr::DrawChild(CFWL_Widget* parent, const CFX_RectF& rtClip, - CFX_Graphics* pGraphics, + CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) { if (!parent) return; diff --git a/chromium/third_party/pdfium/xfa/fwl/cfwl_widgetmgr.h b/chromium/third_party/pdfium/xfa/fwl/cfwl_widgetmgr.h index 4c12e707f62..3b26c7155d3 100644 --- a/chromium/third_party/pdfium/xfa/fwl/cfwl_widgetmgr.h +++ b/chromium/third_party/pdfium/xfa/fwl/cfwl_widgetmgr.h @@ -13,14 +13,14 @@ #include "core/fxcrt/fx_system.h" #include "xfa/fwl/ifwl_widgetmgrdelegate.h" -#include "xfa/fxgraphics/cfx_graphics.h" +#include "xfa/fxgraphics/cxfa_graphics.h" #define FWL_WGTMGR_DisableForm 0x00000002 class CFWL_Message; class CXFA_FFApp; class CXFA_FWLAdapterWidgetMgr; -class CFX_Graphics; +class CXFA_Graphics; class CFX_Matrix; class CFWL_Widget; @@ -33,7 +33,7 @@ class CFWL_WidgetMgr : public CFWL_WidgetMgrDelegate { void OnSetCapability(uint32_t dwCapability) override; void OnProcessMessageToForm(CFWL_Message* pMessage) override; void OnDrawWidget(CFWL_Widget* pWidget, - CFX_Graphics* pGraphics, + CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) override; CFWL_Widget* GetParentWidget(CFWL_Widget* pWidget) const; @@ -82,7 +82,7 @@ class CFWL_WidgetMgr : public CFWL_WidgetMgrDelegate { Item* pPrevious; Item* pNext; CFWL_Widget* const pWidget; - std::unique_ptr<CFX_Graphics> pOffscreen; + std::unique_ptr<CXFA_Graphics> pOffscreen; int32_t iRedrawCounter; #if (_FX_OS_ == _FX_WIN32_DESKTOP_) || (_FX_OS_ == _FX_WIN64_) bool bOutsideChanged; @@ -103,11 +103,11 @@ class CFWL_WidgetMgr : public CFWL_WidgetMgrDelegate { void DrawChild(CFWL_Widget* pParent, const CFX_RectF& rtClip, - CFX_Graphics* pGraphics, + CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix); - CFX_Graphics* DrawWidgetBefore(CFWL_Widget* pWidget, - CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix); + CXFA_Graphics* DrawWidgetBefore(CFWL_Widget* pWidget, + CXFA_Graphics* pGraphics, + const CFX_Matrix* pMatrix); bool IsNeedRepaint(CFWL_Widget* pWidget, CFX_Matrix* pMatrix, const CFX_RectF& rtDirty); diff --git a/chromium/third_party/pdfium/xfa/fwl/ifwl_widgetdelegate.h b/chromium/third_party/pdfium/xfa/fwl/ifwl_widgetdelegate.h index a96f00dc9e9..8dee6da7a94 100644 --- a/chromium/third_party/pdfium/xfa/fwl/ifwl_widgetdelegate.h +++ b/chromium/third_party/pdfium/xfa/fwl/ifwl_widgetdelegate.h @@ -11,7 +11,7 @@ class CFWL_Event; class CFWL_Message; -class CFX_Graphics; +class CXFA_Graphics; class CFX_Matrix; class IFWL_WidgetDelegate { @@ -20,7 +20,7 @@ class IFWL_WidgetDelegate { virtual void OnProcessMessage(CFWL_Message* pMessage) = 0; virtual void OnProcessEvent(CFWL_Event* pEvent) = 0; - virtual void OnDrawWidget(CFX_Graphics* pGraphics, + virtual void OnDrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) = 0; }; diff --git a/chromium/third_party/pdfium/xfa/fwl/ifwl_widgetmgrdelegate.h b/chromium/third_party/pdfium/xfa/fwl/ifwl_widgetmgrdelegate.h index 9f0b5708b38..46996821c5f 100644 --- a/chromium/third_party/pdfium/xfa/fwl/ifwl_widgetmgrdelegate.h +++ b/chromium/third_party/pdfium/xfa/fwl/ifwl_widgetmgrdelegate.h @@ -8,7 +8,7 @@ #define XFA_FWL_IFWL_WIDGETMGRDELEGATE_H_ class CFWL_Message; -class CFX_Graphics; +class CXFA_Graphics; class CFX_Matrix; class CFWL_Widget; @@ -17,7 +17,7 @@ class CFWL_WidgetMgrDelegate { virtual void OnSetCapability(uint32_t dwCapability) = 0; virtual void OnProcessMessageToForm(CFWL_Message* pMessage) = 0; virtual void OnDrawWidget(CFWL_Widget* pWidget, - CFX_Graphics* pGraphics, + CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) = 0; }; diff --git a/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_carettp.cpp b/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_carettp.cpp index 4a04f869f4a..64eef9ffc97 100644 --- a/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_carettp.cpp +++ b/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_carettp.cpp @@ -9,8 +9,8 @@ #include "xfa/fwl/cfwl_caret.h" #include "xfa/fwl/cfwl_themebackground.h" #include "xfa/fwl/cfwl_widget.h" -#include "xfa/fxgraphics/cfx_color.h" -#include "xfa/fxgraphics/cfx_path.h" +#include "xfa/fxgraphics/cxfa_color.h" +#include "xfa/fxgraphics/cxfa_path.h" CFWL_CaretTP::CFWL_CaretTP() {} CFWL_CaretTP::~CFWL_CaretTP() {} @@ -25,7 +25,7 @@ void CFWL_CaretTP::DrawBackground(CFWL_ThemeBackground* pParams) { return; DrawCaretBK(pParams->m_pGraphics, pParams->m_dwStates, - &(pParams->m_rtPart), (CFX_Color*)pParams->m_pData, + &(pParams->m_rtPart), (CXFA_Color*)pParams->m_pData, &(pParams->m_matrix)); break; } @@ -34,18 +34,18 @@ void CFWL_CaretTP::DrawBackground(CFWL_ThemeBackground* pParams) { } } -void CFWL_CaretTP::DrawCaretBK(CFX_Graphics* pGraphics, +void CFWL_CaretTP::DrawCaretBK(CXFA_Graphics* pGraphics, uint32_t dwStates, const CFX_RectF* pRect, - CFX_Color* crFill, + CXFA_Color* crFill, CFX_Matrix* pMatrix) { - CFX_Path path; + CXFA_Path path; CFX_RectF rect = *pRect; path.AddRectangle(rect.left, rect.top, rect.width, rect.height); if (crFill) { pGraphics->SetFillColor(crFill); } else { - CFX_Color crFilltemp(ArgbEncode(255, 0, 0, 0)); + CXFA_Color crFilltemp(ArgbEncode(255, 0, 0, 0)); pGraphics->SetFillColor(&crFilltemp); } pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix); diff --git a/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_carettp.h b/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_carettp.h index f7d44b7f8ed..fdf330b8bfb 100644 --- a/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_carettp.h +++ b/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_carettp.h @@ -18,10 +18,10 @@ class CFWL_CaretTP : public CFWL_WidgetTP { void DrawBackground(CFWL_ThemeBackground* pParams) override; protected: - void DrawCaretBK(CFX_Graphics* pGraphics, + void DrawCaretBK(CXFA_Graphics* pGraphics, uint32_t dwStates, const CFX_RectF* pRect, - CFX_Color* crFill, + CXFA_Color* crFill, CFX_Matrix* pMatrix = nullptr); }; diff --git a/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_checkboxtp.cpp b/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_checkboxtp.cpp index 0a3ae88a460..334c1912a3f 100644 --- a/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_checkboxtp.cpp +++ b/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_checkboxtp.cpp @@ -13,8 +13,8 @@ #include "xfa/fwl/cfwl_themebackground.h" #include "xfa/fwl/cfwl_themetext.h" #include "xfa/fwl/cfwl_widget.h" -#include "xfa/fxgraphics/cfx_color.h" -#include "xfa/fxgraphics/cfx_path.h" +#include "xfa/fxgraphics/cxfa_color.h" +#include "xfa/fxgraphics/cxfa_path.h" namespace { @@ -56,7 +56,7 @@ void CFWL_CheckBoxTP::DrawText(CFWL_ThemeText* pParams) { CFWL_WidgetTP::DrawText(pParams); } -void CFWL_CheckBoxTP::DrawSignCheck(CFX_Graphics* pGraphics, +void CFWL_CheckBoxTP::DrawSignCheck(CXFA_Graphics* pGraphics, const CFX_RectF* pRtSign, FX_ARGB argbFill, CFX_Matrix* pMatrix) { @@ -67,38 +67,38 @@ void CFWL_CheckBoxTP::DrawSignCheck(CFX_Graphics* pGraphics, mt.SetIdentity(); mt.Translate(pRtSign->left, pRtSign->top); mt.Concat(*pMatrix); - CFX_Color crFill(argbFill); + CXFA_Color crFill(argbFill); pGraphics->SaveGraphState(); pGraphics->SetFillColor(&crFill); pGraphics->FillPath(m_pCheckPath.get(), FXFILL_WINDING, &mt); pGraphics->RestoreGraphState(); } -void CFWL_CheckBoxTP::DrawSignCircle(CFX_Graphics* pGraphics, +void CFWL_CheckBoxTP::DrawSignCircle(CXFA_Graphics* pGraphics, const CFX_RectF* pRtSign, FX_ARGB argbFill, CFX_Matrix* pMatrix) { - CFX_Path path; + CXFA_Path path; path.AddEllipse(*pRtSign); - CFX_Color crFill(argbFill); + CXFA_Color crFill(argbFill); pGraphics->SaveGraphState(); pGraphics->SetFillColor(&crFill); pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix); pGraphics->RestoreGraphState(); } -void CFWL_CheckBoxTP::DrawSignCross(CFX_Graphics* pGraphics, +void CFWL_CheckBoxTP::DrawSignCross(CXFA_Graphics* pGraphics, const CFX_RectF* pRtSign, FX_ARGB argbFill, CFX_Matrix* pMatrix) { - CFX_Path path; + CXFA_Path path; float fRight = pRtSign->right(); float fBottom = pRtSign->bottom(); path.AddLine(pRtSign->TopLeft(), CFX_PointF(fRight, fBottom)); path.AddLine(CFX_PointF(pRtSign->left, fBottom), CFX_PointF(fRight, pRtSign->top)); - CFX_Color crFill(argbFill); + CXFA_Color crFill(argbFill); pGraphics->SaveGraphState(); pGraphics->SetStrokeColor(&crFill); pGraphics->SetLineWidth(1.0f); @@ -106,11 +106,11 @@ void CFWL_CheckBoxTP::DrawSignCross(CFX_Graphics* pGraphics, pGraphics->RestoreGraphState(); } -void CFWL_CheckBoxTP::DrawSignDiamond(CFX_Graphics* pGraphics, +void CFWL_CheckBoxTP::DrawSignDiamond(CXFA_Graphics* pGraphics, const CFX_RectF* pRtSign, FX_ARGB argbFill, CFX_Matrix* pMatrix) { - CFX_Path path; + CXFA_Path path; float fWidth = pRtSign->width; float fHeight = pRtSign->height; float fBottom = pRtSign->bottom(); @@ -120,32 +120,32 @@ void CFWL_CheckBoxTP::DrawSignDiamond(CFX_Graphics* pGraphics, path.LineTo(CFX_PointF(pRtSign->right(), pRtSign->top + fHeight / 2)); path.LineTo(CFX_PointF(pRtSign->left + fWidth / 2, pRtSign->top)); - CFX_Color crFill(argbFill); + CXFA_Color crFill(argbFill); pGraphics->SaveGraphState(); pGraphics->SetFillColor(&crFill); pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix); pGraphics->RestoreGraphState(); } -void CFWL_CheckBoxTP::DrawSignSquare(CFX_Graphics* pGraphics, +void CFWL_CheckBoxTP::DrawSignSquare(CXFA_Graphics* pGraphics, const CFX_RectF* pRtSign, FX_ARGB argbFill, CFX_Matrix* pMatrix) { - CFX_Path path; + CXFA_Path path; path.AddRectangle(pRtSign->left, pRtSign->top, pRtSign->width, pRtSign->height); - CFX_Color crFill(argbFill); + CXFA_Color crFill(argbFill); pGraphics->SaveGraphState(); pGraphics->SetFillColor(&crFill); pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix); pGraphics->RestoreGraphState(); } -void CFWL_CheckBoxTP::DrawSignStar(CFX_Graphics* pGraphics, +void CFWL_CheckBoxTP::DrawSignStar(CXFA_Graphics* pGraphics, const CFX_RectF* pRtSign, FX_ARGB argbFill, CFX_Matrix* pMatrix) { - CFX_Path path; + CXFA_Path path; float fBottom = pRtSign->bottom(); float fRadius = (pRtSign->top - fBottom) / (1 + static_cast<float>(cos(FX_PI / 5.0f))); @@ -171,7 +171,7 @@ void CFWL_CheckBoxTP::DrawSignStar(CFX_Graphics* pGraphics, path.LineTo(points[nNext]); } - CFX_Color crFill(argbFill); + CXFA_Color crFill(argbFill); pGraphics->SaveGraphState(); pGraphics->SetFillColor(&crFill); pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix); @@ -218,7 +218,7 @@ void CFWL_CheckBoxTP::SetThemeData() { void CFWL_CheckBoxTP::InitCheckPath(float fCheckLen) { if (!m_pCheckPath) { - m_pCheckPath = pdfium::MakeUnique<CFX_Path>(); + m_pCheckPath = pdfium::MakeUnique<CXFA_Path>(); float fWidth = kSignPath; float fHeight = -kSignPath; @@ -263,7 +263,7 @@ void CFWL_CheckBoxTP::InitCheckPath(float fCheckLen) { m_pCheckPath->BezierTo(pt5 + p1, pt1 + p2, pt1); float fScale = fCheckLen / kSignPath; - CFX_Matrix mt(1, 0, 0, 1, 0, 0); + CFX_Matrix mt; mt.Scale(fScale, fScale); m_pCheckPath->TransformBy(mt); @@ -282,7 +282,7 @@ void CFWL_CheckBoxTP::DrawBackground(CFWL_ThemeBackground* pParams) { } void CFWL_CheckBoxTP::DrawCheckSign(CFWL_Widget* pWidget, - CFX_Graphics* pGraphics, + CXFA_Graphics* pGraphics, const CFX_RectF& pRtBox, int32_t iState, CFX_Matrix* pMatrix) { diff --git a/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_checkboxtp.h b/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_checkboxtp.h index 1070b125981..97ef5cf20c9 100644 --- a/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_checkboxtp.h +++ b/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_checkboxtp.h @@ -36,31 +36,31 @@ class CFWL_CheckBoxTP : public CFWL_WidgetTP { }; void DrawCheckSign(CFWL_Widget* pWidget, - CFX_Graphics* pGraphics, + CXFA_Graphics* pGraphics, const CFX_RectF& pRtBox, int32_t iState, CFX_Matrix* pMatrix); - void DrawSignCheck(CFX_Graphics* pGraphics, + void DrawSignCheck(CXFA_Graphics* pGraphics, const CFX_RectF* pRtSign, FX_ARGB argbFill, CFX_Matrix* pMatrix); - void DrawSignCircle(CFX_Graphics* pGraphics, + void DrawSignCircle(CXFA_Graphics* pGraphics, const CFX_RectF* pRtSign, FX_ARGB argbFill, CFX_Matrix* pMatrix); - void DrawSignCross(CFX_Graphics* pGraphics, + void DrawSignCross(CXFA_Graphics* pGraphics, const CFX_RectF* pRtSign, FX_ARGB argbFill, CFX_Matrix* pMatrix); - void DrawSignDiamond(CFX_Graphics* pGraphics, + void DrawSignDiamond(CXFA_Graphics* pGraphics, const CFX_RectF* pRtSign, FX_ARGB argbFill, CFX_Matrix* pMatrix); - void DrawSignSquare(CFX_Graphics* pGraphics, + void DrawSignSquare(CXFA_Graphics* pGraphics, const CFX_RectF* pRtSign, FX_ARGB argbFill, CFX_Matrix* pMatrix); - void DrawSignStar(CFX_Graphics* pGraphics, + void DrawSignStar(CXFA_Graphics* pGraphics, const CFX_RectF* pRtSign, FX_ARGB argbFill, CFX_Matrix* pMatrix); @@ -68,7 +68,7 @@ class CFWL_CheckBoxTP : public CFWL_WidgetTP { void InitCheckPath(float fCheckLen); std::unique_ptr<CKBThemeData> m_pThemeData; - std::unique_ptr<CFX_Path> m_pCheckPath; + std::unique_ptr<CXFA_Path> m_pCheckPath; private: void SetThemeData(); diff --git a/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_comboboxtp.cpp b/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_comboboxtp.cpp index 53a6eae722f..d8852ffe526 100644 --- a/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_comboboxtp.cpp +++ b/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_comboboxtp.cpp @@ -10,8 +10,8 @@ #include "xfa/fwl/cfwl_themebackground.h" #include "xfa/fwl/cfwl_widget.h" #include "xfa/fwl/ifwl_themeprovider.h" -#include "xfa/fxgraphics/cfx_color.h" -#include "xfa/fxgraphics/cfx_path.h" +#include "xfa/fxgraphics/cxfa_color.h" +#include "xfa/fxgraphics/cxfa_path.h" CFWL_ComboBoxTP::CFWL_ComboBoxTP() {} @@ -27,7 +27,7 @@ void CFWL_ComboBoxTP::DrawBackground(CFWL_ThemeBackground* pParams) { break; } case CFWL_Part::Background: { - CFX_Path path; + CXFA_Path path; CFX_RectF& rect = pParams->m_rtPart; path.AddRectangle(rect.left, rect.top, rect.width, rect.height); FX_ARGB argb_color; @@ -42,7 +42,7 @@ void CFWL_ComboBoxTP::DrawBackground(CFWL_ThemeBackground* pParams) { argb_color = 0xFFFFFFFF; } pParams->m_pGraphics->SaveGraphState(); - CFX_Color cr(argb_color); + CXFA_Color cr(argb_color); pParams->m_pGraphics->SetFillColor(&cr); pParams->m_pGraphics->FillPath(&path, FXFILL_WINDING, &pParams->m_matrix); pParams->m_pGraphics->RestoreGraphState(); @@ -64,10 +64,10 @@ void CFWL_ComboBoxTP::DrawBackground(CFWL_ThemeBackground* pParams) { void CFWL_ComboBoxTP::DrawStrethHandler(CFWL_ThemeBackground* pParams, uint32_t dwStates, CFX_Matrix* pMatrix) { - CFX_Path path; + CXFA_Path path; path.AddRectangle(pParams->m_rtPart.left, pParams->m_rtPart.top, pParams->m_rtPart.width - 1, pParams->m_rtPart.height); - CFX_Color cr(ArgbEncode(0xff, 0xff, 0, 0)); + CXFA_Color cr(ArgbEncode(0xff, 0xff, 0, 0)); pParams->m_pGraphics->SetFillColor(&cr); pParams->m_pGraphics->FillPath(&path, FXFILL_WINDING, &pParams->m_matrix); } diff --git a/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_edittp.cpp b/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_edittp.cpp index 138a99e59d1..b04136ba236 100644 --- a/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_edittp.cpp +++ b/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_edittp.cpp @@ -9,10 +9,10 @@ #include "xfa/fwl/cfwl_edit.h" #include "xfa/fwl/cfwl_themebackground.h" #include "xfa/fwl/cfwl_widget.h" -#include "xfa/fxfa/app/xfa_fwltheme.h" +#include "xfa/fxfa/app/cxfa_fwltheme.h" #include "xfa/fxfa/cxfa_ffwidget.h" -#include "xfa/fxgraphics/cfx_color.h" -#include "xfa/fxgraphics/cfx_path.h" +#include "xfa/fxgraphics/cxfa_color.h" +#include "xfa/fxgraphics/cxfa_path.h" CFWL_EditTP::CFWL_EditTP() {} @@ -30,7 +30,7 @@ void CFWL_EditTP::DrawBackground(CFWL_ThemeBackground* pParams) { fWidth = edge.GetThickness(); } } - CFX_Color crLine(cr); + CXFA_Color crLine(cr); pParams->m_pGraphics->SetStrokeColor(&crLine); pParams->m_pGraphics->SetLineWidth(fWidth); pParams->m_pGraphics->StrokePath(pParams->m_pPath, &pParams->m_matrix); @@ -44,18 +44,18 @@ void CFWL_EditTP::DrawBackground(CFWL_ThemeBackground* pParams) { } case CFWL_Part::Background: { if (pParams->m_pPath) { - CFX_Graphics* pGraphics = pParams->m_pGraphics; + CXFA_Graphics* pGraphics = pParams->m_pGraphics; pGraphics->SaveGraphState(); - CFX_Color crSelected(FWLTHEME_COLOR_BKSelected); + CXFA_Color crSelected(FWLTHEME_COLOR_BKSelected); pGraphics->SetFillColor(&crSelected); pGraphics->FillPath(pParams->m_pPath, FXFILL_WINDING, &pParams->m_matrix); pGraphics->RestoreGraphState(); } else { - CFX_Path path; + CXFA_Path path; path.AddRectangle(pParams->m_rtPart.left, pParams->m_rtPart.top, pParams->m_rtPart.width, pParams->m_rtPart.height); - CFX_Color cr(FWLTHEME_COLOR_Background); + CXFA_Color cr(FWLTHEME_COLOR_Background); if (!pParams->m_bStaticBackground) { if (pParams->m_dwStates & CFWL_PartState_Disabled) cr.Set(FWLTHEME_COLOR_EDGERB1); @@ -75,7 +75,7 @@ void CFWL_EditTP::DrawBackground(CFWL_ThemeBackground* pParams) { case CFWL_Part::CombTextLine: { FX_ARGB cr = 0xFF000000; float fWidth = 1.0f; - CFX_Color crLine(cr); + CXFA_Color crLine(cr); pParams->m_pGraphics->SetStrokeColor(&crLine); pParams->m_pGraphics->SetLineWidth(fWidth); pParams->m_pGraphics->StrokePath(pParams->m_pPath, &pParams->m_matrix); diff --git a/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_listboxtp.cpp b/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_listboxtp.cpp index 4e00420df53..caa764f953b 100644 --- a/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_listboxtp.cpp +++ b/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_listboxtp.cpp @@ -9,8 +9,8 @@ #include "xfa/fwl/cfwl_listbox.h" #include "xfa/fwl/cfwl_themebackground.h" #include "xfa/fwl/cfwl_widget.h" -#include "xfa/fxgraphics/cfx_color.h" -#include "xfa/fxgraphics/cfx_path.h" +#include "xfa/fxgraphics/cxfa_color.h" +#include "xfa/fxgraphics/cxfa_path.h" CFWL_ListBoxTP::CFWL_ListBoxTP() {} @@ -59,17 +59,17 @@ void CFWL_ListBoxTP::DrawBackground(CFWL_ThemeBackground* pParams) { } } -void CFWL_ListBoxTP::DrawListBoxItem(CFX_Graphics* pGraphics, +void CFWL_ListBoxTP::DrawListBoxItem(CXFA_Graphics* pGraphics, uint32_t dwStates, const CFX_RectF* prtItem, void* pData, CFX_Matrix* pMatrix) { if (dwStates & CFWL_PartState_Selected) { pGraphics->SaveGraphState(); - CFX_Color crFill(FWLTHEME_COLOR_BKSelected); + CXFA_Color crFill(FWLTHEME_COLOR_BKSelected); pGraphics->SetFillColor(&crFill); CFX_RectF rt(*prtItem); - CFX_Path path; + CXFA_Path path; #if (_FX_OS_ == _FX_MACOSX_) path.AddRectangle(rt.left, rt.top, rt.width - 1, rt.height - 1); #else diff --git a/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_listboxtp.h b/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_listboxtp.h index dcf5ec89bee..5dc45af4fec 100644 --- a/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_listboxtp.h +++ b/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_listboxtp.h @@ -18,7 +18,7 @@ class CFWL_ListBoxTP : public CFWL_WidgetTP { void DrawBackground(CFWL_ThemeBackground* pParams) override; protected: - void DrawListBoxItem(CFX_Graphics* pGraphics, + void DrawListBoxItem(CXFA_Graphics* pGraphics, uint32_t dwStates, const CFX_RectF* prtItem, void* pData = nullptr, diff --git a/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_monthcalendartp.cpp b/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_monthcalendartp.cpp index b9961af8b0c..8b73bac6686 100644 --- a/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_monthcalendartp.cpp +++ b/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_monthcalendartp.cpp @@ -12,8 +12,8 @@ #include "xfa/fwl/cfwl_themetext.h" #include "xfa/fwl/cfwl_widget.h" #include "xfa/fwl/ifwl_themeprovider.h" -#include "xfa/fxgraphics/cfx_color.h" -#include "xfa/fxgraphics/cfx_path.h" +#include "xfa/fxgraphics/cxfa_color.h" +#include "xfa/fxgraphics/cxfa_path.h" CFWL_MonthCalendarTP::CFWL_MonthCalendarTP() : m_pThemeData(new MCThemeData) { SetThemeData(); @@ -104,12 +104,12 @@ void CFWL_MonthCalendarTP::DrawText(CFWL_ThemeText* pParams) { void CFWL_MonthCalendarTP::DrawTotalBK(CFWL_ThemeBackground* pParams, CFX_Matrix* pMatrix) { - CFX_Path path; + CXFA_Path path; CFX_RectF rtTotal(pParams->m_rtPart); path.AddRectangle(rtTotal.left, rtTotal.top, rtTotal.width, rtTotal.height); pParams->m_pGraphics->SaveGraphState(); - CFX_Color clrBK(m_pThemeData->clrBK); + CXFA_Color clrBK(m_pThemeData->clrBK); pParams->m_pGraphics->SetFillColor(&clrBK); pParams->m_pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix); pParams->m_pGraphics->RestoreGraphState(); @@ -117,12 +117,12 @@ void CFWL_MonthCalendarTP::DrawTotalBK(CFWL_ThemeBackground* pParams, void CFWL_MonthCalendarTP::DrawHeadBk(CFWL_ThemeBackground* pParams, CFX_Matrix* pMatrix) { - CFX_Path path; + CXFA_Path path; CFX_RectF rtHead = pParams->m_rtPart; path.AddRectangle(rtHead.left, rtHead.top, rtHead.width, rtHead.height); pParams->m_pGraphics->SaveGraphState(); - CFX_Color clrHeadBK(m_pThemeData->clrBK); + CXFA_Color clrHeadBK(m_pThemeData->clrBK); pParams->m_pGraphics->SetFillColor(&clrHeadBK); pParams->m_pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix); pParams->m_pGraphics->RestoreGraphState(); @@ -130,20 +130,20 @@ void CFWL_MonthCalendarTP::DrawHeadBk(CFWL_ThemeBackground* pParams, void CFWL_MonthCalendarTP::DrawLButton(CFWL_ThemeBackground* pParams, CFX_Matrix* pMatrix) { - CFX_Path path; + CXFA_Path path; CFX_RectF rtLBtn = pParams->m_rtPart; path.AddRectangle(rtLBtn.left, rtLBtn.top, rtLBtn.width, rtLBtn.height); pParams->m_pGraphics->SaveGraphState(); - CFX_Color clrLBtnEdge(ArgbEncode(0xff, 205, 219, 243)); + CXFA_Color clrLBtnEdge(ArgbEncode(0xff, 205, 219, 243)); pParams->m_pGraphics->SetStrokeColor(&clrLBtnEdge); pParams->m_pGraphics->StrokePath(&path, pMatrix); if (pParams->m_dwStates & CFWL_PartState_Pressed) { - CFX_Color clrLBtnFill(ArgbEncode(0xff, 174, 198, 242)); + CXFA_Color clrLBtnFill(ArgbEncode(0xff, 174, 198, 242)); pParams->m_pGraphics->SetFillColor(&clrLBtnFill); pParams->m_pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix); } else { - CFX_Color clrLBtnFill(ArgbEncode(0xff, 227, 235, 249)); + CXFA_Color clrLBtnFill(ArgbEncode(0xff, 227, 235, 249)); pParams->m_pGraphics->SetFillColor(&clrLBtnFill); pParams->m_pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix); } @@ -156,7 +156,7 @@ void CFWL_MonthCalendarTP::DrawLButton(CFWL_ThemeBackground* pParams, path.LineTo(CFX_PointF(rtLBtn.left + rtLBtn.Width() / 3 * 2, rtLBtn.bottom() - rtLBtn.height / 4)); - CFX_Color clrFlag(ArgbEncode(0xff, 50, 104, 205)); + CXFA_Color clrFlag(ArgbEncode(0xff, 50, 104, 205)); pParams->m_pGraphics->SetStrokeColor(&clrFlag); pParams->m_pGraphics->StrokePath(&path, pMatrix); pParams->m_pGraphics->RestoreGraphState(); @@ -164,20 +164,20 @@ void CFWL_MonthCalendarTP::DrawLButton(CFWL_ThemeBackground* pParams, void CFWL_MonthCalendarTP::DrawRButton(CFWL_ThemeBackground* pParams, CFX_Matrix* pMatrix) { - CFX_Path path; + CXFA_Path path; CFX_RectF rtRBtn = pParams->m_rtPart; path.AddRectangle(rtRBtn.left, rtRBtn.top, rtRBtn.width, rtRBtn.height); pParams->m_pGraphics->SaveGraphState(); - CFX_Color clrRBtnEdge(ArgbEncode(0xff, 205, 219, 243)); + CXFA_Color clrRBtnEdge(ArgbEncode(0xff, 205, 219, 243)); pParams->m_pGraphics->SetStrokeColor(&clrRBtnEdge); pParams->m_pGraphics->StrokePath(&path, pMatrix); if (pParams->m_dwStates & CFWL_PartState_Pressed) { - CFX_Color clrRBtnFill(ArgbEncode(0xff, 174, 198, 242)); + CXFA_Color clrRBtnFill(ArgbEncode(0xff, 174, 198, 242)); pParams->m_pGraphics->SetFillColor(&clrRBtnFill); pParams->m_pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix); } else { - CFX_Color clrRBtnFill(ArgbEncode(0xff, 227, 235, 249)); + CXFA_Color clrRBtnFill(ArgbEncode(0xff, 227, 235, 249)); pParams->m_pGraphics->SetFillColor(&clrRBtnFill); pParams->m_pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix); } @@ -190,7 +190,7 @@ void CFWL_MonthCalendarTP::DrawRButton(CFWL_ThemeBackground* pParams, path.LineTo(CFX_PointF(rtRBtn.left + rtRBtn.Width() / 3, rtRBtn.bottom() - rtRBtn.height / 4)); - CFX_Color clrFlag(ArgbEncode(0xff, 50, 104, 205)); + CXFA_Color clrFlag(ArgbEncode(0xff, 50, 104, 205)); pParams->m_pGraphics->SetStrokeColor(&clrFlag); pParams->m_pGraphics->StrokePath(&path, pMatrix); pParams->m_pGraphics->RestoreGraphState(); @@ -198,13 +198,13 @@ void CFWL_MonthCalendarTP::DrawRButton(CFWL_ThemeBackground* pParams, void CFWL_MonthCalendarTP::DrawHSeperator(CFWL_ThemeBackground* pParams, CFX_Matrix* pMatrix) { - CFX_Path path; + CXFA_Path path; CFX_RectF rtHSep = pParams->m_rtPart; path.MoveTo(CFX_PointF(rtHSep.left, rtHSep.top + rtHSep.height / 2)); path.LineTo(CFX_PointF(rtHSep.right(), rtHSep.top + rtHSep.height / 2)); pParams->m_pGraphics->SaveGraphState(); - CFX_Color clrHSep(m_pThemeData->clrSeperator); + CXFA_Color clrHSep(m_pThemeData->clrSeperator); pParams->m_pGraphics->SetStrokeColor(&clrHSep); pParams->m_pGraphics->StrokePath(&path, pMatrix); pParams->m_pGraphics->RestoreGraphState(); @@ -212,13 +212,13 @@ void CFWL_MonthCalendarTP::DrawHSeperator(CFWL_ThemeBackground* pParams, void CFWL_MonthCalendarTP::DrawWeekNumSep(CFWL_ThemeBackground* pParams, CFX_Matrix* pMatrix) { - CFX_Path path; + CXFA_Path path; CFX_RectF rtWeekSep = pParams->m_rtPart; path.MoveTo(rtWeekSep.TopLeft()); path.LineTo(rtWeekSep.BottomLeft()); pParams->m_pGraphics->SaveGraphState(); - CFX_Color clrHSep(m_pThemeData->clrSeperator); + CXFA_Color clrHSep(m_pThemeData->clrSeperator); pParams->m_pGraphics->SetStrokeColor(&clrHSep); pParams->m_pGraphics->StrokePath(&path, pMatrix); pParams->m_pGraphics->RestoreGraphState(); @@ -228,19 +228,19 @@ void CFWL_MonthCalendarTP::DrawDatesInBK(CFWL_ThemeBackground* pParams, CFX_Matrix* pMatrix) { pParams->m_pGraphics->SaveGraphState(); if (pParams->m_dwStates & CFWL_PartState_Selected) { - CFX_Path path; + CXFA_Path path; CFX_RectF rtSelDay = pParams->m_rtPart; path.AddRectangle(rtSelDay.left, rtSelDay.top, rtSelDay.width, rtSelDay.height); - CFX_Color clrSelDayBK(m_pThemeData->clrDatesSelectedBK); + CXFA_Color clrSelDayBK(m_pThemeData->clrDatesSelectedBK); pParams->m_pGraphics->SetFillColor(&clrSelDayBK); pParams->m_pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix); } else if (pParams->m_dwStates & CFWL_PartState_Hovered) { - CFX_Path path; + CXFA_Path path; CFX_RectF rtSelDay = pParams->m_rtPart; path.AddRectangle(rtSelDay.left, rtSelDay.top, rtSelDay.width, rtSelDay.height); - CFX_Color clrSelDayBK(m_pThemeData->clrDatesHoverBK); + CXFA_Color clrSelDayBK(m_pThemeData->clrDatesHoverBK); pParams->m_pGraphics->SetFillColor(&clrSelDayBK); pParams->m_pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix); } @@ -249,12 +249,12 @@ void CFWL_MonthCalendarTP::DrawDatesInBK(CFWL_ThemeBackground* pParams, void CFWL_MonthCalendarTP::DrawDatesInCircle(CFWL_ThemeBackground* pParams, CFX_Matrix* pMatrix) { - CFX_Path path; + CXFA_Path path; CFX_RectF rtSelDay = pParams->m_rtPart; path.AddRectangle(rtSelDay.left, rtSelDay.top, rtSelDay.width, rtSelDay.height); pParams->m_pGraphics->SaveGraphState(); - CFX_Color clrSelDayBK(m_pThemeData->clrDatesCircle); + CXFA_Color clrSelDayBK(m_pThemeData->clrDatesCircle); pParams->m_pGraphics->SetStrokeColor(&clrSelDayBK); pParams->m_pGraphics->StrokePath(&path, pMatrix); pParams->m_pGraphics->RestoreGraphState(); @@ -262,12 +262,12 @@ void CFWL_MonthCalendarTP::DrawDatesInCircle(CFWL_ThemeBackground* pParams, void CFWL_MonthCalendarTP::DrawTodayCircle(CFWL_ThemeBackground* pParams, CFX_Matrix* pMatrix) { - CFX_Path path; + CXFA_Path path; CFX_RectF rtTodayCircle = pParams->m_rtPart; path.AddRectangle(rtTodayCircle.left, rtTodayCircle.top, rtTodayCircle.width, rtTodayCircle.height); pParams->m_pGraphics->SaveGraphState(); - CFX_Color clrTodayCircle(m_pThemeData->clrDatesCircle); + CXFA_Color clrTodayCircle(m_pThemeData->clrDatesCircle); pParams->m_pGraphics->SetStrokeColor(&clrTodayCircle); pParams->m_pGraphics->StrokePath(&path, pMatrix); pParams->m_pGraphics->RestoreGraphState(); diff --git a/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_pushbuttontp.cpp b/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_pushbuttontp.cpp index 6bb34d06572..d0f5760f44c 100644 --- a/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_pushbuttontp.cpp +++ b/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_pushbuttontp.cpp @@ -10,8 +10,8 @@ #include "xfa/fwl/cfwl_themebackground.h" #include "xfa/fwl/cfwl_widget.h" #include "xfa/fwl/ifwl_themeprovider.h" -#include "xfa/fxgraphics/cfx_color.h" -#include "xfa/fxgraphics/cfx_path.h" +#include "xfa/fxgraphics/cxfa_color.h" +#include "xfa/fxgraphics/cxfa_path.h" #define PUSHBUTTON_SIZE_Corner 2 @@ -32,7 +32,7 @@ void CFWL_PushButtonTP::DrawBackground(CFWL_ThemeBackground* pParams) { float fRight = rect.right(); float fBottom = rect.bottom(); - CFX_Path strokePath; + CXFA_Path strokePath; strokePath.MoveTo( CFX_PointF(rect.left + PUSHBUTTON_SIZE_Corner, rect.top)); strokePath.LineTo(CFX_PointF(fRight - PUSHBUTTON_SIZE_Corner, rect.top)); @@ -48,10 +48,10 @@ void CFWL_PushButtonTP::DrawBackground(CFWL_ThemeBackground* pParams) { strokePath.LineTo( CFX_PointF(rect.left + PUSHBUTTON_SIZE_Corner, rect.top)); - CFX_Path fillPath; + CXFA_Path fillPath; fillPath.AddSubpath(&strokePath); - CFX_Graphics* pGraphics = pParams->m_pGraphics; + CXFA_Graphics* pGraphics = pParams->m_pGraphics; pGraphics->SaveGraphState(); CFX_RectF rtInner(rect); @@ -67,7 +67,7 @@ void CFWL_PushButtonTP::DrawBackground(CFWL_ThemeBackground* pParams) { m_pThemeData->clrEnd[iColor], &fillPath, FXFILL_ALTERNATE, &pParams->m_matrix); - CFX_Color crStroke(m_pThemeData->clrBorder[iColor]); + CXFA_Color crStroke(m_pThemeData->clrBorder[iColor]); pGraphics->SetStrokeColor(&crStroke); pGraphics->StrokePath(&strokePath, &pParams->m_matrix); @@ -75,7 +75,7 @@ void CFWL_PushButtonTP::DrawBackground(CFWL_ThemeBackground* pParams) { fillPath.AddRectangle(rtInner.left, rtInner.top, rtInner.width, rtInner.height); - CFX_Color crFill(m_pThemeData->clrFill[iColor]); + CXFA_Color crFill(m_pThemeData->clrFill[iColor]); pGraphics->SetFillColor(&crFill); pGraphics->FillPath(&fillPath, FXFILL_WINDING, &pParams->m_matrix); if (pParams->m_dwStates & CFWL_PartState_Focused) { diff --git a/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_scrollbartp.cpp b/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_scrollbartp.cpp index bab9a3f3be9..2975888ac2c 100644 --- a/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_scrollbartp.cpp +++ b/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_scrollbartp.cpp @@ -10,8 +10,8 @@ #include "xfa/fwl/cfwl_themebackground.h" #include "xfa/fwl/cfwl_widget.h" #include "xfa/fwl/ifwl_themeprovider.h" -#include "xfa/fxgraphics/cfx_color.h" -#include "xfa/fxgraphics/cfx_path.h" +#include "xfa/fxgraphics/cxfa_color.h" +#include "xfa/fxgraphics/cxfa_path.h" namespace { @@ -38,7 +38,7 @@ void CFWL_ScrollBarTP::DrawBackground(CFWL_ThemeBackground* pParams) { else if (pParams->m_dwStates & CFWL_PartState_Disabled) eState = FWLTHEME_STATE_Disable; - CFX_Graphics* pGraphics = pParams->m_pGraphics; + CXFA_Graphics* pGraphics = pParams->m_pGraphics; CFX_RectF* pRect = &pParams->m_rtPart; bool bVert = !!pWidget->GetStylesEx(); switch (pParams->m_iPart) { @@ -71,7 +71,7 @@ void CFWL_ScrollBarTP::DrawBackground(CFWL_ThemeBackground* pParams) { } } -void CFWL_ScrollBarTP::DrawThumbBtn(CFX_Graphics* pGraphics, +void CFWL_ScrollBarTP::DrawThumbBtn(CXFA_Graphics* pGraphics, const CFX_RectF* pRect, bool bVert, FWLTHEME_STATE eState, @@ -80,7 +80,7 @@ void CFWL_ScrollBarTP::DrawThumbBtn(CFX_Graphics* pGraphics, if (eState < FWLTHEME_STATE_Normal || eState > FWLTHEME_STATE_Disable) return; - CFX_Path path; + CXFA_Path path; CFX_RectF rect(*pRect); if (bVert) { rect.Deflate(1, 0); @@ -92,7 +92,7 @@ void CFWL_ScrollBarTP::DrawThumbBtn(CFX_Graphics* pGraphics, m_pThemeData->clrBtnBK[eState - 1][0], m_pThemeData->clrBtnBK[eState - 1][1], &path, FXFILL_WINDING, pMatrix); - CFX_Color rcStroke; + CXFA_Color rcStroke; rcStroke.Set(m_pThemeData->clrBtnBorder[eState - 1]); pGraphics->SaveGraphState(); pGraphics->SetStrokeColor(&rcStroke); @@ -108,7 +108,7 @@ void CFWL_ScrollBarTP::DrawThumbBtn(CFX_Graphics* pGraphics, m_pThemeData->clrBtnBK[eState - 1][0], m_pThemeData->clrBtnBK[eState - 1][1], &path, FXFILL_WINDING, pMatrix); - CFX_Color rcStroke; + CXFA_Color rcStroke; rcStroke.Set(m_pThemeData->clrBtnBorder[eState - 1]); pGraphics->SaveGraphState(); pGraphics->SetStrokeColor(&rcStroke); @@ -117,12 +117,12 @@ void CFWL_ScrollBarTP::DrawThumbBtn(CFX_Graphics* pGraphics, } } -void CFWL_ScrollBarTP::DrawPaw(CFX_Graphics* pGraphics, +void CFWL_ScrollBarTP::DrawPaw(CXFA_Graphics* pGraphics, const CFX_RectF* pRect, bool bVert, FWLTHEME_STATE eState, CFX_Matrix* pMatrix) { - CFX_Path path; + CXFA_Path path; if (bVert) { float fPawLen = kPawLength; if (pRect->width / 2 <= fPawLen) { @@ -140,7 +140,7 @@ void CFWL_ScrollBarTP::DrawPaw(CFX_Graphics* pGraphics, path.MoveTo(CFX_PointF(fX, fY + 2)); path.LineTo(CFX_PointF(fX + fPawLen, fY + 2)); - CFX_Color clrLight(m_pThemeData->clrPawColorLight[eState - 1]); + CXFA_Color clrLight(m_pThemeData->clrPawColorLight[eState - 1]); pGraphics->SetLineWidth(1); pGraphics->SetStrokeColor(&clrLight); pGraphics->StrokePath(&path); @@ -156,7 +156,7 @@ void CFWL_ScrollBarTP::DrawPaw(CFX_Graphics* pGraphics, path.MoveTo(CFX_PointF(fX, fY + 3)); path.LineTo(CFX_PointF(fX + fPawLen, fY + 3)); - CFX_Color clrDark(m_pThemeData->clrPawColorDark[eState - 1]); + CXFA_Color clrDark(m_pThemeData->clrPawColorDark[eState - 1]); pGraphics->SetLineWidth(1); pGraphics->SetStrokeColor(&clrDark); pGraphics->StrokePath(&path, pMatrix); @@ -177,7 +177,7 @@ void CFWL_ScrollBarTP::DrawPaw(CFX_Graphics* pGraphics, path.MoveTo(CFX_PointF(fX + 2, fY)); path.LineTo(CFX_PointF(fX + 2, fY + fPawLen)); - CFX_Color clrLight(m_pThemeData->clrPawColorLight[eState - 1]); + CXFA_Color clrLight(m_pThemeData->clrPawColorLight[eState - 1]); pGraphics->SetLineWidth(1); pGraphics->SetStrokeColor(&clrLight); pGraphics->StrokePath(&path, pMatrix); @@ -193,14 +193,14 @@ void CFWL_ScrollBarTP::DrawPaw(CFX_Graphics* pGraphics, path.MoveTo(CFX_PointF(fX + 3, fY)); path.LineTo(CFX_PointF(fX + 3, fY + fPawLen)); - CFX_Color clrDark(m_pThemeData->clrPawColorDark[eState - 1]); + CXFA_Color clrDark(m_pThemeData->clrPawColorDark[eState - 1]); pGraphics->SetLineWidth(1); pGraphics->SetStrokeColor(&clrDark); pGraphics->StrokePath(&path, pMatrix); } } -void CFWL_ScrollBarTP::DrawTrack(CFX_Graphics* pGraphics, +void CFWL_ScrollBarTP::DrawTrack(CXFA_Graphics* pGraphics, const CFX_RectF* pRect, bool bVert, FWLTHEME_STATE eState, @@ -210,8 +210,8 @@ void CFWL_ScrollBarTP::DrawTrack(CFX_Graphics* pGraphics, return; pGraphics->SaveGraphState(); - CFX_Color colorLine(ArgbEncode(255, 238, 237, 229)); - CFX_Path path; + CXFA_Color colorLine(ArgbEncode(255, 238, 237, 229)); + CXFA_Path path; float fRight = pRect->right(); float fBottom = pRect->bottom(); if (bVert) { @@ -235,7 +235,7 @@ void CFWL_ScrollBarTP::DrawTrack(CFX_Graphics* pGraphics, m_pThemeData->clrTrackBKEnd, &path, FXFILL_WINDING, pMatrix); } -void CFWL_ScrollBarTP::DrawMaxMinBtn(CFX_Graphics* pGraphics, +void CFWL_ScrollBarTP::DrawMaxMinBtn(CXFA_Graphics* pGraphics, const CFX_RectF* pRect, FWLTHEME_DIRECTION eDict, FWLTHEME_STATE eState, diff --git a/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_scrollbartp.h b/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_scrollbartp.h index 2389eff3c94..eec372c6608 100644 --- a/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_scrollbartp.h +++ b/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_scrollbartp.h @@ -29,24 +29,24 @@ class CFWL_ScrollBarTP : public CFWL_WidgetTP { FX_ARGB clrTrackBKEnd; }; - void DrawThumbBtn(CFX_Graphics* pGraphics, + void DrawThumbBtn(CXFA_Graphics* pGraphics, const CFX_RectF* pRect, bool bVert, FWLTHEME_STATE eState, bool bPawButton = true, CFX_Matrix* pMatrix = nullptr); - void DrawTrack(CFX_Graphics* pGraphics, + void DrawTrack(CXFA_Graphics* pGraphics, const CFX_RectF* pRect, bool bVert, FWLTHEME_STATE eState, bool bLowerTrack, CFX_Matrix* pMatrix = nullptr); - void DrawMaxMinBtn(CFX_Graphics* pGraphics, + void DrawMaxMinBtn(CXFA_Graphics* pGraphics, const CFX_RectF* pRect, FWLTHEME_DIRECTION eDict, FWLTHEME_STATE eState, CFX_Matrix* pMatrix = nullptr); - void DrawPaw(CFX_Graphics* pGraphics, + void DrawPaw(CXFA_Graphics* pGraphics, const CFX_RectF* pRect, bool bVert, FWLTHEME_STATE eState, diff --git a/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_widgettp.cpp b/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_widgettp.cpp index a45716ad6b7..e863a0e0d34 100644 --- a/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_widgettp.cpp +++ b/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_widgettp.cpp @@ -19,9 +19,9 @@ #include "xfa/fwl/cfwl_widget.h" #include "xfa/fwl/cfwl_widgetmgr.h" #include "xfa/fwl/ifwl_themeprovider.h" -#include "xfa/fxgraphics/cfx_color.h" -#include "xfa/fxgraphics/cfx_path.h" -#include "xfa/fxgraphics/cfx_shading.h" +#include "xfa/fxgraphics/cxfa_color.h" +#include "xfa/fxgraphics/cxfa_path.h" +#include "xfa/fxgraphics/cxfa_shading.h" CFWL_WidgetTP::CFWL_WidgetTP() : m_dwRefCount(1), m_pFDEFont(nullptr), m_pColorData(nullptr) {} @@ -45,7 +45,7 @@ void CFWL_WidgetTP::DrawText(CFWL_ThemeText* pParams) { if (iLen <= 0) return; - CFX_Graphics* pGraphics = pParams->m_pGraphics; + CXFA_Graphics* pGraphics = pParams->m_pGraphics; m_pTextOut->SetRenderDevice(pGraphics->GetRenderDevice()); m_pTextOut->SetStyles(pParams->m_dwTTOStyles); m_pTextOut->SetAlignment(pParams->m_iTTOAlign); @@ -96,31 +96,31 @@ void CFWL_WidgetTP::FinalizeTTO() { m_pTextOut.reset(); } -void CFWL_WidgetTP::DrawBorder(CFX_Graphics* pGraphics, +void CFWL_WidgetTP::DrawBorder(CXFA_Graphics* pGraphics, const CFX_RectF* pRect, CFX_Matrix* pMatrix) { if (!pGraphics) return; if (!pRect) return; - CFX_Path path; + CXFA_Path path; path.AddRectangle(pRect->left, pRect->top, pRect->width, pRect->height); path.AddRectangle(pRect->left + 1, pRect->top + 1, pRect->width - 2, pRect->height - 2); pGraphics->SaveGraphState(); - CFX_Color crFill(ArgbEncode(255, 0, 0, 0)); + CXFA_Color crFill(ArgbEncode(255, 0, 0, 0)); pGraphics->SetFillColor(&crFill); pGraphics->FillPath(&path, FXFILL_ALTERNATE, pMatrix); pGraphics->RestoreGraphState(); } -void CFWL_WidgetTP::FillBackground(CFX_Graphics* pGraphics, +void CFWL_WidgetTP::FillBackground(CXFA_Graphics* pGraphics, const CFX_RectF* pRect, CFX_Matrix* pMatrix) { FillSoildRect(pGraphics, FWLTHEME_COLOR_Background, pRect, pMatrix); } -void CFWL_WidgetTP::FillSoildRect(CFX_Graphics* pGraphics, +void CFWL_WidgetTP::FillSoildRect(CXFA_Graphics* pGraphics, FX_ARGB fillColor, const CFX_RectF* pRect, CFX_Matrix* pMatrix) { @@ -129,22 +129,22 @@ void CFWL_WidgetTP::FillSoildRect(CFX_Graphics* pGraphics, if (!pRect) return; pGraphics->SaveGraphState(); - CFX_Color crFill(fillColor); + CXFA_Color crFill(fillColor); pGraphics->SetFillColor(&crFill); - CFX_Path path; + CXFA_Path path; path.AddRectangle(pRect->left, pRect->top, pRect->width, pRect->height); pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix); pGraphics->RestoreGraphState(); } -void CFWL_WidgetTP::DrawAxialShading(CFX_Graphics* pGraphics, +void CFWL_WidgetTP::DrawAxialShading(CXFA_Graphics* pGraphics, float fx1, float fy1, float fx2, float fy2, FX_ARGB beginColor, FX_ARGB endColor, - CFX_Path* path, + CXFA_Path* path, int32_t fillMode, CFX_Matrix* pMatrix) { if (!pGraphics || !path) @@ -152,15 +152,15 @@ void CFWL_WidgetTP::DrawAxialShading(CFX_Graphics* pGraphics, CFX_PointF begPoint(fx1, fy1); CFX_PointF endPoint(fx2, fy2); - CFX_Shading shading(begPoint, endPoint, false, false, beginColor, endColor); + CXFA_Shading shading(begPoint, endPoint, false, false, beginColor, endColor); pGraphics->SaveGraphState(); - CFX_Color color1(&shading); + CXFA_Color color1(&shading); pGraphics->SetFillColor(&color1); pGraphics->FillPath(path, fillMode, pMatrix); pGraphics->RestoreGraphState(); } -void CFWL_WidgetTP::DrawFocus(CFX_Graphics* pGraphics, +void CFWL_WidgetTP::DrawFocus(CXFA_Graphics* pGraphics, const CFX_RectF* pRect, CFX_Matrix* pMatrix) { if (!pGraphics) @@ -168,17 +168,17 @@ void CFWL_WidgetTP::DrawFocus(CFX_Graphics* pGraphics, if (!pRect) return; pGraphics->SaveGraphState(); - CFX_Color cr(0xFF000000); + CXFA_Color cr(0xFF000000); pGraphics->SetStrokeColor(&cr); float DashPattern[2] = {1, 1}; pGraphics->SetLineDash(0.0f, DashPattern, 2); - CFX_Path path; + CXFA_Path path; path.AddRectangle(pRect->left, pRect->top, pRect->width, pRect->height); pGraphics->StrokePath(&path, pMatrix); pGraphics->RestoreGraphState(); } -void CFWL_WidgetTP::DrawArrow(CFX_Graphics* pGraphics, +void CFWL_WidgetTP::DrawArrow(CXFA_Graphics* pGraphics, const CFX_RectF* pRect, FWLTHEME_DIRECTION eDict, FX_ARGB argSign, @@ -189,7 +189,7 @@ void CFWL_WidgetTP::DrawArrow(CFX_Graphics* pGraphics, (float)(((pRect->width - (bVert ? 9 : 6)) / 2 + pRect->left) + 0.5); float fTop = (float)(((pRect->height - (bVert ? 6 : 9)) / 2 + pRect->top) + 0.5); - CFX_Path path; + CXFA_Path path; switch (eDict) { case FWLTHEME_DIRECTION_Down: { path.MoveTo(CFX_PointF(fLeft, fTop + 1)); @@ -228,16 +228,16 @@ void CFWL_WidgetTP::DrawArrow(CFX_Graphics* pGraphics, break; } } - CFX_Color cr(argSign); + CXFA_Color cr(argSign); pGraphics->SetFillColor(&cr); pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix); } -void CFWL_WidgetTP::DrawBtn(CFX_Graphics* pGraphics, +void CFWL_WidgetTP::DrawBtn(CXFA_Graphics* pGraphics, const CFX_RectF* pRect, FWLTHEME_STATE eState, CFX_Matrix* pMatrix) { - CFX_Path path; + CXFA_Path path; InitializeArrowColorData(); float fRight = pRect->right(); @@ -248,13 +248,13 @@ void CFWL_WidgetTP::DrawBtn(CFX_Graphics* pGraphics, m_pColorData->clrEnd[eState - 1], &path, FXFILL_WINDING, pMatrix); - CFX_Color rcStroke; + CXFA_Color rcStroke; rcStroke.Set(m_pColorData->clrBorder[eState - 1]); pGraphics->SetStrokeColor(&rcStroke); pGraphics->StrokePath(&path, pMatrix); } -void CFWL_WidgetTP::DrawArrowBtn(CFX_Graphics* pGraphics, +void CFWL_WidgetTP::DrawArrowBtn(CXFA_Graphics* pGraphics, const CFX_RectF* pRect, FWLTHEME_DIRECTION eDict, FWLTHEME_STATE eState, @@ -291,8 +291,9 @@ bool CFWL_FontData::LoadFont(const CFX_WideStringC& wsFontFamily, m_pFontMgr = CFGAS_FontMgr::Create(m_pFontSource.get()); #endif } - m_pFont = CFGAS_GEFont::LoadFont(wsFontFamily.c_str(), dwFontStyles, - dwCodePage, m_pFontMgr.get()); + // TODO(tsepez): check usage of c_str() below. + m_pFont = CFGAS_GEFont::LoadFont(wsFontFamily.unterminated_c_str(), + dwFontStyles, dwCodePage, m_pFontMgr.get()); return !!m_pFont; } diff --git a/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_widgettp.h b/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_widgettp.h index 730a39cd17b..229b9ea7c3d 100644 --- a/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_widgettp.h +++ b/chromium/third_party/pdfium/xfa/fwl/theme/cfwl_widgettp.h @@ -15,7 +15,7 @@ #include "core/fxcrt/fx_system.h" #include "xfa/fgas/font/cfgas_gefont.h" #include "xfa/fwl/theme/cfwl_utils.h" -#include "xfa/fxgraphics/cfx_graphics.h" +#include "xfa/fxgraphics/cxfa_graphics.h" class CFDE_TextOut; class CFGAS_GEFont; @@ -55,39 +55,39 @@ class CFWL_WidgetTP { void InitTTO(); void FinalizeTTO(); - void DrawBorder(CFX_Graphics* pGraphics, + void DrawBorder(CXFA_Graphics* pGraphics, const CFX_RectF* pRect, CFX_Matrix* pMatrix = nullptr); - void FillBackground(CFX_Graphics* pGraphics, + void FillBackground(CXFA_Graphics* pGraphics, const CFX_RectF* pRect, CFX_Matrix* pMatrix = nullptr); - void FillSoildRect(CFX_Graphics* pGraphics, + void FillSoildRect(CXFA_Graphics* pGraphics, FX_ARGB fillColor, const CFX_RectF* pRect, CFX_Matrix* pMatrix = nullptr); - void DrawAxialShading(CFX_Graphics* pGraphics, + void DrawAxialShading(CXFA_Graphics* pGraphics, float fx1, float fy1, float fx2, float fy2, FX_ARGB beginColor, FX_ARGB endColor, - CFX_Path* path, + CXFA_Path* path, int32_t fillMode = FXFILL_WINDING, CFX_Matrix* pMatrix = nullptr); - void DrawFocus(CFX_Graphics* pGraphics, + void DrawFocus(CXFA_Graphics* pGraphics, const CFX_RectF* pRect, CFX_Matrix* pMatrix = nullptr); - void DrawArrow(CFX_Graphics* pGraphics, + void DrawArrow(CXFA_Graphics* pGraphics, const CFX_RectF* pRect, FWLTHEME_DIRECTION eDict, FX_ARGB argSign, CFX_Matrix* pMatrix = nullptr); - void DrawBtn(CFX_Graphics* pGraphics, + void DrawBtn(CXFA_Graphics* pGraphics, const CFX_RectF* pRect, FWLTHEME_STATE eState, CFX_Matrix* pMatrix = nullptr); - void DrawArrowBtn(CFX_Graphics* pGraphics, + void DrawArrowBtn(CXFA_Graphics* pGraphics, const CFX_RectF* pRect, FWLTHEME_DIRECTION eDict, FWLTHEME_STATE eState, diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffarc.cpp b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffarc.cpp new file mode 100644 index 00000000000..1a12fb5f23d --- /dev/null +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffarc.cpp @@ -0,0 +1,33 @@ +// Copyright 2017 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 "xfa/fxfa/app/cxfa_ffarc.h" + +CXFA_FFArc::CXFA_FFArc(CXFA_WidgetAcc* pDataAcc) : CXFA_FFDraw(pDataAcc) {} + +CXFA_FFArc::~CXFA_FFArc() {} + +void CXFA_FFArc::RenderWidget(CXFA_Graphics* pGS, + CFX_Matrix* pMatrix, + uint32_t dwStatus) { + if (!IsMatchVisibleStatus(dwStatus)) + return; + + CXFA_Value value = m_pDataAcc->GetFormValue(); + if (!value) + return; + + CXFA_Arc arcObj = value.GetArc(); + CFX_Matrix mtRotate = GetRotateMatrix(); + if (pMatrix) + mtRotate.Concat(*pMatrix); + + CFX_RectF rtArc = GetRectWithoutRotate(); + if (CXFA_Margin mgWidget = m_pDataAcc->GetMargin()) + XFA_RectWidthoutMargin(rtArc, mgWidget); + + DrawBorder(pGS, arcObj, rtArc, &mtRotate); +} diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffarc.h b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffarc.h new file mode 100644 index 00000000000..f1bc82f1d2b --- /dev/null +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffarc.h @@ -0,0 +1,23 @@ +// Copyright 2017 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 + +#ifndef XFA_FXFA_APP_CXFA_FFARC_H_ +#define XFA_FXFA_APP_CXFA_FFARC_H_ + +#include "xfa/fxfa/app/cxfa_ffdraw.h" + +class CXFA_FFArc : public CXFA_FFDraw { + public: + explicit CXFA_FFArc(CXFA_WidgetAcc* pDataAcc); + ~CXFA_FFArc() override; + + // CXFA_FFWidget + void RenderWidget(CXFA_Graphics* pGS, + CFX_Matrix* pMatrix, + uint32_t dwStatus) override; +}; + +#endif // XFA_FXFA_APP_CXFA_FFARC_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffbarcode.cpp b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffbarcode.cpp index 4dcffa5bad9..7bbb60dd77d 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffbarcode.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffbarcode.cpp @@ -4,7 +4,7 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fxfa/app/xfa_ffbarcode.h" +#include "xfa/fxfa/app/cxfa_ffbarcode.h" #include <utility> @@ -13,9 +13,8 @@ #include "xfa/fwl/cfwl_app.h" #include "xfa/fwl/cfwl_barcode.h" #include "xfa/fwl/cfwl_notedriver.h" -#include "xfa/fxfa/app/xfa_fffield.h" -#include "xfa/fxfa/app/xfa_fftextedit.h" -#include "xfa/fxfa/app/xfa_fwladapter.h" +#include "xfa/fxfa/app/cxfa_fffield.h" +#include "xfa/fxfa/app/cxfa_fwladapterwidgetmgr.h" #include "xfa/fxfa/cxfa_ffpageview.h" #include "xfa/fxfa/cxfa_ffwidget.h" @@ -138,7 +137,7 @@ bool CXFA_FFBarcode::LoadWidget() { return CXFA_FFField::LoadWidget(); } -void CXFA_FFBarcode::RenderWidget(CFX_Graphics* pGS, +void CXFA_FFBarcode::RenderWidget(CXFA_Graphics* pGS, CFX_Matrix* pMatrix, uint32_t dwStatus) { if (!IsMatchVisibleStatus(dwStatus)) diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffbarcode.h b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffbarcode.h index 51646236d0f..782aec39a1f 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffbarcode.h +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffbarcode.h @@ -4,11 +4,11 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef XFA_FXFA_APP_XFA_FFBARCODE_H_ -#define XFA_FXFA_APP_XFA_FFBARCODE_H_ +#ifndef XFA_FXFA_APP_CXFA_FFBARCODE_H_ +#define XFA_FXFA_APP_CXFA_FFBARCODE_H_ #include "fxbarcode/BC_Library.h" -#include "xfa/fxfa/app/xfa_fftextedit.h" +#include "xfa/fxfa/app/cxfa_fftextedit.h" #include "xfa/fxfa/cxfa_ffpageview.h" enum class BarcodeType { @@ -92,7 +92,7 @@ class CXFA_FFBarcode : public CXFA_FFTextEdit { // CXFA_FFTextEdit bool LoadWidget() override; - void RenderWidget(CFX_Graphics* pGS, + void RenderWidget(CXFA_Graphics* pGS, CFX_Matrix* pMatrix, uint32_t dwStatus) override; void UpdateWidgetProperty() override; @@ -100,4 +100,4 @@ class CXFA_FFBarcode : public CXFA_FFTextEdit { bool OnRButtonDown(uint32_t dwFlags, const CFX_PointF& point) override; }; -#endif // XFA_FXFA_APP_XFA_FFBARCODE_H_ +#endif // XFA_FXFA_APP_CXFA_FFBARCODE_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffbarcode_unittest.cpp b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffbarcode_unittest.cpp index 95e2377cd8f..65e44ade531 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffbarcode_unittest.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffbarcode_unittest.cpp @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "xfa/fxfa/app/xfa_ffbarcode.h" +#include "xfa/fxfa/app/cxfa_ffbarcode.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/base/ptr_util.h" diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffcheckbutton.cpp b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffcheckbutton.cpp index 76531cecddc..c3fd6b9157c 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffcheckbutton.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffcheckbutton.cpp @@ -4,7 +4,7 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fxfa/app/xfa_ffcheckbutton.h" +#include "xfa/fxfa/app/cxfa_ffcheckbutton.h" #include <utility> #include "third_party/base/ptr_util.h" @@ -12,8 +12,8 @@ #include "xfa/fwl/cfwl_messagemouse.h" #include "xfa/fwl/cfwl_notedriver.h" #include "xfa/fwl/cfwl_widgetmgr.h" -#include "xfa/fxfa/app/xfa_ffexclgroup.h" -#include "xfa/fxfa/app/xfa_fffield.h" +#include "xfa/fxfa/app/cxfa_ffexclgroup.h" +#include "xfa/fxfa/app/cxfa_fffield.h" #include "xfa/fxfa/cxfa_ffapp.h" #include "xfa/fxfa/cxfa_ffdoc.h" #include "xfa/fxfa/cxfa_ffdocview.h" @@ -222,7 +222,7 @@ void CXFA_FFCheckButton::AddUIMargin(int32_t iCapPlacement) { } } -void CXFA_FFCheckButton::RenderWidget(CFX_Graphics* pGS, +void CXFA_FFCheckButton::RenderWidget(CXFA_Graphics* pGS, CFX_Matrix* pMatrix, uint32_t dwStatus) { if (!IsMatchVisibleStatus(dwStatus)) @@ -339,7 +339,7 @@ void CXFA_FFCheckButton::OnProcessEvent(CFWL_Event* pEvent) { m_pOldDelegate->OnProcessEvent(pEvent); } -void CXFA_FFCheckButton::OnDrawWidget(CFX_Graphics* pGraphics, +void CXFA_FFCheckButton::OnDrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) { m_pOldDelegate->OnDrawWidget(pGraphics, pMatrix); } diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffcheckbutton.h b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffcheckbutton.h index d4de7e80239..f092abbcf81 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffcheckbutton.h +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffcheckbutton.h @@ -4,10 +4,10 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef XFA_FXFA_APP_XFA_FFCHECKBUTTON_H_ -#define XFA_FXFA_APP_XFA_FFCHECKBUTTON_H_ +#ifndef XFA_FXFA_APP_CXFA_FFCHECKBUTTON_H_ +#define XFA_FXFA_APP_CXFA_FFCHECKBUTTON_H_ -#include "xfa/fxfa/app/xfa_fffield.h" +#include "xfa/fxfa/app/cxfa_fffield.h" #include "xfa/fxfa/cxfa_ffpageview.h" class CXFA_FFCheckButton : public CXFA_FFField { @@ -16,7 +16,7 @@ class CXFA_FFCheckButton : public CXFA_FFField { ~CXFA_FFCheckButton() override; // CXFA_FFField - void RenderWidget(CFX_Graphics* pGS, + void RenderWidget(CXFA_Graphics* pGS, CFX_Matrix* pMatrix, uint32_t dwStatus) override; @@ -27,7 +27,7 @@ class CXFA_FFCheckButton : public CXFA_FFField { bool OnLButtonUp(uint32_t dwFlags, const CFX_PointF& point) override; void OnProcessMessage(CFWL_Message* pMessage) override; void OnProcessEvent(CFWL_Event* pEvent) override; - void OnDrawWidget(CFX_Graphics* pGraphics, + void OnDrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix = nullptr) override; void SetFWLCheckState(XFA_CHECKSTATE eCheckState); @@ -43,4 +43,4 @@ class CXFA_FFCheckButton : public CXFA_FFField { CFX_RectF m_rtCheckBox; }; -#endif // XFA_FXFA_APP_XFA_FFCHECKBUTTON_H_ +#endif // XFA_FXFA_APP_CXFA_FFCHECKBUTTON_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffchoicelist.cpp b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffcombobox.cpp index e24e7f77b7c..c317c1d90f7 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffchoicelist.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffcombobox.cpp @@ -4,227 +4,25 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fxfa/app/xfa_ffchoicelist.h" +#include "xfa/fxfa/app/cxfa_ffcombobox.h" -#include <algorithm> #include <utility> #include <vector> -#include "third_party/base/ptr_util.h" -#include "third_party/base/stl_util.h" -#include "xfa/fwl/cfwl_app.h" #include "xfa/fwl/cfwl_combobox.h" -#include "xfa/fwl/cfwl_edit.h" #include "xfa/fwl/cfwl_eventselectchanged.h" -#include "xfa/fwl/cfwl_listbox.h" #include "xfa/fwl/cfwl_notedriver.h" -#include "xfa/fwl/cfwl_widgetproperties.h" -#include "xfa/fxfa/app/xfa_fffield.h" -#include "xfa/fxfa/app/xfa_fwladapter.h" #include "xfa/fxfa/cxfa_eventparam.h" -#include "xfa/fxfa/cxfa_ffdoc.h" #include "xfa/fxfa/cxfa_ffdocview.h" -#include "xfa/fxfa/cxfa_ffpageview.h" -#include "xfa/fxfa/cxfa_ffwidget.h" namespace { -CFWL_ListBox* ToListBox(CFWL_Widget* widget) { - return static_cast<CFWL_ListBox*>(widget); -} - CFWL_ComboBox* ToComboBox(CFWL_Widget* widget) { return static_cast<CFWL_ComboBox*>(widget); } } // namespace -CXFA_FFListBox::CXFA_FFListBox(CXFA_WidgetAcc* pDataAcc) - : CXFA_FFField(pDataAcc), m_pOldDelegate(nullptr) {} - -CXFA_FFListBox::~CXFA_FFListBox() { - if (!m_pNormalWidget) - return; - - CFWL_NoteDriver* pNoteDriver = - m_pNormalWidget->GetOwnerApp()->GetNoteDriver(); - pNoteDriver->UnregisterEventTarget(m_pNormalWidget.get()); -} - -bool CXFA_FFListBox::LoadWidget() { - auto pNew = pdfium::MakeUnique<CFWL_ListBox>( - GetFWLApp(), pdfium::MakeUnique<CFWL_WidgetProperties>(), nullptr); - CFWL_ListBox* pListBox = pNew.get(); - pListBox->ModifyStyles(FWL_WGTSTYLE_VScroll | FWL_WGTSTYLE_NoBackground, - 0xFFFFFFFF); - m_pNormalWidget = std::move(pNew); - m_pNormalWidget->SetLayoutItem(this); - - CFWL_NoteDriver* pNoteDriver = - m_pNormalWidget->GetOwnerApp()->GetNoteDriver(); - pNoteDriver->RegisterEventTarget(m_pNormalWidget.get(), - m_pNormalWidget.get()); - m_pOldDelegate = m_pNormalWidget->GetDelegate(); - m_pNormalWidget->SetDelegate(this); - m_pNormalWidget->LockUpdate(); - - for (const auto& label : m_pDataAcc->GetChoiceListItems(false)) - pListBox->AddString(label.AsStringC()); - - uint32_t dwExtendedStyle = FWL_STYLEEXT_LTB_ShowScrollBarFocus; - if (m_pDataAcc->GetChoiceListOpen() == XFA_ATTRIBUTEENUM_MultiSelect) - dwExtendedStyle |= FWL_STYLEEXT_LTB_MultiSelection; - - dwExtendedStyle |= GetAlignment(); - m_pNormalWidget->ModifyStylesEx(dwExtendedStyle, 0xFFFFFFFF); - for (int32_t selected : m_pDataAcc->GetSelectedItems()) - pListBox->SetSelItem(pListBox->GetItem(nullptr, selected), true); - - m_pNormalWidget->UnlockUpdate(); - return CXFA_FFField::LoadWidget(); -} - -bool CXFA_FFListBox::OnKillFocus(CXFA_FFWidget* pNewFocus) { - if (!ProcessCommittedData()) - UpdateFWLData(); - - CXFA_FFField::OnKillFocus(pNewFocus); - return true; -} - -bool CXFA_FFListBox::CommitData() { - auto* pListBox = ToListBox(m_pNormalWidget.get()); - std::vector<int32_t> iSelArray; - int32_t iSels = pListBox->CountSelItems(); - for (int32_t i = 0; i < iSels; ++i) - iSelArray.push_back(pListBox->GetSelIndex(i)); - - m_pDataAcc->SetSelectedItems(iSelArray, true, false, true); - return true; -} - -bool CXFA_FFListBox::IsDataChanged() { - std::vector<int32_t> iSelArray = m_pDataAcc->GetSelectedItems(); - int32_t iOldSels = pdfium::CollectionSize<int32_t>(iSelArray); - auto* pListBox = ToListBox(m_pNormalWidget.get()); - int32_t iSels = pListBox->CountSelItems(); - if (iOldSels != iSels) - return true; - - for (int32_t i = 0; i < iSels; ++i) { - CFWL_ListItem* hlistItem = pListBox->GetItem(nullptr, iSelArray[i]); - if (!(hlistItem->GetStates() & FWL_ITEMSTATE_LTB_Selected)) - return true; - } - return false; -} - -uint32_t CXFA_FFListBox::GetAlignment() { - CXFA_Para para = m_pDataAcc->GetPara(); - if (!para) - return 0; - - uint32_t dwExtendedStyle = 0; - switch (para.GetHorizontalAlign()) { - case XFA_ATTRIBUTEENUM_Center: - dwExtendedStyle |= FWL_STYLEEXT_LTB_CenterAlign; - break; - case XFA_ATTRIBUTEENUM_Justify: - break; - case XFA_ATTRIBUTEENUM_JustifyAll: - break; - case XFA_ATTRIBUTEENUM_Radix: - break; - case XFA_ATTRIBUTEENUM_Right: - dwExtendedStyle |= FWL_STYLEEXT_LTB_RightAlign; - break; - default: - dwExtendedStyle |= FWL_STYLEEXT_LTB_LeftAlign; - break; - } - return dwExtendedStyle; -} - -bool CXFA_FFListBox::UpdateFWLData() { - if (!m_pNormalWidget) - return false; - - auto* pListBox = ToListBox(m_pNormalWidget.get()); - std::vector<int32_t> iSelArray = m_pDataAcc->GetSelectedItems(); - std::vector<CFWL_ListItem*> selItemArray(iSelArray.size()); - std::transform(iSelArray.begin(), iSelArray.end(), selItemArray.begin(), - [pListBox](int32_t val) { return pListBox->GetSelItem(val); }); - - pListBox->SetSelItem(pListBox->GetSelItem(-1), false); - for (CFWL_ListItem* pItem : selItemArray) - pListBox->SetSelItem(pItem, true); - - m_pNormalWidget->Update(); - return true; -} - -void CXFA_FFListBox::OnSelectChanged(CFWL_Widget* pWidget) { - CXFA_EventParam eParam; - eParam.m_eType = XFA_EVENT_Change; - eParam.m_pTarget = m_pDataAcc.Get(); - m_pDataAcc->GetValue(eParam.m_wsPrevText, XFA_VALUEPICTURE_Raw); - - auto* pListBox = ToListBox(m_pNormalWidget.get()); - int32_t iSels = pListBox->CountSelItems(); - if (iSels > 0) { - CFWL_ListItem* item = pListBox->GetSelItem(0); - eParam.m_wsNewText = item ? item->GetText() : L""; - } - m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_Change, &eParam); -} - -void CXFA_FFListBox::SetItemState(int32_t nIndex, bool bSelected) { - auto* pListBox = ToListBox(m_pNormalWidget.get()); - pListBox->SetSelItem(pListBox->GetSelItem(nIndex), bSelected); - m_pNormalWidget->Update(); - AddInvalidateRect(); -} - -void CXFA_FFListBox::InsertItem(const CFX_WideStringC& wsLabel, - int32_t nIndex) { - CFX_WideString wsTemp(wsLabel); - ToListBox(m_pNormalWidget.get())->AddString(wsTemp.AsStringC()); - m_pNormalWidget->Update(); - AddInvalidateRect(); -} - -void CXFA_FFListBox::DeleteItem(int32_t nIndex) { - auto* pListBox = ToListBox(m_pNormalWidget.get()); - if (nIndex < 0) - pListBox->DeleteAll(); - else - pListBox->DeleteString(pListBox->GetItem(nullptr, nIndex)); - - pListBox->Update(); - AddInvalidateRect(); -} - -void CXFA_FFListBox::OnProcessMessage(CFWL_Message* pMessage) { - m_pOldDelegate->OnProcessMessage(pMessage); -} - -void CXFA_FFListBox::OnProcessEvent(CFWL_Event* pEvent) { - CXFA_FFField::OnProcessEvent(pEvent); - switch (pEvent->GetType()) { - case CFWL_Event::Type::SelectChanged: - OnSelectChanged(m_pNormalWidget.get()); - break; - default: - break; - } - m_pOldDelegate->OnProcessEvent(pEvent); -} - -void CXFA_FFListBox::OnDrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) { - m_pOldDelegate->OnDrawWidget(pGraphics, pMatrix); -} - CXFA_FFComboBox::CXFA_FFComboBox(CXFA_WidgetAcc* pDataAcc) : CXFA_FFField(pDataAcc), m_pOldDelegate(nullptr) {} @@ -556,7 +354,7 @@ void CXFA_FFComboBox::OnProcessEvent(CFWL_Event* pEvent) { m_pOldDelegate->OnProcessEvent(pEvent); } -void CXFA_FFComboBox::OnDrawWidget(CFX_Graphics* pGraphics, +void CXFA_FFComboBox::OnDrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) { m_pOldDelegate->OnDrawWidget(pGraphics, pMatrix); } diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffchoicelist.h b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffcombobox.h index 20f053cc20f..de239b624ad 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffchoicelist.h +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffcombobox.h @@ -1,44 +1,13 @@ -// Copyright 2014 PDFium Authors. All rights reserved. +// Copyright 2017 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 -#ifndef XFA_FXFA_APP_XFA_FFCHOICELIST_H_ -#define XFA_FXFA_APP_XFA_FFCHOICELIST_H_ +#ifndef XFA_FXFA_APP_CXFA_FFCOMBOBOX_H_ +#define XFA_FXFA_APP_CXFA_FFCOMBOBOX_H_ -#include <vector> - -#include "xfa/fxfa/app/xfa_fffield.h" -#include "xfa/fxfa/cxfa_ffpageview.h" - -class CXFA_FFListBox : public CXFA_FFField { - public: - explicit CXFA_FFListBox(CXFA_WidgetAcc* pDataAcc); - ~CXFA_FFListBox() override; - - // CXFA_FFField - bool LoadWidget() override; - bool OnKillFocus(CXFA_FFWidget* pNewWidget) override; - void OnProcessMessage(CFWL_Message* pMessage) override; - void OnProcessEvent(CFWL_Event* pEvent) override; - void OnDrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix = nullptr) override; - - void OnSelectChanged(CFWL_Widget* pWidget); - void SetItemState(int32_t nIndex, bool bSelected); - void InsertItem(const CFX_WideStringC& wsLabel, int32_t nIndex); - void DeleteItem(int32_t nIndex); - - private: - bool CommitData() override; - bool UpdateFWLData() override; - bool IsDataChanged() override; - - uint32_t GetAlignment(); - - IFWL_WidgetDelegate* m_pOldDelegate; -}; +#include "xfa/fxfa/app/cxfa_fffield.h" class CXFA_FFComboBox : public CXFA_FFField { public: @@ -70,7 +39,7 @@ class CXFA_FFComboBox : public CXFA_FFField { // IFWL_WidgetDelegate void OnProcessMessage(CFWL_Message* pMessage) override; void OnProcessEvent(CFWL_Event* pEvent) override; - void OnDrawWidget(CFX_Graphics* pGraphics, + void OnDrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix = nullptr) override; virtual void OpenDropDownList(); @@ -97,4 +66,4 @@ class CXFA_FFComboBox : public CXFA_FFField { IFWL_WidgetDelegate* m_pOldDelegate; }; -#endif // XFA_FXFA_APP_XFA_FFCHOICELIST_H_ +#endif // XFA_FXFA_APP_CXFA_FFCOMBOBOX_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffdatetimeedit.cpp b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffdatetimeedit.cpp new file mode 100644 index 00000000000..10a7b189f68 --- /dev/null +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffdatetimeedit.cpp @@ -0,0 +1,213 @@ +// Copyright 2017 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 "xfa/fxfa/app/cxfa_ffdatetimeedit.h" + +#include <utility> + +#include "xfa/fwl/cfwl_datetimepicker.h" +#include "xfa/fwl/cfwl_eventselectchanged.h" +#include "xfa/fwl/cfwl_notedriver.h" +#include "xfa/fwl/cfwl_widget.h" +#include "xfa/fxfa/cxfa_eventparam.h" +#include "xfa/fxfa/parser/cxfa_localevalue.h" + +CXFA_FFDateTimeEdit::CXFA_FFDateTimeEdit(CXFA_WidgetAcc* pDataAcc) + : CXFA_FFTextEdit(pDataAcc) {} + +CXFA_FFDateTimeEdit::~CXFA_FFDateTimeEdit() {} + +CFX_RectF CXFA_FFDateTimeEdit::GetBBox(uint32_t dwStatus, bool bDrawFocus) { + if (bDrawFocus) + return CFX_RectF(); + return CXFA_FFWidget::GetBBox(dwStatus); +} + +bool CXFA_FFDateTimeEdit::PtInActiveRect(const CFX_PointF& point) { + auto* pPicker = static_cast<CFWL_DateTimePicker*>(m_pNormalWidget.get()); + return pPicker && pPicker->GetBBox().Contains(point); +} + +bool CXFA_FFDateTimeEdit::LoadWidget() { + auto pNewPicker = pdfium::MakeUnique<CFWL_DateTimePicker>(GetFWLApp()); + CFWL_DateTimePicker* pWidget = pNewPicker.get(); + m_pNormalWidget = std::move(pNewPicker); + m_pNormalWidget->SetLayoutItem(this); + + CFWL_NoteDriver* pNoteDriver = + m_pNormalWidget->GetOwnerApp()->GetNoteDriver(); + pNoteDriver->RegisterEventTarget(m_pNormalWidget.get(), + m_pNormalWidget.get()); + m_pOldDelegate = m_pNormalWidget->GetDelegate(); + m_pNormalWidget->SetDelegate(this); + m_pNormalWidget->LockUpdate(); + + CFX_WideString wsText; + m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Display); + pWidget->SetEditText(wsText); + if (CXFA_Value value = m_pDataAcc->GetFormValue()) { + switch (value.GetChildValueClassID()) { + case XFA_Element::Date: { + if (!wsText.IsEmpty()) { + CXFA_LocaleValue lcValue = XFA_GetLocaleValue(m_pDataAcc.Get()); + CFX_DateTime date = lcValue.GetDate(); + if (date.IsSet()) + pWidget->SetCurSel(date.GetYear(), date.GetMonth(), date.GetDay()); + } + } break; + default: + break; + } + } + UpdateWidgetProperty(); + m_pNormalWidget->UnlockUpdate(); + return CXFA_FFField::LoadWidget(); +} + +void CXFA_FFDateTimeEdit::UpdateWidgetProperty() { + CFWL_DateTimePicker* pWidget = + static_cast<CFWL_DateTimePicker*>(m_pNormalWidget.get()); + if (!pWidget) + return; + + uint32_t dwExtendedStyle = FWL_STYLEEXT_DTP_ShortDateFormat; + dwExtendedStyle |= UpdateUIProperty(); + dwExtendedStyle |= GetAlignment(); + m_pNormalWidget->ModifyStylesEx(dwExtendedStyle, 0xFFFFFFFF); + uint32_t dwEditStyles = FWL_STYLEEXT_EDT_LastLineHeight; + int32_t iNumCells = m_pDataAcc->GetNumberOfCells(); + if (iNumCells > 0) { + dwEditStyles |= FWL_STYLEEXT_EDT_CombText; + pWidget->SetEditLimit(iNumCells); + } + if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open || + !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) { + dwEditStyles |= FWL_STYLEEXT_EDT_ReadOnly; + } + if (m_pDataAcc->GetHorizontalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) + dwEditStyles |= FWL_STYLEEXT_EDT_AutoHScroll; + + pWidget->ModifyEditStylesEx(dwEditStyles, 0xFFFFFFFF); +} + +uint32_t CXFA_FFDateTimeEdit::GetAlignment() { + CXFA_Para para = m_pDataAcc->GetPara(); + if (!para) + return 0; + + uint32_t dwExtendedStyle = 0; + switch (para.GetHorizontalAlign()) { + case XFA_ATTRIBUTEENUM_Center: + dwExtendedStyle |= FWL_STYLEEXT_DTP_EditHCenter; + break; + case XFA_ATTRIBUTEENUM_Justify: + dwExtendedStyle |= FWL_STYLEEXT_DTP_EditJustified; + break; + case XFA_ATTRIBUTEENUM_JustifyAll: + case XFA_ATTRIBUTEENUM_Radix: + break; + case XFA_ATTRIBUTEENUM_Right: + dwExtendedStyle |= FWL_STYLEEXT_DTP_EditHFar; + break; + default: + dwExtendedStyle |= FWL_STYLEEXT_DTP_EditHNear; + break; + } + + switch (para.GetVerticalAlign()) { + case XFA_ATTRIBUTEENUM_Middle: + dwExtendedStyle |= FWL_STYLEEXT_DTP_EditVCenter; + break; + case XFA_ATTRIBUTEENUM_Bottom: + dwExtendedStyle |= FWL_STYLEEXT_DTP_EditVFar; + break; + default: + dwExtendedStyle |= FWL_STYLEEXT_DTP_EditVNear; + break; + } + return dwExtendedStyle; +} + +bool CXFA_FFDateTimeEdit::CommitData() { + auto* pPicker = static_cast<CFWL_DateTimePicker*>(m_pNormalWidget.get()); + if (!m_pDataAcc->SetValue(pPicker->GetEditText(), XFA_VALUEPICTURE_Edit)) + return false; + + m_pDataAcc->UpdateUIDisplay(this); + return true; +} + +bool CXFA_FFDateTimeEdit::UpdateFWLData() { + if (!m_pNormalWidget) + return false; + + XFA_VALUEPICTURE eType = XFA_VALUEPICTURE_Display; + if (IsFocused()) + eType = XFA_VALUEPICTURE_Edit; + + CFX_WideString wsText; + m_pDataAcc->GetValue(wsText, eType); + + auto* normalWidget = static_cast<CFWL_DateTimePicker*>(m_pNormalWidget.get()); + normalWidget->SetEditText(wsText); + if (IsFocused() && !wsText.IsEmpty()) { + CXFA_LocaleValue lcValue = XFA_GetLocaleValue(m_pDataAcc.Get()); + CFX_DateTime date = lcValue.GetDate(); + if (lcValue.IsValid()) { + if (date.IsSet()) + normalWidget->SetCurSel(date.GetYear(), date.GetMonth(), date.GetDay()); + } + } + m_pNormalWidget->Update(); + return true; +} + +bool CXFA_FFDateTimeEdit::IsDataChanged() { + if (m_dwStatus & XFA_WidgetStatus_TextEditValueChanged) + return true; + + CFX_WideString wsText = + static_cast<CFWL_DateTimePicker*>(m_pNormalWidget.get())->GetEditText(); + CFX_WideString wsOldValue; + m_pDataAcc->GetValue(wsOldValue, XFA_VALUEPICTURE_Edit); + return wsOldValue != wsText; +} + +void CXFA_FFDateTimeEdit::OnSelectChanged(CFWL_Widget* pWidget, + int32_t iYear, + int32_t iMonth, + int32_t iDay) { + CFX_WideString wsPicture; + m_pDataAcc->GetPictureContent(wsPicture, XFA_VALUEPICTURE_Edit); + + CXFA_LocaleValue date(XFA_VT_DATE, GetDoc()->GetXFADoc()->GetLocalMgr()); + date.SetDate(CFX_DateTime(iYear, iMonth, iDay, 0, 0, 0, 0)); + + CFX_WideString wsDate; + date.FormatPatterns(wsDate, wsPicture, m_pDataAcc->GetLocal(), + XFA_VALUEPICTURE_Edit); + + auto* pDateTime = static_cast<CFWL_DateTimePicker*>(m_pNormalWidget.get()); + pDateTime->SetEditText(wsDate); + pDateTime->Update(); + GetDoc()->GetDocEnvironment()->SetFocusWidget(GetDoc(), nullptr); + + CXFA_EventParam eParam; + eParam.m_eType = XFA_EVENT_Change; + eParam.m_pTarget = m_pDataAcc.Get(); + m_pDataAcc->GetValue(eParam.m_wsNewText, XFA_VALUEPICTURE_Raw); + m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_Change, &eParam); +} + +void CXFA_FFDateTimeEdit::OnProcessEvent(CFWL_Event* pEvent) { + if (pEvent->GetType() == CFWL_Event::Type::SelectChanged) { + auto* event = static_cast<CFWL_EventSelectChanged*>(pEvent); + OnSelectChanged(m_pNormalWidget.get(), event->iYear, event->iMonth, + event->iDay); + return; + } + CXFA_FFTextEdit::OnProcessEvent(pEvent); +} diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffdatetimeedit.h b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffdatetimeedit.h new file mode 100644 index 00000000000..c62f657fabe --- /dev/null +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffdatetimeedit.h @@ -0,0 +1,47 @@ +// Copyright 2017 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 + +#ifndef XFA_FXFA_APP_CXFA_FFDATETIMEEDIT_H_ +#define XFA_FXFA_APP_CXFA_FFDATETIMEEDIT_H_ + +#include "core/fxcrt/fx_coordinates.h" +#include "xfa/fxfa/app/cxfa_fftextedit.h" + +enum XFA_DATETIMETYPE { + XFA_DATETIMETYPE_Date = 0, + XFA_DATETIMETYPE_Time, + XFA_DATETIMETYPE_DateAndTime +}; + +class CFWL_Event; +class CFWL_Widget; + +class CXFA_FFDateTimeEdit : public CXFA_FFTextEdit { + public: + explicit CXFA_FFDateTimeEdit(CXFA_WidgetAcc* pDataAcc); + ~CXFA_FFDateTimeEdit() override; + + // CXFA_FFTextEdit + CFX_RectF GetBBox(uint32_t dwStatus, bool bDrawFocus = false) override; + bool LoadWidget() override; + void UpdateWidgetProperty() override; + void OnProcessEvent(CFWL_Event* pEvent) override; + + void OnSelectChanged(CFWL_Widget* pWidget, + int32_t iYear, + int32_t iMonth, + int32_t iDay); + + private: + bool PtInActiveRect(const CFX_PointF& point) override; + bool CommitData() override; + bool UpdateFWLData() override; + bool IsDataChanged() override; + + uint32_t GetAlignment(); +}; + +#endif // XFA_FXFA_APP_CXFA_FFDATETIMEEDIT_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffdraw.cpp b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffdraw.cpp index 8742b83c5bf..5736e773524 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffdraw.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffdraw.cpp @@ -4,7 +4,7 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fxfa/app/xfa_ffdraw.h" +#include "xfa/fxfa/app/cxfa_ffdraw.h" #include "xfa/fxfa/cxfa_ffapp.h" #include "xfa/fxfa/cxfa_ffdoc.h" diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffdraw.h b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffdraw.h index bcd74f204c8..2a65ad0a787 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffdraw.h +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffdraw.h @@ -4,8 +4,8 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef XFA_FXFA_APP_XFA_FFDRAW_H_ -#define XFA_FXFA_APP_XFA_FFDRAW_H_ +#ifndef XFA_FXFA_APP_CXFA_FFDRAW_H_ +#define XFA_FXFA_APP_CXFA_FFDRAW_H_ #include "xfa/fxfa/cxfa_ffpageview.h" #include "xfa/fxfa/cxfa_ffwidget.h" @@ -16,4 +16,4 @@ class CXFA_FFDraw : public CXFA_FFWidget { ~CXFA_FFDraw() override; }; -#endif // XFA_FXFA_APP_XFA_FFDRAW_H_ +#endif // XFA_FXFA_APP_CXFA_FFDRAW_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffexclgroup.cpp b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffexclgroup.cpp index 9f2560f82fb..c881a79468e 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffexclgroup.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffexclgroup.cpp @@ -4,7 +4,7 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fxfa/app/xfa_ffexclgroup.h" +#include "xfa/fxfa/app/cxfa_ffexclgroup.h" #include "xfa/fxfa/cxfa_ffapp.h" #include "xfa/fxfa/cxfa_ffdoc.h" @@ -16,7 +16,7 @@ CXFA_FFExclGroup::CXFA_FFExclGroup(CXFA_WidgetAcc* pDataAcc) CXFA_FFExclGroup::~CXFA_FFExclGroup() {} -void CXFA_FFExclGroup::RenderWidget(CFX_Graphics* pGS, +void CXFA_FFExclGroup::RenderWidget(CXFA_Graphics* pGS, CFX_Matrix* pMatrix, uint32_t dwStatus) { if (!IsMatchVisibleStatus(dwStatus)) diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffexclgroup.h b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffexclgroup.h index a14894566c4..3575ad38afa 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffexclgroup.h +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffexclgroup.h @@ -4,8 +4,8 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef XFA_FXFA_APP_XFA_FFEXCLGROUP_H_ -#define XFA_FXFA_APP_XFA_FFEXCLGROUP_H_ +#ifndef XFA_FXFA_APP_CXFA_FFEXCLGROUP_H_ +#define XFA_FXFA_APP_CXFA_FFEXCLGROUP_H_ #include "xfa/fxfa/cxfa_ffpageview.h" #include "xfa/fxfa/cxfa_ffwidget.h" @@ -16,9 +16,9 @@ class CXFA_FFExclGroup : public CXFA_FFWidget { ~CXFA_FFExclGroup() override; // CXFA_FFWidget - void RenderWidget(CFX_Graphics* pGS, + void RenderWidget(CXFA_Graphics* pGS, CFX_Matrix* pMatrix, uint32_t dwStatus) override; }; -#endif // XFA_FXFA_APP_XFA_FFEXCLGROUP_H_ +#endif // XFA_FXFA_APP_CXFA_FFEXCLGROUP_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fffield.cpp b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_fffield.cpp index 425ba30843c..bf98b99a8e0 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fffield.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_fffield.cpp @@ -4,7 +4,7 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fxfa/app/xfa_fffield.h" +#include "xfa/fxfa/app/cxfa_fffield.h" #include "xfa/fwl/cfwl_edit.h" #include "xfa/fwl/cfwl_eventmouse.h" @@ -15,16 +15,16 @@ #include "xfa/fwl/cfwl_messagesetfocus.h" #include "xfa/fwl/cfwl_picturebox.h" #include "xfa/fwl/cfwl_widgetmgr.h" +#include "xfa/fxfa/app/cxfa_fwltheme.h" #include "xfa/fxfa/app/cxfa_textlayout.h" -#include "xfa/fxfa/app/xfa_fwltheme.h" #include "xfa/fxfa/cxfa_ffapp.h" #include "xfa/fxfa/cxfa_ffdoc.h" #include "xfa/fxfa/cxfa_ffdocview.h" #include "xfa/fxfa/cxfa_ffpageview.h" #include "xfa/fxfa/cxfa_ffwidget.h" #include "xfa/fxfa/parser/cxfa_node.h" -#include "xfa/fxgraphics/cfx_color.h" -#include "xfa/fxgraphics/cfx_path.h" +#include "xfa/fxgraphics/cxfa_color.h" +#include "xfa/fxgraphics/cxfa_path.h" namespace { @@ -57,7 +57,7 @@ CFX_RectF CXFA_FFField::GetBBox(uint32_t dwStatus, bool bDrawFocus) { return rtBox; } -void CXFA_FFField::RenderWidget(CFX_Graphics* pGS, +void CXFA_FFField::RenderWidget(CXFA_Graphics* pGS, CFX_Matrix* pMatrix, uint32_t dwStatus) { if (!IsMatchVisibleStatus(dwStatus)) @@ -80,7 +80,7 @@ void CXFA_FFField::RenderWidget(CFX_Graphics* pGS, &mt); } -void CXFA_FFField::DrawHighlight(CFX_Graphics* pGS, +void CXFA_FFField::DrawHighlight(CXFA_Graphics* pGS, CFX_Matrix* pMatrix, uint32_t dwStatus, bool bEllipse) { @@ -93,9 +93,9 @@ void CXFA_FFField::DrawHighlight(CFX_Graphics* pGS, } CXFA_FFDoc* pDoc = GetDoc(); - CFX_Color crHighlight(pDoc->GetDocEnvironment()->GetHighlightColor(pDoc)); + CXFA_Color crHighlight(pDoc->GetDocEnvironment()->GetHighlightColor(pDoc)); pGS->SetFillColor(&crHighlight); - CFX_Path path; + CXFA_Path path; if (bEllipse) path.AddEllipse(m_rtUI); else @@ -104,18 +104,18 @@ void CXFA_FFField::DrawHighlight(CFX_Graphics* pGS, pGS->FillPath(&path, FXFILL_WINDING, pMatrix); } -void CXFA_FFField::DrawFocus(CFX_Graphics* pGS, CFX_Matrix* pMatrix) { +void CXFA_FFField::DrawFocus(CXFA_Graphics* pGS, CFX_Matrix* pMatrix) { if (!(m_dwStatus & XFA_WidgetStatus_Focused)) return; - CFX_Color cr(0xFF000000); + CXFA_Color cr(0xFF000000); pGS->SetStrokeColor(&cr); float DashPattern[2] = {1, 1}; pGS->SetLineDash(0.0f, DashPattern, 2); pGS->SetLineWidth(0, false); - CFX_Path path; + CXFA_Path path; path.AddRectangle(m_rtUI.left, m_rtUI.top, m_rtUI.width, m_rtUI.height); pGS->StrokePath(&path, pMatrix); } @@ -605,7 +605,7 @@ void CXFA_FFField::LayoutCaption() { m_rtCaption.height = fHeight; } -void CXFA_FFField::RenderCaption(CFX_Graphics* pGS, CFX_Matrix* pMatrix) { +void CXFA_FFField::RenderCaption(CXFA_Graphics* pGS, CFX_Matrix* pMatrix) { CXFA_TextLayout* pCapTextLayout = m_pDataAcc->GetCaptionTextLayout(); if (!pCapTextLayout) return; @@ -781,5 +781,5 @@ void CXFA_FFField::OnProcessEvent(CFWL_Event* pEvent) { } } -void CXFA_FFField::OnDrawWidget(CFX_Graphics* pGraphics, +void CXFA_FFField::OnDrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) {} diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fffield.h b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_fffield.h index eb06caf34ad..d2eba09a621 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fffield.h +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_fffield.h @@ -4,8 +4,8 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef XFA_FXFA_APP_XFA_FFFIELD_H_ -#define XFA_FXFA_APP_XFA_FFFIELD_H_ +#ifndef XFA_FXFA_APP_CXFA_FFFIELD_H_ +#define XFA_FXFA_APP_CXFA_FFFIELD_H_ #include <memory> @@ -24,7 +24,7 @@ class CXFA_FFField : public CXFA_FFWidget, public IFWL_WidgetDelegate { // CXFA_FFWidget CFX_RectF GetBBox(uint32_t dwStatus, bool bDrawFocus = false) override; - void RenderWidget(CFX_Graphics* pGS, + void RenderWidget(CXFA_Graphics* pGS, CFX_Matrix* pMatrix, uint32_t dwStatus) override; bool IsLoaded() override; @@ -55,7 +55,7 @@ class CXFA_FFField : public CXFA_FFWidget, public IFWL_WidgetDelegate { // IFWL_WidgetDelegate void OnProcessMessage(CFWL_Message* pMessage) override; void OnProcessEvent(CFWL_Event* pEvent) override; - void OnDrawWidget(CFX_Graphics* pGraphics, + void OnDrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix = nullptr) override; void UpdateFWL(); @@ -69,18 +69,18 @@ class CXFA_FFField : public CXFA_FFWidget, public IFWL_WidgetDelegate { CFWL_Widget* GetNormalWidget() { return m_pNormalWidget.get(); } CFX_PointF FWLToClient(const CFX_PointF& point); void LayoutCaption(); - void RenderCaption(CFX_Graphics* pGS, CFX_Matrix* pMatrix); + void RenderCaption(CXFA_Graphics* pGS, CFX_Matrix* pMatrix); int32_t CalculateOverride(); int32_t CalculateWidgetAcc(CXFA_WidgetAcc* pAcc); bool ProcessCommittedData(); virtual bool CommitData(); virtual bool IsDataChanged(); - void DrawHighlight(CFX_Graphics* pGS, + void DrawHighlight(CXFA_Graphics* pGS, CFX_Matrix* pMatrix, uint32_t dwStatus, bool bEllipse); - void DrawFocus(CFX_Graphics* pGS, CFX_Matrix* pMatrix); + void DrawFocus(CXFA_Graphics* pGS, CFX_Matrix* pMatrix); void TranslateFWLMessage(CFWL_Message* pMessage); void CapPlacement(); void CapTopBottomPlacement(CXFA_Caption caption, @@ -96,4 +96,4 @@ class CXFA_FFField : public CXFA_FFWidget, public IFWL_WidgetDelegate { CFX_RectF m_rtCaption; }; -#endif // XFA_FXFA_APP_XFA_FFFIELD_H_ +#endif // XFA_FXFA_APP_CXFA_FFFIELD_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffimage.cpp b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffimage.cpp index db9b4de52af..cfcc9d6d7d1 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffimage.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffimage.cpp @@ -4,9 +4,9 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fxfa/app/xfa_ffimage.h" +#include "xfa/fxfa/app/cxfa_ffimage.h" -#include "xfa/fxfa/app/xfa_ffdraw.h" +#include "xfa/fxfa/app/cxfa_ffdraw.h" #include "xfa/fxfa/cxfa_ffapp.h" #include "xfa/fxfa/cxfa_ffdoc.h" #include "xfa/fxfa/cxfa_ffpageview.h" @@ -34,7 +34,7 @@ void CXFA_FFImage::UnloadWidget() { GetDataAcc()->SetImageImage(nullptr); } -void CXFA_FFImage::RenderWidget(CFX_Graphics* pGS, +void CXFA_FFImage::RenderWidget(CXFA_Graphics* pGS, CFX_Matrix* pMatrix, uint32_t dwStatus) { if (!IsMatchVisibleStatus(dwStatus)) diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffimage.h b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffimage.h index 2c42791877f..aaa5df4048e 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffimage.h +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffimage.h @@ -4,10 +4,10 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef XFA_FXFA_APP_XFA_FFIMAGE_H_ -#define XFA_FXFA_APP_XFA_FFIMAGE_H_ +#ifndef XFA_FXFA_APP_CXFA_FFIMAGE_H_ +#define XFA_FXFA_APP_CXFA_FFIMAGE_H_ -#include "xfa/fxfa/app/xfa_ffdraw.h" +#include "xfa/fxfa/app/cxfa_ffdraw.h" class CXFA_FFImage : public CXFA_FFDraw { public: @@ -15,7 +15,7 @@ class CXFA_FFImage : public CXFA_FFDraw { ~CXFA_FFImage() override; // CXFA_FFWidget - void RenderWidget(CFX_Graphics* pGS, + void RenderWidget(CXFA_Graphics* pGS, CFX_Matrix* pMatrix, uint32_t dwStatus) override; bool IsLoaded() override; @@ -23,4 +23,4 @@ class CXFA_FFImage : public CXFA_FFDraw { void UnloadWidget() override; }; -#endif // XFA_FXFA_APP_XFA_FFIMAGE_H_ +#endif // XFA_FXFA_APP_CXFA_FFIMAGE_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffimageedit.cpp b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffimageedit.cpp index c8d9509acad..4019dd11d82 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffimageedit.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffimageedit.cpp @@ -4,7 +4,7 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fxfa/app/xfa_ffimageedit.h" +#include "xfa/fxfa/app/cxfa_ffimageedit.h" #include <utility> @@ -13,7 +13,7 @@ #include "xfa/fwl/cfwl_messagemouse.h" #include "xfa/fwl/cfwl_notedriver.h" #include "xfa/fwl/cfwl_picturebox.h" -#include "xfa/fxfa/app/xfa_fffield.h" +#include "xfa/fxfa/app/cxfa_fffield.h" #include "xfa/fxfa/cxfa_ffdoc.h" #include "xfa/fxfa/cxfa_ffdocview.h" #include "xfa/fxfa/cxfa_ffpageview.h" @@ -51,7 +51,7 @@ void CXFA_FFImageEdit::UnloadWidget() { CXFA_FFField::UnloadWidget(); } -void CXFA_FFImageEdit::RenderWidget(CFX_Graphics* pGS, +void CXFA_FFImageEdit::RenderWidget(CXFA_Graphics* pGS, CFX_Matrix* pMatrix, uint32_t dwStatus) { if (!IsMatchVisibleStatus(dwStatus)) @@ -137,7 +137,7 @@ void CXFA_FFImageEdit::OnProcessEvent(CFWL_Event* pEvent) { m_pOldDelegate->OnProcessEvent(pEvent); } -void CXFA_FFImageEdit::OnDrawWidget(CFX_Graphics* pGraphics, +void CXFA_FFImageEdit::OnDrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) { m_pOldDelegate->OnDrawWidget(pGraphics, pMatrix); } diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffimageedit.h b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffimageedit.h index ee91a772e00..c81af5eb086 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffimageedit.h +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffimageedit.h @@ -4,10 +4,10 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef XFA_FXFA_APP_XFA_FFIMAGEEDIT_H_ -#define XFA_FXFA_APP_XFA_FFIMAGEEDIT_H_ +#ifndef XFA_FXFA_APP_CXFA_FFIMAGEEDIT_H_ +#define XFA_FXFA_APP_CXFA_FFIMAGEEDIT_H_ -#include "xfa/fxfa/app/xfa_fffield.h" +#include "xfa/fxfa/app/cxfa_fffield.h" class CXFA_FFImageEdit : public CXFA_FFField { public: @@ -15,7 +15,7 @@ class CXFA_FFImageEdit : public CXFA_FFField { ~CXFA_FFImageEdit() override; // CXFA_FFField - void RenderWidget(CFX_Graphics* pGS, + void RenderWidget(CXFA_Graphics* pGS, CFX_Matrix* pMatrix, uint32_t dwStatus) override; bool LoadWidget() override; @@ -23,7 +23,7 @@ class CXFA_FFImageEdit : public CXFA_FFField { bool OnLButtonDown(uint32_t dwFlags, const CFX_PointF& point) override; void OnProcessMessage(CFWL_Message* pMessage) override; void OnProcessEvent(CFWL_Event* pEvent) override; - void OnDrawWidget(CFX_Graphics* pGraphics, + void OnDrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix = nullptr) override; private: @@ -34,4 +34,4 @@ class CXFA_FFImageEdit : public CXFA_FFField { IFWL_WidgetDelegate* m_pOldDelegate; }; -#endif // XFA_FXFA_APP_XFA_FFIMAGEEDIT_H_ +#endif // XFA_FXFA_APP_CXFA_FFIMAGEEDIT_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffpath.cpp b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffline.cpp index 854a028aaca..6c028dd3402 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffpath.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffline.cpp @@ -1,18 +1,14 @@ -// Copyright 2014 PDFium Authors. All rights reserved. +// Copyright 2017 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 "xfa/fxfa/app/xfa_ffpath.h" +#include "xfa/fxfa/app/cxfa_ffline.h" -#include "xfa/fxfa/app/xfa_ffdraw.h" -#include "xfa/fxfa/cxfa_ffapp.h" -#include "xfa/fxfa/cxfa_ffdoc.h" -#include "xfa/fxfa/cxfa_ffpageview.h" -#include "xfa/fxfa/cxfa_ffwidget.h" -#include "xfa/fxgraphics/cfx_color.h" -#include "xfa/fxgraphics/cfx_path.h" +#include "xfa/fxgraphics/cxfa_color.h" +#include "xfa/fxgraphics/cxfa_graphics.h" +#include "xfa/fxgraphics/cxfa_path.h" CXFA_FFLine::CXFA_FFLine(CXFA_WidgetAcc* pDataAcc) : CXFA_FFDraw(pDataAcc) {} @@ -51,7 +47,7 @@ void CXFA_FFLine::GetRectFromHand(CFX_RectF& rect, } } -void CXFA_FFLine::RenderWidget(CFX_Graphics* pGS, +void CXFA_FFLine::RenderWidget(CXFA_Graphics* pGS, CFX_Matrix* pMatrix, uint32_t dwStatus) { if (!IsMatchVisibleStatus(dwStatus)) @@ -86,13 +82,13 @@ void CXFA_FFLine::RenderWidget(CFX_Graphics* pGS, XFA_RectWidthoutMargin(rtLine, mgWidget); GetRectFromHand(rtLine, lineObj.GetHand(), fLineWidth); - CFX_Path linePath; + CXFA_Path linePath; if (lineObj.GetSlope() && rtLine.right() > 0.0f && rtLine.bottom() > 0.0f) linePath.AddLine(rtLine.TopRight(), rtLine.BottomLeft()); else linePath.AddLine(rtLine.TopLeft(), rtLine.BottomRight()); - CFX_Color color(lineColor); + CXFA_Color color(lineColor); pGS->SaveGraphState(); pGS->SetLineWidth(fLineWidth, true); XFA_StrokeTypeSetLineDash(pGS, iStrokeType, iCap); @@ -101,56 +97,3 @@ void CXFA_FFLine::RenderWidget(CFX_Graphics* pGS, pGS->StrokePath(&linePath, &mtRotate); pGS->RestoreGraphState(); } - -CXFA_FFArc::CXFA_FFArc(CXFA_WidgetAcc* pDataAcc) : CXFA_FFDraw(pDataAcc) {} - -CXFA_FFArc::~CXFA_FFArc() {} - -void CXFA_FFArc::RenderWidget(CFX_Graphics* pGS, - CFX_Matrix* pMatrix, - uint32_t dwStatus) { - if (!IsMatchVisibleStatus(dwStatus)) - return; - - CXFA_Value value = m_pDataAcc->GetFormValue(); - if (!value) - return; - - CXFA_Arc arcObj = value.GetArc(); - CFX_Matrix mtRotate = GetRotateMatrix(); - if (pMatrix) - mtRotate.Concat(*pMatrix); - - CFX_RectF rtArc = GetRectWithoutRotate(); - if (CXFA_Margin mgWidget = m_pDataAcc->GetMargin()) - XFA_RectWidthoutMargin(rtArc, mgWidget); - - DrawBorder(pGS, arcObj, rtArc, &mtRotate); -} - -CXFA_FFRectangle::CXFA_FFRectangle(CXFA_WidgetAcc* pDataAcc) - : CXFA_FFDraw(pDataAcc) {} - -CXFA_FFRectangle::~CXFA_FFRectangle() {} - -void CXFA_FFRectangle::RenderWidget(CFX_Graphics* pGS, - CFX_Matrix* pMatrix, - uint32_t dwStatus) { - if (!IsMatchVisibleStatus(dwStatus)) - return; - - CXFA_Value value = m_pDataAcc->GetFormValue(); - if (!value) - return; - - CXFA_Rectangle rtObj = value.GetRectangle(); - CFX_RectF rect = GetRectWithoutRotate(); - if (CXFA_Margin mgWidget = m_pDataAcc->GetMargin()) - XFA_RectWidthoutMargin(rect, mgWidget); - - CFX_Matrix mtRotate = GetRotateMatrix(); - if (pMatrix) - mtRotate.Concat(*pMatrix); - - DrawBorder(pGS, rtObj, rect, &mtRotate); -} diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffline.h b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffline.h new file mode 100644 index 00000000000..7649f5a8275 --- /dev/null +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffline.h @@ -0,0 +1,26 @@ +// Copyright 2017 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 + +#ifndef XFA_FXFA_APP_CXFA_FFLINE_H_ +#define XFA_FXFA_APP_CXFA_FFLINE_H_ + +#include "xfa/fxfa/app/cxfa_ffdraw.h" + +class CXFA_FFLine : public CXFA_FFDraw { + public: + explicit CXFA_FFLine(CXFA_WidgetAcc* pDataAcc); + ~CXFA_FFLine() override; + + // CXFA_FFWidget + void RenderWidget(CXFA_Graphics* pGS, + CFX_Matrix* pMatrix, + uint32_t dwStatus) override; + + private: + void GetRectFromHand(CFX_RectF& rect, int32_t iHand, float fLineWidth); +}; + +#endif // XFA_FXFA_APP_CXFA_FFLINE_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_fflistbox.cpp b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_fflistbox.cpp new file mode 100644 index 00000000000..cc9100b5db3 --- /dev/null +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_fflistbox.cpp @@ -0,0 +1,210 @@ +// Copyright 2017 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 "xfa/fxfa/app/cxfa_fflistbox.h" + +#include <algorithm> +#include <utility> +#include <vector> + +#include "xfa/fwl/cfwl_listbox.h" +#include "xfa/fwl/cfwl_notedriver.h" +#include "xfa/fwl/cfwl_widget.h" +#include "xfa/fxfa/cxfa_eventparam.h" + +namespace { + +CFWL_ListBox* ToListBox(CFWL_Widget* widget) { + return static_cast<CFWL_ListBox*>(widget); +} + +} // namespace + +CXFA_FFListBox::CXFA_FFListBox(CXFA_WidgetAcc* pDataAcc) + : CXFA_FFField(pDataAcc), m_pOldDelegate(nullptr) {} + +CXFA_FFListBox::~CXFA_FFListBox() { + if (!m_pNormalWidget) + return; + + CFWL_NoteDriver* pNoteDriver = + m_pNormalWidget->GetOwnerApp()->GetNoteDriver(); + pNoteDriver->UnregisterEventTarget(m_pNormalWidget.get()); +} + +bool CXFA_FFListBox::LoadWidget() { + auto pNew = pdfium::MakeUnique<CFWL_ListBox>( + GetFWLApp(), pdfium::MakeUnique<CFWL_WidgetProperties>(), nullptr); + CFWL_ListBox* pListBox = pNew.get(); + pListBox->ModifyStyles(FWL_WGTSTYLE_VScroll | FWL_WGTSTYLE_NoBackground, + 0xFFFFFFFF); + m_pNormalWidget = std::move(pNew); + m_pNormalWidget->SetLayoutItem(this); + + CFWL_NoteDriver* pNoteDriver = + m_pNormalWidget->GetOwnerApp()->GetNoteDriver(); + pNoteDriver->RegisterEventTarget(m_pNormalWidget.get(), + m_pNormalWidget.get()); + m_pOldDelegate = m_pNormalWidget->GetDelegate(); + m_pNormalWidget->SetDelegate(this); + m_pNormalWidget->LockUpdate(); + + for (const auto& label : m_pDataAcc->GetChoiceListItems(false)) + pListBox->AddString(label.AsStringC()); + + uint32_t dwExtendedStyle = FWL_STYLEEXT_LTB_ShowScrollBarFocus; + if (m_pDataAcc->GetChoiceListOpen() == XFA_ATTRIBUTEENUM_MultiSelect) + dwExtendedStyle |= FWL_STYLEEXT_LTB_MultiSelection; + + dwExtendedStyle |= GetAlignment(); + m_pNormalWidget->ModifyStylesEx(dwExtendedStyle, 0xFFFFFFFF); + for (int32_t selected : m_pDataAcc->GetSelectedItems()) + pListBox->SetSelItem(pListBox->GetItem(nullptr, selected), true); + + m_pNormalWidget->UnlockUpdate(); + return CXFA_FFField::LoadWidget(); +} + +bool CXFA_FFListBox::OnKillFocus(CXFA_FFWidget* pNewFocus) { + if (!ProcessCommittedData()) + UpdateFWLData(); + + CXFA_FFField::OnKillFocus(pNewFocus); + return true; +} + +bool CXFA_FFListBox::CommitData() { + auto* pListBox = ToListBox(m_pNormalWidget.get()); + std::vector<int32_t> iSelArray; + int32_t iSels = pListBox->CountSelItems(); + for (int32_t i = 0; i < iSels; ++i) + iSelArray.push_back(pListBox->GetSelIndex(i)); + + m_pDataAcc->SetSelectedItems(iSelArray, true, false, true); + return true; +} + +bool CXFA_FFListBox::IsDataChanged() { + std::vector<int32_t> iSelArray = m_pDataAcc->GetSelectedItems(); + int32_t iOldSels = pdfium::CollectionSize<int32_t>(iSelArray); + auto* pListBox = ToListBox(m_pNormalWidget.get()); + int32_t iSels = pListBox->CountSelItems(); + if (iOldSels != iSels) + return true; + + for (int32_t i = 0; i < iSels; ++i) { + CFWL_ListItem* hlistItem = pListBox->GetItem(nullptr, iSelArray[i]); + if (!(hlistItem->GetStates() & FWL_ITEMSTATE_LTB_Selected)) + return true; + } + return false; +} + +uint32_t CXFA_FFListBox::GetAlignment() { + CXFA_Para para = m_pDataAcc->GetPara(); + if (!para) + return 0; + + uint32_t dwExtendedStyle = 0; + switch (para.GetHorizontalAlign()) { + case XFA_ATTRIBUTEENUM_Center: + dwExtendedStyle |= FWL_STYLEEXT_LTB_CenterAlign; + break; + case XFA_ATTRIBUTEENUM_Justify: + break; + case XFA_ATTRIBUTEENUM_JustifyAll: + break; + case XFA_ATTRIBUTEENUM_Radix: + break; + case XFA_ATTRIBUTEENUM_Right: + dwExtendedStyle |= FWL_STYLEEXT_LTB_RightAlign; + break; + default: + dwExtendedStyle |= FWL_STYLEEXT_LTB_LeftAlign; + break; + } + return dwExtendedStyle; +} + +bool CXFA_FFListBox::UpdateFWLData() { + if (!m_pNormalWidget) + return false; + + auto* pListBox = ToListBox(m_pNormalWidget.get()); + std::vector<int32_t> iSelArray = m_pDataAcc->GetSelectedItems(); + std::vector<CFWL_ListItem*> selItemArray(iSelArray.size()); + std::transform(iSelArray.begin(), iSelArray.end(), selItemArray.begin(), + [pListBox](int32_t val) { return pListBox->GetSelItem(val); }); + + pListBox->SetSelItem(pListBox->GetSelItem(-1), false); + for (CFWL_ListItem* pItem : selItemArray) + pListBox->SetSelItem(pItem, true); + + m_pNormalWidget->Update(); + return true; +} + +void CXFA_FFListBox::OnSelectChanged(CFWL_Widget* pWidget) { + CXFA_EventParam eParam; + eParam.m_eType = XFA_EVENT_Change; + eParam.m_pTarget = m_pDataAcc.Get(); + m_pDataAcc->GetValue(eParam.m_wsPrevText, XFA_VALUEPICTURE_Raw); + + auto* pListBox = ToListBox(m_pNormalWidget.get()); + int32_t iSels = pListBox->CountSelItems(); + if (iSels > 0) { + CFWL_ListItem* item = pListBox->GetSelItem(0); + eParam.m_wsNewText = item ? item->GetText() : L""; + } + m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_Change, &eParam); +} + +void CXFA_FFListBox::SetItemState(int32_t nIndex, bool bSelected) { + auto* pListBox = ToListBox(m_pNormalWidget.get()); + pListBox->SetSelItem(pListBox->GetSelItem(nIndex), bSelected); + m_pNormalWidget->Update(); + AddInvalidateRect(); +} + +void CXFA_FFListBox::InsertItem(const CFX_WideStringC& wsLabel, + int32_t nIndex) { + CFX_WideString wsTemp(wsLabel); + ToListBox(m_pNormalWidget.get())->AddString(wsTemp.AsStringC()); + m_pNormalWidget->Update(); + AddInvalidateRect(); +} + +void CXFA_FFListBox::DeleteItem(int32_t nIndex) { + auto* pListBox = ToListBox(m_pNormalWidget.get()); + if (nIndex < 0) + pListBox->DeleteAll(); + else + pListBox->DeleteString(pListBox->GetItem(nullptr, nIndex)); + + pListBox->Update(); + AddInvalidateRect(); +} + +void CXFA_FFListBox::OnProcessMessage(CFWL_Message* pMessage) { + m_pOldDelegate->OnProcessMessage(pMessage); +} + +void CXFA_FFListBox::OnProcessEvent(CFWL_Event* pEvent) { + CXFA_FFField::OnProcessEvent(pEvent); + switch (pEvent->GetType()) { + case CFWL_Event::Type::SelectChanged: + OnSelectChanged(m_pNormalWidget.get()); + break; + default: + break; + } + m_pOldDelegate->OnProcessEvent(pEvent); +} + +void CXFA_FFListBox::OnDrawWidget(CXFA_Graphics* pGraphics, + const CFX_Matrix* pMatrix) { + m_pOldDelegate->OnDrawWidget(pGraphics, pMatrix); +} diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_fflistbox.h b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_fflistbox.h new file mode 100644 index 00000000000..ac563cc86cd --- /dev/null +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_fflistbox.h @@ -0,0 +1,40 @@ +// Copyright 2017 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 + +#ifndef XFA_FXFA_APP_CXFA_FFLISTBOX_H_ +#define XFA_FXFA_APP_CXFA_FFLISTBOX_H_ + +#include "xfa/fxfa/app/cxfa_fffield.h" + +class CXFA_FFListBox : public CXFA_FFField { + public: + explicit CXFA_FFListBox(CXFA_WidgetAcc* pDataAcc); + ~CXFA_FFListBox() override; + + // CXFA_FFField + bool LoadWidget() override; + bool OnKillFocus(CXFA_FFWidget* pNewWidget) override; + void OnProcessMessage(CFWL_Message* pMessage) override; + void OnProcessEvent(CFWL_Event* pEvent) override; + void OnDrawWidget(CXFA_Graphics* pGraphics, + const CFX_Matrix* pMatrix = nullptr) override; + + void OnSelectChanged(CFWL_Widget* pWidget); + void SetItemState(int32_t nIndex, bool bSelected); + void InsertItem(const CFX_WideStringC& wsLabel, int32_t nIndex); + void DeleteItem(int32_t nIndex); + + private: + bool CommitData() override; + bool UpdateFWLData() override; + bool IsDataChanged() override; + + uint32_t GetAlignment(); + + IFWL_WidgetDelegate* m_pOldDelegate; +}; + +#endif // XFA_FXFA_APP_CXFA_FFLISTBOX_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffnotify.cpp b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffnotify.cpp index b07b6255380..a660ffff127 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffnotify.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffnotify.cpp @@ -4,26 +4,31 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fxfa/app/xfa_ffnotify.h" +#include "xfa/fxfa/app/cxfa_ffnotify.h" #include "fxjs/cfxjse_value.h" +#include "xfa/fxfa/app/cxfa_ffarc.h" +#include "xfa/fxfa/app/cxfa_ffbarcode.h" +#include "xfa/fxfa/app/cxfa_ffcheckbutton.h" +#include "xfa/fxfa/app/cxfa_ffcombobox.h" +#include "xfa/fxfa/app/cxfa_ffdatetimeedit.h" +#include "xfa/fxfa/app/cxfa_ffdraw.h" +#include "xfa/fxfa/app/cxfa_ffexclgroup.h" +#include "xfa/fxfa/app/cxfa_fffield.h" +#include "xfa/fxfa/app/cxfa_ffimage.h" +#include "xfa/fxfa/app/cxfa_ffimageedit.h" +#include "xfa/fxfa/app/cxfa_ffline.h" +#include "xfa/fxfa/app/cxfa_fflistbox.h" +#include "xfa/fxfa/app/cxfa_ffnumericedit.h" +#include "xfa/fxfa/app/cxfa_ffpasswordedit.h" +#include "xfa/fxfa/app/cxfa_ffpushbutton.h" +#include "xfa/fxfa/app/cxfa_ffrectangle.h" +#include "xfa/fxfa/app/cxfa_ffsignature.h" +#include "xfa/fxfa/app/cxfa_ffsubform.h" +#include "xfa/fxfa/app/cxfa_fftext.h" +#include "xfa/fxfa/app/cxfa_fwladapterwidgetmgr.h" #include "xfa/fxfa/app/cxfa_textlayout.h" -#include "xfa/fxfa/app/xfa_ffbarcode.h" -#include "xfa/fxfa/app/xfa_ffcheckbutton.h" -#include "xfa/fxfa/app/xfa_ffchoicelist.h" -#include "xfa/fxfa/app/xfa_ffdraw.h" -#include "xfa/fxfa/app/xfa_ffexclgroup.h" -#include "xfa/fxfa/app/xfa_fffield.h" -#include "xfa/fxfa/app/xfa_ffimage.h" -#include "xfa/fxfa/app/xfa_ffimageedit.h" -#include "xfa/fxfa/app/xfa_ffpath.h" -#include "xfa/fxfa/app/xfa_ffpushbutton.h" -#include "xfa/fxfa/app/xfa_ffsignature.h" -#include "xfa/fxfa/app/xfa_ffsubform.h" -#include "xfa/fxfa/app/xfa_fftext.h" -#include "xfa/fxfa/app/xfa_fftextedit.h" -#include "xfa/fxfa/app/xfa_ffwidgetacc.h" -#include "xfa/fxfa/app/xfa_fwladapter.h" +#include "xfa/fxfa/app/cxfa_textprovider.h" #include "xfa/fxfa/cxfa_ffapp.h" #include "xfa/fxfa/cxfa_ffdoc.h" #include "xfa/fxfa/cxfa_ffdocview.h" diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffnotify.h b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffnotify.h index 930d3b6a90e..935a0c390b3 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffnotify.h +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffnotify.h @@ -4,8 +4,8 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef XFA_FXFA_APP_XFA_FFNOTIFY_H_ -#define XFA_FXFA_APP_XFA_FFNOTIFY_H_ +#ifndef XFA_FXFA_APP_CXFA_FFNOTIFY_H_ +#define XFA_FXFA_APP_CXFA_FFNOTIFY_H_ #include "xfa/fxfa/cxfa_eventparam.h" #include "xfa/fxfa/parser/cxfa_document.h" @@ -74,4 +74,4 @@ class CXFA_FFNotify { CFX_UnownedPtr<CXFA_FFDoc> const m_pDoc; }; -#endif // XFA_FXFA_APP_XFA_FFNOTIFY_H_ +#endif // XFA_FXFA_APP_CXFA_FFNOTIFY_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffnumericedit.cpp b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffnumericedit.cpp new file mode 100644 index 00000000000..09ea524ee4f --- /dev/null +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffnumericedit.cpp @@ -0,0 +1,97 @@ +// Copyright 2017 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 "xfa/fxfa/app/cxfa_ffnumericedit.h" + +#include <utility> + +#include "xfa/fwl/cfwl_edit.h" +#include "xfa/fwl/cfwl_eventvalidate.h" +#include "xfa/fwl/cfwl_notedriver.h" +#include "xfa/fxfa/parser/cxfa_localevalue.h" + +CXFA_FFNumericEdit::CXFA_FFNumericEdit(CXFA_WidgetAcc* pDataAcc) + : CXFA_FFTextEdit(pDataAcc) {} + +CXFA_FFNumericEdit::~CXFA_FFNumericEdit() {} + +bool CXFA_FFNumericEdit::LoadWidget() { + auto pNewEdit = pdfium::MakeUnique<CFWL_Edit>( + GetFWLApp(), pdfium::MakeUnique<CFWL_WidgetProperties>(), nullptr); + CFWL_Edit* pWidget = pNewEdit.get(); + m_pNormalWidget = std::move(pNewEdit); + m_pNormalWidget->SetLayoutItem(this); + + CFWL_NoteDriver* pNoteDriver = + m_pNormalWidget->GetOwnerApp()->GetNoteDriver(); + pNoteDriver->RegisterEventTarget(m_pNormalWidget.get(), + m_pNormalWidget.get()); + m_pOldDelegate = m_pNormalWidget->GetDelegate(); + m_pNormalWidget->SetDelegate(this); + m_pNormalWidget->LockUpdate(); + + CFX_WideString wsText; + m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Display); + pWidget->SetText(wsText); + UpdateWidgetProperty(); + m_pNormalWidget->UnlockUpdate(); + return CXFA_FFField::LoadWidget(); +} + +void CXFA_FFNumericEdit::UpdateWidgetProperty() { + CFWL_Edit* pWidget = static_cast<CFWL_Edit*>(m_pNormalWidget.get()); + if (!pWidget) + return; + + uint32_t dwExtendedStyle = + FWL_STYLEEXT_EDT_ShowScrollbarFocus | FWL_STYLEEXT_EDT_OuterScrollbar | + FWL_STYLEEXT_EDT_Validate | FWL_STYLEEXT_EDT_Number | + FWL_STYLEEXT_EDT_LastLineHeight; + dwExtendedStyle |= UpdateUIProperty(); + if (m_pDataAcc->GetHorizontalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) + dwExtendedStyle |= FWL_STYLEEXT_EDT_AutoHScroll; + + int32_t iNumCells = m_pDataAcc->GetNumberOfCells(); + if (iNumCells > 0) { + dwExtendedStyle |= FWL_STYLEEXT_EDT_CombText; + pWidget->SetLimit(iNumCells); + } + dwExtendedStyle |= GetAlignment(); + if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open || + !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) { + dwExtendedStyle |= FWL_STYLEEXT_EDT_ReadOnly; + } + m_pNormalWidget->ModifyStylesEx(dwExtendedStyle, 0xFFFFFFFF); +} + +void CXFA_FFNumericEdit::OnProcessEvent(CFWL_Event* pEvent) { + if (pEvent->GetType() == CFWL_Event::Type::Validate) { + CFWL_EventValidate* event = static_cast<CFWL_EventValidate*>(pEvent); + event->bValidate = OnValidate(m_pNormalWidget.get(), event->wsInsert); + return; + } + CXFA_FFTextEdit::OnProcessEvent(pEvent); +} + +bool CXFA_FFNumericEdit::OnValidate(CFWL_Widget* pWidget, + CFX_WideString& wsText) { + CFX_WideString wsPattern; + m_pDataAcc->GetPictureContent(wsPattern, XFA_VALUEPICTURE_Edit); + if (!wsPattern.IsEmpty()) + return true; + + int32_t iLeads = 0; + m_pDataAcc->GetLeadDigits(iLeads); + + int32_t iFracs = 0; + m_pDataAcc->GetFracDigits(iFracs); + + CFX_WideString wsFormat; + CXFA_LocaleValue widgetValue = XFA_GetLocaleValue(m_pDataAcc.Get()); + widgetValue.GetNumericFormat(wsFormat, iLeads, iFracs); + return widgetValue.ValidateNumericTemp(wsText, wsFormat, + m_pDataAcc->GetLocal()); +} diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffnumericedit.h b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffnumericedit.h new file mode 100644 index 00000000000..25e2304e87c --- /dev/null +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffnumericedit.h @@ -0,0 +1,31 @@ +// Copyright 2017 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 + +#ifndef XFA_FXFA_APP_CXFA_FFNUMERICEDIT_H_ +#define XFA_FXFA_APP_CXFA_FFNUMERICEDIT_H_ + +#include "core/fxcrt/fx_string.h" +#include "xfa/fxfa/app/cxfa_fftextedit.h" + +class CFWL_Event; +class CFWL_Widget; +class CXFA_WidgetAcc; + +class CXFA_FFNumericEdit : public CXFA_FFTextEdit { + public: + explicit CXFA_FFNumericEdit(CXFA_WidgetAcc* pDataAcc); + ~CXFA_FFNumericEdit() override; + + // CXFA_FFTextEdit + bool LoadWidget() override; + void UpdateWidgetProperty() override; + void OnProcessEvent(CFWL_Event* pEvent) override; + + private: + bool OnValidate(CFWL_Widget* pWidget, CFX_WideString& wsText); +}; + +#endif // XFA_FXFA_APP_CXFA_FFNUMERICEDIT_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffpasswordedit.cpp b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffpasswordedit.cpp new file mode 100644 index 00000000000..1b404fa0463 --- /dev/null +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffpasswordedit.cpp @@ -0,0 +1,64 @@ +// Copyright 2017 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 "xfa/fxfa/app/cxfa_ffpasswordedit.h" + +#include <utility> + +#include "xfa/fwl/cfwl_edit.h" +#include "xfa/fwl/cfwl_notedriver.h" + +CXFA_FFPasswordEdit::CXFA_FFPasswordEdit(CXFA_WidgetAcc* pDataAcc) + : CXFA_FFTextEdit(pDataAcc) {} + +CXFA_FFPasswordEdit::~CXFA_FFPasswordEdit() {} + +bool CXFA_FFPasswordEdit::LoadWidget() { + auto pNewEdit = pdfium::MakeUnique<CFWL_Edit>( + GetFWLApp(), pdfium::MakeUnique<CFWL_WidgetProperties>(), nullptr); + CFWL_Edit* pWidget = pNewEdit.get(); + m_pNormalWidget = std::move(pNewEdit); + m_pNormalWidget->SetLayoutItem(this); + + CFWL_NoteDriver* pNoteDriver = + m_pNormalWidget->GetOwnerApp()->GetNoteDriver(); + pNoteDriver->RegisterEventTarget(m_pNormalWidget.get(), + m_pNormalWidget.get()); + m_pOldDelegate = m_pNormalWidget->GetDelegate(); + m_pNormalWidget->SetDelegate(this); + m_pNormalWidget->LockUpdate(); + + CFX_WideString wsText; + m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Display); + pWidget->SetText(wsText); + UpdateWidgetProperty(); + m_pNormalWidget->UnlockUpdate(); + return CXFA_FFField::LoadWidget(); +} + +void CXFA_FFPasswordEdit::UpdateWidgetProperty() { + CFWL_Edit* pWidget = static_cast<CFWL_Edit*>(m_pNormalWidget.get()); + if (!pWidget) + return; + + uint32_t dwExtendedStyle = + FWL_STYLEEXT_EDT_ShowScrollbarFocus | FWL_STYLEEXT_EDT_OuterScrollbar | + FWL_STYLEEXT_EDT_Password | FWL_STYLEEXT_EDT_LastLineHeight; + dwExtendedStyle |= UpdateUIProperty(); + + CFX_WideString wsPassWord; + m_pDataAcc->GetPasswordChar(wsPassWord); + if (!wsPassWord.IsEmpty()) + pWidget->SetAliasChar(wsPassWord.GetAt(0)); + if (m_pDataAcc->GetHorizontalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) + dwExtendedStyle |= FWL_STYLEEXT_EDT_AutoHScroll; + if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open || + !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) { + dwExtendedStyle |= FWL_STYLEEXT_EDT_ReadOnly; + } + dwExtendedStyle |= GetAlignment(); + m_pNormalWidget->ModifyStylesEx(dwExtendedStyle, 0xFFFFFFFF); +} diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffpasswordedit.h b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffpasswordedit.h new file mode 100644 index 00000000000..5d292d4df3e --- /dev/null +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffpasswordedit.h @@ -0,0 +1,24 @@ +// Copyright 2017 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 + +#ifndef XFA_FXFA_APP_CXFA_FFPASSWORDEDIT_H_ +#define XFA_FXFA_APP_CXFA_FFPASSWORDEDIT_H_ + +#include "xfa/fxfa/app/cxfa_fftextedit.h" + +class CXFA_WidgetAcc; + +class CXFA_FFPasswordEdit : public CXFA_FFTextEdit { + public: + explicit CXFA_FFPasswordEdit(CXFA_WidgetAcc* pDataAcc); + ~CXFA_FFPasswordEdit() override; + + // CXFA_FFTextEdit + bool LoadWidget() override; + void UpdateWidgetProperty() override; +}; + +#endif // XFA_FXFA_APP_CXFA_FFPASSWORDEDIT_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffpushbutton.cpp b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffpushbutton.cpp index b596996b6c1..44ec0d42d06 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffpushbutton.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffpushbutton.cpp @@ -4,7 +4,7 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fxfa/app/xfa_ffpushbutton.h" +#include "xfa/fxfa/app/cxfa_ffpushbutton.h" #include <utility> @@ -12,14 +12,14 @@ #include "xfa/fwl/cfwl_notedriver.h" #include "xfa/fwl/cfwl_pushbutton.h" #include "xfa/fwl/cfwl_widgetmgr.h" +#include "xfa/fxfa/app/cxfa_fffield.h" #include "xfa/fxfa/app/cxfa_textlayout.h" -#include "xfa/fxfa/app/xfa_fffield.h" -#include "xfa/fxfa/app/xfa_ffwidgetacc.h" +#include "xfa/fxfa/app/cxfa_textprovider.h" #include "xfa/fxfa/cxfa_ffapp.h" #include "xfa/fxfa/cxfa_ffpageview.h" #include "xfa/fxfa/cxfa_ffwidget.h" -#include "xfa/fxgraphics/cfx_color.h" -#include "xfa/fxgraphics/cfx_path.h" +#include "xfa/fxgraphics/cxfa_color.h" +#include "xfa/fxgraphics/cxfa_path.h" CXFA_FFPushButton::CXFA_FFPushButton(CXFA_WidgetAcc* pDataAcc) : CXFA_FFField(pDataAcc), m_pOldDelegate(nullptr) {} @@ -28,7 +28,7 @@ CXFA_FFPushButton::~CXFA_FFPushButton() { CXFA_FFPushButton::UnloadWidget(); } -void CXFA_FFPushButton::RenderWidget(CFX_Graphics* pGS, +void CXFA_FFPushButton::RenderWidget(CXFA_Graphics* pGS, CFX_Matrix* pMatrix, uint32_t dwStatus) { if (!IsMatchVisibleStatus(dwStatus)) @@ -166,7 +166,7 @@ void CXFA_FFPushButton::LayoutHighlightCaption() { m_pDownTextLayout->Layout(sz); } -void CXFA_FFPushButton::RenderHighlightCaption(CFX_Graphics* pGS, +void CXFA_FFPushButton::RenderHighlightCaption(CXFA_Graphics* pGS, CFX_Matrix* pMatrix) { CXFA_TextLayout* pCapTextLayout = m_pDataAcc->GetCaptionTextLayout(); CXFA_Caption caption = m_pDataAcc->GetCaption(); @@ -205,7 +205,7 @@ void CXFA_FFPushButton::OnProcessEvent(CFWL_Event* pEvent) { CXFA_FFField::OnProcessEvent(pEvent); } -void CXFA_FFPushButton::OnDrawWidget(CFX_Graphics* pGraphics, +void CXFA_FFPushButton::OnDrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix) { if (m_pNormalWidget->GetStylesEx() & XFA_FWL_PSBSTYLEEXT_HiliteInverted) { if ((m_pNormalWidget->GetStates() & FWL_STATE_PSB_Pressed) && @@ -213,10 +213,10 @@ void CXFA_FFPushButton::OnDrawWidget(CFX_Graphics* pGraphics, CFX_RectF rtFill(0, 0, m_pNormalWidget->GetWidgetRect().Size()); float fLineWith = GetLineWidth(); rtFill.Deflate(fLineWith, fLineWith); - CFX_Color cr(FXARGB_MAKE(128, 128, 255, 255)); + CXFA_Color cr(FXARGB_MAKE(128, 128, 255, 255)); pGraphics->SetFillColor(&cr); - CFX_Path path; + CXFA_Path path; path.AddRectangle(rtFill.left, rtFill.top, rtFill.width, rtFill.height); pGraphics->FillPath(&path, FXFILL_WINDING, (CFX_Matrix*)pMatrix); } @@ -227,11 +227,11 @@ void CXFA_FFPushButton::OnDrawWidget(CFX_Graphics* pGraphics, if ((m_pNormalWidget->GetStates() & FWL_STATE_PSB_Pressed) && (m_pNormalWidget->GetStates() & FWL_STATE_PSB_Hovered)) { float fLineWidth = GetLineWidth(); - CFX_Color cr(FXARGB_MAKE(255, 128, 255, 255)); + CXFA_Color cr(FXARGB_MAKE(255, 128, 255, 255)); pGraphics->SetStrokeColor(&cr); pGraphics->SetLineWidth(fLineWidth); - CFX_Path path; + CXFA_Path path; CFX_RectF rect = m_pNormalWidget->GetWidgetRect(); path.AddRectangle(0, 0, rect.width, rect.height); pGraphics->StrokePath(&path, (CFX_Matrix*)pMatrix); diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffpushbutton.h b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffpushbutton.h index 3695fc4e1b6..e64ef706f34 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffpushbutton.h +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffpushbutton.h @@ -4,12 +4,12 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef XFA_FXFA_APP_XFA_FFPUSHBUTTON_H_ -#define XFA_FXFA_APP_XFA_FFPUSHBUTTON_H_ +#ifndef XFA_FXFA_APP_CXFA_FFPUSHBUTTON_H_ +#define XFA_FXFA_APP_CXFA_FFPUSHBUTTON_H_ #include <memory> -#include "xfa/fxfa/app/xfa_fffield.h" +#include "xfa/fxfa/app/cxfa_fffield.h" #define XFA_FWL_PSBSTYLEEXT_HiliteNone (0L << 0) #define XFA_FWL_PSBSTYLEEXT_HiliteInverted (1L << 0) @@ -24,7 +24,7 @@ class CXFA_FFPushButton : public CXFA_FFField { ~CXFA_FFPushButton() override; // CXFA_FFField - void RenderWidget(CFX_Graphics* pGS, + void RenderWidget(CXFA_Graphics* pGS, CFX_Matrix* pMatrix, uint32_t dwStatus) override; bool LoadWidget() override; @@ -33,13 +33,13 @@ class CXFA_FFPushButton : public CXFA_FFField { void UpdateWidgetProperty() override; void OnProcessMessage(CFWL_Message* pMessage) override; void OnProcessEvent(CFWL_Event* pEvent) override; - void OnDrawWidget(CFX_Graphics* pGraphics, + void OnDrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix = nullptr) override; private: void LoadHighlightCaption(); void LayoutHighlightCaption(); - void RenderHighlightCaption(CFX_Graphics* pGS, CFX_Matrix* pMatrix); + void RenderHighlightCaption(CXFA_Graphics* pGS, CFX_Matrix* pMatrix); float GetLineWidth(); FX_ARGB GetLineColor(); FX_ARGB GetFillColor(); @@ -51,4 +51,4 @@ class CXFA_FFPushButton : public CXFA_FFField { IFWL_WidgetDelegate* m_pOldDelegate; }; -#endif // XFA_FXFA_APP_XFA_FFPUSHBUTTON_H_ +#endif // XFA_FXFA_APP_CXFA_FFPUSHBUTTON_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffrectangle.cpp b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffrectangle.cpp new file mode 100644 index 00000000000..89ae129cb11 --- /dev/null +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffrectangle.cpp @@ -0,0 +1,34 @@ +// Copyright 2017 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 "xfa/fxfa/app/cxfa_ffrectangle.h" + +CXFA_FFRectangle::CXFA_FFRectangle(CXFA_WidgetAcc* pDataAcc) + : CXFA_FFDraw(pDataAcc) {} + +CXFA_FFRectangle::~CXFA_FFRectangle() {} + +void CXFA_FFRectangle::RenderWidget(CXFA_Graphics* pGS, + CFX_Matrix* pMatrix, + uint32_t dwStatus) { + if (!IsMatchVisibleStatus(dwStatus)) + return; + + CXFA_Value value = m_pDataAcc->GetFormValue(); + if (!value) + return; + + CXFA_Rectangle rtObj = value.GetRectangle(); + CFX_RectF rect = GetRectWithoutRotate(); + if (CXFA_Margin mgWidget = m_pDataAcc->GetMargin()) + XFA_RectWidthoutMargin(rect, mgWidget); + + CFX_Matrix mtRotate = GetRotateMatrix(); + if (pMatrix) + mtRotate.Concat(*pMatrix); + + DrawBorder(pGS, rtObj, rect, &mtRotate); +} diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffrectangle.h b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffrectangle.h new file mode 100644 index 00000000000..2ddb35dadea --- /dev/null +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffrectangle.h @@ -0,0 +1,23 @@ +// Copyright 2017 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 + +#ifndef XFA_FXFA_APP_CXFA_FFRECTANGLE_H_ +#define XFA_FXFA_APP_CXFA_FFRECTANGLE_H_ + +#include "xfa/fxfa/app/cxfa_ffdraw.h" + +class CXFA_FFRectangle : public CXFA_FFDraw { + public: + explicit CXFA_FFRectangle(CXFA_WidgetAcc* pDataAcc); + ~CXFA_FFRectangle() override; + + // CXFA_FFWidget + void RenderWidget(CXFA_Graphics* pGS, + CFX_Matrix* pMatrix, + uint32_t dwStatus) override; +}; + +#endif // XFA_FXFA_APP_CXFA_FFRECTANGLE_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffsignature.cpp b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffsignature.cpp index edc34336c69..0afe5cc86a2 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffsignature.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffsignature.cpp @@ -4,9 +4,9 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fxfa/app/xfa_ffsignature.h" +#include "xfa/fxfa/app/cxfa_ffsignature.h" -#include "xfa/fxfa/app/xfa_fffield.h" +#include "xfa/fxfa/app/cxfa_fffield.h" #include "xfa/fxfa/cxfa_ffdoc.h" #include "xfa/fxfa/cxfa_ffpageview.h" #include "xfa/fxfa/cxfa_ffwidget.h" @@ -20,7 +20,7 @@ bool CXFA_FFSignature::LoadWidget() { return CXFA_FFField::LoadWidget(); } -void CXFA_FFSignature::RenderWidget(CFX_Graphics* pGS, +void CXFA_FFSignature::RenderWidget(CXFA_Graphics* pGS, CFX_Matrix* pMatrix, uint32_t dwStatus) { if (!IsMatchVisibleStatus(dwStatus)) diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffsignature.h b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffsignature.h index 934323f436f..8d2a33e21ad 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffsignature.h +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffsignature.h @@ -4,10 +4,10 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef XFA_FXFA_APP_XFA_FFSIGNATURE_H_ -#define XFA_FXFA_APP_XFA_FFSIGNATURE_H_ +#ifndef XFA_FXFA_APP_CXFA_FFSIGNATURE_H_ +#define XFA_FXFA_APP_CXFA_FFSIGNATURE_H_ -#include "xfa/fxfa/app/xfa_fffield.h" +#include "xfa/fxfa/app/cxfa_fffield.h" class CXFA_FFSignature final : public CXFA_FFField { public: @@ -15,7 +15,7 @@ class CXFA_FFSignature final : public CXFA_FFField { ~CXFA_FFSignature() override; // CXFA_FFField - void RenderWidget(CFX_Graphics* pGS, + void RenderWidget(CXFA_Graphics* pGS, CFX_Matrix* pMatrix, uint32_t dwStatus) override; bool LoadWidget() override; @@ -39,4 +39,4 @@ class CXFA_FFSignature final : public CXFA_FFField { bool OnSetCursor(const CFX_PointF& point) override; }; -#endif // XFA_FXFA_APP_XFA_FFSIGNATURE_H_ +#endif // XFA_FXFA_APP_CXFA_FFSIGNATURE_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffsubform.cpp b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffsubform.cpp index d008c5b4f91..80a77829172 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffsubform.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffsubform.cpp @@ -4,7 +4,7 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fxfa/app/xfa_ffsubform.h" +#include "xfa/fxfa/app/cxfa_ffsubform.h" #include "xfa/fxfa/cxfa_ffapp.h" #include "xfa/fxfa/cxfa_ffdoc.h" diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffsubform.h b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffsubform.h index c87688fdcef..d73e53de974 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffsubform.h +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_ffsubform.h @@ -4,8 +4,8 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef XFA_FXFA_APP_XFA_FFSUBFORM_H_ -#define XFA_FXFA_APP_XFA_FFSUBFORM_H_ +#ifndef XFA_FXFA_APP_CXFA_FFSUBFORM_H_ +#define XFA_FXFA_APP_CXFA_FFSUBFORM_H_ #include "xfa/fxfa/cxfa_ffpageview.h" #include "xfa/fxfa/cxfa_ffwidget.h" @@ -16,4 +16,4 @@ class CXFA_FFSubForm : public CXFA_FFWidget { ~CXFA_FFSubForm() override; }; -#endif // XFA_FXFA_APP_XFA_FFSUBFORM_H_ +#endif // XFA_FXFA_APP_CXFA_FFSUBFORM_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fftext.cpp b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_fftext.cpp index 89d77c3eafd..3d90e6cd4ed 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fftext.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_fftext.cpp @@ -4,26 +4,26 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fxfa/app/xfa_fftext.h" +#include "xfa/fxfa/app/cxfa_fftext.h" #include "xfa/fwl/fwl_widgetdef.h" #include "xfa/fwl/fwl_widgethit.h" +#include "xfa/fxfa/app/cxfa_ffdraw.h" #include "xfa/fxfa/app/cxfa_linkuserdata.h" #include "xfa/fxfa/app/cxfa_pieceline.h" #include "xfa/fxfa/app/cxfa_textlayout.h" -#include "xfa/fxfa/app/xfa_ffdraw.h" -#include "xfa/fxfa/app/xfa_textpiece.h" +#include "xfa/fxfa/app/cxfa_textpiece.h" #include "xfa/fxfa/cxfa_ffapp.h" #include "xfa/fxfa/cxfa_ffdoc.h" #include "xfa/fxfa/cxfa_ffpageview.h" #include "xfa/fxfa/cxfa_ffwidget.h" -#include "xfa/fxgraphics/cfx_graphics.h" +#include "xfa/fxgraphics/cxfa_graphics.h" CXFA_FFText::CXFA_FFText(CXFA_WidgetAcc* pDataAcc) : CXFA_FFDraw(pDataAcc) {} CXFA_FFText::~CXFA_FFText() {} -void CXFA_FFText::RenderWidget(CFX_Graphics* pGS, +void CXFA_FFText::RenderWidget(CXFA_Graphics* pGS, CFX_Matrix* pMatrix, uint32_t dwStatus) { if (!IsMatchVisibleStatus(dwStatus)) diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fftext.h b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_fftext.h index eddc1224aca..df920f02664 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fftext.h +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_fftext.h @@ -4,10 +4,10 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef XFA_FXFA_APP_XFA_FFTEXT_H_ -#define XFA_FXFA_APP_XFA_FFTEXT_H_ +#ifndef XFA_FXFA_APP_CXFA_FFTEXT_H_ +#define XFA_FXFA_APP_CXFA_FFTEXT_H_ -#include "xfa/fxfa/app/xfa_ffdraw.h" +#include "xfa/fxfa/app/cxfa_ffdraw.h" class CXFA_FFText : public CXFA_FFDraw { public: @@ -19,7 +19,7 @@ class CXFA_FFText : public CXFA_FFDraw { bool OnLButtonUp(uint32_t dwFlags, const CFX_PointF& point) override; bool OnMouseMove(uint32_t dwFlags, const CFX_PointF& point) override; FWL_WidgetHit OnHitTest(const CFX_PointF& point) override; - void RenderWidget(CFX_Graphics* pGS, + void RenderWidget(CXFA_Graphics* pGS, CFX_Matrix* pMatrix, uint32_t dwStatus) override; bool IsLoaded() override; @@ -29,4 +29,4 @@ class CXFA_FFText : public CXFA_FFDraw { const wchar_t* GetLinkURLAtPoint(const CFX_PointF& point); }; -#endif // XFA_FXFA_APP_XFA_FFTEXT_H_ +#endif // XFA_FXFA_APP_CXFA_FFTEXT_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_fftextedit.cpp b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_fftextedit.cpp new file mode 100644 index 00000000000..0d211eb7b46 --- /dev/null +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_fftextedit.cpp @@ -0,0 +1,359 @@ +// Copyright 2017 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 "xfa/fxfa/app/cxfa_fftextedit.h" + +#include <utility> + +#include "xfa/fwl/cfwl_datetimepicker.h" +#include "xfa/fwl/cfwl_edit.h" +#include "xfa/fwl/cfwl_eventcheckword.h" +#include "xfa/fwl/cfwl_eventtarget.h" +#include "xfa/fwl/cfwl_eventtextchanged.h" +#include "xfa/fwl/cfwl_messagekillfocus.h" +#include "xfa/fwl/cfwl_messagesetfocus.h" +#include "xfa/fwl/cfwl_notedriver.h" +#include "xfa/fxfa/cxfa_eventparam.h" +#include "xfa/fxfa/cxfa_ffapp.h" +#include "xfa/fxfa/parser/cxfa_node.h" + +CXFA_FFTextEdit::CXFA_FFTextEdit(CXFA_WidgetAcc* pDataAcc) + : CXFA_FFField(pDataAcc), m_pOldDelegate(nullptr) {} + +CXFA_FFTextEdit::~CXFA_FFTextEdit() { + if (m_pNormalWidget) { + CFWL_NoteDriver* pNoteDriver = + m_pNormalWidget->GetOwnerApp()->GetNoteDriver(); + pNoteDriver->UnregisterEventTarget(m_pNormalWidget.get()); + } +} + +bool CXFA_FFTextEdit::LoadWidget() { + auto pNewWidget = pdfium::MakeUnique<CFWL_Edit>( + GetFWLApp(), pdfium::MakeUnique<CFWL_WidgetProperties>(), nullptr); + CFWL_Edit* pFWLEdit = pNewWidget.get(); + m_pNormalWidget = std::move(pNewWidget); + m_pNormalWidget->SetLayoutItem(this); + + CFWL_NoteDriver* pNoteDriver = + m_pNormalWidget->GetOwnerApp()->GetNoteDriver(); + pNoteDriver->RegisterEventTarget(m_pNormalWidget.get(), + m_pNormalWidget.get()); + m_pOldDelegate = m_pNormalWidget->GetDelegate(); + m_pNormalWidget->SetDelegate(this); + m_pNormalWidget->LockUpdate(); + UpdateWidgetProperty(); + + CFX_WideString wsText; + m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Display); + pFWLEdit->SetText(wsText); + m_pNormalWidget->UnlockUpdate(); + return CXFA_FFField::LoadWidget(); +} + +void CXFA_FFTextEdit::UpdateWidgetProperty() { + CFWL_Edit* pWidget = static_cast<CFWL_Edit*>(m_pNormalWidget.get()); + if (!pWidget) + return; + + uint32_t dwStyle = 0; + uint32_t dwExtendedStyle = FWL_STYLEEXT_EDT_ShowScrollbarFocus | + FWL_STYLEEXT_EDT_OuterScrollbar | + FWL_STYLEEXT_EDT_LastLineHeight; + dwExtendedStyle |= UpdateUIProperty(); + if (m_pDataAcc->IsMultiLine()) { + dwExtendedStyle |= FWL_STYLEEXT_EDT_MultiLine | FWL_STYLEEXT_EDT_WantReturn; + if (m_pDataAcc->GetVerticalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) { + dwStyle |= FWL_WGTSTYLE_VScroll; + dwExtendedStyle |= FWL_STYLEEXT_EDT_AutoVScroll; + } + } else if (m_pDataAcc->GetHorizontalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) { + dwExtendedStyle |= FWL_STYLEEXT_EDT_AutoHScroll; + } + if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open || + !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) { + dwExtendedStyle |= FWL_STYLEEXT_EDT_ReadOnly; + dwExtendedStyle |= FWL_STYLEEXT_EDT_MultiLine; + } + + XFA_Element eType = XFA_Element::Unknown; + int32_t iMaxChars = m_pDataAcc->GetMaxChars(eType); + if (eType == XFA_Element::ExData) + iMaxChars = 0; + + int32_t iNumCells = m_pDataAcc->GetNumberOfCells(); + if (iNumCells == 0) { + dwExtendedStyle |= FWL_STYLEEXT_EDT_CombText; + pWidget->SetLimit(iMaxChars > 0 ? iMaxChars : 1); + } else if (iNumCells > 0) { + dwExtendedStyle |= FWL_STYLEEXT_EDT_CombText; + pWidget->SetLimit(iNumCells); + } else { + pWidget->SetLimit(iMaxChars); + } + dwExtendedStyle |= GetAlignment(); + m_pNormalWidget->ModifyStyles(dwStyle, 0xFFFFFFFF); + m_pNormalWidget->ModifyStylesEx(dwExtendedStyle, 0xFFFFFFFF); +} + +bool CXFA_FFTextEdit::OnLButtonDown(uint32_t dwFlags, const CFX_PointF& point) { + if (!PtInActiveRect(point)) + return false; + if (!IsFocused()) { + m_dwStatus |= XFA_WidgetStatus_Focused; + UpdateFWLData(); + AddInvalidateRect(); + } + + SetButtonDown(true); + CFWL_MessageMouse ms(nullptr, m_pNormalWidget.get()); + ms.m_dwCmd = FWL_MouseCommand::LeftButtonDown; + ms.m_dwFlags = dwFlags; + ms.m_pos = FWLToClient(point); + TranslateFWLMessage(&ms); + return true; +} + +bool CXFA_FFTextEdit::OnRButtonDown(uint32_t dwFlags, const CFX_PointF& point) { + if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open) + return false; + if (!PtInActiveRect(point)) + return false; + if (!IsFocused()) { + m_dwStatus |= XFA_WidgetStatus_Focused; + UpdateFWLData(); + AddInvalidateRect(); + } + + SetButtonDown(true); + CFWL_MessageMouse ms(nullptr, nullptr); + ms.m_dwCmd = FWL_MouseCommand::RightButtonDown; + ms.m_dwFlags = dwFlags; + ms.m_pos = FWLToClient(point); + TranslateFWLMessage(&ms); + return true; +} + +bool CXFA_FFTextEdit::OnRButtonUp(uint32_t dwFlags, const CFX_PointF& point) { + if (!CXFA_FFField::OnRButtonUp(dwFlags, point)) + return false; + + GetDoc()->GetDocEnvironment()->PopupMenu(this, point); + return true; +} + +bool CXFA_FFTextEdit::OnSetFocus(CXFA_FFWidget* pOldWidget) { + m_dwStatus &= ~XFA_WidgetStatus_TextEditValueChanged; + if (!IsFocused()) { + m_dwStatus |= XFA_WidgetStatus_Focused; + UpdateFWLData(); + AddInvalidateRect(); + } + CXFA_FFWidget::OnSetFocus(pOldWidget); + CFWL_MessageSetFocus ms(nullptr, m_pNormalWidget.get()); + TranslateFWLMessage(&ms); + return true; +} + +bool CXFA_FFTextEdit::OnKillFocus(CXFA_FFWidget* pNewWidget) { + CFWL_MessageKillFocus ms(nullptr, m_pNormalWidget.get()); + TranslateFWLMessage(&ms); + m_dwStatus &= ~XFA_WidgetStatus_Focused; + + SetEditScrollOffset(); + ProcessCommittedData(); + UpdateFWLData(); + AddInvalidateRect(); + CXFA_FFWidget::OnKillFocus(pNewWidget); + + m_dwStatus &= ~XFA_WidgetStatus_TextEditValueChanged; + return true; +} + +bool CXFA_FFTextEdit::CommitData() { + CFX_WideString wsText = + static_cast<CFWL_Edit*>(m_pNormalWidget.get())->GetText(); + if (m_pDataAcc->SetValue(wsText, XFA_VALUEPICTURE_Edit)) { + m_pDataAcc->UpdateUIDisplay(this); + return true; + } + ValidateNumberField(wsText); + return false; +} + +void CXFA_FFTextEdit::ValidateNumberField(const CFX_WideString& wsText) { + CXFA_WidgetAcc* pAcc = GetDataAcc(); + if (!pAcc || pAcc->GetUIType() != XFA_Element::NumericEdit) + return; + + IXFA_AppProvider* pAppProvider = GetApp()->GetAppProvider(); + if (!pAppProvider) + return; + + CFX_WideString wsSomField; + pAcc->GetNode()->GetSOMExpression(wsSomField); + + CFX_WideString wsMessage; + wsMessage.Format(L"%s can not contain %s", wsText.c_str(), + wsSomField.c_str()); + pAppProvider->MsgBox(wsMessage, pAppProvider->GetAppTitle(), XFA_MBICON_Error, + XFA_MB_OK); +} + +bool CXFA_FFTextEdit::IsDataChanged() { + return (m_dwStatus & XFA_WidgetStatus_TextEditValueChanged) != 0; +} + +uint32_t CXFA_FFTextEdit::GetAlignment() { + CXFA_Para para = m_pDataAcc->GetPara(); + if (!para) + return 0; + + uint32_t dwExtendedStyle = 0; + switch (para.GetHorizontalAlign()) { + case XFA_ATTRIBUTEENUM_Center: + dwExtendedStyle |= FWL_STYLEEXT_EDT_HCenter; + break; + case XFA_ATTRIBUTEENUM_Justify: + dwExtendedStyle |= FWL_STYLEEXT_EDT_Justified; + break; + case XFA_ATTRIBUTEENUM_JustifyAll: + case XFA_ATTRIBUTEENUM_Radix: + break; + case XFA_ATTRIBUTEENUM_Right: + dwExtendedStyle |= FWL_STYLEEXT_EDT_HFar; + break; + default: + dwExtendedStyle |= FWL_STYLEEXT_EDT_HNear; + break; + } + + switch (para.GetVerticalAlign()) { + case XFA_ATTRIBUTEENUM_Middle: + dwExtendedStyle |= FWL_STYLEEXT_EDT_VCenter; + break; + case XFA_ATTRIBUTEENUM_Bottom: + dwExtendedStyle |= FWL_STYLEEXT_EDT_VFar; + break; + default: + dwExtendedStyle |= FWL_STYLEEXT_EDT_VNear; + break; + } + return dwExtendedStyle; +} + +bool CXFA_FFTextEdit::UpdateFWLData() { + if (!m_pNormalWidget) + return false; + + CFWL_Edit* pEdit = static_cast<CFWL_Edit*>(m_pNormalWidget.get()); + XFA_VALUEPICTURE eType = XFA_VALUEPICTURE_Display; + if (IsFocused()) + eType = XFA_VALUEPICTURE_Edit; + + bool bUpdate = false; + if (m_pDataAcc->GetUIType() == XFA_Element::TextEdit && + m_pDataAcc->GetNumberOfCells() < 0) { + XFA_Element elementType = XFA_Element::Unknown; + int32_t iMaxChars = m_pDataAcc->GetMaxChars(elementType); + if (elementType == XFA_Element::ExData) + iMaxChars = eType == XFA_VALUEPICTURE_Edit ? iMaxChars : 0; + if (pEdit->GetLimit() != iMaxChars) { + pEdit->SetLimit(iMaxChars); + bUpdate = true; + } + } else if (m_pDataAcc->GetUIType() == XFA_Element::Barcode) { + int32_t nDataLen = 0; + if (eType == XFA_VALUEPICTURE_Edit) + m_pDataAcc->GetBarcodeAttribute_DataLength(&nDataLen); + pEdit->SetLimit(nDataLen); + bUpdate = true; + } + + CFX_WideString wsText; + m_pDataAcc->GetValue(wsText, eType); + + CFX_WideString wsOldText = pEdit->GetText(); + if (wsText != wsOldText || (eType == XFA_VALUEPICTURE_Edit && bUpdate)) { + pEdit->SetText(wsText); + bUpdate = true; + } + if (bUpdate) + m_pNormalWidget->Update(); + + return true; +} + +void CXFA_FFTextEdit::OnTextChanged(CFWL_Widget* pWidget, + const CFX_WideString& wsChanged, + const CFX_WideString& wsPrevText) { + m_dwStatus |= XFA_WidgetStatus_TextEditValueChanged; + CXFA_EventParam eParam; + eParam.m_eType = XFA_EVENT_Change; + eParam.m_wsChange = wsChanged; + eParam.m_pTarget = m_pDataAcc.Get(); + eParam.m_wsPrevText = wsPrevText; + CFWL_Edit* pEdit = static_cast<CFWL_Edit*>(m_pNormalWidget.get()); + if (m_pDataAcc->GetUIType() == XFA_Element::DateTimeEdit) { + CFWL_DateTimePicker* pDateTime = (CFWL_DateTimePicker*)pEdit; + eParam.m_wsNewText = pDateTime->GetEditText(); + int32_t iSels = pDateTime->CountSelRanges(); + if (iSels) + eParam.m_iSelEnd = pDateTime->GetSelRange(0, &eParam.m_iSelStart); + } else { + eParam.m_wsNewText = pEdit->GetText(); + int32_t iSels = pEdit->CountSelRanges(); + if (iSels) + eParam.m_iSelEnd = pEdit->GetSelRange(0, &eParam.m_iSelStart); + } + m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_Change, &eParam); +} + +void CXFA_FFTextEdit::OnTextFull(CFWL_Widget* pWidget) { + CXFA_EventParam eParam; + eParam.m_eType = XFA_EVENT_Full; + eParam.m_pTarget = m_pDataAcc.Get(); + m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_Full, &eParam); +} + +bool CXFA_FFTextEdit::CheckWord(const CFX_ByteStringC& sWord) { + return sWord.IsEmpty() || m_pDataAcc->GetUIType() != XFA_Element::TextEdit; +} + +void CXFA_FFTextEdit::OnProcessMessage(CFWL_Message* pMessage) { + m_pOldDelegate->OnProcessMessage(pMessage); +} + +void CXFA_FFTextEdit::OnProcessEvent(CFWL_Event* pEvent) { + CXFA_FFField::OnProcessEvent(pEvent); + switch (pEvent->GetType()) { + case CFWL_Event::Type::TextChanged: { + CFWL_EventTextChanged* event = + static_cast<CFWL_EventTextChanged*>(pEvent); + CFX_WideString wsChange; + OnTextChanged(m_pNormalWidget.get(), wsChange, event->wsPrevText); + break; + } + case CFWL_Event::Type::TextFull: { + OnTextFull(m_pNormalWidget.get()); + break; + } + case CFWL_Event::Type::CheckWord: { + CFX_WideString wstr(L"FWL_EVENT_DTP_SelectChanged"); + CFWL_EventCheckWord* event = static_cast<CFWL_EventCheckWord*>(pEvent); + event->bCheckWord = CheckWord(event->bsWord.AsStringC()); + break; + } + default: + break; + } + m_pOldDelegate->OnProcessEvent(pEvent); +} + +void CXFA_FFTextEdit::OnDrawWidget(CXFA_Graphics* pGraphics, + const CFX_Matrix* pMatrix) { + m_pOldDelegate->OnDrawWidget(pGraphics, pMatrix); +} diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_fftextedit.h b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_fftextedit.h new file mode 100644 index 00000000000..109a31a0def --- /dev/null +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_fftextedit.h @@ -0,0 +1,57 @@ +// Copyright 2017 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 + +#ifndef XFA_FXFA_APP_CXFA_FFTEXTEDIT_H_ +#define XFA_FXFA_APP_CXFA_FFTEXTEDIT_H_ + +#include "core/fxcrt/fx_coordinates.h" +#include "core/fxcrt/fx_string.h" +#include "xfa/fxfa/app/cxfa_fffield.h" + +class CFWL_Event; +class CFWL_Widget; +class CFX_Matrix; +class CXFA_FFWidget; +class CXFA_WidgetAcc; +class IFWL_WidgetDelegate; + +class CXFA_FFTextEdit : public CXFA_FFField { + public: + explicit CXFA_FFTextEdit(CXFA_WidgetAcc* pDataAcc); + ~CXFA_FFTextEdit() override; + + // CXFA_FFField + bool LoadWidget() override; + void UpdateWidgetProperty() override; + bool OnLButtonDown(uint32_t dwFlags, const CFX_PointF& point) override; + bool OnRButtonDown(uint32_t dwFlags, const CFX_PointF& point) override; + bool OnRButtonUp(uint32_t dwFlags, const CFX_PointF& point) override; + bool OnSetFocus(CXFA_FFWidget* pOldWidget) override; + bool OnKillFocus(CXFA_FFWidget* pNewWidget) override; + void OnProcessMessage(CFWL_Message* pMessage) override; + void OnProcessEvent(CFWL_Event* pEvent) override; + void OnDrawWidget(CXFA_Graphics* pGraphics, + const CFX_Matrix* pMatrix = nullptr) override; + + void OnTextChanged(CFWL_Widget* pWidget, + const CFX_WideString& wsChanged, + const CFX_WideString& wsPrevText); + void OnTextFull(CFWL_Widget* pWidget); + bool CheckWord(const CFX_ByteStringC& sWord); + + protected: + uint32_t GetAlignment(); + + IFWL_WidgetDelegate* m_pOldDelegate; + + private: + bool CommitData() override; + bool UpdateFWLData() override; + bool IsDataChanged() override; + void ValidateNumberField(const CFX_WideString& wsText); +}; + +#endif // XFA_FXFA_APP_CXFA_FFTEXTEDIT_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fwladapter.cpp b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_fwladapterwidgetmgr.cpp index 3cf6e5e8fdd..42362d858a0 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fwladapter.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_fwladapterwidgetmgr.cpp @@ -4,9 +4,9 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fxfa/app/xfa_fwladapter.h" +#include "xfa/fxfa/app/cxfa_fwladapterwidgetmgr.h" -#include "xfa/fxfa/app/xfa_fffield.h" +#include "xfa/fxfa/app/cxfa_fffield.h" #include "xfa/fxfa/cxfa_ffdoc.h" CXFA_FWLAdapterWidgetMgr::CXFA_FWLAdapterWidgetMgr() {} diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fwladapter.h b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_fwladapterwidgetmgr.h index b4a34815885..f9126eac3f9 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fwladapter.h +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_fwladapterwidgetmgr.h @@ -4,8 +4,8 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef XFA_FXFA_APP_XFA_FWLADAPTER_H_ -#define XFA_FXFA_APP_XFA_FWLADAPTER_H_ +#ifndef XFA_FXFA_APP_CXFA_FWLADAPTERWIDGETMGR_H_ +#define XFA_FXFA_APP_CXFA_FWLADAPTERWIDGETMGR_H_ #include "core/fxcrt/fx_coordinates.h" #include "core/fxcrt/fx_system.h" @@ -25,4 +25,4 @@ class CXFA_FWLAdapterWidgetMgr { CFX_RectF& rtPopup); }; -#endif // XFA_FXFA_APP_XFA_FWLADAPTER_H_ +#endif // XFA_FXFA_APP_CXFA_FWLADAPTERWIDGETMGR_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fwltheme.cpp b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_fwltheme.cpp index 9af45e62df0..5ad0873e196 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fwltheme.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_fwltheme.cpp @@ -4,7 +4,7 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fxfa/app/xfa_fwltheme.h" +#include "xfa/fxfa/app/cxfa_fwltheme.h" #include "core/fxcrt/fx_codepage.h" #include "xfa/fde/cfde_textout.h" @@ -24,7 +24,7 @@ #include "xfa/fwl/cfwl_themetext.h" #include "xfa/fxfa/cxfa_ffapp.h" #include "xfa/fxfa/cxfa_ffwidget.h" -#include "xfa/fxgraphics/cfx_color.h" +#include "xfa/fxgraphics/cxfa_color.h" namespace { @@ -105,7 +105,7 @@ void CXFA_FWLTheme::DrawText(CFWL_ThemeText* pParams) { if (pParams->m_iPart == CFWL_Part::Caption) m_pTextOut->SetTextColor(ArgbEncode(0xff, 0, 153, 255)); - CFX_Graphics* pGraphics = pParams->m_pGraphics; + CXFA_Graphics* pGraphics = pParams->m_pGraphics; CFX_RenderDevice* pRenderDevice = pGraphics->GetRenderDevice(); if (!pRenderDevice) return; @@ -126,7 +126,7 @@ void CXFA_FWLTheme::DrawText(CFWL_ThemeText* pParams) { return; CXFA_WidgetAcc* pAcc = pWidget->GetDataAcc(); - CFX_Graphics* pGraphics = pParams->m_pGraphics; + CXFA_Graphics* pGraphics = pParams->m_pGraphics; CFX_RenderDevice* pRenderDevice = pGraphics->GetRenderDevice(); if (!pRenderDevice) return; diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fwltheme.h b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_fwltheme.h index 7563c69ed97..eaca99082dc 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fwltheme.h +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_fwltheme.h @@ -4,8 +4,8 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef XFA_FXFA_APP_XFA_FWLTHEME_H_ -#define XFA_FXFA_APP_XFA_FWLTHEME_H_ +#ifndef XFA_FXFA_APP_CXFA_FWLTHEME_H_ +#define XFA_FXFA_APP_CXFA_FWLTHEME_H_ #include <memory> @@ -67,4 +67,4 @@ class CXFA_FWLTheme final : public IFWL_ThemeProvider { CXFA_FFWidget* XFA_ThemeGetOuterWidget(CFWL_Widget* pWidget); -#endif // XFA_FXFA_APP_XFA_FWLTHEME_H_ +#endif // XFA_FXFA_APP_CXFA_FWLTHEME_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_pieceline.cpp b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_pieceline.cpp index b906cf26e37..2e1ea55f1c1 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_pieceline.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_pieceline.cpp @@ -6,7 +6,7 @@ #include "xfa/fxfa/app/cxfa_pieceline.h" -#include "xfa/fxfa/app/xfa_textpiece.h" +#include "xfa/fxfa/app/cxfa_textpiece.h" CXFA_PieceLine::CXFA_PieceLine() {} diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_pieceline.h b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_pieceline.h index 87f71fc1924..6b17ebfb115 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_pieceline.h +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_pieceline.h @@ -12,14 +12,14 @@ #include "core/fxcrt/fx_basic.h" -class XFA_TextPiece; +class CXFA_TextPiece; class CXFA_PieceLine { public: CXFA_PieceLine(); ~CXFA_PieceLine(); - std::vector<std::unique_ptr<XFA_TextPiece>> m_textPieces; + std::vector<std::unique_ptr<CXFA_TextPiece>> m_textPieces; std::vector<int32_t> m_charCounts; }; diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_textlayout.cpp b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_textlayout.cpp index c43f7e32606..489df9ab9c4 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_textlayout.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_textlayout.cpp @@ -24,10 +24,10 @@ #include "xfa/fxfa/app/cxfa_loadercontext.h" #include "xfa/fxfa/app/cxfa_pieceline.h" #include "xfa/fxfa/app/cxfa_textparsecontext.h" +#include "xfa/fxfa/app/cxfa_textpiece.h" +#include "xfa/fxfa/app/cxfa_textprovider.h" #include "xfa/fxfa/app/cxfa_texttabstopscontext.h" #include "xfa/fxfa/app/cxfa_textuserdata.h" -#include "xfa/fxfa/app/xfa_ffwidgetacc.h" -#include "xfa/fxfa/app/xfa_textpiece.h" #include "xfa/fxfa/parser/cxfa_font.h" #include "xfa/fxfa/parser/cxfa_node.h" #include "xfa/fxfa/parser/cxfa_para.h" @@ -594,7 +594,7 @@ bool CXFA_TextLayout::DrawString(CFX_RenderDevice* pFxDevice, int32_t iPieces = pdfium::CollectionSize<int32_t>(pPieceLine->m_textPieces); int32_t j = 0; for (j = 0; j < iPieces; j++) { - const XFA_TextPiece* pPiece = pPieceLine->m_textPieces[j].get(); + const CXFA_TextPiece* pPiece = pPieceLine->m_textPieces[j].get(); int32_t iChars = pPiece->iChars; if (iCharCount < iChars) { FX_Free(pCharPos); @@ -964,7 +964,7 @@ void CXFA_TextLayout::DoTabstops(CFDE_CSSComputedStyle* pStyle, if (iPieces == 0) return; - XFA_TextPiece* pPiece = pPieceLine->m_textPieces[iPieces - 1].get(); + CXFA_TextPiece* pPiece = pPieceLine->m_textPieces[iPieces - 1].get(); int32_t& iTabstopsIndex = m_pTabstopContext->m_iTabIndex; int32_t iCount = m_textParser.CountTabs(pStyle); if (!pdfium::IndexInBounds(m_pTabstopContext->m_tabstops, iTabstopsIndex)) @@ -975,7 +975,7 @@ void CXFA_TextLayout::DoTabstops(CFDE_CSSComputedStyle* pStyle, m_pTabstopContext->m_bTabstops = true; float fRight = 0; if (iPieces > 1) { - XFA_TextPiece* p = pPieceLine->m_textPieces[iPieces - 2].get(); + CXFA_TextPiece* p = pPieceLine->m_textPieces[iPieces - 2].get(); fRight = p->rtPiece.right(); } m_pTabstopContext->m_fTabWidth = @@ -1032,7 +1032,7 @@ void CXFA_TextLayout::AppendTextLine(CFX_BreakType dwStatus, pStyle = pUserData->m_pStyle; float fVerScale = pPiece->m_iVerticalScale / 100.0f; - auto pTP = pdfium::MakeUnique<XFA_TextPiece>(); + auto pTP = pdfium::MakeUnique<CXFA_TextPiece>(); pTP->iChars = pPiece->m_iChars; pTP->szText = pPiece->GetString(); pTP->Widths = pPiece->GetWidths(); @@ -1149,7 +1149,7 @@ void CXFA_TextLayout::RenderString(CFDE_RenderDevice* pDevice, int32_t iPiece, FXTEXT_CHARPOS* pCharPos, const CFX_Matrix& tmDoc2Device) { - const XFA_TextPiece* pPiece = pPieceLine->m_textPieces[iPiece].get(); + const CXFA_TextPiece* pPiece = pPieceLine->m_textPieces[iPiece].get(); int32_t iCount = GetDisplayPos(pPiece, pCharPos); if (iCount > 0) { pBrush->SetColor(pPiece->dwColor); @@ -1165,7 +1165,7 @@ void CXFA_TextLayout::RenderPath(CFDE_RenderDevice* pDevice, int32_t iPiece, FXTEXT_CHARPOS* pCharPos, const CFX_Matrix& tmDoc2Device) { - XFA_TextPiece* pPiece = pPieceLine->m_textPieces[iPiece].get(); + CXFA_TextPiece* pPiece = pPieceLine->m_textPieces[iPiece].get(); bool bNoUnderline = pPiece->iUnderline < 1 || pPiece->iUnderline > 2; bool bNoLineThrough = pPiece->iLineThrough < 1 || pPiece->iLineThrough > 2; if (bNoUnderline && bNoLineThrough) @@ -1273,7 +1273,7 @@ void CXFA_TextLayout::RenderPath(CFDE_RenderDevice* pDevice, pDevice->DrawPath(pPen, 1, pPath.get(), &tmDoc2Device); } -int32_t CXFA_TextLayout::GetDisplayPos(const XFA_TextPiece* pPiece, +int32_t CXFA_TextLayout::GetDisplayPos(const CXFA_TextPiece* pPiece, FXTEXT_CHARPOS* pCharPos, bool bCharCode) { if (!pPiece) @@ -1285,7 +1285,7 @@ int32_t CXFA_TextLayout::GetDisplayPos(const XFA_TextPiece* pPiece, return m_pBreak->GetDisplayPos(&tr, pCharPos, bCharCode); } -bool CXFA_TextLayout::ToRun(const XFA_TextPiece* pPiece, FX_RTFTEXTOBJ* tr) { +bool CXFA_TextLayout::ToRun(const CXFA_TextPiece* pPiece, FX_RTFTEXTOBJ* tr) { int32_t iLength = pPiece->iChars; if (iLength < 1) return false; diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_textlayout.h b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_textlayout.h index 75c2d563242..e8c203fcc1d 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_textlayout.h +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_textlayout.h @@ -29,7 +29,7 @@ class CXFA_Node; class CXFA_PieceLine; class CXFA_TextProvider; class CXFA_TextTabstopsContext; -class XFA_TextPiece; +class CXFA_TextPiece; class CXFA_TextLayout { public: @@ -112,10 +112,10 @@ class CXFA_TextLayout { int32_t iPiece, FXTEXT_CHARPOS* pCharPos, const CFX_Matrix& tmDoc2Device); - int32_t GetDisplayPos(const XFA_TextPiece* pPiece, + int32_t GetDisplayPos(const CXFA_TextPiece* pPiece, FXTEXT_CHARPOS* pCharPos, bool bCharCode = false); - bool ToRun(const XFA_TextPiece* pPiece, FX_RTFTEXTOBJ* tr); + bool ToRun(const CXFA_TextPiece* pPiece, FX_RTFTEXTOBJ* tr); void DoTabstops(CFDE_CSSComputedStyle* pStyle, CXFA_PieceLine* pPieceLine); bool Layout(int32_t iBlock); int32_t CountBlocks() const; diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_textparser.cpp b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_textparser.cpp index 33bd2b9deb4..8bdb0a83726 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_textparser.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_textparser.cpp @@ -21,8 +21,8 @@ #include "xfa/fgas/font/cfgas_fontmgr.h" #include "xfa/fxfa/app/cxfa_csstagprovider.h" #include "xfa/fxfa/app/cxfa_textparsecontext.h" +#include "xfa/fxfa/app/cxfa_textprovider.h" #include "xfa/fxfa/app/cxfa_texttabstopscontext.h" -#include "xfa/fxfa/app/xfa_ffwidgetacc.h" #include "xfa/fxfa/cxfa_ffapp.h" #include "xfa/fxfa/cxfa_ffdoc.h" #include "xfa/fxfa/cxfa_fontmgr.h" diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_textpiece.cpp b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_textpiece.cpp index c53e45f91a2..4cbad0a4753 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_textpiece.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_textpiece.cpp @@ -4,10 +4,10 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fxfa/app/xfa_textpiece.h" +#include "xfa/fxfa/app/cxfa_textpiece.h" #include "xfa/fxfa/app/cxfa_linkuserdata.h" -XFA_TextPiece::XFA_TextPiece() {} +CXFA_TextPiece::CXFA_TextPiece() {} -XFA_TextPiece::~XFA_TextPiece() {} +CXFA_TextPiece::~CXFA_TextPiece() {} diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_textpiece.h b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_textpiece.h index fd1f3bdbaa4..0fba66ef52c 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_textpiece.h +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_textpiece.h @@ -4,8 +4,8 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef XFA_FXFA_APP_XFA_TEXTPIECE_H_ -#define XFA_FXFA_APP_XFA_TEXTPIECE_H_ +#ifndef XFA_FXFA_APP_CXFA_TEXTPIECE_H_ +#define XFA_FXFA_APP_CXFA_TEXTPIECE_H_ #include <vector> @@ -17,10 +17,10 @@ class CXFA_LinkUserData; -class XFA_TextPiece { +class CXFA_TextPiece { public: - XFA_TextPiece(); - ~XFA_TextPiece(); + CXFA_TextPiece(); + ~CXFA_TextPiece(); CFX_WideString szText; std::vector<int32_t> Widths; @@ -38,4 +38,4 @@ class XFA_TextPiece { CFX_RetainPtr<CXFA_LinkUserData> pLinkData; }; -#endif // XFA_FXFA_APP_XFA_TEXTPIECE_H_ +#endif // XFA_FXFA_APP_CXFA_TEXTPIECE_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffwidgetacc.cpp b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_textprovider.cpp index 2ac27cfdc8e..01bc021f8ce 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffwidgetacc.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_textprovider.cpp @@ -4,7 +4,7 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fxfa/app/xfa_ffwidgetacc.h" +#include "xfa/fxfa/app/cxfa_textprovider.h" #include <algorithm> #include <memory> @@ -16,10 +16,9 @@ #include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" #include "xfa/fde/cfde_textout.h" -#include "xfa/fxfa/app/xfa_ffcheckbutton.h" -#include "xfa/fxfa/app/xfa_ffchoicelist.h" -#include "xfa/fxfa/app/xfa_fffield.h" -#include "xfa/fxfa/app/xfa_fwladapter.h" +#include "xfa/fxfa/app/cxfa_ffcheckbutton.h" +#include "xfa/fxfa/app/cxfa_fffield.h" +#include "xfa/fxfa/app/cxfa_fwladapterwidgetmgr.h" #include "xfa/fxfa/cxfa_eventparam.h" #include "xfa/fxfa/cxfa_ffapp.h" #include "xfa/fxfa/cxfa_ffdoc.h" diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffwidgetacc.h b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_textprovider.h index 7840186b142..08fc6f38e23 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffwidgetacc.h +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_textprovider.h @@ -4,8 +4,8 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef XFA_FXFA_APP_XFA_FFWIDGETACC_H_ -#define XFA_FXFA_APP_XFA_FFWIDGETACC_H_ +#ifndef XFA_FXFA_APP_CXFA_TEXTPROVIDER_H_ +#define XFA_FXFA_APP_CXFA_TEXTPROVIDER_H_ #include "core/fxcrt/fx_string.h" #include "xfa/fxfa/app/cxfa_textlayout.h" @@ -47,4 +47,4 @@ class CXFA_TextProvider { XFA_TEXTPROVIDERTYPE m_eType; }; -#endif // XFA_FXFA_APP_XFA_FFWIDGETACC_H_ +#endif // XFA_FXFA_APP_CXFA_TEXTPROVIDER_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffpath.h b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffpath.h deleted file mode 100644 index 6df53f4e1d6..00000000000 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffpath.h +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2014 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 - -#ifndef XFA_FXFA_APP_XFA_FFPATH_H_ -#define XFA_FXFA_APP_XFA_FFPATH_H_ - -#include "xfa/fxfa/app/xfa_ffdraw.h" - -class CXFA_FFLine : public CXFA_FFDraw { - public: - explicit CXFA_FFLine(CXFA_WidgetAcc* pDataAcc); - ~CXFA_FFLine() override; - - // CXFA_FFWidget - void RenderWidget(CFX_Graphics* pGS, - CFX_Matrix* pMatrix, - uint32_t dwStatus) override; - - private: - void GetRectFromHand(CFX_RectF& rect, int32_t iHand, float fLineWidth); -}; - -class CXFA_FFArc : public CXFA_FFDraw { - public: - explicit CXFA_FFArc(CXFA_WidgetAcc* pDataAcc); - ~CXFA_FFArc() override; - - // CXFA_FFWidget - void RenderWidget(CFX_Graphics* pGS, - CFX_Matrix* pMatrix, - uint32_t dwStatus) override; -}; - -class CXFA_FFRectangle : public CXFA_FFDraw { - public: - explicit CXFA_FFRectangle(CXFA_WidgetAcc* pDataAcc); - ~CXFA_FFRectangle() override; - - // CXFA_FFWidget - void RenderWidget(CFX_Graphics* pGS, - CFX_Matrix* pMatrix, - uint32_t dwStatus) override; -}; - -#endif // XFA_FXFA_APP_XFA_FFPATH_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fftextedit.cpp b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fftextedit.cpp deleted file mode 100644 index 41305efcc8c..00000000000 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fftextedit.cpp +++ /dev/null @@ -1,706 +0,0 @@ -// Copyright 2014 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 "xfa/fxfa/app/xfa_fftextedit.h" - -#include <utility> -#include <vector> - -#include "xfa/fwl/cfwl_datetimepicker.h" -#include "xfa/fwl/cfwl_edit.h" -#include "xfa/fwl/cfwl_eventcheckword.h" -#include "xfa/fwl/cfwl_eventselectchanged.h" -#include "xfa/fwl/cfwl_eventtextchanged.h" -#include "xfa/fwl/cfwl_eventvalidate.h" -#include "xfa/fwl/cfwl_messagekillfocus.h" -#include "xfa/fwl/cfwl_messagemouse.h" -#include "xfa/fwl/cfwl_messagesetfocus.h" -#include "xfa/fwl/cfwl_notedriver.h" -#include "xfa/fxfa/app/xfa_fffield.h" -#include "xfa/fxfa/app/xfa_fwladapter.h" -#include "xfa/fxfa/cxfa_eventparam.h" -#include "xfa/fxfa/cxfa_ffapp.h" -#include "xfa/fxfa/cxfa_ffdoc.h" -#include "xfa/fxfa/cxfa_ffdocview.h" -#include "xfa/fxfa/cxfa_ffpageview.h" -#include "xfa/fxfa/cxfa_ffwidget.h" -#include "xfa/fxfa/parser/cxfa_localevalue.h" -#include "xfa/fxfa/parser/cxfa_node.h" - -CXFA_FFTextEdit::CXFA_FFTextEdit(CXFA_WidgetAcc* pDataAcc) - : CXFA_FFField(pDataAcc), m_pOldDelegate(nullptr) {} - -CXFA_FFTextEdit::~CXFA_FFTextEdit() { - if (m_pNormalWidget) { - CFWL_NoteDriver* pNoteDriver = - m_pNormalWidget->GetOwnerApp()->GetNoteDriver(); - pNoteDriver->UnregisterEventTarget(m_pNormalWidget.get()); - } -} - -bool CXFA_FFTextEdit::LoadWidget() { - auto pNewWidget = pdfium::MakeUnique<CFWL_Edit>( - GetFWLApp(), pdfium::MakeUnique<CFWL_WidgetProperties>(), nullptr); - CFWL_Edit* pFWLEdit = pNewWidget.get(); - m_pNormalWidget = std::move(pNewWidget); - m_pNormalWidget->SetLayoutItem(this); - - CFWL_NoteDriver* pNoteDriver = - m_pNormalWidget->GetOwnerApp()->GetNoteDriver(); - pNoteDriver->RegisterEventTarget(m_pNormalWidget.get(), - m_pNormalWidget.get()); - m_pOldDelegate = m_pNormalWidget->GetDelegate(); - m_pNormalWidget->SetDelegate(this); - m_pNormalWidget->LockUpdate(); - UpdateWidgetProperty(); - - CFX_WideString wsText; - m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Display); - pFWLEdit->SetText(wsText); - m_pNormalWidget->UnlockUpdate(); - return CXFA_FFField::LoadWidget(); -} - -void CXFA_FFTextEdit::UpdateWidgetProperty() { - CFWL_Edit* pWidget = static_cast<CFWL_Edit*>(m_pNormalWidget.get()); - if (!pWidget) - return; - - uint32_t dwStyle = 0; - uint32_t dwExtendedStyle = FWL_STYLEEXT_EDT_ShowScrollbarFocus | - FWL_STYLEEXT_EDT_OuterScrollbar | - FWL_STYLEEXT_EDT_LastLineHeight; - dwExtendedStyle |= UpdateUIProperty(); - if (m_pDataAcc->IsMultiLine()) { - dwExtendedStyle |= FWL_STYLEEXT_EDT_MultiLine | FWL_STYLEEXT_EDT_WantReturn; - if (m_pDataAcc->GetVerticalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) { - dwStyle |= FWL_WGTSTYLE_VScroll; - dwExtendedStyle |= FWL_STYLEEXT_EDT_AutoVScroll; - } - } else if (m_pDataAcc->GetHorizontalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) { - dwExtendedStyle |= FWL_STYLEEXT_EDT_AutoHScroll; - } - if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open || - !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) { - dwExtendedStyle |= FWL_STYLEEXT_EDT_ReadOnly; - dwExtendedStyle |= FWL_STYLEEXT_EDT_MultiLine; - } - - XFA_Element eType = XFA_Element::Unknown; - int32_t iMaxChars = m_pDataAcc->GetMaxChars(eType); - if (eType == XFA_Element::ExData) - iMaxChars = 0; - - int32_t iNumCells = m_pDataAcc->GetNumberOfCells(); - if (iNumCells == 0) { - dwExtendedStyle |= FWL_STYLEEXT_EDT_CombText; - pWidget->SetLimit(iMaxChars > 0 ? iMaxChars : 1); - } else if (iNumCells > 0) { - dwExtendedStyle |= FWL_STYLEEXT_EDT_CombText; - pWidget->SetLimit(iNumCells); - } else { - pWidget->SetLimit(iMaxChars); - } - dwExtendedStyle |= GetAlignment(); - m_pNormalWidget->ModifyStyles(dwStyle, 0xFFFFFFFF); - m_pNormalWidget->ModifyStylesEx(dwExtendedStyle, 0xFFFFFFFF); -} - -bool CXFA_FFTextEdit::OnLButtonDown(uint32_t dwFlags, const CFX_PointF& point) { - if (!PtInActiveRect(point)) - return false; - if (!IsFocused()) { - m_dwStatus |= XFA_WidgetStatus_Focused; - UpdateFWLData(); - AddInvalidateRect(); - } - - SetButtonDown(true); - CFWL_MessageMouse ms(nullptr, m_pNormalWidget.get()); - ms.m_dwCmd = FWL_MouseCommand::LeftButtonDown; - ms.m_dwFlags = dwFlags; - ms.m_pos = FWLToClient(point); - TranslateFWLMessage(&ms); - return true; -} - -bool CXFA_FFTextEdit::OnRButtonDown(uint32_t dwFlags, const CFX_PointF& point) { - if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open) - return false; - if (!PtInActiveRect(point)) - return false; - if (!IsFocused()) { - m_dwStatus |= XFA_WidgetStatus_Focused; - UpdateFWLData(); - AddInvalidateRect(); - } - - SetButtonDown(true); - CFWL_MessageMouse ms(nullptr, nullptr); - ms.m_dwCmd = FWL_MouseCommand::RightButtonDown; - ms.m_dwFlags = dwFlags; - ms.m_pos = FWLToClient(point); - TranslateFWLMessage(&ms); - return true; -} - -bool CXFA_FFTextEdit::OnRButtonUp(uint32_t dwFlags, const CFX_PointF& point) { - if (!CXFA_FFField::OnRButtonUp(dwFlags, point)) - return false; - - GetDoc()->GetDocEnvironment()->PopupMenu(this, point); - return true; -} - -bool CXFA_FFTextEdit::OnSetFocus(CXFA_FFWidget* pOldWidget) { - m_dwStatus &= ~XFA_WidgetStatus_TextEditValueChanged; - if (!IsFocused()) { - m_dwStatus |= XFA_WidgetStatus_Focused; - UpdateFWLData(); - AddInvalidateRect(); - } - CXFA_FFWidget::OnSetFocus(pOldWidget); - CFWL_MessageSetFocus ms(nullptr, m_pNormalWidget.get()); - TranslateFWLMessage(&ms); - return true; -} - -bool CXFA_FFTextEdit::OnKillFocus(CXFA_FFWidget* pNewWidget) { - CFWL_MessageKillFocus ms(nullptr, m_pNormalWidget.get()); - TranslateFWLMessage(&ms); - m_dwStatus &= ~XFA_WidgetStatus_Focused; - - SetEditScrollOffset(); - ProcessCommittedData(); - UpdateFWLData(); - AddInvalidateRect(); - CXFA_FFWidget::OnKillFocus(pNewWidget); - - m_dwStatus &= ~XFA_WidgetStatus_TextEditValueChanged; - return true; -} - -bool CXFA_FFTextEdit::CommitData() { - CFX_WideString wsText = - static_cast<CFWL_Edit*>(m_pNormalWidget.get())->GetText(); - if (m_pDataAcc->SetValue(wsText, XFA_VALUEPICTURE_Edit)) { - m_pDataAcc->UpdateUIDisplay(this); - return true; - } - ValidateNumberField(wsText); - return false; -} - -void CXFA_FFTextEdit::ValidateNumberField(const CFX_WideString& wsText) { - CXFA_WidgetAcc* pAcc = GetDataAcc(); - if (!pAcc || pAcc->GetUIType() != XFA_Element::NumericEdit) - return; - - IXFA_AppProvider* pAppProvider = GetApp()->GetAppProvider(); - if (!pAppProvider) - return; - - CFX_WideString wsSomField; - pAcc->GetNode()->GetSOMExpression(wsSomField); - - CFX_WideString wsMessage; - wsMessage.Format(L"%s can not contain %s", wsText.c_str(), - wsSomField.c_str()); - pAppProvider->MsgBox(wsMessage, pAppProvider->GetAppTitle(), XFA_MBICON_Error, - XFA_MB_OK); -} - -bool CXFA_FFTextEdit::IsDataChanged() { - return (m_dwStatus & XFA_WidgetStatus_TextEditValueChanged) != 0; -} - -uint32_t CXFA_FFTextEdit::GetAlignment() { - CXFA_Para para = m_pDataAcc->GetPara(); - if (!para) - return 0; - - uint32_t dwExtendedStyle = 0; - switch (para.GetHorizontalAlign()) { - case XFA_ATTRIBUTEENUM_Center: - dwExtendedStyle |= FWL_STYLEEXT_EDT_HCenter; - break; - case XFA_ATTRIBUTEENUM_Justify: - dwExtendedStyle |= FWL_STYLEEXT_EDT_Justified; - break; - case XFA_ATTRIBUTEENUM_JustifyAll: - case XFA_ATTRIBUTEENUM_Radix: - break; - case XFA_ATTRIBUTEENUM_Right: - dwExtendedStyle |= FWL_STYLEEXT_EDT_HFar; - break; - default: - dwExtendedStyle |= FWL_STYLEEXT_EDT_HNear; - break; - } - - switch (para.GetVerticalAlign()) { - case XFA_ATTRIBUTEENUM_Middle: - dwExtendedStyle |= FWL_STYLEEXT_EDT_VCenter; - break; - case XFA_ATTRIBUTEENUM_Bottom: - dwExtendedStyle |= FWL_STYLEEXT_EDT_VFar; - break; - default: - dwExtendedStyle |= FWL_STYLEEXT_EDT_VNear; - break; - } - return dwExtendedStyle; -} - -bool CXFA_FFTextEdit::UpdateFWLData() { - if (!m_pNormalWidget) - return false; - - XFA_VALUEPICTURE eType = XFA_VALUEPICTURE_Display; - if (IsFocused()) - eType = XFA_VALUEPICTURE_Edit; - - bool bUpdate = false; - if (m_pDataAcc->GetUIType() == XFA_Element::TextEdit && - m_pDataAcc->GetNumberOfCells() < 0) { - XFA_Element elementType = XFA_Element::Unknown; - int32_t iMaxChars = m_pDataAcc->GetMaxChars(elementType); - if (elementType == XFA_Element::ExData) - iMaxChars = eType == XFA_VALUEPICTURE_Edit ? iMaxChars : 0; - if (static_cast<CFWL_Edit*>(m_pNormalWidget.get())->GetLimit() != - iMaxChars) { - static_cast<CFWL_Edit*>(m_pNormalWidget.get())->SetLimit(iMaxChars); - bUpdate = true; - } - } - - if (m_pDataAcc->GetUIType() == XFA_Element::Barcode) { - int32_t nDataLen = 0; - if (eType == XFA_VALUEPICTURE_Edit) - m_pDataAcc->GetBarcodeAttribute_DataLength(&nDataLen); - static_cast<CFWL_Edit*>(m_pNormalWidget.get())->SetLimit(nDataLen); - bUpdate = true; - } - - CFX_WideString wsText; - m_pDataAcc->GetValue(wsText, eType); - - CFX_WideString wsOldText = - static_cast<CFWL_Edit*>(m_pNormalWidget.get())->GetText(); - if (wsText != wsOldText || (eType == XFA_VALUEPICTURE_Edit && bUpdate)) { - static_cast<CFWL_Edit*>(m_pNormalWidget.get())->SetText(wsText); - bUpdate = true; - } - if (bUpdate) - m_pNormalWidget->Update(); - - return true; -} - -void CXFA_FFTextEdit::OnTextChanged(CFWL_Widget* pWidget, - const CFX_WideString& wsChanged, - const CFX_WideString& wsPrevText) { - m_dwStatus |= XFA_WidgetStatus_TextEditValueChanged; - CXFA_EventParam eParam; - eParam.m_eType = XFA_EVENT_Change; - eParam.m_wsChange = wsChanged; - eParam.m_pTarget = m_pDataAcc.Get(); - eParam.m_wsPrevText = wsPrevText; - CFWL_Edit* pEdit = static_cast<CFWL_Edit*>(m_pNormalWidget.get()); - if (m_pDataAcc->GetUIType() == XFA_Element::DateTimeEdit) { - CFWL_DateTimePicker* pDateTime = (CFWL_DateTimePicker*)pEdit; - eParam.m_wsNewText = pDateTime->GetEditText(); - int32_t iSels = pDateTime->CountSelRanges(); - if (iSels) - eParam.m_iSelEnd = pDateTime->GetSelRange(0, &eParam.m_iSelStart); - } else { - eParam.m_wsNewText = pEdit->GetText(); - int32_t iSels = pEdit->CountSelRanges(); - if (iSels) - eParam.m_iSelEnd = pEdit->GetSelRange(0, &eParam.m_iSelStart); - } - m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_Change, &eParam); -} - -void CXFA_FFTextEdit::OnTextFull(CFWL_Widget* pWidget) { - CXFA_EventParam eParam; - eParam.m_eType = XFA_EVENT_Full; - eParam.m_pTarget = m_pDataAcc.Get(); - m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_Full, &eParam); -} - -bool CXFA_FFTextEdit::CheckWord(const CFX_ByteStringC& sWord) { - if (sWord.IsEmpty() || m_pDataAcc->GetUIType() != XFA_Element::TextEdit) - return true; - return false; -} - -void CXFA_FFTextEdit::OnProcessMessage(CFWL_Message* pMessage) { - m_pOldDelegate->OnProcessMessage(pMessage); -} - -void CXFA_FFTextEdit::OnProcessEvent(CFWL_Event* pEvent) { - CXFA_FFField::OnProcessEvent(pEvent); - switch (pEvent->GetType()) { - case CFWL_Event::Type::TextChanged: { - CFWL_EventTextChanged* event = - static_cast<CFWL_EventTextChanged*>(pEvent); - CFX_WideString wsChange; - OnTextChanged(m_pNormalWidget.get(), wsChange, event->wsPrevText); - break; - } - case CFWL_Event::Type::TextFull: { - OnTextFull(m_pNormalWidget.get()); - break; - } - case CFWL_Event::Type::CheckWord: { - CFX_WideString wstr(L"FWL_EVENT_DTP_SelectChanged"); - CFWL_EventCheckWord* event = static_cast<CFWL_EventCheckWord*>(pEvent); - event->bCheckWord = CheckWord(event->bsWord.AsStringC()); - break; - } - default: - break; - } - m_pOldDelegate->OnProcessEvent(pEvent); -} - -void CXFA_FFTextEdit::OnDrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) { - m_pOldDelegate->OnDrawWidget(pGraphics, pMatrix); -} - -CXFA_FFNumericEdit::CXFA_FFNumericEdit(CXFA_WidgetAcc* pDataAcc) - : CXFA_FFTextEdit(pDataAcc) {} - -CXFA_FFNumericEdit::~CXFA_FFNumericEdit() {} - -bool CXFA_FFNumericEdit::LoadWidget() { - auto pNewEdit = pdfium::MakeUnique<CFWL_Edit>( - GetFWLApp(), pdfium::MakeUnique<CFWL_WidgetProperties>(), nullptr); - CFWL_Edit* pWidget = pNewEdit.get(); - m_pNormalWidget = std::move(pNewEdit); - m_pNormalWidget->SetLayoutItem(this); - - CFWL_NoteDriver* pNoteDriver = - m_pNormalWidget->GetOwnerApp()->GetNoteDriver(); - pNoteDriver->RegisterEventTarget(m_pNormalWidget.get(), - m_pNormalWidget.get()); - m_pOldDelegate = m_pNormalWidget->GetDelegate(); - m_pNormalWidget->SetDelegate(this); - m_pNormalWidget->LockUpdate(); - - CFX_WideString wsText; - m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Display); - pWidget->SetText(wsText); - UpdateWidgetProperty(); - m_pNormalWidget->UnlockUpdate(); - return CXFA_FFField::LoadWidget(); -} - -void CXFA_FFNumericEdit::UpdateWidgetProperty() { - CFWL_Edit* pWidget = static_cast<CFWL_Edit*>(m_pNormalWidget.get()); - if (!pWidget) - return; - - uint32_t dwExtendedStyle = - FWL_STYLEEXT_EDT_ShowScrollbarFocus | FWL_STYLEEXT_EDT_OuterScrollbar | - FWL_STYLEEXT_EDT_Validate | FWL_STYLEEXT_EDT_Number | - FWL_STYLEEXT_EDT_LastLineHeight; - dwExtendedStyle |= UpdateUIProperty(); - if (m_pDataAcc->GetHorizontalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) - dwExtendedStyle |= FWL_STYLEEXT_EDT_AutoHScroll; - - int32_t iNumCells = m_pDataAcc->GetNumberOfCells(); - if (iNumCells > 0) { - dwExtendedStyle |= FWL_STYLEEXT_EDT_CombText; - pWidget->SetLimit(iNumCells); - } - dwExtendedStyle |= GetAlignment(); - if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open || - !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) { - dwExtendedStyle |= FWL_STYLEEXT_EDT_ReadOnly; - } - m_pNormalWidget->ModifyStylesEx(dwExtendedStyle, 0xFFFFFFFF); -} - -void CXFA_FFNumericEdit::OnProcessEvent(CFWL_Event* pEvent) { - if (pEvent->GetType() == CFWL_Event::Type::Validate) { - CFWL_EventValidate* event = static_cast<CFWL_EventValidate*>(pEvent); - event->bValidate = OnValidate(m_pNormalWidget.get(), event->wsInsert); - return; - } - CXFA_FFTextEdit::OnProcessEvent(pEvent); -} - -bool CXFA_FFNumericEdit::OnValidate(CFWL_Widget* pWidget, - CFX_WideString& wsText) { - CFX_WideString wsPattern; - m_pDataAcc->GetPictureContent(wsPattern, XFA_VALUEPICTURE_Edit); - if (!wsPattern.IsEmpty()) - return true; - - int32_t iLeads = 0; - m_pDataAcc->GetLeadDigits(iLeads); - - int32_t iFracs = 0; - m_pDataAcc->GetFracDigits(iFracs); - - CFX_WideString wsFormat; - CXFA_LocaleValue widgetValue = XFA_GetLocaleValue(m_pDataAcc.Get()); - widgetValue.GetNumbericFormat(wsFormat, iLeads, iFracs); - return widgetValue.ValidateNumericTemp(wsText, wsFormat, - m_pDataAcc->GetLocal()); -} - -CXFA_FFPasswordEdit::CXFA_FFPasswordEdit(CXFA_WidgetAcc* pDataAcc) - : CXFA_FFTextEdit(pDataAcc) {} - -CXFA_FFPasswordEdit::~CXFA_FFPasswordEdit() {} - -bool CXFA_FFPasswordEdit::LoadWidget() { - auto pNewEdit = pdfium::MakeUnique<CFWL_Edit>( - GetFWLApp(), pdfium::MakeUnique<CFWL_WidgetProperties>(), nullptr); - CFWL_Edit* pWidget = pNewEdit.get(); - m_pNormalWidget = std::move(pNewEdit); - m_pNormalWidget->SetLayoutItem(this); - - CFWL_NoteDriver* pNoteDriver = - m_pNormalWidget->GetOwnerApp()->GetNoteDriver(); - pNoteDriver->RegisterEventTarget(m_pNormalWidget.get(), - m_pNormalWidget.get()); - m_pOldDelegate = m_pNormalWidget->GetDelegate(); - m_pNormalWidget->SetDelegate(this); - m_pNormalWidget->LockUpdate(); - - CFX_WideString wsText; - m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Display); - pWidget->SetText(wsText); - UpdateWidgetProperty(); - m_pNormalWidget->UnlockUpdate(); - return CXFA_FFField::LoadWidget(); -} - -void CXFA_FFPasswordEdit::UpdateWidgetProperty() { - CFWL_Edit* pWidget = static_cast<CFWL_Edit*>(m_pNormalWidget.get()); - if (!pWidget) - return; - - uint32_t dwExtendedStyle = - FWL_STYLEEXT_EDT_ShowScrollbarFocus | FWL_STYLEEXT_EDT_OuterScrollbar | - FWL_STYLEEXT_EDT_Password | FWL_STYLEEXT_EDT_LastLineHeight; - dwExtendedStyle |= UpdateUIProperty(); - - CFX_WideString wsPassWord; - m_pDataAcc->GetPasswordChar(wsPassWord); - if (!wsPassWord.IsEmpty()) - pWidget->SetAliasChar(wsPassWord.GetAt(0)); - if (m_pDataAcc->GetHorizontalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) - dwExtendedStyle |= FWL_STYLEEXT_EDT_AutoHScroll; - if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open || - !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) { - dwExtendedStyle |= FWL_STYLEEXT_EDT_ReadOnly; - } - dwExtendedStyle |= GetAlignment(); - m_pNormalWidget->ModifyStylesEx(dwExtendedStyle, 0xFFFFFFFF); -} - -CXFA_FFDateTimeEdit::CXFA_FFDateTimeEdit(CXFA_WidgetAcc* pDataAcc) - : CXFA_FFTextEdit(pDataAcc) {} - -CXFA_FFDateTimeEdit::~CXFA_FFDateTimeEdit() {} - -CFX_RectF CXFA_FFDateTimeEdit::GetBBox(uint32_t dwStatus, bool bDrawFocus) { - if (bDrawFocus) - return CFX_RectF(); - return CXFA_FFWidget::GetBBox(dwStatus); -} - -bool CXFA_FFDateTimeEdit::PtInActiveRect(const CFX_PointF& point) { - auto* pPicker = static_cast<CFWL_DateTimePicker*>(m_pNormalWidget.get()); - return pPicker && pPicker->GetBBox().Contains(point); -} - -bool CXFA_FFDateTimeEdit::LoadWidget() { - auto pNewPicker = pdfium::MakeUnique<CFWL_DateTimePicker>(GetFWLApp()); - CFWL_DateTimePicker* pWidget = pNewPicker.get(); - m_pNormalWidget = std::move(pNewPicker); - m_pNormalWidget->SetLayoutItem(this); - - CFWL_NoteDriver* pNoteDriver = - m_pNormalWidget->GetOwnerApp()->GetNoteDriver(); - pNoteDriver->RegisterEventTarget(m_pNormalWidget.get(), - m_pNormalWidget.get()); - m_pOldDelegate = m_pNormalWidget->GetDelegate(); - m_pNormalWidget->SetDelegate(this); - m_pNormalWidget->LockUpdate(); - - CFX_WideString wsText; - m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Display); - pWidget->SetEditText(wsText); - if (CXFA_Value value = m_pDataAcc->GetFormValue()) { - switch (value.GetChildValueClassID()) { - case XFA_Element::Date: { - if (!wsText.IsEmpty()) { - CXFA_LocaleValue lcValue = XFA_GetLocaleValue(m_pDataAcc.Get()); - CFX_DateTime date = lcValue.GetDate(); - if (date.IsSet()) - pWidget->SetCurSel(date.GetYear(), date.GetMonth(), date.GetDay()); - } - } break; - default: - break; - } - } - UpdateWidgetProperty(); - m_pNormalWidget->UnlockUpdate(); - return CXFA_FFField::LoadWidget(); -} - -void CXFA_FFDateTimeEdit::UpdateWidgetProperty() { - CFWL_DateTimePicker* pWidget = - static_cast<CFWL_DateTimePicker*>(m_pNormalWidget.get()); - if (!pWidget) - return; - - uint32_t dwExtendedStyle = FWL_STYLEEXT_DTP_ShortDateFormat; - dwExtendedStyle |= UpdateUIProperty(); - dwExtendedStyle |= GetAlignment(); - m_pNormalWidget->ModifyStylesEx(dwExtendedStyle, 0xFFFFFFFF); - uint32_t dwEditStyles = FWL_STYLEEXT_EDT_LastLineHeight; - int32_t iNumCells = m_pDataAcc->GetNumberOfCells(); - if (iNumCells > 0) { - dwEditStyles |= FWL_STYLEEXT_EDT_CombText; - pWidget->SetEditLimit(iNumCells); - } - if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open || - !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) { - dwEditStyles |= FWL_STYLEEXT_EDT_ReadOnly; - } - if (m_pDataAcc->GetHorizontalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) - dwEditStyles |= FWL_STYLEEXT_EDT_AutoHScroll; - - pWidget->ModifyEditStylesEx(dwEditStyles, 0xFFFFFFFF); -} - -uint32_t CXFA_FFDateTimeEdit::GetAlignment() { - CXFA_Para para = m_pDataAcc->GetPara(); - if (!para) - return 0; - - uint32_t dwExtendedStyle = 0; - switch (para.GetHorizontalAlign()) { - case XFA_ATTRIBUTEENUM_Center: - dwExtendedStyle |= FWL_STYLEEXT_DTP_EditHCenter; - break; - case XFA_ATTRIBUTEENUM_Justify: - dwExtendedStyle |= FWL_STYLEEXT_DTP_EditJustified; - break; - case XFA_ATTRIBUTEENUM_JustifyAll: - case XFA_ATTRIBUTEENUM_Radix: - break; - case XFA_ATTRIBUTEENUM_Right: - dwExtendedStyle |= FWL_STYLEEXT_DTP_EditHFar; - break; - default: - dwExtendedStyle |= FWL_STYLEEXT_DTP_EditHNear; - break; - } - - switch (para.GetVerticalAlign()) { - case XFA_ATTRIBUTEENUM_Middle: - dwExtendedStyle |= FWL_STYLEEXT_DTP_EditVCenter; - break; - case XFA_ATTRIBUTEENUM_Bottom: - dwExtendedStyle |= FWL_STYLEEXT_DTP_EditVFar; - break; - default: - dwExtendedStyle |= FWL_STYLEEXT_DTP_EditVNear; - break; - } - return dwExtendedStyle; -} - -bool CXFA_FFDateTimeEdit::CommitData() { - auto* pPicker = static_cast<CFWL_DateTimePicker*>(m_pNormalWidget.get()); - if (!m_pDataAcc->SetValue(pPicker->GetEditText(), XFA_VALUEPICTURE_Edit)) - return false; - - m_pDataAcc->UpdateUIDisplay(this); - return true; -} - -bool CXFA_FFDateTimeEdit::UpdateFWLData() { - if (!m_pNormalWidget) - return false; - - XFA_VALUEPICTURE eType = XFA_VALUEPICTURE_Display; - if (IsFocused()) - eType = XFA_VALUEPICTURE_Edit; - - CFX_WideString wsText; - m_pDataAcc->GetValue(wsText, eType); - - auto* normalWidget = static_cast<CFWL_DateTimePicker*>(m_pNormalWidget.get()); - normalWidget->SetEditText(wsText); - if (IsFocused() && !wsText.IsEmpty()) { - CXFA_LocaleValue lcValue = XFA_GetLocaleValue(m_pDataAcc.Get()); - CFX_DateTime date = lcValue.GetDate(); - if (lcValue.IsValid()) { - if (date.IsSet()) - normalWidget->SetCurSel(date.GetYear(), date.GetMonth(), date.GetDay()); - } - } - m_pNormalWidget->Update(); - return true; -} - -bool CXFA_FFDateTimeEdit::IsDataChanged() { - if (m_dwStatus & XFA_WidgetStatus_TextEditValueChanged) - return true; - - CFX_WideString wsText = - static_cast<CFWL_DateTimePicker*>(m_pNormalWidget.get())->GetEditText(); - CFX_WideString wsOldValue; - m_pDataAcc->GetValue(wsOldValue, XFA_VALUEPICTURE_Edit); - return wsOldValue != wsText; -} - -void CXFA_FFDateTimeEdit::OnSelectChanged(CFWL_Widget* pWidget, - int32_t iYear, - int32_t iMonth, - int32_t iDay) { - CFX_WideString wsPicture; - m_pDataAcc->GetPictureContent(wsPicture, XFA_VALUEPICTURE_Edit); - - CXFA_LocaleValue date(XFA_VT_DATE, GetDoc()->GetXFADoc()->GetLocalMgr()); - date.SetDate(CFX_DateTime(iYear, iMonth, iDay, 0, 0, 0, 0)); - - CFX_WideString wsDate; - date.FormatPatterns(wsDate, wsPicture, m_pDataAcc->GetLocal(), - XFA_VALUEPICTURE_Edit); - - auto* pDateTime = static_cast<CFWL_DateTimePicker*>(m_pNormalWidget.get()); - pDateTime->SetEditText(wsDate); - pDateTime->Update(); - GetDoc()->GetDocEnvironment()->SetFocusWidget(GetDoc(), nullptr); - - CXFA_EventParam eParam; - eParam.m_eType = XFA_EVENT_Change; - eParam.m_pTarget = m_pDataAcc.Get(); - m_pDataAcc->GetValue(eParam.m_wsNewText, XFA_VALUEPICTURE_Raw); - m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_Change, &eParam); -} - -void CXFA_FFDateTimeEdit::OnProcessEvent(CFWL_Event* pEvent) { - if (pEvent->GetType() == CFWL_Event::Type::SelectChanged) { - auto* event = static_cast<CFWL_EventSelectChanged*>(pEvent); - OnSelectChanged(m_pNormalWidget.get(), event->iYear, event->iMonth, - event->iDay); - return; - } - CXFA_FFTextEdit::OnProcessEvent(pEvent); -} diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fftextedit.h b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fftextedit.h deleted file mode 100644 index 9b9324f9d21..00000000000 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fftextedit.h +++ /dev/null @@ -1,105 +0,0 @@ -// Copyright 2014 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 - -#ifndef XFA_FXFA_APP_XFA_FFTEXTEDIT_H_ -#define XFA_FXFA_APP_XFA_FFTEXTEDIT_H_ - -#include <vector> - -#include "xfa/fxfa/app/xfa_fffield.h" - -class CXFA_FFTextEdit : public CXFA_FFField { - public: - explicit CXFA_FFTextEdit(CXFA_WidgetAcc* pDataAcc); - ~CXFA_FFTextEdit() override; - - // CXFA_FFField - bool LoadWidget() override; - void UpdateWidgetProperty() override; - bool OnLButtonDown(uint32_t dwFlags, const CFX_PointF& point) override; - bool OnRButtonDown(uint32_t dwFlags, const CFX_PointF& point) override; - bool OnRButtonUp(uint32_t dwFlags, const CFX_PointF& point) override; - bool OnSetFocus(CXFA_FFWidget* pOldWidget) override; - bool OnKillFocus(CXFA_FFWidget* pNewWidget) override; - void OnProcessMessage(CFWL_Message* pMessage) override; - void OnProcessEvent(CFWL_Event* pEvent) override; - void OnDrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix = nullptr) override; - - void OnTextChanged(CFWL_Widget* pWidget, - const CFX_WideString& wsChanged, - const CFX_WideString& wsPrevText); - void OnTextFull(CFWL_Widget* pWidget); - bool CheckWord(const CFX_ByteStringC& sWord); - - protected: - uint32_t GetAlignment(); - - IFWL_WidgetDelegate* m_pOldDelegate; - - private: - bool CommitData() override; - bool UpdateFWLData() override; - bool IsDataChanged() override; - void ValidateNumberField(const CFX_WideString& wsText); -}; - -class CXFA_FFNumericEdit : public CXFA_FFTextEdit { - public: - explicit CXFA_FFNumericEdit(CXFA_WidgetAcc* pDataAcc); - ~CXFA_FFNumericEdit() override; - - // CXFA_FFTextEdit - bool LoadWidget() override; - void UpdateWidgetProperty() override; - void OnProcessEvent(CFWL_Event* pEvent) override; - - private: - bool OnValidate(CFWL_Widget* pWidget, CFX_WideString& wsText); -}; - -class CXFA_FFPasswordEdit : public CXFA_FFTextEdit { - public: - explicit CXFA_FFPasswordEdit(CXFA_WidgetAcc* pDataAcc); - ~CXFA_FFPasswordEdit() override; - - // CXFA_FFTextEdit - bool LoadWidget() override; - void UpdateWidgetProperty() override; -}; - -enum XFA_DATETIMETYPE { - XFA_DATETIMETYPE_Date = 0, - XFA_DATETIMETYPE_Time, - XFA_DATETIMETYPE_DateAndTime -}; - -class CXFA_FFDateTimeEdit : public CXFA_FFTextEdit { - public: - explicit CXFA_FFDateTimeEdit(CXFA_WidgetAcc* pDataAcc); - ~CXFA_FFDateTimeEdit() override; - - // CXFA_FFTextEdit - CFX_RectF GetBBox(uint32_t dwStatus, bool bDrawFocus = false) override; - bool LoadWidget() override; - void UpdateWidgetProperty() override; - void OnProcessEvent(CFWL_Event* pEvent) override; - - void OnSelectChanged(CFWL_Widget* pWidget, - int32_t iYear, - int32_t iMonth, - int32_t iDay); - - private: - bool PtInActiveRect(const CFX_PointF& point) override; - bool CommitData() override; - bool UpdateFWLData() override; - bool IsDataChanged() override; - - uint32_t GetAlignment(); -}; - -#endif // XFA_FXFA_APP_XFA_FFTEXTEDIT_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffapp.cpp b/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffapp.cpp index 7b97116c7af..cb308f2c46c 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffapp.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffapp.cpp @@ -16,8 +16,8 @@ #include "xfa/fgas/font/cfgas_fontmgr.h" #include "xfa/fwl/cfwl_notedriver.h" #include "xfa/fwl/cfwl_widgetmgr.h" -#include "xfa/fxfa/app/xfa_fwladapter.h" -#include "xfa/fxfa/app/xfa_fwltheme.h" +#include "xfa/fxfa/app/cxfa_fwladapterwidgetmgr.h" +#include "xfa/fxfa/app/cxfa_fwltheme.h" #include "xfa/fxfa/cxfa_ffdoc.h" #include "xfa/fxfa/cxfa_ffdochandler.h" #include "xfa/fxfa/cxfa_ffwidgethandler.h" diff --git a/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffdoc.cpp b/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffdoc.cpp index bde40ce11fe..326fc7f228d 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffdoc.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffdoc.cpp @@ -22,7 +22,7 @@ #include "core/fxcrt/xml/cfx_xmlnode.h" #include "third_party/base/ptr_util.h" #include "xfa/fwl/cfwl_notedriver.h" -#include "xfa/fxfa/app/xfa_ffnotify.h" +#include "xfa/fxfa/app/cxfa_ffnotify.h" #include "xfa/fxfa/cxfa_ffapp.h" #include "xfa/fxfa/cxfa_ffdocview.h" #include "xfa/fxfa/cxfa_ffwidget.h" @@ -365,13 +365,12 @@ CFX_RetainPtr<CFX_DIBitmap> CXFA_FFDoc::GetPDFNamedImage( return nullptr; CPDF_NameTree nametree(pXFAImages); - CFX_ByteString bsName = PDF_EncodeText(wsName.c_str(), wsName.GetLength()); - CPDF_Object* pObject = nametree.LookupValue(bsName); + CPDF_Object* pObject = nametree.LookupValue(CFX_WideString(wsName)); if (!pObject) { for (size_t i = 0; i < nametree.GetCount(); i++) { - CFX_ByteString bsTemp; - CPDF_Object* pTempObject = nametree.LookupValueAndName(i, &bsTemp); - if (bsTemp == bsName) { + CFX_WideString wsTemp; + CPDF_Object* pTempObject = nametree.LookupValueAndName(i, &wsTemp); + if (wsTemp == wsName) { pObject = pTempObject; break; } diff --git a/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffdocview.cpp b/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffdocview.cpp index d9c97f71b16..03a692be836 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffdocview.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffdocview.cpp @@ -9,22 +9,19 @@ #include "core/fxcrt/fx_extension.h" #include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" -#include "xfa/fxfa/app/xfa_ffbarcode.h" -#include "xfa/fxfa/app/xfa_ffcheckbutton.h" -#include "xfa/fxfa/app/xfa_ffchoicelist.h" -#include "xfa/fxfa/app/xfa_ffdraw.h" -#include "xfa/fxfa/app/xfa_ffexclgroup.h" -#include "xfa/fxfa/app/xfa_fffield.h" -#include "xfa/fxfa/app/xfa_ffimage.h" -#include "xfa/fxfa/app/xfa_ffimageedit.h" -#include "xfa/fxfa/app/xfa_ffpath.h" -#include "xfa/fxfa/app/xfa_ffpushbutton.h" -#include "xfa/fxfa/app/xfa_ffsignature.h" -#include "xfa/fxfa/app/xfa_ffsubform.h" -#include "xfa/fxfa/app/xfa_fftext.h" -#include "xfa/fxfa/app/xfa_fftextedit.h" -#include "xfa/fxfa/app/xfa_ffwidgetacc.h" -#include "xfa/fxfa/app/xfa_fwladapter.h" +#include "xfa/fxfa/app/cxfa_ffbarcode.h" +#include "xfa/fxfa/app/cxfa_ffcheckbutton.h" +#include "xfa/fxfa/app/cxfa_ffdraw.h" +#include "xfa/fxfa/app/cxfa_ffexclgroup.h" +#include "xfa/fxfa/app/cxfa_fffield.h" +#include "xfa/fxfa/app/cxfa_ffimage.h" +#include "xfa/fxfa/app/cxfa_ffimageedit.h" +#include "xfa/fxfa/app/cxfa_ffpushbutton.h" +#include "xfa/fxfa/app/cxfa_ffsignature.h" +#include "xfa/fxfa/app/cxfa_ffsubform.h" +#include "xfa/fxfa/app/cxfa_fftext.h" +#include "xfa/fxfa/app/cxfa_fwladapterwidgetmgr.h" +#include "xfa/fxfa/app/cxfa_textprovider.h" #include "xfa/fxfa/cxfa_ffapp.h" #include "xfa/fxfa/cxfa_ffdoc.h" #include "xfa/fxfa/cxfa_ffpageview.h" @@ -199,28 +196,26 @@ void CXFA_FFDocView::UpdateDocView() { UnlockUpdate(); } -int32_t CXFA_FFDocView::CountPageViews() { - if (!m_pXFADocLayout) { - return 0; - } - return m_pXFADocLayout->CountPages(); +int32_t CXFA_FFDocView::CountPageViews() const { + return m_pXFADocLayout ? m_pXFADocLayout->CountPages() : 0; } -CXFA_FFPageView* CXFA_FFDocView::GetPageView(int32_t nIndex) { - if (!m_pXFADocLayout) { + +CXFA_FFPageView* CXFA_FFDocView::GetPageView(int32_t nIndex) const { + if (!m_pXFADocLayout) return nullptr; - } return static_cast<CXFA_FFPageView*>(m_pXFADocLayout->GetPage(nIndex)); } CXFA_LayoutProcessor* CXFA_FFDocView::GetXFALayout() const { return m_pDoc->GetXFADoc()->GetDocLayout(); } + bool CXFA_FFDocView::ResetSingleWidgetAccData(CXFA_WidgetAcc* pWidgetAcc) { CXFA_Node* pNode = pWidgetAcc->GetNode(); XFA_Element eType = pNode->GetElementType(); - if (eType != XFA_Element::Field && eType != XFA_Element::ExclGroup) { + if (eType != XFA_Element::Field && eType != XFA_Element::ExclGroup) return false; - } + pWidgetAcc->ResetData(); pWidgetAcc->UpdateUIDisplay(); if (CXFA_Validate validate = pWidgetAcc->GetValidate(false)) { @@ -229,6 +224,7 @@ bool CXFA_FFDocView::ResetSingleWidgetAccData(CXFA_WidgetAcc* pWidgetAcc) { } return true; } + void CXFA_FFDocView::ResetWidgetData(CXFA_WidgetAcc* pWidgetAcc) { m_bLayoutEvent = true; bool bChanged = false; @@ -239,9 +235,9 @@ void CXFA_FFDocView::ResetWidgetData(CXFA_WidgetAcc* pWidgetAcc) { } else { pFormNode = GetRootSubform(); } - if (!pFormNode) { + if (!pFormNode) return; - } + if (pFormNode->GetElementType() != XFA_Element::Field && pFormNode->GetElementType() != XFA_Element::ExclGroup) { CXFA_WidgetAccIterator Iterator(pFormNode); @@ -256,6 +252,7 @@ void CXFA_FFDocView::ResetWidgetData(CXFA_WidgetAcc* pWidgetAcc) { m_pDoc->GetDocEnvironment()->SetChangeMark(m_pDoc.Get()); } } + int32_t CXFA_FFDocView::ProcessWidgetEvent(CXFA_EventParam* pParam, CXFA_WidgetAcc* pWidgetAcc) { if (!pParam) @@ -303,7 +300,6 @@ int32_t CXFA_FFDocView::ProcessWidgetEvent(CXFA_EventParam* pParam, CXFA_FFWidgetHandler* CXFA_FFDocView::GetWidgetHandler() { if (!m_pWidgetHandler) m_pWidgetHandler = pdfium::MakeUnique<CXFA_FFWidgetHandler>(this); - return m_pWidgetHandler.get(); } @@ -322,7 +318,7 @@ CXFA_FFWidget* CXFA_FFDocView::GetFocusWidget() const { void CXFA_FFDocView::KillFocus() { if (m_pFocusWidget && (m_pFocusWidget->GetStatus() & XFA_WidgetStatus_Focused)) { - (m_pFocusWidget)->OnKillFocus(nullptr); + m_pFocusWidget->OnKillFocus(nullptr); } m_pFocusAcc = nullptr; m_pFocusWidget = nullptr; @@ -432,6 +428,7 @@ static int32_t XFA_ProcessEvent(CXFA_FFDocView* pDocView, pWidgetAcc->ProcessEvent(gs_EventActivity[pParam->m_eType], pParam); return iRet; } + int32_t CXFA_FFDocView::ExecEventActivityByDeepFirst(CXFA_Node* pFormNode, XFA_EVENTTYPE eEventType, bool bIsFormReady, @@ -495,9 +492,9 @@ CXFA_WidgetAcc* CXFA_FFDocView::GetWidgetAccByName( uint32_t dwStyle = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_Parent; CXFA_ScriptContext* pScriptContext = m_pDoc->GetXFADoc()->GetScriptContext(); - if (!pScriptContext) { + if (!pScriptContext) return nullptr; - } + CXFA_Node* refNode = nullptr; if (pRefWidgetAcc) { refNode = pRefWidgetAcc->GetNode(); @@ -508,9 +505,9 @@ CXFA_WidgetAcc* CXFA_FFDocView::GetWidgetAccByName( XFA_RESOLVENODE_RS resoveNodeRS; int32_t iRet = pScriptContext->ResolveObjects( refNode, wsExpression.AsStringC(), resoveNodeRS, dwStyle); - if (iRet < 1) { + if (iRet < 1) return nullptr; - } + if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) { CXFA_Node* pNode = resoveNodeRS.objects.front()->AsNode(); if (pNode) @@ -528,15 +525,19 @@ void CXFA_FFDocView::OnPageEvent(CXFA_ContainerLayoutItem* pSender, void CXFA_FFDocView::LockUpdate() { m_iLock++; } + void CXFA_FFDocView::UnlockUpdate() { m_iLock--; } + bool CXFA_FFDocView::IsUpdateLocked() { return m_iLock > 0; } + void CXFA_FFDocView::ClearInvalidateList() { m_mapPageInvalidate.clear(); } + void CXFA_FFDocView::AddInvalidateRect(CXFA_FFWidget* pWidget, const CFX_RectF& rtInvalidate) { AddInvalidateRect(pWidget->GetPageView(), rtInvalidate); @@ -643,34 +644,32 @@ void CXFA_FFDocView::AddCalculateNodeNotify(CXFA_Node* pNodeChange) { } } -void CXFA_FFDocView::RunCalculateRecursive(int32_t& iIndex) { - while (iIndex < pdfium::CollectionSize<int32_t>(m_CalculateAccs)) { - CXFA_WidgetAcc* pCurAcc = m_CalculateAccs[iIndex]; +size_t CXFA_FFDocView::RunCalculateRecursive(size_t index) { + while (index < m_CalculateAccs.size()) { + CXFA_WidgetAcc* pCurAcc = m_CalculateAccs[index]; AddCalculateNodeNotify(pCurAcc->GetNode()); int32_t iRefCount = (int32_t)(uintptr_t)pCurAcc->GetNode()->GetUserData(XFA_CalcRefCount); iRefCount++; pCurAcc->GetNode()->SetUserData(XFA_CalcRefCount, (void*)(uintptr_t)iRefCount); - if (iRefCount > 11) { + if (iRefCount > 11) break; - } - if ((pCurAcc->ProcessCalculate()) == XFA_EVENTERROR_Success) { + + if (pCurAcc->ProcessCalculate() == XFA_EVENTERROR_Success) AddValidateWidget(pCurAcc); - } - iIndex++; - RunCalculateRecursive(iIndex); + + index = RunCalculateRecursive(++index); } + return index; } int32_t CXFA_FFDocView::RunCalculateWidgets() { - if (!m_pDoc->GetDocEnvironment()->IsCalculationsEnabled(m_pDoc.Get())) { + if (!m_pDoc->GetDocEnvironment()->IsCalculationsEnabled(m_pDoc.Get())) return XFA_EVENTERROR_Disabled; - } - int32_t iCounts = pdfium::CollectionSize<int32_t>(m_CalculateAccs); - int32_t iIndex = 0; - if (iCounts > 0) - RunCalculateRecursive(iIndex); + + if (!m_CalculateAccs.empty()) + RunCalculateRecursive(0); for (CXFA_WidgetAcc* pCurAcc : m_CalculateAccs) pCurAcc->GetNode()->SetUserData(XFA_CalcRefCount, (void*)(uintptr_t)0); diff --git a/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffdocview.h b/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffdocview.h index 3164bcfb6af..314ce293934 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffdocview.h +++ b/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffdocview.h @@ -49,8 +49,8 @@ class CXFA_FFDocView { void StopLayout(); int32_t GetLayoutStatus(); void UpdateDocView(); - int32_t CountPageViews(); - CXFA_FFPageView* GetPageView(int32_t nIndex); + int32_t CountPageViews() const; + CXFA_FFPageView* GetPageView(int32_t nIndex) const; void ResetWidgetData(CXFA_WidgetAcc* pWidgetAcc); int32_t ProcessWidgetEvent(CXFA_EventParam* pParam, @@ -111,7 +111,7 @@ class CXFA_FFDocView { void RunBindItems(); bool InitCalculate(CXFA_Node* pNode); void InitLayout(CXFA_Node* pNode); - void RunCalculateRecursive(int32_t& iIndex); + size_t RunCalculateRecursive(size_t index); void ShowNullTestMsg(); bool ResetSingleWidgetAccData(CXFA_WidgetAcc* pWidgetAcc); CXFA_Node* GetRootSubform(); diff --git a/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffpageview.cpp b/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffpageview.cpp index c83ffaea7ef..841318672f0 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffpageview.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffpageview.cpp @@ -13,13 +13,11 @@ #include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" #include "xfa/fde/cfde_rendercontext.h" -#include "xfa/fxfa/app/xfa_ffcheckbutton.h" -#include "xfa/fxfa/app/xfa_ffchoicelist.h" -#include "xfa/fxfa/app/xfa_fffield.h" -#include "xfa/fxfa/app/xfa_ffimageedit.h" -#include "xfa/fxfa/app/xfa_ffpushbutton.h" -#include "xfa/fxfa/app/xfa_fftextedit.h" -#include "xfa/fxfa/app/xfa_fwladapter.h" +#include "xfa/fxfa/app/cxfa_ffcheckbutton.h" +#include "xfa/fxfa/app/cxfa_fffield.h" +#include "xfa/fxfa/app/cxfa_ffimageedit.h" +#include "xfa/fxfa/app/cxfa_ffpushbutton.h" +#include "xfa/fxfa/app/cxfa_fwladapterwidgetmgr.h" #include "xfa/fxfa/cxfa_ffdoc.h" #include "xfa/fxfa/cxfa_ffdocview.h" #include "xfa/fxfa/cxfa_ffwidget.h" diff --git a/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffwidget.cpp b/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffwidget.cpp index 9de99255abd..2573ff4f6bc 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffwidget.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffwidget.cpp @@ -30,11 +30,11 @@ #include "xfa/fxfa/cxfa_widgetacc.h" #include "xfa/fxfa/parser/cxfa_corner.h" #include "xfa/fxfa/parser/cxfa_node.h" -#include "xfa/fxgraphics/cfx_color.h" -#include "xfa/fxgraphics/cfx_graphics.h" -#include "xfa/fxgraphics/cfx_path.h" -#include "xfa/fxgraphics/cfx_pattern.h" -#include "xfa/fxgraphics/cfx_shading.h" +#include "xfa/fxgraphics/cxfa_color.h" +#include "xfa/fxgraphics/cxfa_graphics.h" +#include "xfa/fxgraphics/cxfa_path.h" +#include "xfa/fxgraphics/cxfa_pattern.h" +#include "xfa/fxgraphics/cxfa_shading.h" CXFA_FFWidget::CXFA_FFWidget(CXFA_WidgetAcc* pDataAcc) : CXFA_ContentLayoutItem(pDataAcc->GetNode()), @@ -110,7 +110,7 @@ bool CXFA_FFWidget::GetToolTip(CFX_WideString& wsToolTip) { return GetCaptionText(wsToolTip); } -void CXFA_FFWidget::RenderWidget(CFX_Graphics* pGS, +void CXFA_FFWidget::RenderWidget(CXFA_Graphics* pGS, CFX_Matrix* pMatrix, uint32_t dwStatus) { if (!IsMatchVisibleStatus(dwStatus)) @@ -145,7 +145,7 @@ bool CXFA_FFWidget::UpdateFWLData() { return false; } void CXFA_FFWidget::UpdateWidgetProperty() {} -void CXFA_FFWidget::DrawBorder(CFX_Graphics* pGS, +void CXFA_FFWidget::DrawBorder(CXFA_Graphics* pGS, CXFA_Box box, const CFX_RectF& rtBorder, CFX_Matrix* pMatrix, @@ -184,10 +184,6 @@ bool CXFA_FFWidget::GetCaptionText(CFX_WideString& wsCap) { return true; } -bool CXFA_FFWidget::IsFocused() { - return !!(m_dwStatus & XFA_WidgetStatus_Focused); -} - bool CXFA_FFWidget::OnMouseEnter() { return false; } @@ -348,9 +344,7 @@ CFX_PointF CXFA_FFWidget::Rotate2Normal(const CFX_PointF& point) { if (mt.IsIdentity()) return point; - CFX_Matrix mtReverse; - mtReverse.SetReverse(mt); - return mtReverse.Transform(point); + return mt.GetInverse().Transform(point); } static void XFA_GetMatrix(CFX_Matrix& m, @@ -500,7 +494,7 @@ void CXFA_FFWidget::SetButtonDown(bool bSet) { bSet ? m_dwStatus |= XFA_WidgetStatus_ButtonDown : m_dwStatus &= ~XFA_WidgetStatus_ButtonDown; } -int32_t XFA_StrokeTypeSetLineDash(CFX_Graphics* pGraphics, +int32_t XFA_StrokeTypeSetLineDash(CXFA_Graphics* pGraphics, int32_t iStrokeType, int32_t iCapType) { switch (iStrokeType) { @@ -662,15 +656,12 @@ bool CXFA_ImageRenderer::StartDIBSource() { m_Status = 2; m_pTransformer = pdfium::MakeUnique<CFX_ImageTransformer>( pDib, &m_ImageMatrix, m_Flags, &clip_box); - m_pTransformer->Start(); return true; } - if (m_ImageMatrix.a < 0) { + if (m_ImageMatrix.a < 0) dest_width = -dest_width; - } - if (m_ImageMatrix.d > 0) { + if (m_ImageMatrix.d > 0) dest_height = -dest_height; - } int dest_left, dest_top; dest_left = dest_width > 0 ? image_rect.left : image_rect.right; dest_top = dest_height > 0 ? image_rect.top : image_rect.bottom; @@ -833,7 +824,7 @@ void CXFA_ImageRenderer::CompositeDIBitmap( continue; } -void XFA_DrawImage(CFX_Graphics* pGS, +void XFA_DrawImage(CXFA_Graphics* pGS, const CFX_RectF& rtImage, CFX_Matrix* pMatrix, const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap, @@ -1186,7 +1177,7 @@ bool XFA_IsCreateWidget(XFA_Element eType) { } static void XFA_BOX_GetPath_Arc(CXFA_Box box, CFX_RectF rtDraw, - CFX_Path& fillPath, + CXFA_Path& fillPath, uint32_t dwFlags) { float a, b; a = rtDraw.width / 2.0f; @@ -1214,7 +1205,7 @@ static void XFA_BOX_GetPath_Arc(CXFA_Box box, static void XFA_BOX_GetPath(CXFA_Box box, const std::vector<CXFA_Stroke>& strokes, CFX_RectF rtWidget, - CFX_Path& path, + CXFA_Path& path, int32_t nIndex, bool bStart, bool bCorner) { @@ -1383,7 +1374,7 @@ static void XFA_BOX_GetPath(CXFA_Box box, static void XFA_BOX_GetFillPath(CXFA_Box box, const std::vector<CXFA_Stroke>& strokes, CFX_RectF rtWidget, - CFX_Path& fillPath, + CXFA_Path& fillPath, uint16_t dwFlags) { if (box.IsArc() || (dwFlags & XFA_DRAWBOX_ForceRound) != 0) { CXFA_Edge edge = box.GetEdge(0); @@ -1532,8 +1523,8 @@ static void XFA_BOX_GetFillPath(CXFA_Box box, } } static void XFA_BOX_Fill_Radial(CXFA_Box box, - CFX_Graphics* pGS, - CFX_Path& fillPath, + CXFA_Graphics* pGS, + CXFA_Path& fillPath, CFX_RectF rtFill, CFX_Matrix* pMatrix) { CXFA_Fill fill = box.GetFill(); @@ -1545,18 +1536,18 @@ static void XFA_BOX_Fill_Radial(CXFA_Box box, crEnd = crStart; crStart = temp; } - CFX_Shading shading(rtFill.Center(), rtFill.Center(), 0, - sqrt(rtFill.Width() * rtFill.Width() + - rtFill.Height() * rtFill.Height()) / - 2, - true, true, crStart, crEnd); - CFX_Color cr(&shading); + CXFA_Shading shading(rtFill.Center(), rtFill.Center(), 0, + sqrt(rtFill.Width() * rtFill.Width() + + rtFill.Height() * rtFill.Height()) / + 2, + true, true, crStart, crEnd); + CXFA_Color cr(&shading); pGS->SetFillColor(&cr); pGS->FillPath(&fillPath, FXFILL_WINDING, pMatrix); } static void XFA_BOX_Fill_Pattern(CXFA_Box box, - CFX_Graphics* pGS, - CFX_Path& fillPath, + CXFA_Graphics* pGS, + CXFA_Path& fillPath, CFX_RectF rtFill, CFX_Matrix* pMatrix) { CXFA_Fill fill = box.GetFill(); @@ -1584,14 +1575,14 @@ static void XFA_BOX_Fill_Pattern(CXFA_Box box, break; } - CFX_Pattern pattern(iHatch, crEnd, crStart); - CFX_Color cr(&pattern, 0x0); + CXFA_Pattern pattern(iHatch, crEnd, crStart); + CXFA_Color cr(&pattern, 0x0); pGS->SetFillColor(&cr); pGS->FillPath(&fillPath, FXFILL_WINDING, pMatrix); } static void XFA_BOX_Fill_Linear(CXFA_Box box, - CFX_Graphics* pGS, - CFX_Path& fillPath, + CXFA_Graphics* pGS, + CXFA_Path& fillPath, CFX_RectF rtFill, CFX_Matrix* pMatrix) { CXFA_Fill fill = box.GetFill(); @@ -1620,14 +1611,14 @@ static void XFA_BOX_Fill_Linear(CXFA_Box box, default: break; } - CFX_Shading shading(ptStart, ptEnd, false, false, crStart, crEnd); - CFX_Color cr(&shading); + CXFA_Shading shading(ptStart, ptEnd, false, false, crStart, crEnd); + CXFA_Color cr(&shading); pGS->SetFillColor(&cr); pGS->FillPath(&fillPath, FXFILL_WINDING, pMatrix); } static void XFA_BOX_Fill(CXFA_Box box, const std::vector<CXFA_Stroke>& strokes, - CFX_Graphics* pGS, + CXFA_Graphics* pGS, const CFX_RectF& rtWidget, CFX_Matrix* pMatrix, uint32_t dwFlags) { @@ -1636,7 +1627,7 @@ static void XFA_BOX_Fill(CXFA_Box box, return; pGS->SaveGraphState(); - CFX_Path fillPath; + CXFA_Path fillPath; XFA_BOX_GetFillPath(box, strokes, rtWidget, fillPath, (dwFlags & XFA_DRAWBOX_ForceRound) != 0); fillPath.Close(); @@ -1664,7 +1655,7 @@ static void XFA_BOX_Fill(CXFA_Box box, } else { cr = fill.GetColor(); } - CFX_Color fillColor(cr); + CXFA_Color fillColor(cr); pGS->SetFillColor(&fillColor); pGS->FillPath(&fillPath, FXFILL_WINDING, pMatrix); } break; @@ -1672,8 +1663,8 @@ static void XFA_BOX_Fill(CXFA_Box box, pGS->RestoreGraphState(); } static void XFA_BOX_StrokePath(CXFA_Stroke stroke, - CFX_Path* pPath, - CFX_Graphics* pGS, + CXFA_Path* pPath, + CXFA_Graphics* pGS, CFX_Matrix* pMatrix) { if (!stroke || !stroke.IsVisible()) { return; @@ -1690,13 +1681,13 @@ static void XFA_BOX_StrokePath(CXFA_Stroke stroke, pGS->SetLineCap(CFX_GraphStateData::LineCapButt); XFA_StrokeTypeSetLineDash(pGS, stroke.GetStrokeType(), XFA_ATTRIBUTEENUM_Butt); - CFX_Color fxColor(stroke.GetColor()); + CXFA_Color fxColor(stroke.GetColor()); pGS->SetStrokeColor(&fxColor); pGS->StrokePath(pPath, pMatrix); pGS->RestoreGraphState(); } static void XFA_BOX_StrokeArc(CXFA_Box box, - CFX_Graphics* pGS, + CXFA_Graphics* pGS, CFX_RectF rtWidget, CFX_Matrix* pMatrix, uint32_t dwFlags) { @@ -1727,7 +1718,7 @@ static void XFA_BOX_StrokeArc(CXFA_Box box, if (fHalf < 0.001f) return; - CFX_Path arcPath; + CXFA_Path arcPath; XFA_BOX_GetPath_Arc(box, rtWidget, arcPath, dwFlags); XFA_BOX_StrokePath(edge, &arcPath, pGS, pMatrix); return; @@ -1753,11 +1744,11 @@ static void XFA_BOX_StrokeArc(CXFA_Box box, startAngle = startAngle * FX_PI / 180.0f; sweepAngle = -sweepAngle * FX_PI / 180.0f; - CFX_Path arcPath; + CXFA_Path arcPath; arcPath.AddArc(rtWidget.TopLeft(), rtWidget.Size(), 3.0f * FX_PI / 4.0f, FX_PI); - CFX_Color cr(0xFF808080); + CXFA_Color cr(0xFF808080); pGS->SetStrokeColor(&cr); pGS->StrokePath(&arcPath, pMatrix); arcPath.Clear(); @@ -1784,17 +1775,17 @@ static void XFA_BOX_StrokeArc(CXFA_Box box, pGS->StrokePath(&arcPath, pMatrix); pGS->RestoreGraphState(); } -static void XFA_Draw3DRect(CFX_Graphics* pGraphic, +static void XFA_Draw3DRect(CXFA_Graphics* pGraphic, const CFX_RectF& rt, float fLineWidth, CFX_Matrix* pMatrix, FX_ARGB argbTopLeft, FX_ARGB argbBottomRight) { - CFX_Color crLT(argbTopLeft); + CXFA_Color crLT(argbTopLeft); pGraphic->SetFillColor(&crLT); float fBottom = rt.bottom(); float fRight = rt.right(); - CFX_Path pathLT; + CXFA_Path pathLT; pathLT.MoveTo(CFX_PointF(rt.left, fBottom)); pathLT.LineTo(CFX_PointF(rt.left, rt.top)); pathLT.LineTo(CFX_PointF(fRight, rt.top)); @@ -1804,10 +1795,10 @@ static void XFA_Draw3DRect(CFX_Graphics* pGraphic, pathLT.LineTo(CFX_PointF(rt.left, fBottom)); pGraphic->FillPath(&pathLT, FXFILL_WINDING, pMatrix); - CFX_Color crRB(argbBottomRight); + CXFA_Color crRB(argbBottomRight); pGraphic->SetFillColor(&crRB); - CFX_Path pathRB; + CXFA_Path pathRB; pathRB.MoveTo(CFX_PointF(fRight, rt.top)); pathRB.LineTo(CFX_PointF(fRight, fBottom)); pathRB.LineTo(CFX_PointF(rt.left, fBottom)); @@ -1817,37 +1808,37 @@ static void XFA_Draw3DRect(CFX_Graphics* pGraphic, pathRB.LineTo(CFX_PointF(fRight, rt.top)); pGraphic->FillPath(&pathRB, FXFILL_WINDING, pMatrix); } -static void XFA_BOX_Stroke_3DRect_Lowered(CFX_Graphics* pGS, +static void XFA_BOX_Stroke_3DRect_Lowered(CXFA_Graphics* pGS, CFX_RectF rt, float fThickness, CFX_Matrix* pMatrix) { float fHalfWidth = fThickness / 2.0f; CFX_RectF rtInner(rt); rtInner.Deflate(fHalfWidth, fHalfWidth); - CFX_Color cr(0xFF000000); + CXFA_Color cr(0xFF000000); pGS->SetFillColor(&cr); - CFX_Path path; + CXFA_Path path; path.AddRectangle(rt.left, rt.top, rt.width, rt.height); path.AddRectangle(rtInner.left, rtInner.top, rtInner.width, rtInner.height); pGS->FillPath(&path, FXFILL_ALTERNATE, pMatrix); XFA_Draw3DRect(pGS, rtInner, fHalfWidth, pMatrix, 0xFF808080, 0xFFC0C0C0); } -static void XFA_BOX_Stroke_3DRect_Raised(CFX_Graphics* pGS, +static void XFA_BOX_Stroke_3DRect_Raised(CXFA_Graphics* pGS, CFX_RectF rt, float fThickness, CFX_Matrix* pMatrix) { float fHalfWidth = fThickness / 2.0f; CFX_RectF rtInner(rt); rtInner.Deflate(fHalfWidth, fHalfWidth); - CFX_Color cr(0xFF000000); + CXFA_Color cr(0xFF000000); pGS->SetFillColor(&cr); - CFX_Path path; + CXFA_Path path; path.AddRectangle(rt.left, rt.top, rt.width, rt.height); path.AddRectangle(rtInner.left, rtInner.top, rtInner.width, rtInner.height); pGS->FillPath(&path, FXFILL_ALTERNATE, pMatrix); XFA_Draw3DRect(pGS, rtInner, fHalfWidth, pMatrix, 0xFFFFFFFF, 0xFF808080); } -static void XFA_BOX_Stroke_3DRect_Etched(CFX_Graphics* pGS, +static void XFA_BOX_Stroke_3DRect_Etched(CXFA_Graphics* pGS, CFX_RectF rt, float fThickness, CFX_Matrix* pMatrix) { @@ -1857,7 +1848,7 @@ static void XFA_BOX_Stroke_3DRect_Etched(CFX_Graphics* pGS, rtInner.Deflate(fHalfWidth, fHalfWidth); XFA_Draw3DRect(pGS, rtInner, fHalfWidth, pMatrix, 0xFFFFFFFF, 0xFF808080); } -static void XFA_BOX_Stroke_3DRect_Embossed(CFX_Graphics* pGS, +static void XFA_BOX_Stroke_3DRect_Embossed(CXFA_Graphics* pGS, CFX_RectF rt, float fThickness, CFX_Matrix* pMatrix) { @@ -1869,7 +1860,7 @@ static void XFA_BOX_Stroke_3DRect_Embossed(CFX_Graphics* pGS, } static void XFA_BOX_Stroke_Rect(CXFA_Box box, const std::vector<CXFA_Stroke>& strokes, - CFX_Graphics* pGS, + CXFA_Graphics* pGS, CFX_RectF rtWidget, CFX_Matrix* pMatrix) { bool bVisible = false; @@ -1927,7 +1918,7 @@ static void XFA_BOX_Stroke_Rect(CXFA_Box box, } } bool bStart = true; - CFX_Path path; + CXFA_Path path; for (int32_t i = 0; i < 8; i++) { CXFA_Stroke stroke = strokes[i]; if ((i % 1) == 0 && stroke.GetRadius() < 0) { @@ -1957,7 +1948,7 @@ static void XFA_BOX_Stroke_Rect(CXFA_Box box, } static void XFA_BOX_Stroke(CXFA_Box box, const std::vector<CXFA_Stroke>& strokes, - CFX_Graphics* pGS, + CXFA_Graphics* pGS, CFX_RectF rtWidget, CFX_Matrix* pMatrix, uint32_t dwFlags) { @@ -2021,7 +2012,7 @@ static void XFA_BOX_Stroke(CXFA_Box box, XFA_BOX_Stroke_Rect(box, strokes, pGS, rtWidget, pMatrix); } void XFA_DrawBox(CXFA_Box box, - CFX_Graphics* pGS, + CXFA_Graphics* pGS, const CFX_RectF& rtWidget, CFX_Matrix* pMatrix, uint32_t dwFlags) { diff --git a/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffwidget.h b/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffwidget.h index b7bb123bda1..0e7c35e3615 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffwidget.h +++ b/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffwidget.h @@ -35,11 +35,11 @@ enum XFA_WIDGETITEM { XFA_WIDGETITEM_PrevSibling, }; -int32_t XFA_StrokeTypeSetLineDash(CFX_Graphics* pGraphics, +int32_t XFA_StrokeTypeSetLineDash(CXFA_Graphics* pGraphics, int32_t iStrokeType, int32_t iCapType); CFX_GraphStateData::LineCap XFA_LineCapToFXGE(int32_t iLineCap); -void XFA_DrawImage(CFX_Graphics* pGS, +void XFA_DrawImage(CXFA_Graphics* pGS, const CFX_RectF& rtImage, CFX_Matrix* pMatrix, const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap, @@ -71,7 +71,7 @@ bool XFA_IsCreateWidget(XFA_Element iType); #define XFA_DRAWBOX_ForceRound 1 #define XFA_DRAWBOX_Lowered3D 2 void XFA_DrawBox(CXFA_Box box, - CFX_Graphics* pGS, + CXFA_Graphics* pGS, const CFX_RectF& rtWidget, CFX_Matrix* pMatrix, uint32_t dwFlags = 0); @@ -91,7 +91,7 @@ class CXFA_FFWidget : public CXFA_ContentLayoutItem { ~CXFA_FFWidget() override; virtual CFX_RectF GetBBox(uint32_t dwStatus, bool bDrawFocus = false); - virtual void RenderWidget(CFX_Graphics* pGS, + virtual void RenderWidget(CXFA_Graphics* pGS, CFX_Matrix* pMatrix, uint32_t dwStatus); virtual bool IsLoaded(); @@ -160,7 +160,7 @@ class CXFA_FFWidget : public CXFA_ContentLayoutItem { void InvalidateWidget(const CFX_RectF* pRect = nullptr); void AddInvalidateRect(const CFX_RectF* pRect = nullptr); bool GetCaptionText(CFX_WideString& wsCap); - bool IsFocused(); + bool IsFocused() const { return !!(m_dwStatus & XFA_WidgetStatus_Focused); } CFX_PointF Rotate2Normal(const CFX_PointF& point); CFX_Matrix GetRotateMatrix(); bool IsLayoutRectEmpty(); @@ -171,7 +171,7 @@ class CXFA_FFWidget : public CXFA_ContentLayoutItem { protected: virtual bool PtInActiveRect(const CFX_PointF& point); - void DrawBorder(CFX_Graphics* pGS, + void DrawBorder(CXFA_Graphics* pGS, CXFA_Box box, const CFX_RectF& rtBorder, CFX_Matrix* pMatrix, diff --git a/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffwidgethandler.cpp b/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffwidgethandler.cpp index 6fe24fee292..b703f746e8e 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffwidgethandler.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffwidgethandler.cpp @@ -8,9 +8,8 @@ #include <vector> -#include "xfa/fxfa/app/xfa_ffchoicelist.h" -#include "xfa/fxfa/app/xfa_fffield.h" -#include "xfa/fxfa/app/xfa_fwladapter.h" +#include "xfa/fxfa/app/cxfa_fffield.h" +#include "xfa/fxfa/app/cxfa_fwladapterwidgetmgr.h" #include "xfa/fxfa/cxfa_ffdoc.h" #include "xfa/fxfa/cxfa_ffdocview.h" #include "xfa/fxfa/cxfa_ffwidget.h" @@ -156,7 +155,7 @@ bool CXFA_FFWidgetHandler::OnSetCursor(CXFA_FFWidget* hWidget, } void CXFA_FFWidgetHandler::RenderWidget(CXFA_FFWidget* hWidget, - CFX_Graphics* pGS, + CXFA_Graphics* pGS, CFX_Matrix* pMatrix, bool bHighlight) { hWidget->RenderWidget(pGS, pMatrix, diff --git a/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffwidgethandler.h b/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffwidgethandler.h index 8f44dbbd454..36d91a709c9 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffwidgethandler.h +++ b/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffwidgethandler.h @@ -59,7 +59,7 @@ class CXFA_FFWidgetHandler { FWL_WidgetHit OnHitTest(CXFA_FFWidget* hWidget, const CFX_PointF& point); bool OnSetCursor(CXFA_FFWidget* hWidget, const CFX_PointF& point); void RenderWidget(CXFA_FFWidget* hWidget, - CFX_Graphics* pGS, + CXFA_Graphics* pGS, CFX_Matrix* pMatrix, bool bHighlight); bool HasEvent(CXFA_WidgetAcc* pWidgetAcc, XFA_EVENTTYPE eEventType); diff --git a/chromium/third_party/pdfium/xfa/fxfa/cxfa_rendercontext.cpp b/chromium/third_party/pdfium/xfa/fxfa/cxfa_rendercontext.cpp index 02c7cbb3710..bac13f36764 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/cxfa_rendercontext.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/cxfa_rendercontext.cpp @@ -8,15 +8,13 @@ #include "xfa/fxfa/cxfa_ffpageview.h" #include "xfa/fxfa/cxfa_ffwidget.h" -#include "xfa/fxgraphics/cfx_graphics.h" +#include "xfa/fxgraphics/cxfa_graphics.h" CXFA_RenderContext::CXFA_RenderContext(CXFA_FFPageView* pPageView, const CFX_RectF& clipRect, const CFX_Matrix& matrix) : m_pWidget(nullptr), m_matrix(matrix), m_rtClipRect(clipRect) { - CFX_Matrix mtRes; - mtRes.SetReverse(matrix); - mtRes.TransformRect(m_rtClipRect); + matrix.GetInverse().TransformRect(m_rtClipRect); m_pWidgetIterator = pPageView->CreateWidgetIterator( XFA_TRAVERSEWAY_Form, @@ -26,7 +24,7 @@ CXFA_RenderContext::CXFA_RenderContext(CXFA_FFPageView* pPageView, CXFA_RenderContext::~CXFA_RenderContext() {} -void CXFA_RenderContext::DoRender(CFX_Graphics* gs) { +void CXFA_RenderContext::DoRender(CXFA_Graphics* gs) { while (m_pWidget) { CFX_RectF rtWidgetBox = m_pWidget->GetBBox(XFA_WidgetStatus_Visible); rtWidgetBox.width += 1; diff --git a/chromium/third_party/pdfium/xfa/fxfa/cxfa_rendercontext.h b/chromium/third_party/pdfium/xfa/fxfa/cxfa_rendercontext.h index 0fd1dc9e1f1..8f9ef3d0aa4 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/cxfa_rendercontext.h +++ b/chromium/third_party/pdfium/xfa/fxfa/cxfa_rendercontext.h @@ -18,7 +18,7 @@ class CXFA_RenderContext { const CFX_Matrix& matrix); ~CXFA_RenderContext(); - void DoRender(CFX_Graphics* gs); + void DoRender(CXFA_Graphics* gs); private: std::unique_ptr<IXFA_WidgetIterator> m_pWidgetIterator; diff --git a/chromium/third_party/pdfium/xfa/fxfa/cxfa_widgetacc.cpp b/chromium/third_party/pdfium/xfa/fxfa/cxfa_widgetacc.cpp index 9b52f95b63f..3c136df0ffe 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/cxfa_widgetacc.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/cxfa_widgetacc.cpp @@ -14,7 +14,7 @@ #include "third_party/base/stl_util.h" #include "xfa/fde/cfde_textout.h" #include "xfa/fxfa/app/cxfa_textlayout.h" -#include "xfa/fxfa/app/xfa_ffwidgetacc.h" +#include "xfa/fxfa/app/cxfa_textprovider.h" #include "xfa/fxfa/cxfa_ffapp.h" #include "xfa/fxfa/cxfa_ffdoc.h" #include "xfa/fxfa/cxfa_ffdocview.h" @@ -409,7 +409,8 @@ int32_t CXFA_WidgetAcc::ProcessFormatTestValidate(CXFA_Validate validate, return XFA_EVENTERROR_NotExist; CXFA_LocaleValue lcValue = XFA_GetLocaleValue(this); - if (!lcValue.ValidateValue(lcValue.GetValue(), wsPicture, pLocale)) { + if (!lcValue.ValidateValue(lcValue.GetValue(), wsPicture, pLocale, + nullptr)) { IXFA_AppProvider* pAppProvider = GetAppProvider(); if (!pAppProvider) return XFA_EVENTERROR_NotExist; diff --git a/chromium/third_party/pdfium/xfa/fxfa/fm2js/DEPS b/chromium/third_party/pdfium/xfa/fxfa/fm2js/DEPS new file mode 100644 index 00000000000..2be03524b6a --- /dev/null +++ b/chromium/third_party/pdfium/xfa/fxfa/fm2js/DEPS @@ -0,0 +1,3 @@ +include_rules = [ + '+third_party/icu', +] diff --git a/chromium/third_party/pdfium/xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp b/chromium/third_party/pdfium/xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp index 4b3b5e2ab17..5f1a4d29899 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp @@ -17,7 +17,7 @@ #include "fxjs/cfxjse_value.h" #include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" -#include "xfa/fxfa/app/xfa_ffnotify.h" +#include "xfa/fxfa/app/cxfa_ffnotify.h" #include "xfa/fxfa/fm2js/cxfa_fmparse.h" #include "xfa/fxfa/parser/cxfa_document.h" #include "xfa/fxfa/parser/cxfa_localevalue.h" @@ -35,140 +35,95 @@ struct XFA_FMHtmlReserveCode { const wchar_t* m_htmlReserve; }; -struct XFA_FMHtmlHashedReserveCode { - uint32_t m_uHash; - uint32_t m_uCode; -}; - -const XFA_FMHtmlHashedReserveCode reservesForDecode[] = { - {0x00018b62, /*L"Mu",*/ 924}, {0x00019083, /*L"Nu",*/ 925}, - {0x00019ab9, /*L"Pi",*/ 928}, {0x0001c3c1, /*L"Xi",*/ 926}, - {0x000210ac, /*L"ge",*/ 8805}, {0x000210bb, /*L"gt",*/ 62}, - {0x00022a51, /*L"le",*/ 8804}, {0x00022a60, /*L"lt",*/ 60}, - {0x00022f82, /*L"mu",*/ 956}, {0x00023493, /*L"ne",*/ 8800}, - {0x00023497, /*L"ni",*/ 8715}, {0x000234a3, /*L"nu",*/ 957}, - {0x000239c1, /*L"or",*/ 8744}, {0x00023ed9, /*L"pi",*/ 960}, - {0x000267e1, /*L"xi",*/ 958}, {0x00c41789, /*L"lceil",*/ 8968}, - {0x00eef34f, /*L"thetasym",*/ 977}, {0x012d7ead, /*L"lcirc",*/ 206}, - {0x01637b56, /*L"agrave",*/ 224}, {0x020856da, /*L"crarr",*/ 8629}, - {0x022188c3, /*L"gamma",*/ 947}, {0x033586d3, /*L"nbsp",*/ 160}, - {0x04f4c358, /*L"nsub",*/ 8836}, {0x0581466a, /*L"dagger",*/ 8224}, - {0x06b1f790, /*L"oelig",*/ 339}, {0x06e490d4, /*L"Chi",*/ 935}, - {0x0718c6a1, /*L"ETH",*/ 208}, {0x07196ada, /*L"Eta",*/ 919}, - {0x07f667ca, /*L"Ugrave",*/ 217}, {0x083a8a21, /*L"Phi",*/ 934}, - {0x083ac28c, /*L"Psi",*/ 936}, {0x086f26a9, /*L"Rho",*/ 929}, - {0x089b5b51, /*L"aring",*/ 229}, {0x08a39f4a, /*L"Tau",*/ 932}, - {0x08b6188b, /*L"THORN",*/ 222}, {0x09ce792a, /*L"icirc",*/ 238}, - {0x09f9d61e, /*L"amp",*/ 38}, {0x09f9db33, /*L"and",*/ 8743}, - {0x09f9db36, /*L"ang",*/ 8736}, {0x0a2e3514, /*L"cap",*/ 8745}, - {0x0a2e58f4, /*L"chi",*/ 967}, {0x0a2e9ba8, /*L"cup",*/ 8746}, - {0x0a4897d0, /*L"deg",*/ 176}, {0x0a6332fa, /*L"eta",*/ 951}, - {0x0a633301, /*L"eth",*/ 240}, {0x0acc4d4b, /*L"int",*/ 8747}, - {0x0b1b3d35, /*L"loz",*/ 9674}, {0x0b1b4c8b, /*L"lrm",*/ 8206}, - {0x0b4fd9b1, /*L"not",*/ 172}, {0x0b845241, /*L"phi",*/ 966}, - {0x0b84576f, /*L"piv",*/ 982}, {0x0b848aac, /*L"psi",*/ 968}, - {0x0bb8df5e, /*L"reg",*/ 174}, {0x0bb8eec9, /*L"rho",*/ 961}, - {0x0bb9034b, /*L"rlm",*/ 8207}, {0x0bd33d14, /*L"shy",*/ 173}, - {0x0bd34229, /*L"sim",*/ 8764}, {0x0bd37faa, /*L"sub",*/ 8834}, - {0x0bd37fb5, /*L"sum",*/ 8721}, {0x0bd37fb8, /*L"sup",*/ 8835}, - {0x0bed676a, /*L"tau",*/ 964}, {0x0c07f32e, /*L"uml",*/ 168}, - {0x0c71032c, /*L"yen",*/ 165}, {0x0c7f2889, /*L"szlig",*/ 223}, - {0x0c8badbb, /*L"zwj",*/ 8205}, {0x10ba4dba, /*L"Egrave",*/ 200}, - {0x10f1ea24, /*L"para",*/ 182}, {0x10f1ea37, /*L"part",*/ 8706}, - {0x115b2337, /*L"perp",*/ 8869}, {0x12b10d15, /*L"prod",*/ 8719}, - {0x12b10d21, /*L"prop",*/ 8733}, {0x12dfa9f4, /*L"rfloor",*/ 8971}, - {0x12eb4736, /*L"Agrave",*/ 192}, {0x12fff2b7, /*L"pund",*/ 163}, - {0x13fda9f2, /*L"tilde",*/ 732}, {0x1417fd62, /*L"times",*/ 215}, - {0x154fc726, /*L"ecirc",*/ 234}, {0x165aa451, /*L"sigma",*/ 963}, - {0x1709124a, /*L"Dagger",*/ 8225}, {0x192f78d5, /*L"iexcl",*/ 161}, - {0x1b7ed8d7, /*L"rArr",*/ 8658}, {0x1ec88c68, /*L"rang",*/ 9002}, - {0x1ec8a0f7, /*L"rarr",*/ 8594}, {0x1eda07f3, /*L"atilde",*/ 227}, - {0x1f3182c4, /*L"real",*/ 8476}, {0x1fc34f8b, /*L"yacute",*/ 253}, - {0x20d11522, /*L"acirc",*/ 226}, {0x21933a9b, /*L"rsaquo",*/ 8250}, - {0x21f44907, /*L"uacute",*/ 250}, {0x220cca72, /*L"acute",*/ 180}, - {0x242cded1, /*L"alefsym",*/ 8501}, {0x2655c66a, /*L"delta",*/ 948}, - {0x269e4b4d, /*L"exist",*/ 8707}, {0x273379fa, /*L"micro",*/ 181}, - {0x27a37440, /*L"forall",*/ 8704}, {0x2854e62c, /*L"minus",*/ 8722}, - {0x28636f81, /*L"cedil",*/ 184}, {0x2887357b, /*L"iacute",*/ 237}, - {0x2994d5ff, /*L"frac12",*/ 189}, {0x2994d601, /*L"frac14",*/ 188}, - {0x2994e043, /*L"frac34",*/ 190}, {0x2a1feb41, /*L"lambda",*/ 955}, - {0x2ab215f3, /*L"apos",*/ 39}, {0x2ab82ef7, /*L"eacute",*/ 233}, - {0x2b3592ef, /*L"auml",*/ 228}, {0x2ce92873, /*L"aacute",*/ 225}, - {0x2daff48a, /*L"oslash",*/ 248}, {0x2ef68882, /*L"aelig",*/ 230}, - {0x3061d3d3, /*L"Atilde",*/ 195}, {0x314b1b6b, /*L"Yacute",*/ 221}, - {0x337c14e7, /*L"Uacute",*/ 218}, {0x37676aca, /*L"cent",*/ 162}, - {0x37d0b841, /*L"circ",*/ 710}, {0x386e7947, /*L"cong",*/ 8773}, - {0x386e839b, /*L"copy",*/ 169}, {0x3a0e225a, /*L"Epsilon",*/ 917}, - {0x3ba7b721, /*L"Lambda",*/ 923}, {0x3bd9abe6, /*L"Alpha",*/ 913}, - {0x3c3ffad7, /*L"Eacute",*/ 201}, {0x3cfaf69f, /*L"brvbar",*/ 166}, - {0x3d54a489, /*L"omega",*/ 969}, {0x3e70f453, /*L"Aacute",*/ 193}, - {0x3f37c06a, /*L"Oslash",*/ 216}, {0x40e1b34e, /*L"diams",*/ 9830}, - {0x416596df, /*L"plusmn",*/ 177}, {0x4354ff16, /*L"Ucirc",*/ 219}, - {0x454fce6a, /*L"Upsilon",*/ 933}, {0x4610ad35, /*L"emsp",*/ 8195}, - {0x462afb76, /*L"ensp",*/ 8194}, {0x46e30073, /*L"euml",*/ 235}, - {0x46e31a1b, /*L"euro",*/ 8364}, {0x46f2eada, /*L"lowast",*/ 8727}, - {0x4dca26cf, /*L"Auml",*/ 196}, {0x4e2d6083, /*L"image",*/ 8465}, - {0x4f964ee8, /*L"notin",*/ 8713}, {0x50917a7a, /*L"epsilon",*/ 949}, - {0x52f9a4cd, /*L"Kappa",*/ 922}, {0x5496f410, /*L"Ocirc",*/ 212}, - {0x568cbf34, /*L"zeta",*/ 950}, {0x57badd20, /*L"ntilde",*/ 241}, - {0x58662109, /*L"zwnj",*/ 8204}, {0x5b39870f, /*L"empty",*/ 8709}, - {0x5bd3268a, /*L"upsilon",*/ 965}, {0x5e2bf8a3, /*L"Gamma",*/ 915}, - {0x5f73c13a, /*L"rsquo",*/ 8217}, {0x61f2bc4d, /*L"iota",*/ 953}, - {0x625bbcf3, /*L"isin",*/ 8712}, {0x62906df7, /*L"iuml",*/ 239}, - {0x64a5cb31, /*L"Aring",*/ 197}, {0x66f25c4a, /*L"sbquo",*/ 8218}, - {0x6851ab60, /*L"spades",*/ 9824}, {0x6942a900, /*L"Ntilde",*/ 209}, - {0x69779453, /*L"Euml",*/ 203}, {0x6cda6e23, /*L"current",*/ 164}, - {0x70b5b634, /*L"lsquo",*/ 8216}, {0x715a3706, /*L"Ecirc",*/ 202}, - {0x71e8bf8d, /*L"tdquo",*/ 8221}, {0x72651431, /*L"Sigma",*/ 931}, - {0x7569813b, /*L"iquest",*/ 191}, {0x776a436a, /*L"equiv",*/ 8801}, - {0x79215314, /*L"Zeta",*/ 918}, {0x79b81224, /*L"ograve",*/ 242}, - {0x7c2f8b23, /*L"macr",*/ 175}, {0x7cdb8502, /*L"Acirc",*/ 194}, - {0x8185c62e, /*L"ndash",*/ 8211}, {0x8260364a, /*L"Delta",*/ 916}, - {0x846619ad, /*L"mdash",*/ 8212}, {0x8550fb50, /*L"OElig",*/ 338}, - {0x88eb5b85, /*L"ldquo",*/ 8220}, {0x8b3fde04, /*L"Ograve",*/ 210}, - {0x8bc5794b, /*L"ordf",*/ 170}, {0x8bc57952, /*L"ordm",*/ 186}, - {0x8c14923d, /*L"ouml",*/ 246}, {0x8c5a7cd6, /*L"theta",*/ 952}, - {0x8d61812b, /*L"thorn",*/ 254}, {0x912b95aa, /*L"asymp",*/ 8776}, - {0x947faf81, /*L"middot",*/ 183}, {0x9629202e, /*L"lfloor",*/ 8970}, - {0x972e9ec1, /*L"otilde",*/ 245}, {0x9748f231, /*L"otimes",*/ 8855}, - {0x995f1469, /*L"Omega",*/ 937}, {0x99eb5349, /*L"quot",*/ 34}, - {0x9aeb639e, /*L"hellip",*/ 8230}, {0xa0ae2f86, /*L"Scaron",*/ 352}, - {0xa4dcb0d5, /*L"lsaquo",*/ 8249}, {0xa53dbf41, /*L"oacute",*/ 243}, - {0xa5ae9e7b, /*L"bdquo",*/ 8222}, {0xa602d7ba, /*L"sdot",*/ 8901}, - {0xa61ce86f, /*L"sect",*/ 167}, {0xa6e4c3d7, /*L"sigmaf",*/ 962}, - {0xa7c1c74f, /*L"sube",*/ 8838}, {0xa7c20ee9, /*L"sup1",*/ 185}, - {0xa7c20eea, /*L"sup2",*/ 178}, {0xa7c20eeb, /*L"sup3",*/ 179}, - {0xa7c20f1d, /*L"supe",*/ 8839}, {0xa8b66aa1, /*L"Otilde",*/ 213}, - {0xad958c42, /*L"AElig",*/ 198}, {0xaea9261d, /*L"Ouml",*/ 214}, - {0xb040eafa, /*L"uArr",*/ 8657}, {0xb07c2e1c, /*L"beta",*/ 946}, - {0xb220e92f, /*L"bull",*/ 8226}, {0xb22750c4, /*L"ccedil",*/ 231}, - {0xb38ab31a, /*L"uarr",*/ 8593}, {0xb598b683, /*L"uuml",*/ 252}, - {0xb6c58b21, /*L"Oacute",*/ 211}, {0xb6d2a617, /*L"oline",*/ 8254}, - {0xba9fd989, /*L"dArr",*/ 8659}, {0xbb5ccd41, /*L"lgrave",*/ 204}, - {0xbd39b44c, /*L"weierp",*/ 8472}, {0xbde9a1a9, /*L"darr",*/ 8595}, - {0xc027e329, /*L"permil",*/ 8240}, {0xc2451389, /*L"upsih",*/ 978}, - {0xc3af1ca4, /*L"Ccedil",*/ 199}, {0xcd164249, /*L"fnof",*/ 402}, - {0xcf6c8467, /*L"hearts",*/ 9829}, {0xd1228390, /*L"trade",*/ 8482}, - {0xd1462407, /*L"yuml",*/ 255}, {0xd2cf2253, /*L"oplus",*/ 8853}, - {0xd310c1fc, /*L"Beta",*/ 914}, {0xd59c4d74, /*L"infin",*/ 8734}, - {0xd64d470d, /*L"hArr",*/ 8660}, {0xd67d9c75, /*L"divide",*/ 247}, - {0xd698dd37, /*L"Omicron",*/ 927}, {0xd82d4a63, /*L"Uuml",*/ 220}, - {0xd9970f2d, /*L"harr",*/ 8596}, {0xda91fd99, /*L"clubs",*/ 9827}, - {0xdbe5bdcc, /*L"there4",*/ 8756}, {0xdd7671bd, /*L"prime",*/ 8242}, - {0xdfcf3c06, /*L"alpha",*/ 945}, {0xe0213063, /*L"saron",*/ 353}, - {0xe1911d83, /*L"radic",*/ 8730}, {0xe2e75468, /*L"raquo",*/ 187}, - {0xe6e27a5e, /*L"lacute",*/ 205}, {0xe74a8f36, /*L"ucirc",*/ 251}, - {0xe864ecb6, /*L"Theta",*/ 920}, {0xecddde5e, /*L"nabla",*/ 8711}, - {0xed1c3557, /*L"omicron",*/ 959}, {0xef82228f, /*L"rceil",*/ 8969}, - {0xf1fab491, /*L"lArr",*/ 8656}, {0xf3dab7e7, /*L"Yuml",*/ 376}, - {0xf4294962, /*L"laquo",*/ 171}, {0xf5446822, /*L"lang",*/ 9001}, - {0xf5447cb1, /*L"larr",*/ 8592}, {0xf66e9bea, /*L"ugrave",*/ 249}, - {0xf6b4ce70, /*L"lota",*/ 921}, {0xf6ef34ed, /*L"kappa",*/ 954}, - {0xf72a3a56, /*L"thinsp",*/ 8201}, {0xf752801a, /*L"luml",*/ 207}, - {0xf88c8430, /*L"ocirc",*/ 244}, {0xf9676178, /*L"frasl",*/ 8260}, - {0xfd01885e, /*L"igrave",*/ 236}, {0xff3281da, /*L"egrave",*/ 232}, +// Sorted by m_htmlReserve +XFA_FMHtmlReserveCode reservesForDecode[] = { + {198, L"AElig"}, {193, L"Aacute"}, {194, L"Acirc"}, + {192, L"Agrave"}, {913, L"Alpha"}, {197, L"Aring"}, + {195, L"Atilde"}, {196, L"Auml"}, {914, L"Beta"}, + {199, L"Ccedil"}, {935, L"Chi"}, {8225, L"Dagger"}, + {916, L"Delta"}, {208, L"ETH"}, {201, L"Eacute"}, + {202, L"Ecirc"}, {200, L"Egrave"}, {917, L"Epsilon"}, + {919, L"Eta"}, {203, L"Euml"}, {915, L"Gamma"}, + {922, L"Kappa"}, {923, L"Lambda"}, {924, L"Mu"}, + {209, L"Ntilde"}, {925, L"Nu"}, {338, L"OElig"}, + {211, L"Oacute"}, {212, L"Ocirc"}, {210, L"Ograve"}, + {937, L"Omega"}, {927, L"Omicron"}, {216, L"Oslash"}, + {213, L"Otilde"}, {214, L"Ouml"}, {934, L"Phi"}, + {928, L"Pi"}, {936, L"Psi"}, {929, L"Rho"}, + {352, L"Scaron"}, {931, L"Sigma"}, {222, L"THORN"}, + {932, L"Tau"}, {920, L"Theta"}, {218, L"Uacute"}, + {219, L"Ucirc"}, {217, L"Ugrave"}, {933, L"Upsilon"}, + {220, L"Uuml"}, {926, L"Xi"}, {221, L"Yacute"}, + {376, L"Yuml"}, {918, L"Zeta"}, {225, L"aacute"}, + {226, L"acirc"}, {180, L"acute"}, {230, L"aelig"}, + {224, L"agrave"}, {8501, L"alefsym"}, {945, L"alpha"}, + {38, L"amp"}, {8743, L"and"}, {8736, L"ang"}, + {39, L"apos"}, {229, L"aring"}, {8776, L"asymp"}, + {227, L"atilde"}, {228, L"auml"}, {8222, L"bdquo"}, + {946, L"beta"}, {166, L"brvbar"}, {8226, L"bull"}, + {8745, L"cap"}, {231, L"ccedil"}, {184, L"cedil"}, + {162, L"cent"}, {967, L"chi"}, {710, L"circ"}, + {9827, L"clubs"}, {8773, L"cong"}, {169, L"copy"}, + {8629, L"crarr"}, {8746, L"cup"}, {164, L"current"}, + {8659, L"dArr"}, {8224, L"dagger"}, {8595, L"darr"}, + {176, L"deg"}, {948, L"delta"}, {9830, L"diams"}, + {247, L"divide"}, {233, L"eacute"}, {234, L"ecirc"}, + {232, L"egrave"}, {8709, L"empty"}, {8195, L"emsp"}, + {8194, L"ensp"}, {949, L"epsilon"}, {8801, L"equiv"}, + {951, L"eta"}, {240, L"eth"}, {235, L"euml"}, + {8364, L"euro"}, {8707, L"exist"}, {402, L"fnof"}, + {8704, L"forall"}, {189, L"frac12"}, {188, L"frac14"}, + {190, L"frac34"}, {8260, L"frasl"}, {947, L"gamma"}, + {8805, L"ge"}, {62, L"gt"}, {8660, L"hArr"}, + {8596, L"harr"}, {9829, L"hearts"}, {8230, L"hellip"}, + {237, L"iacute"}, {238, L"icirc"}, {161, L"iexcl"}, + {236, L"igrave"}, {8465, L"image"}, {8734, L"infin"}, + {8747, L"int"}, {953, L"iota"}, {191, L"iquest"}, + {8712, L"isin"}, {239, L"iuml"}, {954, L"kappa"}, + {8656, L"lArr"}, {205, L"lacute"}, {955, L"lambda"}, + {9001, L"lang"}, {171, L"laquo"}, {8592, L"larr"}, + {8968, L"lceil"}, {206, L"lcirc"}, {8220, L"ldquo"}, + {8804, L"le"}, {8970, L"lfloor"}, {204, L"lgrave"}, + {921, L"lota"}, {8727, L"lowast"}, {9674, L"loz"}, + {8206, L"lrm"}, {8249, L"lsaquo"}, {8216, L"lsquo"}, + {60, L"lt"}, {207, L"luml"}, {175, L"macr"}, + {8212, L"mdash"}, {181, L"micro"}, {183, L"middot"}, + {8722, L"minus"}, {956, L"mu"}, {8711, L"nabla"}, + {160, L"nbsp"}, {8211, L"ndash"}, {8800, L"ne"}, + {8715, L"ni"}, {172, L"not"}, {8713, L"notin"}, + {8836, L"nsub"}, {241, L"ntilde"}, {957, L"nu"}, + {243, L"oacute"}, {244, L"ocirc"}, {339, L"oelig"}, + {242, L"ograve"}, {8254, L"oline"}, {969, L"omega"}, + {959, L"omicron"}, {8853, L"oplus"}, {8744, L"or"}, + {170, L"ordf"}, {186, L"ordm"}, {248, L"oslash"}, + {245, L"otilde"}, {8855, L"otimes"}, {246, L"ouml"}, + {182, L"para"}, {8706, L"part"}, {8240, L"permil"}, + {8869, L"perp"}, {966, L"phi"}, {960, L"pi"}, + {982, L"piv"}, {177, L"plusmn"}, {8242, L"prime"}, + {8719, L"prod"}, {8733, L"prop"}, {968, L"psi"}, + {163, L"pund"}, {34, L"quot"}, {8658, L"rArr"}, + {8730, L"radic"}, {9002, L"rang"}, {187, L"raquo"}, + {8594, L"rarr"}, {8969, L"rceil"}, {8476, L"real"}, + {174, L"reg"}, {8971, L"rfloor"}, {961, L"rho"}, + {8207, L"rlm"}, {8250, L"rsaquo"}, {8217, L"rsquo"}, + {353, L"saron"}, {8218, L"sbquo"}, {8901, L"sdot"}, + {167, L"sect"}, {173, L"shy"}, {963, L"sigma"}, + {962, L"sigmaf"}, {8764, L"sim"}, {9824, L"spades"}, + {8834, L"sub"}, {8838, L"sube"}, {8721, L"sum"}, + {8835, L"sup"}, {185, L"sup1"}, {178, L"sup2"}, + {179, L"sup3"}, {8839, L"supe"}, {223, L"szlig"}, + {964, L"tau"}, {8221, L"tdquo"}, {8756, L"there4"}, + {952, L"theta"}, {977, L"thetasym"}, {8201, L"thinsp"}, + {254, L"thorn"}, {732, L"tilde"}, {215, L"times"}, + {8482, L"trade"}, {8657, L"uArr"}, {250, L"uacute"}, + {8593, L"uarr"}, {251, L"ucirc"}, {249, L"ugrave"}, + {168, L"uml"}, {978, L"upsih"}, {965, L"upsilon"}, + {252, L"uuml"}, {8472, L"weierp"}, {958, L"xi"}, + {253, L"yacute"}, {165, L"yen"}, {255, L"yuml"}, + {950, L"zeta"}, {8205, L"zwj"}, {8204, L"zwnj"}, }; +// Sorted by m_uCode const XFA_FMHtmlReserveCode reservesForEncode[] = { {34, L"quot"}, {38, L"amp"}, {39, L"apos"}, {60, L"lt"}, {62, L"gt"}, {160, L"nbsp"}, @@ -501,7 +456,10 @@ bool PatternStringType(const CFX_ByteStringC& szPattern, } CXFA_FM2JSContext* ToJSContext(CFXJSE_Value* pValue, CFXJSE_Class* pClass) { - return static_cast<CXFA_FM2JSContext*>(pValue->ToHostObject(pClass)); + CFXJSE_HostObject* pHostObj = pValue->ToHostObject(pClass); + if (!pHostObj || pHostObj->type() != CFXJSE_HostObject::kFM2JS) + return nullptr; + return static_cast<CXFA_FM2JSContext*>(pHostObj); } bool IsWhitespace(char c) { @@ -1776,9 +1734,6 @@ bool CXFA_FM2JSContext::IsIsoTimeFormat(const char* pData, int32_t iPos = 0; int32_t iIndex = 0; while (iIndex < iZone) { - if (iIndex >= iZone) - break; - if (!std::isdigit(pData[iIndex])) return false; @@ -1815,43 +1770,44 @@ bool CXFA_FM2JSContext::IsIsoTimeFormat(const char* pData, iIndex += 2; } } - if (pData[iIndex] == '.') { - ++iIndex; - char strSec[4]; - strSec[3] = '\0'; - if (!std::isdigit(pData[iIndex])) - return false; - strSec[0] = pData[iIndex]; - if (!std::isdigit(pData[iIndex + 1])) + if (iIndex < iLength && pData[iIndex] == '.') { + constexpr int kSubSecondLength = 3; + if (iIndex + kSubSecondLength >= iLength) return false; - strSec[1] = pData[iIndex + 1]; - if (!std::isdigit(pData[iIndex + 2])) - return false; + ++iIndex; + char strSec[kSubSecondLength + 1]; + for (int i = 0; i < kSubSecondLength; ++i) { + char c = pData[iIndex + i]; + if (!std::isdigit(c)) + return false; + strSec[i] = c; + } + strSec[kSubSecondLength] = '\0'; - strSec[2] = pData[iIndex + 2]; iMilliSecond = FXSYS_atoi(strSec); if (iMilliSecond > 100) { iMilliSecond = 0; return false; } - iIndex += 3; + iIndex += kSubSecondLength; } - if (pData[iIndex] == 'z' || pData[iIndex] == 'Z') + + if (iIndex < iLength && FXSYS_tolower(pData[iIndex]) == 'z') return true; int32_t iSign = 1; - if (pData[iIndex] == '+') { - ++iIndex; - } else if (pData[iIndex] == '-') { - iSign = -1; - ++iIndex; + if (iIndex < iLength) { + if (pData[iIndex] == '+') { + ++iIndex; + } else if (pData[iIndex] == '-') { + iSign = -1; + ++iIndex; + } } iPos = 0; while (iIndex < iLength) { - if (iIndex >= iLength) - return false; if (!std::isdigit(pData[iIndex])) return false; @@ -1929,12 +1885,8 @@ bool CXFA_FM2JSContext::IsIsoDateTimeFormat(const char* pData, (iLength - iIndex != 15)) { return true; } - if (!IsIsoTimeFormat(pData + iIndex, iLength - iIndex, iHour, iMinute, - iSecond, iMillionSecond, iZoneHour, iZoneMinute)) { - return false; - } - - return true; + return IsIsoTimeFormat(pData + iIndex, iLength - iIndex, iHour, iMinute, + iSecond, iMillionSecond, iZoneHour, iZoneMinute); } // static @@ -2018,8 +1970,8 @@ int32_t CXFA_FM2JSContext::DateString2Num(const CFX_ByteStringC& szDateString) { int32_t iDay = 0; if (iLength <= 10) { int32_t iStyle = -1; - if (!IsIsoDateFormat(szDateString.c_str(), iLength, iStyle, iYear, iMonth, - iDay)) { + if (!IsIsoDateFormat(szDateString.unterminated_c_str(), iLength, iStyle, + iYear, iMonth, iDay)) { return 0; } } else { @@ -2029,9 +1981,9 @@ int32_t CXFA_FM2JSContext::DateString2Num(const CFX_ByteStringC& szDateString) { int32_t iMilliSecond = 0; int32_t iZoneHour = 0; int32_t iZoneMinute = 0; - if (!IsIsoDateTimeFormat(szDateString.c_str(), iLength, iYear, iMonth, iDay, - iHour, iMinute, iSecond, iMilliSecond, iZoneHour, - iZoneMinute)) { + if (!IsIsoDateTimeFormat(szDateString.unterminated_c_str(), iLength, iYear, + iMonth, iDay, iHour, iMinute, iSecond, + iMilliSecond, iZoneHour, iZoneMinute)) { return 0; } } @@ -3301,7 +3253,7 @@ void CXFA_FM2JSContext::DecodeHTML(const CFX_ByteStringC& szHTMLString, strString[iStrIndex] = 0; } uint32_t iData = 0; - if (HTMLSTR2Code(strString, iData)) { + if (HTMLSTR2Code(strString, &iData)) { wsResultBuf.AppendChar((wchar_t)iData); } else { wsResultBuf.AppendChar(iCode); @@ -3564,7 +3516,8 @@ void CXFA_FM2JSContext::EncodeURL(const CFX_ByteStringC& szURLString, // static void CXFA_FM2JSContext::EncodeHTML(const CFX_ByteStringC& szHTMLString, CFX_ByteTextBuf& szResultBuf) { - CFX_ByteString str = szHTMLString.c_str(); + // TODO(tsepez): check usage of c_str() below. + CFX_ByteString str = szHTMLString.unterminated_c_str(); CFX_WideString wsHTMLString = CFX_WideString::FromUTF8(str.AsStringC()); const wchar_t* strCode = L"0123456789abcdef"; wchar_t strEncode[9]; @@ -3582,7 +3535,7 @@ void CXFA_FM2JSContext::EncodeHTML(const CFX_ByteStringC& szHTMLString, while (i < iLen) { uint32_t ch = pData[i]; CFX_WideString htmlReserve; - if (HTMLCode2STR(ch, htmlReserve)) { + if (HTMLCode2STR(ch, &htmlReserve)) { wsResultBuf.AppendChar(L'&'); wsResultBuf << htmlReserve; wsResultBuf.AppendChar(L';'); @@ -3682,44 +3635,36 @@ void CXFA_FM2JSContext::EncodeXML(const CFX_ByteStringC& szXMLString, // static bool CXFA_FM2JSContext::HTMLSTR2Code(const CFX_WideStringC& pData, - uint32_t& iCode) { - uint32_t uHash = FX_HashCode_GetW(pData, false); - int32_t iStart = 0; - int32_t iEnd = FX_ArraySize(reservesForDecode) - 1; - do { - int32_t iMid = (iStart + iEnd) / 2; - XFA_FMHtmlHashedReserveCode htmlhashedreservecode = reservesForDecode[iMid]; - if (uHash == htmlhashedreservecode.m_uHash) { - iCode = htmlhashedreservecode.m_uCode; - return true; - } - - if (uHash < htmlhashedreservecode.m_uHash) - iEnd = iMid - 1; - else - iStart = iMid + 1; - } while (iStart <= iEnd); + uint32_t* iCode) { + auto cmpFunc = [](const XFA_FMHtmlReserveCode& iter, + const CFX_WideStringC& val) { + // TODO(tsepez): check usage of c_str() below. + return wcscmp(val.unterminated_c_str(), iter.m_htmlReserve) > 0; + }; + const XFA_FMHtmlReserveCode* result = + std::lower_bound(std::begin(reservesForDecode), + std::end(reservesForDecode), pData, cmpFunc); + if (result != std::end(reservesForEncode) && + !wcscmp(pData.unterminated_c_str(), result->m_htmlReserve)) { + *iCode = result->m_uCode; + return true; + } return false; } // static bool CXFA_FM2JSContext::HTMLCode2STR(uint32_t iCode, - CFX_WideString& wsHTMLReserve) { - int32_t iStart = 0; - int32_t iEnd = FX_ArraySize(reservesForEncode) - 1; - do { - int32_t iMid = (iStart + iEnd) / 2; - XFA_FMHtmlReserveCode htmlreservecode = reservesForEncode[iMid]; - if (iCode == htmlreservecode.m_uCode) { - wsHTMLReserve = htmlreservecode.m_htmlReserve; - return true; - } - - if (iCode < htmlreservecode.m_uCode) - iEnd = iMid - 1; - else - iStart = iMid + 1; - } while (iStart <= iEnd); + CFX_WideString* wsHTMLReserve) { + auto cmpFunc = [](const XFA_FMHtmlReserveCode iter, const uint32_t& val) { + return iter.m_uCode < val; + }; + const XFA_FMHtmlReserveCode* result = + std::lower_bound(std::begin(reservesForEncode), + std::end(reservesForEncode), iCode, cmpFunc); + if (result != std::end(reservesForEncode) && result->m_uCode == iCode) { + *wsHTMLReserve = result->m_htmlReserve; + return true; + } return false; } @@ -4481,7 +4426,7 @@ void CXFA_FM2JSContext::TrillionUS(const CFX_ByteStringC& szData, "Sixty", "Seventy", "Eighty", "Ninety"}; CFX_ByteStringC pComm[] = {" Hundred ", " Thousand ", " Million ", " Billion ", "Trillion"}; - const char* pData = szData.c_str(); + const char* pData = szData.unterminated_c_str(); int32_t iLength = szData.GetLength(); int32_t iComm = 0; if (iLength > 12) @@ -4570,7 +4515,7 @@ void CXFA_FM2JSContext::TrillionUS(const CFX_ByteStringC& szData, void CXFA_FM2JSContext::WordUS(const CFX_ByteStringC& szData, int32_t iStyle, CFX_ByteTextBuf& strBuf) { - const char* pData = szData.c_str(); + const char* pData = szData.unterminated_c_str(); int32_t iLength = szData.GetLength(); if (iStyle < 0 || iStyle > 2) { return; @@ -6133,13 +6078,13 @@ bool CXFA_FM2JSContext::Translate(const CFX_WideStringC& wsFormcalc, CXFA_FM2JSContext::CXFA_FM2JSContext(v8::Isolate* pScriptIsolate, CFXJSE_Context* pScriptContext, CXFA_Document* pDoc) - : m_pIsolate(pScriptIsolate), + : CFXJSE_HostObject(kFM2JS), + m_pIsolate(pScriptIsolate), m_pFMClass(CFXJSE_Class::Create(pScriptContext, &formcalc_fm2js_descriptor, false)), m_pValue(pdfium::MakeUnique<CFXJSE_Value>(pScriptIsolate)), m_pDocument(pDoc) { - m_pValue.get()->SetNull(); m_pValue.get()->SetObject(this, m_pFMClass); } @@ -6151,7 +6096,9 @@ void CXFA_FM2JSContext::GlobalPropertyGetter(CFXJSE_Value* pValue) { void CXFA_FM2JSContext::ThrowNoDefaultPropertyException( const CFX_ByteStringC& name) const { - ThrowException(L"%.16s doesn't have a default property.", name.c_str()); + // TODO(tsepez): check usage of c_str() below. + ThrowException(L"%.16S doesn't have a default property.", + name.unterminated_c_str()); } void CXFA_FM2JSContext::ThrowCompilerErrorException() const { diff --git a/chromium/third_party/pdfium/xfa/fxfa/fm2js/cxfa_fm2jscontext.h b/chromium/third_party/pdfium/xfa/fxfa/fm2js/cxfa_fm2jscontext.h index 63fc0f42bdd..7946c02993b 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/fm2js/cxfa_fm2jscontext.h +++ b/chromium/third_party/pdfium/xfa/fxfa/fm2js/cxfa_fm2jscontext.h @@ -239,8 +239,8 @@ class CXFA_FM2JSContext : public CFXJSE_HostObject { CFX_ByteTextBuf& szResultBuf); static void EncodeXML(const CFX_ByteStringC& szXMLString, CFX_ByteTextBuf& szResultBuf); - static bool HTMLSTR2Code(const CFX_WideStringC& pData, uint32_t& iCode); - static bool HTMLCode2STR(uint32_t iCode, CFX_WideString& wsHTMLReserve); + static bool HTMLSTR2Code(const CFX_WideStringC& pData, uint32_t* iCode); + static bool HTMLCode2STR(uint32_t iCode, CFX_WideString* wsHTMLReserve); static void Format(CFXJSE_Value* pThis, const CFX_ByteStringC& szFuncName, CFXJSE_Arguments& args); diff --git a/chromium/third_party/pdfium/xfa/fxfa/fm2js/cxfa_fm2jscontext_embeddertest.cpp b/chromium/third_party/pdfium/xfa/fxfa/fm2js/cxfa_fm2jscontext_embeddertest.cpp index 45f1d16e358..ff2e2001865 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/fm2js/cxfa_fm2jscontext_embeddertest.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/fm2js/cxfa_fm2jscontext_embeddertest.cpp @@ -859,7 +859,10 @@ TEST_F(FM2JSContextEmbedderTest, Oneof) { {"Oneof(3, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1)", true}, {"Oneof(\"John\", \"Bill\", \"Gary\", \"Joan\", \"John\", \"Lisa\")", true}, - {"Oneof(3, 1, 25)", false}}; + {"Oneof(3, 1, 25)", false}, + {"Oneof(3, 3, null)", true}, + {"Oneof(3, null, null)", false}, + }; for (size_t i = 0; i < FX_ArraySize(tests); ++i) { EXPECT_TRUE(Execute(tests[i].program)); @@ -1429,3 +1432,15 @@ TEST_F(FM2JSContextEmbedderTest, Post) { TEST_F(FM2JSContextEmbedderTest, Put) { // TODO(dsinclair): Is this supported? } + +TEST_F(FM2JSContextEmbedderTest, InvalidFunctions) { + ASSERT_TRUE(OpenDocument("simple_xfa.pdf")); + + const char* const tests[] = { + "F()", "()", "()()()", "Round(2.0)()", + }; + + for (size_t i = 0; i < FX_ArraySize(tests); ++i) { + EXPECT_FALSE(ExecuteSilenceFailure(tests[i])); + } +} diff --git a/chromium/third_party/pdfium/xfa/fxfa/fm2js/cxfa_fmlexer.cpp b/chromium/third_party/pdfium/xfa/fxfa/fm2js/cxfa_fmlexer.cpp index 433839a88c7..6b8508a5034 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/fm2js/cxfa_fmlexer.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/fm2js/cxfa_fmlexer.cpp @@ -1,4 +1,4 @@ -// Copyright 2014 PDFium Authors. All rights reserved. +// Copright 2014 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. @@ -6,16 +6,30 @@ #include "xfa/fxfa/fm2js/cxfa_fmlexer.h" +#include <algorithm> + #include "core/fxcrt/fx_extension.h" #include "third_party/base/ptr_util.h" +#include "third_party/icu/source/common/unicode/uchar.h" namespace { -bool IsValid(const wchar_t* p) { +bool IsValidFormCalcCharacter(const wchar_t* p) { return *p == 0 || (*p >= 0x09 && *p <= 0x0D) || (*p >= 0x20 && *p <= 0xd7FF) || (*p >= 0xE000 && *p <= 0xFFFD); } +bool IsValidIdentifierCharacter(const wchar_t* p) { + return u_isalnum(*p) || *p == 0x005F || // '_' + *p == 0x0024; // '$' +} + +bool IsValidInitialIdentifierCharacter(const wchar_t* p) { + return u_isalpha(*p) || *p == 0x005F || // '_' + *p == 0x0024 || // '$' + *p == 0x0021; // '!' +} + const XFA_FMKeyword keyWords[] = { {TOKand, 0x00000026, L"&"}, {TOKlparen, 0x00000028, L"("}, @@ -97,7 +111,7 @@ CXFA_FMToken::CXFA_FMToken(uint32_t uLineNum) CXFA_FMToken::~CXFA_FMToken() {} CXFA_FMLexer::CXFA_FMLexer(const CFX_WideStringC& wsFormCalc) - : m_ptr(wsFormCalc.c_str()), + : m_ptr(wsFormCalc.unterminated_c_str()), m_end(m_ptr + wsFormCalc.GetLength() - 1), m_uCurrentLine(1), m_LexerError(false) {} @@ -116,9 +130,9 @@ CXFA_FMToken* CXFA_FMLexer::NextToken() { } std::unique_ptr<CXFA_FMToken> CXFA_FMLexer::Scan() { - uint16_t ch = 0; + wchar_t ch = 0; auto p = pdfium::MakeUnique<CXFA_FMToken>(m_uCurrentLine); - if (!IsValid(m_ptr)) { + if (!IsValidFormCalcCharacter(m_ptr)) { ch = *m_ptr; m_LexerError = true; return p; @@ -134,7 +148,7 @@ std::unique_ptr<CXFA_FMToken> CXFA_FMLexer::Scan() { } ch = *m_ptr; - if (!IsValid(m_ptr)) { + if (!IsValidFormCalcCharacter(m_ptr)) { m_LexerError = true; return p; } @@ -181,7 +195,7 @@ std::unique_ptr<CXFA_FMToken> CXFA_FMLexer::Scan() { return p; } - if (IsValid(m_ptr)) { + if (IsValidFormCalcCharacter(m_ptr)) { ch = *m_ptr; if (ch == '=') { p->m_type = TOKeq; @@ -201,7 +215,7 @@ std::unique_ptr<CXFA_FMToken> CXFA_FMLexer::Scan() { return p; } - if (IsValid(m_ptr)) { + if (IsValidFormCalcCharacter(m_ptr)) { ch = *m_ptr; if (ch == '=') { p->m_type = TOKle; @@ -224,7 +238,7 @@ std::unique_ptr<CXFA_FMToken> CXFA_FMLexer::Scan() { return p; } - if (IsValid(m_ptr)) { + if (IsValidFormCalcCharacter(m_ptr)) { ch = *m_ptr; if (ch == '=') { p->m_type = TOKge; @@ -284,7 +298,7 @@ std::unique_ptr<CXFA_FMToken> CXFA_FMLexer::Scan() { return p; } - if (!IsValid(m_ptr)) { + if (!IsValidFormCalcCharacter(m_ptr)) { ch = *m_ptr; m_LexerError = true; return p; @@ -304,7 +318,7 @@ std::unique_ptr<CXFA_FMToken> CXFA_FMLexer::Scan() { return p; } - if (IsValid(m_ptr)) { + if (IsValidFormCalcCharacter(m_ptr)) { ch = *m_ptr; if (ch == '.') { p->m_type = TOKdotdot; @@ -334,6 +348,10 @@ std::unique_ptr<CXFA_FMToken> CXFA_FMLexer::Scan() { ++m_ptr; break; default: { + if (!IsValidInitialIdentifierCharacter(m_ptr)) { + m_LexerError = true; + return p; + } m_ptr = Identifiers(p.get(), m_ptr); return p; } @@ -366,7 +384,7 @@ const wchar_t* CXFA_FMLexer::String(CXFA_FMToken* t, const wchar_t* p) { uint16_t ch = *p; while (ch) { - if (!IsValid(p)) { + if (!IsValidFormCalcCharacter(p)) { ch = *p; t->m_wstring = CFX_WideStringC(pStart, (p - pStart)); m_LexerError = true; @@ -387,7 +405,7 @@ const wchar_t* CXFA_FMLexer::String(CXFA_FMToken* t, const wchar_t* p) { if (p > m_end) break; - if (!IsValid(p)) { + if (!IsValidFormCalcCharacter(p)) { ch = *p; t->m_wstring = CFX_WideStringC(pStart, (p - pStart)); m_LexerError = true; @@ -410,34 +428,15 @@ const wchar_t* CXFA_FMLexer::String(CXFA_FMToken* t, const wchar_t* p) { const wchar_t* CXFA_FMLexer::Identifiers(CXFA_FMToken* t, const wchar_t* p) { const wchar_t* pStart = p; - uint16_t ch = *p; ++p; - if (p > m_end) { - t->m_wstring = CFX_WideStringC(pStart, (p - pStart)); - t->m_type = IsKeyword(t->m_wstring); - return p; - } - - if (!IsValid(p)) { - t->m_wstring = CFX_WideStringC(pStart, (p - pStart)); - m_LexerError = true; - return p; - } - - ch = *p; - while (ch) { - if (!IsValid(p)) { + while (p <= m_end && *p) { + if (!IsValidFormCalcCharacter(p)) { t->m_wstring = CFX_WideStringC(pStart, (p - pStart)); m_LexerError = true; return p; } - ch = *p; - if (ch == 0 || ch == 0x0A || ch == 0x0D || ch == 0x09 || ch == 0x0B || - ch == 0x0C || ch == 0x20 || ch == '.' || ch == ';' || ch == '"' || - ch == '=' || ch == '<' || ch == '>' || ch == ',' || ch == '(' || - ch == ')' || ch == ']' || ch == '[' || ch == '&' || ch == '|' || - ch == '+' || ch == '-' || ch == '*' || ch == '/') { + if (!IsValidIdentifierCharacter(p)) { break; } ++p; @@ -472,18 +471,15 @@ const wchar_t* CXFA_FMLexer::Comment(const wchar_t* p) { } XFA_FM_TOKEN CXFA_FMLexer::IsKeyword(const CFX_WideStringC& str) { - uint32_t uHash = FX_HashCode_GetW(str, true); - int32_t iStart = KEYWORD_START; - int32_t iEnd = KEYWORD_END; - do { - int32_t iMid = (iStart + iEnd) / 2; - XFA_FMKeyword keyword = keyWords[iMid]; - if (uHash == keyword.m_uHash) - return keyword.m_type; - if (uHash < keyword.m_uHash) - iEnd = iMid - 1; - else - iStart = iMid + 1; - } while (iStart <= iEnd); + uint32_t key = FX_HashCode_GetW(str, true); + auto cmpFunc = [](const XFA_FMKeyword& iter, const uint32_t& val) { + return iter.m_uHash < val; + }; + + const XFA_FMKeyword* result = std::lower_bound( + std::begin(keyWords) + KEYWORD_START, std::end(keyWords), key, cmpFunc); + if (result <= keyWords + KEYWORD_END && result->m_uHash == key) { + return result->m_type; + } return TOKidentifier; } diff --git a/chromium/third_party/pdfium/xfa/fxfa/fm2js/cxfa_fmlexer_unittest.cpp b/chromium/third_party/pdfium/xfa/fxfa/fm2js/cxfa_fmlexer_unittest.cpp index 7ca12d2fadc..5a8139d416e 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/fm2js/cxfa_fmlexer_unittest.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/fm2js/cxfa_fmlexer_unittest.cpp @@ -208,7 +208,7 @@ TEST(CXFA_FMLexerTest, Comments) { EXPECT_EQ(TOKeof, token->m_type); } -TEST(CXFA_FMLexerTest, Identifiers) { +TEST(CXFA_FMLexerTest, ValidIdentifiers) { std::vector<const wchar_t*> identifiers = { L"a", L"an_identifier", L"_ident", L"$ident", L"!ident", L"GetAddr"}; for (const auto* ident : identifiers) { @@ -219,6 +219,39 @@ TEST(CXFA_FMLexerTest, Identifiers) { } } +TEST(CXFA_FMLexerTest, InvalidIdentifiers) { + auto lexer = pdfium::MakeUnique<CXFA_FMLexer>(L"#a"); + lexer->NextToken(); + // TODO(rharrison): Add an expects for the return being nullptr here. + // See https://crbug.com/pdfium/814 + EXPECT_TRUE(lexer->HasError()); + + lexer = pdfium::MakeUnique<CXFA_FMLexer>(L"1a"); + lexer->NextToken(); + // TODO(rharrison): Add an expects for the return being nullptr here. + // See https://crbug.com/pdfium/814 + EXPECT_TRUE(lexer->HasError()); + + lexer = pdfium::MakeUnique<CXFA_FMLexer>(L"an@identifier"); + lexer->NextToken(); + EXPECT_FALSE(lexer->HasError()); + lexer->NextToken(); + // TODO(rharrison): Add an expects for the return being nullptr here. + // See https://crbug.com/pdfium/814 + EXPECT_TRUE(lexer->HasError()); + // TODO(rharrison): Add a test for if an another call to NextToken occurs, + // the error state will be retained, instead of continuing the parse. + // See https://crbug.com/pdfium/814 + + lexer = pdfium::MakeUnique<CXFA_FMLexer>(L"_ident@"); + lexer->NextToken(); + EXPECT_FALSE(lexer->HasError()); + lexer->NextToken(); + // TODO(rharrison): Add an expects for the return being nullptr here. + // See https://crbug.com/pdfium/814 + EXPECT_TRUE(lexer->HasError()); +} + TEST(CXFA_FMLexerTest, Whitespace) { auto lexer = pdfium::MakeUnique<CXFA_FMLexer>(L" \t\xc\x9\xb"); CXFA_FMToken* token = lexer->NextToken(); diff --git a/chromium/third_party/pdfium/xfa/fxfa/fm2js/cxfa_fmsimpleexpression.cpp b/chromium/third_party/pdfium/xfa/fxfa/fm2js/cxfa_fmsimpleexpression.cpp index 13051265541..955b06fe939 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/fm2js/cxfa_fmsimpleexpression.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/fm2js/cxfa_fmsimpleexpression.cpp @@ -6,6 +6,7 @@ #include "xfa/fxfa/fm2js/cxfa_fmsimpleexpression.h" +#include <algorithm> #include <utility> #include "core/fxcrt/fx_extension.h" @@ -13,6 +14,7 @@ namespace { +// Indexed by XFA_FM_SimpleExpressionType const wchar_t* const gs_lpStrExpFuncName[] = { L"pfm_rt.asgn_val_op", L"pfm_rt.log_or_op", L"pfm_rt.log_and_op", L"pfm_rt.eq_op", L"pfm_rt.neq_op", L"pfm_rt.lt_op", @@ -25,74 +27,55 @@ const wchar_t* const gs_lpStrExpFuncName[] = { L"pfm_rt.var_filter", }; -struct XFA_FMBuildInFunc { - uint32_t m_uHash; - const wchar_t* m_buildinfunc; +const wchar_t* const g_BuiltInFuncs[] = { + L"Abs", L"Apr", L"At", L"Avg", + L"Ceil", L"Choose", L"Concat", L"Count", + L"Cterm", L"Date", L"Date2Num", L"DateFmt", + L"Decode", L"Encode", L"Eval", L"Exists", + L"Floor", L"Format", L"FV", L"Get", + L"HasValue", L"If", L"Ipmt", L"IsoDate2Num", + L"IsoTime2Num", L"Left", L"Len", L"LocalDateFmt", + L"LocalTimeFmt", L"Lower", L"Ltrim", L"Max", + L"Min", L"Mod", L"NPV", L"Num2Date", + L"Num2GMTime", L"Num2Time", L"Oneof", L"Parse", + L"Pmt", L"Post", L"PPmt", L"Put", + L"PV", L"Rate", L"Ref", L"Replace", + L"Right", L"Round", L"Rtrim", L"Space", + L"Str", L"Stuff", L"Substr", L"Sum", + L"Term", L"Time", L"Time2Num", L"TimeFmt", + L"UnitType", L"UnitValue", L"Upper", L"Uuid", + L"Within", L"WordNum", }; -const XFA_FMBuildInFunc g_BuildInFuncs[] = { - {0x0001f1f5, L"At"}, {0x00020b9c, L"FV"}, - {0x00021aef, L"If"}, {0x00023ee6, L"PV"}, - {0x04b5c9ee, L"Encode"}, {0x08e96685, L"DateFmt"}, - {0x09f99db6, L"Abs"}, {0x09f9e583, L"Apr"}, - {0x09fa043e, L"Avg"}, {0x0a9782a0, L"Get"}, - {0x0b1b09df, L"Len"}, {0x0b3543a6, L"Max"}, - {0x0b356ca4, L"Min"}, {0x0b358b60, L"Mod"}, - {0x0b4fded4, L"NPV"}, {0x0b846bf1, L"Pmt"}, - {0x0b8494f9, L"Put"}, {0x0bb8df5d, L"Ref"}, - {0x0bd37a99, L"Str"}, {0x0bd37fb5, L"Sum"}, - {0x1048469b, L"Cterm"}, {0x11e03660, L"Exists"}, - {0x126236e6, L"Post"}, {0x127c6661, L"PPmt"}, - {0x193ade3e, L"Right"}, {0x1ec8ab2c, L"Rate"}, - {0x20e476dc, L"IsoTime2Num"}, {0x23eb6816, L"TimeFmt"}, - {0x24fb17b0, L"LocalDateFmt"}, {0x28dee6e9, L"Format"}, - {0x2d0890b8, L"Term"}, {0x2d71b00f, L"Time"}, - {0x2f890fb1, L"Num2Time"}, {0x3767511d, L"Ceil"}, - {0x3ffd1941, L"LocalTimeFmt"}, {0x442f68c8, L"Round"}, - {0x46fd1128, L"Eval"}, {0x4d629440, L"Date2Num"}, - {0x4dcf25f8, L"Concat"}, {0x4e00255d, L"UnitValue"}, - {0x55a5cc29, L"Lower"}, {0x5e43e04c, L"WordNum"}, - {0x620ce6ba, L"Ipmt"}, {0x6f544d49, L"Count"}, - {0x7e241013, L"Within"}, {0x9b9a6e2b, L"IsoDate2Num"}, - {0xb2c941c2, L"UnitType"}, {0xb598a1f7, L"Uuid"}, - {0xbde9abde, L"Date"}, {0xc0010b80, L"Num2Date"}, - {0xc1f6144c, L"Upper"}, {0xc44028f7, L"Oneof"}, - {0xc62c1b2c, L"Space"}, {0xd0ff50f9, L"HasValue"}, - {0xd1537042, L"Floor"}, {0xd2ac9cf1, L"Time2Num"}, - {0xd907aee5, L"Num2GMTime"}, {0xdf24f7c4, L"Decode"}, - {0xe2664803, L"Substr"}, {0xe3e7b528, L"Stuff"}, - {0xe6792d4e, L"Rtrim"}, {0xe8c23f5b, L"Parse"}, - {0xea18d121, L"Choose"}, {0xebfef69c, L"Replace"}, - {0xf5ad782b, L"Left"}, {0xf7bb2248, L"Ltrim"}, -}; +const FX_STRSIZE g_BuiltInFuncsMaxLen = 12; struct XFA_FMSOMMethod { - uint32_t m_uHash; const wchar_t* m_wsSomMethodName; uint32_t m_dParameters; }; + const XFA_FMSOMMethod gs_FMSomMethods[] = { - {0x00000068, L"h", 0x01}, - {0x00000077, L"w", 0x01}, - {0x00000078, L"x", 0x01}, - {0x00000079, L"y", 0x01}, - {0x05eb5b0f, L"pageSpan", 0x01}, - {0x10f1b1bd, L"page", 0x01}, - {0x3bf1c2a5, L"absPageSpan", 0x01}, - {0x3c752495, L"verify", 0x0d}, - {0x44c352ad, L"formNodes", 0x01}, - {0x5775c2cc, L"absPageInBatch", 0x01}, - {0x5ee00996, L"setElement", 0x01}, - {0x7033bfd5, L"insert", 0x03}, - {0x8c5feb32, L"sheetInBatch", 0x01}, - {0x8f3a8379, L"sheet", 0x01}, - {0x92dada4f, L"saveFilteredXML", 0x01}, - {0x9cab7cae, L"remove", 0x01}, - {0xa68635f1, L"sign", 0x61}, - {0xaac241c8, L"isRecordGroup", 0x01}, - {0xd8ed1467, L"clear", 0x01}, - {0xda12e518, L"append", 0x01}, - {0xe74f0653, L"absPage", 0x01}, + {L"absPage", 0x01}, + {L"absPageInBatch", 0x01}, + {L"absPageSpan", 0x01}, + {L"append", 0x01}, + {L"clear", 0x01}, + {L"formNodes", 0x01}, + {L"h", 0x01}, + {L"insert", 0x03}, + {L"isRecordGroup", 0x01}, + {L"page", 0x01}, + {L"pageSpan", 0x01}, + {L"remove", 0x01}, + {L"saveFilteredXML", 0x01}, + {L"setElement", 0x01}, + {L"sheet", 0x01}, + {L"sheetInBatch", 0x01}, + {L"sign", 0x61}, + {L"verify", 0x0d}, + {L"w", 0x01}, + {L"x", 0x01}, + {L"y", 0x01}, }; } // namespace @@ -533,43 +516,38 @@ CXFA_FMCallExpression::CXFA_FMCallExpression( CXFA_FMCallExpression::~CXFA_FMCallExpression() {} -bool CXFA_FMCallExpression::IsBuildInFunc(CFX_WideTextBuf* funcName) { - uint32_t uHash = FX_HashCode_GetW(funcName->AsStringC(), true); - const XFA_FMBuildInFunc* pEnd = g_BuildInFuncs + FX_ArraySize(g_BuildInFuncs); - const XFA_FMBuildInFunc* pFunc = - std::lower_bound(g_BuildInFuncs, pEnd, uHash, - [](const XFA_FMBuildInFunc& func, uint32_t hash) { - return func.m_uHash < hash; - }); - if (pFunc < pEnd && uHash == pFunc->m_uHash) { +bool CXFA_FMCallExpression::IsBuiltInFunc(CFX_WideTextBuf* funcName) { + if (funcName->GetLength() > g_BuiltInFuncsMaxLen) + return false; + + auto cmpFunc = [](const wchar_t* iter, const CFX_WideString& val) -> bool { + return val.CompareNoCase(iter) > 0; + }; + CFX_WideString str = funcName->MakeString(); + const wchar_t* const* pMatchResult = std::lower_bound( + std::begin(g_BuiltInFuncs), std::end(g_BuiltInFuncs), str, cmpFunc); + if (pMatchResult != std::end(g_BuiltInFuncs) && + !str.CompareNoCase(*pMatchResult)) { funcName->Clear(); - *funcName << pFunc->m_buildinfunc; + *funcName << *pMatchResult; return true; } return false; } uint32_t CXFA_FMCallExpression::IsMethodWithObjParam( - const CFX_WideStringC& methodName) { - uint32_t uHash = FX_HashCode_GetW(methodName, false); - XFA_FMSOMMethod somMethodWithObjPara; - uint32_t parameters = 0x00; - int32_t iStart = 0, - iEnd = (sizeof(gs_FMSomMethods) / sizeof(gs_FMSomMethods[0])) - 1; - int32_t iMid = (iStart + iEnd) / 2; - do { - iMid = (iStart + iEnd) / 2; - somMethodWithObjPara = gs_FMSomMethods[iMid]; - if (uHash == somMethodWithObjPara.m_uHash) { - parameters = somMethodWithObjPara.m_dParameters; - break; - } else if (uHash < somMethodWithObjPara.m_uHash) { - iEnd = iMid - 1; - } else { - iStart = iMid + 1; - } - } while (iStart <= iEnd); - return parameters; + const CFX_WideString& methodName) { + auto cmpFunc = [](const XFA_FMSOMMethod iter, const CFX_WideString& val) { + return val.Compare(iter.m_wsSomMethodName) > 0; + }; + const XFA_FMSOMMethod* result = + std::lower_bound(std::begin(gs_FMSomMethods), std::end(gs_FMSomMethods), + methodName, cmpFunc); + if (result != std::end(gs_FMSomMethods) && + !methodName.Compare(result->m_wsSomMethodName)) { + return result->m_dParameters; + } + return 0; } bool CXFA_FMCallExpression::ToJavaScript(CFX_WideTextBuf& javascript) { @@ -579,7 +557,7 @@ bool CXFA_FMCallExpression::ToJavaScript(CFX_WideTextBuf& javascript) { if (m_bIsSomMethod) { javascript << funcName; javascript << L"("; - uint32_t methodPara = IsMethodWithObjParam(funcName.AsStringC()); + uint32_t methodPara = IsMethodWithObjParam(funcName.MakeString()); if (methodPara > 0) { for (size_t i = 0; i < m_Arguments.size(); ++i) { // Currently none of our expressions use objects for a parameter over @@ -618,7 +596,7 @@ bool CXFA_FMCallExpression::ToJavaScript(CFX_WideTextBuf& javascript) { } else { bool isEvalFunc = false; bool isExistsFunc = false; - if (IsBuildInFunc(&funcName)) { + if (IsBuiltInFunc(&funcName)) { if (funcName.AsStringC() == L"Eval") { isEvalFunc = true; javascript << L"eval.call(this, "; @@ -633,7 +611,11 @@ bool CXFA_FMCallExpression::ToJavaScript(CFX_WideTextBuf& javascript) { javascript << funcName; } } else { - javascript << funcName; + // If a function is not a SomMethod or a built-in then the input was + // invalid, so failing. The scanner/lexer should catch this, but currently + // doesn't. This failure will bubble up to the top-level and cause the + // transpile to fail. + return false; } javascript << L"("; if (isExistsFunc) { diff --git a/chromium/third_party/pdfium/xfa/fxfa/fm2js/cxfa_fmsimpleexpression.h b/chromium/third_party/pdfium/xfa/fxfa/fm2js/cxfa_fmsimpleexpression.h index 8cdaf35b0f3..e47334926dd 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/fm2js/cxfa_fmsimpleexpression.h +++ b/chromium/third_party/pdfium/xfa/fxfa/fm2js/cxfa_fmsimpleexpression.h @@ -238,8 +238,8 @@ class CXFA_FMCallExpression : public CXFA_FMUnaryExpression { bool bIsSomMethod); ~CXFA_FMCallExpression() override; - bool IsBuildInFunc(CFX_WideTextBuf* funcName); - uint32_t IsMethodWithObjParam(const CFX_WideStringC& methodName); + bool IsBuiltInFunc(CFX_WideTextBuf* funcName); + uint32_t IsMethodWithObjParam(const CFX_WideString& methodName); bool ToJavaScript(CFX_WideTextBuf& javascript) override; private: diff --git a/chromium/third_party/pdfium/xfa/fxfa/fxfa.h b/chromium/third_party/pdfium/xfa/fxfa/fxfa.h index 6dd901eaf47..3e78ed2f952 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/fxfa.h +++ b/chromium/third_party/pdfium/xfa/fxfa/fxfa.h @@ -14,7 +14,7 @@ #include "xfa/fxfa/fxfa_basic.h" class CFGAS_GEFont; -class CFX_Graphics; +class CXFA_Graphics; class CPDF_Document; class CXFA_FFPageView; class CXFA_Node; diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_eventpseudomodel.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_eventpseudomodel.cpp index c57b0bdc781..ede59871f15 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_eventpseudomodel.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_eventpseudomodel.cpp @@ -7,7 +7,7 @@ #include "xfa/fxfa/parser/cscript_eventpseudomodel.h" #include "fxjs/cfxjse_arguments.h" -#include "xfa/fxfa/app/xfa_ffnotify.h" +#include "xfa/fxfa/app/cxfa_ffnotify.h" #include "xfa/fxfa/cxfa_eventparam.h" #include "xfa/fxfa/cxfa_ffwidgethandler.h" #include "xfa/fxfa/parser/cxfa_document.h" diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_hostpseudomodel.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_hostpseudomodel.cpp index d2633ec4aee..d9eb5d699fc 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_hostpseudomodel.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_hostpseudomodel.cpp @@ -9,7 +9,7 @@ #include <memory> #include "fxjs/cfxjse_arguments.h" -#include "xfa/fxfa/app/xfa_ffnotify.h" +#include "xfa/fxfa/app/cxfa_ffnotify.h" #include "xfa/fxfa/parser/cxfa_document.h" #include "xfa/fxfa/parser/cxfa_layoutprocessor.h" #include "xfa/fxfa/parser/cxfa_localemgr.h" @@ -325,7 +325,7 @@ static int32_t XFA_FilterName(const CFX_WideStringC& wsExpression, } wchar_t* pBuf = wsFilter.GetBuffer(iLength - nStart); int32_t nCount = 0; - const wchar_t* pSrc = wsExpression.c_str(); + const wchar_t* pSrc = wsExpression.unterminated_c_str(); wchar_t wCur; while (nStart < iLength) { wCur = pSrc[nStart++]; diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_layoutpseudomodel.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_layoutpseudomodel.cpp index 6e6a1086ff9..130c9f0843d 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_layoutpseudomodel.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_layoutpseudomodel.cpp @@ -10,7 +10,7 @@ #include "fxjs/cfxjse_arguments.h" #include "third_party/base/stl_util.h" -#include "xfa/fxfa/app/xfa_ffnotify.h" +#include "xfa/fxfa/app/cxfa_ffnotify.h" #include "xfa/fxfa/parser/cxfa_arraynodelist.h" #include "xfa/fxfa/parser/cxfa_containerlayoutitem.h" #include "xfa/fxfa/parser/cxfa_contentlayoutitem.h" diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_signaturepseudomodel.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_signaturepseudomodel.cpp index 0886809db1b..023d3e541f7 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_signaturepseudomodel.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_signaturepseudomodel.cpp @@ -7,7 +7,7 @@ #include "xfa/fxfa/parser/cscript_signaturepseudomodel.h" #include "fxjs/cfxjse_arguments.h" -#include "xfa/fxfa/app/xfa_ffnotify.h" +#include "xfa/fxfa/app/cxfa_ffnotify.h" #include "xfa/fxfa/parser/cxfa_document.h" #include "xfa/fxfa/parser/cxfa_localemgr.h" #include "xfa/fxfa/parser/cxfa_scriptcontext.h" diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_data.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_data.cpp index bdfc25c79c6..7bf18a5d3e9 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_data.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_data.cpp @@ -17,7 +17,7 @@ FX_ARGB CXFA_Data::ToColor(const CFX_WideStringC& wsValue) { return 0xff000000; int cc = 0; - const wchar_t* str = wsValue.c_str(); + const wchar_t* str = wsValue.unterminated_c_str(); int len = wsValue.GetLength(); while (FXSYS_iswspace(str[cc]) && cc < len) cc++; diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_document.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_document.cpp index a1180e7b8ea..ec80866bb0a 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_document.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_document.cpp @@ -7,7 +7,7 @@ #include "xfa/fxfa/parser/cxfa_document.h" #include "core/fxcrt/fx_extension.h" -#include "xfa/fxfa/app/xfa_ffnotify.h" +#include "xfa/fxfa/app/cxfa_ffnotify.h" #include "xfa/fxfa/parser/cscript_datawindow.h" #include "xfa/fxfa/parser/cscript_eventpseudomodel.h" #include "xfa/fxfa/parser/cscript_hostpseudomodel.h" diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp index b2e4e725a74..694b24dc279 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp @@ -14,7 +14,7 @@ #include "third_party/base/logging.h" #include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" -#include "xfa/fxfa/app/xfa_ffnotify.h" +#include "xfa/fxfa/app/cxfa_ffnotify.h" #include "xfa/fxfa/parser/cxfa_containerlayoutitem.h" #include "xfa/fxfa/parser/cxfa_contentlayoutitem.h" #include "xfa/fxfa/parser/cxfa_document.h" @@ -1748,7 +1748,7 @@ void CXFA_ItemLayoutProcessor::DoLayoutTableContainer(CXFA_Node* pLayoutNode) { : containerSize.width - fLeftInset - fRightInset; CFX_WideStringC wsColumnWidths; if (pLayoutNode->TryCData(XFA_ATTRIBUTE_ColumnWidths, wsColumnWidths)) { - auto widths = SeparateStringW(wsColumnWidths.c_str(), + auto widths = SeparateStringW(wsColumnWidths.unterminated_c_str(), wsColumnWidths.GetLength(), L' '); for (auto& width : widths) { width.TrimLeft(L' '); diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_layoutitem.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_layoutitem.cpp index 2bac7950ef6..a769da0f2ab 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_layoutitem.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_layoutitem.cpp @@ -6,7 +6,7 @@ #include "xfa/fxfa/parser/cxfa_layoutitem.h" -#include "xfa/fxfa/app/xfa_ffnotify.h" +#include "xfa/fxfa/app/cxfa_ffnotify.h" #include "xfa/fxfa/parser/cxfa_containerlayoutitem.h" #include "xfa/fxfa/parser/cxfa_contentlayoutitem.h" #include "xfa/fxfa/parser/cxfa_measurement.h" diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp index 5c94a6a2568..0bf091ed34c 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp @@ -7,7 +7,7 @@ #include "xfa/fxfa/parser/cxfa_layoutpagemgr.h" #include "third_party/base/stl_util.h" -#include "xfa/fxfa/app/xfa_ffnotify.h" +#include "xfa/fxfa/app/cxfa_ffnotify.h" #include "xfa/fxfa/parser/cxfa_containerlayoutitem.h" #include "xfa/fxfa/parser/cxfa_contentlayoutitem.h" #include "xfa/fxfa/parser/cxfa_document.h" diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_localemgr.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_localemgr.cpp index fbb12e2b48a..633f4b41fdb 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_localemgr.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_localemgr.cpp @@ -36,6 +36,13 @@ #define FX_LANG_es_LA 0x080a #define FX_LANG_es_ES 0x0c0a +// These arrays are the hex encoded XML strings which define the locale. +// <locale name="en_US" desc="English(America)"> +// <calendarSymbols name="gregorian"> +// <monthNames> +// <month>January</month> +// <month>February</month> +// ... const uint8_t g_enUS_Locale[] = { 0x78, 0x9C, 0x95, 0x56, 0xD1, 0x6E, 0x9B, 0x30, 0x14, 0x7D, 0x9F, 0xB4, 0x7F, 0x40, 0xD6, 0x2A, 0xB5, 0x52, 0x56, 0x6F, 0x8F, 0xA9, 0x88, 0xA5, @@ -1061,7 +1068,7 @@ static std::unique_ptr<IFX_Locale> XFA_GetLocaleFromBuffer(const uint8_t* pBuf, uint32_t dwSize; CCodec_ModuleMgr* pCodecMgr = CPDF_ModuleMgr::Get()->GetCodecModule(); pCodecMgr->GetFlateModule()->FlateOrLZWDecode(false, pBuf, nBufLen, true, 0, - 0, 0, 0, 0, pOut, dwSize); + 0, 0, 0, 0, &pOut, &dwSize); if (!pOut) return nullptr; diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_localevalue.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_localevalue.cpp index d2e526eb958..5b5c27f1d45 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_localevalue.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_localevalue.cpp @@ -16,41 +16,83 @@ #include "xfa/fxfa/parser/cxfa_localemgr.h" #include "xfa/fxfa/parser/xfa_utils.h" -CXFA_LocaleValue::CXFA_LocaleValue() { - m_dwType = XFA_VT_NULL; - m_bValid = true; - m_pLocaleMgr = nullptr; -} -CXFA_LocaleValue::CXFA_LocaleValue(const CXFA_LocaleValue& value) { - m_dwType = XFA_VT_NULL; - m_bValid = true; - m_pLocaleMgr = nullptr; - *this = value; -} -CXFA_LocaleValue::CXFA_LocaleValue(uint32_t dwType, - CXFA_LocaleMgr* pLocaleMgr) { - m_dwType = dwType; - m_bValid = (m_dwType != XFA_VT_NULL); - m_pLocaleMgr = pLocaleMgr; +namespace { + +FX_LOCALECATEGORY ValueCategory(FX_LOCALECATEGORY eCategory, + uint32_t dwValueType) { + if (eCategory != FX_LOCALECATEGORY_Unknown) + return eCategory; + + switch (dwValueType) { + case XFA_VT_BOOLEAN: + case XFA_VT_INTEGER: + case XFA_VT_DECIMAL: + case XFA_VT_FLOAT: + return FX_LOCALECATEGORY_Num; + case XFA_VT_TEXT: + return FX_LOCALECATEGORY_Text; + case XFA_VT_DATE: + return FX_LOCALECATEGORY_Date; + case XFA_VT_TIME: + return FX_LOCALECATEGORY_Time; + case XFA_VT_DATETIME: + return FX_LOCALECATEGORY_DateTime; + } + return FX_LOCALECATEGORY_Unknown; +} + +bool ValueSplitDateTime(const CFX_WideString& wsDateTime, + CFX_WideString& wsDate, + CFX_WideString& wsTime) { + wsDate = L""; + wsTime = L""; + if (wsDateTime.IsEmpty()) + return false; + + int nSplitIndex = wsDateTime.Find('T'); + if (nSplitIndex < 0) + nSplitIndex = wsDateTime.Find(' '); + if (nSplitIndex < 0) + return false; + + wsDate = wsDateTime.Left(nSplitIndex); + wsTime = wsDateTime.Right(wsDateTime.GetLength() - nSplitIndex - 1); + return true; } + +} // namespace + +CXFA_LocaleValue::CXFA_LocaleValue() + : m_pLocaleMgr(nullptr), m_dwType(XFA_VT_NULL), m_bValid(true) {} + +CXFA_LocaleValue::CXFA_LocaleValue(const CXFA_LocaleValue& value) + : m_pLocaleMgr(value.m_pLocaleMgr), + m_wsValue(value.m_wsValue), + m_dwType(value.m_dwType), + m_bValid(value.m_bValid) {} + +CXFA_LocaleValue::CXFA_LocaleValue(uint32_t dwType, CXFA_LocaleMgr* pLocaleMgr) + : m_pLocaleMgr(pLocaleMgr), + m_dwType(dwType), + m_bValid(m_dwType != XFA_VT_NULL) {} + CXFA_LocaleValue::CXFA_LocaleValue(uint32_t dwType, const CFX_WideString& wsValue, - CXFA_LocaleMgr* pLocaleMgr) { - m_wsValue = wsValue; - m_dwType = dwType; - m_pLocaleMgr = pLocaleMgr; - m_bValid = ValidateCanonicalValue(wsValue, dwType); -} + CXFA_LocaleMgr* pLocaleMgr) + : m_pLocaleMgr(pLocaleMgr), + m_wsValue(wsValue), + m_dwType(dwType), + m_bValid(ValidateCanonicalValue(wsValue, dwType)) {} + CXFA_LocaleValue::CXFA_LocaleValue(uint32_t dwType, const CFX_WideString& wsValue, const CFX_WideString& wsFormat, IFX_Locale* pLocale, - CXFA_LocaleMgr* pLocaleMgr) { - m_pLocaleMgr = pLocaleMgr; - m_bValid = true; - m_dwType = dwType; - m_bValid = ParsePatternValue(wsValue, wsFormat, pLocale); -} + CXFA_LocaleMgr* pLocaleMgr) + : m_pLocaleMgr(pLocaleMgr), + m_dwType(dwType), + m_bValid(ParsePatternValue(wsValue, wsFormat, pLocale)) {} + CXFA_LocaleValue& CXFA_LocaleValue::operator=(const CXFA_LocaleValue& value) { m_wsValue = value.m_wsValue; m_dwType = value.m_dwType; @@ -58,28 +100,8 @@ CXFA_LocaleValue& CXFA_LocaleValue::operator=(const CXFA_LocaleValue& value) { m_pLocaleMgr = value.m_pLocaleMgr; return *this; } + CXFA_LocaleValue::~CXFA_LocaleValue() {} -static FX_LOCALECATEGORY XFA_ValugeCategory(FX_LOCALECATEGORY eCategory, - uint32_t dwValueType) { - if (eCategory == FX_LOCALECATEGORY_Unknown) { - switch (dwValueType) { - case XFA_VT_BOOLEAN: - case XFA_VT_INTEGER: - case XFA_VT_DECIMAL: - case XFA_VT_FLOAT: - return FX_LOCALECATEGORY_Num; - case XFA_VT_TEXT: - return FX_LOCALECATEGORY_Text; - case XFA_VT_DATE: - return FX_LOCALECATEGORY_Date; - case XFA_VT_TIME: - return FX_LOCALECATEGORY_Time; - case XFA_VT_DATETIME: - return FX_LOCALECATEGORY_DateTime; - } - } - return eCategory; -} bool CXFA_LocaleValue::ValidateValue(const CFX_WideString& wsValue, const CFX_WideString& wsPattern, @@ -92,42 +114,36 @@ bool CXFA_LocaleValue::ValidateValue(const CFX_WideString& wsValue, auto pFormat = pdfium::MakeUnique<CFGAS_FormatString>(m_pLocaleMgr); std::vector<CFX_WideString> wsPatterns; - pFormat->SplitFormatString(wsPattern, wsPatterns); + pFormat->SplitFormatString(wsPattern, &wsPatterns); bool bRet = false; int32_t iCount = pdfium::CollectionSize<int32_t>(wsPatterns); int32_t i = 0; for (; i < iCount && !bRet; i++) { CFX_WideString wsFormat = wsPatterns[i]; - FX_LOCALECATEGORY eCategory = pFormat->GetCategory(wsFormat); - eCategory = XFA_ValugeCategory(eCategory, m_dwType); - switch (eCategory) { + switch (ValueCategory(pFormat->GetCategory(wsFormat), m_dwType)) { case FX_LOCALECATEGORY_Null: bRet = pFormat->ParseNull(wsValue, wsFormat); - if (!bRet) { + if (!bRet) bRet = wsValue.IsEmpty(); - } break; case FX_LOCALECATEGORY_Zero: bRet = pFormat->ParseZero(wsValue, wsFormat); - if (!bRet) { + if (!bRet) bRet = wsValue == L"0"; - } break; case FX_LOCALECATEGORY_Num: { CFX_WideString fNum; - bRet = pFormat->ParseNum(wsValue, wsFormat, fNum); - if (!bRet) { - bRet = pFormat->FormatNum(wsValue, wsFormat, wsOutput); - } + bRet = pFormat->ParseNum(wsValue, wsFormat, &fNum); + if (!bRet) + bRet = pFormat->FormatNum(wsValue, wsFormat, &wsOutput); break; } case FX_LOCALECATEGORY_Text: - bRet = pFormat->ParseText(wsValue, wsFormat, wsOutput); + bRet = pFormat->ParseText(wsValue, wsFormat, &wsOutput); wsOutput.clear(); - if (!bRet) { - bRet = pFormat->FormatText(wsValue, wsFormat, wsOutput); - } + if (!bRet) + bRet = pFormat->FormatText(wsValue, wsFormat, &wsOutput); break; case FX_LOCALECATEGORY_Date: { CFX_DateTime dt; @@ -136,8 +152,8 @@ bool CXFA_LocaleValue::ValidateValue(const CFX_WideString& wsValue, bRet = pFormat->ParseDateTime(wsValue, wsFormat, FX_DATETIMETYPE_Date, &dt); if (!bRet) { - bRet = pFormat->FormatDateTime(wsValue, wsFormat, wsOutput, - FX_DATETIMETYPE_Date); + bRet = pFormat->FormatDateTime(wsValue, wsFormat, + FX_DATETIMETYPE_Date, &wsOutput); } } break; @@ -147,8 +163,8 @@ bool CXFA_LocaleValue::ValidateValue(const CFX_WideString& wsValue, bRet = pFormat->ParseDateTime(wsValue, wsFormat, FX_DATETIMETYPE_Time, &dt); if (!bRet) { - bRet = pFormat->FormatDateTime(wsValue, wsFormat, wsOutput, - FX_DATETIMETYPE_Time); + bRet = pFormat->FormatDateTime(wsValue, wsFormat, + FX_DATETIMETYPE_Time, &wsOutput); } break; } @@ -157,8 +173,8 @@ bool CXFA_LocaleValue::ValidateValue(const CFX_WideString& wsValue, bRet = pFormat->ParseDateTime(wsValue, wsFormat, FX_DATETIMETYPE_DateTime, &dt); if (!bRet) { - bRet = pFormat->FormatDateTime(wsValue, wsFormat, wsOutput, - FX_DATETIMETYPE_DateTime); + bRet = pFormat->FormatDateTime(wsValue, wsFormat, + FX_DATETIMETYPE_DateTime, &wsOutput); } break; } @@ -169,106 +185,12 @@ bool CXFA_LocaleValue::ValidateValue(const CFX_WideString& wsValue, } if (bRet && pMatchFormat) *pMatchFormat = wsPatterns[i - 1]; - if (pLocale) m_pLocaleMgr->SetDefLocale(locale); return bRet; } -CFX_WideString CXFA_LocaleValue::GetValue() const { - return m_wsValue; -} -uint32_t CXFA_LocaleValue::GetType() const { - return m_dwType; -} -void CXFA_LocaleValue::SetValue(const CFX_WideString& wsValue, - uint32_t dwType) { - m_wsValue = wsValue; - m_dwType = dwType; -} -CFX_WideString CXFA_LocaleValue::GetText() const { - if (m_bValid && m_dwType == XFA_VT_TEXT) { - return m_wsValue; - } - return CFX_WideString(); -} -float CXFA_LocaleValue::GetNum() const { - if (m_bValid && (m_dwType == XFA_VT_BOOLEAN || m_dwType == XFA_VT_INTEGER || - m_dwType == XFA_VT_DECIMAL || m_dwType == XFA_VT_FLOAT)) { - int64_t nIntegral = 0; - uint32_t dwFractional = 0; - int32_t nExponent = 0; - int cc = 0; - bool bNegative = false, bExpSign = false; - const wchar_t* str = m_wsValue.c_str(); - int len = m_wsValue.GetLength(); - while (FXSYS_iswspace(str[cc]) && cc < len) { - cc++; - } - if (cc >= len) { - return 0; - } - if (str[0] == '+') { - cc++; - } else if (str[0] == '-') { - bNegative = true; - cc++; - } - int nIntegralLen = 0; - while (cc < len) { - if (str[cc] == '.' || !FXSYS_isDecimalDigit(str[cc]) || - nIntegralLen > 17) { - break; - } - nIntegral = nIntegral * 10 + str[cc] - '0'; - cc++; - nIntegralLen++; - } - nIntegral = bNegative ? -nIntegral : nIntegral; - int scale = 0; - double fraction = 0.0; - if (cc < len && str[cc] == '.') { - cc++; - while (cc < len) { - fraction += XFA_GetFractionalScale(scale) * (str[cc] - '0'); - scale++; - cc++; - if (scale == XFA_GetMaxFractionalScale() || - !FXSYS_isDecimalDigit(str[cc])) { - break; - } - } - dwFractional = (uint32_t)(fraction * 4294967296.0); - } - if (cc < len && (str[cc] == 'E' || str[cc] == 'e')) { - cc++; - if (cc < len) { - if (str[cc] == '+') { - cc++; - } else if (str[cc] == '-') { - bExpSign = true; - cc++; - } - } - while (cc < len) { - if (str[cc] == '.' || !FXSYS_isDecimalDigit(str[cc])) { - break; - } - nExponent = nExponent * 10 + str[cc] - '0'; - cc++; - } - nExponent = bExpSign ? -nExponent : nExponent; - } - float fValue = (float)(dwFractional / 4294967296.0); - fValue = nIntegral + (nIntegral >= 0 ? fValue : -fValue); - if (nExponent != 0) { - fValue *= FXSYS_pow(10, (float)nExponent); - } - return fValue; - } - return 0; -} double CXFA_LocaleValue::GetDoubleNum() const { if (m_bValid && (m_dwType == XFA_VT_BOOLEAN || m_dwType == XFA_VT_INTEGER || m_dwType == XFA_VT_DECIMAL || m_dwType == XFA_VT_FLOAT)) { @@ -276,7 +198,8 @@ double CXFA_LocaleValue::GetDoubleNum() const { uint32_t dwFractional = 0; int32_t nExponent = 0; int32_t cc = 0; - bool bNegative = false, bExpSign = false; + bool bNegative = false; + bool bExpSign = false; const wchar_t* str = m_wsValue.c_str(); int len = m_wsValue.GetLength(); while (FXSYS_iswspace(str[cc]) && cc < len) @@ -301,6 +224,7 @@ double CXFA_LocaleValue::GetDoubleNum() const { cc++; nIntegralLen++; } + nIntegral = bNegative ? -nIntegral : nIntegral; int32_t scale = 0; double fraction = 0.0; @@ -348,64 +272,22 @@ double CXFA_LocaleValue::GetDoubleNum() const { } CFX_DateTime CXFA_LocaleValue::GetDate() const { - if (m_bValid && m_dwType == XFA_VT_DATE) { - CFX_DateTime dt; - FX_DateFromCanonical(m_wsValue, &dt); - return dt; - } - return CFX_DateTime(); -} - -CFX_DateTime CXFA_LocaleValue::GetTime() const { - if (m_bValid && m_dwType == XFA_VT_TIME) { - ASSERT(m_pLocaleMgr); - - CFX_DateTime dt; - FX_TimeFromCanonical(m_wsValue.AsStringC(), &dt, - m_pLocaleMgr->GetDefLocale()); - return dt; - } - return CFX_DateTime(); -} - -CFX_DateTime CXFA_LocaleValue::GetDateTime() const { - if (m_bValid && m_dwType == XFA_VT_DATETIME) { - int32_t index = m_wsValue.Find('T'); - CFX_DateTime dt; - FX_DateFromCanonical(m_wsValue.Left(index), &dt); - ASSERT(m_pLocaleMgr); - FX_TimeFromCanonical( - m_wsValue.Right(m_wsValue.GetLength() - index - 1).AsStringC(), &dt, - m_pLocaleMgr->GetDefLocale()); - return dt; - } - return CFX_DateTime(); -} + if (!m_bValid || m_dwType != XFA_VT_DATE) + return CFX_DateTime(); -bool CXFA_LocaleValue::SetText(const CFX_WideString& wsText) { - m_dwType = XFA_VT_TEXT; - m_wsValue = wsText; - return true; -} - -bool CXFA_LocaleValue::SetText(const CFX_WideString& wsText, - const CFX_WideString& wsFormat, - IFX_Locale* pLocale) { - m_dwType = XFA_VT_TEXT; - return m_bValid = ParsePatternValue(wsText, wsFormat, pLocale); + CFX_DateTime dt; + FX_DateFromCanonical(m_wsValue, &dt); + return dt; } -bool CXFA_LocaleValue::SetNum(float fNum) { - m_dwType = XFA_VT_FLOAT; - m_wsValue.Format(L"%.8g", static_cast<double>(fNum)); - return true; -} +CFX_DateTime CXFA_LocaleValue::GetTime() const { + if (!m_bValid || m_dwType != XFA_VT_TIME) + return CFX_DateTime(); -bool CXFA_LocaleValue::SetNum(const CFX_WideString& wsNum, - const CFX_WideString& wsFormat, - IFX_Locale* pLocale) { - m_dwType = XFA_VT_FLOAT; - return m_bValid = ParsePatternValue(wsNum, wsFormat, pLocale); + CFX_DateTime dt; + FX_TimeFromCanonical(m_wsValue.AsStringC(), &dt, + m_pLocaleMgr->GetDefLocale()); + return dt; } bool CXFA_LocaleValue::SetDate(const CFX_DateTime& d) { @@ -414,13 +296,6 @@ bool CXFA_LocaleValue::SetDate(const CFX_DateTime& d) { return true; } -bool CXFA_LocaleValue::SetDate(const CFX_WideString& wsDate, - const CFX_WideString& wsFormat, - IFX_Locale* pLocale) { - m_dwType = XFA_VT_DATE; - return m_bValid = ParsePatternValue(wsDate, wsFormat, pLocale); -} - bool CXFA_LocaleValue::SetTime(const CFX_DateTime& t) { m_dwType = XFA_VT_TIME; m_wsValue.Format(L"%02d:%02d:%02d", t.GetHour(), t.GetMinute(), @@ -433,13 +308,6 @@ bool CXFA_LocaleValue::SetTime(const CFX_DateTime& t) { return true; } -bool CXFA_LocaleValue::SetTime(const CFX_WideString& wsTime, - const CFX_WideString& wsFormat, - IFX_Locale* pLocale) { - m_dwType = XFA_VT_TIME; - return m_bValid = ParsePatternValue(wsTime, wsFormat, pLocale); -} - bool CXFA_LocaleValue::SetDateTime(const CFX_DateTime& dt) { m_dwType = XFA_VT_DATETIME; m_wsValue.Format(L"%04d-%02d-%02dT%02d:%02d:%02d", dt.GetYear(), @@ -453,20 +321,13 @@ bool CXFA_LocaleValue::SetDateTime(const CFX_DateTime& dt) { return true; } -bool CXFA_LocaleValue::SetDateTime(const CFX_WideString& wsDateTime, - const CFX_WideString& wsFormat, - IFX_Locale* pLocale) { - m_dwType = XFA_VT_DATETIME; - return m_bValid = ParsePatternValue(wsDateTime, wsFormat, pLocale); -} - bool CXFA_LocaleValue::FormatPatterns(CFX_WideString& wsResult, const CFX_WideString& wsFormat, IFX_Locale* pLocale, XFA_VALUEPICTURE eValueType) const { auto pFormat = pdfium::MakeUnique<CFGAS_FormatString>(m_pLocaleMgr); std::vector<CFX_WideString> wsPatterns; - pFormat->SplitFormatString(wsFormat, wsPatterns); + pFormat->SplitFormatString(wsFormat, &wsPatterns); wsResult.clear(); int32_t iCount = pdfium::CollectionSize<int32_t>(wsPatterns); for (int32_t i = 0; i < iCount; i++) { @@ -487,36 +348,34 @@ bool CXFA_LocaleValue::FormatSinglePattern(CFX_WideString& wsResult, wsResult.clear(); bool bRet = false; auto pFormat = pdfium::MakeUnique<CFGAS_FormatString>(m_pLocaleMgr); - FX_LOCALECATEGORY eCategory = pFormat->GetCategory(wsFormat); - eCategory = XFA_ValugeCategory(eCategory, m_dwType); + FX_LOCALECATEGORY eCategory = + ValueCategory(pFormat->GetCategory(wsFormat), m_dwType); switch (eCategory) { case FX_LOCALECATEGORY_Null: - if (m_wsValue.IsEmpty()) { - bRet = pFormat->FormatNull(wsFormat, wsResult); - } + if (m_wsValue.IsEmpty()) + bRet = pFormat->FormatNull(wsFormat, &wsResult); break; case FX_LOCALECATEGORY_Zero: - if (m_wsValue == L"0") { - bRet = pFormat->FormatZero(wsFormat, wsResult); - } + if (m_wsValue == L"0") + bRet = pFormat->FormatZero(wsFormat, &wsResult); break; case FX_LOCALECATEGORY_Num: - bRet = pFormat->FormatNum(m_wsValue, wsFormat, wsResult); + bRet = pFormat->FormatNum(m_wsValue, wsFormat, &wsResult); break; case FX_LOCALECATEGORY_Text: - bRet = pFormat->FormatText(m_wsValue, wsFormat, wsResult); + bRet = pFormat->FormatText(m_wsValue, wsFormat, &wsResult); break; case FX_LOCALECATEGORY_Date: - bRet = pFormat->FormatDateTime(m_wsValue, wsFormat, wsResult, - FX_DATETIMETYPE_Date); + bRet = pFormat->FormatDateTime(m_wsValue, wsFormat, FX_DATETIMETYPE_Date, + &wsResult); break; case FX_LOCALECATEGORY_Time: - bRet = pFormat->FormatDateTime(m_wsValue, wsFormat, wsResult, - FX_DATETIMETYPE_Time); + bRet = pFormat->FormatDateTime(m_wsValue, wsFormat, FX_DATETIMETYPE_Time, + &wsResult); break; case FX_LOCALECATEGORY_DateTime: - bRet = pFormat->FormatDateTime(m_wsValue, wsFormat, wsResult, - FX_DATETIMETYPE_DateTime); + bRet = pFormat->FormatDateTime(m_wsValue, wsFormat, + FX_DATETIMETYPE_DateTime, &wsResult); break; default: wsResult = m_wsValue; @@ -532,39 +391,20 @@ bool CXFA_LocaleValue::FormatSinglePattern(CFX_WideString& wsResult, return bRet; } -static bool XFA_ValueSplitDateTime(const CFX_WideString& wsDateTime, - CFX_WideString& wsDate, - CFX_WideString& wsTime) { - wsDate = L""; - wsTime = L""; - if (wsDateTime.IsEmpty()) { - return false; - } - int nSplitIndex = -1; - nSplitIndex = wsDateTime.Find('T'); - if (nSplitIndex < 0) { - nSplitIndex = wsDateTime.Find(' '); - } - if (nSplitIndex < 0) { - return false; - } - wsDate = wsDateTime.Left(nSplitIndex); - wsTime = wsDateTime.Right(wsDateTime.GetLength() - nSplitIndex - 1); - return true; -} bool CXFA_LocaleValue::ValidateCanonicalValue(const CFX_WideString& wsValue, uint32_t dwVType) { - if (wsValue.IsEmpty()) { + if (wsValue.IsEmpty()) return true; - } + CFX_DateTime dt; switch (dwVType) { case XFA_VT_DATE: { if (ValidateCanonicalDate(wsValue, &dt)) return true; - CFX_WideString wsDate, wsTime; - if (XFA_ValueSplitDateTime(wsValue, wsDate, wsTime) && + CFX_WideString wsDate; + CFX_WideString wsTime; + if (ValueSplitDateTime(wsValue, wsDate, wsTime) && ValidateCanonicalDate(wsDate, &dt)) { return true; } @@ -574,8 +414,9 @@ bool CXFA_LocaleValue::ValidateCanonicalValue(const CFX_WideString& wsValue, if (ValidateCanonicalTime(wsValue)) return true; - CFX_WideString wsDate, wsTime; - if (XFA_ValueSplitDateTime(wsValue, wsDate, wsTime) && + CFX_WideString wsDate; + CFX_WideString wsTime; + if (ValueSplitDateTime(wsValue, wsDate, wsTime) && ValidateCanonicalTime(wsTime)) { return true; } @@ -583,7 +424,7 @@ bool CXFA_LocaleValue::ValidateCanonicalValue(const CFX_WideString& wsValue, } case XFA_VT_DATETIME: { CFX_WideString wsDate, wsTime; - if (XFA_ValueSplitDateTime(wsValue, wsDate, wsTime) && + if (ValueSplitDateTime(wsValue, wsDate, wsTime) && ValidateCanonicalDate(wsDate, &dt) && ValidateCanonicalTime(wsTime)) { return true; } @@ -591,82 +432,74 @@ bool CXFA_LocaleValue::ValidateCanonicalValue(const CFX_WideString& wsValue, } return true; } + bool CXFA_LocaleValue::ValidateCanonicalDate(const CFX_WideString& wsDate, CFX_DateTime* unDate) { - const uint16_t LastDay[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; - const uint16_t wCountY = 4, wCountM = 2, wCountD = 2; + static const uint16_t LastDay[12] = {31, 28, 31, 30, 31, 30, + 31, 31, 30, 31, 30, 31}; + static const uint16_t wCountY = 4; + static const uint16_t wCountM = 2; + static const uint16_t wCountD = 2; int nLen = wsDate.GetLength(); - if (nLen < wCountY || nLen > wCountY + wCountM + wCountD + 2) { + if (nLen < wCountY || nLen > wCountY + wCountM + wCountD + 2) return false; - } + const bool bSymbol = wsDate.Find(0x2D) != -1; uint16_t wYear = 0; uint16_t wMonth = 0; uint16_t wDay = 0; const wchar_t* pDate = wsDate.c_str(); - int nIndex = 0, nStart = 0; + int nIndex = 0; + int nStart = 0; while (pDate[nIndex] != '\0' && nIndex < wCountY) { - if (!FXSYS_isDecimalDigit(pDate[nIndex])) { + if (!FXSYS_isDecimalDigit(pDate[nIndex])) return false; - } + wYear = (pDate[nIndex] - '0') + wYear * 10; nIndex++; } if (bSymbol) { - if (pDate[nIndex] != 0x2D) { + if (pDate[nIndex] != 0x2D) return false; - } nIndex++; } + nStart = nIndex; while (pDate[nIndex] != '\0' && nIndex - nStart < wCountM && nIndex < nLen) { - if (!FXSYS_isDecimalDigit(pDate[nIndex])) { + if (!FXSYS_isDecimalDigit(pDate[nIndex])) return false; - } + wMonth = (pDate[nIndex] - '0') + wMonth * 10; nIndex++; } if (bSymbol) { - if (pDate[nIndex] != 0x2D) { + if (pDate[nIndex] != 0x2D) return false; - } nIndex++; } + nStart = nIndex; while (pDate[nIndex] != '\0' && nIndex - nStart < wCountD && nIndex < nLen) { - if (!FXSYS_isDecimalDigit(pDate[nIndex])) { + if (!FXSYS_isDecimalDigit(pDate[nIndex])) return false; - } + wDay = (pDate[nIndex] - '0') + wDay * 10; nIndex++; } - if (nIndex != nLen) { + if (nIndex != nLen) return false; - } - if (wYear < 1900 || wYear > 2029) { + if (wYear < 1900 || wYear > 2029) return false; - } - if (wMonth < 1 || wMonth > 12) { - if (wMonth == 0 && nLen == wCountY) { - return true; - } - return false; - } - if (wDay < 1) { - if (wDay == 0 && (nLen == wCountY + wCountM)) { - return true; - } - return false; - } + if (wMonth < 1 || wMonth > 12) + return wMonth == 0 && nLen == wCountY; + if (wDay < 1) + return wDay == 0 && (nLen == wCountY + wCountM); if (wMonth == 2) { if (wYear % 400 == 0 || (wYear % 100 != 0 && wYear % 4 == 0)) { - if (wDay > 29) { + if (wDay > 29) return false; - } - } else { - if (wDay > 28) { - return false; - } + } else if (wDay > 28) { + return false; } } else if (wDay > LastDay[wMonth - 1]) { return false; @@ -681,6 +514,7 @@ bool CXFA_LocaleValue::ValidateCanonicalTime(const CFX_WideString& wsTime) { int nLen = wsTime.GetLength(); if (nLen < 2) return false; + const uint16_t wCountH = 2; const uint16_t wCountM = 2; const uint16_t wCountS = 2; @@ -704,6 +538,7 @@ bool CXFA_LocaleValue::ValidateCanonicalTime(const CFX_WideString& wsTime) { return false; nIndex++; } + nStart = nIndex; while (nIndex - nStart < wCountM && nIndex < nLen && pTime[nIndex]) { if (!FXSYS_isDecimalDigit(pTime[nIndex])) @@ -769,25 +604,6 @@ bool CXFA_LocaleValue::ValidateCanonicalTime(const CFX_WideString& wsTime) { wFraction <= 999; } -bool CXFA_LocaleValue::ValidateCanonicalDateTime( - const CFX_WideString& wsDateTime) { - CFX_WideString wsDate, wsTime; - if (wsDateTime.IsEmpty()) - return false; - - int nSplitIndex = -1; - nSplitIndex = wsDateTime.Find('T'); - if (nSplitIndex < 0) - nSplitIndex = wsDateTime.Find(' '); - if (nSplitIndex < 0) - return false; - - wsDate = wsDateTime.Left(nSplitIndex); - wsTime = wsDateTime.Right(wsDateTime.GetLength() - nSplitIndex - 1); - CFX_DateTime dt; - return ValidateCanonicalDate(wsDate, &dt) && ValidateCanonicalTime(wsTime); -} - bool CXFA_LocaleValue::ParsePatternValue(const CFX_WideString& wsValue, const CFX_WideString& wsPattern, IFX_Locale* pLocale) { @@ -797,19 +613,16 @@ bool CXFA_LocaleValue::ParsePatternValue(const CFX_WideString& wsValue, auto pFormat = pdfium::MakeUnique<CFGAS_FormatString>(m_pLocaleMgr); std::vector<CFX_WideString> wsPatterns; - pFormat->SplitFormatString(wsPattern, wsPatterns); + pFormat->SplitFormatString(wsPattern, &wsPatterns); bool bRet = false; int32_t iCount = pdfium::CollectionSize<int32_t>(wsPatterns); for (int32_t i = 0; i < iCount && !bRet; i++) { CFX_WideString wsFormat = wsPatterns[i]; - FX_LOCALECATEGORY eCategory = pFormat->GetCategory(wsFormat); - eCategory = XFA_ValugeCategory(eCategory, m_dwType); - switch (eCategory) { + switch (ValueCategory(pFormat->GetCategory(wsFormat), m_dwType)) { case FX_LOCALECATEGORY_Null: bRet = pFormat->ParseNull(wsValue, wsFormat); - if (bRet) { + if (bRet) m_wsValue.clear(); - } break; case FX_LOCALECATEGORY_Zero: bRet = pFormat->ParseZero(wsValue, wsFormat); @@ -818,14 +631,13 @@ bool CXFA_LocaleValue::ParsePatternValue(const CFX_WideString& wsValue, break; case FX_LOCALECATEGORY_Num: { CFX_WideString fNum; - bRet = pFormat->ParseNum(wsValue, wsFormat, fNum); - if (bRet) { + bRet = pFormat->ParseNum(wsValue, wsFormat, &fNum); + if (bRet) m_wsValue = fNum; - } break; } case FX_LOCALECATEGORY_Text: - bRet = pFormat->ParseText(wsValue, wsFormat, m_wsValue); + bRet = pFormat->ParseText(wsValue, wsFormat, &m_wsValue); break; case FX_LOCALECATEGORY_Date: { CFX_DateTime dt; @@ -869,19 +681,18 @@ bool CXFA_LocaleValue::ParsePatternValue(const CFX_WideString& wsValue, return bRet; } -void CXFA_LocaleValue::GetNumbericFormat(CFX_WideString& wsFormat, - int32_t nIntLen, - int32_t nDecLen, - bool bSign) { +void CXFA_LocaleValue::GetNumericFormat(CFX_WideString& wsFormat, + int32_t nIntLen, + int32_t nDecLen) { ASSERT(wsFormat.IsEmpty()); ASSERT(nIntLen >= -1 && nDecLen >= -1); - int32_t nTotalLen = (nIntLen >= 0 ? nIntLen : 2) + (bSign ? 1 : 0) + + + int32_t nTotalLen = (nIntLen >= 0 ? nIntLen : 2) + 1 + (nDecLen >= 0 ? nDecLen : 2) + (nDecLen == 0 ? 0 : 1); wchar_t* lpBuf = wsFormat.GetBuffer(nTotalLen); int32_t nPos = 0; - if (bSign) { - lpBuf[nPos++] = L's'; - } + lpBuf[nPos++] = L's'; + if (nIntLen == -1) { lpBuf[nPos++] = L'z'; lpBuf[nPos++] = L'*'; @@ -905,37 +716,37 @@ void CXFA_LocaleValue::GetNumbericFormat(CFX_WideString& wsFormat, } wsFormat.ReleaseBuffer(nTotalLen); } -bool CXFA_LocaleValue::ValidateNumericTemp(CFX_WideString& wsNumeric, - CFX_WideString& wsFormat, - IFX_Locale* pLocale, - int32_t* pos) { - if (wsFormat.IsEmpty() || wsNumeric.IsEmpty()) { + +bool CXFA_LocaleValue::ValidateNumericTemp(const CFX_WideString& wsNumeric, + const CFX_WideString& wsFormat, + IFX_Locale* pLocale) { + if (wsFormat.IsEmpty() || wsNumeric.IsEmpty()) return true; - } + const wchar_t* pNum = wsNumeric.c_str(); const wchar_t* pFmt = wsFormat.c_str(); - int32_t n = 0, nf = 0; + int32_t n = 0; + int32_t nf = 0; wchar_t c = pNum[n]; wchar_t cf = pFmt[nf]; if (cf == L's') { - if (c == L'-' || c == L'+') { + if (c == L'-' || c == L'+') ++n; - } ++nf; } + bool bLimit = true; int32_t nCount = wsNumeric.GetLength(); int32_t nCountFmt = wsFormat.GetLength(); while (n < nCount && (bLimit ? nf < nCountFmt : true) && FXSYS_isDecimalDigit(c = pNum[n])) { if (bLimit == true) { - if ((cf = pFmt[nf]) == L'*') { + if ((cf = pFmt[nf]) == L'*') bLimit = false; - } else if (cf == L'z') { + else if (cf == L'z') nf++; - } else { + else return false; - } } n++; } @@ -948,6 +759,7 @@ bool CXFA_LocaleValue::ValidateNumericTemp(CFX_WideString& wsNumeric, ASSERT(cf == L'z' || cf == L'*'); ++nf; } + CFX_WideString wsDecimalSymbol; if (pLocale) wsDecimalSymbol = pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Decimal); @@ -965,13 +777,12 @@ bool CXFA_LocaleValue::ValidateNumericTemp(CFX_WideString& wsNumeric, while (n < nCount && (bLimit ? nf < nCountFmt : true) && FXSYS_isDecimalDigit(c = pNum[n])) { if (bLimit == true) { - if ((cf = pFmt[nf]) == L'*') { + if ((cf = pFmt[nf]) == L'*') bLimit = false; - } else if (cf == L'z') { + else if (cf == L'z') nf++; - } else { + else return false; - } } n++; } diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_localevalue.h b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_localevalue.h index cb30d377922..caf4b0c0f13 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_localevalue.h +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_localevalue.h @@ -44,11 +44,30 @@ class CXFA_LocaleValue { bool ValidateValue(const CFX_WideString& wsValue, const CFX_WideString& wsPattern, IFX_Locale* pLocale, - CFX_WideString* pMatchFormat = nullptr); + CFX_WideString* pMatchFormat); + bool FormatPatterns(CFX_WideString& wsResult, const CFX_WideString& wsFormat, IFX_Locale* pLocale, XFA_VALUEPICTURE eValueType) const; + + void GetNumericFormat(CFX_WideString& wsFormat, + int32_t nIntLen, + int32_t nDecLen); + bool ValidateNumericTemp(const CFX_WideString& wsNumeric, + const CFX_WideString& wsFormat, + IFX_Locale* pLocale); + + CFX_WideString GetValue() const { return m_wsValue; } + uint32_t GetType() const { return m_dwType; } + double GetDoubleNum() const; + bool SetDate(const CFX_DateTime& d); + CFX_DateTime GetDate() const; + CFX_DateTime GetTime() const; + + bool IsValid() const { return m_bValid; } + + private: bool FormatSinglePattern(CFX_WideString& wsResult, const CFX_WideString& wsFormat, IFX_Locale* pLocale, @@ -57,53 +76,14 @@ class CXFA_LocaleValue { bool ValidateCanonicalDate(const CFX_WideString& wsDate, CFX_DateTime* unDate); bool ValidateCanonicalTime(const CFX_WideString& wsTime); - bool ValidateCanonicalDateTime(const CFX_WideString& wsDateTime); - void GetNumbericFormat(CFX_WideString& wsFormat, - int32_t nIntLen, - int32_t nDecLen, - bool bSign = true); - bool ValidateNumericTemp(CFX_WideString& wsNumeric, - CFX_WideString& wsFormat, - IFX_Locale* pLocale = nullptr, - int32_t* pos = nullptr); - - CFX_WideString GetValue() const; - uint32_t GetType() const; - void SetValue(const CFX_WideString& wsValue, uint32_t dwType); - CFX_WideString GetText() const; - float GetNum() const; - double GetDoubleNum() const; - CFX_DateTime GetDate() const; - CFX_DateTime GetTime() const; - CFX_DateTime GetDateTime() const; - bool SetText(const CFX_WideString& wsText); - bool SetText(const CFX_WideString& wsText, - const CFX_WideString& wsFormat, - IFX_Locale* pLocale); - bool SetNum(float fNum); - bool SetNum(const CFX_WideString& wsNum, - const CFX_WideString& wsFormat, - IFX_Locale* pLocale); - bool SetDate(const CFX_DateTime& d); - bool SetDate(const CFX_WideString& wsDate, - const CFX_WideString& wsFormat, - IFX_Locale* pLocale); + bool SetTime(const CFX_DateTime& t); - bool SetTime(const CFX_WideString& wsTime, - const CFX_WideString& wsFormat, - IFX_Locale* pLocale); bool SetDateTime(const CFX_DateTime& dt); - bool SetDateTime(const CFX_WideString& wsDateTime, - const CFX_WideString& wsFormat, - IFX_Locale* pLocale); - bool IsNull() const { return m_dwType == XFA_VT_NULL; } - bool IsEmpty() const { return m_wsValue.IsEmpty(); } - bool IsValid() const { return m_bValid; } - private: bool ParsePatternValue(const CFX_WideString& wsValue, const CFX_WideString& wsPattern, IFX_Locale* pLocale); + CXFA_LocaleMgr* m_pLocaleMgr; CFX_WideString m_wsValue; uint32_t m_dwType; diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_measurement.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_measurement.cpp index 9173223d3c6..70420d7b5e8 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_measurement.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_measurement.cpp @@ -28,7 +28,7 @@ void CXFA_Measurement::Set(const CFX_WideStringC& wsMeasure) { } int32_t iUsedLen = 0; int32_t iOffset = (wsMeasure.GetAt(0) == L'=') ? 1 : 0; - float fValue = FXSYS_wcstof(wsMeasure.c_str() + iOffset, + float fValue = FXSYS_wcstof(wsMeasure.unterminated_c_str() + iOffset, wsMeasure.GetLength() - iOffset, &iUsedLen); XFA_UNIT eUnit = GetUnit(wsMeasure.Mid(iOffset + iUsedLen)); Set(fValue, eUnit); diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_node.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_node.cpp index 2daa49e066d..5c4f8d102ec 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_node.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_node.cpp @@ -23,7 +23,7 @@ #include "third_party/base/logging.h" #include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" -#include "xfa/fxfa/app/xfa_ffnotify.h" +#include "xfa/fxfa/app/cxfa_ffnotify.h" #include "xfa/fxfa/cxfa_eventparam.h" #include "xfa/fxfa/cxfa_ffwidget.h" #include "xfa/fxfa/parser/cxfa_arraynodelist.h" @@ -3591,7 +3591,7 @@ bool CXFA_Node::SetAttribute(XFA_ATTRIBUTE eAttr, return SetBoolean(pAttr->eName, wsValue != L"0", bNotify); case XFA_ATTRIBUTETYPE_Integer: return SetInteger(pAttr->eName, - FXSYS_round(FXSYS_wcstof(wsValue.c_str(), + FXSYS_round(FXSYS_wcstof(wsValue.unterminated_c_str(), wsValue.GetLength(), nullptr)), bNotify); case XFA_ATTRIBUTETYPE_Measure: @@ -4554,7 +4554,8 @@ bool CXFA_Node::RemoveChild(CXFA_Node* pNode, bool bNotify) { static_cast<CFX_XMLElement*>(pNode->m_pXMLNode); CFX_WideStringC wsAttributeName = pNode->GetCData(XFA_ATTRIBUTE_QualifiedName); - pXMLElement->RemoveAttribute(wsAttributeName.c_str()); + // TODO(tsepez): check usage of c_str() below. + pXMLElement->RemoveAttribute(wsAttributeName.unterminated_c_str()); } CFX_WideString wsName; pNode->GetAttribute(XFA_ATTRIBUTE_Name, wsName, false); @@ -4850,7 +4851,7 @@ bool CXFA_Node::GetMapModuleValue(void* pKey, void*& pValue) { } void CXFA_Node::SetMapModuleString(void* pKey, const CFX_WideStringC& wsValue) { - SetMapModuleBuffer(pKey, (void*)wsValue.c_str(), + SetMapModuleBuffer(pKey, (void*)wsValue.unterminated_c_str(), wsValue.GetLength() * sizeof(wchar_t)); } diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_object.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_object.cpp index bd7daec83ae..32aed5de1b3 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_object.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_object.cpp @@ -8,7 +8,7 @@ #include "core/fxcrt/fx_extension.h" #include "fxjs/cfxjse_value.h" -#include "xfa/fxfa/app/xfa_ffnotify.h" +#include "xfa/fxfa/app/cxfa_ffnotify.h" #include "xfa/fxfa/parser/cxfa_document.h" #include "xfa/fxfa/parser/cxfa_node.h" #include "xfa/fxfa/parser/cxfa_nodelist.h" @@ -17,7 +17,8 @@ CXFA_Object::CXFA_Object(CXFA_Document* pDocument, XFA_ObjectType objectType, XFA_Element elementType, const CFX_WideStringC& elementName) - : m_pDocument(pDocument), + : CFXJSE_HostObject(kXFA), + m_pDocument(pDocument), m_objectType(objectType), m_elementType(elementType), m_elementNameHash(FX_HashCode_GetW(elementName, false)), diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_resolveprocessor.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_resolveprocessor.cpp index add8cb8fcb8..93b2d860618 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_resolveprocessor.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_resolveprocessor.cpp @@ -502,7 +502,7 @@ int32_t CXFA_ResolveProcessor::GetFilter(const CFX_WideStringC& wsExpression, int32_t nConditionCount = 0; std::vector<int32_t> stack; int32_t nType = -1; - const wchar_t* pSrc = wsExpression.c_str(); + const wchar_t* pSrc = wsExpression.unterminated_c_str(); wchar_t wPrev = 0, wCur; bool bIsCondition = false; while (nStart < iLength) { diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_scriptcontext.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_scriptcontext.cpp index 49da63eee30..fcf22442f1c 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_scriptcontext.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_scriptcontext.cpp @@ -14,7 +14,7 @@ #include "fxjs/cfxjse_value.h" #include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" -#include "xfa/fxfa/app/xfa_ffnotify.h" +#include "xfa/fxfa/app/cxfa_ffnotify.h" #include "xfa/fxfa/cxfa_eventparam.h" #include "xfa/fxfa/parser/cxfa_document.h" #include "xfa/fxfa/parser/cxfa_localemgr.h" @@ -115,7 +115,10 @@ const XFA_METHODINFO* GetMethodByName(XFA_Element eElement, // static. CXFA_Object* CXFA_ScriptContext::ToObject(CFXJSE_Value* pValue, CFXJSE_Class* pClass) { - return static_cast<CXFA_Object*>(pValue->ToHostObject(pClass)); + CFXJSE_HostObject* pHostObj = pValue->ToHostObject(pClass); + if (!pHostObj || pHostObj->type() != CFXJSE_HostObject::kXFA) + return nullptr; + return static_cast<CXFA_Object*>(pHostObj); } CXFA_ScriptContext::CXFA_ScriptContext(CXFA_Document* pDocument) diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_widgetdata.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_widgetdata.cpp index bf9afc062f9..cd4aa573323 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_widgetdata.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_widgetdata.cpp @@ -10,7 +10,7 @@ #include "core/fxcrt/fx_extension.h" #include "fxbarcode/BC_Library.h" #include "third_party/base/stl_util.h" -#include "xfa/fxfa/app/xfa_ffnotify.h" +#include "xfa/fxfa/app/cxfa_ffnotify.h" #include "xfa/fxfa/parser/cxfa_document.h" #include "xfa/fxfa/parser/cxfa_event.h" #include "xfa/fxfa/parser/cxfa_localevalue.h" diff --git a/chromium/third_party/pdfium/xfa/fxgraphics/cfx_color.h b/chromium/third_party/pdfium/xfa/fxgraphics/cfx_color.h deleted file mode 100644 index 75f7fe2010d..00000000000 --- a/chromium/third_party/pdfium/xfa/fxgraphics/cfx_color.h +++ /dev/null @@ -1,43 +0,0 @@ -// 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 - -#ifndef XFA_FXGRAPHICS_CFX_COLOR_H_ -#define XFA_FXGRAPHICS_CFX_COLOR_H_ - -#include "core/fxge/fx_dib.h" -#include "xfa/fxgraphics/cfx_graphics.h" - -class CFX_Pattern; -class CFX_Shading; - -enum { FX_COLOR_None = 0, FX_COLOR_Solid, FX_COLOR_Pattern, FX_COLOR_Shading }; - -class CFX_Color { - public: - CFX_Color(); - explicit CFX_Color(const FX_ARGB argb); - explicit CFX_Color(CFX_Shading* shading); - CFX_Color(CFX_Pattern* pattern, const FX_ARGB argb); - virtual ~CFX_Color(); - - void Set(const FX_ARGB argb); - void Set(CFX_Pattern* pattern, const FX_ARGB argb); - void Set(CFX_Shading* shading); - - private: - friend class CFX_Graphics; - - int32_t m_type; - union { - struct { - FX_ARGB argb; - CFX_Pattern* pattern; - } m_info; - CFX_Shading* m_shading; - }; -}; - -#endif // XFA_FXGRAPHICS_CFX_COLOR_H_ diff --git a/chromium/third_party/pdfium/xfa/fxgraphics/cfx_shading.h b/chromium/third_party/pdfium/xfa/fxgraphics/cfx_shading.h deleted file mode 100644 index 1fb34d2b07d..00000000000 --- a/chromium/third_party/pdfium/xfa/fxgraphics/cfx_shading.h +++ /dev/null @@ -1,56 +0,0 @@ -// 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 - -#ifndef XFA_FXGRAPHICS_CFX_SHADING_H_ -#define XFA_FXGRAPHICS_CFX_SHADING_H_ - -#include "core/fxcrt/fx_coordinates.h" -#include "core/fxcrt/fx_system.h" -#include "core/fxge/fx_dib.h" - -#define FX_SHADING_Steps 256 - -enum CFX_Shading_Type { FX_SHADING_Axial = 1, FX_SHADING_Radial }; - -class CFX_Shading { - public: - // Axial shading. - CFX_Shading(const CFX_PointF& beginPoint, - const CFX_PointF& endPoint, - bool isExtendedBegin, - bool isExtendedEnd, - const FX_ARGB beginArgb, - const FX_ARGB endArgb); - - // Radial shading. - CFX_Shading(const CFX_PointF& beginPoint, - const CFX_PointF& endPoint, - const float beginRadius, - const float endRadius, - bool isExtendedBegin, - bool isExtendedEnd, - const FX_ARGB beginArgb, - const FX_ARGB endArgb); - virtual ~CFX_Shading(); - - private: - friend class CFX_Graphics; - - void InitArgbArray(); - - const CFX_Shading_Type m_type; - const CFX_PointF m_beginPoint; - const CFX_PointF m_endPoint; - const float m_beginRadius; - const float m_endRadius; - const bool m_isExtendedBegin; - const bool m_isExtendedEnd; - const FX_ARGB m_beginArgb; - const FX_ARGB m_endArgb; - FX_ARGB m_argbArray[FX_SHADING_Steps]; -}; - -#endif // XFA_FXGRAPHICS_CFX_SHADING_H_ diff --git a/chromium/third_party/pdfium/xfa/fxgraphics/cfx_color.cpp b/chromium/third_party/pdfium/xfa/fxgraphics/cxfa_color.cpp index 36025a82c89..79c0e5f794d 100644 --- a/chromium/third_party/pdfium/xfa/fxgraphics/cfx_color.cpp +++ b/chromium/third_party/pdfium/xfa/fxgraphics/cxfa_color.cpp @@ -4,33 +4,33 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fxgraphics/cfx_color.h" +#include "xfa/fxgraphics/cxfa_color.h" -CFX_Color::CFX_Color() : m_type(FX_COLOR_None) {} +CXFA_Color::CXFA_Color() : m_type(FX_COLOR_None) {} -CFX_Color::CFX_Color(const FX_ARGB argb) { +CXFA_Color::CXFA_Color(const FX_ARGB argb) { Set(argb); } -CFX_Color::CFX_Color(CFX_Pattern* pattern, const FX_ARGB argb) { +CXFA_Color::CXFA_Color(CXFA_Pattern* pattern, const FX_ARGB argb) { Set(pattern, argb); } -CFX_Color::CFX_Color(CFX_Shading* shading) { +CXFA_Color::CXFA_Color(CXFA_Shading* shading) { Set(shading); } -CFX_Color::~CFX_Color() { +CXFA_Color::~CXFA_Color() { m_type = FX_COLOR_None; } -void CFX_Color::Set(const FX_ARGB argb) { +void CXFA_Color::Set(const FX_ARGB argb) { m_type = FX_COLOR_Solid; m_info.argb = argb; m_info.pattern = nullptr; } -void CFX_Color::Set(CFX_Pattern* pattern, const FX_ARGB argb) { +void CXFA_Color::Set(CXFA_Pattern* pattern, const FX_ARGB argb) { if (!pattern) return; m_type = FX_COLOR_Pattern; @@ -38,7 +38,7 @@ void CFX_Color::Set(CFX_Pattern* pattern, const FX_ARGB argb) { m_info.pattern = pattern; } -void CFX_Color::Set(CFX_Shading* shading) { +void CXFA_Color::Set(CXFA_Shading* shading) { if (!shading) return; m_type = FX_COLOR_Shading; diff --git a/chromium/third_party/pdfium/xfa/fxgraphics/cxfa_color.h b/chromium/third_party/pdfium/xfa/fxgraphics/cxfa_color.h new file mode 100644 index 00000000000..f5bba27586e --- /dev/null +++ b/chromium/third_party/pdfium/xfa/fxgraphics/cxfa_color.h @@ -0,0 +1,43 @@ +// 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 + +#ifndef XFA_FXGRAPHICS_CXFA_COLOR_H_ +#define XFA_FXGRAPHICS_CXFA_COLOR_H_ + +#include "core/fxge/fx_dib.h" +#include "xfa/fxgraphics/cxfa_graphics.h" + +class CXFA_Pattern; +class CXFA_Shading; + +enum { FX_COLOR_None = 0, FX_COLOR_Solid, FX_COLOR_Pattern, FX_COLOR_Shading }; + +class CXFA_Color { + public: + CXFA_Color(); + explicit CXFA_Color(const FX_ARGB argb); + explicit CXFA_Color(CXFA_Shading* shading); + CXFA_Color(CXFA_Pattern* pattern, const FX_ARGB argb); + virtual ~CXFA_Color(); + + void Set(const FX_ARGB argb); + void Set(CXFA_Pattern* pattern, const FX_ARGB argb); + void Set(CXFA_Shading* shading); + + private: + friend class CXFA_Graphics; + + int32_t m_type; + union { + struct { + FX_ARGB argb; + CXFA_Pattern* pattern; + } m_info; + CXFA_Shading* m_shading; + }; +}; + +#endif // XFA_FXGRAPHICS_CXFA_COLOR_H_ diff --git a/chromium/third_party/pdfium/xfa/fxgraphics/cfx_graphics.cpp b/chromium/third_party/pdfium/xfa/fxgraphics/cxfa_graphics.cpp index a67932f0521..8648abb81dd 100644 --- a/chromium/third_party/pdfium/xfa/fxgraphics/cfx_graphics.cpp +++ b/chromium/third_party/pdfium/xfa/fxgraphics/cxfa_graphics.cpp @@ -4,7 +4,7 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fxgraphics/cfx_graphics.h" +#include "xfa/fxgraphics/cxfa_graphics.h" #include <memory> @@ -12,10 +12,10 @@ #include "core/fxge/cfx_renderdevice.h" #include "core/fxge/cfx_unicodeencoding.h" #include "third_party/base/ptr_util.h" -#include "xfa/fxgraphics/cfx_color.h" -#include "xfa/fxgraphics/cfx_path.h" -#include "xfa/fxgraphics/cfx_pattern.h" -#include "xfa/fxgraphics/cfx_shading.h" +#include "xfa/fxgraphics/cxfa_color.h" +#include "xfa/fxgraphics/cxfa_path.h" +#include "xfa/fxgraphics/cxfa_pattern.h" +#include "xfa/fxgraphics/cxfa_shading.h" namespace { @@ -97,16 +97,16 @@ const FX_HATCHDATA hatchBitmapData[FX_HATCHSTYLE_Total] = { } // namespace -CFX_Graphics::CFX_Graphics(CFX_RenderDevice* renderDevice) +CXFA_Graphics::CXFA_Graphics(CFX_RenderDevice* renderDevice) : m_type(FX_CONTEXT_None), m_renderDevice(renderDevice) { if (!renderDevice) return; m_type = FX_CONTEXT_Device; } -CFX_Graphics::~CFX_Graphics() {} +CXFA_Graphics::~CXFA_Graphics() {} -void CFX_Graphics::SaveGraphState() { +void CXFA_Graphics::SaveGraphState() { if (m_type != FX_CONTEXT_Device || !m_renderDevice) return; @@ -114,7 +114,7 @@ void CFX_Graphics::SaveGraphState() { m_infoStack.push_back(pdfium::MakeUnique<TInfo>(m_info)); } -void CFX_Graphics::RestoreGraphState() { +void CXFA_Graphics::RestoreGraphState() { if (m_type != FX_CONTEXT_Device || !m_renderDevice) return; @@ -127,15 +127,15 @@ void CFX_Graphics::RestoreGraphState() { return; } -void CFX_Graphics::SetLineCap(CFX_GraphStateData::LineCap lineCap) { +void CXFA_Graphics::SetLineCap(CFX_GraphStateData::LineCap lineCap) { if (m_type == FX_CONTEXT_Device && m_renderDevice) { m_info.graphState.m_LineCap = lineCap; } } -void CFX_Graphics::SetLineDash(float dashPhase, - float* dashArray, - int32_t dashCount) { +void CXFA_Graphics::SetLineDash(float dashPhase, + float* dashArray, + int32_t dashCount) { if (dashCount > 0 && !dashArray) return; @@ -153,19 +153,19 @@ void CFX_Graphics::SetLineDash(float dashPhase, } } -void CFX_Graphics::SetLineDash(FX_DashStyle dashStyle) { +void CXFA_Graphics::SetLineDash(FX_DashStyle dashStyle) { if (m_type == FX_CONTEXT_Device && m_renderDevice) RenderDeviceSetLineDash(dashStyle); } -void CFX_Graphics::SetLineWidth(float lineWidth, bool isActOnDash) { +void CXFA_Graphics::SetLineWidth(float lineWidth, bool isActOnDash) { if (m_type == FX_CONTEXT_Device && m_renderDevice) { m_info.graphState.m_LineWidth = lineWidth; m_info.isActOnDash = isActOnDash; } } -void CFX_Graphics::SetStrokeColor(CFX_Color* color) { +void CXFA_Graphics::SetStrokeColor(CXFA_Color* color) { if (!color) return; if (m_type == FX_CONTEXT_Device && m_renderDevice) { @@ -173,7 +173,7 @@ void CFX_Graphics::SetStrokeColor(CFX_Color* color) { } } -void CFX_Graphics::SetFillColor(CFX_Color* color) { +void CXFA_Graphics::SetFillColor(CXFA_Color* color) { if (!color) return; if (m_type == FX_CONTEXT_Device && m_renderDevice) { @@ -181,32 +181,32 @@ void CFX_Graphics::SetFillColor(CFX_Color* color) { } } -void CFX_Graphics::StrokePath(CFX_Path* path, CFX_Matrix* matrix) { +void CXFA_Graphics::StrokePath(CXFA_Path* path, CFX_Matrix* matrix) { if (!path) return; if (m_type == FX_CONTEXT_Device && m_renderDevice) RenderDeviceStrokePath(path, matrix); } -void CFX_Graphics::FillPath(CFX_Path* path, - FX_FillMode fillMode, - CFX_Matrix* matrix) { +void CXFA_Graphics::FillPath(CXFA_Path* path, + FX_FillMode fillMode, + CFX_Matrix* matrix) { if (!path) return; if (m_type == FX_CONTEXT_Device && m_renderDevice) RenderDeviceFillPath(path, fillMode, matrix); } -void CFX_Graphics::StretchImage(const CFX_RetainPtr<CFX_DIBSource>& source, - const CFX_RectF& rect, - CFX_Matrix* matrix) { +void CXFA_Graphics::StretchImage(const CFX_RetainPtr<CFX_DIBSource>& source, + const CFX_RectF& rect, + CFX_Matrix* matrix) { if (!source) return; if (m_type == FX_CONTEXT_Device && m_renderDevice) RenderDeviceStretchImage(source, rect, matrix); } -void CFX_Graphics::ConcatMatrix(const CFX_Matrix* matrix) { +void CXFA_Graphics::ConcatMatrix(const CFX_Matrix* matrix) { if (!matrix) return; if (m_type == FX_CONTEXT_Device && m_renderDevice) { @@ -214,13 +214,13 @@ void CFX_Graphics::ConcatMatrix(const CFX_Matrix* matrix) { } } -CFX_Matrix* CFX_Graphics::GetMatrix() { +CFX_Matrix* CXFA_Graphics::GetMatrix() { if (m_type == FX_CONTEXT_Device && m_renderDevice) return &m_info.CTM; return nullptr; } -CFX_RectF CFX_Graphics::GetClipRect() const { +CFX_RectF CXFA_Graphics::GetClipRect() const { if (m_type != FX_CONTEXT_Device || !m_renderDevice) return CFX_RectF(); @@ -228,7 +228,7 @@ CFX_RectF CFX_Graphics::GetClipRect() const { return CFX_Rect(r.left, r.top, r.Width(), r.Height()).As<float>(); } -void CFX_Graphics::SetClipRect(const CFX_RectF& rect) { +void CXFA_Graphics::SetClipRect(const CFX_RectF& rect) { if (m_type == FX_CONTEXT_Device && m_renderDevice) { m_renderDevice->SetClip_Rect( FX_RECT(FXSYS_round(rect.left), FXSYS_round(rect.top), @@ -236,11 +236,11 @@ void CFX_Graphics::SetClipRect(const CFX_RectF& rect) { } } -CFX_RenderDevice* CFX_Graphics::GetRenderDevice() { +CFX_RenderDevice* CXFA_Graphics::GetRenderDevice() { return m_renderDevice; } -void CFX_Graphics::RenderDeviceSetLineDash(FX_DashStyle dashStyle) { +void CXFA_Graphics::RenderDeviceSetLineDash(FX_DashStyle dashStyle) { switch (dashStyle) { case FX_DASHSTYLE_Solid: { m_info.graphState.SetDashCount(0); @@ -271,7 +271,8 @@ void CFX_Graphics::RenderDeviceSetLineDash(FX_DashStyle dashStyle) { } } -void CFX_Graphics::RenderDeviceStrokePath(CFX_Path* path, CFX_Matrix* matrix) { +void CXFA_Graphics::RenderDeviceStrokePath(CXFA_Path* path, + CFX_Matrix* matrix) { if (!m_info.strokeColor) return; CFX_Matrix m(m_info.CTM.a, m_info.CTM.b, m_info.CTM.c, m_info.CTM.d, @@ -290,9 +291,9 @@ void CFX_Graphics::RenderDeviceStrokePath(CFX_Path* path, CFX_Matrix* matrix) { } } -void CFX_Graphics::RenderDeviceFillPath(CFX_Path* path, - FX_FillMode fillMode, - CFX_Matrix* matrix) { +void CXFA_Graphics::RenderDeviceFillPath(CXFA_Path* path, + FX_FillMode fillMode, + CFX_Matrix* matrix) { if (!m_info.fillColor) return; CFX_Matrix m(m_info.CTM.a, m_info.CTM.b, m_info.CTM.c, m_info.CTM.d, @@ -317,7 +318,7 @@ void CFX_Graphics::RenderDeviceFillPath(CFX_Path* path, } } -void CFX_Graphics::RenderDeviceStretchImage( +void CXFA_Graphics::RenderDeviceStretchImage( const CFX_RetainPtr<CFX_DIBSource>& source, const CFX_RectF& rect, CFX_Matrix* matrix) { @@ -343,10 +344,10 @@ void CFX_Graphics::RenderDeviceStretchImage( FXSYS_round(r.left - left), FXSYS_round(r.top - top)); } -void CFX_Graphics::FillPathWithPattern(CFX_Path* path, - FX_FillMode fillMode, - CFX_Matrix* matrix) { - CFX_Pattern* pattern = m_info.fillColor->m_info.pattern; +void CXFA_Graphics::FillPathWithPattern(CXFA_Path* path, + FX_FillMode fillMode, + CFX_Matrix* matrix) { + CXFA_Pattern* pattern = m_info.fillColor->m_info.pattern; CFX_RetainPtr<CFX_DIBitmap> bitmap = m_renderDevice->GetBitmap(); int32_t width = bitmap->GetWidth(); int32_t height = bitmap->GetHeight(); @@ -380,9 +381,9 @@ void CFX_Graphics::FillPathWithPattern(CFX_Path* path, SetDIBitsWithMatrix(bmp, &pattern->m_matrix); } -void CFX_Graphics::FillPathWithShading(CFX_Path* path, - FX_FillMode fillMode, - CFX_Matrix* matrix) { +void CXFA_Graphics::FillPathWithShading(CXFA_Path* path, + FX_FillMode fillMode, + CFX_Matrix* matrix) { CFX_RetainPtr<CFX_DIBitmap> bitmap = m_renderDevice->GetBitmap(); int32_t width = bitmap->GetWidth(); int32_t height = bitmap->GetHeight(); @@ -498,7 +499,7 @@ void CFX_Graphics::FillPathWithShading(CFX_Path* path, } } -void CFX_Graphics::SetDIBitsWithMatrix( +void CXFA_Graphics::SetDIBitsWithMatrix( const CFX_RetainPtr<CFX_DIBSource>& source, CFX_Matrix* matrix) { if (matrix->IsIdentity()) { @@ -515,17 +516,17 @@ void CFX_Graphics::SetDIBitsWithMatrix( } } -CFX_Graphics::TInfo::TInfo() +CXFA_Graphics::TInfo::TInfo() : isActOnDash(false), strokeColor(nullptr), fillColor(nullptr) {} -CFX_Graphics::TInfo::TInfo(const TInfo& info) +CXFA_Graphics::TInfo::TInfo(const TInfo& info) : graphState(info.graphState), CTM(info.CTM), isActOnDash(info.isActOnDash), strokeColor(info.strokeColor), fillColor(info.fillColor) {} -CFX_Graphics::TInfo& CFX_Graphics::TInfo::operator=(const TInfo& other) { +CXFA_Graphics::TInfo& CXFA_Graphics::TInfo::operator=(const TInfo& other) { graphState.Copy(other.graphState); CTM = other.CTM; isActOnDash = other.isActOnDash; diff --git a/chromium/third_party/pdfium/xfa/fxgraphics/cfx_graphics.h b/chromium/third_party/pdfium/xfa/fxgraphics/cxfa_graphics.h index 8785a387d68..5492d4d3be1 100644 --- a/chromium/third_party/pdfium/xfa/fxgraphics/cfx_graphics.h +++ b/chromium/third_party/pdfium/xfa/fxgraphics/cxfa_graphics.h @@ -4,8 +4,8 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef XFA_FXGRAPHICS_CFX_GRAPHICS_H_ -#define XFA_FXGRAPHICS_CFX_GRAPHICS_H_ +#ifndef XFA_FXGRAPHICS_CXFA_GRAPHICS_H_ +#define XFA_FXGRAPHICS_CXFA_GRAPHICS_H_ #include <memory> #include <vector> @@ -17,8 +17,8 @@ #include "core/fxge/fx_dib.h" #include "core/fxge/fx_font.h" -class CFX_Color; -class CFX_Path; +class CXFA_Color; +class CXFA_Path; using FX_FillMode = int32_t; @@ -41,10 +41,10 @@ enum class FX_HatchStyle { class CFX_RenderDevice; -class CFX_Graphics { +class CXFA_Graphics { public: - explicit CFX_Graphics(CFX_RenderDevice* renderDevice); - ~CFX_Graphics(); + explicit CXFA_Graphics(CFX_RenderDevice* renderDevice); + ~CXFA_Graphics(); void SaveGraphState(); void RestoreGraphState(); @@ -57,11 +57,11 @@ class CFX_Graphics { void SetLineDash(float dashPhase, float* dashArray, int32_t dashCount); void SetLineDash(FX_DashStyle dashStyle); void SetLineWidth(float lineWidth, bool isActOnDash = false); - void SetStrokeColor(CFX_Color* color); - void SetFillColor(CFX_Color* color); + void SetStrokeColor(CXFA_Color* color); + void SetFillColor(CXFA_Color* color); void SetClipRect(const CFX_RectF& rect); - void StrokePath(CFX_Path* path, CFX_Matrix* matrix = nullptr); - void FillPath(CFX_Path* path, + void StrokePath(CXFA_Path* path, CFX_Matrix* matrix = nullptr); + void FillPath(CXFA_Path* path, FX_FillMode fillMode = FXFILL_WINDING, CFX_Matrix* matrix = nullptr); void StretchImage(const CFX_RetainPtr<CFX_DIBSource>& source, @@ -81,23 +81,23 @@ class CFX_Graphics { CFX_GraphStateData graphState; CFX_Matrix CTM; bool isActOnDash; - CFX_Color* strokeColor; - CFX_Color* fillColor; + CXFA_Color* strokeColor; + CXFA_Color* fillColor; } m_info; void RenderDeviceSetLineDash(FX_DashStyle dashStyle); - void RenderDeviceStrokePath(CFX_Path* path, CFX_Matrix* matrix); - void RenderDeviceFillPath(CFX_Path* path, + void RenderDeviceStrokePath(CXFA_Path* path, CFX_Matrix* matrix); + void RenderDeviceFillPath(CXFA_Path* path, FX_FillMode fillMode, CFX_Matrix* matrix); void RenderDeviceStretchImage(const CFX_RetainPtr<CFX_DIBSource>& source, const CFX_RectF& rect, CFX_Matrix* matrix); - void FillPathWithPattern(CFX_Path* path, + void FillPathWithPattern(CXFA_Path* path, FX_FillMode fillMode, CFX_Matrix* matrix); - void FillPathWithShading(CFX_Path* path, + void FillPathWithShading(CXFA_Path* path, FX_FillMode fillMode, CFX_Matrix* matrix); @@ -108,4 +108,4 @@ class CFX_Graphics { std::vector<std::unique_ptr<TInfo>> m_infoStack; }; -#endif // XFA_FXGRAPHICS_CFX_GRAPHICS_H_ +#endif // XFA_FXGRAPHICS_CXFA_GRAPHICS_H_ diff --git a/chromium/third_party/pdfium/xfa/fxgraphics/cfx_path.cpp b/chromium/third_party/pdfium/xfa/fxgraphics/cxfa_path.cpp index fc0051ad4cb..6d7ed0be583 100644 --- a/chromium/third_party/pdfium/xfa/fxgraphics/cfx_path.cpp +++ b/chromium/third_party/pdfium/xfa/fxgraphics/cxfa_path.cpp @@ -4,52 +4,52 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fxgraphics/cfx_path.h" +#include "xfa/fxgraphics/cxfa_path.h" #include "core/fxge/cfx_pathdata.h" #include "third_party/base/ptr_util.h" -CFX_Path::CFX_Path() {} +CXFA_Path::CXFA_Path() {} -CFX_Path::~CFX_Path() {} +CXFA_Path::~CXFA_Path() {} -void CFX_Path::Clear() { +void CXFA_Path::Clear() { data_.Clear(); } -void CFX_Path::Close() { +void CXFA_Path::Close() { data_.ClosePath(); } -void CFX_Path::MoveTo(const CFX_PointF& point) { +void CXFA_Path::MoveTo(const CFX_PointF& point) { data_.AppendPoint(point, FXPT_TYPE::MoveTo, false); } -void CFX_Path::LineTo(const CFX_PointF& point) { +void CXFA_Path::LineTo(const CFX_PointF& point) { data_.AppendPoint(point, FXPT_TYPE::LineTo, false); } -void CFX_Path::BezierTo(const CFX_PointF& c1, - const CFX_PointF& c2, - const CFX_PointF& to) { +void CXFA_Path::BezierTo(const CFX_PointF& c1, + const CFX_PointF& c2, + const CFX_PointF& to) { data_.AppendPoint(c1, FXPT_TYPE::BezierTo, false); data_.AppendPoint(c2, FXPT_TYPE::BezierTo, false); data_.AppendPoint(to, FXPT_TYPE::BezierTo, false); } -void CFX_Path::ArcTo(const CFX_PointF& pos, - const CFX_SizeF& size, - float start_angle, - float sweep_angle) { +void CXFA_Path::ArcTo(const CFX_PointF& pos, + const CFX_SizeF& size, + float start_angle, + float sweep_angle) { CFX_SizeF new_size = size / 2.0f; ArcToInternal(CFX_PointF(pos.x + new_size.width, pos.y + new_size.height), new_size, start_angle, sweep_angle); } -void CFX_Path::ArcToInternal(const CFX_PointF& pos, - const CFX_SizeF& size, - float start_angle, - float sweep_angle) { +void CXFA_Path::ArcToInternal(const CFX_PointF& pos, + const CFX_SizeF& size, + float start_angle, + float sweep_angle) { float x0 = cos(sweep_angle / 2); float y0 = sin(sweep_angle / 2); float tx = ((1.0f - x0) * 4) / (3 * 1.0f); @@ -73,23 +73,23 @@ void CFX_Path::ArcToInternal(const CFX_PointF& pos, data_.AppendPoint(bezier, FXPT_TYPE::BezierTo, false); } -void CFX_Path::AddLine(const CFX_PointF& p1, const CFX_PointF& p2) { +void CXFA_Path::AddLine(const CFX_PointF& p1, const CFX_PointF& p2) { data_.AppendPoint(p1, FXPT_TYPE::MoveTo, false); data_.AppendPoint(p2, FXPT_TYPE::LineTo, false); } -void CFX_Path::AddRectangle(float left, float top, float width, float height) { +void CXFA_Path::AddRectangle(float left, float top, float width, float height) { data_.AppendRect(left, top, left + width, top + height); } -void CFX_Path::AddEllipse(const CFX_RectF& rect) { +void CXFA_Path::AddEllipse(const CFX_RectF& rect) { AddArc(rect.TopLeft(), rect.Size(), 0, FX_PI * 2); } -void CFX_Path::AddArc(const CFX_PointF& original_pos, - const CFX_SizeF& original_size, - float start_angle, - float sweep_angle) { +void CXFA_Path::AddArc(const CFX_PointF& original_pos, + const CFX_SizeF& original_size, + float start_angle, + float sweep_angle) { if (sweep_angle == 0) return; @@ -137,12 +137,12 @@ void CFX_Path::AddArc(const CFX_PointF& original_pos, } while (!done); } -void CFX_Path::AddSubpath(CFX_Path* path) { +void CXFA_Path::AddSubpath(CXFA_Path* path) { if (!path) return; data_.Append(&path->data_, nullptr); } -void CFX_Path::TransformBy(const CFX_Matrix& mt) { +void CXFA_Path::TransformBy(const CFX_Matrix& mt) { data_.Transform(&mt); } diff --git a/chromium/third_party/pdfium/xfa/fxgraphics/cfx_path.h b/chromium/third_party/pdfium/xfa/fxgraphics/cxfa_path.h index 186465f8102..9c71a4d5ff6 100644 --- a/chromium/third_party/pdfium/xfa/fxgraphics/cfx_path.h +++ b/chromium/third_party/pdfium/xfa/fxgraphics/cxfa_path.h @@ -4,17 +4,17 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef XFA_FXGRAPHICS_CFX_PATH_H_ -#define XFA_FXGRAPHICS_CFX_PATH_H_ +#ifndef XFA_FXGRAPHICS_CXFA_PATH_H_ +#define XFA_FXGRAPHICS_CXFA_PATH_H_ #include "core/fxcrt/fx_system.h" #include "core/fxge/cfx_pathdata.h" -#include "xfa/fxgraphics/cfx_graphics.h" +#include "xfa/fxgraphics/cxfa_graphics.h" -class CFX_Path final { +class CXFA_Path final { public: - CFX_Path(); - ~CFX_Path(); + CXFA_Path(); + ~CXFA_Path(); const CFX_PathData* GetPathData() const { return &data_; } @@ -41,7 +41,7 @@ class CFX_Path final { float startAngle, float sweepAngle); - void AddSubpath(CFX_Path* path); + void AddSubpath(CXFA_Path* path); private: void ArcToInternal(const CFX_PointF& pos, @@ -52,4 +52,4 @@ class CFX_Path final { CFX_PathData data_; }; -#endif // XFA_FXGRAPHICS_CFX_PATH_H_ +#endif // XFA_FXGRAPHICS_CXFA_PATH_H_ diff --git a/chromium/third_party/pdfium/xfa/fxgraphics/cfx_pattern.cpp b/chromium/third_party/pdfium/xfa/fxgraphics/cxfa_pattern.cpp index a20ec24aa5a..ea6cea87a55 100644 --- a/chromium/third_party/pdfium/xfa/fxgraphics/cfx_pattern.cpp +++ b/chromium/third_party/pdfium/xfa/fxgraphics/cxfa_pattern.cpp @@ -4,12 +4,12 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fxgraphics/cfx_pattern.h" +#include "xfa/fxgraphics/cxfa_pattern.h" -CFX_Pattern::CFX_Pattern(FX_HatchStyle hatchStyle, - const FX_ARGB foreArgb, - const FX_ARGB backArgb, - CFX_Matrix* matrix) +CXFA_Pattern::CXFA_Pattern(FX_HatchStyle hatchStyle, + const FX_ARGB foreArgb, + const FX_ARGB backArgb, + CFX_Matrix* matrix) : m_hatchStyle(hatchStyle), m_foreArgb(foreArgb), m_backArgb(backArgb) { if (matrix) m_matrix = *matrix; @@ -17,4 +17,4 @@ CFX_Pattern::CFX_Pattern(FX_HatchStyle hatchStyle, m_matrix.SetIdentity(); } -CFX_Pattern::~CFX_Pattern() {} +CXFA_Pattern::~CXFA_Pattern() {} diff --git a/chromium/third_party/pdfium/xfa/fxgraphics/cfx_pattern.h b/chromium/third_party/pdfium/xfa/fxgraphics/cxfa_pattern.h index ef0008a3eaf..838ec98b01e 100644 --- a/chromium/third_party/pdfium/xfa/fxgraphics/cfx_pattern.h +++ b/chromium/third_party/pdfium/xfa/fxgraphics/cxfa_pattern.h @@ -4,27 +4,27 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef XFA_FXGRAPHICS_CFX_PATTERN_H_ -#define XFA_FXGRAPHICS_CFX_PATTERN_H_ +#ifndef XFA_FXGRAPHICS_CXFA_PATTERN_H_ +#define XFA_FXGRAPHICS_CXFA_PATTERN_H_ #include "core/fxcrt/fx_coordinates.h" #include "core/fxcrt/fx_system.h" -#include "xfa/fxgraphics/cfx_graphics.h" +#include "xfa/fxgraphics/cxfa_graphics.h" class CFX_DIBitmap; class CFX_Matrix; -class CFX_Pattern { +class CXFA_Pattern { public: - CFX_Pattern(FX_HatchStyle hatchStyle, - const FX_ARGB foreArgb, - const FX_ARGB backArgb, - CFX_Matrix* matrix = nullptr); + CXFA_Pattern(FX_HatchStyle hatchStyle, + const FX_ARGB foreArgb, + const FX_ARGB backArgb, + CFX_Matrix* matrix = nullptr); - virtual ~CFX_Pattern(); + virtual ~CXFA_Pattern(); private: - friend class CFX_Graphics; + friend class CXFA_Graphics; CFX_Matrix m_matrix; @@ -33,4 +33,4 @@ class CFX_Pattern { const FX_ARGB m_backArgb; }; -#endif // XFA_FXGRAPHICS_CFX_PATTERN_H_ +#endif // XFA_FXGRAPHICS_CXFA_PATTERN_H_ diff --git a/chromium/third_party/pdfium/xfa/fxgraphics/cfx_shading.cpp b/chromium/third_party/pdfium/xfa/fxgraphics/cxfa_shading.cpp index b099bb97b14..599a3f9d420 100644 --- a/chromium/third_party/pdfium/xfa/fxgraphics/cfx_shading.cpp +++ b/chromium/third_party/pdfium/xfa/fxgraphics/cxfa_shading.cpp @@ -4,14 +4,14 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fxgraphics/cfx_shading.h" +#include "xfa/fxgraphics/cxfa_shading.h" -CFX_Shading::CFX_Shading(const CFX_PointF& beginPoint, - const CFX_PointF& endPoint, - bool isExtendedBegin, - bool isExtendedEnd, - const FX_ARGB beginArgb, - const FX_ARGB endArgb) +CXFA_Shading::CXFA_Shading(const CFX_PointF& beginPoint, + const CFX_PointF& endPoint, + bool isExtendedBegin, + bool isExtendedEnd, + const FX_ARGB beginArgb, + const FX_ARGB endArgb) : m_type(FX_SHADING_Axial), m_beginPoint(beginPoint), m_endPoint(endPoint), @@ -24,14 +24,14 @@ CFX_Shading::CFX_Shading(const CFX_PointF& beginPoint, InitArgbArray(); } -CFX_Shading::CFX_Shading(const CFX_PointF& beginPoint, - const CFX_PointF& endPoint, - const float beginRadius, - const float endRadius, - bool isExtendedBegin, - bool isExtendedEnd, - const FX_ARGB beginArgb, - const FX_ARGB endArgb) +CXFA_Shading::CXFA_Shading(const CFX_PointF& beginPoint, + const CFX_PointF& endPoint, + const float beginRadius, + const float endRadius, + bool isExtendedBegin, + bool isExtendedEnd, + const FX_ARGB beginArgb, + const FX_ARGB endArgb) : m_type(FX_SHADING_Radial), m_beginPoint(beginPoint), m_endPoint(endPoint), @@ -44,9 +44,9 @@ CFX_Shading::CFX_Shading(const CFX_PointF& beginPoint, InitArgbArray(); } -CFX_Shading::~CFX_Shading() {} +CXFA_Shading::~CXFA_Shading() {} -void CFX_Shading::InitArgbArray() { +void CXFA_Shading::InitArgbArray() { int32_t a1; int32_t r1; int32_t g1; diff --git a/chromium/third_party/pdfium/xfa/fxgraphics/cxfa_shading.h b/chromium/third_party/pdfium/xfa/fxgraphics/cxfa_shading.h new file mode 100644 index 00000000000..22ef941250f --- /dev/null +++ b/chromium/third_party/pdfium/xfa/fxgraphics/cxfa_shading.h @@ -0,0 +1,56 @@ +// 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 + +#ifndef XFA_FXGRAPHICS_CXFA_SHADING_H_ +#define XFA_FXGRAPHICS_CXFA_SHADING_H_ + +#include "core/fxcrt/fx_coordinates.h" +#include "core/fxcrt/fx_system.h" +#include "core/fxge/fx_dib.h" + +#define FX_SHADING_Steps 256 + +enum CXFA_Shading_Type { FX_SHADING_Axial = 1, FX_SHADING_Radial }; + +class CXFA_Shading { + public: + // Axial shading. + CXFA_Shading(const CFX_PointF& beginPoint, + const CFX_PointF& endPoint, + bool isExtendedBegin, + bool isExtendedEnd, + const FX_ARGB beginArgb, + const FX_ARGB endArgb); + + // Radial shading. + CXFA_Shading(const CFX_PointF& beginPoint, + const CFX_PointF& endPoint, + const float beginRadius, + const float endRadius, + bool isExtendedBegin, + bool isExtendedEnd, + const FX_ARGB beginArgb, + const FX_ARGB endArgb); + virtual ~CXFA_Shading(); + + private: + friend class CXFA_Graphics; + + void InitArgbArray(); + + const CXFA_Shading_Type m_type; + const CFX_PointF m_beginPoint; + const CFX_PointF m_endPoint; + const float m_beginRadius; + const float m_endRadius; + const bool m_isExtendedBegin; + const bool m_isExtendedEnd; + const FX_ARGB m_beginArgb; + const FX_ARGB m_endArgb; + FX_ARGB m_argbArray[FX_SHADING_Steps]; +}; + +#endif // XFA_FXGRAPHICS_CXFA_SHADING_H_ |