예제 #1
0
		private void CreateCharacterGlyph(char lineCharacter, ref float totalGlyphWidth,
			float lineStartX)
		{
			Glyph characterGlyph = GetGlyphFromDictionary(lineCharacter);
			totalGlyphWidth += GetKerningFromDictionary(lineCharacter, lastGlyph);
			var newDrawInfo = PlaceGlyphInLine(characterGlyph, lineStartX, totalGlyphWidth);
			glyphs.Add(newDrawInfo);
			lastDrawData = newDrawInfo;
			totalGlyphWidth += (float)Math.Round(characterGlyph.AdvanceWidth);
			lastGlyph = characterGlyph;
		}
예제 #2
0
		private void LoadGlyph(XmlData glyphData, Size fontMapSize)
		{
			char character = glyphData.GetAttributeValue("Character", ' ');
			var glyph = new Glyph
			{
				UV = new Rectangle(glyphData.GetAttributeValue("UV")),
				LeftSideBearing = glyphData.GetAttributeValue("LeftBearing", 0.0f),
				RightSideBearing = glyphData.GetAttributeValue("RightBearing", 0.0f)
			};
			glyph.AdvanceWidth = glyphData.GetAttributeValue("AdvanceWidth", glyph.UV.Width - 2.0f);
			glyph.PrecomputedFontMapUV = Rectangle.BuildUVRectangle(glyph.UV, fontMapSize);
			GlyphDictionary.Add(character, glyph);
		}
예제 #3
0
		private Glyph ParseCharacter(Size maxTextPixelSize, bool isClipping, Glyph lastGlyph,
			List<char> currentTextLine)
		{
			char character = parsedLine[characterIndex];
			glyph = glyphDictionary[character];
			float glyphWidth = glyph.AdvanceWidth;
			glyphWidth += GetGlyphWidth(character, lastGlyph);
			glyphWidth = GetNextFullPixel(glyphWidth);
			glyphWidth += GetGlyphWidthOfNextCharacterInLine();
			if (isClipping)
				HandleClipping(maxTextPixelSize, currentTextLine, character, glyphWidth);
			else
				HandleNoClipping(currentTextLine, character, glyphWidth);
			lastGlyph = glyph;
			return lastGlyph;
		}
예제 #4
0
		private GlyphDrawData PlaceGlyphInLine(Glyph characterGlyph, float lineStartX,
			float totalGlyphWidth)
		{
			var glyph = new GlyphDrawData();
			var position =
				new Vector2D((lineStartX + totalGlyphWidth + characterGlyph.LeftSideBearing).Round(),
					lastDrawData.DrawArea.Top);
			glyph.DrawArea = new Rectangle(position, characterGlyph.UV.Size);
			glyph.UV = characterGlyph.PrecomputedFontMapUV;
			return glyph;
		}
예제 #5
0
		private static int GetKerningFromDictionary(char textChar, Glyph lastGlyph)
		{
			int characterKerning;
			return lastGlyph != null && lastGlyph.Kernings != null &&
				lastGlyph.Kernings.TryGetValue(textChar, out characterKerning) ? characterKerning : 0;
		}
예제 #6
0
		private static int GetGlyphWidth(char character, Glyph lastGlyph)
		{
			int charKerning;
			if (lastGlyph != null && lastGlyph.Kernings != null &&
					lastGlyph.Kernings.TryGetValue(character, out charKerning))
				return charKerning;

			return 0;
		}
예제 #7
0
        public List<List<char>> SplitTextIntoLines(string text, Size maxTextPixelSize,
            bool isClipping)
        {
            characterLines = new List<List<char>>();
            if (String.IsNullOrEmpty(text))
                return characterLines;

            if (isClipping && IsFontFittingIntoHeight(maxTextPixelSize.Height))
                return characterLines;

            MaxTextLineWidth = 0.0f;
            TextLineWidths = new List<float>();
            parsedLines = parser.GetLines(text);
            for (lineIndex = 0; lineIndex < parsedLines.Count; lineIndex++)
            {
                parsedLine = parsedLines[lineIndex];
                var currentTextLine = new List<char>();
                currentTextLineWidth = 0.0f;
                currentWord = new List<char>();
                currentWordWidth = 0.0f;
                wordNumber = 0;
                Glyph lastGlyph = null;
                for (characterIndex = 0; characterIndex < parsedLine.Count; characterIndex++)
                {
                    char character = parsedLine[characterIndex];
                    glyph = glyphDictionary[character];
                    float glyphWidth = glyph.AdvanceWidth;
                    glyphWidth += GetGlyphWidth(character, lastGlyph);
                    glyphWidth = GetNextFullPixel(glyphWidth);
                    glyphWidth += GetGlyphWidthOfNextCharacterInLine();

                    if (isClipping)
                    {
                        currentWord.Add(character);
                        if (!IsSpaceOrTab(character))
                            currentWordWidth += glyphWidth;

                        if (IsSpaceOrTab(character) || IsLastCharacterInLine())
                        {
                            if (IsEnoughSpaceForWordInCurrentLineAvailable(maxTextPixelSize) || wordNumber == 0)
                            {
                                currentTextLine.AddRange(currentWord);
                                currentTextLineWidth += currentWordWidth;
                                if (IsSpaceOrTab(character))
                                    currentTextLineWidth += glyphWidth;

                                wordNumber++;
                            }
                            else
                                MoveRestOfLineToTheNextLine();

                            currentWord = new List<char>();
                            currentWordWidth = 0.0f;
                        }
                    }
                    else
                    {
                        currentTextLine.Add(character);
                        currentTextLineWidth += glyphWidth;
                    }

                    lastGlyph = glyph;
                }
                characterLines.Add(currentTextLine);
                TextLineWidths.Add(currentTextLineWidth);
                UpdateMaxTextLineWidth();
                if (!IsEnoughSpaceForNextLineAvailable(isClipping, maxTextPixelSize))
                    break;
            }
            return characterLines;
        }