!***********************************************************************
! PDFcontrol2mark v1.1                                                 *
! 02.01.1999 / Vertex Systems Oy / MikaP                               *
! 21.09.1999 / Vertex Systems Oy / PekkaMal                            *
! pdfmark-komentojen muodostus ohjaustiedostosta                       *
!***********************************************************************
!
!*** Perusasetukset ***
!-----------------------------------------------------------------------
DefaultZoom = -1      ;! -1=Fit in Window
!                     ;!  0=Acrobat Reader asetus
!                     ;!  50=50%, 200=200%, jne
!-----------------------------------------------------------------------
!
!
!*** Muut vakiot ***
Date$ = get($DATE)                ;! Paivamaara
Time$ = get($TIME)                ;! Aika
HomeDir$ = get($DIR_HOME)         ;! Kotihakemisto
OpenFile$ = get(PS_CONTROL_FILE)  ;! Ohjaustiedosto, asetetaan PDFproject2pdf:ssa
ProjectId$ = get($ACTPROJNAME)    ;! Projektitunnus
PdfMarkFile$ = get(PDF_MARK_FILE) ;! pdfmark-tiedosto, asetetaan PDFproject2pdf:ssa
NoMetaData = get(PDF_MARK_NO_METADATA)
!
if DefaultZoom = -1 then
  ViewArray$ = "[/Fit]"
else
  if DefaultZoom = 0 then
    Zoom$ = "null"
  endif
  if DefaultZoom > 0 then
    DefaultZoom = DefaultZoom/100
    Zoom$ = DefaultZoom
  endif
  ViewArray$ = "[/XYZ null null "&Zoom$&"]"
endif
!
!
!*** paivamaara ja aika pdf-muotoon ***
DateLen = len(Date$)
TimeLen = len(Time$)
PdfDate$ = ""
i=0
loop DateLen
  i=i+1
  if (cmp(Date$[i,i],"-")==0) then
    PdfDate$ = PdfDate$&Date$[i,i]
  endif
endloop
i=0
loop TimeLen
  i=i+1
  if (cmp(Time$[i,i],":")==0) then
    PdfDate$ = PdfDate$&Time$[i,i]
  endif
endloop
!
!
!*** pdfmark-komennot pdf-tiedoston avaustavalle ja document infolle ***
open(9) PdfMarkFile$
write(9) "%!PS-Adobe-3.0"
write(9) ""
write(9) "<< /AutoRotatePages /None"
write(9) ">> setdistillerparams"
write(9) ""
write(9) "% OPEN INFO"
write(9) "[ /PageMode /UseOutlines "
write(9) "  /Page 1 /View "&ViewArray$
write(9) "/DOCVIEW pdfmark"
write(9) ""
if (NoMetaData==0) then
  write(9) "% CATALOG INFO"
  write(9) "[ /Title "&pdfmarkstr(ProjectId$,0)
  write(9) "  /Author "&pdfmarkstr("Vertex BD",0)
  write(9) "  /Keywords "&pdfmarkstr(ProjectId$,0)
  write(9) "  /Creator "&pdfmarkstr("Vertex BD",0)
  !write(9) "  /CreationDate "&pdfmarkstr(PdfDate$,0) ;! Oma asetus vain Distiller
  !write(9) "  /ModDate ( )"                   ;! YYYYMMDDHHMMSS
  write(9) "/DOCINFO pdfmark"
  write(9) ""
endif
!
!
!*** piirustusten laskenta ***
open(2) OpenFile$
pic=0
sheet(pic)=0
loop
  In$=read(2)
  end=findstr(In$," ")
  Ind1$=In$[1,end-1]
  Ind1=Ind1$
  if Ind1>0 then
    pic=pic+1
    sheet(pic)=0
  endif
  exitif eof(2)
endloop
close(2)
!
!
!*** pdfmark-komennot pdf-tiedoston hakemistoa varten ***
!---------------------------------------------------------
! Paahakemisto            0 0 'Title'
! Toisen tason otsikot    x 0 'Sub'
! Kolmannen tason otsikot x x 'Picname'
!---------------------------------------------------------
open(2) OpenFile$
Page=1
write(9) "% BOOKMARKS"
loop
  In$=read(2)
  space=findstr(In$," ")
  Ind1$=In$[1,space-1]
  Ind1 = Ind1$
  end=len(In$)
  In$=In$[space+1,end]
  quote = findstr(In$,"""")
  if quote>0 then
    end=len(In$)
    In$=In$[quote+1,end-1]
  endif
  Title$=pdfmarkstr(In$,0)
  !
  if Ind1=0 then
    write(9) "[ /Count "&pic&" /Page 1 /View "&ViewArray$&" /Title "&Title$
    write(9) "/OUT pdfmark"
  endif
  if Ind1>0 then
    if sheet(Ind1)=0 then
      write(9) "[ /Page "&Page&" /View "&ViewArray$&" /Title "&Title$
      write(9) "/OUT pdfmark "
      Page=Page+1
    else
      if Ind1 = 1 then
        Sign$ = ""
      else
        Sign$ = "-"
      endif
      write(9) "[ /Count "&Sign$&sheet(Ind1)&" /Page "&Page&" /View "&ViewArray$&" /Title "&Title$
      write(9) "/OUT pdfmark"
    endif
  endif
  exitif eof(2)
endloop
write(9) ""
close(2)
close(9)
