# This is -*- tcl -*- script
# $Id: gost_pages_duplex,v 1.2 2001/08/14 12:56:28 fedya Exp $

# Can't be used with page_headers
global TEItools_page_headers_in_use
if { [info exists TEItools_page_headers_in_use] } {
    puts stderr "\n*** 'gost_pages' style can't be used with 'page_headers'!\n"
    exit 1
}

rename extraPreamble extraPreamble_GOSTPages

proc extraPreamble {} {
debug 1
    foreach keyName { DisKey CheckKey TechKey NormKey ProvKey DocTitle ProdKey \
			  keyword tuKey } {
	set theKey [string tolower $keyName]
	global TEItools_GOST_$theKey
    }
    global TEItools_GOST_no_head
    if { "$TEItools_GOST_tukey" == "" } {
	set theTu ""
	set TEItools_GOST_no_head ",nohead"
    } else {
	set theTu "\\raisebox{-1ex}{\\bf\\sl\\large[localize cyr]${TEItools_GOST_tukey}~~}"
	set TEItools_GOST_no_head ""
    }

    set ret "
% Page layout

\\newcommand{\\cent}\[2\]{\\hbox to #2mm{\\hfil{}#1\\hfil{}}}
\\newcommand{\\rcent}\[2\]{\\rotatebox{90}{\\cent{#1}{#2}}}
\\newcommand{\\cbox}\[3\]{\\parbox\[b\]\[#3mm\]\[c\]{#2mm}{\\begin{center}#1\\end{center}}}

\\usepackage{afterpage}
\\usepackage{lastpage}
% Stamp at the bottom
\\usepackage{fancyhdr}
\\pagestyle{fancy}
\\renewcommand{\\headrulewidth}{0pt}
\\renewcommand{\\footrulewidth}{0pt}
\\fancyfoot\[L,R,C\]{}
\\fancyhead\[L,R,C\]{}
\\fancyhead\[LE,RO\]{${theTu}}
\\fancyfoot\[LE\]{\\TEItoolsGOSTstampEven}
\\fancyfoot\[RO\]{\\TEItoolsGOSTstamp}

\\newcommand{\\TEItoolsGOSTstamp}{\\theTEItoolsGOSTstamp{11}}

\\newcommand{\\TEItoolsGOSTstampEven}{\\theTEItoolsGOSTstamp{0}}

\\newcommand{\\theTEItoolsGOSTstamp}\[1\]{\\unitlength=1mm\\thicklines%
  \\begin{picture}(185,15)(#1,5)
    \\footnotesize
    \\sf\\sl
    %  
    \\put(0,0){\\line(1,0){185}}
    \\put(0,0){\\line(0,1){286}}
    \\put(185,0){\\line(0,1){286}}
    \\put(0,286){\\line(1,0){185}}
    %  
    \\put(0,15){\\line(1,0){185}}
    \\put(0,5){\\line(1,0){65}}
    \\put(0,10){\\line(1,0){65}}
    \\put(7,0){\\line(0,1){15}}
    \\put(17,0){\\line(0,1){15}}
    \\put(40,0){\\line(0,1){15}}
    \\put(55,0){\\line(0,1){15}}
    \\put(65,0){\\line(0,1){15}}
    \\put(0,1.5){\\cent{[localize cyr]\\tiny .}{7}}
    \\put(7,1.5){\\cent{[localize cyr]\\tiny }{10}}
    \\put(17,1.5){\\cent{[localize cyr]\\tiny \\textnumero{}~.}{23}}
    \\put(40,1.5){\\cent{[localize cyr]\\tiny .}{15}}
    \\put(55,1.5){\\cent{[localize cyr]\\tiny }{10}}
    \\put(175,0){\\line(0,1){15}}
    \\put(175,8){\\line(1,0){10}}
    \\put(175,11){\\cent{[localize cyr]\\tiny }{10}}
    \\put(175,3){\\cent{[localize cyr]\\tiny \\thepage}{10}}
    \\put(65,7){\\cent{[localize cyr]${TEItools_GOST_keyword}}{110}}
  \\end{picture}}

\\newcommand{\\TEItoolsGOSTstampA}{\\unitlength=1mm\\thicklines%
  \\begin{picture}(185,15)(3,5)
    \\footnotesize
    \\sf\\sl
    %  
    \\put(0,0){\\line(1,0){185}}
    \\put(0,0){\\line(0,1){286}}
    \\put(185,0){\\line(0,1){286}}
    \\put(0,286){\\line(1,0){185}}
    \\put(0,0){\\line(-1,0){12}}
    \\put(0,25){\\line(-1,0){12}}
    \\put(0,60){\\line(-1,0){12}}
    \\put(0,85){\\line(-1,0){12}}
    \\put(0,110){\\line(-1,0){12}}
    \\put(0,145){\\line(-1,0){12}}
    \\put(-7,0){\\line(0,1){145}}
    \\put(-12,0){\\line(0,1){145}}
    \\put(-11,1){\\rcent{[localize cyr]\\tiny . \\textnumero{} .}{25}}
    \\put(-11,26){\\rcent{[localize cyr]\\tiny .  }{35}}
    \\put(-11,60){\\rcent{[localize cyr]\\tiny ..\\textnumero}{25}}
    \\put(-11,86){\\rcent{[localize cyr]\\tiny . \\textnumero{} .}{25}}
    \\put(-11,111){\\rcent{[localize cyr]\\tiny .  }{35}}

    %  
    \\put(0,40){\\line(1,0){185}}
    \\put(0,30){\\line(1,0){65}}
    \\put(0,35){\\line(1,0){65}}
    \\put(7,25){\\line(0,1){15}}
    \\put(17,0){\\line(0,1){40}}
    \\put(40,0){\\line(0,1){40}}
    \\put(55,0){\\line(0,1){40}}
    \\put(65,0){\\line(0,1){40}}
    \\put(0,26.5){\\cent{[localize cyr]\\tiny .}{7}}
    \\put(7,26.5){\\cent{[localize cyr]\\tiny }{10}}
    \\put(17,26.5){\\cent{[localize cyr]\\tiny \\textnumero~.}{23}}
    \\put(40,26.5){\\cent{[localize cyr]\\tiny .}{15}}
    \\put(55,26.5){\\cent{[localize cyr]\\tiny }{10}}
    \\put(0,25){\\line(1,0){185}}
    \\put(0,20){\\line(1,0){65}}
    \\put(0,15){\\line(1,0){65}}
    \\put(0,10){\\line(1,0){65}}
    \\put(0,5){\\line(1,0){65}}
    \\put(65,0){\\line(0,1){25}}
    \\put(135,0){\\line(0,1){25}}
    \\put(135,20){\\line(1,0){50}}
    \\put(135,15){\\line(1,0){50}}
    \\put(140,20){\\line(0,-1){5}}
    \\put(145,20){\\line(0,-1){5}}
    \\put(150,25){\\line(0,-1){10}}
    \\put(165,25){\\line(0,-1){10}}
    \\put(1.5,1){[localize cyr]\\tiny .}
    \\put(1.5,6){[localize cyr]\\tiny ..}
    \\put(1.5,11){[localize cyr]\\tiny ..}
    \\put(1.5,16){[localize cyr]\\tiny .}
    \\put(1.5,21){[localize cyr]\\tiny .}
    \\put(135,21){\\cent{[localize cyr]\\tiny .}{15}}
    \\put(150,21){\\cent{[localize cyr]\\tiny }{15}}
    \\put(150,16){\\cent{\\thepage}{15}}
    \\put(165,21){\\cent{[localize cyr]}{15}}
    \\put(165,16){\\cent{\\pageref{LastPage}}{15}}
    \\put(18,21){\\tiny{}[localize cyr]$TEItools_GOST_diskey}
    \\put(18,16){\\tiny{}[localize cyr]$TEItools_GOST_checkkey}
    \\put(18,11){\\tiny{}[localize cyr]$TEItools_GOST_techkey}
    \\put(18,6){\\tiny{}[localize cyr]$TEItools_GOST_normkey}
    \\put(18,1){\\tiny{}[localize cyr]$TEItools_GOST_provkey}
    \\put(66,26){\\cbox{[localize cyr]$TEItools_GOST_keyword}{115}{13}}
    \\put(136,1){\\cbox{[localize cyr]$TEItools_GOST_prodkey}{45}{13}}
    \\put(66,1){\\cbox{[localize cyr]$TEItools_GOST_doctitle}{65}{23}}
  \\end{picture}}
[extraPreamble_GOSTPages]
"
    return $ret
}


rename TitlePageHook TitlePageHook_gost_pages

proc TitlePageHook {} {
    return "%\\thispagestyle{empty}
\\thispagestyle{fancy}\\enlargethispage{-25mm}
\\setlength\\evensidemargin{3mm}
\\fancyfoot\[LE,RO\]{\\TEItoolsGOSTstampA}
\\afterpage{\\global\\setlength{\\evensidemargin}{-13mm}\\fancyfoot\[LE\]{\\TEItoolsGOSTstampEven}\\fancyfoot\[RO\]{\\TEItoolsGOSTstamp}}

[TitlePageHook_gost_pages]
"
}

rename geometryArgs {}

proc geometryArgs {} {
    global TEItools_GOST_no_head
    return "a4paper,twoside,twosideshift=10.5mm,top=15mm,bottom=15mm,footskip=1cm,width=165mm${TEItools_GOST_no_head}"
}


if { "[info proc frontpagePlacement]" != "" } {
    rename frontpagePlacement {}
    proc frontpagePlacement {} {
	return "-112,-790"
    }
}

foreach keyName { DocTitle DisKey CheckKey TechKey NormKey ProvKey ProdKey \
		      keyword tuKey } {
    set theKey [string tolower $keyName]
    global TEItools_GOST_$theKey
    set TEItools_GOST_$theKey ""
    proc TEItools_PI_$theKey { args } [ subst -nocommands -nobackslashes {
	global TEItools_GOST_$theKey
	set TEItools_GOST_$theKey [set args]
    }]
}

rename openFront {}

proc openFront {} {
    return
}

rename closeFront {}

proc closeFront {} {
    return
}
    
