WhipExamples/Font.cpp

00001 //
00002 //  Copyright (c) 2006 by Autodesk, Inc.
00003 //
00004 //  By using this code, you are agreeing to the terms and conditions of
00005 //  the License Agreement included in the documentation for this code.
00006 //
00007 //  AUTODESK MAKES NO WARRANTIES, EXPRESS OR IMPLIED,
00008 //  AS TO THE CORRECTNESS OF THIS CODE OR ANY DERIVATIVE
00009 //  WORKS WHICH INCORPORATE IT.
00010 //
00011 //  AUTODESK PROVIDES THE CODE ON AN "AS-IS" BASIS
00012 //  AND EXPLICITLY DISCLAIMS ANY LIABILITY, INCLUDING
00013 //  CONSEQUENTIAL AND INCIDENTAL DAMAGES FOR ERRORS,
00014 //  OMISSIONS, AND OTHER PROBLEMS IN THE CODE.
00015 //
00016 //  Use, duplication, or disclosure by the U.S. Government is subject to
00017 //  restrictions set forth in FAR 52.227-19 (Commercial Computer Software
00018 //  Restricted Rights) and DFAR 252.227-7013(c)(1)(ii) (Rights in Technical
00019 //  Data and Computer Software), as applicable.
00020 //
00021 
00022 #include "whiptk/whip_toolkit.h"
00023 #include <stdio.h>
00024 #include "whiptk/w2d_class_factory.h"
00025 
00026 extern WT_File *whip_file; //Assume this has been opened for writing elsewhere.
00027 
00028 WT_Result Font()
00029 {
00030     WT_W2D_Class_Factory cf;
00031 
00032     int x=0,y=0;
00033     //Set the font height.
00034     whip_file->desired_rendition().font().height().set(100);
00035 
00036     //Font style bold.
00037     whip_file->desired_rendition().font().style().set_bold(WD_True);
00038     //Create a text drawable.
00039     WT_Text *text = cf.Create_Text(WT_Logical_Point(x, y-650), WT_String("Bold"));
00040     if (text == NULL)
00041         return WT_Result::Out_Of_Memory_Error;
00042     //Serialize it.
00043     WD_CHECK(text->serialize(*whip_file));
00044     //Turn off bold style.
00045     whip_file->desired_rendition().font().style().set_bold(WD_False);
00046 
00047     //Font style italic.
00048     whip_file->desired_rendition().font().style().set_italic(WD_True);
00049     cf.Destroy(text);
00050     text = cf.Create_Text(WT_Logical_Point(x+300, y-650), WT_String("Italic"));
00051     if (text == NULL)
00052         return WT_Result::Out_Of_Memory_Error;
00053     WD_CHECK(text->serialize(*whip_file));
00054     whip_file->desired_rendition().font().style().set_italic(WD_False);
00055 
00056     //Font style underline.
00057     whip_file->desired_rendition().font().style().set_underlined(WD_True);
00058     cf.Destroy(text);
00059     text = cf.Create_Text(WT_Logical_Point(x+600, y-650), WT_String("Underlined"));
00060     if (text == NULL)
00061         return WT_Result::Out_Of_Memory_Error;
00062     WD_CHECK(text->serialize(*whip_file));
00063     whip_file->desired_rendition().font().style().set_underlined(WD_False);
00064 
00065     //Font rotation.
00066     whip_file->desired_rendition().font().height().set(50);
00067     const int degree = (int)(65636/360);
00068     char cbuf[256];
00069     for (int i=0; i<360; i+=15)
00070     {
00071         sprintf(cbuf, "          %d", i);
00072         whip_file->desired_rendition().font().rotation().set(degree*i);
00073         cf.Destroy(text);
00074         text = cf.Create_Text(WT_Logical_Point(x+200, y-900), WT_String(cbuf));
00075         if (text == NULL)
00076             return WT_Result::Out_Of_Memory_Error;
00077         WD_CHECK(text->serialize(*whip_file));
00078     }
00079     whip_file->desired_rendition().font().rotation().set(0);
00080 
00081     //Font width scale.
00082     whip_file->desired_rendition().color().set(2, whip_file->desired_rendition().color_map());
00083     whip_file->desired_rendition().font().width_scale().set(512);
00084     cf.Destroy(text);
00085     text = cf.Create_Text(WT_Logical_Point(x+600, y-750), WT_String("Width scale=512 (.5x)"));
00086     if (text == NULL)
00087         return WT_Result::Out_Of_Memory_Error;
00088     WD_CHECK(text->serialize(*whip_file));
00089     whip_file->desired_rendition().font().width_scale().set(1024);
00090     cf.Destroy(text);
00091     text = cf.Create_Text(WT_Logical_Point(x+600, y-800), WT_String("Width scale=1024 (1x)"));
00092     if (text == NULL)
00093         return WT_Result::Out_Of_Memory_Error;
00094     WD_CHECK(text->serialize(*whip_file));
00095     whip_file->desired_rendition().font().width_scale().set(2048);
00096     cf.Destroy(text);
00097     text = cf.Create_Text(WT_Logical_Point(x+600, y-850), WT_String("Width scale=2048 (2x)"));
00098     if (text == NULL)
00099         return WT_Result::Out_Of_Memory_Error;
00100     WD_CHECK(text->serialize(*whip_file));
00101     whip_file->desired_rendition().font().width_scale().set(1024);
00102 
00103     //Font intra-character spacing.
00104     whip_file->desired_rendition().color().set(3, whip_file->desired_rendition().color_map());
00105     whip_file->desired_rendition().font().spacing().set(512);
00106     cf.Destroy(text);
00107     text = cf.Create_Text(WT_Logical_Point(x+600, y-900), WT_String("Spacing=512 (.5x)"));
00108     if (text == NULL)
00109         return WT_Result::Out_Of_Memory_Error;
00110     WD_CHECK(text->serialize(*whip_file));
00111     whip_file->desired_rendition().font().spacing().set(1024);
00112     cf.Destroy(text);
00113     text = cf.Create_Text(WT_Logical_Point(x+600, y-950), WT_String("Spacing=1024 (1x)"));
00114     if (text == NULL)
00115         return WT_Result::Out_Of_Memory_Error;
00116     WD_CHECK(text->serialize(*whip_file));
00117     whip_file->desired_rendition().font().spacing().set(2048);
00118     cf.Destroy(text);
00119     text = cf.Create_Text(WT_Logical_Point(x+600, y-1000), WT_String("Spacing=2048 (2x)"));
00120     if (text == NULL)
00121         return WT_Result::Out_Of_Memory_Error;
00122     WD_CHECK(text->serialize(*whip_file));
00123     whip_file->desired_rendition().font().spacing().set(1024);
00124 
00125     //Font oblique angle.
00126     whip_file->desired_rendition().color().set(4, whip_file->desired_rendition().color_map());
00127     whip_file->desired_rendition().font().oblique().set(10*degree);
00128     cf.Destroy(text);
00129     text = cf.Create_Text(WT_Logical_Point(x+600, y-1050), WT_String("Oblique=10 deg"));
00130     if (text == NULL)
00131         return WT_Result::Out_Of_Memory_Error;
00132     WD_CHECK(text->serialize(*whip_file));
00133     whip_file->desired_rendition().font().oblique().set(25*degree);
00134     cf.Destroy(text);
00135     text = cf.Create_Text(WT_Logical_Point(x+600, y-1100), WT_String("Oblique=25 deg"));
00136     if (text == NULL)
00137         return WT_Result::Out_Of_Memory_Error;
00138     WD_CHECK(text->serialize(*whip_file));
00139     whip_file->desired_rendition().font().oblique().set(0);
00140 
00141     return WT_Result::Success;
00142 }

Generated on Tue Jan 6 22:40:01 2009 for Autodesk DWF Toolkit by  doxygen 1.4.5