home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Exec 3 / CD_Magazyn_EXEC_nr_3.iso / Recent / misc / edu / WhirlDisc.lha / WhirlDisc / Source / paragraph.c < prev    next >
C/C++ Source or Header  |  2000-08-11  |  2KB  |  104 lines

  1. /*
  2.  
  3. File: paragraph.c
  4. Author: Neil Cafferkey
  5. Copyright (C) 2000 Neil Cafferkey
  6.  
  7. This program is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU General Public License
  9. as published by the Free Software Foundation; either version 2
  10. of the License, or (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 59 Temple Place - Suite 330, Boston,
  20. MA 02111-1307, USA.
  21.  
  22. */
  23.  
  24. #include "viewer.h"
  25. #include <exec/memory.h>
  26.  
  27. #include "paragraph_protos.h"
  28. #include "general_protos.h"
  29.  
  30.  
  31.  
  32. /* Function: CreateParagraph
  33.  * =========================
  34.  * Creates a Paragraph.
  35.  */
  36.  
  37. Paragraph CreateParagraph(UBYTE *raw_paragraph,UWORD length)
  38. {
  39.    Paragraph paragraph;
  40.  
  41.    if((paragraph=(Paragraph)AllocMem(sizeof(Paragraph_imp),MEMF_ANY))!=NULL)
  42.    {
  43.  
  44.       paragraph->text=raw_paragraph;
  45.       paragraph->length=length;
  46.  
  47.    }
  48.    else
  49.    {
  50.       ReportError(NULL,ERROR_REPORT_MEM,NULL,0);
  51.    }
  52.  
  53.    return paragraph;
  54. }
  55.  
  56.  
  57. /* Function: FitParagraphLine
  58.  * ==========================
  59.  * Calculates the number of characters that will fit on a line of a given
  60.  * pixel width.
  61.  */
  62.  
  63. UWORD FitParagraphLine(Paragraph paragraph,struct Window *window,
  64.    UWORD offset)
  65. {
  66.    struct TextExtent temp_extent;
  67.    ULONG char_count;
  68.    UBYTE *p,*q=paragraph->text;
  69.  
  70.    char_count=TextFit(window->RPort,paragraph->text+offset,
  71.       paragraph->length-offset,&temp_extent,NULL,1,window->GZZWidth
  72.       -MARGIN_WIDTH*2,32767);
  73.  
  74. /*
  75. printf("FitParagraphLine:offset=%u\n",offset);
  76. printf("FitParagraphLine:paragraph->length=%u\n",paragraph->length);
  77. printf("FitParagraphLine:window->Width=%u\n",window->Width);
  78. */
  79.  
  80.    /* Find the last space in the fitted substring */
  81.  
  82.    if(offset+char_count!=paragraph->length)
  83.    {
  84.       for(p=paragraph->text+offset+char_count;(p>q)&&(*p!=' ');p--)
  85.          char_count--;
  86.    }
  87. /*printf("FitParagraphLine:char_count=%u\n",char_count);*/
  88.  
  89.    return char_count;
  90. }
  91.  
  92.  
  93. /* Function: KillParagraph
  94.  * =======================
  95.  * Destroys a paragraph.
  96.  */
  97.  
  98. VOID KillParagraph(Paragraph paragraph)
  99. {
  100.    FreeMem(paragraph,sizeof(Paragraph_imp));
  101. }
  102.  
  103.  
  104.