From: Kouhei S. <nu...@co...> - 2017-07-31 01:24:09
|
Kouhei Sutou 2017-07-31 10:23:40 +0900 (Mon, 31 Jul 2017) New Revision: cd2f4662d173648735ad0265829debd6f0fe338a https://github.com/ruby-gnome2/ruby-gnome2/commit/cd2f4662d173648735ad0265829debd6f0fe338a Message: poppler: define class for each field type Removed files: poppler/lib/poppler/form-field.rb Modified files: poppler/lib/poppler/loader.rb poppler/test/test-document.rb Deleted: poppler/lib/poppler/form-field.rb (+0 -23) 100644 =================================================================== --- poppler/lib/poppler/form-field.rb 2017-07-31 10:15:15 +0900 (b000013) +++ /dev/null @@ -1,23 +0,0 @@ -# Copyright (C) 2017 Ruby-GNOME2 Project Team -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - -module Poppler - class FormField - - alias_method :text, :text_get_text - alias_method :text=, :text_set_text - end -end Modified: poppler/lib/poppler/loader.rb (+41 -1) =================================================================== --- poppler/lib/poppler/loader.rb 2017-07-31 10:15:15 +0900 (d1bbfc6) +++ poppler/lib/poppler/loader.rb 2017-07-31 10:23:40 +0900 (31ae237) @@ -18,10 +18,12 @@ module Poppler class Loader < GObjectIntrospection::Loader private def pre_load(repository, namespace) + @form_field_classes = {} end def post_load(repository, namespace) require_libraries + convert_field_classes end def require_libraries @@ -31,7 +33,6 @@ module Poppler require "poppler/cairo" require "poppler/color" require "poppler/document" - require "poppler/form-field" require "poppler/deprecated" end @@ -43,8 +44,47 @@ module Poppler when "annot_type" method_name = "type" end + when "Poppler::FormField" + case method_name + when /\Abutton_/ + klass = define_field_class("ButtonField") + method_name = rubyish_method_name(info, prefix: "button_") + method_name = "type" if method_name == "button_type" + when /\Atext_/ + klass = define_field_class("TextField") + method_name = rubyish_method_name(info, prefix: "text_") + method_name = "type" if method_name == "text_type" + when /\Achoice_/ + klass = define_field_class("ChoiceField") + method_name = rubyish_method_name(info, prefix: "choice_") + method_name = "type" if method_name == "choice_type" + end end super(info, klass, method_name) end + + def define_field_class(name) + klass = @form_field_classes[name] + return klass if klass + + field_class = @base_module.const_get("FormField") + klass = @form_field_classes[name] = Class.new(field_class) + @base_module.const_set(name, klass) + klass + end + + def convert_field_classes + define_field_class("SignatureField") + + field_map = { + FormFieldType::BUTTON => ButtonField, + FormFieldType::TEXT => TextField, + FormFieldType::CHOICE => ChoiceField, + FormFieldType::SIGNATURE => SignatureField, + } + self.class.register_object_class_converter(FormField.gtype) do |field| + field_map[field.field_type] || FormField + end + end end end Modified: poppler/test/test-document.rb (+1 -2) =================================================================== --- poppler/test/test-document.rb 2017-07-31 10:15:15 +0900 (1ca9f36) +++ poppler/test/test-document.rb 2017-07-31 10:23:40 +0900 (e57b199) @@ -50,8 +50,7 @@ class TestDocument < Test::Unit::TestCase document.each do |page| page.form_field_mapping.each do |mapping| field = mapping.field - p field.class - return field if field.field_type == Poppler::FormFieldType::TEXT + return field if field.is_a?(Poppler::TextField) end end end |