package FormatSGML;


# PACKAGE : FormatSGML
# PURPOSE : Contains the Folio View V4 specific tags information
# AUTHOR  : William Chesters (WilliamC@dai.ed.ac.uk)
# CREATED : 1 Sep 1998
#-----------------------------------------------------------------------------

# Modification History Log
# ========================
# Who                      When       What
#-----------------------------------------
# Williamc@dai.ed.ac.uk    31/08/98   Write
# Tim@paneris.co.uk        31/08/98   Rename
#-----------------------------------------


use DX::Format;

@ISA = ('Format');


%default_value = (
    'baseshift'          => 0,
    'alignment'          => 'left',
#    for (temp_int = 0; temp_int < max_tabs; temp_int++)
#    {
#           "tabs[temp_int]"  => 0,  
#    }
    'tabstops'           => [], # tabstopsParse('1,2,"foo"');  
    'left_indent'        => 0,  
    'first_line_indent'  => 0,
    'right_indent'       => 0,  
    'leading'            => 0,
    'space_before'       => 0,
    'space_after'        => 0,
    'grid_lock_flag'     => 1,
    'language'           => " ",
    'hyphenation'        => " ",
    'rule_above'        => new Rule,
    'rule_below'        => new Rule,
    'drop_cap'           => 0,
    'dc_char_count'      => 0,
    'dc_line_count'      => 0,
    'keep_with'          => 0,
    'keep_together'      => 0,
    'kt_start_line'      => 0,
    'kt_end_line'        => 0,


    'plain'              => 1, 
    'bold'               => 0,
    'italic'             => 0,   
    'outline'            => 0,
    'shadow'             => 0, 
    'underline'          => 0,
    'wordunderline'      => 0,
    'strikethrough'      => 0,
    'all_caps'           => 0,  
    'small_caps'         => 0,   
    'superscript'        => 0,
    'subscript'          => 0,
    'superior'           => 0,
    'font_name'          => 'Times-Roman',
    'font_size'          => 10,
    'colour'             => ' ',
    'shade_percent'      => 0,
    'hscale_percent'     => 0,
    'vscale_percent'     => 0,
    'kern'               => 0,
    'track'              => 0, 

);


sub concreteAttribValueOutput {
  my ($self, $attrib, $value) = @_;

  if ($value =~ /[^a-zA-Z0-9.]/) {
    $value =~ s/\"/\\\"/g;
    $value = "\"$value\"";
  }

  "$tag='$value'";
}

sub blockOutput {
  shift;
  join(' ', @_);
}

# for each kind of attribute, define 
#   EITHER 
#      <attrib>Output, 
#   OR
#      <attrib>Tag and <attrib>Value
#
# in the latter case the default Format::attribOutput will use
# <attrib>Attribute and <attrib>Value in conjunction with the supplied 
# concreteAttribValueOutput above

sub nameAttribute {
  'PA';
}

sub recordOutput {
  'RD';
}

sub paraOutput {
  'HR';
}

sub breakOutput {
  'CR';
}

sub tabOutput {
  'TAB';
}

sub asciiOutput {
  my $code = shift;
  "&#$code;";
}


sub alignmentAttribute {
  'JU';
}

$alignmentValues = {
  'left' => 'LF',
  'right' => 'RT',
  'centre' => 'CN',
  'justify' => 'FL'
};

sub alignmentValue {
  $alignmentValues{$_[1]};
}

sub indentOutput {
  undef;
}

sub leadingOutput {
  undef;
}

sub space_beforeAttribute {
  'BP';
}

sub space_afterAttribute {
  'AP';
}

sub keep_withOutput {
  undef;
}

sub tabstopsOutput {
  undef;
}

sub keep_togetherOutput {
  undef;
}

sub font_nameAttribute {
  'FT';
}

sub font_sizeAttribute {
  'PT';
}

sub boldOutput {
  $_[1]->{bold} ? 'BD+' : 'BD';
}

sub italicOutput {
  $_[1]->{italic} ? 'IT+' : 'IT';
}

sub underlineOutput {
  $_[1]->{underline} ? 'UL+' : 'UL';
}

sub strikethroughOutput {
  $_[1]->{strikethrough} ? 'SO+' : 'SO';
}

# FIXME what is this meant to be?

sub verticalOffsetAttribute {
  'SP';
}

sub hscale_percentOutput {
  undef;
}

sub colourOutput {
  undef;
}

sub smallCapsOutput {
  undef;
}

sub outlineOutput {
  undef;
}


sub definitionOutput {
  my $self = shift;
  my $name = shift;

  $self->definition_header .
  $self->definition_footer ;
}

sub invocationOutput {
  $_[0]->blockOutput($_[0]->concreteAttribValueOutput('PS', $_[1]));
}


sub definition_footer
{
  undef;
}
sub definition_header
{
  undef;
}

sub new {
  bless {};
}

sub copy {

    my($self) = shift;

    # Create the anonymous hash reference to hold the object's data.

    my %copy = %$self;

    return bless \%copy;  
}


1;

