Skip to content

Commit

Permalink
Better error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
pgundlach committed Jan 23, 2025
1 parent 26066f3 commit 50be73d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 16 deletions.
25 changes: 17 additions & 8 deletions src/lua/publisher.lua
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,7 @@ function get_colentry_from_name(colorname, default)
if colorname then
if not colors[colorname] then
if default then
err("Color %q is not defined yet.",colorname)
splib.error("Color is not defined yet","name",colorname)
else
colentry = nil
end
Expand Down Expand Up @@ -2209,7 +2209,7 @@ function shipout(nodelist, pagenumber,dataxml)
}
if colorname then
if not colors[colorname] then
err("Pagetype / defaultcolor: color %q is not defined yet.",colorname)
splib.error("Pagetype / defaultcolor: color is not defined yet.","name",colorname)
else
local colorindex = colors[colorname].index
nodelist = set_color_if_necessary(nodelist,colorindex)
Expand Down Expand Up @@ -3059,11 +3059,15 @@ function bgtext( box, textstring, angle, colorname, fontfamily, bgsize)
end

--- Draw a background behind the rectangular (box) object.
function background( box, colorname )
function background( box, colorname,origin )
-- color '-' means 'no color'
if colorname == "-" then return box end
if not colors[colorname] then
warning("Background: Color %q is not defined",colorname)
if origin then
splib.log("warn","Background: color is not defined","name",colorname,"from",origin)
else
splib.log("warn","Background: color is not defined","name",colorname)
end
return box
end
local colentry = colors[colorname]
Expand Down Expand Up @@ -3125,7 +3129,7 @@ function frame(obj)

local colentry = get_colentry_from_name(obj.colorname,"black")
if not colentry then
err("Color %q is not defined",tostring(obj.colorname))
splib.error("Color is not defined","name",tostring(obj.colorname))
colentry = colors["black"]
end
local pdfcolorstring = colentry.pdfstring
Expand Down Expand Up @@ -4147,7 +4151,7 @@ function dothingsbeforeoutput( thispage,data )
if options.background and options.background ~= '-' then
local colentry = get_colentry_from_name(options.background,"white")
if not colentry then
err("Color %q is not defined",tostring(options.background))
splib.error("Color is not defined","name",tostring(options.backgroun))
colentry = colors["white"]
end
local pdfcolorstring = colentry.pdfstring
Expand Down Expand Up @@ -7211,7 +7215,7 @@ function get_languagecode( locale_or_name )
end

function set_mainlanguage( mainlanguage )
log("Setting default language to %q",mainlanguage or "?")
splib.log("info","Setting default language","lang",mainlanguage or "?")
defaultlanguage = get_languagecode(mainlanguage)
end

Expand Down Expand Up @@ -7315,7 +7319,12 @@ function next_row(rownumber,areaname,rows,dataxml)
end

local current_row
current_row = grid:find_suitable_row(1,grid:number_of_columns(areaname),rows,areaname)
local noc = grid:number_of_columns(areaname)
if noc == nil then
splib.error("number of columns is not set for area","area",areaname)
return
end
current_row = grid:find_suitable_row(1,noc,rows,areaname)
if not current_row then
next_area(areaname,nil, dataxml)
setup_page(nil,"next_row",dataxml)
Expand Down
20 changes: 17 additions & 3 deletions src/lua/publisher/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3517,7 +3517,7 @@ function commands.place_object( layoutxml,dataxml)


if background == "full" or css_rules["background-color"] then
object = publisher.background(object,backgroundcolor or css_rules["background-color"])
object = publisher.background(object,backgroundcolor or css_rules["background-color"],"PlaceObject")
end
if frame == "solid" then
framewidth = rulewidth_sp
Expand Down Expand Up @@ -3790,6 +3790,20 @@ function commands.positioning_frame( layoutxml, dataxml )
local row = publisher.read_attribute(layoutxml,dataxml,"row" ,"number")
local width = publisher.read_attribute(layoutxml,dataxml,"width","number")
local height = publisher.read_attribute(layoutxml,dataxml,"height" ,"number")
if row == nil or column == nil or width == nil or height == nil then
if not row then
splib.error("row not set in PositioningFrame")
end
if not column then
splib.error("column not set in PositioningFrame")
end
if not width then
splib.error("width not set in PositioningFrame")
end
if not height then
splib.error("height not set in PositioningFrame")
end
end
return {
column = column,
row = row,
Expand Down Expand Up @@ -5100,7 +5114,7 @@ function commands.text(layoutxml,dataxml)
local colorindex
if colorname then
if not publisher.colors[colorname] then
err("Color %q is not defined.",colorname)
splib.error("Color is not defined","name",tostring(colorname))
else
colorindex = publisher.colors[colorname].index
end
Expand Down Expand Up @@ -5287,7 +5301,7 @@ function commands.textblock( layoutxml,dataxml )
local colorindex
if colorname then
if not publisher.colors[colorname] then
err("Color %q is not defined.",colorname)
splib.error("Color is not defined","name",tostring(colorname))
else
colorindex = publisher.colors[colorname].index
end
Expand Down
12 changes: 7 additions & 5 deletions src/lua/publisher/grid.lua
Original file line number Diff line number Diff line change
Expand Up @@ -763,11 +763,13 @@ function draw_grid(self)
pdfcolorstring = " 1 0 0 RG "
end
for _,frame in ipairs(area) do
x = sp_to_bp(( frame.column - 1) * ( self.gridwidth + self.grid_dx) + self.extra_margin + self.margin_left)
y = sp_to_bp(( frame.row - 1) * ( self.gridheight + self.grid_dy) + self.margin_top )
width = sp_to_bp(frame.width * self.gridwidth + (frame.width - 1) * self.grid_dx)
height = sp_to_bp(frame.height * self.gridheight + (frame.height - 1) * self.grid_dy)
ret[#ret + 1] = string.format("q %s %g w %g %g %g %g re S Q", pdfcolorstring,0.5, x,math.round(paperheight_bp - y,2),width,-height)
if frame.width and frame.height then
x = sp_to_bp(( frame.column - 1) * ( self.gridwidth + self.grid_dx) + self.extra_margin + self.margin_left)
y = sp_to_bp(( frame.row - 1) * ( self.gridheight + self.grid_dy) + self.margin_top )
width = sp_to_bp(frame.width * self.gridwidth + (frame.width - 1) * self.grid_dx)
height = sp_to_bp(frame.height * self.gridheight + (frame.height - 1) * self.grid_dy)
ret[#ret + 1] = string.format("q %s %g w %g %g %g %g re S Q", pdfcolorstring,0.5, x,math.round(paperheight_bp - y,2),width,-height)
end
end
end
ret[#ret + 1] = "Q"
Expand Down

0 comments on commit 50be73d

Please sign in to comment.