Need to set border around PDAnnotationTextMarkup, Highlight text in PDF - scala

Desired Result:
How do I set border(red) to my PDAnnotationTextMarkup? Just need to work with AdobePDF mainly.
def addCoordinates(cord: List[Coordinates], page) : PDPage = {
val annotations = page.getAnnotations
val borderThick = new PDBorderStyleDictionary()
borderThick.setWidth(0.8.toFloat)
borderThick.setStyle(PDBorderStyleDictionary.STYLE_SOLID)
cord.foreach {
val textM = new PDAnnotationTextMarkup(PDAnnotationTextMarkup.SUB_TYPE_HIGHLIGHT)
textM.setBorderStyle(borderThick)
textM.setColor(yellow)
// Set rectange and quads
annotations.add(markup) // Need to set border to markup?
// Below code i was able to get red border with Square annotation.
// This is more kind of workaround, see two annotations in Adobe PDF (not user friendly.)
val aSquare = new PDAnnotationSquareCircle(PDAnnotationSquareCircle.SUB_TYPE_SQUARE)
aSquare.setColor(red);
// set rectange and quads
annotations.add(aSquare)
}
page
}

Related

element.remove() and element.append() conflicting with each other

I am writing a chess game in JavaScript/React.
When I drag the white piece to the black piece, I am trying to remove the black piece and append the white one, like this :
function drop(ev) {
ev.preventDefault();
//Set the background to original color on droping the piece:
ev.target.style.backgroundColor = ev.target.dataset.squarecolor
//Save moving piece data into an object:
let movingPiece = JSON.parse(ev.dataTransfer.getData("Text"))
if (movingPiece.color === 'white' && ev.target?.dataset?.color === 'black' && ev.target.nodeName === 'IMG')
{
ev.target.remove()
ev.target.append(document.getElementById(movingPiece.id));
}
}
So:
Remove black piece
Add white piece
But I end up with 0 pieces on the screen. Not sure if this is because of render or JS is removing the newly appended item.
Reproducible example:
https://codesandbox.io/s/chess-app-11qvk9?file=/src/components/pieces.jsx
No need to remove
function drop(ev) {
ev.preventDefault();
//Set the background to original color on droping the piece:
ev.target.style.backgroundColor = ev.target.dataset.squarecolor
//Save moving piece data into an object:
let movingPiece = JSON.parse(ev.dataTransfer.getData("Text"))
if (movingPiece.color === 'white')
{
//ev.target.remove()
ev.target.append(document.getElementById(movingPiece.id));
}
}

How to properly display floating Buttons on top of BottomNavigationView?

I want to display 2 "floating buttons" a bit on top of a BottomNavigationView if one of its menu is clicked.
Here's my attempt. Basically it uses an AlertDialog supplied with a LinearLayout (full code: https://github.com/anta40/ButtonAnimTest)
bottomNav.setOnItemSelectedListener { menu ->
when (menu.itemId){
R.id.game_menu -> {
val dialogBuilder = AlertDialog.Builder(this)
val customView = layoutInflater.inflate(R.layout.custom_alert_layout, null)
dialogBuilder.setView(customView)
dialogBuilder.setCancelable(true)
val btnYes = customView.findViewById<Button>(R.id.btn_dialog_yes)
val btnNo = customView.findViewById<Button>(R.id.btn_dialog_no)
/*
taken from https://stackoverflow.com/questions/9467026/changing-position-of-the-dialog-on-screen-android
*/
val alert = dialogBuilder.create()
val dialogWindow = alert.window
val layoutParams = dialogWindow!!.attributes
layoutParams.gravity = Gravity.BOTTOM or Gravity.CENTER_HORIZONTAL
layoutParams.flags = layoutParams.flags and WindowManager.LayoutParams.FLAG_DIM_BEHIND.inv()
dialogWindow.attributes = layoutParams
dialogWindow.setBackgroundDrawable(ColorDrawable(android.graphics.Color.TRANSPARENT))
btnYes.setOnClickListener {
alert.dismiss()
}
btnNo.setOnClickListener {
alert.dismiss()
}
alert.show()
true
}
}
false
}
}
There are 2 problems:
The LinearLayout is displayed too high, aligned with the TitleBar. What I want is just a little bit on top of the BottomNavigationView, like 10dp or 20dp.
The screen is dimmed a bit. I don't want the brightness to be changed when those buttons appear.
How to fix these?

android-graphview shows wrong graphs with setNumVerticalLabels

