예제 #1
0
 public Contour(Contour cont):
     this()
 {
     if (cont==null)
     {
         throw new ExceptionGMath("Contour","Contour","Null argument");
     }
     Knot knCopy;
     foreach (Knot kn in cont.knots)
     {
         knCopy=new Knot(kn);
         this.knots.Add(knCopy);
     }
 }
예제 #2
0
 public Outline(Outline outl):
     this()
 {
     if (outl==null)
     {
         throw new ExceptionGMath("Outline","Outline",null);
     }
     Contour contCopy;
     foreach (Contour cont in this.conts)
     {
         contCopy=new Contour(cont);
         this.conts.Add(contCopy);
     }
     this.isChangedByRound=outl.IsChangedByRound;
 }
예제 #3
0
        public bool AreDuplicatedComponents(Component componentA,
                                            Component componentB,
                                            out bool areDuplicated)
        {
            areDuplicated = false;
            if ((componentA == null) || (componentB == null))
            {
                throw new ExceptionGMath("Outline", "AreDuplicatedComponents", null);
                //return false;
            }

            if (componentA == componentB)
            {
                return(true);
            }
            for (int pozContA = componentA.PozContStart;
                 pozContA < componentA.PozContStart + componentA.NumCont;
                 pozContA++)
            {
                Contour contA = this.ContourByPoz(pozContA);
                for (int pozContB = componentB.PozContStart;
                     pozContB < componentB.PozContStart + componentB.NumCont;
                     pozContB++)
                {
                    Contour contB = this.ContourByPoz(pozContB);
                    bool    areDuplicatedCont;
                    contA.AreDuplicated(contB, out areDuplicatedCont);
                    if (!areDuplicatedCont)
                    {
                        return(true);
                    }
                }
            }
            areDuplicated = true;
            return(true);
        }
예제 #4
0
 public bool AreDuplicated(Contour cont, out bool isDupl)
 {
     isDupl=true;
     if (cont==null)
     {
         throw new ExceptionGMath("Contour","AreDuplicated",null);
         //return false;
     }
     if (this.NumKnot!=cont.NumKnot)
     {
         isDupl=false;
         return true;
     }
     int numKnot=this.NumKnot;
     int pozA=0, pozB;
     for (pozB=0; pozB<numKnot; pozB++)
     {
         if (cont.KnotByPoz(pozB).Val==this.KnotByPoz(0).Val)
             break;
     }
     if (pozB==numKnot)
     {
         isDupl=false;
         return true;
     }
     int iKnot;
     for (iKnot=0; iKnot<numKnot; iKnot++)
     {
         if (this.KnotByPoz(pozA).Val!=cont.KnotByPoz(pozB).Val)
             break;
         pozA=this.PozNext(pozA);
         pozB=cont.PozNext(pozB);
     }
     if (iKnot!=numKnot)
     {
         isDupl=false;
         return true;
     }
     return true; // contours are DUPLICATED
 }
예제 #5
0
        public bool Intersect(Contour cont, ListInfoInters linters)
        {
            Contour contA=this;
            Contour contB=cont;
            if (contA==contB)
            {
                return this.Intersect(linters);
            }
            BoxD bboxContA=contA.BBox;
            BoxD bboxContB=contB.BBox;
            if (!bboxContA.HasInters(bboxContB))
                return true;

            for (int pozA=0; pozA<contA.NumKnot; pozA++)
            {
                Knot knA=contA.KnotByPoz(pozA);
                BCurve curveA=contA.CurveByPoz(pozA);
                if (curveA!=null)
                {    
                    BoxD bboxCurveA=curveA.BBox;
                    if (bboxCurveA.HasInters(bboxContB))
                    {
                        for (int pozB=0; pozB<contB.NumKnot; pozB++)
                        {
                            BCurve curveB=contB.CurveByPoz(pozB);
                            if (curveB!=null)
                            {
                                int numIntersBefore=linters.Count;
                                Inters.IntersectBB(curveA, curveB, null, null, linters);
                                Knot knB=contB.KnotByPoz(pozB);
                                linters.ParamToCParam(knA,knB,numIntersBefore);
                            }
                        }
                    }
                }
            }

            contA=null;
            contB=null;
            return true;
        }
예제 #6
0
 public bool OutlineAdd(Outline outl, MatrixD trD)
 {
     if ((outl==null)||(trD==null))
     {
         throw new ExceptionGMath("Outline","OutlineAdd",null);
         //return false;
     }
     for (int pozCont=0; pozCont<outl.NumCont; pozCont++)
     {
         Contour cont=new Contour(outl.ContourByPoz(pozCont));
         cont.Transform(trD);
         this.ContourAdd(cont);
     }
     this.ReNumber();
     return true;
 }
예제 #7
0
 public void ContourDelete(Contour cont)
 {
     // TODO: ReNumber ???
     if (cont!=null)
     {
         if (this.conts.Contains(cont))
         {
             this.conts.Remove(cont);
         }
     }
 }
예제 #8
0
 public void ContourAdd(Contour cont)
 {
     // TODO: ReNumber ???
     if (cont!=null)
     {
         this.conts.Add(cont);
     }
 }
