• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

cdtext.c

Go to the documentation of this file.
00001 //
00002 // cdtext is an example program that uses the text attribute commands
00003 // cdSetTextPath and cdSetTextOrient
00004 //
00005 //
00006 // cdtext.c: test program for the cgmdraw module.
00007 //
00008 //      Written by G. Edward Johnson <mailto:lorax@nist.gov>
00009 //      Date: May 1996
00010 //      Copyright: cd software produced by NIST, an agency of the
00011 //      U.S. government, is by statute not subject to copyright
00012 //      in the United States. Recipients of this software assume all
00013 //      responsibilities associated with its operation, modification
00014 //      and maintenance.
00015 //
00016 //
00017 
00018 
00019 #include <stdio.h>
00020 #include <math.h>
00021 #include <string.h>
00022 #include <stdlib.h>
00023 #include "defines.h"
00024 #include "cd.h"
00025 
00026 
00027 int main()
00028 {
00029     // you must create a pointer to the image(s) that you will be using
00030     // not suprisingly, it is of type cdImagePtr
00031     cdImagePtr im;
00032 
00033     // this is a pointer to the output file you will be using
00034     FILE *outf;
00035 
00036     // these will be index's into the color palette containing
00037     // the corresponding colors
00038     int black, white, blue;
00039 
00040 
00041     // Create an image 800 pixels wide by 400 pixels high
00042     im = cdImageCreate( 800, 400 );
00043 
00044     // allocate some colors (isn't this fun?)
00045     // the first color allocated is the background color
00046     white = cdImageColorAllocate( im, 255, 255, 255 );
00047     black = cdImageColorAllocate( im, 0, 0, 0 );
00048     blue  = cdImageColorAllocate( im, 0, 0, 255 );
00049 
00050 
00051     // set the text attributes
00052     // font, colorindex, and size respectivily
00053 
00054     // font is the style the text is written in. 1 is for Times,
00055     // 5 is for Helvetica.
00056     // we will have black text for this one
00057     // Size is a tough one,  but larger numbers give larger text.
00058     //
00059     if ( !( cdSetTextAttrib( im, 5, black, 20 ) ) )
00060         return 1;
00061 
00062     // Set some line attributes,  lets make lines solid, width 1, and blue
00063     //
00064     if ( !( cdSetLineAttrib( im, 1, 1, blue ) ) )
00065         return 1;
00066 
00067     // Draw a couple of grid lines
00068     if ( !( cdLine( im, 0, 200, 799, 200 ) ) )
00069         return 1;
00070     if ( !( cdLine( im, 200, 0, 200, 399 ) ) )
00071         return 1;
00072     if ( !( cdLine( im, 600, 0, 600, 399 ) ) )
00073         return 1;
00074 
00075 
00076     // Show Text going left, up, down, and right, all starting
00077     // from the same point
00078 
00079     // Text going to the left
00080     if ( !( cdSetTextPath( im, 1 ) ) )
00081         return 1;
00082     if ( !( cdText( im, 200, 200, "Text Left" ) ) )
00083         return 1;
00084 
00085     // Text going UP
00086     if ( !( cdSetTextPath( im, 2 ) ) )
00087         return 1;
00088     if ( !( cdText( im, 200, 200, "Text Up" ) ) )
00089         return 1;
00090 
00091     // Text going DOWN
00092     if ( !( cdSetTextPath( im, 3 ) ) )
00093         return 1;
00094     if ( !( cdText( im, 200, 200, "Text Down" ) ) )
00095         return 1;
00096 
00097     // Text going to the RIGHT
00098     if ( !( cdSetTextPath( im, 0 ) ) )
00099         return 1;
00100     if ( !( cdText( im, 200, 200, "Text Right" ) ) )
00101         return 1;
00102 
00103     // Show text going at an angle of 0, 45, 90, 135, 180 Degrees
00104     //
00105 
00106     // Text at no angle
00107     if ( !( cdText( im, 600, 200, "CGM Draw" ) ) )
00108         return 1;
00109 
00110     // Text, 45 Degree Angle
00111     if ( !( cdSetTextOrient( im, -1, 1, 1, 1 ) ) )
00112         return 1;
00113     if ( !( cdText( im, 600, 200, "CGM Draw" ) ) )
00114         return 1;
00115 
00116     // Text, 90 Degree Angle
00117     if ( !( cdSetTextOrient( im, -1, 0, 0, 1 ) ) )
00118         return 1;
00119     if ( !( cdText( im, 600, 200, "CGM Draw" ) ) )
00120         return 1;
00121 
00122     // Text, 135 Degree Angle
00123     if ( !( cdSetTextOrient( im, -1, -1, -1, 1 ) ) )
00124         return 1;
00125     if ( !( cdText( im, 600, 200, "CGM Draw" ) ) )
00126         return 1;
00127 
00128     // Text, 180 Degree Angle
00129     if ( !( cdSetTextOrient( im, 0, -1, -1, 0 ) ) )
00130         return 1;
00131     if ( !( cdText( im, 600, 200, "CGM Draw" ) ) )
00132         return 1;
00133 
00134     // Skewed Text, No Angle
00135     if ( !( cdSetTextOrient( im, 1, 1, 1, 0 ) ) )
00136     {
00137         return 1;
00138     }
00139     if ( !( cdSetTextAttrib( im, -1, -1, 40 ) ) )
00140     {
00141         return 1;
00142     }
00143     if ( !( cdText( im, 300, 300, "CGM Draw" ) ) )
00144     {
00145         return 1;
00146     }
00147     // show some lines around it
00148     if ( !( cdLine( im, 300, 300, 500, 300 ) ) )
00149         return 1;
00150     if ( !( cdLine( im, 300, 300, 340, 340 ) ) )
00151         return 1;
00152 
00153     // reset the text to 0 angle
00154     if ( !( cdSetTextOrient( im, 0, 1, 1, 0 ) ) )
00155         return 1;
00156 
00157 
00158     if ( !( cdSetTextAttrib( im, 5, -1, 20 ) ) )
00159         return 1;
00160     if ( !( cdText( im, 5, 5, "G. Edward Johnson" ) ) )
00161         return 1;
00162 
00163     // now write the file out, lets call it cdtext.cgm
00164     outf = fopen( "cdtext.cgm", "wb" );
00165     if ( !outf )
00166         return 1;
00167     cdImageCgm( im, outf );
00168     fclose( outf );
00169     outf = 0;
00170 
00171     // Remember to destroy the image when you are done
00172     cdImageDestroy( im );
00173     im = 0;
00174 
00175     printf( "CGM Text Example!!!\n" );
00176 
00177     return 0;
00178 }

Generated on Wed Oct 12 2011 20:42:21 for PLplot by  doxygen 1.7.1