Esempio n. 1
0
		// Attempts to instantiate the requested GDI+ font object.
		static Font CreateFont(FontDescription options)
		{
			Font font = new Font(options.FontName, PointsToPixels(options.Size), (System.Drawing.FontStyle)options.Style, GraphicsUnit.Pixel);

			try
			{
				// The font constructor automatically substitutes fonts if it can't find the one requested.
				// But we prefer the caller to know if anything is wrong with their data. A simple string compare
				// isn't sufficient because some fonts (eg. MS Mincho) change names depending on the locale.

				// Early out: in most cases the name will match the current or invariant culture.
				if (options.FontName.Equals(font.FontFamily.GetName(CultureInfo.CurrentCulture.LCID), StringComparison.OrdinalIgnoreCase) ||
				    options.FontName.Equals(font.FontFamily.GetName(CultureInfo.InvariantCulture.LCID), StringComparison.OrdinalIgnoreCase))
				{
					return font;
				}

				// Check the font name in every culture.
				foreach (CultureInfo culture in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
				{
					if (options.FontName.Equals(font.FontFamily.GetName(culture.LCID), StringComparison.OrdinalIgnoreCase))
					{
						return font;
					}
				}

				// A font substitution must have occurred.
				throw new Exception(string.Format("Can't find font '{0}'.", options.FontName));
			}
			catch
			{
				font.Dispose();
				throw;
			}
		}
Esempio n. 2
0
    public override SpriteFontContent Process(FontDescription input,
        ContentProcessorContext context)
    {
        {
            //ファイル読み込み
            string fullPath = Path.GetFullPath("kana_list.txt");
            context.AddDependency(fullPath);
            string letters = File.ReadAllText(fullPath, System.Text.Encoding.UTF8);

            //フォントの追加
            foreach (char c in letters)
            {
                input.Characters.Add(c);
            }
        }

        {
            //ファイル読み込み
            string fullPath = Path.GetFullPath("kanji_list.txt");
            context.AddDependency(fullPath);
            string letters = File.ReadAllText(fullPath, System.Text.Encoding.UTF8);

            //フォントの追加
            foreach (char c in letters)
            {
                input.Characters.Add(c);
            }
        }

        return base.Process(input, context);
    }
Esempio n. 3
0
        /// <summary>
        /// コンテントパイプラインから呼ばれるメソッド
        /// </summary>
        public override SpriteFontContent Process(FontDescription input,
                                                    ContentProcessorContext context)
        {
            // MessageFilenameで指定されたファイル内の文字を追加する 
            AppendCharacters(input, context);

            // 文字列を追加した後は単純にFontDescriptionProcessorのプロセスを呼ぶだけ
            return base.Process(input, context);
        }
        /// <summary>
        /// �R���e���g�p�C�v���C������Ă΂�郁�\�b�h
        /// </summary>
        public override SpriteFontContent Process(FontDescription input,
                                                    ContentProcessorContext context)
        {
            // MessageFilename�Ŏw�肳�ꂽ�t�@�C����̕�����lj�����
            AppendCharacters(input, context);

            // �������lj�������͒P����FontDescriptionProcessor�̃v���Z�X��ĂԂ���
            return base.Process(input, context);
        }
Esempio n. 5
0
        public override SpriteFontContent Process(FontDescription input, ContentProcessorContext context)
        {
            SpriteFontContent sfc = base.Process(input, context);

            if(context.TargetPlatform == TargetPlatform.Windows)
                CreateExEnOutput(sfc, input, context);

            return sfc;
        }
 public override SpriteFontContent Process(FontDescription input, ContentProcessorContext context)
 {
     string path = Path.GetFullPath(m_FilePath);
     context.AddDependency(path);
     string content = File.ReadAllText(path, Encoding.UTF8);//FontDescription.txt文件必须保存成utf-8格式,此处也需使用utf-8读取
     foreach (char c in content)//读取文件中字符,存放到FontDescription中
     {
         input.Characters.Add(c);
     }
     return base.Process(input, context);
 }
Esempio n. 7
0
        public SpriteFontContent(FontDescription desc)
        {
            FontName = desc.FontName;
            Style = desc.Style;
            FontSize = desc.Size;
            CharacterMap = new List<char>(desc.Characters.Count);
            VerticalLineSpacing = (int)desc.Spacing; // Will be replaced in the pipeline.
            HorizontalSpacing = desc.Spacing;

            DefaultCharacter = desc.DefaultCharacter;
        }
Esempio n. 8
0
        public SpriteFontContent(FontDescription desc)
        {
            FontName = desc.FontName;
            Style = desc.Style;
            FontSize = desc.Size;
			CharacterMap = CharacterRegion.Flatten(desc.CharacterRegions).ToList();
            VerticalLineSpacing = (int)desc.Spacing; // Will be replaced in the pipeline.
            HorizontalSpacing = desc.Spacing;

            DefaultCharacter = desc.DefaultCharacter;
        }
        public override SpriteFontContent Process(FontDescription input, ContentProcessorContext context)
        {
            // TODO: 处理输入对象,并返回修改的数据。
            string fullPath = Path.GetFullPath(MessageFile);
            context.AddDependency(fullPath);
            string letters = File.ReadAllText(fullPath, System.Text.Encoding.UTF8);
            foreach (char c in letters)
            {
                input.Characters.Add(c);
            }

            return base.Process(input, context);
        }
Esempio n. 10
0
        private void CreateExEnOutput(SpriteFontContent spriteFontContent, FontDescription input, ContentProcessorContext context)
        {
            ExEnFontWriter.CreateOutputDirectory(input.Identity);

            ExEnFontWriter.WriteTexture(spriteFontContent, true, context,
                    ExEnFontWriter.AssetOutputFilename(input.Identity, context, "-exenfont.png"));
            ExEnFontWriter.WriteMetrics(spriteFontContent, context,
                    ExEnFontWriter.AssetOutputFilename(input.Identity, context, "-exenfont.exenfont"));

            // Retina Display
            input.BecomeAt2x();
            SpriteFontContent spriteFontContentAt2x = base.Process(input, context);
            ExEnFontWriter.WriteTexture(spriteFontContentAt2x, true, context,
                    ExEnFontWriter.AssetOutputFilename(input.Identity, context, "*****@*****.**"));
            ExEnFontWriter.WriteMetrics(spriteFontContentAt2x, context,
                    ExEnFontWriter.AssetOutputFilename(input.Identity, context, "*****@*****.**"));
        }
        /// <summary>
        /// FontDescription��MessageFilename�Ŏw�肳�ꂽ�t�@�C����̕�����lj�����
        /// </summary>
        void AppendCharacters(FontDescription input, ContentProcessorContext context)
        {
            // MessageFilename�͗L���ȕ����񂩁H
            if (String.IsNullOrEmpty(MessageFilename))
                return;

            if (!File.Exists(MessageFilename))
            {
                throw new FileNotFoundException(
                    String.Format( "MessageFilename�Ŏw�肳�ꂽ�t�@�C��[{0}]�����݂��܂���",
                                    Path.GetFullPath(MessageFilename)));
            }

            // �w�肳�ꂽ�t�@�C�����當�����ǂݍ��݁A
            // FontDescription.Charctars�ɒlj�����
            try
            {
                int totalCharacterCount = 0;

                using (StreamReader sr = File.OpenText(MessageFilename))
                {
                    string line;
                    while ( ( line = sr.ReadLine() ) != null )
                    {
                        totalCharacterCount += line.Length;

                        foreach( char c in line )
                            input.Characters.Add( c );
                    }
                }

                context.Logger.LogImportantMessage("�g�p������{0}, ��������:{1}",
                    input.Characters.Count, totalCharacterCount);

                // CP�Ƀt�@�C���ˑ����Ă��邱�Ƃ������
                context.AddDependency(Path.GetFullPath(MessageFilename));
            }
            catch (Exception e)
            {
                // �\�����Ȃ���O������
                context.Logger.LogImportantMessage("��O����!! {0}", e.Message);
                throw e;
            }
        }
Esempio n. 12
0
		public void Import(FontDescription options, string fontName)
		{
			lib = new Library ();
			// Create a bunch of GDI+ objects.
			Face face = CreateFontFace (options, fontName);
			try {
				using (Brush brush = new SolidBrush(System.Drawing.Color.White))
					using (StringFormat stringFormat = new StringFormat(StringFormatFlags.NoFontFallback))
					using (Bitmap bitmap = new Bitmap(MaxGlyphSize, MaxGlyphSize, PixelFormat.Format32bppArgb))
					using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bitmap))
				{
					graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
					graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
					graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;

					// Which characters do we want to include?
					var characters = CharacterRegion.Flatten(options.CharacterRegions);

					var glyphList = new List<Glyph>();
					// Rasterize each character in turn.
					foreach (char character in characters)
					{
						Glyph glyph = ImportGlyph(character, face, brush, stringFormat, bitmap, graphics);
						glyphList.Add(glyph);

					}
					Glyphs = glyphList;

					// Store the font height.
					LineSpacing = 0;
					foreach (var glyph in Glyphs) 
					{
						LineSpacing = (glyph.Subrect.Height > LineSpacing) ? glyph.Subrect.Height : LineSpacing;
					}
				}
			} finally {
				if (face != null)
					face.Dispose ();
				if (lib != null) {
					lib.Dispose ();
					lib = null;
				}
			}
		}
