mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-15 06:05:58 -06:00
PixelMode
This commit is contained in:
parent
c0935e3ab9
commit
c119e90c6c
11 changed files with 150 additions and 31 deletions
|
|
@ -2,6 +2,13 @@
|
|||
#include <Painter/Painter.h>
|
||||
|
||||
namespace Upp {
|
||||
|
||||
RichObject RichEdit::Adjust(RichObject o)
|
||||
{
|
||||
if(pixel_mode)
|
||||
o.SetSize(o.GetPixelSize() * 8 / DPI(1));
|
||||
return o;
|
||||
}
|
||||
|
||||
void RichEdit::InsertImage()
|
||||
{
|
||||
|
|
@ -20,7 +27,7 @@ void RichEdit::InsertImage()
|
|||
}
|
||||
RichText clip;
|
||||
RichPara p;
|
||||
p.Cat(CreateRawImageObject(data), formatinfo);
|
||||
p.Cat(Adjust(CreateRawImageObject(data)), formatinfo);
|
||||
clip.Cat(p);
|
||||
ClipPaste(clip, "image/raw");
|
||||
}
|
||||
|
|
@ -40,7 +47,7 @@ bool RichEdit::Accept(PasteClip& d, RichText& clip, String& fmt)
|
|||
StringStream ss(data);
|
||||
if(StreamRaster::OpenAny(ss) || ext == ".svg" && IsSVG(LoadFile(fn))) {
|
||||
RichPara p;
|
||||
p.Cat(CreateRawImageObject(data), formatinfo);
|
||||
p.Cat(Adjust(CreateRawImageObject(data)), formatinfo);
|
||||
clip.Cat(p);
|
||||
fmt = "files";
|
||||
}
|
||||
|
|
@ -90,7 +97,7 @@ bool RichEdit::Accept(PasteClip& d, RichText& clip, String& fmt)
|
|||
Value data = rt.Read(d);
|
||||
if(!IsNull(data)) {
|
||||
RichPara p;
|
||||
RichObject o = RichObject(&rt, data, pagesz);
|
||||
RichObject o = Adjust(RichObject(&rt, data, pagesz));
|
||||
p.Cat(o, formatinfo);
|
||||
clip.Cat(p);
|
||||
fmt = o.GetTypeName();
|
||||
|
|
|
|||
|
|
@ -15,13 +15,17 @@ bool FontHeight::Key(dword key, int count)
|
|||
return WithDropChoice<EditDouble>::Key(key, count);
|
||||
}
|
||||
|
||||
double RichEdit::DotToPt(int dt)
|
||||
double RichEdit::DotToPt(int dot, int unit)
|
||||
{
|
||||
return 7200 * minmax(dt, 8, 8000) / 600 / 10 / 10.0;
|
||||
if(unit == UNIT_PIXELMODE)
|
||||
return dot / 8.0;
|
||||
return 7200 * minmax(dot, 8, 8000) / 600 / 10 / 10.0;
|
||||
}
|
||||
|
||||
int RichEdit::PtToDot(double pt)
|
||||
int RichEdit::PtToDot(double pt, int unit)
|
||||
{
|
||||
if(unit == UNIT_PIXELMODE)
|
||||
return pt * 8;
|
||||
return int((600 * pt + 71) / 72);
|
||||
}
|
||||
|
||||
|
|
@ -221,9 +225,37 @@ RichEdit& RichEdit::Floating(double zoomlevel_)
|
|||
return *this;
|
||||
}
|
||||
|
||||
RichEdit& RichEdit::PixelMode()
|
||||
{
|
||||
NoRuler();
|
||||
ShowCodes(Blend(SColorHighlight(), SColorPaper()));
|
||||
ViewBorder(0);
|
||||
|
||||
RichPara::Format f;
|
||||
f.language = LNG_('C','S','C','Z');
|
||||
(Font&)f = Arial(StdFont().GetHeight() * 8 / DPI(1));
|
||||
f.tabsize = f['W'] * 8;
|
||||
RichText::FormatInfo fi;
|
||||
fi.Set(f);
|
||||
ApplyFormatInfo(fi);
|
||||
|
||||
pixel_mode = true;
|
||||
RefreshLayoutDeep();
|
||||
|
||||
height.SetFilter(CharFilterDigit);
|
||||
|
||||
unit = UNIT_PIXELMODE;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void RichEdit::Layout()
|
||||
{
|
||||
Size sz = GetTextRect().GetSize();
|
||||
if(pixel_mode) {
|
||||
SetPage(Size(max(sz.cx, 5) / DPI(1) * 8, INT_MAX));
|
||||
}
|
||||
else
|
||||
if(!IsNull(floating_zoom)) {
|
||||
Zoom m = GetRichTextStdScreenZoom();
|
||||
SetPage(Size(int(1 / floating_zoom * m.d / m.m * sz.cx), INT_MAX));
|
||||
|
|
@ -233,7 +265,7 @@ void RichEdit::Layout()
|
|||
SetSb();
|
||||
sb = zsc * GetZoom();
|
||||
PlaceCaret();
|
||||
if(GetSize() != p_size) {
|
||||
if(GetSize() != p_size && !pixel_mode) {
|
||||
sizetracking = true;
|
||||
KillSetTimeCallback(250, THISBACK(EndSizeTracking), TIMEID_ENDSIZETRACKING);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -174,6 +174,8 @@ void ParaFormatting::Set(int unit, const RichText::FormatInfo& formatinfo, bool
|
|||
if(RichText::TABS & formatinfo.paravalid)
|
||||
for(int i = 0; i < formatinfo.tab.GetCount(); i++)
|
||||
tabs.Add(formatinfo.tab[i].pos, formatinfo.tab[i].align, formatinfo.tab[i].fillchar);
|
||||
if(unit == UNIT_PIXELMODE)
|
||||
tabs.Disable();
|
||||
tabsize.Set(unit, RichText::TABSIZE & formatinfo.paravalid ? formatinfo.tabsize : Null);
|
||||
keepindent = formatinfo.indent != ComputeIndent();
|
||||
SetupIndent();
|
||||
|
|
@ -355,7 +357,7 @@ void StyleManager::EnterStyle()
|
|||
const RichStyle& s = style.Get(list.GetKey());
|
||||
f.Set(s.format);
|
||||
para.Set(unit, f);
|
||||
height <<= RichEdit::DotToPt(s.format.GetHeight());
|
||||
height <<= RichEdit::DotToPt(s.format.GetHeight(), unit);
|
||||
face <<= s.format.GetFace();
|
||||
bold = s.format.IsBold();
|
||||
italic = s.format.IsItalic();
|
||||
|
|
@ -375,7 +377,7 @@ void StyleManager::GetFont(Font& font)
|
|||
if(!IsNull(face))
|
||||
font.Face(~face);
|
||||
if(!IsNull(height))
|
||||
font.Height(RichEdit::PtToDot(~height));
|
||||
font.Height(RichEdit::PtToDot(~height, unit));
|
||||
font.Bold(bold);
|
||||
font.Italic(italic);
|
||||
font.Underline(underline);
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@ void RichEdit::SetFace()
|
|||
void RichEdit::SetHeight()
|
||||
{
|
||||
NextUndo();
|
||||
formatinfo.Height(PtToDot(~height));
|
||||
formatinfo.Height(PtToDot(~height, unit));
|
||||
ApplyFormat(RichText::HEIGHT);
|
||||
SetFocus();
|
||||
}
|
||||
|
|
@ -218,7 +218,7 @@ void RichEdit::ShowFormat()
|
|||
face <<= Null;
|
||||
|
||||
if(formatinfo.charvalid & RichText::HEIGHT)
|
||||
height <<= DotToPt(formatinfo.GetHeight());
|
||||
height <<= DotToPt(formatinfo.GetHeight(), unit);
|
||||
else
|
||||
height <<= Null;
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ namespace Upp {
|
|||
|
||||
Size RichEdit::GetPhysicalSize(const RichObject& obj)
|
||||
{
|
||||
if(pixel_mode)
|
||||
return obj.GetPixelSize() * 8;
|
||||
if(ignore_physical_size)
|
||||
return 600 * obj.GetPixelSize() / 96;
|
||||
return obj.GetPhysicalSize();
|
||||
|
|
@ -238,6 +240,7 @@ void RichEdit::StdBar(Bar& menu)
|
|||
menu.Add(t_("Object position.."), THISBACK(AdjustObjectSize));
|
||||
menu.Separator();
|
||||
menu.Add(b, "20 %", THISBACK1(SetObjectPercent, 20)).Check(IsObjectPercent(percent, 20));
|
||||
menu.Add(b, "25 %", THISBACK1(SetObjectPercent, 25)).Check(IsObjectPercent(percent, 20));
|
||||
menu.Add(b, "30 %", THISBACK1(SetObjectPercent, 30)).Check(IsObjectPercent(percent, 30));
|
||||
menu.Add(b, "40 %", THISBACK1(SetObjectPercent, 40)).Check(IsObjectPercent(percent, 40));
|
||||
menu.Add(b, "50 %", THISBACK1(SetObjectPercent, 50)).Check(IsObjectPercent(percent, 50));
|
||||
|
|
@ -248,13 +251,18 @@ void RichEdit::StdBar(Bar& menu)
|
|||
menu.Add(b, "100 %", THISBACK1(SetObjectPercent, 100)).Check(IsObjectPercent(percent, 100));
|
||||
menu.Break();
|
||||
int delta = bar_object.GetYDelta();
|
||||
menu.Add(t_("3 pt up"), THISBACK1(SetObjectYDelta, -3)).Check(IsObjectDelta(delta, -3));
|
||||
menu.Add(t_("2 pt up"), THISBACK1(SetObjectYDelta, -2)).Check(IsObjectDelta(delta, -2));
|
||||
menu.Add(t_("1 pt up"), THISBACK1(SetObjectYDelta, -1)).Check(IsObjectDelta(delta, -1));
|
||||
auto pma = [=](String s) {
|
||||
if(pixel_mode)
|
||||
s.Replace(" pt", "");
|
||||
return s;
|
||||
};
|
||||
menu.Add(pma(t_("3 pt up")), THISBACK1(SetObjectYDelta, -3)).Check(IsObjectDelta(delta, -3));
|
||||
menu.Add(pma(t_("2 pt up")), THISBACK1(SetObjectYDelta, -2)).Check(IsObjectDelta(delta, -2));
|
||||
menu.Add(pma(t_("1 pt up")), THISBACK1(SetObjectYDelta, -1)).Check(IsObjectDelta(delta, -1));
|
||||
menu.Add(t_("Baseline"), THISBACK1(SetObjectYDelta, 0)).Check(IsObjectDelta(delta, 0));
|
||||
menu.Add(t_("1 pt down"), THISBACK1(SetObjectYDelta, 1)).Check(IsObjectDelta(delta, 1));
|
||||
menu.Add(t_("2 pt down"), THISBACK1(SetObjectYDelta, 2)).Check(IsObjectDelta(delta, 2));
|
||||
menu.Add(t_("3 pt down"), THISBACK1(SetObjectYDelta, 3)).Check(IsObjectDelta(delta, 3));
|
||||
menu.Add(pma(t_("1 pt down")), THISBACK1(SetObjectYDelta, 1)).Check(IsObjectDelta(delta, 1));
|
||||
menu.Add(pma(t_("2 pt down")), THISBACK1(SetObjectYDelta, 2)).Check(IsObjectDelta(delta, 2));
|
||||
menu.Add(pma(t_("3 pt down")), THISBACK1(SetObjectYDelta, 3)).Check(IsObjectDelta(delta, 3));
|
||||
menu.Separator();
|
||||
CopyTool(menu);
|
||||
CutTool(menu);
|
||||
|
|
|
|||
|
|
@ -84,6 +84,8 @@ enum {
|
|||
UNIT_INCH,
|
||||
UNIT_MM,
|
||||
UNIT_CM,
|
||||
|
||||
UNIT_PIXELMODE,
|
||||
};
|
||||
|
||||
class UnitEdit : public EditField, public Convert {
|
||||
|
|
@ -103,9 +105,10 @@ private:
|
|||
static String DotAsText(int dot, int unit);
|
||||
void Spin(int delta);
|
||||
void Read(double& q, int& u) const;
|
||||
void SyncFilter();
|
||||
|
||||
public:
|
||||
UnitEdit& SetUnit(int _unit) { unit = _unit; return *this; }
|
||||
UnitEdit& SetUnit(int _unit) { unit = _unit; SyncFilter(); return *this; }
|
||||
void Set(int _unit, int d) { unit = _unit; SetData(d); }
|
||||
UnitEdit& WithSgn(bool b = true);
|
||||
|
||||
|
|
@ -303,6 +306,8 @@ private:
|
|||
|
||||
PaintInfo paint_info;
|
||||
bool ignore_physical_size;
|
||||
|
||||
bool pixel_mode = false;
|
||||
|
||||
static int fh[];
|
||||
|
||||
|
|
@ -623,7 +628,9 @@ private:
|
|||
void ZoomClip(RichText& text) const;
|
||||
|
||||
void InsertImage();
|
||||
|
||||
|
||||
RichObject Adjust(RichObject o);
|
||||
|
||||
void StyleKeys();
|
||||
void ApplyStyleKey(int i);
|
||||
|
||||
|
|
@ -663,8 +670,8 @@ public:
|
|||
virtual void PasteFilter(RichText& txt, const String& fmt);
|
||||
virtual void Filter(RichText& txt);
|
||||
|
||||
static double DotToPt(int dot);
|
||||
static int PtToDot(double pt);
|
||||
static double DotToPt(int dot, int unit = UNIT_DOT);
|
||||
static int PtToDot(double pt, int unit = UNIT_DOT);
|
||||
static Bits SpellParagraph(const RichPara& p);
|
||||
static void FixedLang(int lang) { fixedlang = lang; }
|
||||
|
||||
|
|
@ -819,9 +826,10 @@ public:
|
|||
RichEdit& BulletIndent(int i) { bullet_indent = i; return *this; }
|
||||
RichEdit& PersistentFindReplace(bool b = true) { persistent_findreplace = b; return *this; }
|
||||
RichEdit& Floating(double zoomlevel_ = 1);
|
||||
RichEdit& NoFloating(double zoomlevel_ = 1) { return Floating(Null); }
|
||||
RichEdit& NoFloating() { return Floating(Null); }
|
||||
RichEdit& SetPaintInfo(const PaintInfo& pi) { paint_info = pi; return *this; }
|
||||
RichEdit& IgnorePhysicalObjectSize(bool b = true){ ignore_physical_size = b; return *this; }
|
||||
RichEdit& PixelMode();
|
||||
|
||||
struct UndoInfo {
|
||||
int undoserial;
|
||||
|
|
|
|||
|
|
@ -25,6 +25,10 @@ void RichEdit::InsertTable()
|
|||
if(dlg.Run() != IDOK)
|
||||
return;
|
||||
RichTable::Format fmt;
|
||||
if(pixel_mode) {
|
||||
fmt.grid = 1;
|
||||
fmt.frame = 2;
|
||||
}
|
||||
int nx = minmax((int)~dlg.columns, 1, 20);
|
||||
for(int q = nx; q--;)
|
||||
fmt.column.Add(1);
|
||||
|
|
@ -42,6 +46,12 @@ void RichEdit::InsertTable()
|
|||
p.format.label.Clear();
|
||||
h.Cat(p);
|
||||
table.SetPick(i, j, pick(h));
|
||||
if(pixel_mode) {
|
||||
RichCell::Format fmt;
|
||||
fmt.margin.left = fmt.margin.right = 4;
|
||||
fmt.margin.top = fmt.margin.bottom = 3;
|
||||
table.SetFormat(i, j, fmt);
|
||||
}
|
||||
}
|
||||
NextUndo();
|
||||
if(cursorp.posinpara)
|
||||
|
|
|
|||
|
|
@ -5,13 +5,14 @@ namespace Upp {
|
|||
double UnitMultiplier(int unit) {
|
||||
static double m[] =
|
||||
{
|
||||
1,
|
||||
72.0 / 600,
|
||||
1.0 / 600,
|
||||
25.4 / 600,
|
||||
2.54 / 600,
|
||||
1, // DOT
|
||||
72.0 / 600, // POINT
|
||||
1.0 / 600, // INCH
|
||||
25.4 / 600, // mm
|
||||
2.54 / 600, // cm
|
||||
1 / 8.0, // PIXELMODE
|
||||
};
|
||||
ASSERT(unit >= UNIT_DOT && unit <= UNIT_CM);
|
||||
ASSERT(unit >= UNIT_DOT && unit <= UNIT_PIXELMODE);
|
||||
return m[unit];
|
||||
}
|
||||
|
||||
|
|
@ -23,6 +24,7 @@ const char *UnitText(int unit) {
|
|||
"\"",
|
||||
"mm",
|
||||
"cm"
|
||||
"",
|
||||
};
|
||||
return txt[unit];
|
||||
}
|
||||
|
|
@ -78,6 +80,8 @@ String UnitEdit::AsText(double d, int unit)
|
|||
{
|
||||
if(IsNull(d))
|
||||
return Null;
|
||||
if(unit == UNIT_PIXELMODE)
|
||||
return AsString(d);
|
||||
String utxt = UnitText(unit);
|
||||
if(unit == UNIT_POINT)
|
||||
d = floor(10 * d + 0.5) / 10;
|
||||
|
|
@ -127,6 +131,7 @@ void UnitEdit::Spin(int delta)
|
|||
case UNIT_MM: h = 0.5; break;
|
||||
case UNIT_CM:
|
||||
case UNIT_INCH: h = 0.05; break;
|
||||
case UNIT_PIXELMODE: h = 1; break;
|
||||
default: NEVER();
|
||||
}
|
||||
h *= delta;
|
||||
|
|
@ -148,10 +153,28 @@ int CharFilterUnitEditSgn(int c)
|
|||
return c == '-' ? c : CharFilterUnitEdit(c);
|
||||
}
|
||||
|
||||
int CharFilterUnitEditPx(int c)
|
||||
{
|
||||
return IsDigit(c) || c == '.' ? c : 0;
|
||||
}
|
||||
|
||||
int CharFilterUnitEditSgnPx(int c)
|
||||
{
|
||||
return c == '-' ? c : CharFilterUnitEditPx(c);
|
||||
}
|
||||
|
||||
void UnitEdit::SyncFilter()
|
||||
{
|
||||
if(unit == UNIT_PIXELMODE)
|
||||
SetFilter(sgn ? CharFilterUnitEditSgnPx : CharFilterUnitEditPx);
|
||||
else
|
||||
SetFilter(sgn ? CharFilterUnitEditSgn : CharFilterUnitEdit);
|
||||
}
|
||||
|
||||
UnitEdit& UnitEdit::WithSgn(bool b)
|
||||
{
|
||||
sgn = b;
|
||||
SetFilter(b ? CharFilterUnitEditSgn : CharFilterUnitEdit);
|
||||
SyncFilter();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -84,7 +84,6 @@ Size RichImage::GetPhysicalSize(const Value& data) const
|
|||
void RichImage::Paint(const Value& data, Draw& w, Size sz, void *) const
|
||||
{
|
||||
Image x = LoadImageFromString(data);
|
||||
// Size outsz(min(sz.cx, 4 * x.GetWidth()), min(sz.cy, 4 * x.GetHeight()));
|
||||
w.DrawImage(0, 0, sz.cx, sz.cy, x);
|
||||
}
|
||||
|
||||
|
|
@ -242,7 +241,7 @@ void RichRawImage::Paint(const Value& data, Draw& w, Size sz, void *) const
|
|||
if(r) {
|
||||
Size isz = r->GetSize();
|
||||
if(GetIsJPGFn() && GetIsJPGFn()(~r) && GetPdfDrawJPEGFn())
|
||||
GetPdfDrawJPEGFn()(w, 0, 0, sz.cx, sz.cy, data);
|
||||
GetPdfDrawJPEGFn()(w, 0, 0, sz.cx, sz.cy, data); // make sure we export jpg to pdf without reprocessing
|
||||
else
|
||||
if(isz.cx * isz.cy > sz.cx * sz.cy) { // conserve memory by scaling down from source
|
||||
ImageEncoder m;
|
||||
|
|
|
|||
10
upptst/RichTextPixelMode/RichTextPixelMode.upp
Normal file
10
upptst/RichTextPixelMode/RichTextPixelMode.upp
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
uses
|
||||
CtrlLib,
|
||||
RichEdit;
|
||||
|
||||
file
|
||||
main.cpp;
|
||||
|
||||
mainconfig
|
||||
"" = "GUI";
|
||||
|
||||
20
upptst/RichTextPixelMode/main.cpp
Normal file
20
upptst/RichTextPixelMode/main.cpp
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#include <CtrlLib/CtrlLib.h>
|
||||
#include <RichEdit/RichEdit.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
GUI_APP_MAIN
|
||||
{
|
||||
TopWindow win;
|
||||
RichEditWithToolBar edit;
|
||||
edit.PixelMode();
|
||||
RichEditWithToolBar edit2;
|
||||
edit2.PixelMode();
|
||||
win << edit.HSizePos().VSizePos(0, Zx(200));
|
||||
win << edit2.HSizePos().BottomPos(0, Zx(200));
|
||||
win.Sizeable();
|
||||
String fn = ConfigFile("test.qtf");
|
||||
edit.SetQTF(LoadFile(fn));
|
||||
win.Run();
|
||||
SaveFile(fn, edit.GetQTF());
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue