textdisplay.c

Go to the documentation of this file.
00001 
00002 /*  $Id: textdisplay.c 355 2005-01-11 22:48:55Z andreradke $    */
00003 
00004 /******************************************************************************
00005 
00006     UserLand Frontier(tm) -- High performance Web content management,
00007     object database, system-level and Internet scripting environment,
00008     including source code editing and debugging.
00009 
00010     Copyright (C) 1992-2004 UserLand Software, Inc.
00011 
00012     This program is free software; you can redistribute it and/or modify
00013     it under the terms of the GNU General Public License as published by
00014     the Free Software Foundation; either version 2 of the License, or
00015     (at your option) any later version.
00016 
00017     This program is distributed in the hope that it will be useful,
00018     but WITHOUT ANY WARRANTY; without even the implied warranty of
00019     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020     GNU General Public License for more details.
00021 
00022     You should have received a copy of the GNU General Public License
00023     along with this program; if not, write to the Free Software
00024     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 
00026 ******************************************************************************/
00027 
00028 #include "frontier.h"
00029 #include "standard.h"
00030 
00031 #include "quickdraw.h"
00032 #include "font.h"
00033 #include "smallicon.h"
00034 #include "textdisplay.h"
00035 
00036 
00037 #define horizinset 0
00038 #define vertinset 0
00039 
00040 
00041 
00042 
00043 void gettextdisplayinfo (Rect r, short fontnum, short fontsize, short fontstyle, tylinespacing spacing, short horizscrollunit, tytextdisplayinfo *info) {
00044 
00045     /*
00046     this is a central bottleneck -- anyone who wants to know where lines
00047     are, how big they are, how big the display is, etc, calls this 
00048     routine.  the displayinfo field of the outline record is filled.
00049     
00050     we establish the display size and the position for the first line
00051     of text, also the height of each line.
00052     
00053     we add a little extra space above each line to balance the space
00054     that's left when most characters don't descend.  makes the display
00055     look more balanced, but the coding is a little wierd...
00056     */
00057     
00058     register short r1, r2, r3; /*registers that get re-used*/
00059     tytextdisplayinfo displayinfo;
00060     
00061     displayinfo.r = r;
00062     
00063     insetrect (&displayinfo.r, horizinset, vertinset);
00064     
00065     pushstyle (fontnum, fontsize, fontstyle);
00066     
00067     r1 = globalfontinfo.ascent + globalfontinfo.descent;
00068     
00069     r2 = globalfontinfo.descent;
00070     
00071     r3 = r1 + r2;
00072     
00073     switch (spacing) {
00074         
00075         case singlespaced:
00076             break;
00077         
00078         case oneandalittlespaced:
00079             r3 += 1; break;
00080     
00081         case oneandaquarterspaced:
00082             r3 += (r3 / 4); break;
00083             
00084         case oneandahalfspaced:
00085             r3 += (r3 / 2); break;
00086             
00087         case doublespaced:
00088             r3 *= 2; break;
00089             
00090         case triplespaced:
00091             r3 *= 3; break;
00092         
00093         } /*switch*/
00094     
00095     r3 = max (r3, heightsmallicon - 2); /*make sure it can handle an icon (almost)*/
00096         
00097     displayinfo.lh = r3;
00098     
00099     displayinfo.v = displayinfo.r.top + globalfontinfo.ascent + r2;
00100     
00101     displayinfo.h = displayinfo.r.left;
00102     
00103     r1 = displayinfo.r.bottom - displayinfo.r.top;
00104     
00105     displayinfo.screenlines = r1 / r3;
00106     
00107     r2 = r1 - (displayinfo.screenlines * r3); /*number of extra pixels*/
00108     
00109     r1 = r2 / 2; /*number of pixels added at top of display rectangle*/
00110     
00111     displayinfo.r.top += r1;
00112     
00113     displayinfo.v += r1;
00114     
00115     displayinfo.r.bottom -= r2 - r1; /*subtract the complementary number of pixels from bottom*/
00116     
00117     displayinfo.horizscrollpixels = horizscrollunit;
00118     
00119     popstyle ();
00120     
00121     *info = displayinfo;    
00122     } /*gettextdisplayinfo*/
00123     
00124 

Generated on Wed May 31 18:20:03 2006 for frontierkernel 10.1.10a by  doxygen 1.4.6