public MatrixD(OTF2Dot14[,] tr, VecD shift) : this() { if (tr!=null) { if ((tr.GetLength(0)!=2)||(tr.GetLength(1)!=2)) { throw new ExceptionGMath("MatrixD","MatrixD",null); } for (int i=0;i<2;i++) for (int j=0;j<2;j++) { this.tr[i,j]=(double)tr[i,j]; } } else { this.tr[0,0]=this.tr[1,1]=1.0; this.tr[0,1]=this.tr[1,0]=0.0; } if (shift!=null) { this.tr[2,0]=shift.X; this.tr[2,1]=shift.Y; } }
public GErrComponentIncorrectTransform(int indGlyphOwner, int indGlyphComponent, OTF2Dot14[,] tr) : base(indGlyphOwner, indGlyphComponent) { // ValInfoBasic base.Name = "GERR_COMPONENT_INCORRECT_TRANSFORM"; // this if ((tr.GetLength(0)!=2)||(tr.GetLength(1)!=2)) { throw new ExceptionGlyph("GErrComponentIncorrectTransform","GErrComponentIncorrectTransform",null); } this.tr=new OTF2Dot14[2,2]; for (int i=0; i<2; i++) for (int j=0; j<2; j++) this.tr[i,j]=tr[i,j]; }
public void ReadGGC(int indexGlyph, out Composite comp, DIAction dia) { this.m_validator.DIA=dia; comp=null; GConsts.TypeGlyph typeGlyph; this.ReadTypeGlyph(indexGlyph, out typeGlyph, dia); if (typeGlyph!=GConsts.TypeGlyph.Composite) 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; uint offsCur=(uint)(offsStart+Table_glyf.FieldOffsets.nextAfterHeader); bool isLast=false; try { Component component; while (!isLast) { ushort flags=buffer.GetUshort(offsCur); isLast=((flags&(ushort)Table_glyf.MaskFlagComponent.MORE_COMPONENTS)==0); offsCur+=2; ushort indGlyphCur=buffer.GetUshort(offsCur); // TODO: save component=new Component(indGlyphCur); // TODO: validate indGlyph is in right boundaries // TODO: add Relations to FManager offsCur+=2; bool weHaveAScale=((flags&(ushort)Table_glyf.MaskFlagComponent.WE_HAVE_A_SCALE)!=0); bool weHaveAnXAndYScale=((flags&(ushort)Table_glyf.MaskFlagComponent.WE_HAVE_AN_X_AND_Y_SCALE)!=0); bool weHaveATwoByTwo=((flags&(ushort)Table_glyf.MaskFlagComponent.WE_HAVE_A_TWO_BY_TWO)!=0); int cnt=0; if (weHaveAScale) cnt++; if (weHaveAnXAndYScale) cnt++; if (weHaveATwoByTwo) cnt++; if (cnt>1) { this.m_validator.Error(T.T_NULL, E.glyf_E_CompositeAmbigousTransform, (OTTag)"glyf", "Index Component: "+indGlyphCur); return; } if ((flags&(ushort)Table_glyf.MaskFlagComponent.RESERVED)!=0) { this.m_validator.Warning(T.T_NULL, W.glyf_W_CompositeReservedBit, (OTTag)"glyf", "Index Component: "+indGlyphCur); } int arg1, arg2; if ((flags&(ushort)Table_glyf.MaskFlagComponent.ARG_1_AND_2_ARE_WORDS)!=0) { arg1=(int)buffer.GetShort(offsCur); offsCur+=2; arg2=(int)buffer.GetShort(offsCur); offsCur+=2; } else { arg1=(int)buffer.GetSbyte(offsCur); offsCur+=1; arg2=(int)buffer.GetSbyte(offsCur); offsCur+=1; } // TODO: validate bounding boxes // TODO: check that NOT BOTH shift & knots are initialized, but ONE of them IS initialized // TODO: validate that indKnots (both!) are in the right boundaries // TODO: validate that a single-point contour in any glyph is used as attachment point in at least one other glyph if ((flags&(ushort)Table_glyf.MaskFlagComponent.ARGS_ARE_XY_VALUES)!=0) { component.Shift=new VecD(arg1,arg2); } else { component.IndexKnotAttGlyph=arg1; component.IndexKnotAttComponent=arg2; } // TODO: check that matrix is non-degenerated (if not null) if (weHaveAScale) { OTF2Dot14[,] m=new OTF2Dot14[2,2]; m[0,0]=buffer.GetF2Dot14(offsCur); /* // for debug only - begin if (indGlyphCur==272) { m[0,0]=new OTF2Dot14(30390); } // for debug only - end */ offsCur+=2; m[1,1]=m[0,0]; component.TrOTF2Dot14=m; } else if (weHaveAnXAndYScale) { OTF2Dot14[,] m=new OTF2Dot14[2,2]; m[0,0]=buffer.GetF2Dot14(offsCur); offsCur+=2; m[1,1]=buffer.GetF2Dot14(offsCur); offsCur+=2; component.TrOTF2Dot14=m; } else if (weHaveATwoByTwo) { OTF2Dot14[,] m=new OTF2Dot14[2,2]; m[0,0]=buffer.GetF2Dot14(offsCur); offsCur+=2; m[0,1]=buffer.GetF2Dot14(offsCur); offsCur+=2; m[1,0]=buffer.GetF2Dot14(offsCur); offsCur+=2; m[1,1]=buffer.GetF2Dot14(offsCur); offsCur+=2; component.TrOTF2Dot14=m; } if ((flags&(ushort)Table_glyf.MaskFlagComponent.WE_HAVE_INSTRUCTIONS)!=0) { ushort numInstr=buffer.GetUshort(offsCur); offsCur+=2; if (offsCur+numInstr>buffer.GetLength()) { throw new System.IndexOutOfRangeException(); } } if (comp==null) comp=new Composite(); comp.AddComponent(component); } } catch (System.IndexOutOfRangeException) { this.m_validator.Error( E._GEN_E_OffsetExceedsTableLength, (OTTag)"glyf"); if (comp != null) { comp.ClearDestroy(); comp=null; } } }