コード例 #1
0
        /// <summary> Adds supported characters in the specified range from the given
        /// font face.
        ///
        /// </summary>
        /// <param name="face">
        /// </param>
        /// <param name="fromChar">
        /// </param>
        /// <param name="count">
        /// </param>
        public void  addCharset(FontFace face, int fromChar, int count)
        {
            int remaining = count;

            for (int i = fromChar; remaining > 0 && i < System.Char.MaxValue; i++)
            {
                char       c  = (char)i;
                GlyphEntry ge = addChar(face, c);
                if (ge != null)
                {
                    remaining--;
                }
            }
        }
コード例 #2
0
        /// <summary> If supported, includes a character from the given font face.
        ///
        /// </summary>
        /// <param name="c">
        /// </param>
        public GlyphEntry addChar(FontFace face, char c)
        {
            GlyphEntry ge = (GlyphEntry)glyphEntryMap.get_Renamed(c);

            if (ge == null)
            {
                ge = face.getGlyphEntry(c);

                if (ge != null)
                {
                    //Add to this tag's collection
                    glyphEntryMap.put(c, ge);
                }
            }

            if (flashType && ge != null && ge.zoneRecord == null && zoneRecordBuilder != null)
            {
                ge.zoneRecord = zoneRecordBuilder.build(c);
            }

            return(ge);
        }
コード例 #3
0
        /// <summary> Creates a DefineFont2 or DefineFont3 tag depending on the code specified
        /// on construction.
        /// </summary>
        public DefineTag build()
        {
            int count = glyphEntryMap.size();

            if (Trace.font)
            {
                Trace.trace("Building font '" + tag.fontName + "' with " + count + " characters.");
            }

            if (flashType && tag is DefineFont3)
            {
                DefineFont3 df3 = (DefineFont3)tag;
                df3.zones              = new DefineFontAlignZones();
                df3.zones.font         = df3;
                df3.zones.zoneTable    = new ZoneRecord[count];
                df3.zones.csmTableHint = 1;
            }

            tag.glyphShapeTable = new Shape[count];

            if (tag.code != flash.swf.TagValues_Fields.stagDefineFont)
            {
                tag.codeTable = new char[count];

                if (tag.hasLayout)
                {
                    tag.advanceTable = new short[count];
                    tag.boundsTable  = new Rect[count];
                }
            }

            // Process each GlyphEntry
            System.Collections.IEnumerator it = glyphEntryMap.iterator();
            int i = 0;

            // long flashTypeTime = 0;
            //UPGRADE_TODO: Method 'java.util.Iterator.hasNext' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratorhasNext'"
            while (it.MoveNext() && i < count)
            {
                //UPGRADE_TODO: Method 'java.util.Iterator.next' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratornext'"
                GlyphEntry ge = (GlyphEntry)((System.Collections.DictionaryEntry)it.Current).Value;

                if (flashType && tag is DefineFont3)
                {
                    ((DefineFont3)tag).zones.zoneTable[i] = ge.zoneRecord;
                }

                // Note: offsets to shape table entries calculated on encoding
                tag.glyphShapeTable[i] = ge.shape;

                // IMPORTANT! Update GlyphEntry Index
                ge.Index = i;

                // DEFINEFONT2/3 specific properties
                if (tag.code != flash.swf.TagValues_Fields.stagDefineFont)
                {
                    tag.codeTable[i] = ge.character;                     // unsigned code point

                    // Layout information
                    if (tag.hasLayout)
                    {
                        tag.advanceTable[i] = (short)ge.advance;                          //advance in emScale
                        // The player doesn't need ge.bounds, so we ignore it.
                        // We must still generate this value, however, for ADF use.
                        tag.boundsTable[i] = IDENTITY_RECT;
                    }
                    else
                    {
                        if (Trace.font)
                        {
                            Trace.trace("Warning: font tag created without layout information.");
                        }
                    }
                }

                i++;
            }

            if (tag.hasLayout)
            {
                tag.kerningTable = new KerningRecord[0];
            }

            // FIXME: we should allow the user to set the language code
            //tag.langCode = 1;

            // if we have any license info, create a DefineFontName tag
            if (useLicenseTag && ((FSType != null && !FSType.installable) || Copyright != null || Name != null))
            {
                tag.license           = new DefineFontName();
                tag.license.font      = tag;
                tag.license.fontName  = Name;
                tag.license.copyright = Copyright;
            }

            return(tag);
        }
