[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677

darin darin at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 06:16:36 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit 35ba201e7e80e9412ad2967a04c0212d69fd2c20
Author: darin <darin at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Tue Jun 4 17:09:28 2002 +0000

    	Moved the string truncator class here from WebBrowser so we don't have to
    	export our text machinery.
    
    	* WebKit.pbproj/project.pbxproj:
    	* Misc.subproj/IFStringTruncator.h: Added.
    	* Misc.subproj/IFStringTruncator.m: Added.
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@1262 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebKit/ChangeLog b/WebKit/ChangeLog
index d2e118b..088348f 100644
--- a/WebKit/ChangeLog
+++ b/WebKit/ChangeLog
@@ -1,3 +1,12 @@
+2002-06-04  Darin Adler  <darin at apple.com>
+
+	Moved the string truncator class here from WebBrowser so we don't have to
+	export our text machinery.
+
+	* WebKit.pbproj/project.pbxproj:
+	* Misc.subproj/IFStringTruncator.h: Added.
+	* Misc.subproj/IFStringTruncator.m: Added.
+
 2002-06-03  Darin Adler  <darin at apple.com>
 
 	* WebCoreSupport.subproj/IFImageRenderer.m:
diff --git a/WebKit/ChangeLog-2002-12-03 b/WebKit/ChangeLog-2002-12-03
index d2e118b..088348f 100644
--- a/WebKit/ChangeLog-2002-12-03
+++ b/WebKit/ChangeLog-2002-12-03
@@ -1,3 +1,12 @@
+2002-06-04  Darin Adler  <darin at apple.com>
+
+	Moved the string truncator class here from WebBrowser so we don't have to
+	export our text machinery.
+
+	* WebKit.pbproj/project.pbxproj:
+	* Misc.subproj/IFStringTruncator.h: Added.
+	* Misc.subproj/IFStringTruncator.m: Added.
+
 2002-06-03  Darin Adler  <darin at apple.com>
 
 	* WebCoreSupport.subproj/IFImageRenderer.m:
diff --git a/WebKit/Misc.subproj/IFStringTruncator.h b/WebKit/Misc.subproj/IFStringTruncator.h
new file mode 100644
index 0000000..ac97638
--- /dev/null
+++ b/WebKit/Misc.subproj/IFStringTruncator.h
@@ -0,0 +1,22 @@
+//
+//  IFStringTruncator.h
+//
+//  Created by Darin Adler on Fri May 10 2002.
+//  Copyright (c) 2002 Apple Computer, Inc. All rights reserved.
+//
+//  Complete rewrite with API similar to slow truncator by Al Dul
+
+#import <Foundation/Foundation.h>
+
+ at class NSFont;
+
+ at interface IFStringTruncator : NSObject
+{
+}
+
++ (NSString *)centerTruncateString:(NSString *)string toWidth:(float)maxWidth withFont:(NSFont *)font;
+
+// Default font is [NSFont menuFontOfSize:0].
++ (NSString *)centerTruncateString:(NSString *)string toWidth:(float)maxWidth;
+
+ at end
diff --git a/WebKit/Misc.subproj/IFStringTruncator.m b/WebKit/Misc.subproj/IFStringTruncator.m
new file mode 100644
index 0000000..48927b6
--- /dev/null
+++ b/WebKit/Misc.subproj/IFStringTruncator.m
@@ -0,0 +1,164 @@
+//
+//  IFStringTruncator.m
+//
+//  Created by Darin Adler on Fri May 10 2002.
+//  Copyright (c) 2002 Apple Computer, Inc. All rights reserved.
+//
+//  Complete rewrite with API similar to slow truncator by Al Dul
+
+#import <WebKit/IFStringTruncator.h>
+#import <Cocoa/Cocoa.h>
+
+#import <WebKit/WebKitDebug.h>
+#import <WebKit/IFTextRendererFactory.h>
+#import <WebKit/IFTextRenderer.h>
+
+#define STRING_BUFFER_SIZE 2048
+#define ELLIPSIS_CHARACTER 0x2026
+
+static NSFont *currentFont;
+static IFTextRenderer *currentRenderer;
+static float currentEllipsisWidth;
+
+ at implementation IFStringTruncator
+
++ (unsigned)centerTruncateString:(NSString *)string length:(unsigned)length keepCount:(unsigned)keepCount toBuffer:(unichar *)buffer
+{
+    unsigned omitStart;
+    NSRange omitEndRange, beforeRange, afterRange;
+    unsigned truncatedLength;
+    
+    WEBKIT_ASSERT(keepCount < STRING_BUFFER_SIZE);
+    
+    omitStart = (keepCount + 1) / 2;
+    
+    omitEndRange = [string rangeOfComposedCharacterSequenceAtIndex:omitStart + (length - keepCount) - 1];
+    
+    beforeRange.location = 0;
+    beforeRange.length = [string rangeOfComposedCharacterSequenceAtIndex:omitStart].location;
+    
+    afterRange.location = omitEndRange.location + omitEndRange.length;
+    afterRange.length = length - afterRange.location;
+    
+    truncatedLength = beforeRange.length + 1 + afterRange.length;
+    WEBKIT_ASSERT(truncatedLength <= length);
+
+    [string getCharacters:buffer range:beforeRange];
+    buffer[beforeRange.length] = ELLIPSIS_CHARACTER;
+    [string getCharacters:&buffer[beforeRange.length + 1] range:afterRange];
+    
+    return truncatedLength;
+}
+
++ (NSString *)centerTruncateString:(NSString *)string toWidth:(float)maxWidth
+{
+    return [self centerTruncateString:string toWidth:maxWidth withFont:[NSFont menuFontOfSize:0]];
+}
+
++ (NSString *)centerTruncateString:(NSString *)string toWidth:(float)maxWidth withFont:(NSFont *)font
+{
+    unichar stringBuffer[STRING_BUFFER_SIZE];
+    unsigned length;
+    unsigned keepCount;
+    unsigned truncatedLength;
+    float width;
+    unichar ellipsis;
+    unsigned keepCountForLargestKnownToFit, keepCountForSmallestKnownToNotFit;
+    float widthForLargestKnownToFit, widthForSmallestKnownToNotFit;
+    float ratio;
+    
+    WEBKIT_ASSERT_VALID_ARG(font, font);
+    WEBKIT_ASSERT_VALID_ARG(maxWidth, maxWidth >= 0);
+    
+    if (![currentFont isEqual:font]) {
+        [currentFont release];
+        currentFont = [font retain];
+        [currentRenderer release];
+        [IFTextRendererFactory createSharedFactory];
+        currentRenderer = [[[IFTextRendererFactory sharedFactory] rendererWithFont:font] retain];
+        ellipsis = ELLIPSIS_CHARACTER;
+        currentEllipsisWidth = [currentRenderer floatWidthForCharacters:&ellipsis length:1];
+    }
+    
+    WEBKIT_ASSERT(currentRenderer);
+
+    length = [string length];
+    if (length > STRING_BUFFER_SIZE) {
+        keepCount = STRING_BUFFER_SIZE - 1; // need 1 character for the ellipsis
+        truncatedLength = [self centerTruncateString:string
+                                             length:length
+                                          keepCount:keepCount
+                                           toBuffer:stringBuffer];
+    } else {
+        keepCount = length;
+        [string getCharacters:stringBuffer];
+        truncatedLength = length;
+    }
+
+    width = [currentRenderer floatWidthForCharacters:stringBuffer
+                                              length:truncatedLength];
+    if (width <= maxWidth) {
+        return string;
+    }
+
+    keepCountForLargestKnownToFit = 0;
+    widthForLargestKnownToFit = currentEllipsisWidth;
+    
+    keepCountForSmallestKnownToNotFit = keepCount;
+    widthForSmallestKnownToNotFit = width;
+    
+    if (currentEllipsisWidth >= maxWidth) {
+        keepCountForLargestKnownToFit = 1;
+        keepCountForSmallestKnownToNotFit = 2;
+    }
+    
+    while (keepCountForLargestKnownToFit + 1 < keepCountForSmallestKnownToNotFit) {
+        WEBKIT_ASSERT(widthForLargestKnownToFit <= maxWidth);
+        WEBKIT_ASSERT(widthForSmallestKnownToNotFit > maxWidth);
+
+        ratio = (keepCountForSmallestKnownToNotFit - keepCountForLargestKnownToFit)
+            / (widthForSmallestKnownToNotFit - widthForLargestKnownToFit);
+        keepCount = maxWidth * ratio;
+        
+        if (keepCount <= keepCountForLargestKnownToFit) {
+            keepCount = keepCountForLargestKnownToFit + 1;
+        } else if (keepCount >= keepCountForSmallestKnownToNotFit) {
+            keepCount = keepCountForSmallestKnownToNotFit - 1;
+        }
+        
+        WEBKIT_ASSERT(keepCount < length);
+        WEBKIT_ASSERT(keepCount > 0);
+        WEBKIT_ASSERT(keepCount < keepCountForSmallestKnownToNotFit);
+        WEBKIT_ASSERT(keepCount > keepCountForLargestKnownToFit);
+        
+	truncatedLength = [self centerTruncateString:string
+                                              length:length
+                                           keepCount:keepCount
+                                            toBuffer:stringBuffer];
+        
+        width = [currentRenderer floatWidthForCharacters:stringBuffer length:truncatedLength];
+        if (width <= maxWidth) {
+            keepCountForLargestKnownToFit = keepCount;
+            widthForLargestKnownToFit = width;
+        } else {
+            keepCountForSmallestKnownToNotFit = keepCount;
+            widthForSmallestKnownToNotFit = width;
+        }
+    }
+    
+    if (keepCountForLargestKnownToFit == 0) {
+        keepCountForLargestKnownToFit = 1;
+    }
+    
+    if (keepCount != keepCountForLargestKnownToFit) {
+        keepCount = keepCountForLargestKnownToFit;
+	truncatedLength = [self centerTruncateString:string
+                                              length:length
+                                           keepCount:keepCount
+                                            toBuffer:stringBuffer];
+    }
+        
+    return [NSString stringWithCharacters:stringBuffer length:truncatedLength];
+}
+
+ at end
diff --git a/WebKit/Misc.subproj/WebStringTruncator.h b/WebKit/Misc.subproj/WebStringTruncator.h
new file mode 100644
index 0000000..ac97638
--- /dev/null
+++ b/WebKit/Misc.subproj/WebStringTruncator.h
@@ -0,0 +1,22 @@
+//
+//  IFStringTruncator.h
+//
+//  Created by Darin Adler on Fri May 10 2002.
+//  Copyright (c) 2002 Apple Computer, Inc. All rights reserved.
+//
+//  Complete rewrite with API similar to slow truncator by Al Dul
+
+#import <Foundation/Foundation.h>
+
+ at class NSFont;
+
+ at interface IFStringTruncator : NSObject
+{
+}
+
++ (NSString *)centerTruncateString:(NSString *)string toWidth:(float)maxWidth withFont:(NSFont *)font;
+
+// Default font is [NSFont menuFontOfSize:0].
++ (NSString *)centerTruncateString:(NSString *)string toWidth:(float)maxWidth;
+
+ at end
diff --git a/WebKit/Misc.subproj/WebStringTruncator.m b/WebKit/Misc.subproj/WebStringTruncator.m
new file mode 100644
index 0000000..48927b6
--- /dev/null
+++ b/WebKit/Misc.subproj/WebStringTruncator.m
@@ -0,0 +1,164 @@
+//
+//  IFStringTruncator.m
+//
+//  Created by Darin Adler on Fri May 10 2002.
+//  Copyright (c) 2002 Apple Computer, Inc. All rights reserved.
+//
+//  Complete rewrite with API similar to slow truncator by Al Dul
+
+#import <WebKit/IFStringTruncator.h>
+#import <Cocoa/Cocoa.h>
+
+#import <WebKit/WebKitDebug.h>
+#import <WebKit/IFTextRendererFactory.h>
+#import <WebKit/IFTextRenderer.h>
+
+#define STRING_BUFFER_SIZE 2048
+#define ELLIPSIS_CHARACTER 0x2026
+
+static NSFont *currentFont;
+static IFTextRenderer *currentRenderer;
+static float currentEllipsisWidth;
+
+ at implementation IFStringTruncator
+
++ (unsigned)centerTruncateString:(NSString *)string length:(unsigned)length keepCount:(unsigned)keepCount toBuffer:(unichar *)buffer
+{
+    unsigned omitStart;
+    NSRange omitEndRange, beforeRange, afterRange;
+    unsigned truncatedLength;
+    
+    WEBKIT_ASSERT(keepCount < STRING_BUFFER_SIZE);
+    
+    omitStart = (keepCount + 1) / 2;
+    
+    omitEndRange = [string rangeOfComposedCharacterSequenceAtIndex:omitStart + (length - keepCount) - 1];
+    
+    beforeRange.location = 0;
+    beforeRange.length = [string rangeOfComposedCharacterSequenceAtIndex:omitStart].location;
+    
+    afterRange.location = omitEndRange.location + omitEndRange.length;
+    afterRange.length = length - afterRange.location;
+    
+    truncatedLength = beforeRange.length + 1 + afterRange.length;
+    WEBKIT_ASSERT(truncatedLength <= length);
+
+    [string getCharacters:buffer range:beforeRange];
+    buffer[beforeRange.length] = ELLIPSIS_CHARACTER;
+    [string getCharacters:&buffer[beforeRange.length + 1] range:afterRange];
+    
+    return truncatedLength;
+}
+
++ (NSString *)centerTruncateString:(NSString *)string toWidth:(float)maxWidth
+{
+    return [self centerTruncateString:string toWidth:maxWidth withFont:[NSFont menuFontOfSize:0]];
+}
+
++ (NSString *)centerTruncateString:(NSString *)string toWidth:(float)maxWidth withFont:(NSFont *)font
+{
+    unichar stringBuffer[STRING_BUFFER_SIZE];
+    unsigned length;
+    unsigned keepCount;
+    unsigned truncatedLength;
+    float width;
+    unichar ellipsis;
+    unsigned keepCountForLargestKnownToFit, keepCountForSmallestKnownToNotFit;
+    float widthForLargestKnownToFit, widthForSmallestKnownToNotFit;
+    float ratio;
+    
+    WEBKIT_ASSERT_VALID_ARG(font, font);
+    WEBKIT_ASSERT_VALID_ARG(maxWidth, maxWidth >= 0);
+    
+    if (![currentFont isEqual:font]) {
+        [currentFont release];
+        currentFont = [font retain];
+        [currentRenderer release];
+        [IFTextRendererFactory createSharedFactory];
+        currentRenderer = [[[IFTextRendererFactory sharedFactory] rendererWithFont:font] retain];
+        ellipsis = ELLIPSIS_CHARACTER;
+        currentEllipsisWidth = [currentRenderer floatWidthForCharacters:&ellipsis length:1];
+    }
+    
+    WEBKIT_ASSERT(currentRenderer);
+
+    length = [string length];
+    if (length > STRING_BUFFER_SIZE) {
+        keepCount = STRING_BUFFER_SIZE - 1; // need 1 character for the ellipsis
+        truncatedLength = [self centerTruncateString:string
+                                             length:length
+                                          keepCount:keepCount
+                                           toBuffer:stringBuffer];
+    } else {
+        keepCount = length;
+        [string getCharacters:stringBuffer];
+        truncatedLength = length;
+    }
+
+    width = [currentRenderer floatWidthForCharacters:stringBuffer
+                                              length:truncatedLength];
+    if (width <= maxWidth) {
+        return string;
+    }
+
+    keepCountForLargestKnownToFit = 0;
+    widthForLargestKnownToFit = currentEllipsisWidth;
+    
+    keepCountForSmallestKnownToNotFit = keepCount;
+    widthForSmallestKnownToNotFit = width;
+    
+    if (currentEllipsisWidth >= maxWidth) {
+        keepCountForLargestKnownToFit = 1;
+        keepCountForSmallestKnownToNotFit = 2;
+    }
+    
+    while (keepCountForLargestKnownToFit + 1 < keepCountForSmallestKnownToNotFit) {
+        WEBKIT_ASSERT(widthForLargestKnownToFit <= maxWidth);
+        WEBKIT_ASSERT(widthForSmallestKnownToNotFit > maxWidth);
+
+        ratio = (keepCountForSmallestKnownToNotFit - keepCountForLargestKnownToFit)
+            / (widthForSmallestKnownToNotFit - widthForLargestKnownToFit);
+        keepCount = maxWidth * ratio;
+        
+        if (keepCount <= keepCountForLargestKnownToFit) {
+            keepCount = keepCountForLargestKnownToFit + 1;
+        } else if (keepCount >= keepCountForSmallestKnownToNotFit) {
+            keepCount = keepCountForSmallestKnownToNotFit - 1;
+        }
+        
+        WEBKIT_ASSERT(keepCount < length);
+        WEBKIT_ASSERT(keepCount > 0);
+        WEBKIT_ASSERT(keepCount < keepCountForSmallestKnownToNotFit);
+        WEBKIT_ASSERT(keepCount > keepCountForLargestKnownToFit);
+        
+	truncatedLength = [self centerTruncateString:string
+                                              length:length
+                                           keepCount:keepCount
+                                            toBuffer:stringBuffer];
+        
+        width = [currentRenderer floatWidthForCharacters:stringBuffer length:truncatedLength];
+        if (width <= maxWidth) {
+            keepCountForLargestKnownToFit = keepCount;
+            widthForLargestKnownToFit = width;
+        } else {
+            keepCountForSmallestKnownToNotFit = keepCount;
+            widthForSmallestKnownToNotFit = width;
+        }
+    }
+    
+    if (keepCountForLargestKnownToFit == 0) {
+        keepCountForLargestKnownToFit = 1;
+    }
+    
+    if (keepCount != keepCountForLargestKnownToFit) {
+        keepCount = keepCountForLargestKnownToFit;
+	truncatedLength = [self centerTruncateString:string
+                                              length:length
+                                           keepCount:keepCount
+                                            toBuffer:stringBuffer];
+    }
+        
+    return [NSString stringWithCharacters:stringBuffer length:truncatedLength];
+}
+
+ at end
diff --git a/WebKit/WebKit.pbproj/project.pbxproj b/WebKit/WebKit.pbproj/project.pbxproj
index d25b5ff..c7f133f 100644
--- a/WebKit/WebKit.pbproj/project.pbxproj
+++ b/WebKit/WebKit.pbproj/project.pbxproj
@@ -243,6 +243,7 @@
 				F83DCC73029D09F301000131,
 				9CE1F8A402A5C6F30ECA2ACD,
 				9CE1F8A602A5C6F30ECA2ACD,
+				F59668CA02AD2923018635CA,
 			);
 			isa = PBXHeadersBuildPhase;
 		};
