⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 173521 in webkit


Ignore:
Timestamp:
Sep 11, 2014, 11:29:43 AM (12 years ago)
Author:
mmaxfield@apple.com
Message:

Initial implementation of SVG to OTF font converter
​https://bugs.webkit.org/show_bug.cgi?id=136688

Patch by Myles C. Maxfield <​mmaxfield@apple.com> <​litherum@gmail.com> on 2014-09-11
Reviewed by Darin Adler.

This patch creates a new file and new function which turns an SVG font into an OpenType font.
This function is not very full featured, and as such is never called. However, it works with
fonts that only support simple horizontal basic multilingual plane codepoints. It has only
been tested on OS X, and does not have any automated tests. This patch is only jumping off
point, laying the basic groundwork for a more robust font converter.

The goal of this patch is to eventually allow us to delete the codepath with which we draw
text using SVG fonts. Using a native codepath instead will allow for better performance,
security, and code clarity. In my initial benchmarks, using this converter instead of the
SVG codepath is at least a 100x speed improvement (after running for 4 hours I stepped
away from my machine).

No new tests because the function is not ready to be called (yet!)
Initial implementation of SVG to OTF font converter
​https://bugs.webkit.org/show_bug.cgi?id=136688

  • WebCore.xcodeproj/project.pbxproj: Add new file.
  • svg/SVGPathBuilder.h: Single function. Takes a SVGFontElement and returns a byte
  • svg/SVGToOTFFontConversion.cpp: Added.

(WebCore::write32): Write a big-endian Int32.
(WebCore::write16): Write a big-endian Int16.
(WebCore::overwrite32): Overwrite an existing Int32 in a vector (instead of appending)
(WebCore::SVGToOTFFontConverter::GlyphData::GlyphData): Internal class to hold state during
function calls.
(WebCore::roundDownToPowerOfTwo):
(WebCore::SVGToOTFFontConverter::appendCMAPTable): See function name.
(WebCore::SVGToOTFFontConverter::appendHEADTable): Ditto.
(WebCore::clampTo): Used to clamp data types to fit into other data types.
(WebCore::SVGToOTFFontConverter::appendHHEATable): See function name.
(WebCore::SVGToOTFFontConverter::appendHMTXTable): Ditto.
(WebCore::SVGToOTFFontConverter::appendMAXPTable): Ditto.
(WebCore::SVGToOTFFontConverter::appendNAMETable): Ditto.
(WebCore::SVGToOTFFontConverter::appendOS2Table): Ditto.
(WebCore::SVGToOTFFontConverter::appendPOSTTable): Ditto.
(WebCore::isValidStringForCFF): The CFF font format only allows strings with particular
characters in them.
(WebCore::appendCFFValidString): Append a string assuming it's valid to append.
(WebCore::SVGToOTFFontConverter::appendCFFTable): See function name.
(WebCore::SVGToOTFFontConverter::appendVORGTable): Ditto.
(WebCore::writeCFFEncodedNumber): CFF has this wacky encoding scheme for encoding and
decoding numbers.
(WebCore::CFFBuilder::CFFBuilder): Subclass of SVGPathBuilder, which is used for building
CFF CharStrings (which are glyph path representations).
(WebCore::CFFBuilder::updateForConstituentPoint): Invoked for every point in a path, does
things like updates glyph bounding box information.
(WebCore::CFFBuilder::boundingBox): Getter.
(WebCore::transcodeGlyphPaths): SVG path data string -> CFF CharString
(WebCore::SVGToOTFFontConverter::SVGToOTFFontConverter): Generate internal state ahead of
time before generating any tables.
(WebCore::isFourByteAligned):
(WebCore::calculateChecksum): OTF files have checksums.
(WebCore::SVGToOTFFontConverter::appendTable): Invoked for each entry in the table of
contents of the OTF font.
(WebCore::SVGToOTFFontConverter::convertSVGToOTFFont): Write out the tables.
(WebCore::convertSVGToOTFFont): Entry point.

  • svg/SVGToOTFFontConversion.h: Added.