コード例 #4
0
        private void  init(System.String alias)
        {
            fontHeight = defaultFace.PointSize;

            if (tag.code != flash.swf.TagValues_Fields.stagDefineFont)
            {
                tag.fontName = alias;
                tag.bold     = defaultFace.isBold();
                tag.italic   = defaultFace.isItalic();

                if (tag.hasLayout)
                {
                    tag.ascent  = defaultFace.Ascent;
                    tag.descent = defaultFace.Descent;
                    tag.leading = defaultFace.LineGap;

                    if (Trace.font)
                    {
                        Trace.trace("\tBold: " + tag.bold);
                        Trace.trace("\tItalic: " + tag.italic);
                        Trace.trace("\tAscent: " + tag.ascent);
                        Trace.trace("\tDescent: " + tag.descent);
                        Trace.trace("\tLeading: " + tag.leading);
                    }
                }
            }

            // If flashType enabled we must have z, Z, l, L
            if (flashType)
            {
                GlyphEntry adfGE = defaultFace.getGlyphEntry('z');
                if (adfGE == null)
                {
                    flashType = false;
                }

                adfGE = defaultFace.getGlyphEntry('Z');
                if (adfGE == null)
                {
                    flashType = false;
                }

                adfGE = defaultFace.getGlyphEntry('l');
                if (adfGE == null)
                {
                    flashType = false;
                }

                adfGE = defaultFace.getGlyphEntry('L');
                if (adfGE == null)
                {
                    flashType = false;
                }
            }

            if (flashType)
            {
                zoneRecordBuilder = ZoneRecordBuilder.createInstance();
                if (zoneRecordBuilder != null)
                {
                    zoneRecordBuilder.FontAlias   = alias;
                    zoneRecordBuilder.FontBuilder = this;
                    zoneRecordBuilder.FontFace    = defaultFace;
                }
                else
                {
                    // FlashType Zone Records are not available, so we should
                    // disable flashType
                    flashType = false;
                }
            }

            addChar(' ');             // Add at least a space char by default
        }
コード例 #5
0
        /// <summary> </summary>
        /// <param name="fontBuilder">FontBuilder
        /// </param>
        /// <param name="height">double
        /// </param>
        /// <param name="text">String
        /// </param>
        /// <param name="color">Color
        /// </param>
        /// <param name="xOffset">int
        /// </param>
        /// <param name="yOffset">int
        /// </param>
        /// <throws>  IOException </throws>
        /// <summary> add text</summary>
        //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'"
        public virtual void  add(FontBuilder fontBuilder, double height, System.String text, ref System.Drawing.Color color, int xOffset, int yOffset)
        {
            fontBuilders.Add(fontBuilder);

            //UPGRADE_ISSUE: Constructor 'java.io.BufferedReader.BufferedReader' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javaioBufferedReaderBufferedReader_javaioReader'"
            System.IO.StreamReader reader = new BufferedReader(new System.IO.StringReader(text));
            System.String          line;
            char[] chars;
            int    yCount   = 0;
            double t_width  = 0.0f;
            double t_height = 0.0f;

            while (true)
            {
                line = reader.ReadLine();
                // Make sure we don't create empty TextRecords
                // A empty textRecord will crash Flash Player. Player Bug#57644
                if ((line == null) || (line.Length == 0))
                {
                    break;
                }

                //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
                //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'"
                TextRecord tr = getStyleRecord(fontBuilder, height, ref color, xOffset, (int)(yOffset + yCount * height * flash.swf.SwfConstants_Fields.TWIPS_PER_PIXEL));

                chars      = line.ToCharArray();
                tr.entries = new GlyphEntry[chars.Length];
                double w = 0;
                for (int i = 0; i < chars.Length; i++)
                {
                    char c = chars[i];
                    // preilly: According to Sherman Gong, we need to clone the font GlyphEntry, so
                    // that the advance value can be mapped from the font's logical scale to the
                    // text's physical scale.
                    GlyphEntry ge = (GlyphEntry)fontBuilder.getGlyph(c).Clone();
                    //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
                    ge.advance    = (int)((ge.advance / 1024f) * tr.height);
                    tr.entries[i] = ge;
                    w            += ge.advance;
                }
                if (w > t_width)
                {
                    t_width = w;
                }
                tag.records.Add(tr);
                yCount++;
            }
            t_height = yCount * height;

            double x1 = 0;
            double y1 = 0;
            double x2 = x1 + t_width;
            double y2 = y1 + t_height;

            x1 = x1 * flash.swf.SwfConstants_Fields.TWIPS_PER_PIXEL;
            x2 = x2 * flash.swf.SwfConstants_Fields.TWIPS_PER_PIXEL;
            y1 = y1 * flash.swf.SwfConstants_Fields.TWIPS_PER_PIXEL;
            y2 = y2 * flash.swf.SwfConstants_Fields.TWIPS_PER_PIXEL;

            /**
             *  If the values are greater than Max_value, then
             *  the results are not to be trusted.
             */
            if (x1 > System.Int32.MaxValue)
            {
                x1 = 0;
            }
            if (x2 > System.Int32.MaxValue)
            {
                x2 = 0;
            }
            if (y1 > System.Int32.MaxValue)
            {
                y1 = 0;
            }
            if (y2 > System.Int32.MaxValue)
            {
                y2 = 0;
            }

            //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
            tag.bounds = new Rect((int)x1, (int)x2, (int)y1, (int)y2);
        }
