prawnpdf/ttfunk

Multitude of Warnings

Opened this issue · 8 comments

Hi,

I am using prawn lately, it works very well.

One problem I have is the amount of warnings though:

/Programs/Ruby/2.1.1/lib/ruby/gems/2.1.0/gems/ttfunk-1.1.1/lib/ttfunk/directory.rb:7: warning: assigned but unused variable - search_range
/Programs/Ruby/2.1.1/lib/ruby/gems/2.1.0/gems/ttfunk-1.1.1/lib/ttfunk/directory.rb:8: warning: assigned but unused variable - entry_selector
/Programs/Ruby/2.1.1/lib/ruby/gems/2.1.0/gems/ttfunk-1.1.1/lib/ttfunk/directory.rb:8: warning: assigned but unused variable - range_shift
/Programs/Ruby/2.1.1/lib/ruby/gems/2.1.0/gems/ttfunk-1.1.1/lib/ttfunk/resource_file.rb:15: warning: assigned but unused variable - data_length
/Programs/Ruby/2.1.1/lib/ruby/gems/2.1.0/gems/ttfunk-1.1.1/lib/ttfunk/table/cmap/format00.rb:47: warning: assigned but unused variable - length
/Programs/Ruby/2.1.1/lib/ruby/gems/2.1.0/gems/ttfunk-1.1.1/lib/ttfunk/table/cmap/format06.rb:40: warning: assigned but unused variable - length
/Programs/Ruby/2.1.1/lib/ruby/gems/2.1.0/gems/ttfunk-1.1.1/lib/ttfunk/table/cmap/format10.rb:40: warning: assigned but unused variable - length
/Programs/Ruby/2.1.1/lib/ruby/gems/2.1.0/gems/ttfunk-1.1.1/lib/ttfunk/table/cmap/format12.rb:51: warning: assigned but unused variable - length
/Programs/Ruby/2.1.1/lib/ruby/gems/2.1.0/gems/ttfunk-1.1.1/lib/ttfunk/table/kern/format0.rb:15: warning: assigned but unused variable - search_range
/Programs/Ruby/2.1.1/lib/ruby/gems/2.1.0/gems/ttfunk-1.1.1/lib/ttfunk/table/kern/format0.rb:15: warning: assigned but unused variable - entry_selector
/Programs/Ruby/2.1.1/lib/ruby/gems/2.1.0/gems/ttfunk-1.1.1/lib/ttfunk/table/kern/format0.rb:15: warning: assigned but unused variable - range_shift
/Programs/Ruby/2.1.1/lib/ruby/gems/2.1.0/gems/ttfunk-1.1.1/lib/ttfunk/table/name.rb:56: warning: assigned but unused variable - id
/Programs/Ruby/2.1.1/lib/ruby/gems/2.1.0/gems/ttfunk-1.1.1/lib/ttfunk/table/name.rb:79: warning: assigned but unused variable - format
/Programs/Ruby/2.1.1/lib/ruby/gems/2.1.0/gems/ttfunk-1.1.1/lib/ttfunk/table/post.rb:66: warning: assigned but unused variable - end_of_table
/Programs/Ruby/2.1.1/lib/ruby/gems/2.1.0/gems/ttfunk-1.1.1/lib/ttfunk/table/post/format25.rb:17: warning: assigned but unused variable - number_of_glyphs
/Programs/Ruby/2.1.1/lib/ruby/gems/2.1.0/gems/ttfunk-1.1.1/lib/ttfunk/subset/base.rb:34: warning: assigned but unused variable - code

Would it be possible to do something about these variables? I am not sure if fixing it is easy or worth it, but right now I am unsure what to do - I run my ruby code with warnings enabled, and ttfunk is the first gem that really outputs a lot of these things when I require prawn.

I meant the warnings of ttfunk, not in prawn itself - forgot to make that clear above. From prawn itself I do not get any warnings.

I'd absolutely accept a patch to quiet these. I'll leave the ticket open because it's worth fixing, but it may be some time until I get around to it myself.

Hi guys, I just submitted a pull request (#21) that fixes this issue.

@jessedoyle; Awesome! What do you think of the idea of using _fieldname instead of the single anonymous _ variable? I think that would still quiet the warnings, and would prevent the need to add a comment for each line that has some unused variables. For example:

@scaler_type, _table_count, _search_range, entry_selector = io.read(12).unpack("Nn*")

If that looks OK to you, please update the pull request and then I'll merge.

@sandal @jessedoyle

What do you think about calling #seek on the IO object to skip over the information we don't need and only assign to variables the data we need? It fixes the warnings and removes the references to unused data in the source.

@packetmonkey: That would also be OK! So would using pack's skip syntax, i.e. something like "nx2n" to read a 16 bit integer, skip ahead two bytes, and then read another. Either way works.

Thanks for the quick feedback!

@sandal: I like your idea about using the about using the unpack skip directive. I'll gladly update pull request #21 to use the byteskip directive.

I'll use an example to demonstrate the proposed changes:
(from ttfunk/lib/ttfunk/resource_file.rb:15)

Old Code:

data_offset, map_offset, data_length, map_length = @io.read(16).unpack("N*")

Updated Code: (Here the variable data_length is unused)

data_offset, map_offset, map_length = @io.read(16).unpack("NNx4N")

Is everyone okay if I go ahead and make these changes across all the unused variable assignments that ruby complains about?

I've cut a TTFunk release w. @jessedoyle's patch which should resolve this problem. It will be used in the next version of Prawn.