Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(210)

Side by Side Diff: third_party/go/src/golang.org/x/mobile/font/font_darwin.go

Issue 1275153002: Remove third_party/golang.org/x/mobile as it is no longer used with Go 1.5. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Remove golang.org/x/mobile Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package font
6
7 /*
8 #cgo darwin LDFLAGS: -framework CoreFoundation -framework CoreText
9 #include <CoreFoundation/CFArray.h>
10 #include <CoreFoundation/CFBase.h>
11 #include <CoreFoundation/CFData.h>
12 #include <CoreText/CTFont.h>
13 */
14 import "C"
15 import "unsafe"
16
17 func buildFont(f C.CTFontRef) []byte {
18 ctags := C.CTFontCopyAvailableTables(f, C.kCTFontTableOptionExcludeSynth etic)
19 tagsCount := C.CFArrayGetCount(ctags)
20
21 var tags []uint32
22 var dataRefs []C.CFDataRef
23 var dataLens []uint32
24
25 for i := C.CFIndex(0); i < tagsCount; i++ {
26 tag := (C.CTFontTableTag)((uintptr)(C.CFArrayGetValueAtIndex(cta gs, i)))
27 dataRef := C.CTFontCopyTable(f, tag, 0) // retained
28 tags = append(tags, uint32(tag))
29 dataRefs = append(dataRefs, dataRef)
30 dataLens = append(dataLens, uint32(C.CFDataGetLength(dataRef)))
31 }
32
33 totalLen := 0
34 for _, l := range dataLens {
35 totalLen += int(l)
36 }
37
38 // Big-endian output.
39 buf := make([]byte, 0, 12+16*len(tags)+totalLen)
40 write16 := func(x uint16) { buf = append(buf, byte(x>>8), byte(x)) }
41 write32 := func(x uint32) { buf = append(buf, byte(x>>24), byte(x>>16), byte(x>>8), byte(x)) }
42
43 // File format description: http://www.microsoft.com/typography/otspec/o tff.htm
44 write32(0x00010000) // version 1.0
45 write16(uint16(len(tags))) // numTables
46 write16(0) // searchRange
47 write16(0) // entrySelector
48 write16(0) // rangeShift
49
50 // Table tags, includes offsets into following data segments.
51 offset := uint32(12 + 16*len(tags)) // offset starts after table tags
52 for i, tag := range tags {
53 write32(tag)
54 write32(0)
55 write32(offset)
56 write32(dataLens[i])
57 offset += dataLens[i]
58 }
59
60 // Data segments.
61 for i, dataRef := range dataRefs {
62 data := (*[1<<31 - 2]byte)((unsafe.Pointer)(C.CFDataGetBytePtr(d ataRef)))[:dataLens[i]]
63 buf = append(buf, data...)
64 C.CFRelease(C.CFTypeRef(dataRef))
65 }
66
67 return buf
68 }
69
70 func buildDefault() ([]byte, error) {
71 return buildFont(C.CTFontCreateUIFontForLanguage(C.kCTFontSystemFontType , 0, nil)), nil
72 }
73
74 func buildMonospace() ([]byte, error) {
75 return buildFont(C.CTFontCreateUIFontForLanguage(C.kCTFontUserFixedPitch FontType, 0, nil)), nil
76 }
OLDNEW
« no previous file with comments | « third_party/go/src/golang.org/x/mobile/font/font_android.go ('k') | third_party/go/src/golang.org/x/mobile/font/font_linux.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698