Skip to content

Commit

Permalink
Add TextField.lineSpaceScale
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugh Sanderson committed Mar 29, 2024
1 parent 4e2aeba commit 63fee42
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 6 deletions.
3 changes: 3 additions & 0 deletions project/include/TextField.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class TextField : public DisplayObject
float sharpness;
int textColor;
float thickness;
float lineSpaceScale;
bool useRichTextClipboard;
bool wordWrap;
bool isInput;
Expand Down Expand Up @@ -122,6 +123,8 @@ class TextField : public DisplayObject
void modifyLocalMatrix(Matrix &ioMatrix);
void setAntiAliasType(int inVal);
int getAntiAliasType() const { return (int)antiAliasType; }
void setLineSpaceScale(double inVal);
inline float getLineSpaceScale() const { return lineSpaceScale; }


int getCaretIndex() { return caretIndex; }
Expand Down
1 change: 1 addition & 0 deletions project/src/common/ExternalInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4137,6 +4137,7 @@ TEXT_PROP_PRIME(embed_fonts,EmbedFonts,bool);
TEXT_PROP_PRIME(auto_size,AutoSize,int);
TEXT_PROP_PRIME(caret_index,CaretIndex,int);
TEXT_PROP_PRIME(anti_alias_type,AntiAliasType,int);
TEXT_PROP_PRIME(line_space_scale,LineSpaceScale,double);
TEXT_PROP_GET_PRIME(text_width,TextWidth,double);
TEXT_PROP_GET_PRIME(text_height,TextHeight,double);
TEXT_PROP_GET_PRIME(max_scroll_h,MaxScrollH,int);
Expand Down
2 changes: 1 addition & 1 deletion project/src/common/FreeType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ class FreeTypeFont : public FontFace
if (!sGammaLUTInit)
{
for(int i=0;i<256;i++)
sGammaLUT[i] = pow(i/255.0,1.25)*255 + 0.5;
sGammaLUT[i] = pow(i/255.0,1.6)*255 + 0.5;
sGammaLUTInit = true;
}
lut = sGammaLUT;
Expand Down
20 changes: 17 additions & 3 deletions project/src/common/TextField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ TextField::TextField(bool inInitRef) : DisplayObject(inInitRef),
sharpness(0),
textColor(0x000000),
thickness(0),
lineSpaceScale(1.0f),
useRichTextClipboard(false),
wordWrap(false),
isInput(false)
Expand Down Expand Up @@ -301,6 +302,16 @@ void TextField::setAntiAliasType(int inVal)
}


void TextField::setLineSpaceScale(double inScale)
{
if (lineSpaceScale!=inScale)
{
lineSpaceScale = (float)inScale;
Layout();
}
}


