Print Preview ActiveX Active Users: 73 / Visits Today: 273
Highest Active Users: 102
Print Preview ActiveX
Home | Profile | Register | Active Topics | Members | Search | FAQ | RSS
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Print Preview
 Tips & Tricks
 Splitting Paratext to fit on page(s)
 New Topic  Reply to Topic
 Printer Friendly
Author  Topic Next Topic: Number of Item in a group  

emiel
Administrator

Belgium
327 Posts

Posted - 06/16/2006 :  13:01:35  Show Profile  Reply with Quote
Private Function PrintParaText(Stxt As String, CurX As Long, CurY As Long, BlockWidth As Long)

' this function takes care for the actual printing of the paratext, and checks the
' the paratext for fitting on the page by calling a split function (CalculateLines (....))
' if the text is not fitting on the page, it adds a new page and so on and so forth, until
' all paratext is printed.

' The paratext-tags however are considered as text, in which case if there are few tags it
' will not be a problem, in case of many there should be added a routine to eliminate the
' the width of the tags, the location for the call is given in the CalculateLines function.

Dim sTxtFirstPart             As String
Dim sTxtLastPart              As String
Dim nI                        As Long
Dim nTxtWidth                 As Long
Dim nParaBlockWidth           As Long
Dim nParaBlockLines           As Long
Dim bSplits                   As Boolean

nParaBlockWidth = BlockWidth ' in twips

preview.CurrentY = CurY

                              ' check text for fitting on page
Check_Lastpart: ' return point if second part of splitted text has been returned

Stxt = CalculateLines(Stxt, nParaBlockWidth, preview.CurrentY, preview.PageInsideBottom, _
                        preview.TextHeight("W"))

' is the returned paratext to be split ?- delimitter 
  
If InStr(1, Stxt, "") <> 0 Then
   
   nI = InStr(1, Stxt, "")
   sTxtFirstPart = Mid(Stxt, 1, nI - 1)
   sTxtLastPart = Mid(Stxt, nI + 1)
   bSplits = True
   
End If

If bSplits Then

   ' reset bSplits
   bSplits = False

   ' print the first part    
      
   preview.ParaText sTxtFirstPart, CurX, preview.CurrentY, nParaBlockWidth

    pPagina = pPagina + 1
    preview.AddPage 1000, 1000, 1000, 1000
    Call PageSetting ' personal routine to set the page properties
    Call PagPlaats ' personal routine setting the pagenumber
    preview.AddTextAt ' blanc line
    nI = preview.CurrentY
    preview.FontSize = pT1 ' the used fontsize

    preview.CurrentY = nI

   Stxt = sTxtLastPart
   GoTo Check_Lastpart   ' check if lastpart fits on this new page
   
Else ' The text fits so print it

   preview.ParaText Stxt, CurX, preview.CurrentY, nParaBlockWidth
   
End If

End Function

' ---------------------

Private Function CalculateLines(Stxt As String, nLenBlock As Long, nCurY As Long, _
        nBottom As Long, nTxtHeight As Long) As String
        
'* This function calculates the lines of the paratext for a certain paratextblock
'* on base of the calculated lines it will check if the text will fit on the page
'* if it fits it returns the plain text, otherwise only one delimmiter  will be added
'* for splitting the text, and the function is recalled till all text is printed properly.


Dim nLines       As Long
Dim nPos1         As Long
Dim nPos2         As Long
Dim nPos3         As Long
Dim nLastPos      As Long
Dim nSplit        As Long
Dim sHelpText     As String
Dim strTxt        As String
Dim lDeduct	  As Long
Dim sWord	  As String
Dim bEliminate	  As Boolean

sWord = "" ' used for eliminating textwidth for paratext-tags
lDeduct = 0 ' used for eliminating textwidth of the paratext-tags
bEliminate = False ' used for eliminating textwidth for paratext-tags

sHelpText = ""

nPos2 = 1 ' starting position

strTxt = Stxt 
strTxt = Trim(strTxt) + " " ' last space used as end of text, to be certain first trim it
nLastPos = Len(strTxt) ' position of end space
nLines = -1 ' set line counter
nBottom = nBottom - 1500  '(3 * nTxtHeight) ' bug insidebottom last 3 lines will not be printed , 1500 is a personal setting

' this part does NOT take note of paratext tags !

Do While True

   If preview.TextWidth(sHelpText) - lDeduct < nLenBlock And nPos1 <> nLastPos Then ' check len
   
      ' add words, sequential, from the string to sHelpText
      
      nPos3 = nPos1
      nPos1 = InStr(nPos2, strTxt, " ")

	' Here to add a call to eliminate a paratext tag like :

	' sWord = mid(strTxt, nPos2, npos1) ' get word or possible tag if separated with spaces
	' bEliminate = EliminateTag( sWord ) ' this routine should check all available tags and should return "true", when available for deletion
	' if bEliminate = True Then

	      lDeduct = lDeduct + preview.TextWidth(trim(sWord)) 'don't remove this line !!!!!!
 
        ' endif

      sHelpText = Mid(strTxt, 1, nPos1)
      nPos2 = nPos1 + 1
      
   Else
            
      nLines = nLines + 1
      
      If nCurY + (nLines * nTxtHeight) > nBottom Then    ' check bottom page for fitting
       
         Stxt = Mid(Stxt, 1, nSplit) & "" & Mid(Stxt, nSplit + 1)  ' place delimmiter 
	   lDeduct = 0
         GoTo ReturnValue
         
      End If
      
      sHelpText = Mid(sHelpText, 1, nPos1 - 1)          ' remove previously added end-space 
                                                      ' check hulptxt > blockwidth
      
      If preview.TextWidth(sHelpText) > nLenBlock Then ' Yes
      
         nPos2 = nPos3 + 1                            ' then continue with last word
         
      End If
      
      If nLastPos = nPos1 Then                        ' ready
      
         Exit Do
         
      End If
      
      sHelpText = ""
      strTxt = Mid(strTxt, nPos2)      ' remove hulptext
      nSplit = Len(Stxt) - Len(strTxt) ' keep track in case of splitting
      nPos2 = 1                        ' startpoint for InStr function
      nLastPos = Len(strTxt)           ' reset last space location
      
   End If

Loop

ReturnValue:

CalculateLines = Stxt
   
End Function
Go to Bottom of Page
   Topic Next Topic: Number of Item in a group  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
Print Preview ActiveX © Mandix Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000 Version 3.4.02