예제 #9
0
        public void ReadGGO(int indexGlyph, 
            out Outline outl, 
            DIAction dia)
        {
            this.m_validator.DIA=dia;
            outl=null;
            
            GConsts.TypeGlyph typeGlyph;
            this.ReadTypeGlyph(indexGlyph, out typeGlyph, dia);
            if (typeGlyph!=GConsts.TypeGlyph.Simple)
                return;
            int offsStart, length;
            if (!this.m_tableLoca.GetValidateEntryGlyf(indexGlyph,
                out offsStart, out length, this.m_validator, this.m_font))
                return;
            MBOBuffer buffer=this.m_tableGlyf.Buffer;
            int iKnot;
            ushort[] arrIndKnotEnd;
            short[] arrXRel, arrYRel;
            byte[] arrFlag;
            int numCont;
            try 
            {
                numCont=buffer.GetShort((uint)(offsStart+(int)Table_glyf.FieldOffsets.numCont));
                arrIndKnotEnd = new ushort [numCont];
                for (short iCont=0; iCont<numCont; iCont++)
                {
                    arrIndKnotEnd[iCont]=buffer.GetUshort((uint)(offsStart+Table_glyf.FieldOffsets.nextAfterHeader+iCont*2));
                }
                int numKnot=arrIndKnotEnd[numCont-1]+1;
                uint offsInstrLength=(uint)(offsStart+Table_glyf.FieldOffsets.nextAfterHeader+2*numCont);
                ushort lengthInstr=buffer.GetUshort(offsInstrLength);
                uint offsInstr=offsInstrLength+2;
                uint offsFlag=offsInstr+lengthInstr;
                arrFlag = new byte [numKnot];
                iKnot=0;                    // index of flag in array flags
                uint offsCur=offsFlag;        // counter of flag in the file
                while (iKnot<numKnot)
                {
                    byte flag=buffer.GetByte(offsCur++);
                    arrFlag[iKnot++]=flag;
                    bool toRepeat=((flag&(byte)(Table_glyf.MaskFlagKnot.toRepeat))!=0);
                    if (toRepeat)
                    {
                        byte numRepeat=buffer.GetByte(offsCur++);
                        for (byte iRepeat=0; iRepeat<numRepeat; iRepeat++)
                        {
                            arrFlag[iKnot++]=flag;
                        }
                    }
                }
                arrXRel = new short [numKnot];
                arrYRel = new short [numKnot];
                // read data for x-coordinates
                for (iKnot=0; iKnot<numKnot; iKnot++)
                {
                    if ((arrFlag[iKnot]&(byte)(Table_glyf.MaskFlagKnot.isXByte))!=0)
                    {
                        byte xRel=buffer.GetByte(offsCur++);
                        if ((arrFlag[iKnot]&(byte)(Table_glyf.MaskFlagKnot.isXSameOrPozitive))!=0)
                        {
                            arrXRel[iKnot]=xRel;
                        }
                        else
                        {
                            arrXRel[iKnot]=(short)(-xRel);
                        }
                    }
                    else
                    {
                        if ((arrFlag[iKnot]&(byte)(Table_glyf.MaskFlagKnot.isXSameOrPozitive))!=0)
                        {
                            arrXRel[iKnot]=0;
                        }
                        else
                        {
                            arrXRel[iKnot]=buffer.GetShort(offsCur);
                            offsCur+=2;
                        }
                    }
                }
                // read data for y-coordinates
                for (iKnot=0; iKnot<numKnot; iKnot++)
                {
                    if ((arrFlag[iKnot]&(byte)(Table_glyf.MaskFlagKnot.isYByte))!=0)
                    {
                        byte yRel=buffer.GetByte(offsCur++);
                        if ((arrFlag[iKnot]&(byte)(Table_glyf.MaskFlagKnot.isYSameOrPozitive))!=0)
                        {
                            arrYRel[iKnot]=yRel;
                        }
                        else
                        {
                            arrYRel[iKnot]=(short)(-yRel);
                        }
                    }
                    else
                    {
                        if ((arrFlag[iKnot]&(byte)(Table_glyf.MaskFlagKnot.isYSameOrPozitive))!=0)
                        {
                            arrYRel[iKnot]=0;
                        }
                        else
                        {
                            arrYRel[iKnot]=buffer.GetShort(offsCur);
                            offsCur+=2;
                        }
                    }
                }
                if (offsCur-2>=offsStart+length)
                {
                    throw new System.IndexOutOfRangeException();
                }
            }
            catch (System.IndexOutOfRangeException) 
            {
                this.m_validator.Error(
                    E._GEN_E_OffsetExceedsTableLength,
                    (OTTag)"glyf");
                return;
            }

            try
            {
                short xAbs=0;
                short yAbs=0;
                int indKnotStart, indKnotEnd=-1;
                outl=new Outline();
                for (ushort iCont=0; iCont<numCont; iCont++)
                {
                    indKnotStart=indKnotEnd+1;
                    indKnotEnd=arrIndKnotEnd[iCont];
                    Contour cont=null;
                    cont = new Contour();
                    for (iKnot=indKnotStart; iKnot<=indKnotEnd; iKnot++)
                    {
                        xAbs += arrXRel[iKnot];
                        yAbs += arrYRel[iKnot];
                        bool isOn=((arrFlag[iKnot]&((byte)(Table_glyf.MaskFlagKnot.isOnCurve)))!=0);
                        Knot knot = new Knot(iKnot, xAbs, yAbs, isOn);
                        cont.KnotAdd(knot);
                    }
                    outl.ContourAdd(cont);
                }
            }
            catch
            {
                outl.ClearDestroy();
                outl=null;
            }
        }