Path: utzoo!attcan!uunet!hsi!genly!chris Newsgroups: comp.sys.amiga.tech Subject: LongText() Message-ID: Date: 31 Jul 90 14:29:47 GMT Organization: Eggplant Software Tools, New Haven, Ct. Lines: 183 I have a very odd problem with LongText(), the code below. I'm writing to a bitmap 1728 pixels wide. The normal Text() function can't handle this. It seems to be unable to write to bitmaps wider than about 976 pixels, it truncates. So I wrote LongText(). Longtext() works by breaking the input string into sections that are are rendered in less than a 976 pixel width. Each section is drawn using Text() and a bitmap which is overlayed on the original bitmap. Each time Text() is called, the start of the overlay bitmap is moved to where the Text() function finished drawing the previous time. (Observing the restriction that the bitmap start on a 16 bit boundary and be an even number of bytes long.) This function works most of the time. Out of the hundreds of lines of text I've rendered, the one below is the only one to have a problem. The string is rendered in 3 parts. The first and third parts are fine. The second part causes streaks to be written to the workbench screen. I've tried several techniques, they all have the same problem. This is the most conservative technique I've tried. I tried to eliminate the effect of any optimizations the Text() routine might make, by initing the rastport every time it is used. A log of the output is shown after the function listing. An interesting result of one of my experiments is everything works if I never allow the x value to be zero for any section except the first. I'm baffled. Any help would be appreciated. Thanks in advance. Environment: Amiga 2000HD, 1 meg chip, 2 meg fast Lattice Version 5.04 C compiler Workbench 1.3.2 Inputs: Raster = Points to an initialized rastport writing to a bitmap 1728 pixels wide. string="failed because of any error not setting errno. " PixMax = 1668 count = 47 /* * This function replaces the Text() function. It works with bitmaps * longer than 976 pixels. The line is truncated on a character basis * to fit within the bitmap. */ #include #include #include #include #include #include "longrast.h" #include "log.h" #define DOING 20 int LongText( struct RastPort *Raster, char *string, int count, int PixMax ) { int i, words, doing, done, left; int depth = Raster->BitMap->Depth; int len; int x, y; int truncated = FALSE; static struct RastPort Raster_, *Raster2 = &Raster_; static struct BitMap BitMap_, *BitMap2 = &BitMap_; Raster2->cp_x = Raster->cp_x; Raster2->cp_y = Raster->cp_y; *BitMap2 = *Raster->BitMap; /* Write doing characters at a time */ for(done=0; done != count && !truncated; done += doing) { /* doing: the number of chars to write during this pass */ left = count - done; doing = DOING; if (left < doing) doing = left; /* * Normalize the Raster port to move the start of the plane as * close to the word occupied by the current (cp_x, cp_y). */ x = Raster2->cp_x; y = Raster2->cp_y; InitRastPort(Raster2); Raster2->BitMap = BitMap2; words = x/16; #ifdef whats_going_on /* * If I dont have this, streaks are written to the * workbench screen!! This code just prevents the * new x from being 0. */ if (words != 0 && words*16 == x) words--; #endif for(i=0; iBitMap->Planes[i] += words*2; SetFont(Raster2, Raster->Font); SetAPen(Raster2, Raster->FgPen); SetBPen(Raster2, Raster->BgPen); SetDrMd(Raster2, Raster->DrawMode); Move(Raster2, x - words*16, y); /* * Truncate the line so it doesn't go out of the bitmap */ while(doing >= 0) { len = TextLength(Raster2, string+done, doing) + (Raster2->BitMap->Planes[0]-Raster->BitMap->Planes[0])*8 + Raster->cp_x; Log_Print("LongText: len = %d PixMax = %d\n", len, PixMax); if (len < PixMax) break; Log_Print("Too long, shortening\n"); --doing; --count; truncated = TRUE; } Log_Print("before x=%d y=%d plane[0]=0x%08x\n", Raster2->cp_x, Raster2->cp_y, Raster2->BitMap->Planes[0]); Log_Print("doing=%d s='%s'\n", doing, string+done); Text(Raster2, string+done, doing); Log_Print("after x=%d y=%d plane[0]=0x%08x\n", Raster2->cp_x, Raster2->cp_y, Raster2->BitMap->Planes[0]); } /* * Update the original raster port */ Raster->cp_x = (Raster2->BitMap->Planes[0]-Raster->BitMap->Planes[0])*8 + Raster2->cp_x, y; return done; } logfile with arithmetic notes: [3.850] LongText: len = 224 PixMax = 1668 [3.983] before x=0 y=11 plane[0]=0x00016a98 [4.066] doing=20 s='failed because of any error not setting errno. ' [4.183] after x=224 y=11 plane[0]=0x00016a98 224/16 = 14 rem 0 2*14 = 28 = 0x1c 0x16a98 + 0x1c = 0x16ab4 [4.266] LongText: len = 457 PixMax = 1668 [4.333] before x=0 y=11 plane[0]=0x00016ab4 [4.416] doing=20 s='y error not setting errno. ' [4.500] after x=233 y=11 plane[0]=0x00016ab4 233/16 = 14 rem 9 2*14 = 28 = 0x1c 0x16ab4 + 0x1a = 0x16ad0 [4.600] LongText: len = 528 PixMax = 1668 [4.666] before x=9 y=11 plane[0]=0x00016ad0 [4.750] doing=7 s='errno. ' [4.833] after x=89 y=11 plane[0]=0x00016ad0 ------------------------------------------------------- Chris Hind Genly (KC1VP) UUCP: uunet!hsi!genly!chris 95 Fountain Terr, New Haven, Ct., 06515 (203) 389-8680