Esempio n. 13
0
        /// <summary>
        /// FontDescriptionにMessageFilenameで指定されたファイル内の文字を追加する
        /// </summary>
        void AppendCharacters(FontDescription input, ContentProcessorContext context)
        {
            // MessageFilenameは有効な文字列か?
            if (String.IsNullOrEmpty(MessageFilename))
                return;

            if (!File.Exists(MessageFilename))
            {
                throw new FileNotFoundException(
                    String.Format( "MessageFilenameで指定されたファイル[{0}]が存在しません",
                                    Path.GetFullPath(MessageFilename)));
            }

            // 指定されたファイルから文字列を読み込み、
            // FontDescription.Charctarsに追加する
            try
            {
                int totalCharacterCount = 0;

                using (StreamReader sr = File.OpenText(MessageFilename))
                {
                    string line;
                    while ( ( line = sr.ReadLine() ) != null )
                    {
                        totalCharacterCount += line.Length;

                        foreach( char c in line )
                            input.Characters.Add(c);
                    }
                }

                context.Logger.LogImportantMessage("使用文字数{0}, 総文字数:{1}",
                    input.Characters.Count, totalCharacterCount);

                // CPにファイル依存していることを教える
                context.AddDependency(Path.GetFullPath(MessageFilename));
            }
            catch (Exception e)
            {
                // 予期しない例外が発生
                context.Logger.LogImportantMessage("例外発生!! {0}", e.Message);
                throw e;
            }
        }
