Mozilla2:GFXTextRun: Difference between revisions
		
		
		
		
		
		Jump to navigation
		Jump to search
		
				
		
		
	
| Line 28: | Line 28: | ||
   // Set the spacing between clusters. For each character index i that is  |    // Set the spacing between clusters. For each character index i that is  | ||
   // the start of a cluster, spacingArray[i] is the amount of space to insert  |    // the start of a cluster, spacingArray[i] is the amount of space to insert  | ||
   // before that cluster (possibly negative). For each character index i that  |    // before that cluster (possibly negative) (i.e. between this cluster  | ||
  // and the cluster containing the previous character in the string).  | |||
  // For each character index i that is not the start of a cluster,  | |||
  // spacingArray[i] must be zero. spacingArray[0] must be zero.  | |||
   void SetSpacing(gfxFloat* spacingArray);  |    void SetSpacing(gfxFloat* spacingArray);  | ||
Revision as of 00:34, 12 October 2005
Class gfxTextRun
/**
 * A class representing a single span of styled text.
 * It assumes that the text is laid out along a straight line with the glyphs
 * oriented normally with respect to the baseline.
 */
class gfxTextRun {
  // these do not copy the text
  gfxTextRun(const char* ASCII, int length, nsFontMetrics* font, nsIAtom* language);
  gfxTextRun(const PRUnichar* unicode, int length, nsFontMetrics* font, nsIAtom* language);
  enum { ClusterStart = 0x1 } CharFlags;
  // ClusterStart: character is the first character of a cluster
  // Get the flags for each character in a substring. 'flags' is an array
  // of length 'len'
  void GetCharacterFlags(int pos, int len, CharFlags* flags);
  // Set whether or not this text run starts/ends a word
  void SetWordStartEnd(PRBool startsWord, PRBool endsWord);
  // Set whether or not this text run starts/ends a line
  void SetLineStartEnd(PRBool startsLine, PRBool endsLine);
  // Set the spacing between clusters. For each character index i that is
  // the start of a cluster, spacingArray[i] is the amount of space to insert
  // before that cluster (possibly negative) (i.e. between this cluster
  // and the cluster containing the previous character in the string).
  // For each character index i that is not the start of a cluster,
  // spacingArray[i] must be zero. spacingArray[0] must be zero.
  void SetSpacing(gfxFloat* spacingArray);
         
  // The substring must not contain any partial clusters. 'pt' is the
  // the baseline of the visually left edge of the visually leftmost cluster.
  void Draw(gfxContext* ctx, gfxPoint& pt, int pos, int len);
  struct Dimensions {
    // start of the substring relative to the origin of the whole string
    gfxFloat xOffset;
    // width of the substring;
    gfxFloat width;
    // font ascent and descent for this substring
    gfxFloat ascent, descent;
    // the bounding box of area actually rendered by the glyphs in the
    // substring, relative to the origin of the whole string; if this can't
    // be accurately determined, then at least this must contain the true
    // bounding box
    gfxRect boundingBox;
  };
  // The substring must not contain any partial clusters
  Dimensions MeasureText(int pos, int len);
  // Compute how many characters from this string starting at
  // character 'pos' and up to length 'len' fit
  // into the given width. A break is allowed before character i
  // wherever breaks[i] is nonzero, i.e., if the result of GetCharsFit
  // is i then breaks[i] is nonzero.
  // We will usually want to call MeasureText right afterwards,
  // the implementor could optimize for that.
  // The substring must not contain any partial clusters
  int GetCharsFit(int pos, int len, gfxFloat width, PRUint8* breaks);
  // Return the index of the character selected if the user clicks the
  // mouse at point pt. If the point is exactly between two characters,
  // if preferLeft is true then return the character visually to the left
  // (as if pt.x had been smaller) if there is one, otherwise return the
  // character visually to the right. If the point is before the start of
  // the string, return -1. If the point is beyond the end of the string,
  // return the full string length.
  int GetPositionInString(gfxPoint& pt, PRBool preferLeft);
};