Module: Minicomic

Extended by:
Minicomic
Included in:
Minicomic
Defined in:
lib/minicomic.rb

Defined Under Namespace

Classes: BookletLayout

Instance Method Summary collapse

Instance Method Details

#minicomic(dir) ⇒ Object



305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
# File 'lib/minicomic.rb', line 305

def minicomic( dir )
  pages_dir = File.join( dir, 'pages' )

  scratch_dir = File.join( dir, 'scratch' )
  directory scratch_dir

  web_dir = File.join( dir, 'web' )
  directory web_dir

  print_dir = File.join( dir, 'print' )
  directory print_dir

  layout_ps = File.join( scratch_dir, 'layout.ps' )

  specials = Set.new
  pages = []

  FileList[File.join( pages_dir, '*.svg' )].each do |page_svg|
    name = File.basename( page_svg )
    name.sub!( /\.svg$/, '' )

    min = max = nil
    print_name = name
    case name
    when *SPECIAL_NAME_RES
      name = normalize_special_name( name )
      next unless SPECIAL_NAMES.include? name # warning?
      next if specials.include? name # warning?
      specials.add name
      if name == 'front-cover'
        web_name = "page-00"
      else
        web_name = nil
      end
    when /^page\W*(\d+)$/i
      min = max = $1.to_i
      suffix = "%02d" % [ min ]
      print_name = "page-#{ suffix }"
      web_name = print_name
    when /^pages?\W*(\d+)\D+(\d+)$/i
      min, max = $1.to_i, $2.to_i
      min, max = max, min if max < min
      suffix = "%02d-%02d" % [ min, max ]
      print_name = "pages-#{ suffix }"
      web_name = print_name
    else
      # warning?
      next
    end

    page_eps = File.join( scratch_dir, "#{ print_name }.eps" )

    if min and min > 0
      size = max - min + 1
      (0...size).each do |n|
        pages[n+min-1] = [ n, size, page_eps ]
      end
    end

    eps_from_svg( page_eps, page_svg )
    task page_eps => [ scratch_dir ]

    if web_name
      page_png = File.join( web_dir, "#{ web_name }.png" )
      png_from_svg( page_png, page_svg )
      task page_png => [ web_dir ]
      
      thumbnail_name = web_name.sub( /^page/, 'thumbnail' )
      thumbnail_jpeg = File.join( web_dir, "#{ thumbnail_name }.jpeg" )
      thumbnail_jpeg_from_image( thumbnail_jpeg, page_png )
      task thumbnail_jpeg => [ web_dir ]

      task :web => [ page_png, thumbnail_jpeg ]
    end
  end

  pages = [ nil, nil ] + pages + [ nil ] * ( pages.size % 4 ) + [ nil, nil ]

  specials.each do |name|
    filename = File.join( scratch_dir, "#{ name }.eps" )
    case name
    when 'front-cover'
      pages[0] ||= [ 0, 1, filename ] # 'cover' takes precedence
    when 'back-cover'
      pages[-1] ||= [ 0, 1, filename ] # 'cover' takes precedence
    when 'cover'
      pages[-1] = [ 0, 2, filename ]
      pages[0] = [ 1, 2, filename ]
    when 'inside-front'
      pages[1] = [ 0, 1, filename ]
    when 'inside-back'
      pages[-2] = [ 0, 1, filename ]
    end
  end

  layout_booklet( layout_ps, *pages )

  duplex_eps = File.join( scratch_dir, "duplex.eps" )

  %w(proof back front duplex).each do |kind|
    case kind
    when 'duplex', 'proof'
      source = layout_ps
    else
      source = duplex_eps
    end 
    kind_eps = File.join( scratch_dir, "#{ kind }.eps" )
    send( "#{ kind }_eps", kind_eps, source )
    task kind_eps => [ scratch_dir ]
    kind_pdf = File.join( print_dir, "#{ kind }.pdf" )
    pdf_from_eps( kind_pdf, kind_eps )
    task kind_pdf => [ print_dir ]
    task kind => [ kind_pdf ]
  end

  desc "Generate PDF files for printing"
  task :print => [ :duplex, :front, :back ]

  desc "Generate a proof PDF for review"
  task :proof

  desc "Remove all output and intermediate files"
  task :clean do
    rm_rf print_dir
    rm_rf web_dir
    rm_rf scratch_dir
  end

  desc "Generate graphics for the web"
  task :web

  desc "Generate web and print output"
  task :both => [ :print, :web ]

  task :default => [ :both ]
end