Esempio n. 14
0
        public override SpriteFontContent Process(FontDescription input, ContentProcessorContext context)
        {
            var fullPath = Path.GetFullPath(MessageFile);

            context.AddDependency(fullPath);

            var letters = File.ReadAllText(fullPath, System.Text.Encoding.UTF8);

            foreach (char c in letters)
            {
                if (c == '\r' || c == '\n')
                {
                    continue;
                }
                input.Characters.Add(c);
            }

            return base.Process(input, context);
        }
 public override SpriteFontContent Process(FontDescription input, ContentProcessorContext context)
 {
   input_ = input;
   context_ = context;
   SpriteFontContent ret = base.Process(input, context);
   System.Reflection.PropertyInfo pi = ret.GetType().GetProperty("Texture", System.Reflection.BindingFlags.NonPublic
       | System.Reflection.BindingFlags.Instance);
   if (pi != null)
   {
     if (!AddOutline(pi.GetValue(ret, null) as Texture2DContent))
     {
       throw new System.FormatException("The format of the bitmap is not recognized.");
     }
   }
   else
   {
     context.Logger.LogWarning("http://msdn.microsoft.com/", input.Identity, "Could not get property 'Texture'");
   }
   return ret;
 }
Esempio n. 16
0
		// Attempts to instantiate the requested GDI+ font object.
		Face CreateFontFace(FontDescription options, string fontName)
		{

			try {
				Face face = lib.NewFace (fontName, 0);
				face.SetCharSize(0, (int)options.Size * 64, 0, 96);

				if (face.FamilyName == "Microsoft Sans Serif" && options.FontName != "Microsoft Sans Serif")
					throw new PipelineException(string.Format("Font {0} is not installed on this computer.", options.FontName));

				return face;

				// A font substitution must have occurred.
				//throw new Exception(string.Format("Can't find font '{0}'.", options.FontName));
			}
			catch
			{
				throw;
			}
		}
        public override SpriteFontContent Process(FontDescription input, ContentProcessorContext context)
        {
            // Fallback if we aren't buiding for iOS.
            var platform = ContentHelper.GetMonoGamePlatform();
            if (platform != MonoGamePlatform.iOS)
                return base.Process(input, context);

            SpriteFontContent content = base.Process(input, context);
            FieldInfo TextureField = typeof(SpriteFontContent).GetField("texture", BindingFlags.Instance | BindingFlags.NonPublic);
            Texture2DContent texture = (Texture2DContent)TextureField.GetValue(content);
            
            // TODO: This is a very lame way of doing this as we're getting compression artifacts twice, but is the quickest way to get
            // Compressed fonts up and running. The SpriteFontContent/Processor contains a ton
            // of sealed/internal classes riddled with private fields, so overriding CompressFontTexture
            // or even Process is tricky. This works for now, but should be replaced when the content pipeline
            // moves a bit further

            var texWidth = ContentHelper.NextPOT(texture.Faces[0][0].Width);
            var texHeight = ContentHelper.NextPOT(texture.Faces[0][0].Height);

            // Resize to square, power of two if necessary.
            if (texWidth != texHeight || texture.Faces[0][0].Width != texture.Faces[0][0].Height || texWidth != texture.Faces[0][0].Width || texHeight != texture.Faces[0][0].Height)
            {
                texHeight = texWidth = Math.Max(texHeight, texWidth);
                var resizedBitmap = (BitmapContent)Activator.CreateInstance(typeof(PixelBitmapContent<Color>), new object[] { texWidth, texHeight });
                var textureRegion = new Rectangle(0, 0, texture.Faces[0][0].Width, texture.Faces[0][0].Height);
                BitmapContent.Copy(texture.Faces[0][0], textureRegion, resizedBitmap, textureRegion);

                texture.Faces[0].Clear();
                texture.Faces[0].Add(resizedBitmap);
                
                context.Logger.LogImportantMessage(string.Format("Resized font texture {0} to {1}x{2}", input.Name, resizedBitmap.Width, resizedBitmap.Height));
            }
            else
                texture.ConvertBitmapType(typeof(PixelBitmapContent<Color>));

            MGTextureProcessor.ConvertToPVRTC(texture, 1, true, MGCompressionMode.PVRTCFourBitsPerPixel);

            return content; 

        }
