B4J Question [Solved] Printing BBCodeview using jFX8Print, scaling and background color

William Lancee

Active Member
Licensed User
I can't get the background to show as white, and after scaling, I can't get the BBCodeview back to original scaling. Any ideas?

I should add that my printer is a black and white HP laser printer, so the faint gray background I see on paper could be a faint color. I don't know.

B4X:
        BBCV.mBase.SetColorAndBorder(xui.Color_White, 0, xui.Color_White, 0)

        Dim P As Printer = Printer_Static.GetDefaultPrinter
        Dim PJ As PrinterJob = PrinterJob_Static.CreatePrinterJob2(P)
        Private pl As PageLayout = P.CreatePageLayout(P.GetPrinterAttributes.GetDefaultPaper, PageOrientation_Static.PORTRAIT, 0.5, 0.5, 0.5, 0.5)
        PJ.GetJobSettings.SetPageLayout(pl)
        If PJ.ShowPrintDialog(Null) Then PJ.PrintPage(ScaleOutput(P, BBCV.mBase))
        PJ.EndJob
B4X:
Sub ScaleOutput(P As Printer, N As Node) As Node
    Dim PL As PageLayout = P.GetDefaultPageLayout
    Dim ScaleX,ScaleY As Double
    Dim NJO As JavaObject = N
    Dim JO As JavaObject = N
    ScaleX = PL.GetPrintableWidth / JO.RunMethodJO("getBoundsInParent",Null).RunMethod("getWidth",Null)
    'ScaleY = PL.GetPrintableHeight / JO.RunMethodJO("getBoundsInParent",Null).RunMethod("getHeight",Null)
    ScaleY = ScaleX

    Dim SJO As JavaObject
    SJO.InitializeNewInstance("javafx.scene.transform.Scale",Array(ScaleX,ScaleY))
    NJO.RunMethodJO("getTransforms",Null).RunMethod("add",Array(SJO))
    Return NJO
End Sub
 
Last edited:

William Lancee

Active Member
Licensed User
In making a small project, I saw that although the alpha in the designer for the BBCodeview was 1.0, the color was #00FFFFFF. When I changed that to #FFFFFFFF, the gray background became white as required. Therefore that problem was fixed. I am still uncertain how to reset the scaling after printing, and the attached project also illustrates that the wrapping has some effects that I don't fully understand.
 

Attachments

Erel

Administrator
Staff member
Licensed User
You are not using the vertical offset correctly. If you want to put the text in the center of the screen then use this code:
B4X:
BBCV.Text = $"[Alignment=Center][TextSize=20][Color=Black][b]This is a centered Title I am mking it longer to show the effect of wrapping and scaling[/b][/Color][/TextSize][/Alignment]"$
BBCV.mBase.Top = MainForm.RootPane.Height / 2 - BBCV.ForegroundImageView.Height / 2
Not sure whether it will help or not however you can get the bitmap with:
B4X:
Dim iv As ImageView = BBCV.ForegroundImageView
Dim bmp As Image = iv.GetImage
 

William Lancee

Active Member
Licensed User
That was very helpful. By creating a new imageview with the same image, the original scaling is untouched. See post #1 for scaling sub.

B4X:
Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("1")
    MainForm.Show
    
    BBCV.mBase.SetLayoutAnimated(0, .05*MainForm.width, .05*MainForm.Height, .9*MainForm.width, .9*MainForm.Height)
    TextEngine.Initialize(MainForm.RootPane)
    
    Dim verticalCenter As Float = .05*MainForm.Height + .4*MainForm.Height

    MainForm.Show
    
    BBCV.Text = $"[Alignment=Center][TextSize=20][Color=Black][b]This is a centered Title[/b][/Color][/TextSize][/Alignment]"$
    BBCV.mBase.Top = MainForm.RootPane.Height / 2 - BBCV.ForegroundImageView.Height / 2
    
    Dim iv As ImageView = BBCV.ForegroundImageView
    Dim bmp As Image = iv.GetImage

    'This creates a new imageview with a copy of the image that will be scaled by the print job
    'The original BBCV is untouched
    Dim newiv As ImageView: newiv.Initialize("")
    newiv.SetImage(bmp)
        
    Dim P As Printer = Printer_Static.GetDefaultPrinter
    Dim PJ As PrinterJob = PrinterJob_Static.CreatePrinterJob2(P)
    Private pl As PageLayout = P.CreatePageLayout(P.GetPrinterAttributes.GetDefaultPaper, PageOrientation_Static.PORTRAIT, 0.5, 0.5, 0.5, 0.5)
    PJ.GetJobSettings.SetPageLayout(pl)
    If PJ.ShowPrintDialog(Null) Then PJ.PrintPage(ScaleOutput(P, newiv))
    PJ.EndJob

End Sub
 
Top