void CalculateCharWidthRange(IntPtr hDC, uint firstChar, uint numChars) { Win32FontSystem.ABCFLOAT[] values = new Win32FontSystem.ABCFLOAT[numChars]; Win32FontSystem.GetCharABCWidthsFloat(hDC, firstChar, firstChar + numChars - 1, values); for (uint i = 0; i < numChars; i++) { Debug.Assert(!_charWidths.ContainsKey(i + firstChar)); _charWidths[i + firstChar] = values[i]; } }
public float[] GetCharacterXPositions(Graphics g, string str) { #if true // Make sure our _charWidths list has all the necessary characters. using (GdiObjectSelector selector = new GdiObjectSelector(g, _font)) { UpdateCharWidths(selector.HDC, str); } float[] xCoords = new float[str.Length]; float curXOffset = 0; for (int i = 0; i < str.Length; i++) { xCoords[i] = curXOffset; Win32FontSystem.ABCFLOAT abc = _charWidths[(uint)str[i]]; curXOffset += abc.abcfA + abc.abcfB + abc.abcfC; } return(xCoords); #else // This method gives us spacing between character cells, but it doesn't tell us what the cells are! Win32FontSystem.GCP_RESULTS results = new Win32FontSystem.GCP_RESULTS(); results.StructSize = Marshal.SizeOf(typeof(Win32FontSystem.GCP_RESULTS)); // Setup the int array for them to write results into. int[] dx = new int[str.Length]; GCHandle handle = GCHandle.Alloc(dx, GCHandleType.Pinned); results.Dx = Marshal.UnsafeAddrOfPinnedArrayElement(dx, 0); using (GdiObjectSelector selector = new GdiObjectSelector(g, _font)) { // Call GetCharacterPlacement Win32FontSystem.GetCharacterPlacementW( selector.HDC, str, str.Length, 0, // max extent (ignored) ref results, (uint)Win32FontSystem.GCPFlags.GCP_USEKERNING); } // Unpin the array. handle.Free(); // Convert to floats for output. return(dx.Select(x => (float)x).ToArray()); #endif }
void CalculateCharWidthRange( IntPtr hDC, uint firstChar, uint numChars ) { Win32FontSystem.ABCFLOAT[] values = new Win32FontSystem.ABCFLOAT[numChars]; Win32FontSystem.GetCharABCWidthsFloat( hDC, firstChar, firstChar + numChars - 1, values ); for ( uint i=0; i < numChars; i++ ) { Debug.Assert( !_charWidths.ContainsKey( i + firstChar ) ); _charWidths[i + firstChar] = values[i]; } }