support arbitrary fill patterns

This issue has been created since 2021-04-01.
module Prawn
  module Graphics
    module Patterns

can generate shading patterns

PatternType: 2

but there is no support for fill patterns yet

PatternType: 1

here an example from the PDF doc

15 0 obj
<< /Type /Pattern
/PatternType 1          % Tiling pattern
/PaintType 1
/TilingType 2
/BBox [ 0 0 100 100 ]
/XStep 100
/YStep 100
/Resources 16 0 R
/Matrix [ 0.4 0.0 0.0 0.4 0.0 0.0 ]
/Length 183
>>

it would be great if prawn would support this. think of (monochrome) bar charts with patterns etc.

artbot1 wrote this answer on 2021-04-01

here some (very) quick an dirty sample code for this (just to see what's possible):

require 'prawn.rb'

module Prawn
  module Graphics
    module Patterns
      def create_art_pattern
        patterns = page.resources[:Pattern] ||= {}

        art_pat= ref!(
          #Type: '/Pattern',
          PatternType: 1,
          PaintType: 1,
          TilingType: 2,
          BBox: [ 0,0,20,20 ],
          XStep: 20,
          YStep: 20,
          Matrix: [ 1.0,0.0,0.0,1.0,0.0,0.0 ]
        )

        stream= PDF::Core::Stream.new
        stream << "5.0 5.0 10.0 10.0 re"
        stream << "\nf"

        art_pat.stream = stream

        registry_key= "dummytest123"
        patterns["SP#{registry_key}"] = art_pat

        type= :fill

        operator =
          case type
          when :fill
            'scn'
          when :stroke
            'SCN'
          else
            raise ArgumentError, "unknown type '#{type}'"
          end

        set_color_space type, :Pattern
        renderer.add_content "/SP#{registry_key} #{operator}"
      end

    end
  end
end

pdf= Prawn::Document.new(page_layout: :portrait, page_size: 'A4', margin: 0.0) do
  #stroke_axis(:step_length => 1.cm.to_i) #only shows up with margin > 0
  pdf= self
  #fill_gradient [50, 300], [150, 200], 'ff0000', '0000ff'

  create_art_pattern
  fill_rectangle [50, 300], 100, 100

  #fill_rectangle [155, 300], 100, 100


  render_file('/tmp/gradient.pdf')
end
gettalong wrote this answer on 2022-02-04

Thanks - this sounds useful to have in Prawn but will probably be need to be implemented by the community. So pull requests for this feature are welcome!

More Details About Repo
Owner Name prawnpdf
Repo Name prawn
Full Name prawnpdf/prawn
Language Ruby
Created Date 2008-04-04
Updated Date 2022-09-13
Star Count 4358
Watcher Count 97
Fork Count 668
Issue Count 113

YOU MAY BE INTERESTED

Issue Title Created Date Comment Count Updated Date
Tsize too large for encoding 9 2022-03-15 2022-09-12
Finished Step 5 but still encounter "fetching that device" error, Unable to Click **New Authorization 1 2021-04-01 2022-05-15
Signature verification failed downloading for the first time 11 2022-01-05 2022-09-02
recent-changes feeds for a certain period of time 3 2021-05-28 2022-05-08
JSON deserialization failure 5 2020-12-14 2022-07-23
`quantus.explain` shows zennit warning, when generating explanatins for TF model using tf-explain 1 2022-08-25 2022-09-17
Dependency conflict in requirements 2 2022-09-04 2022-09-17
Enable batch processing for TF-Explain 2 2022-08-25 2022-09-17
Accessing ATL14 gridded land ice data with icepyx.Query 4 2022-03-05 2022-05-16
I do Mass DM after a while I get each time a lot of captchas- maybe the settings need to change? 0 2022-04-26 2022-09-19
TypeError: Cannot read property 'getContractFactory' of undefined 1 2021-10-25 2022-09-16
[Proposal] Support multiple `refreshListenable`s 4 2021-11-22 2022-09-27
Breaks with a comma character in the code block info string 1 2021-03-06 2022-09-05
Evaluate stripping of `&quot;` in HTML output 1 2021-12-19 2022-07-03
BUG: Structure view breaks with tstzrange exclusion constraint 0 2022-08-08 2022-09-09
BUG: always loading 3 2022-08-05 2022-09-02
the plugin does not work on ios 18 2018-10-17 2022-09-25
StreetComplete asks for data on cycleways under construction 11 2021-10-23 2022-09-26
net::ERR_CONNECTION_REFUSED 0 2021-08-07 2022-09-20
workspace bulk-add: allow parsing stdin instead of filesystem paths 1 2021-12-02 2022-09-26
Node identity import error 5 2022-02-03 2022-08-04
State parameter for multi tenant web app. 0 2022-05-23 2022-09-22
QUESTION: Port Example to FastAPI Framework? 0 2021-12-22 2022-09-22
Additional Context is Needed for Working with PowerBi and Queries 2 2022-05-18 2022-08-31
SignalRNegotiateHTTPTrigger error in python 2 2021-10-17 2022-09-22
Installing @oclif/plugin-help gives 5 moderate vulnerabilities and npm audit fix breaks it. 0 2021-10-15 2022-08-27
[BUG] CLI | skipped policy message is displayed even if variable is passed 0 2021-09-28 2022-09-28
`/(?<foo>A)\k<foo>/` is a syntax error unless using Annex B 8 2021-06-13 2022-09-25
Avoid polluting notification feed with meaningless logs 0 2018-01-19 2022-09-28
TASK: Triage JS SDK user guide code example feedback (issues) 1 2021-12-08 2022-09-10
TASK: Triage AWS SDK for PHP customer feedback issues 0 2021-12-09 2022-07-16
App Stuck on Splash Screen on Android 4 2022-02-10 2022-09-05
Load Balancer Target Group Sticky Option 0 2022-07-18 2022-09-21
For ArrayBuffer#min and max, Scala 2.13 is slower than 2.12 7 2022-07-01 2022-09-18
Windows CMake error "Could NOT find Protobuf" 2 2021-05-24 2022-08-29
help!! windows Omnicore desktop wallet start fail 1 2021-02-26 2022-09-22
Error: voca_malloc: maximum dict size exceeded limit (65535) 2 2021-01-05 2022-09-20
Reaction stopped working while Notification from telegram in its background 0 2022-06-01 2022-09-19
Intelligently rerun `nbdev_export` in `nbdev_merge` for more automated conflict resolution 6 2022-08-16 2022-09-24
IntelliSense does not work when changed SearchPath in PythonSettings.json file in open folder. 4 2021-08-03 2022-09-20
Adding new module/module default version in same template fails if module already existed 4 2021-02-22 2022-09-11
copilot task run doesn't fill in secrets and variables from manifest.yml 2 2022-06-27 2022-09-02
[Dynamic Region] some region can not split after change region size repeatedly 6 2022-05-12 2022-09-19
Implement upload in chunks 0 2020-05-25 2022-09-22
gzip from Ubuntu Jammy doesn't execute 24 2022-04-01 2022-09-26
Unable to install on Ubuntu 20.04.3 LTS 6 2021-11-11 2022-09-22
Vault agent ignored listener unless cache stanza is specified 3 2022-03-10 2022-09-26
Speed up cache service tests by not forking Minion jobs 1 2021-08-31 2022-05-02
[Improvement] Add Iceberg (and minimal Spark DSv2) commands to Authz module 3 2022-04-28 2022-09-16
Couldn't resolve parser "tsx" 3 2020-01-08 2022-09-07