/// <summary> Load a font from a URL /// /// </summary> /// <param name="code"> /// </param> /// <param name="alias">The name used to bind a DefineFont tag to a DefineEditText tag. /// </param> /// <param name="location">remote url or a relative, local file path /// </param> /// <param name="style"> /// </param> /// <param name="hasLayout"> /// </param> public FontBuilder(int code, FontManager manager, System.String alias, System.Uri location, int style, bool hasLayout, bool flashType) : this(code, hasLayout, flashType) { if (manager == null) { throw new NoFontManagerException(); } if (Trace.font) { Trace.trace("Locating font using FontManager '" + manager.GetType().FullName + "'"); } bool useTwips = code != flash.swf.TagValues_Fields.stagDefineFont && code != flash.swf.TagValues_Fields.stagDefineFont2; FontFace fontFace = manager.getEntryFromLocation(location, style, useTwips); if (fontFace == null) { throwFontNotFound(alias, null, style, location.ToString()); } if (Trace.font) { Trace.trace("Initializing font at '" + location.ToString() + "' as '" + alias + "'"); } this.defaultFace = fontFace; init(alias); }
/// <summary> Adds all supported characters from 0 to the highest glyph /// contained in the given font face. /// /// </summary> /// <param name="face"> /// </param> public void addAllChars(FontFace face) { int min = face.FirstChar; int count = face.NumGlyphs; if (Trace.font) Trace.trace("\tAdding " + count + " chars, starting from " + min); addCharset(min, count); }
/// <summary> Based on Timothee Groleau's public ActionScript library (which is based on /// Helen Triolo's approach) using Casteljau's approximation for drawing 3rd-order Cubic /// curves as a collection of 2nd-order Quadratic curves - with a fixed level of accuracy /// using just 4 quadratic curves. /// <p/> /// The reason this fixed-level approach was chosen is because it is very fast and should /// provide us with a reasonable approximation for small curves involved in fonts. /// <p/> /// "This function will trace a cubic approximation of the cubic Bezier /// It will calculate a series of [control point/Destination point] which /// will be used to draw quadratic Bezier starting from P0" /// <p/> /// /// </summary> /// <link> http://timotheegroleau.com/Flash/articles/cubic_bezier_in_flash.htm </link> private void approximateCubicBezier(Point P0, Point P1, Point P2, Point P3) { // calculates the useful base points Point PA = getPointOnSegment(P0, P1, 3.0 / 4.0); Point PB = getPointOnSegment(P3, P2, 3.0 / 4.0); // get 1/16 of the [P3, P0] segment double dx = (P3.x - P0.x) / 16.0; double dy = (P3.y - P0.y) / 16.0; // calculate control point 1 Point c1 = getPointOnSegment(P0, P1, 3.0 / 8.0); // calculate control point 2 Point c2 = getPointOnSegment(PA, PB, 3.0 / 8.0); c2.x = c2.x - dx; c2.y = c2.y - dy; // calculate control point 3 Point c3 = getPointOnSegment(PB, PA, 3.0 / 8.0); c3.x = c3.x + dx; c3.y = c3.y + dy; // calculate control point 4 Point c4 = getPointOnSegment(P3, P2, 3.0 / 8.0); // calculate the 3 anchor points (as midpoints of the control segments) Point a1 = new Point(((c1.x + c2.x) / 2.0), ((c1.y + c2.y) / 2.0)); Point a2 = new Point(((PA.x + PB.x) / 2.0), ((PA.y + PB.y) / 2.0)); Point a3 = new Point(((c3.x + c4.x) / 2.0), ((c3.y + c4.y) / 2.0)); // draw the four quadratic sub-segments curved(c1.x, c1.y, a1.x, a1.y); curved(c2.x, c2.y, a2.x, a2.y); curved(c3.x, c3.y, a3.x, a3.y); curved(c4.x, c4.y, P3.x, P3.y); if (Trace.font_cubic) { Trace.trace("Cubic Curve\n"); Trace.trace("P0:\t" + P0.x + "\t" + P0.y); Trace.trace("c1:\t" + c1.x + "\t" + c1.y + "\t\tP1:\t" + P1.x + "\t" + P1.y); Trace.trace("a1:\t" + a1.x + "\t" + a1.y); Trace.trace("c2:\t" + c2.x + "\t" + c2.y); Trace.trace("a2:\t" + a2.x + "\t" + a2.y); Trace.trace("c3:\t" + c3.x + "\t" + c3.y); Trace.trace("a3:\t" + a3.x + "\t" + a3.y); Trace.trace("c4:\t" + c4.x + "\t" + c4.y + "\t\tP2:\t" + P2.x + "\t" + P2.y); Trace.trace("P3:\t" + P3.x + "\t" + P3.y); } }
public static ZoneRecordBuilder createInstance() { try { //UPGRADE_TODO: The differences in the format of parameters for method 'java.lang.Class.forName' may cause compilation errors. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'" System.Type c = System.Type.GetType(DEFAULT_BUILDER); ZoneRecordBuilder builder = (ZoneRecordBuilder)System.Activator.CreateInstance(c); return(builder); } //UPGRADE_NOTE: Exception 'java.lang.Throwable' was converted to 'System.Exception' which has different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1100'" catch (System.Exception t) { if (Trace.error) { Trace.trace("ZoneRecordBuilder implementation not found '" + DEFAULT_BUILDER + "'"); } } return(null); }
/// <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); }
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 }