Location:
trunk/Source/WebCore
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r173520 r173521  
     12014-09-11  Myles C. Maxfield <mmaxfield@apple.com>  <litherum@gmail.com>
     2
     3        Initial implementation of SVG to OTF font converter
     4        https://bugs.webkit.org/show_bug.cgi?id=136688
     5
     6        Reviewed by Darin Adler.
     7
     8        This patch creates a new file and new function which turns an SVG font into an OpenType font.
     9        This function is not very full featured, and as such is never called. However, it works with
     10        fonts that only support simple horizontal basic multilingual plane codepoints. It has only
     11        been tested on OS X, and does not have any automated tests. This patch is only jumping off
     12        point, laying the basic groundwork for a more robust font converter.
     13
     14        The goal of this patch is to eventually allow us to delete the codepath with which we draw
     15        text using SVG fonts. Using a native codepath instead will allow for better performance,
     16        security, and code clarity. In my initial benchmarks, using this converter instead of the
     17        SVG codepath is at least a 100x speed improvement (after running for 4 hours I stepped
     18        away from my machine).
     19
     20        No new tests because the function is not ready to be called (yet!)
     21        Initial implementation of SVG to OTF font converter
     22        https://bugs.webkit.org/show_bug.cgi?id=136688
     23
     24        * WebCore.xcodeproj/project.pbxproj: Add new file.
     25        * svg/SVGPathBuilder.h: Single function. Takes a SVGFontElement and returns a byte
     26        * svg/SVGToOTFFontConversion.cpp: Added.
     27        (WebCore::write32): Write a big-endian Int32.
     28        (WebCore::write16): Write a big-endian Int16.
     29        (WebCore::overwrite32): Overwrite an existing Int32 in a vector (instead of appending)
     30        (WebCore::SVGToOTFFontConverter::GlyphData::GlyphData): Internal class to hold state during
     31        function calls.
     32        (WebCore::roundDownToPowerOfTwo):
     33        (WebCore::SVGToOTFFontConverter::appendCMAPTable): See function name.
     34        (WebCore::SVGToOTFFontConverter::appendHEADTable): Ditto.
     35        (WebCore::clampTo): Used to clamp data types to fit into other data types.
     36        (WebCore::SVGToOTFFontConverter::appendHHEATable): See function name.
     37        (WebCore::SVGToOTFFontConverter::appendHMTXTable): Ditto.
     38        (WebCore::SVGToOTFFontConverter::appendMAXPTable): Ditto.
     39        (WebCore::SVGToOTFFontConverter::appendNAMETable): Ditto.
     40        (WebCore::SVGToOTFFontConverter::appendOS2Table): Ditto.
     41        (WebCore::SVGToOTFFontConverter::appendPOSTTable): Ditto.
     42        (WebCore::isValidStringForCFF): The CFF font format only allows strings with particular
     43        characters in them.
     44        (WebCore::appendCFFValidString): Append a string assuming it's valid to append.
     45        (WebCore::SVGToOTFFontConverter::appendCFFTable): See function name.
     46        (WebCore::SVGToOTFFontConverter::appendVORGTable): Ditto.
     47        (WebCore::writeCFFEncodedNumber): CFF has this wacky encoding scheme for encoding and
     48        decoding numbers.
     49        (WebCore::CFFBuilder::CFFBuilder): Subclass of SVGPathBuilder, which is used for building
     50        CFF CharStrings (which are glyph path representations).
     51        (WebCore::CFFBuilder::updateForConstituentPoint): Invoked for every point in a path, does
     52        things like updates glyph bounding box information.
     53        (WebCore::CFFBuilder::boundingBox): Getter.
     54        (WebCore::transcodeGlyphPaths): SVG path data string -> CFF CharString
     55        (WebCore::SVGToOTFFontConverter::SVGToOTFFontConverter): Generate internal state ahead of
     56        time before generating any tables.
     57        (WebCore::isFourByteAligned):
     58        (WebCore::calculateChecksum): OTF files have checksums.
     59        (WebCore::SVGToOTFFontConverter::appendTable): Invoked for each entry in the table of
     60        contents of the OTF font.
     61        (WebCore::SVGToOTFFontConverter::convertSVGToOTFFont): Write out the tables.
     62        (WebCore::convertSVGToOTFFont): Entry point.
     63        * svg/SVGToOTFFontConversion.h: Added.
     64
    1652014-09-11  Jer Noble  <jer.noble@apple.com>
    266
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r173457 r173521  
    953953                1CB4214D0AF2B2CA0085AD91 /* DOMRangeInternal.h in Copy Generated Headers */ = {isa = PBXBuildFile; fileRef = 8538F05A0AD722F1006A81D1 /* DOMRangeInternal.h */; };
    954954                1CCA732210ADD44A00FD440D /* DOMHTMLInputElementPrivate.h in Copy Generated Headers */ = {isa = PBXBuildFile; fileRef = 1CCA732110ADD43E00FD440D /* DOMHTMLInputElementPrivate.h */; };
     955                1CCDF5BD1990332400BCEBAD /* SVGToOTFFontConversion.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1CCDF5BB1990332400BCEBAD /* SVGToOTFFontConversion.cpp */; };
     956                1CCDF5BE1990332400BCEBAD /* SVGToOTFFontConversion.h in Headers */ = {isa = PBXBuildFile; fileRef = 1CCDF5BC1990332400BCEBAD /* SVGToOTFFontConversion.h */; };
    955957                1CE83AC30ADAFFD7009354F6 /* DeleteButtonController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1C4C8EFF0AD85D87009475CE /* DeleteButtonController.cpp */; };
    956958                1CE83AC40ADAFFD8009354F6 /* DeleteButton.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1C4C8F630AD8655D009475CE /* DeleteButton.cpp */; };
    … …  
    78967898                1CAF34800A6C405200ABE06E /* WebScriptObjectPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebScriptObjectPrivate.h; sourceTree = "<group>"; };
    78977899                1CCA732110ADD43E00FD440D /* DOMHTMLInputElementPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOMHTMLInputElementPrivate.h; sourceTree = "<group>"; };
     7900                1CCDF5BB1990332400BCEBAD /* SVGToOTFFontConversion.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SVGToOTFFontConversion.cpp; sourceTree = "<group>"; };
     7901                1CCDF5BC1990332400BCEBAD /* SVGToOTFFontConversion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGToOTFFontConversion.h; sourceTree = "<group>"; };
    78987902                1CD0B6200AABDB5000D0A3FF /* PublicDOMInterfaces.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PublicDOMInterfaces.h; sourceTree = "<group>"; };
    78997903                1CDD45E40BA9C84600F90147 /* DebugRelease.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = DebugRelease.xcconfig; sourceTree = "<group>"; };
    … …  
    2016820172                                B2E4EC960D00C22B00432643 /* SVGZoomEvent.idl */,
    2016920173                                B28C6A260D00C44800334AA4 /* xlinkattrs.in */,
     20174                                1CCDF5BB1990332400BCEBAD /* SVGToOTFFontConversion.cpp */,
     20175                                1CCDF5BC1990332400BCEBAD /* SVGToOTFFontConversion.h */,
    2017020176                        );
    2017120177                        path = svg;
    … …  
    2497024976                                B27B28260CEF0C0700D39D54 /* JSSVGFontElement.h in Headers */,
    2497124977                                A83B79050CCAFF15000B0825 /* JSSVGFontFaceElement.h in Headers */,
     24978                                1CCDF5BE1990332400BCEBAD /* SVGToOTFFontConversion.h in Headers */,
    2497224979                                A83B79000CCAFF15000B0825 /* JSSVGFontFaceFormatElement.h in Headers */,
    2497324980                                A83B79020CCAFF15000B0825 /* JSSVGFontFaceNameElement.h in Headers */,
    … …  
    2697426981                                E1CDE92015018ED000862CC5 /* AsyncFileStream.cpp in Sources */,
    2697526982                                0FFD4D6018651FA300512F6E /* AsyncScrollingCoordinator.cpp in Sources */,
     26983                                1CCDF5BD1990332400BCEBAD /* SVGToOTFFontConversion.cpp in Sources */,
    2697626984                                A8C4A80E09D563270003AC8D /* Attr.cpp in Sources */,
    2697726985                                FD629EA4154B47160006D026 /* AudioBasicInspectorNode.cpp in Sources */,
  • trunk/Source/WebCore/svg/SVGPathBuilder.h

    r163440 r173521  
    3838    void setCurrentPath(Path* path) { m_path = path; }
    3939
     40protected:
     41    FloatPoint m_current;
     42
    4043private:
    4144    virtual void incrementPathSegmentCount() override { }
    … …  
    5861
    5962    Path* m_path;
    60     FloatPoint m_current;
    6163};
    6264
Note: See TracChangeset for help on using the changeset viewer.