void TextField::setTextColor(int inCol)
{
textColor = inCol;
Expand Down Expand Up @@ -2233,9 +2244,10 @@ void TextField::Layout(const Matrix &inMatrix, const RenderTarget *inTarget)
if (ch=='\n' || ch=='\r')
{
// New line ...
line.mMetrics.fontToLocal(fontToLocal);
line.mMetrics.fontToLocal(fontToLocal*lineSpaceScale);
if (i+1<mCharGroups.size() || cid+1<g.Chars())
line.mMetrics.height += g.mFormat->leading;

charY += line.mMetrics.height;
mLines.push_back(line);
line.Clear();
Expand Down Expand Up @@ -2281,7 +2293,7 @@ void TextField::Layout(const Matrix &inMatrix, const RenderTarget *inTarget)
line.mChars = last_word_line_chars;
line.mMetrics.width = last_word_x;
}
line.mMetrics.fontToLocal(fontToLocal);
line.mMetrics.fontToLocal(fontToLocal*lineSpaceScale);
if (i+1<mCharGroups.size() || cid+1<g.Chars())
line.mMetrics.height += g.mFormat->leading;
charY += line.mMetrics.height;
Expand All @@ -2302,7 +2314,7 @@ void TextField::Layout(const Matrix &inMatrix, const RenderTarget *inTarget)
{
CharGroup *last=mCharGroups[mCharGroups.size()-1];
last->UpdateMetrics(line.mMetrics);
line.mMetrics.fontToLocal(fontToLocal);
line.mMetrics.fontToLocal(fontToLocal*lineSpaceScale);
if (endsWidthNewLine)
{
line.mY0 = charY;
Expand Down Expand Up @@ -2430,6 +2442,7 @@ void TextField::decodeStream(ObjectStreamIn &stream)
stream.get(sharpness);
stream.get(textColor);
stream.get(thickness);
stream.get(lineSpaceScale);
stream.get(useRichTextClipboard);
stream.get(wordWrap);
stream.get(isInput);
Expand Down Expand Up @@ -2489,6 +2502,7 @@ void TextField::encodeStream(ObjectStreamOut &stream)
stream.add(sharpness);
stream.add(textColor);
stream.add(thickness);
stream.add(lineSpaceScale);
stream.add(useRichTextClipboard);
stream.add(wordWrap);
stream.add(isInput);
Expand Down
4 changes: 2 additions & 2 deletions project/src/windows/GDIFont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class GDIFont : public FontFace
if (!sGammaLUTInit)
{
for(int i=0;i<256;i++)
sGammaLUT[i] = pow(i/255.0,1.25)*255 + 0.5;
sGammaLUT[i] = pow(i/255.0,1.6)*255 + 0.5;

sGammaLUTInit = true;
}
Expand Down Expand Up @@ -119,7 +119,7 @@ class GDIFont : public FontFace
uint8 *dest = (uint8 *)outTarget.Row(y + outTarget.mRect.y) + outTarget.mRect.x;
for(int x=0;x<outTarget.mRect.w;x++)
{
*dest++= sGammaLUT[ (src->r + src->g*2 + src->b + 2) / 4];
*dest++= sGammaLUT[ (src->r + src->g + src->b + 1) / 3];
src++;
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/nme/text/TextField.hx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class TextField extends InteractiveObject
public var selectionEndIndex(get, null):Int;
public var multiline(get, set):Bool;
public var numLines(get, null):Int;
public var lineSpaceScale(get, set):Float;
public var scrollH(get, set):Int;
public var scrollV(get, set):Int;
public var selectable(get, set):Bool;
Expand Down Expand Up @@ -184,6 +185,8 @@ class TextField extends InteractiveObject
private function set_text(inText:String):String { nme_text_field_set_text(nmeHandle, inText); return inText; }
private function get_textColor():Int { return nme_text_field_get_text_color(nmeHandle); }
private function set_textColor(inCol:Int):Int { nme_text_field_set_text_color(nmeHandle, inCol); return inCol; }
private function get_lineSpaceScale():Float { return nme_text_field_get_line_space_scale(nmeHandle); }
private function set_lineSpaceScale(inValue:Float):Float { nme_text_field_set_line_space_scale(nmeHandle, inValue); return inValue; }
private function get_textWidth():Float { return nme_text_field_get_text_width(nmeHandle); }
private function get_textHeight():Float { return nme_text_field_get_text_height(nmeHandle); }
private function get_type():TextFieldType { return nme_text_field_get_type(nmeHandle) ? TextFieldType.INPUT : TextFieldType.DYNAMIC; }
Expand Down Expand Up @@ -270,6 +273,8 @@ class TextField extends InteractiveObject
private static var nme_text_field_send_key = PrimeLoader.load("nme_text_field_send_key", "oiiiv");
private static var nme_text_field_set_anti_alias_type = PrimeLoader.load("nme_text_field_set_anti_alias_type", "oiv");
private static var nme_text_field_get_anti_alias_type = PrimeLoader.load("nme_text_field_get_anti_alias_type", "oi");
private static var nme_text_field_set_line_space_scale = PrimeLoader.load("nme_text_field_set_line_space_scale", "odv");
private static var nme_text_field_get_line_space_scale = PrimeLoader.load("nme_text_field_get_line_space_scale", "od");
}

#else
Expand Down

0 comments on commit 63fee42

Please sign in to comment.