2022-03-04 20:28:38 +01:00
|
|
|
Class {
|
|
|
|
#name : #OpenGLFontTex,
|
|
|
|
#superclass : #OpenGLTexImage2D,
|
|
|
|
#instVars : [
|
2022-03-06 00:58:28 +01:00
|
|
|
'charmap',
|
|
|
|
'cellw',
|
2022-03-06 18:33:10 +01:00
|
|
|
'cellh',
|
2022-03-16 21:33:35 +01:00
|
|
|
'spacing',
|
2022-03-17 00:32:19 +01:00
|
|
|
'fontSize',
|
|
|
|
'colp',
|
|
|
|
'rowp',
|
|
|
|
'face',
|
|
|
|
'maxbearing',
|
2022-03-21 01:45:21 +01:00
|
|
|
'maxrows',
|
|
|
|
'meanww'
|
2022-03-04 20:28:38 +01:00
|
|
|
],
|
|
|
|
#pools : [
|
|
|
|
'OpenGLConstants',
|
|
|
|
'OpenGLTypes'
|
|
|
|
],
|
|
|
|
#category : #'Diya-Fonts'
|
|
|
|
}
|
|
|
|
|
|
|
|
{ #category : #'instance creation' }
|
2022-03-06 00:58:28 +01:00
|
|
|
OpenGLFontTex class >> fromFace: face ofSize: size [
|
|
|
|
^self new fromFace: face ofSize: size; yourself
|
2022-03-04 20:28:38 +01:00
|
|
|
]
|
|
|
|
|
2022-08-14 15:42:59 +02:00
|
|
|
{ #category : #processing }
|
2022-03-06 00:58:28 +01:00
|
|
|
OpenGLFontTex >> blitPixel8: bitmap at: offset size: size [
|
|
|
|
size = (0@0) ifTrue:[^self].
|
|
|
|
0 to: size y - 1 do: [ :i|
|
|
|
|
LibC memCopy: (bitmap getHandle + (i* (size x))) to:(data getHandle + ((i + offset y) * width + (offset x) )) size: size x
|
2022-03-16 21:33:35 +01:00
|
|
|
].
|
2022-03-04 20:28:38 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
2022-03-06 00:58:28 +01:00
|
|
|
OpenGLFontTex >> cellh [
|
|
|
|
^ cellh
|
2022-03-04 20:28:38 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
2022-03-06 00:58:28 +01:00
|
|
|
OpenGLFontTex >> cellw [
|
|
|
|
^ cellw
|
2022-03-04 20:28:38 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
2022-03-06 00:58:28 +01:00
|
|
|
OpenGLFontTex >> charmap [
|
|
|
|
^ charmap
|
|
|
|
]
|
|
|
|
|
2022-03-06 18:33:10 +01:00
|
|
|
{ #category : #accessing }
|
|
|
|
OpenGLFontTex >> drop [
|
|
|
|
OpenGL
|
2022-08-14 15:42:59 +02:00
|
|
|
pixelstorei: GL_UNPACK_ALIGNMENT param: 4";
|
2022-03-06 18:33:10 +01:00
|
|
|
disable: GL_CULL_FACE;
|
2022-08-14 15:42:59 +02:00
|
|
|
disable: GL_BLEND".
|
2022-03-06 18:33:10 +01:00
|
|
|
]
|
|
|
|
|
2022-03-16 21:33:35 +01:00
|
|
|
{ #category : #accessing }
|
|
|
|
OpenGLFontTex >> fontSize [
|
|
|
|
^ fontSize
|
|
|
|
]
|
|
|
|
|
2022-03-06 00:58:28 +01:00
|
|
|
{ #category : #'instance creation' }
|
2022-03-17 00:32:19 +01:00
|
|
|
OpenGLFontTex >> fromFace: aFace ofSize: size [
|
2022-03-21 01:45:21 +01:00
|
|
|
|minhang rec iptr charcode w numw|
|
2022-03-16 21:33:35 +01:00
|
|
|
fontSize := size.
|
2022-03-17 00:32:19 +01:00
|
|
|
face := aFace.
|
2022-08-14 15:42:59 +02:00
|
|
|
commited := false.
|
|
|
|
name := aFace familyName, '@', aFace styleName,'@', size asString.
|
2022-03-17 00:32:19 +01:00
|
|
|
charmap := Dictionary new.
|
|
|
|
face setPixelWidth:0 height: self fontSize.
|
|
|
|
cellw := cellh := minhang := maxbearing := 0.
|
2022-03-16 21:33:35 +01:00
|
|
|
iptr := FFIExternalArray externalNewType: GLuint size:1.
|
|
|
|
iptr at:1 put: 0.
|
2022-03-06 00:58:28 +01:00
|
|
|
rec := (FTFaceRec fromHandle: face getHandle).
|
2022-03-16 21:33:35 +01:00
|
|
|
charcode := face getFirstChar: iptr getHandle.
|
2022-03-21 01:45:21 +01:00
|
|
|
meanww := 0.
|
|
|
|
numw := 0.
|
2022-03-16 21:33:35 +01:00
|
|
|
[ (iptr at: 1) = 0 ] whileFalse: [
|
|
|
|
face loadCharacter: charcode flags: (1 << 2).
|
|
|
|
w := ((rec glyph metrics width) >> 6).
|
|
|
|
(w > (size << 1)) ifFalse:[
|
|
|
|
maxbearing := maxbearing max: ((rec glyph metrics horiBearingY) >> 6).
|
|
|
|
cellw := cellw max: w.
|
|
|
|
minhang := minhang min: ((( rec glyph metrics horiBearingY) - (rec glyph metrics height)) >> 6).
|
2022-03-21 01:45:21 +01:00
|
|
|
meanww := meanww + w.
|
|
|
|
numw := numw + 1.
|
2022-03-16 21:33:35 +01:00
|
|
|
].
|
|
|
|
charcode := face getNextChar: charcode iptr: iptr getHandle.
|
2022-03-06 00:58:28 +01:00
|
|
|
].
|
|
|
|
cellh := maxbearing - minhang.
|
2022-03-17 00:32:19 +01:00
|
|
|
spacing := (cellw >> 2) asInteger.
|
2022-03-21 01:45:21 +01:00
|
|
|
meanww := meanww / numw.
|
2022-03-17 00:32:19 +01:00
|
|
|
maxrows := 8.
|
|
|
|
data := FFIExternalArray externalNewType: GLubyte size:cellw * cellh * (maxrows << 5).
|
|
|
|
LibC memset: data getHandle value: 0 size: data size.
|
|
|
|
width := cellw << 5.
|
|
|
|
height := cellh.
|
|
|
|
data autoRelease.
|
2022-03-16 21:33:35 +01:00
|
|
|
iptr free.
|
2022-03-06 00:58:28 +01:00
|
|
|
]
|
|
|
|
|
2022-08-14 15:42:59 +02:00
|
|
|
{ #category : #processing }
|
2022-03-17 00:32:19 +01:00
|
|
|
OpenGLFontTex >> genGlyph:c [
|
|
|
|
|rec offset glyph gsize|
|
|
|
|
face setPixelWidth:0 height: self fontSize.
|
|
|
|
face loadCharacter: c flags: (1 << 2).
|
|
|
|
rec := (FTFaceRec fromHandle: face getHandle).
|
|
|
|
gsize := ((rec glyph metrics width) >> 6)@((rec glyph metrics height) >> 6).
|
|
|
|
offset := (colp * cellw) @ (rowp*cellh).
|
|
|
|
glyph := (DiyaFontGlyph origin: offset extent: ((gsize x) @ cellh)).
|
|
|
|
glyph
|
|
|
|
bearing: face glyph hBearing asFloatPoint;
|
|
|
|
advance: face glyph advance;
|
|
|
|
tex: self.
|
|
|
|
self blitPixel8: rec glyph bitmap buffer at: (offset x) @ ((offset y) + maxbearing - ((rec glyph metrics horiBearingY) >> 6) ) size: gsize.
|
|
|
|
colp := (colp + 1) % 32.
|
|
|
|
colp = 0 ifTrue:[
|
|
|
|
rowp := rowp + 1.
|
|
|
|
height := height + cellh.
|
|
|
|
rowp >= maxrows ifTrue:[
|
|
|
|
self reallocateBuffer.
|
|
|
|
].
|
|
|
|
].
|
2022-08-14 15:42:59 +02:00
|
|
|
commited := false.
|
2022-03-17 00:32:19 +01:00
|
|
|
^glyph
|
|
|
|
|
|
|
|
]
|
|
|
|
|
2022-08-14 15:42:59 +02:00
|
|
|
{ #category : #processing }
|
|
|
|
OpenGLFontTex >> genPrintableASCII [
|
|
|
|
33 to: 126 do: [ :c| self genGlyph: c ]
|
|
|
|
]
|
|
|
|
|
2022-03-06 12:07:20 +01:00
|
|
|
{ #category : #accessing }
|
|
|
|
OpenGLFontTex >> getGlyph: c [
|
2022-08-14 15:42:59 +02:00
|
|
|
^(self charmap at: c ifAbsentPut:[
|
|
|
|
self genGlyph:c])
|
2022-03-06 12:07:20 +01:00
|
|
|
]
|
|
|
|
|
2022-03-06 00:58:28 +01:00
|
|
|
{ #category : #initialization }
|
|
|
|
OpenGLFontTex >> initialize [
|
|
|
|
super initialize.
|
2022-03-16 21:33:35 +01:00
|
|
|
charmap := Dictionary new.
|
2022-03-06 00:58:28 +01:00
|
|
|
data := nil.
|
2022-03-04 20:28:38 +01:00
|
|
|
level := 0.
|
|
|
|
border := 0.
|
|
|
|
format := GL_ALPHA.
|
2022-03-06 00:58:28 +01:00
|
|
|
internalFormat := GL_ALPHA.
|
2022-03-04 20:28:38 +01:00
|
|
|
type := GL_UNSIGNED_BYTE.
|
|
|
|
target := GL_TEXTURE_2D.
|
2022-03-17 00:32:19 +01:00
|
|
|
colp := 0.
|
|
|
|
rowp := 0.
|
2022-03-04 20:28:38 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
OpenGLFontTex >> linespace [
|
2022-03-06 00:58:28 +01:00
|
|
|
^ cellh
|
|
|
|
]
|
|
|
|
|
2022-03-21 01:45:21 +01:00
|
|
|
{ #category : #accessing }
|
|
|
|
OpenGLFontTex >> meanww [
|
|
|
|
^ meanww
|
|
|
|
]
|
|
|
|
|
2022-08-14 15:42:59 +02:00
|
|
|
{ #category : #processing }
|
2022-03-17 00:32:19 +01:00
|
|
|
OpenGLFontTex >> reallocateBuffer [
|
|
|
|
|newbuffer|
|
|
|
|
maxrows := maxrows + 4.
|
|
|
|
newbuffer := FFIExternalArray externalNewType: GLubyte size:cellw * cellh * (maxrows << 5).
|
|
|
|
LibC memset: newbuffer getHandle value: 0 size: newbuffer size.
|
|
|
|
LibC memCopy: data getHandle to: newbuffer getHandle size: data size.
|
|
|
|
newbuffer autoRelease.
|
|
|
|
data free.
|
|
|
|
data := newbuffer
|
|
|
|
|
|
|
|
]
|
|
|
|
|
2022-08-14 15:42:59 +02:00
|
|
|
{ #category : #initialization }
|
2022-03-06 18:33:10 +01:00
|
|
|
OpenGLFontTex >> setup [
|
|
|
|
OpenGL
|
2022-08-14 15:42:59 +02:00
|
|
|
"enable: GL_CULL_FACE;
|
2022-03-06 18:33:10 +01:00
|
|
|
enable: GL_BLEND;
|
2022-08-14 15:42:59 +02:00
|
|
|
blendFnWithSfactor: GL_SRC_ALPHA dfactor: GL_ONE_MINUS_SRC_ALPHA;"
|
2022-03-06 18:33:10 +01:00
|
|
|
pixelstorei: GL_UNPACK_ALIGNMENT param: 1.
|
|
|
|
OpenGLTexture
|
|
|
|
parameteri: GL_TEXTURE_2D pname: GL_TEXTURE_WRAP_S param: GL_CLAMP_TO_EDGE;
|
|
|
|
parameteri: GL_TEXTURE_2D pname: GL_TEXTURE_WRAP_T param: GL_CLAMP_TO_EDGE;
|
|
|
|
parameteri: GL_TEXTURE_2D pname: GL_TEXTURE_MIN_FILTER param: GL_LINEAR;
|
|
|
|
parameteri: GL_TEXTURE_2D pname: GL_TEXTURE_MAG_FILTER param: GL_LINEAR.
|
|
|
|
]
|
|
|
|
|
2022-03-06 00:58:28 +01:00
|
|
|
{ #category : #accessing }
|
|
|
|
OpenGLFontTex >> spacing [
|
2022-03-06 18:33:10 +01:00
|
|
|
^ spacing
|
2022-03-04 20:28:38 +01:00
|
|
|
]
|