File handling cleanup.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9973 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
1 parent
0dbe234226
commit
823ac010c5
3 files changed
+30
-25
No files matched your search
@@ -57,12 +57,7 @@ module RFPDF
|
|||||||
end
|
end
|
||||||
|
|
||||||
out['bits'] = image.channel_depth
|
out['bits'] = image.channel_depth
|
||||||
File.open( TCPDF.k_path_cache + File::basename(filename), 'w'){|f|
|
|
||||||
f.binmode
|
|
||||||
f.print image.to_blob
|
|
||||||
f.close
|
|
||||||
}
|
|
||||||
|
|
||||||
out
|
out
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,9 @@
|
|||||||
#
|
#
|
||||||
#============================================================+
|
#============================================================+
|
||||||
|
|
||||||
|
require 'tempfile'
|
||||||
|
require 'core/rmagick'
|
||||||
|
|
||||||
#
|
#
|
||||||
# TCPDF Class.
|
# TCPDF Class.
|
||||||
# @package com.tecnick.tcpdf
|
# @package com.tecnick.tcpdf
|
||||||
@@ -86,10 +89,10 @@ class TCPDF
|
|||||||
@@k_small_ratio = 2/3.0
|
@@k_small_ratio = 2/3.0
|
||||||
|
|
||||||
cattr_accessor :k_path_cache
|
cattr_accessor :k_path_cache
|
||||||
@@k_path_cache = Rails.root.join('tmp').to_s
|
@@k_path_cache = Rails.root.join('tmp')
|
||||||
|
|
||||||
cattr_accessor :k_path_url_cache
|
cattr_accessor :k_path_url_cache
|
||||||
@@k_path_url_cache = Rails.root.join('tmp').to_s
|
@@k_path_url_cache = Rails.root.join('tmp')
|
||||||
|
|
||||||
cattr_accessor :decoder
|
cattr_accessor :decoder
|
||||||
|
|
||||||
@@ -2060,16 +2063,12 @@ class TCPDF
|
|||||||
type.downcase!
|
type.downcase!
|
||||||
if (type == 'jpg' or type == 'jpeg')
|
if (type == 'jpg' or type == 'jpeg')
|
||||||
info=parsejpg(file);
|
info=parsejpg(file);
|
||||||
elsif (type == 'png' or type == 'gif')
|
elsif (type == 'png')
|
||||||
img = Magick::ImageList.new(file)
|
info=parsepng(file);
|
||||||
img.format = "PNG" # convert to PNG from gif
|
elsif (type == 'gif')
|
||||||
img.opacity = 0 # PNG alpha channel delete
|
tmpFile = imageToPNG(file);
|
||||||
open( @@k_path_cache + File::basename(file), 'w') do |f|
|
info=parsepng(tmpFile.path);
|
||||||
f.binmode
|
tmpFile.delete
|
||||||
f.print img.to_blob
|
|
||||||
end
|
|
||||||
info=parsepng( @@k_path_cache + File::basename(file));
|
|
||||||
File.delete( @@k_path_cache + File::basename(file))
|
|
||||||
else
|
else
|
||||||
#Allow for additional formats
|
#Allow for additional formats
|
||||||
mtd='parse' + type;
|
mtd='parse' + type;
|
||||||
@@ -2892,14 +2891,29 @@ class TCPDF
|
|||||||
#Read whole file
|
#Read whole file
|
||||||
data='';
|
data='';
|
||||||
|
|
||||||
open( @@k_path_cache + File::basename(file),'rb') do |f|
|
open(file,'rb') do |f|
|
||||||
data<<f.read();
|
data<<f.read();
|
||||||
end
|
end
|
||||||
File.delete( @@k_path_cache + File::basename(file))
|
|
||||||
|
|
||||||
return {'w' => a[0],'h' => a[1],'cs' => colspace,'bpc' => bpc,'f'=>'DCTDecode','data' => data}
|
return {'w' => a[0],'h' => a[1],'cs' => colspace,'bpc' => bpc,'f'=>'DCTDecode','data' => data}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def imageToPNG(file)
|
||||||
|
return unless Object.const_defined?(:Magick)
|
||||||
|
|
||||||
|
img = Magick::ImageList.new(file)
|
||||||
|
img.format = 'PNG' # convert to PNG from gif
|
||||||
|
img.opacity = 0 # PNG alpha channel delete
|
||||||
|
|
||||||
|
#use a temporary file....
|
||||||
|
tmpFile = Tempfile.new(['', '_' + File::basename(file) + '.png'], @@k_path_cache);
|
||||||
|
tmpFile.binmode
|
||||||
|
tmpFile.print img.to_blob
|
||||||
|
tmpFile
|
||||||
|
ensure
|
||||||
|
tmpFile.close
|
||||||
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Extract info from a PNG file
|
# Extract info from a PNG file
|
||||||
# @access protected
|
# @access protected
|
||||||
@@ -3937,9 +3951,6 @@ class TCPDF
|
|||||||
rescue => err
|
rescue => err
|
||||||
logger.error "pdf: Image: error: #{err.message}"
|
logger.error "pdf: Image: error: #{err.message}"
|
||||||
Write(@lasth, attrs['src'], '', fill);
|
Write(@lasth, attrs['src'], '', fill);
|
||||||
if File.file?( @@k_path_cache + File::basename(file))
|
|
||||||
File.delete( @@k_path_cache + File::basename(file))
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ require 'tcpdf'
|
|||||||
require 'fpdf/chinese'
|
require 'fpdf/chinese'
|
||||||
require 'fpdf/japanese'
|
require 'fpdf/japanese'
|
||||||
require 'fpdf/korean'
|
require 'fpdf/korean'
|
||||||
require 'core/rmagick'
|
|
||||||
|
|
||||||
module Redmine
|
module Redmine
|
||||||
module Export
|
module Export
|
||||||
@@ -36,7 +35,7 @@ module Redmine
|
|||||||
attr_accessor :footer_date
|
attr_accessor :footer_date
|
||||||
|
|
||||||
def initialize(lang)
|
def initialize(lang)
|
||||||
@@k_path_cache = Rails.root.join('tmp', 'pdf').to_s
|
@@k_path_cache = Rails.root.join('tmp', 'pdf')
|
||||||
FileUtils.mkdir_p @@k_path_cache unless File::exist?(@@k_path_cache)
|
FileUtils.mkdir_p @@k_path_cache unless File::exist?(@@k_path_cache)
|
||||||
set_language_if_valid lang
|
set_language_if_valid lang
|
||||||
pdf_encoding = l(:general_pdf_encoding).upcase
|
pdf_encoding = l(:general_pdf_encoding).upcase
|
||||||
|
|||||||
Reference in new issue
Block a user