home *** CD-ROM | disk | FTP | other *** search
- #---------------------------------------------------------------------------
- #
- # (c) Westmount Technology 1994
- #
- # File: @(#)fmdocconge.tcl /main/hindenburg/1
- # Author: <generated>
- # Description:
- #---------------------------------------------------------------------------
- # SccsId = @(#)fmdocconge.tcl /main/hindenburg/1 23 Oct 1996 Copyright 1994 Westmount Technology
-
- # Start user added include file section
- # End user added include file section
-
- require "fmcongen.tcl"
-
- Class FmDocConGen : {FmConGen} {
- method destructor
- constructor
- method generate
- method genComponent
- method genPicture
- method genText
- method genTextLine
- method genTitle
- method section
- attribute frameWidth
- attribute frameHeight
- attribute frames
- attribute pgfs
- attribute chapter
- attribute _section
- }
-
- global FmDocConGen::pictureNr
- set FmDocConGen::pictureNr ""
-
-
- method FmDocConGen::destructor {this} {
- set ref [$this _section]
- if {$ref != ""} {
- $ref _contentsGenerator ""
- }
- # Start destructor user section
- # End destructor user section
- $this FmConGen::destructor
- }
-
- constructor FmDocConGen {class this name section} {
- set this [FmConGen::constructor $class $this $name $section]
- $section _contentsGenerator $this
-
- global FmDocConGen::pictureNr
- if {${FmDocConGen::pictureNr} == ""} {
- # Start numbering pictures at 100 to prevent conflicts with
- # default frames in the template
- set FmDocConGen::pictureNr 100
- }
-
- $this frameWidth "6.0625"
- $this frameHeight "7.0625"
-
- return $this
- }
-
- method FmDocConGen::generate {this} {
-
- # First the contents is generated in two sections: the frames and the
- # paragraphs. These sections are put in a MIF-file by expanding the
- # template MIF-file '<name><version>.mif'. This file contains
- # expandable TCL-macro's to include the contents of the sections.
- # Furthermore the template MIF-file contains a macro to include the
- # title of the document using 'FmDocConGen::genTitle'.
-
- set mifFid [$this openMif]
-
- if {$mifFid == ""} {
- return
- }
-
- # get the parent (chapter) if the current section
- $this chapter [[$this section] parentSection]
- if { [$this chapter] == "" } {
- return ""
- }
-
- # Start the sections for the frames and the paragraphs
- $this frames [TextSection new]
- $this pgfs [TextSection new]
-
- set inSubdoc 0
- set subLevel 0
-
- foreach sect [[$this section] getTree] {
-
- set level [$sect indentation]
- set name [$sect uiName]
- set type [$sect type]
- set class [$sect operationClass]
-
- if {$inSubdoc} {
- # Check for end of subdoc
- if {$level <= $subLevel} {
- set inSubdoc 0
- set subLevel 0
- }
- }
-
- if {!$inSubdoc} {
- # Check if the section is manipulatable. If so then skip
- # this section and all it's underlying sections.
- if {$class == "manipulate"} {
- # In subdocument
- set inSubdoc 1
- set subLevel $level
- } else {
- # Generate contents for this section
- $this genComponent $sect
- }
- }
- }
-
- # Make the Framemaker file
- # Make a section and expand the template into it
- set contents [TextSection new]
-
- # need to do this, otherwise pgfs is removed ???????
- set pgfs [$this pgfs]
- expand_file $contents [$this templatePath]
-
- # Write the contents into the MIF-file
- $contents write $mifFid
- close $mifFid
-
- $this mif2Bin
- }
-
- method FmDocConGen::genComponent {this section} {
-
- # Look at the doctype of the class and generate a picture
- # or a text for it in the MIF-file.
- case [$section docType] {
- {Epsi Eps Ximage} {$this genPicture $section}
- {default} {$this genText $section}
- }
- }
-
- method FmDocConGen::genPicture {this section} {
-
- # Generate MIF for a picture. This consists of making a frame with a
- # reference to the path of the picture in the frames-section, and making
- # a paragraph with a reference to this frame in the paragraphs-section.
- # Also a paragraph for the picture-title is generated in the paragraphs-
- # section.
-
- set frames [$this frames]
- set pgfs [$this pgfs]
- set fWidth [$this frameWidth]
- set fHeight [$this frameHeight]
-
- # Take next picture-nr
- global FmDocConGen::pictureNr
- incr FmDocConGen::pictureNr
-
- set objFile "[[$this section] escape [$section docLocation]]"
-
-
- # get the boundingbox size and make the shaperect
- # also 'center' the picture
- set hasBoundingBox 0
-
- if {![catch {set ps [open [$section docLocation] r]} reason]} {
- seek $ps -200 end
- while {[gets $ps line] != -1} {
- if [regexp "%%BoundingBox:" $line] {
- set boxList [split $line]
- lvarpop boxList
- set left [lvarpop boxList]
- set top [lvarpop boxList]
- set right [lvarpop boxList]
- set bottom [lvarpop boxList]
- set hasBoundingBox 1
- break
- }
- }
- }
-
- # Generate the frame in the frames-section
- $frames append " <Frame\n"
- $frames append " <ID ${FmDocConGen::pictureNr}>\n"
- if {$hasBoundingBox == 1} {
- set width [expr {($right - $left)/72.0}]
- set height [expr {($bottom - $top)/72.0}]
- set leftOffset [expr {($fWidth-$width)/2.0}]
- set topOffset [expr {($fHeight-$height)/2.0}]
- $frames append " <ShapeRect $leftOffset\" \
- $topOffset\" $width\" $height\">\n"
- } else {
- $frames append " <ShapeRect 0.0\" 0.0\" $fWidth\" \
- $fHeight\">\n"
- }
- $frames append " <FrameType Below>\n"
- $frames append " <Float No>\n"
- $frames append " <NSOffset 0.0\">\n"
- $frames append " <BLOffset 0.0\">\n"
- $frames append " <AnchorAlign Center>\n"
- $frames append " <ImportObject\n"
- $frames append " <ImportObFile `$objFile'>\n"
- $frames append " >\n"
- $frames append " >\n"
-
- # Generate a paragraph with a reference to the frame in the
- # paragraphs-section
- $pgfs append " <Para\n"
- $pgfs append " <PgfTag `Normal'>\n"
- $pgfs append " <ParaLine\n"
- $pgfs append " <AFrame ${FmDocConGen::pictureNr}>\n"
- $pgfs append " >\n"
- $pgfs append " >\n"
-
- # Generate a paragraph for the title of the picture in the
- # paragraphs-section
- $pgfs append " <Para\n"
- $pgfs append " <PgfTag `PictureTitle'>\n"
- $pgfs append " <ParaLine\n"
- $pgfs append " <String `[[$this section] escapeText [$section docTitle]]'>\n"
- $pgfs append " <Char HardReturn>\n"
- $pgfs append " >\n"
- $pgfs append " <ParaLine\n"
- $pgfs append " <String `'>\n"
- $pgfs append " <Char HardReturn>\n"
- $pgfs append " >\n"
- $pgfs append " >\n"
- }
-
- method FmDocConGen::genText {this section} {
-
- set pgfs [$this pgfs]
-
- # Generate a paragraph for the text-title
- $pgfs append " <Para\n"
- $pgfs append " <PgfTag `TextTitle'>\n"
- $pgfs append " <ParaLine\n"
- $pgfs append " <String `[[$this section] escapeText [$section docTitle]]'>\n"
- $pgfs append " >\n"
- $pgfs append " >\n"
-
- # Start the paragraph for the text
- $pgfs append " <Para\n"
- $pgfs append " <PgfTag `Normal'>\n"
-
- # Open the text-file
- if {[catch {set text [open [$section docLocation] r]} reason]} {
- # Open failed. Put the error on the screen and
- # in the contents of the
- # paragraph. Error is not fatal so continue execution.
- set err "Error on opening 'path' for reading: $reason"
- wmtkerror $err
- $this genTextLine $err
- } else {
- # Read all lines from the text-file and put them in
- # the paragraph
- while {[gets $text line] != -1} {
- $this genTextLine $line
- }
- # Close the text-file
- close $text
- }
-
- # Finish the paragraph
- $pgfs append " >\n"
- }
-
- method FmDocConGen::genTextLine {this line} {
-
- set pgfs [$this pgfs]
-
- # Start the paragraph-line
- $pgfs append " <ParaLine\n"
-
- # Walk through the leading spaces and tabs code the hard in the MIF
- set i 0
- set l [string length $line]
- while {$i < $l} {
- case [string index $line $i] {
- { " " } {$pgfs append " <Char HardSpace>\n"}
- { "\t" } {$pgfs append " <Char Tab>\n"}
- default {break}
- }
- incr i
- }
-
- # Strip the leading spaces and tabs
- set pureLine [string trim $line " \t"]
-
- # Put the string without the leading spaces and tabs
- # in the paragraph-line and finish the paragraph-line
- $pgfs append " <String `[[$this section] escapeText $pureLine]'>\n"
- $pgfs append " <Char HardReturn>\n"
- $pgfs append " >\n"
- }
-
- method FmDocConGen::genTitle {this textRectID} {
-
- # Get the level of the section.
- # This determines the kind of title
- set level [[$this section] indentation]
-
- # Determine the kind of title, i.e. the paragraph-tag
- case $level {
- {0 1} {set tag Chapter}
- {2} {set tag Section}
- {3} {set tag SubSection}
- {4} {set tag SubSubSection}
- default {return ""}
- }
-
- # Check if the section is the first one of this level
- # within the upper level. If so then use the paragraph-tag
- # extended with '1', to make the number starting at the beginning.
- set extension 1
-
- set parent [[$this section] parentSection]
- if { $parent == "" } {
- return ""
- }
-
- set brothers [$parent childSectionSet]
-
- # only if it's the first the extension is 1
- if {[$this section] == [$brothers index]} {
- set extension 1
- } else {
- set extension ""
- }
-
- # Make a section for the title
- set title [TextSection new]
-
- # Fill the section with the paragraph that defined the complete title
- $title append " <Para\n"
- $title append " <PgfTag `$tag$extension'>\n"
- $title append " <ParaLine\n"
- $title append " <TextRectID $textRectID>\n"
- $title append " <String `[[$this section] escapeText [[$this section] docTitle]]'>\n"
- $title append " >\n"
- $title append " >\n"
-
- # Return the contents of the title-section to be filled in into
- # the template
- return [$title contents]
- }
-
- # Do not delete this line -- regeneration end marker
-
- method FmDocConGen::section {this args} {
- if {$args == ""} {
- return [$this _section]
- }
- set ref [$this _section]
- if {$ref != ""} {
- $ref _contentsGenerator ""
- }
- set obj [lindex $args 0]
- if {$obj != ""} {
- $obj _contentsGenerator $this
- }
- $this _section $obj
- }
-
-