private void treasure(string name, int level, string foreColour, int price) { var localGlyph = _glyph.Clone() as Glyph; localGlyph.Fore = foreColour; item(name, level, localGlyph, treasure: true, price: price); }
public IEnumerable <IGlyphSelection> GetGlyphCombination() { var hexGlyphs = this.Glyphs.Where(g => g.Shape == Shape.Hex).ToArray(); var leafGlyphs = this.Glyphs.Where(g => g.Shape == Shape.Leaf).ToArray();; var squareGlyphs = this.Glyphs.Where(g => g.Shape == Shape.Square).ToArray();; if (hexGlyphs.Count() < 2) { throw new ApplicationException("Not enough hex glyphs"); } if (leafGlyphs.Count() < 2) { throw new ApplicationException("Not enough leaf glyphs"); } if (squareGlyphs.Count() < 2) { throw new ApplicationException("Not enough square glyphs"); } Glyph[] glyphs = new Glyph[6]; for (int i = 0; i < hexGlyphs.Count() - 1; i++) { glyphs[0] = hexGlyphs[i]; for (int j = i + 1; j < hexGlyphs.Count(); j++) { glyphs[1] = hexGlyphs[j]; for (int k = 0; k < leafGlyphs.Count() - 1; k++) { glyphs[2] = leafGlyphs[k]; for (int l = k + 1; l < leafGlyphs.Count(); l++) { glyphs[3] = leafGlyphs[l]; for (int m = 0; m < squareGlyphs.Count() - 1; m++) { glyphs[4] = squareGlyphs[m]; for (int n = m + 1; n < squareGlyphs.Count(); n++) { glyphs[5] = squareGlyphs[n]; //Si paralellism, cloner les objets yield return(new Selection() { Glyphs = (Glyph[])glyphs.Clone() }); } } } } } } }
public void Draw(SpriteBatch spriteBatch) { if (Bounds.Contains(Main.mouseX, Main.mouseY)) { Main.LocalPlayer.mouseInterface = true; Main.HoverItem = Glyph.Clone(); if (Main.mouseLeft && Main.mouseLeftRelease) { AttemptPlace(); } } if (Glyph.type == 0) { return; } Texture2D texture = Main.itemTexture[Glyph.type]; spriteBatch.Draw(texture, Bounds.TopLeft() + new Vector2(2f, 2f), Color.White, scale()); }
static Glyph ReadCompositeGlyph(Glyph[] createdGlyhps, BinaryReader reader, int contourCount, Bounds bounds) { //------------------------------------------------------ //https://www.microsoft.com/typography/OTSPEC/glyf.htm //Composite Glyph Description //This is the table information needed for composite glyphs (numberOfContours is -1). //A composite glyph starts with two USHORT values (“flags” and “glyphIndex,” i.e. the index of the first contour in this composite glyph); //the data then varies according to “flags”). //Type Name Description //USHORT flags component flag //USHORT glyphIndex glyph index of component //VARIABLE argument1 x-offset for component or point number; type depends on bits 0 and 1 in component flags //VARIABLE argument2 y-offset for component or point number; type depends on bits 0 and 1 in component flags //--------- //see more at https://fontforge.github.io/assets/old/Composites/index.html //--------- Glyph finalGlyph = null; CompositeGlyphFlags flags; do { flags = (CompositeGlyphFlags)reader.ReadUInt16(); ushort glyphIndex = reader.ReadUInt16(); Glyph newGlyph = Glyph.Clone(createdGlyhps[glyphIndex]); short arg1 = 0; short arg2 = 0; ushort arg1and2 = 0; if (HasFlag(flags, CompositeGlyphFlags.ARG_1_AND_2_ARE_WORDS)) { arg1 = reader.ReadInt16(); arg2 = reader.ReadInt16(); } else { byte a1 = reader.ReadByte(); byte a2 = reader.ReadByte(); arg1and2 = (ushort)((a1 << 8) | a2); } //----------------------------------------- float xscale = 1; float scale01 = 0; float scale10 = 0; float yscale = 1; bool useMatrix = false; //----------------------------------------- bool hasScale = false; if (HasFlag(flags, CompositeGlyphFlags.WE_HAVE_A_SCALE)) { //If the bit WE_HAVE_A_SCALE is set, //the scale value is read in 2.14 format-the value can be between -2 to almost +2. //The glyph will be scaled by this value before grid-fitting. xscale = yscale = ((float)reader.ReadInt16()) / (1 << 14); /* Format 2.14 */ hasScale = true; } else if (HasFlag(flags, CompositeGlyphFlags.WE_HAVE_AN_X_AND_Y_SCALE)) { xscale = ((float)reader.ReadInt16()) / (1 << 14); /* Format 2.14 */ yscale = ((float)reader.ReadInt16()) / (1 << 14); /* Format 2.14 */ hasScale = true; } else if (HasFlag(flags, CompositeGlyphFlags.WE_HAVE_A_TWO_BY_TWO)) { //The bit WE_HAVE_A_TWO_BY_TWO allows for linear transformation of the X and Y coordinates by specifying a 2 × 2 matrix. //This could be used for scaling and 90-degree*** rotations of the glyph components, for example. //2x2 matrix //The purpose of USE_MY_METRICS is to force the lsb and rsb to take on a desired value. //For example, an i-circumflex (U+00EF) is often composed of the circumflex and a dotless-i. //In order to force the composite to have the same metrics as the dotless-i, //set USE_MY_METRICS for the dotless-i component of the composite. //Without this bit, the rsb and lsb would be calculated from the hmtx entry for the composite //(or would need to be explicitly set with TrueType instructions). //Note that the behavior of the USE_MY_METRICS operation is undefined for rotated composite components. useMatrix = true; hasScale = true; xscale = ((float)reader.ReadInt16()) / (1 << 14); /* Format 2.14 */ scale01 = ((float)reader.ReadInt16()) / (1 << 14); /* Format 2.14 */ scale10 = ((float)reader.ReadInt16()) / (1 << 14); /* Format 2.14 */ yscale = ((float)reader.ReadInt16()) / (1 << 14); /* Format 2.14 */ if (HasFlag(flags, CompositeGlyphFlags.UNSCALED_COMPONENT_OFFSET)) { } else { } if (HasFlag(flags, CompositeGlyphFlags.USE_MY_METRICS)) { } } //-------------------------------------------------------------------- if (HasFlag(flags, CompositeGlyphFlags.ARGS_ARE_XY_VALUES)) { //Argument1 and argument2 can be either x and y offsets to be added to the glyph or two point numbers. //x and y offsets to be added to the glyph //When arguments 1 and 2 are an x and a y offset instead of points and the bit ROUND_XY_TO_GRID is set to 1, //the values are rounded to those of the closest grid lines before they are added to the glyph. //X and Y offsets are described in FUnits. if (useMatrix) { //use this matrix Glyph.TransformNormalWith2x2Matrix(newGlyph, xscale, scale01, scale10, yscale); Glyph.OffsetXY(newGlyph, (short)(arg1), arg2); } else { if (hasScale) { if (xscale == 1.0 && yscale == 1.0) { } else { Glyph.TransformNormalWith2x2Matrix(newGlyph, xscale, 0, 0, yscale); } Glyph.OffsetXY(newGlyph, arg1, arg2); } else { if (HasFlag(flags, CompositeGlyphFlags.ROUND_XY_TO_GRID)) { //TODO: implement round xy to grid*** //---------------------------- } //just offset*** Glyph.OffsetXY(newGlyph, arg1, arg2); } } } else { //two point numbers. //the first point number indicates the point that is to be matched to the new glyph. //The second number indicates the new glyph's “matched” point. //Once a glyph is added,its point numbers begin directly after the last glyphs (endpoint of first glyph + 1) } // if (finalGlyph == null) { finalGlyph = newGlyph; } else { //merge Glyph.AppendGlyph(finalGlyph, newGlyph); } } while (HasFlag(flags, CompositeGlyphFlags.MORE_COMPONENTS)); if (HasFlag(flags, CompositeGlyphFlags.WE_HAVE_INSTRUCTIONS)) { ushort numInstr = reader.ReadUInt16(); byte[] insts = reader.ReadBytes(numInstr); finalGlyph.GlyphInstructions = insts; } //F2DOT14 16-bit signed fixed number with the low 14 bits of fraction (2.14). //Transformation Option // //The C pseudo-code fragment below shows how the composite glyph information is stored and parsed; definitions for “flags” bits follow this fragment: // do { // USHORT flags; // USHORT glyphIndex; // if ( flags & ARG_1_AND_2_ARE_WORDS) { // (SHORT or FWord) argument1; // (SHORT or FWord) argument2; // } else { // USHORT arg1and2; /* (arg1 << 8) | arg2 */ // } // if ( flags & WE_HAVE_A_SCALE ) { // F2Dot14 scale; /* Format 2.14 */ // } else if ( flags & WE_HAVE_AN_X_AND_Y_SCALE ) { // F2Dot14 xscale; /* Format 2.14 */ // F2Dot14 yscale; /* Format 2.14 */ // } else if ( flags & WE_HAVE_A_TWO_BY_TWO ) { // F2Dot14 xscale; /* Format 2.14 */ // F2Dot14 scale01; /* Format 2.14 */ // F2Dot14 scale10; /* Format 2.14 */ // F2Dot14 yscale; /* Format 2.14 */ // } //} while ( flags & MORE_COMPONENTS ) //if (flags & WE_HAVE_INSTR){ // USHORT numInstr // BYTE instr[numInstr] //------------------------------------------------------------ return((finalGlyph == null) ? Glyph.Empty : finalGlyph); }
/// <inheritdoc cref="Clone"/> public virtual object Clone() { return(new CharacterInfo(CodePoint, CharacterSize, (System.Drawing.Image)Glyph.Clone())); }