Esempio n. 18
0
        // Attempts to instantiate the requested GDI+ font object.
        Face CreateFontFace(FontDescription options, string fontName)
        {
            try {
                Face face = lib.NewFace(fontName, 0);
                face.SetCharSize(0, (int)options.Size * 64, 0, 96);

                if (face.FamilyName == "Microsoft Sans Serif" && options.FontName != "Microsoft Sans Serif")
                {
                    throw new PipelineException(string.Format("Font {0} is not installed on this computer.", options.FontName));
                }

                return(face);

                // A font substitution must have occurred.
                //throw new Exception(string.Format("Can't find font '{0}'.", options.FontName));
            }
            catch
            {
                throw;
            }
        }
Esempio n. 19
0
        public void Import(FontDescription options, string fontName)
        {
            // Create a bunch of GDI+ objects.
            using (Font font = CreateFont(options))
                using (Brush brush = new SolidBrush(System.Drawing.Color.White))
                    using (StringFormat stringFormat = new StringFormat(StringFormatFlags.NoFontFallback))
                        using (Bitmap bitmap = new Bitmap(MaxGlyphSize, MaxGlyphSize, PixelFormat.Format32bppArgb))
                            using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bitmap))
                            {
                                graphics.PixelOffsetMode   = PixelOffsetMode.HighQuality;
                                graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                                graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;

                                //				var characterRegions = new List<CharacterRegion> ();
                                //				foreach (var character in options.Characters)
                                //				{
                                //					characterRegions.Add (new CharacterRegion ('a', 'b'));
                                //				}

                                // Which characters do we want to include?
                                var characters = options.Characters;

                                var glyphList = new List <Glyph>();

                                // Rasterize each character in turn.
                                foreach (char character in characters)
                                {
                                    Glyph glyph = ImportGlyph(character, font, brush, stringFormat, bitmap, graphics);

                                    glyphList.Add(glyph);
                                }

                                Glyphs = glyphList;

                                // Store the font height.
                                LineSpacing = font.GetHeight();
                                YOffsetMin  = (int)LineSpacing;
                            }
        }
