How to print a Dotted or Dashed LINE on a Report?

Hi ! Is it possible to print different dotted lines in reports? Thanks !

ChromePDF

See LINE in the help and SETPENSTYLE. This is not the line control but the LINE drawing command. There maybe more options in Capesoft’s Draw. I haven’t investigated to see.

1 Like

Thanks ! This is already a good solution. :slight_smile:

Ahhhh… this is where you use SETTARGET( Report , Band ) to specify the Report Detail Band onto which you draw with graphics Line(), Ellipse(), Box(), etc.

What I would do is put a normal LINE control on the Report. Then use code like below to put the Graphic Line() in the Position of the Line Control, which you hide:

    SETTARGET(Report,?DetailWithLine)   !Must have , ?Detail Band FEQ
    GETPOSITION(?Line1,X#,Y#,W#,H#)     !Line1 Control Position
    HIDE(?Line1)        !Hide to put Dotted line on top
    SETPENSTYLE(PEN:dot)     
    Line(X#,Y# + 0,W#,H#)    !on top of Line 1
    PRINT(Rpt:DetailWithLine)

Here’s the output of my test showing the Detail with LINE, then the same with Dot, Dash and Dot+Dash lines:

image

Test Report Project Code:

    PROGRAM  !Report Test Framework. Get more tests from https://gist.github.com/CarlTBarnes/29f78a2ca43813e83489dc62a4d5e0c0
    MAP
    END

PreviewQ  QUEUE,PRE(PreQ)
FileName    STRING(260)
    END

    !>>>--Define your Report with ,PREVIEW(PreviewQ) attribute
Report REPORT,AT(1000,2000,6000,7000),FONT('Arial',10),PRE(RPT),PREVIEW(PreviewQ), |
            THOUS
        HEADER,AT(1000,1000,6000,1000),USE(?HEADER1)
            STRING('Report Test for LINE SetPenStype'),AT(208,94),USE(?STRING1),TRN
        END
DetailWithLine DETAIL,AT(0,0,6000,800),USE(?DetailWithLine)
            STRING('Detail with LINE'),AT(83,10,1229,146),USE(?DetailIsWhat),TRN,FONT(,8)
            LINE,AT(1094,83,4000,0),USE(?LINE1),LINEWIDTH(3)
        END
        FOOTER,AT(1000,9000,6000,1000),USE(?unnamed)
        END
    END

    CODE
    OPEN(Report)
    PRINT(Rpt:DetailWithLine)       !Print without drawing 
    
    SETTARGET(Report,?DetailWithLine)   !Must have , ?Detail Band FEQ
    GETPOSITION(?Line1,X#,Y#,W#,H#)     !Line1 Control Position
    ?DetailIsWhat{PROP:Text}='Graphic Line()'
    HIDE(?Line1)        !Hide to put Dotted line on top
    SETPENCOLOR(Color:Red)   ; SETPENSTYLE(PEN:dot)     ; Line(X#,Y# +   0,W#,H#)
    SETPENCOLOR(Color:Blue)  ; SETPENSTYLE(PEN:dash)    ; Line(X#,Y# + 100,W#,H#)
    SETPENCOLOR(Color:Green) ; SETPENSTYLE(PEN:DashDot) ; Line(X#,Y# + 200,W#,H#)

!Edit 3/5/24 with 2 other styles
    SETPENCOLOR(Color:Orange) ; SETPENSTYLE(PEN:dashdotdot) ; Line(X#,Y# + 350,W#,H#)  !New 
    SETPENCOLOR(Color:Olive)  ; SETPENSTYLE(PEN:solid)      ; Line(X#,Y# + 450,W#,H#)  !New 
    
    SETPENWIDTH(10)    ! PenWidth >=10 sets back to Solid PenStyle, no way to do thick dash lines, maybe with multiple adjusting Y a little
    SETPENCOLOR(Color:Purple) ; SETPENSTYLE(PEN:Dash) ; Line(X#,Y# + 700,W#,H#)
    
    PRINT(Rpt:DetailWithLine)
    
    ENDPAGE(Report)

    !--Preview the report
    DO ReportPreviewRtn
    CLOSE(Report)

!-----------------  Open Preview Window and display --------------------------
ReportPreviewRtn    ROUTINE     
    DATA
PreviewWindow WINDOW('Preview'),AT(,,495,332),FONT('MS Sans Serif',8,,FONT:regular),SYSTEM,MAX,RESIZE
       LIST,AT(1,2,245,11),USE(?List:PreviewQ),DROP(10),FROM(PreviewQ),VScroll,FONT(,10)
       IMAGE,AT(1,15),USE(?Image1),FULL ,hvscroll
     END
    CODE
    
    OPEN(PreviewWindow)
    ?List:PreviewQ{PROP:Selected}=1
    ACCEPT
        IF ACCEPTED()=?List:PreviewQ OR EVENT()=Event:OpenWindow
           GET(PreviewQ,CHOICE(?List:PreviewQ))
           ?Image1{PROP:Text}=PreviewQ
           DISPLAY
        END
    END
    CLOSE(PreviewWindow)

SETPENWIDTH() seems to prevent Pen Style.

4 Likes

Thanks ! This method also works in windows. :slight_smile:

1

2 Likes

20+ years using Clarion and still learning something new!!
I’d like to have found ClarionHub before!

Thanks Carl and all the community!

Depending on what you’re doing, maybe the api call DrawFocusRect() could be useful (on windows only, probably). DrawFocusRect function (winuser.h) - Win32 apps | Microsoft Learn

2 styles that I missed in my example … “Dash Dot Dot” was not in the Help for SetPenStyle(), maybe it was not in Win 3.1. Also Solid that is a Normal line, so that’s a way to change back to Solid after using Dot or Dash:

PEN:solid               EQUATE (0)
PEN:dashdotdot          EQUATE (4)    

    SETPENCOLOR(Color:Orange) ; SETPENSTYLE(PEN:dashdotdot) ; Line(X#,Y# + 350,W#,H#)  !New 
    SETPENCOLOR(Color:Olive)  ; SETPENSTYLE(PEN:solid)      ; Line(X#,Y# + 450,W#,H#)  !New 


This screen shot the bottom 2 are Dash Dot Dot colored Orange and Solid in Olive:

image

I’ll adjust my original code above.


I am troubled that SETPENWIDTH(10) changes Dot Style to a Solid line. I tested further and found widths 1 to 9 did not change Style, but also did not make it any thicker.

Looking at Windows API CreatePen() on MSDN it says the below which concurs that Width greater than 1 will reset Dots / Dashes to Solid.

CreatePen returns a pen with the specified width but with the PS_SOLID style if you specify a width greater than one for the following styles: PS_DASH, PS_DOT, PS_DASHDOT, PS_DASHDOTDOT.

So it seems you cannot have thicker width Dashed Lines. Maybe you could lay down multiple Dashed Lines with the Y value adjusted down a little.

I tested this code that prints 5 Dash / Dot lines spaced 10 THOUS to make it look like one thick line on the Report:

    ?DetailIsWhat{PROP:Text}='Thick Dashed'
    SETPENCOLOR(Color:Blue)  ; SETPENSTYLE(PEN:dash)    
    Line(X#,Y# + 000,W#,H#)    !Normal Dashed line, not thick
    LOOP I#=0 TO 40 BY 10   !I# writes 5 spaced 10 on Y axis
        SETPENCOLOR(Color:Red)    ; SETPENSTYLE(PEN:dash)
        Line(X#,Y# + 100 + I#,W#,H#) 
        SETPENCOLOR(Color:Orange) ; SETPENSTYLE(PEN:dot) 
        Line(X#,Y# + 200 + I#,W#,H#)
    END
    PRINT(Rpt:DetailWithLine)

image

The above is 5 lines, below is 3 lines (LOOP I#=0 TO 20 BY 10 ) which seems thick enough to me:

image

2 Likes

Interesting effects when drawing on the screen. :slight_smile:

1

I looked at Carl’s algorithm carefully. :wink: Screen:

1

Report:

2

Thanks for the help ! :slight_smile:

I made a Procedure to wrap making a Report Line output as a Dot / Dash Line. It makes it easy to do before printing one Detail with a Line like this with one call:

 ReportLineSetAsDots(Report, ?CheckTotalLine, ?CheckTotal_UnderLine, PEN:dot) !<-- this
 Print(RPT:CheckTotalLine) 
 Report$?CheckTotal_UnderLine{PROP:Hide}=False   !Optional if want to use LINE control

For a Report Detail like below with a LINE:

CheckTotalLine DETAIL,AT(0,0,7500,187),USE(?CheckTotalLine)
   STRING('CHECK TOTAL:'),AT(4625,0),USE(?TotalCheckLit),TRN
   LINE,AT(0,167,7500,0),USE(?CheckTotal_UnderLine),COLOR(COLOR:Black)

Report preview showing Dotted Lines under CHECK TOTAL:


The procedures that wrap creating a Dot or Dash line:

 MAP
   ReportLineSetAsDots  (*REPORT RptRef, LONG DetailFEQ, LONG LineFEQ, LONG PEN_Style=PEN:Dot , LONG PEN_Color=-1)
   ReportLineSetAsDashed(*REPORT RptRef, LONG DetailFEQ, LONG LineFEQ, LONG PEN_Style=PEN:Dash, LONG PEN_Color=-1)
ReportLineSetAsDashed PROCEDURE(*REPORT RptRef, LONG DetailFEQ, LONG LineFEQ, LONG PEN_Style=PEN:Dash, LONG PEN_Color=-1)
    CODE   !FYI :the PEN Style Prototype Default is PEN:Dash
    ReportLineSetAsDots(RptRef, DetailFEQ, LineFEQ, PEN_Style,PEN_Color)  
    RETURN
!------------------
ReportLineSetAsDots  PROCEDURE(*REPORT RptRef, LONG DetailFEQ, LONG LineFEQ, LONG PEN_Style=PEN:Dot, LONG PEN_Color=-1)
XLn LONG,AUTO
YLn LONG,AUTO
WLn LONG,AUTO
HLn LONG,AUTO
Orig_Target_Prop LONG,AUTO       !Original SetTarget()
Orig_Target_Ref  &WINDOW         !Also a &REPORT
    CODE 
    IF PEN_Style = PEN:Solid THEN           !Passing SOLID Pen means to Unhide the Line
       RptRef$(LineFEQ){PROP:Hide} = FALSE  !Unhide the LINE
       RETURN 
    END

    Orig_Target_Prop = SYSTEM{PROP:Target}
    IF Orig_Target_Prop THEN                     !I would expect this to always be <> Zero 
       Orig_Target_Ref &= (Orig_Target_Prop)
    END

    SETTARGET(RptRef,DetailFEQ)             !To Draw Line must SetTarget(Report,Band)
    GETPOSITION(LineFEQ,XLn,YLn,WLn,HLn)    !Original Line Control Position
    HIDE(LineFEQ)                           !Hide to put Dashed line on top
    SETPENSTYLE(PEN_Style)                  !Set to passed Dash Dot etc 
    IF PEN_Color <> COLOR:None THEN 
       SETPENCOLOR(PEN_Color)
    END
    Line(XLn,YLn + 0,WLn,HLn)               !Draw Line on top of existing Line Control
    
    IF Orig_Target_Prop THEN                 !Restore to TARGET() before called
       SETTARGET(Orig_Target_Ref)            !bug that does not restore (Rpt,?Band)
    ELSE 
       SETTARGET()                          !Should never happen, if it does restore to WINDOW 
    END
    RETURN 

!How this works:
!   A Report LINE,AT(x,y) Control can only be Solid. 
!   A Draw   LINE(x,y,..) Graphic can use any PENSTYLE Dot Dash DashDot DashDotDot.
!   This works by HIDE() the LINE Control, then draws a graphic LINE() at the X,Y,W,H of the LINE control GetPosition
!   You must Unhide the LINE Control if you want to use it normally i.e. not Dotted. You can call this with Style as SOLID to do that
!   The graphic LINE() only exists for one PRINT() then is cleared AFAIK
!   This code is careful to try to preserve if there's a SetTarget(Report) current
4 Likes

Interestingly, the lines made by Line(…) they are always drawn on top of objects made by Create(…), including Create(0,Create:Line) …

I just noticed in the Help there are functions to get the current PEN values so they can be saved and restored as shown in this help code:

ColorNow LONG
StyleNow LONG
WidthNow LONG
  CODE
  ColorNow = PENCOLOR() !Get current pen color
  StyleNow = PENSTYLE() !Get current pen style
  WidthNow = PENWIDTH() !Get current pen width
  OPEN(MDIChild2)
  SETPENCOLOR(ColorNow) !Set same pen color
  SETPENSTYLE(StyleNow) !Set same pen style
  SETPENWIDTH(WidthNow) !Set same pen width

I’ll add this to my Dotted Line procedure to so the possible side effects are zero.

1 Like