/// <summary>Gets a displayable character as a surrogate pair from this font. Avoids checking for alternate providers.</summary> public Glyph GetCharacterDirect(int charcode, FontFaceFlags style) { Glyph result; if (Family != null) { result = Family.GetGlyph(charcode, style); } else { result = null; } if (result == null) { if (Fallback != null) { result = Fallback.GetCharacterDirect(charcode, style); } // Global fallback - last chance! if (result == null) { if (DefaultFamily == null && !LoadInternalFont()) { // Font not found! return(null); } return(DefaultFamily.Family.GetGlyph(charcode, style)); } } return(result); }
/// <summary>Gets a displayable character as a surrogate pair from this font.</summary> /// <param name="lowCharacter">The low surrogate character to display.</param> /// <param name="highCharacter">The high surrogate character to display.</param> /// <param name="style">The style of the character.</param> /// <returns>The displayable character.</returns> public Glyph GetCharacter(int charcode, FontFaceFlags style) { // Is it e.g. emoji? Glyph result = CharacterProviders.Find(charcode); if (result != null) { // Character has been overriden. return(result); } if (Family != null) { result = Family.GetGlyph(charcode, style); } if (result == null) { if (Fallback != null) { result = Fallback.GetCharacterDirect(charcode, style); } // Global fallback - last chance! if (result == null) { if (DefaultFamily == null && !LoadInternalFont()) { // Font not found! return(null); } return(DefaultFamily.Family.GetGlyph(charcode, style)); } } return(result); }
/// <summary>Gets or synthesises a glyph for the given style settings which include weight and italic. Style code 400 means regular.</summary> public Glyph GetGlyph(int charcode,FontFaceFlags style){ // Try getting the face: FontFace face=null; if(FontFaces.TryGetValue(style,out face)){ // Great! Raster using that font face: return face.GetGlyph(charcode); } // Get the code as an int: int styleCode=(int)style; // Italic? bool italic=((styleCode&1)==1); // Get the font weight: int weight=(styleCode&~1); if(weight==0){ // Regular: weight=400; } int match=0; if(italic){ // Find one with the closest weight match. face=BestWeight(Italics,weight,out match); }else if(weight==400){ // Regular. Note that regular must be set - the family wouldn't exist otherwise. return Regular.GetGlyph(charcode); }else{ // Find best weight match. Must also be not italic (this is why the bold set doesn't contain italic ones). face=BestWeight(Bold,weight,out match); } if(face==null || match!=0){ // We're synthesizing! if(face==null){ face=Regular; } // Derive from face. face=face.CreateSynthetic(italic,weight); } return face.GetGlyph(charcode); }
/// <summary>Loads the character array (<see cref="PowerUI.Css.TextRenderingProperty.Characters"/>) from the text string.</summary> public void SetText() { if (Text == null || FontToDraw == null) { // Can't do it just yet - we have no text/ font to use. return; } char[] characters = Text.ToCharArray(); Characters = new Glyph[characters.Length]; // Find the style ID for our properties: int fontStyle = Weight; if (Italic) { fontStyle |= 1; } FontFaceFlags fontStyleID = (FontFaceFlags)fontStyle; // The number of punctuation marks in a row that have been spotted. int punctuationCount = 0; // This goes true when we hit the first non-punctuation value in the word. bool endedStartPunctuation = false; StartPunctuationCount = 0; // Considered all whitespaces until shown otherwise. AllWhitespace = true; // Next, for each character, find its dynamic character. // At the same time we want to find out what dimensions this word has so it can be located correctly. Glyph previous = null; for (int i = 0; i < characters.Length; i++) { char rawChar = characters[i]; Glyph character = null; // Is it a unicode high/low surrogate pair? if (char.IsHighSurrogate(rawChar) && i != characters.Length - 1) { // Low surrogate follows: char lowChar = characters[i + 1]; // Get the full charcode: int charcode = char.ConvertToUtf32(rawChar, lowChar); // Grab the surrogate pair char: character = FontToDraw.GetCharacter(charcode, fontStyleID); // Make sure there is no char in the low surrogate spot: Characters[i + 1] = null; // Update this character: Characters[i] = character; // Skip the low surrogate: i++; } else { character = FontToDraw.GetCharacter((int)characters[i], fontStyleID); Characters[i] = character; } if (character == null) { continue; } if (previous != null) { // Look for a kern pair: if (character.Kerning != null) { float offset; if (character.Kerning.TryGetValue(previous, out offset)) { // Got a kern! if (Kerning == null) { Kerning = new float[characters.Length]; } Kerning[i] = offset; } } } previous = character; if (!character.Space || character.Image != null) { AllWhitespace = false; } if (character.Space || (!char.IsNumber((char)character.RawCharcode) && !char.IsLetter((char)character.RawCharcode))) { // Considered punctuation if it's not alphanumeric. punctuationCount++; } else { if (!endedStartPunctuation) { StartPunctuationCount = punctuationCount; endedStartPunctuation = true; } punctuationCount = 0; } } EndPunctuationCount = punctuationCount; // Update dimensions: SetDimensions(); // And finally request a redraw: RequestLayout(); }
/// <summary>Gets a displayable character as a surrogate pair from this font. Avoids checking for alternate providers.</summary> public Glyph GetCharacterDirect(int charcode,FontFaceFlags style){ Glyph result; if(Family!=null){ result=Family.GetGlyph(charcode,style); }else{ result=null; } if(result==null){ if(Fallback!=null){ result=Fallback.GetCharacterDirect(charcode,style); } // Global fallback - last chance! if(result==null){ if(DefaultFamily==null && !LoadInternalFont()){ // Font not found! return null; } return DefaultFamily.Family.GetGlyph(charcode,style); } } return result; }
/// <summary>Gets a displayable character as a surrogate pair from this font.</summary> /// <param name="lowCharacter">The low surrogate character to display.</param> /// <param name="highCharacter">The high surrogate character to display.</param> /// <param name="style">The style of the character.</param> /// <returns>The displayable character.</returns> public Glyph GetCharacter(int charcode,FontFaceFlags style){ // Is it e.g. emoji? Glyph result=CharacterProviders.Find(charcode); if(result!=null){ // Character has been overriden. return result; } if(Family!=null){ result=Family.GetGlyph(charcode,style); } if(result==null){ if(Fallback!=null){ result=Fallback.GetCharacterDirect(charcode,style); } // Global fallback - last chance! if(result==null){ if(DefaultFamily==null && !LoadInternalFont()){ // Font not found! return null; } return DefaultFamily.Family.GetGlyph(charcode,style); } } return result; }
//--------------------------------------