Esempio n. 20
0
        public void Import(FontDescription options, string fontName)
        {
            lib = new Library();
            // Create a bunch of GDI+ objects.
            var face = CreateFontFace(options, fontName);

            try
            {
                // Which characters do we want to include?
                var characters = options.Characters;

                var glyphList = new List <Glyph>();
                // Rasterize each character in turn.
                foreach (char character in characters)
                {
                    var glyph = ImportGlyph(character, face);
                    glyphList.Add(glyph);
                }
                Glyphs = glyphList;

                // Store the font height.
                LineSpacing = face.Size.Metrics.Height >> 6;

                // The height used to calculate the Y offset for each character.
                YOffsetMin = -face.Size.Metrics.Ascender >> 6;
            }
            finally
            {
                if (face != null)
                {
                    face.Dispose();
                }
                if (lib != null)
                {
                    lib.Dispose();
                    lib = null;
                }
            }
        }
Esempio n. 21
0
		public void Import(FontDescription options, string fontName)
		{
			// Create a bunch of GDI+ objects.
			using (Font font = CreateFont(options))
				using (Brush brush = new SolidBrush(System.Drawing.Color.White))
					using (StringFormat stringFormat = new StringFormat(StringFormatFlags.NoFontFallback))
					using (Bitmap bitmap = new Bitmap(MaxGlyphSize, MaxGlyphSize, PixelFormat.Format32bppArgb))
					using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bitmap))
			{
				graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
				graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
				graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;

				//				var characterRegions = new List<CharacterRegion> ();
				//				foreach (var character in options.Characters) 
				//				{
				//					characterRegions.Add (new CharacterRegion ('a', 'b'));
				//				}

				// Which characters do we want to include?
                var characters = options.Characters;

				var glyphList = new List<Glyph>();

				// Rasterize each character in turn.
				foreach (char character in characters)
				{
					Glyph glyph = ImportGlyph(character, font, brush, stringFormat, bitmap, graphics);

					glyphList.Add(glyph);
				}

				Glyphs = glyphList;

				// Store the font height.
				LineSpacing = font.GetHeight();
				YOffsetMin = (int)LineSpacing;
			}
		}
Esempio n. 22
0
		public void Import(FontDescription options, string fontName)
		{
			lib = new Library();
			// Create a bunch of GDI+ objects.
			var face = CreateFontFace(options, fontName);
			try
            {
					// Which characters do we want to include?
                    var characters = options.Characters;

					var glyphList = new List<Glyph>();
					// Rasterize each character in turn.
					foreach (char character in characters)
					{
						var glyph = ImportGlyph(character, face);
						glyphList.Add(glyph);
					}
					Glyphs = glyphList;

					// Store the font height.
					LineSpacing = face.Size.Metrics.Height >> 6;

					// The height used to calculate the Y offset for each character.
					YOffsetMin = -face.Size.Metrics.Ascender >> 6;
			}
            finally
            {
				if (face != null)
					face.Dispose();
				if (lib != null)
                {
					lib.Dispose();
					lib = null;
				}
			}
		}