i test the android-graphview library and i find this behavior:
I use the latest GraphViewDemos and the first SimpleGraph example. It shows a linegraph with the correct data. (The y-axis values are 1,2,3)
GraphViewSeries exampleSeries = new GraphViewSeries(new GraphViewData[] {
new GraphViewData(1, 2.0d)
, new GraphViewData(2, 1.5d)
, new GraphViewData(2.5, 3.0d) // another frequency
, new GraphViewData(3, 2.5d)
, new GraphViewData(4, 1.0d)
, new GraphViewData(5, 3.0d)
});
The max value is three (Sorry i can't post an image) and all other coordinates are correct.
If i add these lines
graphView.getGraphViewStyle().setNumVerticalLabels(5);
graphView.setVerticalLabels( new String[]{"4","3","2","1","0"});
before
LinearLayout layout = (LinearLayout) findViewById(R.id.graph1);
layout.addView(graphView);
in the code to change the y-axis, i get a graph where the max-value is not still three, it's four. And all the other coordinates are wrong in the y-values.
Why does the complete graph change and not only the y-axis?
with the line:
graphView.setVerticalLabels( new String[]{"4","3","2","1","0"});
you set static labels to the graph. So the vertical labels (y-values) have no link to the data anymore.
This line is for dynamic labels. You can modify the count of the labels that will be generated.
graphView.getGraphViewStyle().setNumVerticalLabels(5);
But you are using static labels, so the line doesn't make sense.
http://android-graphview.org/
Visit this page and scroll to the Custom Label Formatter part of the tutorial.
GraphView graphView = new LineGraphView(this, "example");
graphView.setCustomLabelFormatter(new CustomLabelFormatter() {
#Override
public String formatLabel(double value, boolean isValueX) {
if (isValueX) {
if (value < 5) {
return "small";
} else if (value < 15) {
return "middle";
} else {
return "big";
}
}
return null; // let graphview generate Y-axis label for us
}
});
Basically you will have to map the actual y value with the static Vertical Label you have provided

copy chart control to new form

Is there a way to copy a chart control to a new form?
I have a Windows Form with a chart control on it, but the form is not allowed to be resizable. For that reason I have a button "Zoom" that opens the chart in a new form that is resizable. I have set a lot of chart properties in the "original" chart (axis color, axis intervalls etc.) and would like to just reuse this properties. I tried to call the constructor of the new form with the chart as parameter, but that didn't work.
public ZoomChartSeriesForm(Chart myChart)
My main problem is, that I allow zooming inside of the chart and that crashes, when I just copy the chart.
Here is the code of my "original chart" (example):
System.Drawing.Color color = System.Drawing.Color.Red;
//plot new doublelist
var series = new Series
{
Name = "Series2",
Color = color,
ChartType = SeriesChartType.Line,
ChartArea = "ChartArea1",
IsXValueIndexed = true,
};
this.chart1.Series.Add(series);
List<double> doubleList = new List<double>();
doubleList.Add(1.0);
doubleList.Add(5.0);
doubleList.Add(3.0);
doubleList.Add(1.0);
doubleList.Add(4.0);
series.Points.DataBindY(doubleList);
var chartArea = chart1.ChartAreas["ChartArea1"];
LabelStyle ls = new LabelStyle();
ls.ForeColor = color;
Axis a = chartArea.AxisY;
a.TitleForeColor = color; //color of axis title
a.MajorTickMark.LineColor = color; //color of ticks
a.LabelStyle = ls; //color of tick labels
chartArea.Visible = true;
chartArea.AxisY.Title = "TEST";
chartArea.RecalculateAxesScale();
chartArea.AxisX.Minimum = 1;
chartArea.AxisX.Maximum = doubleList.Count;
// Set automatic scrolling
chartArea.CursorX.AutoScroll = true;
chartArea.CursorY.AutoScroll = true;
// Allow user to select area for zooming
chartArea.CursorX.IsUserEnabled = true;
chartArea.CursorX.IsUserSelectionEnabled = true;
chartArea.CursorY.IsUserEnabled = true;
chartArea.CursorY.IsUserSelectionEnabled = true;
// Set automatic zooming
chartArea.AxisX.ScaleView.Zoomable = true;
chartArea.AxisY.ScaleView.Zoomable = true;
chartArea.AxisX.ScrollBar.IsPositionedInside = true;
chartArea.AxisY.ScrollBar.IsPositionedInside = true;
//reset zoom
chartArea.AxisX.ScaleView.ZoomReset();
chartArea.AxisY.ScaleView.ZoomReset();
chart1.Invalidate();
Copy as in deep copying the object?
I ran into this exact problem recently myself. Unfortunately, MS Chart has no method to clone their chart object and their class is not marked as serializable so you can't use the method suggested here.
If you want to do this the right way, you'll have to introduce a third party control such as Copyable or handle the reflection yourself, but this won't be easy.
A really nice workaround I found is to use the built-in serialization inside MS Chart control. The idea is to serialize the chart using memorystream, create a new instance of the chart and deserialize the chart.
private Chart CloneChart(Chart chart)
{
MemoryStream stream = new MemoryStream();
Chart clonedChart = chart;
clonedChart.Serializer.Save(stream);
clonedChart = new Chart();
clonedChart.Serializer.Load(stream);
return clonedChart;
}
Not exactly an efficient solution, but if performance isn't your priority, this works like a charm.

WordProcessingML. How do I assign background color to text?

I have code that creates document with several paragraphs with different text-color for some words. Something like:
using (var doc = WordprocessingDocument.Create("some-file-name", WordprocessingDocumentType.Document))
{
// Add a new main document part.
var mainPart = doc.AddMainDocumentPart();
mainPart.Document = new Document();
var body = new Body();
var paragraph = new Paragraph();
var run = new Run();
...
// append bold text
run.AppendChild(new RunProperties {Bold = new Bold(), });
run.AppendChild(new Text("some-text"));
...
// append red text
run.AppendChild(new RunProperties
{ Color = new Color {Val = "FF0000"}});
run.AppendChild(new Text("some-text"));
But I haven't found a way how to add text with colored background. How can I do that?
Let me answer myself:
Background is Highlight property:
// yellow background sample
run.AppendChild(new RunProperties { Highlight = new Highlight { Val = HighlightColorValues.Yellow } });
run.AppendChild(new Text("some-text"));
I found that I needed to set the w:shd property in the run properties. I was using docx4j, but the principal is the same.