コード例 #6
0
        /// <summary> Description:  This version is the same as the straight add function
        /// The difference is that we use java layout class to
        /// calculate the bounding box.
        ///
        /// </summary>
        /// <param name="fontBuilder">FontBuilder
        /// </param>
        /// <param name="height">     double
        /// </param>
        /// <param name="text">       String
        /// </param>
        /// <param name="color">      Color
        /// </param>
        /// <param name="xOffset">    int
        /// </param>
        /// <param name="yOffset">    int
        /// </param>
        /// <param name="bounds">     Rectangle2D
        /// </param>
        /// <throws>  IOException </throws>
        //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'"
        public virtual void  addWithLayout(FontBuilder fontBuilder, double height, System.String text, ref System.Drawing.Color color, int xOffset, int yOffset, ref System.Drawing.RectangleF bounds)
        {
            fontBuilders.Add(fontBuilder);

            //UPGRADE_ISSUE: Constructor 'java.io.BufferedReader.BufferedReader' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javaioBufferedReaderBufferedReader_javaioReader'"
            System.IO.StreamReader reader = new BufferedReader(new System.IO.StringReader(text));
            System.String          line;
            char[] chars;
            int    yCount = 0;

            while (true)
            {
                line = reader.ReadLine();
                // Make sure we don't create empty TextRecords
                // A empty textRecord will crash Flash Player. Player Bug #102948
                if ((line == null) || (line.Length == 0))
                {
                    break;
                }
                //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
                //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'"
                TextRecord tr = getStyleRecord(fontBuilder, height, ref color, xOffset, (int)(yOffset + yCount * height * flash.swf.SwfConstants_Fields.TWIPS_PER_PIXEL));

                chars      = line.ToCharArray();
                tr.entries = new GlyphEntry[chars.Length];
                for (int i = 0; i < chars.Length; i++)
                {
                    char       c  = chars[i];
                    GlyphEntry ge = (GlyphEntry)fontBuilder.getGlyph(c).Clone();
                    //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
                    ge.advance    = (int)((ge.advance / 1024f) * tr.height);
                    tr.entries[i] = ge;
                }
                tag.records.Add(tr);
                yCount++;
            }

            /**
             *  on JDK1.4.x the bounds.getMinX() can returns values > bounds.getMaxX()
             *  and also return values > Interger.MAX_VALUE which can cause many
             *  problems when we encode the the position valures in the tagEncoder.
             *
             *  So we stay away from the getMinx, getMinxY methods, and also
             *  double check everything here.
             *
             */

            double x1          = (double)bounds.X;
            double y1          = (double)bounds.Y;
            double rect_width  = (double)bounds.Width;
            double rect_height = (double)bounds.Height;
            double x2          = x1 + rect_width;
            double y2          = y1 + rect_height;

            x1 = x1 * flash.swf.SwfConstants_Fields.TWIPS_PER_PIXEL;
            x2 = x2 * flash.swf.SwfConstants_Fields.TWIPS_PER_PIXEL;
            y1 = y1 * flash.swf.SwfConstants_Fields.TWIPS_PER_PIXEL;
            y2 = y2 * flash.swf.SwfConstants_Fields.TWIPS_PER_PIXEL;

            /**
             *  If the values are greater than Max_value, then
             *  the results are not to be trusted.
             */
            if (x1 > System.Int32.MaxValue)
            {
                x1 = 0;
            }
            if (x2 > System.Int32.MaxValue)
            {
                x2 = 0;
            }
            if (y1 > System.Int32.MaxValue)
            {
                y1 = 0;
            }
            if (y2 > System.Int32.MaxValue)
            {
                y2 = 0;
            }

            //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
            tag.bounds = new Rect((int)x1, (int)x2, (int)y1, (int)y2);
        }