@@ -308,6 +309,7 @@
 				F83DCC74029D09F301000131,
 				9CE1F8A502A5C6F30ECA2ACD,
 				9CE1F8A702A5C6F30ECA2ACD,
+				F59668CB02AD2923018635CA,
 			);
 			isa = PBXSourcesBuildPhase;
 		};
@@ -393,6 +395,8 @@
 				25A5593201A5996D0ECA149E,
 				F59EAE3E0253C7EE018635CA,
 				F59EAE410253C8DE018635CA,
+				F59668C802AD2923018635CA,
+				F59668C902AD2923018635CA,
 			);
 			isa = PBXGroup;
 			name = "Other Sources";
@@ -1405,6 +1409,30 @@
 			isa = PBXBuildStyle;
 			name = Unoptimized;
 		};
+		F59668C802AD2923018635CA = {
+			isa = PBXFileReference;
+			name = IFStringTruncator.h;
+			path = Misc.subproj/IFStringTruncator.h;
+			refType = 4;
+		};
+		F59668C902AD2923018635CA = {
+			isa = PBXFileReference;
+			name = IFStringTruncator.m;
+			path = Misc.subproj/IFStringTruncator.m;
+			refType = 4;
+		};
+		F59668CA02AD2923018635CA = {
+			fileRef = F59668C802AD2923018635CA;
+			isa = PBXBuildFile;
+			settings = {
+			};
+		};
+		F59668CB02AD2923018635CA = {
+			fileRef = F59668C902AD2923018635CA;
+			isa = PBXBuildFile;
+			settings = {
+			};
+		};
 		F599A817028C6D0D0124FDD6 = {
 			isa = PBXFileReference;
 			name = bookmark_folder.tiff;

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list