Esempio n. 23
0
        public void ValidateMembers()
        {
            {
                var font = new FontDescription("FontName", 12.34f, 5.67f);
                Assert.NotNull(font.Characters);
                Assert.AreEqual(0, font.Characters.Count);
                Assert.IsNull(font.DefaultCharacter);
                Assert.AreEqual("FontName", font.FontName);
                Assert.AreEqual(12.34f, font.Size);
                Assert.AreEqual(5.67f, font.Spacing);
                Assert.AreEqual(FontDescriptionStyle.Regular, font.Style);
                Assert.AreEqual(false, font.UseKerning);
                Assert.IsNull(font.Identity);
                Assert.IsNull(font.Name);
                Assert.NotNull(font.OpaqueData);
                Assert.AreEqual(0, font.OpaqueData.Count);
            }

            {
                var font = new FontDescription("FontName", 12.34f, 5.67f, FontDescriptionStyle.Italic);
                Assert.NotNull(font.Characters);
                Assert.AreEqual(0, font.Characters.Count);
                Assert.IsNull(font.DefaultCharacter);
                Assert.AreEqual("FontName", font.FontName);
                Assert.AreEqual(12.34f, font.Size);
                Assert.AreEqual(5.67f, font.Spacing);
                Assert.AreEqual(FontDescriptionStyle.Italic, font.Style);
                Assert.AreEqual(false, font.UseKerning);
                Assert.IsNull(font.Identity);
                Assert.IsNull(font.Name);
                Assert.NotNull(font.OpaqueData);
                Assert.AreEqual(0, font.OpaqueData.Count);
            }

            {
                var font = new FontDescription("FontName", 12.34f, 5.67f, FontDescriptionStyle.Bold, true);
                Assert.NotNull(font.Characters);
                Assert.AreEqual(0, font.Characters.Count);
                Assert.IsNull(font.DefaultCharacter);
                Assert.AreEqual("FontName", font.FontName);
                Assert.AreEqual(12.34f, font.Size);
                Assert.AreEqual(5.67f, font.Spacing);
                Assert.AreEqual(FontDescriptionStyle.Bold, font.Style);
                Assert.AreEqual(true, font.UseKerning);
                Assert.IsNull(font.Identity);
                Assert.IsNull(font.Name);
                Assert.NotNull(font.OpaqueData);
                Assert.AreEqual(0, font.OpaqueData.Count);
            }

            Assert.Throws<ArgumentNullException>(() => new FontDescription(null, 1, 1));
            Assert.Throws<ArgumentNullException>(() => new FontDescription("", 1, 1));
            Assert.Throws<ArgumentOutOfRangeException>(() => new FontDescription("Aye", 0, 1));
            Assert.Throws<ArgumentOutOfRangeException>(() => new FontDescription("Aye", -1, 1));

            {
                var font = new FontDescription("Bee", 1, 1);
                
                font.DefaultCharacter = 'A';
                Assert.AreEqual('A', font.DefaultCharacter);
                font.DefaultCharacter = null;
                Assert.IsNull(font.DefaultCharacter);

                font.FontName = "See";
                Assert.AreEqual("See", font.FontName);
                Assert.Throws<ArgumentNullException>(() => font.FontName = null);
                Assert.Throws<ArgumentNullException>(() => font.FontName = "");

                font.Size = 2;
                Assert.AreEqual(2, font.Size);
                Assert.Throws<ArgumentOutOfRangeException>(() => font.Size = 0);
                Assert.Throws<ArgumentOutOfRangeException>(() => font.Size = -1);

                font.Spacing = 2;
                Assert.AreEqual(2, font.Spacing);
                font.Spacing = 0;
                Assert.AreEqual(0, font.Spacing);
                font.Spacing = -2;
                Assert.AreEqual(-2, font.Spacing);

                font.Style = FontDescriptionStyle.Italic;
                Assert.AreEqual(FontDescriptionStyle.Italic, font.Style);

                font.UseKerning = true;
                Assert.AreEqual(true, font.UseKerning);
            }

        }