3
« on: June 26, 2020, 06:24:34 pm »
I've found a way to influence the image size. It needs some scripting though, so you'll need a custom template fragment with a call to a script to create the diagram image.
Here's what I've done:
1. Create a User Template Fragment for a diagram with a call to a script: documentDiagram(#DIAGRAMID#, "DiagramTemplate")
2. Create the documentDiagram() function...
function documentUPPDiagram(diagramId, diagramTemplate)
(...)
set docG = Repository.CreateDocumentGenerator
if (docG.NewDocument("")) then
docG.DocumentDiagram diagramId, 1, diagramTemplate
DIM rtf
rtf = docG.GetDocumentAsRTF()
rtf = maximizeDiagramImageHeightInCm(rtf, 14.6)
documentDiagram = rtf
end function
And, I used these functions to influence the RTF.
function getRtfValue(rtf, entry)
DIM i1, i2, l
DIM e
i1 = InStr(rtf, entry)
if (i1 > 0) then
i2 = InStr(i1 + 1, rtf, "\")
if (i2 > 0) then
l = i2 - i1 - Len(entry)
e = Mid(rtf, i1 + Len(entry), l)
getRtfValue = e
end if
end if
end function
function rtfReplace(rtf, entry, new_value)
DIM i1, i2
i1 = InStr(rtf, entry)
if (i1 > 0) then
i2 = InStr(i1 + 1, rtf, "\")
if (i2 > 0) then
rtfReplace = Left(rtf, i1 - 1) & entry & new_value & Mid(rtf, i2)
end if
end if
end function
function maximizeDiagramImageHeightInCm(rtf, max_height_in_cm)
DIM w_goal, h_goal
DIM scale_w, scale_h
DIM factor
DIM max_height_in_twips
max_height_in_twips = Round((max_height_in_cm / 2.54) * 1440)
scale_h = CInt(getRtfValue(rtf, "\picscaley"))
max_height_in_twips = Round((1.0 / (scale_h / 100.0)) * max_height_in_twips)
w_goal = getRtfValue(rtf, "\picwgoal")
h_goal = getRtfValue(rtf, "\pichgoal")
LOGDebug("\picwgoal = " & w_goal & ", \pichgoal = " & h_goal)
h_goal = CInt(h_goal)
if (h_goal > max_height_in_twips) then
factor = max_height_in_twips / h_goal
h_goal = Round(h_goal * factor)
w_goal = CInt(w_goal)
w_goal = Round(w_goal * factor)
LOGDebug("Scaled to: \picwgoal = " & w_goal & ", \pichgoal = " & h_goal)
rtf = rtfReplace(rtf, "\picwgoal", w_goal)
rtf = rtfReplace(rtf, "\pichgoal", h_goal)
end if
maximizeDiagramImageHeightInCm = rtf
end function
Oke, it's a dirty hack, but it works.