Commit 73896c25 authored by Mame Coumba Sall's avatar Mame Coumba Sall

Various patches by mame to support width and height.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@14510 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 1d978441
def ERP5Site_createModuleScribus(self, form_id=None, module_portal_type=None, def ERP5Site_createModuleScribus(self, form_id=None, module_portal_type=None,
portal_skins_folder=None, object_portal_type=None, object_title=None, module_id=None, portal_skins_folder=None, object_portal_type=None, object_title=None, module_id=None,
module_title=None, selection_index=None, selection_name=None, import_scribus_file=None, module_title=None, selection_index=None, selection_name=None, import_scribus_file=None,
import_pdf_file=None, option_html=None, import_image_1=None, import_image_2=None, import_pdf_file=None, option_html=None,desired_height=None, desired_width=None, import_image_1=None, import_image_2=None,
import_image_3=None, **kw) : import_image_3=None, **kw) :
""" Creates a module, portal_type and ERP5Form from a scribus and """ Creates a module, portal_type and ERP5Form from a scribus and
PDFForm file""" PDFForm file"""
...@@ -27,21 +27,21 @@ def ERP5Site_createModuleScribus(self, form_id=None, module_portal_type=None, ...@@ -27,21 +27,21 @@ def ERP5Site_createModuleScribus(self, form_id=None, module_portal_type=None,
ManageCSS = ManageCSS() ManageCSS = ManageCSS()
generator = LocalGenerator() generator = LocalGenerator()
# DECLARING VARIABLES # DECLARING VARIABLES
def_lineNumberInList = 20 def_lineNumberInList = 20 # JPS-XXX - hardcoded
def_colorRequired = 'rgb(192,192,255)' def_colorRequired = 'rgb(192,192,255)' # JPS-XXX - hardcoded
def_colorRequiredError = 'rgb(128,128,255)' def_colorRequiredError = 'rgb(128,128,255)' # JPS-XXX - hardcoded
def_color = '#F6FFFF' def_color = '#F6FFFF' # JPS-XXX - hardcoded
def_colorError = 'rgb(255,64,64)' def_colorError = 'rgb(255,64,64)' # JPS-XXX - hardcoded
# recovering objects # recovering objects
portal = context.getPortalObject() portal = context.getPortalObject()
portal_types = portal.portal_types portal_types = portal.portal_types
object_portal_type_id = object_portal_type object_portal_type_id = object_portal_type
desired_height= desired_height
desired_width= desired_width
resolution= 300 # JPS-XXX - hardcoded
option_html = option_html
# DECLARING NAMES # DECLARING NAMES
# declaring names for ERP5 objects, such as Form, DTML Document, etc. # declaring names for ERP5 objects, such as Form, DTML Document, etc.
...@@ -49,7 +49,6 @@ def ERP5Site_createModuleScribus(self, form_id=None, module_portal_type=None, ...@@ -49,7 +49,6 @@ def ERP5Site_createModuleScribus(self, form_id=None, module_portal_type=None,
object_names = ManageModule.setObjectNames(object_portal_type_id, object_names = ManageModule.setObjectNames(object_portal_type_id,
object_title) object_title)
# CREATING NEW PORTAL TYPE FOR THE MODULE # CREATING NEW PORTAL TYPE FOR THE MODULE
# Manage the creation of a ne portal_type for the module # Manage the creation of a ne portal_type for the module
# (module is not saved for the moment, but properties can be # (module is not saved for the moment, but properties can be
...@@ -96,6 +95,7 @@ def ERP5Site_createModuleScribus(self, form_id=None, module_portal_type=None, ...@@ -96,6 +95,7 @@ def ERP5Site_createModuleScribus(self, form_id=None, module_portal_type=None,
global_properties = ScribusParser.initFieldDict() global_properties = ScribusParser.initFieldDict()
# PARSER VARIABLES DECLARATION # PARSER VARIABLES DECLARATION
# the following variable will recover the final CSS # the following variable will recover the final CSS
# file's content object (string) before saving it # file's content object (string) before saving it
...@@ -105,14 +105,11 @@ def ERP5Site_createModuleScribus(self, form_id=None, module_portal_type=None, ...@@ -105,14 +105,11 @@ def ERP5Site_createModuleScribus(self, form_id=None, module_portal_type=None,
properties_css_dict = {} properties_css_dict = {}
# init page number # init page number
page_number_int = 0 page_number_int = 0
scale_factor=0
# import scribus file # import scribus file
# take the input ScribusFile and read the content # take the input ScribusFile and read the content
xml_string = ScribusParser.getContentFile(import_scribus_file) xml_string = ScribusParser.getContentFile(import_scribus_file)
if xml_string == None: if xml_string == None:
LOG("ScribusParser",1,"Scribus file is empty !")
print "no field was defined in the Scribus file" print "no field was defined in the Scribus file"
pass pass
else: else:
...@@ -121,7 +118,6 @@ def ERP5Site_createModuleScribus(self, form_id=None, module_portal_type=None, ...@@ -121,7 +118,6 @@ def ERP5Site_createModuleScribus(self, form_id=None, module_portal_type=None,
# get string from ScribusFile content # get string from ScribusFile content
output_string = str(xml_string) output_string = str(xml_string)
print " createmodule > ScribusParser.getXmlObjectPropertiesDict" print " createmodule > ScribusParser.getXmlObjectPropertiesDict"
# building a tree from the output string elaborated from the # building a tree from the output string elaborated from the
# original Scribus file. # original Scribus file.
...@@ -141,10 +137,13 @@ def ERP5Site_createModuleScribus(self, form_id=None, module_portal_type=None, ...@@ -141,10 +137,13 @@ def ERP5Site_createModuleScribus(self, form_id=None, module_portal_type=None,
# to extract all the usefull properties and organize elements. Then check # to extract all the usefull properties and organize elements. Then check
# attributes to get properties values. # attributes to get properties values.
# This represents the main process of the script. # This represents the main process of the script.
widget_properties = ScribusParser.getPropertiesConversionDict(text_field_list) (widget_properties) = ScribusParser.getPropertiesConversionDict(text_field_list)
print " createmodule < ScribusParser.getPropertiesConversionDict\n" print " createmodule < ScribusParser.getPropertiesConversionDict\n"
# testing if final rendering is PDF-like # testing if final rendering is PDF-like
if option_html ==1 : if option_html ==1 :
print " createmodule > generating background" print " createmodule > generating background"
...@@ -153,35 +152,30 @@ def ERP5Site_createModuleScribus(self, form_id=None, module_portal_type=None, ...@@ -153,35 +152,30 @@ def ERP5Site_createModuleScribus(self, form_id=None, module_portal_type=None,
# format (JPG) and add them to the skin folder as Image objects. # format (JPG) and add them to the skin folder as Image objects.
# used only with option_html == 1 # used only with option_html == 1
# recover image_size # recover image_size
image_size = ManageFiles.setBackgroundPictures(import_pdf_file, image_size=ManageFiles.setBackgroundPictures(import_pdf_file,object_names,skin_folder,desired_height,desired_width,resolution)
object_names,
skin_folder) page_height,page_width,original_page_height,original_page_width = image_size
page_height, page_width = image_size
print " height = " + str(page_height) print " height = " + str(page_height)
print " width = " + str(page_width) print " width = " + str(page_width)
print " createmodule < background generated\n" print " createmodule < background generated\n"
# add field from OrderedWidgetProperties in ERP5 Module created # add field from OrderedWidgetProperties in ERP5 Module created
# radiofield_widget_properties = {} # radiofield_widget_properties = {}
position = {} position = {}
# personal_properties_list is used to create PropertySheet # personal_properties_list is used to create PropertySheet
personal_properties_list = [] personal_properties_list = []
# recovering number of pages # recovering number of pages
global_properties['page'] = len(widget_properties) global_properties['page'] = len(widget_properties)
# CSS FILE INIT # CSS FILE INIT
# init the CSS dict by creating sub-dicts to store various information # init the CSS dict by creating sub-dicts to store various information
# i.e : 'head', 'standard' ,'error', etc. # i.e : 'head', 'standard' ,'error', etc.
# these sub-dicts are stored in the properties_css_dict # these sub-dicts are stored in the properties_css_dict
properties_css_dict = ManageCSS.setInit() properties_css_dict = ManageCSS.setInit()
# BEGINING DATA INTERPRETATION # BEGINING DATA INTERPRETATION
LOG("ScribusParser",0,"begining interpretation of data")
print " createmodule > begining data interpretation" print " createmodule > begining data interpretation"
#iterating pages #iterating pages
#print " %s" % int(global_properties['page']) #print " %s" % int(global_properties['page'])
...@@ -190,22 +184,22 @@ def ERP5Site_createModuleScribus(self, form_id=None, module_portal_type=None, ...@@ -190,22 +184,22 @@ def ERP5Site_createModuleScribus(self, form_id=None, module_portal_type=None,
page_content = widget_properties[page_number] page_content = widget_properties[page_number]
page_id = "page_" + page_number page_id = "page_" + page_number
if option_html == 1: if option_html == 1:
# CSS PAGE DEFINITION (PAGE AND BACKGROUND IMAGE) # CSS PAGE DEFINITION (PAGE AND BACKGROUND IMAGE)
# get CSS class properties relative to the actual page # get CSS class properties relative to the actual page
# (background picture position, picture size, etc.) # (background picture position, picture size, etc.)
# and add them to the css dict # and add them to the css dict
properties_css_dict = ManageCSS.setPageProperties( width_groups,height_groups = ManageFiles.getPageattributes(
global_properties,
import_pdf_file)
properties_css_dict,properties_page,actual_width,actual_height = ManageCSS.setPageProperties(
properties_css_dict, properties_css_dict,
page_iterator, page_iterator,
page_id, page_id,
page_height) page_height,
page_width,
original_page_width,
original_page_height,width_groups,height_groups)
# RESUME DATA INTERPRETATION # RESUME DATA INTERPRETATION
# iterating pageobjects in page # iterating pageobjects in page
...@@ -226,11 +220,16 @@ def ERP5Site_createModuleScribus(self, form_id=None, module_portal_type=None, ...@@ -226,11 +220,16 @@ def ERP5Site_createModuleScribus(self, form_id=None, module_portal_type=None,
page_height, page_height,
page_iterator, page_iterator,
page_gap, page_gap,
keep_page) keep_page,
0,
0,
properties_page,actual_width,actual_height)
# recover useful page_object attributes from scribus dict # recover useful page_object attributes from scribus dict
# to be able to create and update correctly the fields # to be able to create and update correctly the fields
# composing the form # composing the form
ScribusParser.getFieldAttributes(page_content[index], ScribusParser.getFieldAttributes(page_content[index],
option_html, option_html,
page_id, page_id,
...@@ -270,13 +269,15 @@ def ERP5Site_createModuleScribus(self, form_id=None, module_portal_type=None, ...@@ -270,13 +269,15 @@ def ERP5Site_createModuleScribus(self, form_id=None, module_portal_type=None,
# create fields corresponding to the page_objects # create fields corresponding to the page_objects
# recovered from the scribus file # recovered from the scribus file
ManageModule.setFieldsInObjectForm(skin_folder, ManageModule.setFieldsInObjectForm(skin_folder,
object_names, object_names,
default_groups, default_groups,
global_properties, global_properties,
option_html option_html
) )
print " createmodue < fields created in ERP5 Form\n"
print " createmodule < fields created in ERP5 Form\n"
...@@ -296,6 +297,7 @@ def ERP5Site_createModuleScribus(self, form_id=None, module_portal_type=None, ...@@ -296,6 +297,7 @@ def ERP5Site_createModuleScribus(self, form_id=None, module_portal_type=None,
# PROPERTYSHEET AND DOCUMENT CREATION # PROPERTYSHEET AND DOCUMENT CREATION
print " createmodule > PropertySheet and Document creation" print " createmodule > PropertySheet and Document creation"
# recover personal properties and save them in a PropertySheet # recover personal properties and save them in a PropertySheet
# then create the Document related to the object # then create the Document related to the object
...@@ -346,4 +348,4 @@ def ERP5Site_createModuleScribus(self, form_id=None, module_portal_type=None, ...@@ -346,4 +348,4 @@ def ERP5Site_createModuleScribus(self, form_id=None, module_portal_type=None,
) )
# redirect # redirect
portal.REQUEST.RESPONSE.redirect( redirect_url ) portal.REQUEST.RESPONSE.redirect(redirect_url )
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
# Copyright (c) 2005 Nexedi SARL and Contributors. All Rights Reserved. # Copyright (c) 2005 Nexedi SARL and Contributors. All Rights Reserved.
# Guy Oswald OBAMA <guy@nexedi.com> # Guy Oswald OBAMA <guy@nexedi.com>
# thomas <thomas@nexedi.com> # thomas <thomas@nexedi.com>
# Mame C.Sall <mame@nexedi.com>
# #
# This program is Free Software; you can redistribute it and/or # This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
...@@ -28,7 +29,7 @@ ...@@ -28,7 +29,7 @@
from Products.PythonScripts.Utility import allow_class from Products.PythonScripts.Utility import allow_class
from ZPublisher.HTTPRequest import FileUpload from ZPublisher.HTTPRequest import FileUpload
#from xml.dom.ext.reader import PyExpat from xml.dom.ext.reader import PyExpat
from xml.dom import Node, minidom from xml.dom import Node, minidom
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Globals import InitializeClass, get_request from Globals import InitializeClass, get_request
...@@ -41,7 +42,7 @@ import getopt, sys, os ...@@ -41,7 +42,7 @@ import getopt, sys, os
from urllib import quote from urllib import quote
from Products.ERP5.ERP5Site import ERP5Site from Products.ERP5.ERP5Site import ERP5Site
from Products.Formulator.TALESField import TALESMethod
# defining global variables # defining global variables
# ANFLAG tag # ANFLAG tag
# these values can be found in the Scribus document format # these values can be found in the Scribus document format
...@@ -77,6 +78,7 @@ class ManageModule: ...@@ -77,6 +78,7 @@ class ManageModule:
""" """
temp_portal_type = object_portal_type_id.replace(' ','') temp_portal_type = object_portal_type_id.replace(' ','')
object_names = {} object_names = {}
real_object_names={}
# declaring object that generate pdf output # declaring object that generate pdf output
object_names['view_pdf'] = temp_portal_type + '_view' +\ object_names['view_pdf'] = temp_portal_type + '_view' +\
temp_portal_type + 'AsPdf' temp_portal_type + 'AsPdf'
...@@ -143,8 +145,8 @@ class ManageModule: ...@@ -143,8 +145,8 @@ class ManageModule:
form_list_id = form_view_list_object.id form_list_id = form_view_list_object.id
form_list = form_view_list_object.restrictedTraverse(form_list_id) form_list = form_view_list_object.restrictedTraverse(form_list_id)
# defining groups for objects listing # defining groups for objects listing
form_view_list_object.rename_group('Default','left') form_view_list_object.rename_group('Default','bottom')
default_groups = ['right','center','bottom','hidden'] default_groups = []
# adding groups # adding groups
for group in default_groups: for group in default_groups:
form_view_list_object.add_group(group) form_view_list_object.add_group(group)
...@@ -157,7 +159,6 @@ class ManageModule: ...@@ -157,7 +159,6 @@ class ManageModule:
title = title_module title = title_module
field_type = 'ListBox' field_type = 'ListBox'
form_view_list_object.manage_addField(id,title,field_type) form_view_list_object.manage_addField(id,title,field_type)
form_view_list_object.move_field_group(['listbox'], 'left', 'bottom')
# manage ListBox settings # manage ListBox settings
values_settings = {} values_settings = {}
values_settings['pt'] = "form_list" values_settings['pt'] = "form_list"
...@@ -171,7 +172,8 @@ class ManageModule: ...@@ -171,7 +172,8 @@ class ManageModule:
# adding field columns # adding field columns
field_attributes.values['columns'] = [('id','ID'), field_attributes.values['columns'] = [('id','ID'),
('title','Title'), ('title','Title'),
('description','Description')] ('description','Description'),
('translated_simulation_state','State')]
field_attributes.values['list_action'] = 'list' field_attributes.values['list_action'] = 'list'
field_attributes.values['search'] = 1 field_attributes.values['search'] = 1
field_attributes.values['select'] = 1 field_attributes.values['select'] = 1
...@@ -184,7 +186,7 @@ class ManageModule: ...@@ -184,7 +186,7 @@ class ManageModule:
object_names, object_names,
option_html, option_html,
global_properties, global_properties,
object_portal_type, object_portal_type
): ):
""" """
create and manage erp5 form to handle object, and update its create and manage erp5 form to handle object, and update its
...@@ -196,6 +198,7 @@ class ManageModule: ...@@ -196,6 +198,7 @@ class ManageModule:
form_view_id_object = skin_folder[object_names['view_id']] form_view_id_object = skin_folder[object_names['view_id']]
form_id = form_view_id_object.id form_id = form_view_id_object.id
form = form_view_id_object.restrictedTraverse(form_id) form = form_view_id_object.restrictedTraverse(form_id)
#get the scaling factor
# managing form groups # managing form groups
default_groups = [] default_groups = []
if option_html !=1: if option_html !=1:
...@@ -205,6 +208,7 @@ class ManageModule: ...@@ -205,6 +208,7 @@ class ManageModule:
else: else:
# using special page positioning convention for # using special page positioning convention for
# pdf-like rendering # pdf-like rendering
del default_groups[0:]
for page_iterator in range(global_properties['page']): for page_iterator in range(global_properties['page']):
page_number = 'page_%s' % str(page_iterator) page_number = 'page_%s' % str(page_iterator)
default_groups.append(page_number) default_groups.append(page_number)
...@@ -238,8 +242,7 @@ class ManageModule: ...@@ -238,8 +242,7 @@ class ManageModule:
# using the dict declared just above to set the attributes # using the dict declared just above to set the attributes
for key, value in values.items(): for key, value in values.items():
setattr(form,key,value) setattr(form,key,value)
return default_groups return (default_groups)
security.declarePublic('setFieldsInObjectForm') security.declarePublic('setFieldsInObjectForm')
def setFieldsInObjectForm(self, def setFieldsInObjectForm(self,
...@@ -286,6 +289,7 @@ class ManageModule: ...@@ -286,6 +289,7 @@ class ManageModule:
field_type = field_values['erp_type'] field_type = field_values['erp_type']
field_title = field_values['title'] field_title = field_values['title']
field_order = field_values['order'] field_order = field_values['order']
#field_tales = field_values['tales']
# creating new field in form # creating new field in form
form_view_id_object.manage_addField(field_id, form_view_id_object.manage_addField(field_id,
field_title, field_title,
...@@ -296,6 +300,15 @@ class ManageModule: ...@@ -296,6 +300,15 @@ class ManageModule:
field_order) field_order)
# recover field # recover field
access_field = getattr(form_view_id_object,field_id) access_field = getattr(form_view_id_object,field_id)
if field_type == 'CheckBoxField':
test_name= field_id[3:]
tales = {field_id : {'default' : 'here'+ '/'+ test_name}}
forms = [object_names['view_id']]
form = form_view_id_object.restrictedTraverse(forms[0])
for k, v in tales.items() :
if hasattr(form, k) :
form[k].manage_tales_xmlrpc(v)
#if field_type == 'CheckBoxField': #if field_type == 'CheckBoxField':
# print " dir(%s) > %s" % (field_id,dir(access_field)) # print " dir(%s) > %s" % (field_id,dir(access_field))
# print "---manage_tales > %s \n\n" % dir(access_field.manage_tales) # print "---manage_tales > %s \n\n" % dir(access_field.manage_tales)
...@@ -532,26 +545,35 @@ class ManageFiles: ...@@ -532,26 +545,35 @@ class ManageFiles:
if cell_process_name_list[-1] == 'List': if cell_process_name_list[-1] == 'List':
TALES = "python: " + ", ".join( TALES = "python: " + ", ".join(
"here.get" + "".join(cell_process_name_list) + "()" ) "here.get" + "".join(cell_process_name_list) + "()" )
else: else:
TALES = "python: here.get" + "".join( TALES = "python: here.get" + "".join(
cell_process_name_list) + "()" cell_process_name_list) + "()"
else: else:
# PropertySheet and Document # PropertySheet and Document
if cell_process_name_list[-1] == 'List': if cell_process_name_list[-1] == 'List':
TALES = "python: " + ", ".join( TALES = "python: " + ", ".join(
"here.getProperty('" + cell_name[3:] + "')") "here.getProperty('" + cell_name[3:] + "')")
else: else:
TALES = "python: here.getProperty('" + cell_name[3:] +"')" TALES = "python: here.getProperty('" + cell_name[3:] +"')"
print " %s > %s " % (cell_name,TALES) print " %s > %s " % (cell_name,TALES)
c.setCellTALES(cell_name,TALES) c.setCellTALES(cell_name,TALES)
def getPDFFile(self, file_descriptor):
""" Get file content """
return file_descriptor.open()
security.declarePublic('setBackgroundPictures') security.declarePublic('setBackgroundPictures')
def setBackgroundPictures(self, def setBackgroundPictures(self,
pdf_file, pdf_file,
object_names, object_names,
skin_folder skin_folder,
desired_height,
desired_width,
resolution
): ):
""" """
extract background pictures from pdf file and convert them extract background pictures from pdf file and convert them
...@@ -566,22 +588,50 @@ class ManageFiles: ...@@ -566,22 +588,50 @@ class ManageFiles:
image (i.e page_0) and returns them. image (i.e page_0) and returns them.
""" """
import commands import commands
import tempfile
from tempfile import NamedTemporaryFile
# opening new file on HDD to save PDF content # opening new file on HDD to save PDF content
temp_pdf = open('/tmp/ScribusUtilsTempPDF','w') #temp_test= NamedTemporaryFile(mode= "w+b")
#tempFile= NamedTemporaryFile().name
ScribusUtilsTempPDF= NamedTemporaryFile(mode= "w+b")
ScribusUtilstempsPDFName= NamedTemporaryFile().name
# going to the begining of the input file
# XXX - this is really bad because the appropriate
# way to run zope is to create a local instance
# it should be removed XXX - some people
# do this just to make sure "it works"
# but it is not even multiplatform
os.putenv('TMPDIR', '/tmp')
# saving content
temp_pdf = open(ScribusUtilstempsPDFName,'w')
# going to the begining of the input file # going to the begining of the input file
pdf_file.seek(0) pdf_file.seek(0)
# saving content # saving content
temp_pdf.write(pdf_file.read()) temp_pdf.write(pdf_file.read())
temp_pdf.close() temp_pdf.close()
# launching first soft to convert from PDF to PPM # launching first soft to convert from PDF to PPM
result = commands.getstatusoutput( \ ScribusUtilstempsPPM = NamedTemporaryFile(mode="w+b")
'pdftoppm -r 72 /tmp/ScribusUtilsTempPDF /tmp/ScribusUtilsTempPPM') ScribusUtilstempsPPMName = NamedTemporaryFile().name
result = commands.getstatusoutput('pdftoppm -r %s %s %s' % (resolution, ScribusUtilstempsPDFName, ScribusUtilstempsPPMName))
# launching second soft to convert from PPM to JPEG # launching second soft to convert from PPM to JPEG
result = commands.getstatusoutput( \ ScribusUtilstempsJPG = NamedTemporaryFile(mode="w+b")
'convert /tmp/ScribusUtilsTempPPM* jpg:/tmp/ScribusUtilsTempJPG') ScribusUtilstempsJPGName = NamedTemporaryFile().name
original_result= commands.getstatusoutput('identify %s' % (ScribusUtilstempsPDFName))
result = commands.getstatusoutput('convert -density %s -resize %sx%s %s %s' % (resolution,desired_width,desired_height,ScribusUtilstempsPPMName + '*', 'jpg:' + ScribusUtilstempsJPGName))
number = ScribusUtilstempsJPGName.find('tmp')
directory_tmp= ScribusUtilstempsJPGName[:(number+4)]
# getting list of JPG output files # getting list of JPG output files
result = commands.getstatusoutput( \ result = commands.getstatusoutput('ls %s | grep %s' % (directory_tmp, ScribusUtilstempsJPGName.split('/')[-1]))
'ls /tmp/ | grep ScribusUtilsTempJPG') # deleting all temporary files
# getting the original size of the file
real_size_x= 0
real_size_y= 0
image_number = 0 image_number = 0
if result[1] != '': if result[1] != '':
# result[1] contains the output string from the command, # result[1] contains the output string from the command,
...@@ -594,16 +644,56 @@ class ManageFiles: ...@@ -594,16 +644,56 @@ class ManageFiles:
addImage(form_page_id,temp_jpg,"background image") addImage(form_page_id,temp_jpg,"background image")
image_number += 1 image_number += 1
# deleting all temporary files # deleting all temporary files
result = commands.getstatusoutput('rm -f /tmp/ScribusUtilsTemp*') result = commands.getstatusoutput('rm -f /tmp/tmp*') # JPS-XXX Extremely dangerous
# open page_0's final background picture to recover size_x and size_y # open page_0's final background picture to recover size_x and size_y
final_image = getattr(skin_folder, object_names['page'] + '0') final_image = getattr(skin_folder, object_names['page'] + '0')
size_x = final_image.getProperty('height') size_x = desired_height
size_y = final_image.getProperty('width') size_y = desired_width
# return size
#print size_x return (size_x, size_y,real_size_x,real_size_y)
#print size_y
return (size_x, size_y)
security.declarePublic('getPageattributes')
def getPageattributes (self,
global_properties,
pdf_file
):
import commands
from tempfile import NamedTemporaryFile
# opening new file on HDD to save PDF content
ScribusUtilsOriginalTempPDF= NamedTemporaryFile(mode= "w+b")
ScribusUtilsOriginaltempsPDFName= NamedTemporaryFile().name
# going to the begining of the input file
# saving content
temp_pdf = open(ScribusUtilsOriginaltempsPDFName,'w')
# going to the begining of the input file
pdf_file.seek(0)
# saving content
temp_pdf.write(pdf_file.read())
temp_pdf.close()
width_groups = []
height_groups = []
# launching first soft to convert from PDF to PPM
ScribusUtilsOriginaltempsPPM = NamedTemporaryFile(mode="w+b")
ScribusUtilsOriginaltempsPPMName = NamedTemporaryFile().name
original_result = commands.getstatusoutput('pdftoppm -r %s %s %s' % (72, ScribusUtilsOriginaltempsPDFName, ScribusUtilsOriginaltempsPPMName))
original_result= commands.getstatusoutput('identify %s' % (ScribusUtilsOriginaltempsPPMName + '*'))
pg_nbr = len(original_result[1].split('\n'))
real_size_x = {}
real_size_y = {}
for i in range(0,pg_nbr):
real_size_x[i]= \
float(original_result[1].split('\n')[i].split(' ')[2].split('x')[1])
real_size_y[i]= \
float(original_result[1].split('\n')[i].split(' ')[2].split('x')[0])
for page_iterator in range(global_properties['page']):
actual_page_height = real_size_x[page_iterator]
actual_page_width = real_size_y[page_iterator]
width_groups.append(actual_page_width)
height_groups.append(actual_page_height)
return (width_groups,height_groups)
security.declarePublic('setPropertySheetAndDocument') security.declarePublic('setPropertySheetAndDocument')
def setPropertySheetAndDocument(self, def setPropertySheetAndDocument(self,
...@@ -695,14 +785,16 @@ class ManageCSS: ...@@ -695,14 +785,16 @@ class ManageCSS:
# return dict # return dict
return properties_css_dict return properties_css_dict
security.declarePublic('setPageProperties') security.declarePublic('setPageProperties')
def setPageProperties(self def setPageProperties(self
,properties_css_dict ,properties_css_dict,
,page_iterator page_iterator
,page_id ,page_id
,page_height): ,page_height,
page_width,
original_page_width,
original_page_height,
width_groups,height_groups):
""" """
recover all CSS data relative to the current page and save these recover all CSS data relative to the current page and save these
information in the output dict information in the output dict
...@@ -710,6 +802,7 @@ class ManageCSS: ...@@ -710,6 +802,7 @@ class ManageCSS:
# Processing current page for CSS data # Processing current page for CSS data
# getting properties # getting properties
properties_css_page = {} properties_css_page = {}
properties_page = {}
properties_css_page['position'] = 'relative' properties_css_page['position'] = 'relative'
# creating image class for background # creating image class for background
properties_css_background = {} properties_css_background = {}
...@@ -721,14 +814,34 @@ class ManageCSS: ...@@ -721,14 +814,34 @@ class ManageCSS:
if page_iterator == 0: if page_iterator == 0:
# margin-top = 0 (first page) # margin-top = 0 (first page)
properties_css_page['margin-top'] = "0px" properties_css_page['margin-top'] = "0px"
properties_css_background['height'] = \
str(page_height) + 'px'
properties_css_background['width']= \
str (page_width) + 'px'
properties_page['actual_width'] = width_groups[page_iterator]
properties_page['actual_height'] = height_groups[page_iterator]
actual_width = width_groups[page_iterator]
actual_height = height_groups[page_iterator]
#properties_css_background['margin-top'] = \
# str((y_pos -10))+ 'px'
#properties_css_background['margin-left']= \
# str((x_pos- 5))+ 'px'
else: else:
# margin-top = page height # margin-top = page height
properties_css_page['margin-top'] = "%spx" % (page_height + 20) properties_css_page['margin-top'] = "%spx" %(page_height + 20)
properties_page['actual_width'] = width_groups[page_iterator]
properties_page['actual_height'] = height_groups[page_iterator]
actual_width = width_groups[page_iterator-1]
actual_height = height_groups[page_iterator -1]
properties_css_background['height'] = \
str(page_height) + 'px'
properties_css_background['width']= \
str (page_width) + 'px'
# adding properties dict to global dicts # adding properties dict to global dicts
properties_css_dict['head'][page_id] = properties_css_page properties_css_dict['head'][page_id] = properties_css_page
properties_css_dict['head'][background_id] = properties_css_background properties_css_dict['head'][background_id] = properties_css_background
# return updated dict # return updated dict
return properties_css_dict return (properties_css_dict,properties_page,actual_width,actual_height)
...@@ -739,25 +852,35 @@ class ManageCSS: ...@@ -739,25 +852,35 @@ class ManageCSS:
,properties_css_dict ,properties_css_dict
,field ,field
,page_width ,page_width
,page_height ,page_height,
,page_iterator page_iterator
,page_gap ,page_gap
,keep_page): ,keep_page,
original_page_width,
original_page_height,properties_page,actual_width,actual_height):
""" """
recover all CSS data relative to the current page_object (field) recover all CSS data relative to the current page_object (field)
and save these informations in the output dict and save these informations in the output dict
""" """
(field_name, properties_field) = field (field_name, properties_field) = field
print " => %s : %s" % (field_name,properties_field['rendering']) print " => %s : %s" % (field_name,properties_field['rendering'])
# updating field properties if necessary # updating field properties if necessary
if keep_page == 1: if keep_page == 1:
# document format is 1.3.* and define object position from the top-left # document format is 1.3.* and define object position from the top-left
# corner of the first page, whereas the field position is expected to # corner of the first page, whereas the field position is expected to
# be found from the current's page top left corner. # be found from the current's page top left corner.
# that's why Y position must be updated # that's why Y position must be updated
scaling_factor1= (page_width)/(properties_page['actual_width'])
scaling_factor2= (page_height)/(properties_page['actual_height'])
properties_field['position_y'] = \ properties_field['position_y'] = \
str(float(properties_field['position_y']) - \ str(float(properties_field['position_y']) - \
(page_height + page_gap)* page_iterator) (actual_height + page_gap)* page_iterator)
# Processing object for CSS data # Processing object for CSS data
# declaring dict containing all css data # declaring dict containing all css data
# _stand for general display # _stand for general display
...@@ -776,25 +899,35 @@ class ManageCSS: ...@@ -776,25 +899,35 @@ class ManageCSS:
properties_css_object_err_d['padding'] = '0px' properties_css_object_err_d['padding'] = '0px'
# getting field height # getting field height
properties_css_object_stand['height'] = \ properties_css_object_stand['height'] = \
str(properties_field['size_y']) + 'px' str(scaling_factor2 *float(properties_field['size_y'])) + 'px'
properties_css_object_error['height'] = \ properties_css_object_error['height'] = \
str(properties_field['size_y']) + 'px' str(scaling_factor2 *float(properties_field['size_y'])) + 'px'
# defining font-size from height - 2 (this value seems to have a good # defining font-size from height - 2 (this value seems to have a good
# rendering on Mozilla and Konqueror) # rendering on Mozilla and Konqueror)
# do not match for TextArea (as it is a multiline object) # do not match for TextArea (as it is a multiline object)
if properties_field['type'] != 'TextAreaField': if properties_field['type'] != 'TextAreaField':
if float(properties_field['size_y']) > 8.0:
properties_css_object_stand['font-size'] = \
str((scaling_factor2 *float(properties_field['size_y']))-5.5 ) + 'px'
properties_css_object_error['font-size'] = \
str((scaling_factor2 *float(properties_field['size_y']))-5.5) + 'px'
else:
properties_css_object_stand['font-size'] = \ properties_css_object_stand['font-size'] = \
str(int(properties_field['size_y']) - 2) + 'px' str((scaling_factor2 *float(properties_field['size_y']))-3.5 ) + 'px'
properties_css_object_error['font-size'] = \ properties_css_object_error['font-size'] = \
str(int(properties_field['size_y']) - 2) + 'px' str((scaling_factor2 *float(properties_field['size_y']))-3.5) + 'px'
# getting field position else:
properties_css_object_stand['font-size'] = \
str(12) + 'px'
properties_css_object_error['font-size'] = \
str(12) + 'px'
properties_css_object_err_d['margin-left'] = str(page_width + 20 ) + 'px' properties_css_object_err_d['margin-left'] = str(page_width + 20 ) + 'px'
properties_css_object_stand['margin-top'] = \ properties_css_object_stand['margin-top'] = \
str(properties_field['position_y']) + 'px' str((scaling_factor2 *float(properties_field['position_y']))) + 'px'
properties_css_object_error['margin-top'] = \ properties_css_object_error['margin-top'] = \
str(properties_field['position_y']) + 'px' str((scaling_factor2 *float(properties_field['position_y']))) + 'px'
properties_css_object_err_d['margin-top'] = \ properties_css_object_err_d['margin-top'] = \
str(properties_field['position_y']) + 'px' str((scaling_factor2 *float(properties_field['position_y']))) + 'px'
# adding special text_color for text error # adding special text_color for text error
properties_css_object_err_d['color'] = 'rgb(255,0,0)' properties_css_object_err_d['color'] = 'rgb(255,0,0)'
# then getting additional properties # then getting additional properties
...@@ -804,8 +937,11 @@ class ManageCSS: ...@@ -804,8 +937,11 @@ class ManageCSS:
# color = 'green' when error # color = 'green' when error
properties_css_object_stand['background'] = 'rgb(192,192,255)' properties_css_object_stand['background'] = 'rgb(192,192,255)'
properties_css_object_error['background'] = 'rgb(128,128,255)' properties_css_object_error['background'] = 'rgb(128,128,255)'
elif properties_field['type'] != 'TextAreaField':
properties_css_object_stand['background'] = '#F5F5DC'
properties_css_object_error['background'] = 'rgb(255,64,64)'
else: else:
properties_css_object_stand['background'] = '#F6FFFF' properties_css_object_stand['background'] = '#F5F5DC'
properties_css_object_error['background'] = 'rgb(255,64,64)' properties_css_object_error['background'] = 'rgb(255,64,64)'
# add completed properties (in our case only the class rendering the text # add completed properties (in our case only the class rendering the text
...@@ -819,13 +955,13 @@ class ManageCSS: ...@@ -819,13 +955,13 @@ class ManageCSS:
# single rendering (like StringField, TextArea, etc.). # single rendering (like StringField, TextArea, etc.).
# Do not need any special treatment # Do not need any special treatment
properties_css_object_stand['width'] = \ properties_css_object_stand['width'] = \
str(properties_field['size_x']) + 'px' str(scaling_factor1 *float(properties_field['size_x'])) + 'px'
properties_css_object_error['width'] = \ properties_css_object_error['width'] = \
str(properties_field['size_x']) + 'px' str(scaling_factor1 *float(properties_field['size_x'])) + 'px'
properties_css_object_stand['margin-left'] = \ properties_css_object_stand['margin-left'] = \
str(properties_field['position_x']) + 'px' str((scaling_factor1 *float(properties_field['position_x']))) + 'px'
properties_css_object_error['margin-left'] = \ properties_css_object_error['margin-left'] = \
str(properties_field['position_x']) + 'px' str((scaling_factor1 *float(properties_field['position_x']))) + 'px'
# in case of checkboxfield, '_class_2' is used because field is rendered # in case of checkboxfield, '_class_2' is used because field is rendered
# as two fields, the first one hidden. (supports xhtml_style) # as two fields, the first one hidden. (supports xhtml_style)
# UPDATE : modified because need to keep compatibility with html_style # UPDATE : modified because need to keep compatibility with html_style
...@@ -836,7 +972,6 @@ class ManageCSS: ...@@ -836,7 +972,6 @@ class ManageCSS:
# adding all these properties to the global dicts # adding all these properties to the global dicts
properties_css_dict['standard'][field_id] = properties_css_object_stand properties_css_dict['standard'][field_id] = properties_css_object_stand
properties_css_dict['error'][field_id] = properties_css_object_error properties_css_dict['error'][field_id] = properties_css_object_error
else: else:
sub_field_dict = {} sub_field_dict = {}
field_dict = {} field_dict = {}
...@@ -853,16 +988,16 @@ class ManageCSS: ...@@ -853,16 +988,16 @@ class ManageCSS:
# processing main StringField # processing main StringField
field_dict[1] = {} field_dict[1] = {}
field_dict[1]['width'] = \ field_dict[1]['width'] = \
str(int(properties_field['size_x']) / 2) + 'px' str(scaling_factor1*(float(properties_field['size_x']) / 2)) + 'px'
field_dict[1]['margin-left'] = \ field_dict[1]['margin-left'] = \
str(properties_field['position_x']) + 'px' str(scaling_factor1*float(properties_field['position_x'])) + 'px'
# processing secondary input picture # processing secondary input picture
field_dict[2] = {} field_dict[2] = {}
field_dict[2]['width'] = str(int(properties_field['size_x']) /2) + 'px' field_dict[2]['width'] = str(scaling_factor1*(float(properties_field['size_x']) /2)) + 'px'
field_dict[2]['margin-left'] = \ field_dict[2]['margin-left'] = \
str(int(properties_field['size_x']) /2 +\ str(scaling_factor1*(float(properties_field['size_x']) /2 +\
int(properties_field['position_x'])) + 'px' float(properties_field['position_x']))) + 'px'
elif properties_field['type'] == 'DateTimeField': elif properties_field['type'] == 'DateTimeField':
# rendering DateTimeField, composed at least of three input # rendering DateTimeField, composed at least of three input
# areas, and their order can be changed # areas, and their order can be changed
...@@ -885,7 +1020,7 @@ class ManageCSS: ...@@ -885,7 +1020,7 @@ class ManageCSS:
print " Option : Date Only" print " Option : Date Only"
field_nb = 3 field_nb = 3
# same as before but without hours and minutes # same as before but without hours and minutes
width_part = int(float(properties_field['size_x']) / 4) width_part = int((float(properties_field['size_x']) / 4))
print " input_order=%s" % properties_field['input_order'] print " input_order=%s" % properties_field['input_order']
...@@ -897,42 +1032,42 @@ class ManageCSS: ...@@ -897,42 +1032,42 @@ class ManageCSS:
# the last field). # the last field).
# processing first field # processing first field
field_dict[1] = {} field_dict[1] = {}
field_dict[1]['width'] = str(width_part) + 'px' field_dict[1]['width'] = str(scaling_factor1*float(width_part)) + 'px'
field_dict[1]['margin-left'] = \ field_dict[1]['margin-left'] = \
str(properties_field['position_x']) + 'px' str(scaling_factor1 *float(properties_field['position_x'])) + 'px'
# processing second field # processing second field
field_dict[2] = {} field_dict[2] = {}
field_dict[2]['width'] = str(width_part) + 'px' field_dict[2]['width'] = str(scaling_factor1*float(width_part)) + 'px'
field_dict[2]['margin-left'] = \ field_dict[2]['margin-left'] = \
str(int(properties_field['position_x']) + width_part) + 'px' str(scaling_factor1 *(float(properties_field['position_x']) + width_part)) + 'px'
# processing last field # processing last field
field_dict[3] = {} field_dict[3] = {}
field_dict[3]['width'] = str(width_part*2) + 'px' field_dict[3]['width'] = str(scaling_factor1*float(width_part*2)) + 'px'
field_dict[3]['margin-left'] = \ field_dict[3]['margin-left'] = \
str(int(properties_field['position_x']) + width_part*2) + 'px' str(scaling_factor1 *(float(properties_field['position_x']) + width_part*2)) + 'px'
else: else:
# all other cases, including default one (year/month/day) # all other cases, including default one (year/month/day)
width_part = int(int(properties_field['size_x']) / 4) width_part = int(int(properties_field['size_x']) / 4)
# processing year field # processing year field
field_dict[1] = {} field_dict[1] = {}
field_dict[1]['width'] = str(width_part *2) + 'px' field_dict[1]['width'] = str(scaling_factor1*float(width_part *2)) + 'px'
field_dict[1]['margin-left'] = \ field_dict[1]['margin-left'] = \
str(properties_field['position_x']) + 'px' str(scaling_factor1 *float(properties_field['position_x'])) + 'px'
# processing second field (two digits only) # processing second field (two digits only)
field_dict[2] = {} field_dict[2] = {}
field_dict[2]['width'] = str(width_part) + 'px' field_dict[2]['width'] = str(scaling_factor1*float(width_part)) + 'px'
field_dict[2]['margin-left'] = \ field_dict[2]['margin-left'] = \
str(int(properties_field['position_x']) + width_part*2) + 'px' str(scaling_factor1 *(float(properties_field['position_x']) + width_part*2)) + 'px'
# processing day field # processing day field
field_dict[3] = {} field_dict[3] = {}
field_dict[3]['width'] = str(width_part) + 'px' field_dict[3]['width'] = str(scaling_factor1*float(width_part)) + 'px'
field_dict[3]['margin-left'] = \ field_dict[3]['margin-left'] = \
str(int(properties_field['position_x']) + width_part*3) + 'px' str(scaling_factor1 *(float(properties_field['position_x']) + width_part*3)) + 'px'
# rendering time if necessary # rendering time if necessary
...@@ -990,6 +1125,7 @@ class ManageCSS: ...@@ -990,6 +1125,7 @@ class ManageCSS:
for prop_id in properties_css_dict['standard'][class_name].keys(): for prop_id in properties_css_dict['standard'][class_name].keys():
print " prop:%s=%s" % (prop_id,properties_css_dict['standard'][class_name][prop_id]) print " prop:%s=%s" % (prop_id,properties_css_dict['standard'][class_name][prop_id])
return properties_css_dict return properties_css_dict
...@@ -1222,16 +1358,15 @@ class ScribusParser: ...@@ -1222,16 +1358,15 @@ class ScribusParser:
keep_page = 1 keep_page = 1
# first of all getting DOCUMENT element to recover Scratch coordinates # first of all getting DOCUMENT element to recover Scratch coordinates
document_list = dom_root.getElementsByTagName("DOCUMENT") document_list = dom_root.getElementsByTagName("DOCUMENT")
scratch_left = int(float(document_list[0].attributes["ScratchLeft"].value)) scratch_left = int(float(document_list[0].attributes["ScratchLeft"].value))
scratch_top = int(float(document_list[0].attributes["ScratchTop"].value)) scratch_top = int(float(document_list[0].attributes["ScratchTop"].value))
page_gap = int(float(document_list[0].attributes["BORDERTOP"].value)) page_gap = int(float(document_list[0].attributes["BORDERTOP"].value))
scribus_page_width= int(float(document_list[0].attributes["PAGEWIDTH"].value))
scribus_page_height = \
int(float(document_list[0].attributes["PAGEHEIGHT"].value))
print " DOCUMENT > scratch_left = %s scratch_top = %s" % (scratch_left,scratch_top) print " DOCUMENT > scratch_left = %s scratch_top = %s" % (scratch_left,scratch_top)
#page_list = dom_root.getElementsByTagName("PAGE") #page_list = dom_root.getElementsByTagName("PAGE")
page_object_list = dom_root.getElementsByTagName("PAGEOBJECT") page_object_list = dom_root.getElementsByTagName("PAGEOBJECT")
...@@ -1332,14 +1467,18 @@ class ScribusParser: ...@@ -1332,14 +1467,18 @@ class ScribusParser:
# iterating through 'PAGEOBJECT' of the page # iterating through 'PAGEOBJECT' of the page
# id = object_name # id = object_name
# content = object_content # content = object_content
object_name = object_data['ANNAME'] object_name = object_data['ANNAME']
del object_data['ANNAME'] del object_data['ANNAME']
object_content = object_data object_content = object_data
multiline_field= 0
#multiline_field= object_content['ANFLAG']
print " => PAGEOBJECT = " + str(object_name) print " => PAGEOBJECT = " + str(object_name)
# recovering other attributes list (string format) from 'ANTOOLTIP' # recovering other attributes list (string format) from 'ANTOOLTIP'
text_tooltipfield_properties = \ text_tooltipfield_properties = \
sp.getObjectTooltipProperty('ANTOOLTIP','',object_name,object_content) sp.getObjectTooltipProperty('ANTOOLTIP','',object_name,object_content)
#recovering the page attributes
#declaring output file #declaring output file
tooltipfield_properties_dict = {} tooltipfield_properties_dict = {}
#splitting the different attributes #splitting the different attributes
...@@ -1348,8 +1487,6 @@ class ScribusParser: ...@@ -1348,8 +1487,6 @@ class ScribusParser:
print " " + str(tooltipfield_properties_list) print " " + str(tooltipfield_properties_list)
# test if first argument is nb according to previous # test if first argument is nb according to previous
# naming-conventions i.e composed of three digits without # naming-conventions i.e composed of three digits without
# id 'nb:' written # id 'nb:' written
...@@ -1387,6 +1524,7 @@ class ScribusParser: ...@@ -1387,6 +1524,7 @@ class ScribusParser:
#and 'ANTOOLTIP' #and 'ANTOOLTIP'
# #
object_properties = {} object_properties = {}
page_properties = {}
# getting object position and size # getting object position and size
object_properties['position_x'] = \ object_properties['position_x'] = \
sp.getObjectTooltipProperty('XPOS', sp.getObjectTooltipProperty('XPOS',
...@@ -1398,6 +1536,7 @@ class ScribusParser: ...@@ -1398,6 +1536,7 @@ class ScribusParser:
'0', '0',
object_name, object_name,
object_content) object_content)
object_properties['size_x'] = \ object_properties['size_x'] = \
sp.getObjectTooltipProperty('WIDTH', sp.getObjectTooltipProperty('WIDTH',
'100', '100',
...@@ -1410,6 +1549,7 @@ class ScribusParser: ...@@ -1410,6 +1549,7 @@ class ScribusParser:
object_content) object_content)
# converting values to integer-compliant to prevent errors # converting values to integer-compliant to prevent errors
# when using them for that converting from 'str' -> 'float' # when using them for that converting from 'str' -> 'float'
# -> 'int' -> 'str' # -> 'int' -> 'str'
...@@ -1775,7 +1915,7 @@ class ScribusParser: ...@@ -1775,7 +1915,7 @@ class ScribusParser:
# returning final dict containing all the modified data # returning final dict containing all the modified data
print " => end ScribusParser.getPropertiesConversion" print " => end ScribusParser.getPropertiesConversion"
return returned_page_dict return (returned_page_dict)
...@@ -1794,6 +1934,8 @@ class ScribusParser: ...@@ -1794,6 +1934,8 @@ class ScribusParser:
global_properties = {} global_properties = {}
global_properties['object'] = global_object_dict global_properties['object'] = global_object_dict
global_properties['page'] = global_page_number global_properties['page'] = global_page_number
global_properties['page_width']= 595
global_properties['page_height']= 842
# return final main dict # return final main dict
return global_properties return global_properties
...@@ -1896,6 +2038,10 @@ class ScribusParser: ...@@ -1896,6 +2038,10 @@ class ScribusParser:
def getContentFile(self, file_descriptor): def getContentFile(self, file_descriptor):
""" Get file content """ """ Get file content """
return file_descriptor.read() return file_descriptor.read()
security.declareProtected('Import/Export objects', 'getFileOpen')
def getFileOpen(self, file_descriptor):
""" Get file content """
return file_descriptor.open('r')
InitializeClass(ScribusParser) InitializeClass(ScribusParser)
allow_class(ScribusParser) allow_class(ScribusParser)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment