Example #1
0
 public FontSW(FontDefinition fd, Image img)
 {
     fontDefinition = fd; image = img;
 }
Example #2
0
        public static FontDefinition Import(Image img, bool bVariableWidth)
        {
            using(Image.LockCache cache = img.LockReadonly()) {
                Softimage si = cache.Softimage;
                int bgcol = si.GetPixel(0, 0);

                int w, h;
                for(w = 1;w < si.w;w++)
                    if(bgcol == si.GetPixel(w, 1))
                        break;
                for(h = 1;h < si.h;h++)
                    if(bgcol == si.GetPixel(1, h))
                        break;
                w--;
                h--;

                int subsets = si.Height / ((h * 5) + 4);

                FontDefinition fd = new FontDefinition();
                fd.Height = h;
                int y = 0, x = 0;
                for(int i = 0;i < tbl.Length;i++) {
                    if(tbl[i] != 0) {
                        fd.characters[(int)tbl[i]].x = 1 + x * (w + 1);
                        fd.characters[(int)tbl[i]].y = 1 + y * (h + 1);
                        fd.characters[(int)tbl[i]].vx = 0;
                        fd.characters[(int)tbl[i]].vy = 0;
                        fd.characters[(int)tbl[i]].w = w;
                        fd.characters[(int)tbl[i]].h = h;
                        fd.characters[(int)tbl[i]].vw = w;
                        fd.characters[(int)tbl[i]].vh = h;
                    }
                    x++;
                    if(x == 20) { y++; x = 0; }
                }

                if(bVariableWidth) {
                    for(int i = 1;i < tbl.Length;i++) {
                        int zx;
                        for(zx = fd.characters[(int)tbl[i]].w - 1;zx >= 0;zx--) {
                            int zy;
                            for(zy = 0;zy < fd.characters[(int)tbl[i]].h;zy++) {
                                int pixel = si.GetPixel(fd.characters[(int)tbl[i]].x + zx, fd.characters[(int)tbl[i]].y + zy);
                                if((pixel & 0xFF000000) != 0)
                                    break;
                            }
                            if(zy != fd.characters[(int)tbl[i]].h)
                                break;
                        }
                        fd.characters[(int)tbl[i]].vw = zx + 1;
                    }
                }
                return fd;
            } //using softimagewrapper
        }
Example #3
0
        public static FontDefinition Import(Image img, char startChar)
        {
            using(Image.LockCache cache = img.LockReadonly()) {
                Softimage si = cache.Softimage;
                int col0 = si.GetPixel(0, 0);

                FontDefinition fd = new FontDefinition();
                fd.Height = si.Height-1;

                bool mode = false;
                int startx=0;
                int x = 0;
                while(x<si.Width) {
                    x++;
                    if(
                        (!mode && si.GetPixel(x, 0) != col0)
                        || (mode && si.GetPixel(x, 0) == col0)
                        ) {
                        mode = !mode;
                        //this is the first pixel of a new character
                        int idx = (int)startChar;
                        startChar++;
                        fd.characters[idx].x = startx;
                        fd.characters[idx].y = 1;
                        fd.characters[idx].vx = 0;
                        fd.characters[idx].vy = 0;
                        fd.characters[idx].w = x-startx;
                        fd.characters[idx].h = fd.Height;
                        fd.characters[idx].vw = x-startx;
                        fd.characters[idx].vh = fd.Height;
                        startx = x;
                    }
                }

                return fd;
            }
        }