Das stellst Du doch im PrintRequester ein?doctorized hat geschrieben:Querformat Papierausrichtung?
Oder verstehe ich Dich jetzt falsch?
Das stellst Du doch im PrintRequester ein?doctorized hat geschrieben:Querformat Papierausrichtung?
Code: Alles auswählen
;==>https://www.purebasic.fr/german/viewtopic.php?p=347448#p347448
Enumeration
#PrintListIcon_Orientation_Auto
#PrintListIcon_Orientation_Portrait
#PrintListIcon_Orientation_LandScape
EndEnumeration
Procedure PrintListIcon(ListIcon, PageName.s = "Page {NUM}", LineThickness = 2, Orientation = #PrintListIcon_Orientation_Auto)
Protected i, j, k, Count, Columns, NewLine, CurrentPage, LastLineReached
Protected OutputHeight.d, OutputWidth.d, SizeFactor.d, PixPos.d
Protected XSpaceBetweenTextAndTable.d, YSpaceBetweenTextAndTable.d, XSpaceBetweenEdgeAndTable.d, YSpaceBetweenEdgeAndTable.d
Protected H.d, size.d, OverallSize.d
Static DefaultFontID.i, BoldFontID.i
If Not DefaultFontID
DefaultFontID = FontID(LoadFont(#PB_Any, "Arial", 16))
BoldFontID = FontID(LoadFont(#PB_Any, "Arial", 16, #PB_Font_Bold))
EndIf
If IsGadget(ListIcon) = 0 Or GadgetType(ListIcon) <> #PB_GadgetType_ListIcon
ProcedureReturn
EndIf
Columns = GetGadgetAttribute(ListIcon, #PB_ListIcon_ColumnCount)
Dim Widths.d(Columns)
If PrintRequester() And StartPrinting("ParameterList")
If Orientation = #PrintListIcon_Orientation_Auto Or
(Orientation = #PrintListIcon_Orientation_LandScape And PrinterPageWidth() > PrinterPageHeight()) Or
(Orientation = #PrintListIcon_Orientation_Portrait And PrinterPageWidth() < PrinterPageHeight())
OutputHeight = PrinterPageHeight()
OutputWidth = PrinterPageWidth()
Orientation = #PrintListIcon_Orientation_Auto
Else
OutputWidth = PrinterPageHeight()
OutputHeight = PrinterPageWidth()
EndIf
Count = CountGadgetItems(ListIcon) - 1
If StartVectorDrawing(PrinterVectorOutput(#PB_Unit_Pixel))
If Orientation <> #PrintListIcon_Orientation_Auto
RotateCoordinates(0, 0, 270)
TranslateCoordinates(-PrinterPageHeight(), 0)
EndIf
VectorFont(DefaultFontID)
H = VectorTextHeight("P°²gT_")
YSpaceBetweenTextAndTable = H / 4 ;<-- spacing between table line and text on top and bottom, 25% of max text height
XSpaceBetweenTextAndTable = VectorTextWidth(" ") ;<-- spacing between table line and text left and right, one space here, add more if needed
YSpaceBetweenEdgeAndTable = OutputHeight / 20 ;<-- spacing of 1/20 of complete width will be used left and right of the table
XSpaceBetweenEdgeAndTable = OutputWidth / 20 ;<-- spacing of 1/20 of complete height will be used on top and bottom of the table
;find max column widths
For j = 0 To Columns - 1
Widths(j) = VectorTextWidth(GetGadgetItemText(ListIcon, -1, j))
Next j
For i = 0 To Count
For j = 0 To Columns - 1
size = VectorTextWidth(GetGadgetItemText(ListIcon, i, j))
If size > Widths(j)
Widths(j) = size
EndIf
Next j
Next i
;Add some more space for each column, in front and behind the text
size = 0
For j = 0 To Columns - 1
Widths(j) + 2 * XSpaceBetweenTextAndTable
size + Widths(j)
Next j
OverallSize = size
size + (Columns - 1) * XSpaceBetweenTextAndTable + XSpaceBetweenEdgeAndTable * 2
SizeFactor = OutputWidth / size
OutputWidth = OutputWidth / SizeFactor
OutputHeight = OutputHeight / SizeFactor
NewLine = #True
ScaleCoordinates(SizeFactor, SizeFactor)
H + YSpaceBetweenTextAndTable * 2
For i = 0 To Count
If NewLine
;print Header
PixPos = YSpaceBetweenEdgeAndTable
VectorFont(BoldFontID)
For j = 0 To Columns - 1
size = 0
For k = 0 To j - 1
size + Widths(k)
Next k
AddPathBox(XSpaceBetweenEdgeAndTable + size, PixPos, Widths(j), H)
MovePathCursor(XSpaceBetweenEdgeAndTable + XSpaceBetweenTextAndTable + size, PixPos + YSpaceBetweenTextAndTable)
DrawVectorText(GetGadgetItemText(ListIcon, -1, j))
Next j
StrokePath(LineThickness)
NewLine = #False
PixPos + H
EndIf
VectorFont(DefaultFontID)
For j = 0 To Columns - 1
size = 0
For k = 0 To j - 1
size + Widths(k)
Next k
AddPathBox(XSpaceBetweenEdgeAndTable + size, PixPos, Widths(j), H)
MovePathCursor(XSpaceBetweenEdgeAndTable + XSpaceBetweenTextAndTable + size, PixPos + YSpaceBetweenTextAndTable)
DrawVectorText(GetGadgetItemText(ListIcon, i, j))
Next j
StrokePath(LineThickness)
PixPos + H
If PixPos + 4 * H > OutputHeight
CurrentPage + 1
MovePathCursor(XSpaceBetweenEdgeAndTable + OverallSize - VectorTextWidth(ReplaceString(PageName, "{NUM}", Str(CurrentPage))), OutputHeight - 2 * H)
DrawVectorText(ReplaceString(PageName, "{NUM}", Str(CurrentPage)))
NewPrinterPage()
CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
ScaleCoordinates(SizeFactor, SizeFactor)
CompilerEndIf
NewLine = #True
PixPos = 0
If i = Count
LastLineReached = #True
EndIf
EndIf
Next i
If LastLineReached = 0
CurrentPage + 1
MovePathCursor(XSpaceBetweenEdgeAndTable + OverallSize - VectorTextWidth(ReplaceString(PageName, "{NUM}", Str(CurrentPage))), OutputHeight - 2 * H)
DrawVectorText(ReplaceString(PageName, "{NUM}", Str(CurrentPage)))
EndIf
StopVectorDrawing()
EndIf
StopPrinting()
EndIf
EndProcedure
CompilerIf #PB_Compiler_IsMainFile
Procedure main()
Protected i, j, Columns, Items, TextSize, a$
OpenWindow(0, 0, 0, 640, 480, "ListIcon Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ListIconGadget(0, 5, 5, 630, 430, "Column 1", 200)
ButtonGadget(1, 270, 440, 100, 22, "Print")
Columns = Random(6, 3)
Items = 100
For i = 1 To Columns - 1
AddGadgetColumn(0, i, "Column " + Str(i + 1), 200)
Next i
For i = 1 To Items
a$ = ""
For j = 0 To Columns - 1
TextSize = Random(40, 5)
If j > 0
a$ + #LF$
EndIf
a$ + Left("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam", TextSize)
Next j
AddGadgetItem(0, -1, a$)
Next i
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Gadget
If EventGadget() = 1
PrintListIcon(0, "Page {NUM}", 2, #PrintListIcon_Orientation_LandScape)
EndIf
EndSelect
ForEver
EndProcedure
main()
CompilerEndIf